diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-07 14:17:39 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-07 14:17:39 +0000 |
commit | ccb7372246091549d8fdbb62477069496202281e (patch) | |
tree | 5251b5b6a9a8bbd5ebf2f34cc1485bfc878bfa3e /device/bluetooth/bluetooth_discovery_session.cc | |
parent | a2093312232560c7984ad6213df0e99343bea225 (diff) | |
download | chromium_src-ccb7372246091549d8fdbb62477069496202281e.zip chromium_src-ccb7372246091549d8fdbb62477069496202281e.tar.gz chromium_src-ccb7372246091549d8fdbb62477069496202281e.tar.bz2 |
Migrate chrome.bluetooth API backend to use device::BluetoothDiscoverySession.
Modified chrome.bluetooth API code to use the new discovery session API for
device discovery.
This CL is the same as r255262 which was reverted due to a memory leak. The leak
has been addressed in this patch.
BUG=346982,349942
TEST=1. Run unit_tests and browser_tests with LSan.
2. Use multiple running extension instances with the bluetooth permission
and check for the following behavior:
- Only one session per extension. Calling chrome.bluetooth.stopDiscovery
from one running app should fail if that app never called
chrome.bluetooth.startDiscovery.
- An app's discovery sessions should get cleaned up if that app crashes
or unloads.
- Use bt_console and run "power off". This should cause all discovery
sessions that have been assigned to apps to get marked as inactive.
Verify by requesting a new discovery session from apps, which should
succeed.
Review URL: https://codereview.chromium.org/189463002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255609 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth/bluetooth_discovery_session.cc')
-rw-r--r-- | device/bluetooth/bluetooth_discovery_session.cc | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/device/bluetooth/bluetooth_discovery_session.cc b/device/bluetooth/bluetooth_discovery_session.cc index e07df34..6818a3c 100644 --- a/device/bluetooth/bluetooth_discovery_session.cc +++ b/device/bluetooth/bluetooth_discovery_session.cc @@ -9,13 +9,21 @@ namespace device { -BluetoothDiscoverySession::BluetoothDiscoverySession(BluetoothAdapter* adapter) - : active_(true), - adapter_(adapter), - weak_ptr_factory_(this) { +BluetoothDiscoverySession::BluetoothDiscoverySession( + scoped_refptr<BluetoothAdapter> adapter) + : active_(true), adapter_(adapter), weak_ptr_factory_(this) { + DCHECK(adapter_.get()); } +BluetoothDiscoverySession::BluetoothDiscoverySession() + : active_(false), weak_ptr_factory_(this) {} + BluetoothDiscoverySession::~BluetoothDiscoverySession() { + // |adapter_| may be NULL if this instance was initialized as a mock. + if (!adapter_.get()) { + DCHECK(!active_); + return; + } Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); adapter_->DiscoverySessionDestroyed(this); } @@ -28,11 +36,12 @@ void BluetoothDiscoverySession::Stop( const base::Closure& callback, const ErrorCallback& error_callback) { if (!active_) { - LOG(ERROR) << "Discovery session not active. Cannot stop."; + LOG(WARNING) << "Discovery session not active. Cannot stop."; error_callback.Run(); return; } VLOG(1) << "Stopping device discovery session."; + DCHECK(adapter_.get()); adapter_->RemoveDiscoverySession( base::Bind(&BluetoothDiscoverySession::OnStop, weak_ptr_factory_.GetWeakPtr(), |