diff options
author | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-06 05:40:17 +0000 |
---|---|---|
committer | armansito@chromium.org <armansito@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-06 05:40:17 +0000 |
commit | 2c0ff463223c2f87b61aee2828ee5caac2cf2b4a (patch) | |
tree | 6470c5d065083a3e7a314b1f7fff7c7c41333c4e /device | |
parent | ddb36b577d606880b74dd96e52f7d0323a9ca80e (diff) | |
download | chromium_src-2c0ff463223c2f87b61aee2828ee5caac2cf2b4a.zip chromium_src-2c0ff463223c2f87b61aee2828ee5caac2cf2b4a.tar.gz chromium_src-2c0ff463223c2f87b61aee2828ee5caac2cf2b4a.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.
BUG=346982
TEST=1. unit_tests, browser_tests
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/179123008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@255262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth.gyp | 2 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter.cc | 2 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_discovery_session.cc | 15 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_discovery_session.h | 6 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_adapter.cc | 10 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_adapter.h | 13 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_discovery_session.cc | 14 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_discovery_session.h | 32 |
8 files changed, 83 insertions, 11 deletions
diff --git a/device/bluetooth/bluetooth.gyp b/device/bluetooth/bluetooth.gyp index 5693fdc..fd76ec2 100644 --- a/device/bluetooth/bluetooth.gyp +++ b/device/bluetooth/bluetooth.gyp @@ -123,6 +123,8 @@ 'test/mock_bluetooth_adapter.h', 'test/mock_bluetooth_device.cc', 'test/mock_bluetooth_device.h', + 'test/mock_bluetooth_discovery_session.cc', + 'test/mock_bluetooth_discovery_session.h', 'test/mock_bluetooth_profile.cc', 'test/mock_bluetooth_profile.h', 'test/mock_bluetooth_socket.cc', diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc index ce63bdd..2868159 100644 --- a/device/bluetooth/bluetooth_adapter.cc +++ b/device/bluetooth/bluetooth_adapter.cc @@ -113,7 +113,7 @@ void BluetoothAdapter::OnStartDiscoverySession( const DiscoverySessionCallback& callback) { VLOG(1) << "Discovery session started!"; scoped_ptr<BluetoothDiscoverySession> discovery_session( - new BluetoothDiscoverySession(this)); + new BluetoothDiscoverySession(scoped_refptr<BluetoothAdapter>(this))); discovery_sessions_.insert(discovery_session.get()); callback.Run(discovery_session.Pass()); } diff --git a/device/bluetooth/bluetooth_discovery_session.cc b/device/bluetooth/bluetooth_discovery_session.cc index e07df34..076123e 100644 --- a/device/bluetooth/bluetooth_discovery_session.cc +++ b/device/bluetooth/bluetooth_discovery_session.cc @@ -9,13 +9,23 @@ namespace device { -BluetoothDiscoverySession::BluetoothDiscoverySession(BluetoothAdapter* adapter) +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() { + if (!active_) + return; + DCHECK(adapter_.get()); Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); adapter_->DiscoverySessionDestroyed(this); } @@ -28,11 +38,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(), diff --git a/device/bluetooth/bluetooth_discovery_session.h b/device/bluetooth/bluetooth_discovery_session.h index bc2f893..666538b 100644 --- a/device/bluetooth/bluetooth_discovery_session.h +++ b/device/bluetooth/bluetooth_discovery_session.h @@ -58,10 +58,12 @@ class BluetoothDiscoverySession { const ErrorCallback& error_callback); protected: - friend class BluetoothAdapter; - explicit BluetoothDiscoverySession(BluetoothAdapter* adapter); + BluetoothDiscoverySession(); // Called by mock. private: + friend class BluetoothAdapter; + explicit BluetoothDiscoverySession(scoped_refptr<BluetoothAdapter> adapter); + // Internal callback invoked when a call to Stop has succeeded. void OnStop(const base::Closure& callback); diff --git a/device/bluetooth/test/mock_bluetooth_adapter.cc b/device/bluetooth/test/mock_bluetooth_adapter.cc index 5848db3..5e63ffb 100644 --- a/device/bluetooth/test/mock_bluetooth_adapter.cc +++ b/device/bluetooth/test/mock_bluetooth_adapter.cc @@ -14,4 +14,14 @@ MockBluetoothAdapter::MockBluetoothAdapter() { MockBluetoothAdapter::~MockBluetoothAdapter() {} +void MockBluetoothAdapter::AddDiscoverySession( + const base::Closure& callback, + const ErrorCallback& error_callback) { +} + +void MockBluetoothAdapter::RemoveDiscoverySession( + const base::Closure& callback, + const ErrorCallback& error_callback) { +} + } // namespace device diff --git a/device/bluetooth/test/mock_bluetooth_adapter.h b/device/bluetooth/test/mock_bluetooth_adapter.h index 56647fe..3a959e9 100644 --- a/device/bluetooth/test/mock_bluetooth_adapter.h +++ b/device/bluetooth/test/mock_bluetooth_adapter.h @@ -52,6 +52,9 @@ class MockBluetoothAdapter : public BluetoothAdapter { const base::Closure& callback, const ErrorCallback& error_callback)); MOCK_CONST_METHOD0(IsDiscovering, bool()); + MOCK_METHOD2(StartDiscoverySession, + void(const DiscoverySessionCallback& callback, + const ErrorCallback& error_callback)); MOCK_METHOD2(StartDiscovering, void(const base::Closure& callback, const ErrorCallback& error_callback)); @@ -74,12 +77,10 @@ class MockBluetoothAdapter : public BluetoothAdapter { MOCK_METHOD0(DefaultPairingDelegate, BluetoothDevice::PairingDelegate*()); protected: - MOCK_METHOD2(AddDiscoverySession, - void(const base::Closure& callback, - const ErrorCallback& error_callback)); - MOCK_METHOD2(RemoveDiscoverySession, - void(const base::Closure& callback, - const ErrorCallback& error_callback)); + virtual void AddDiscoverySession(const base::Closure& callback, + const ErrorCallback& error_callback); + virtual void RemoveDiscoverySession(const base::Closure& callback, + const ErrorCallback& error_callback); virtual ~MockBluetoothAdapter(); MOCK_METHOD1(RemovePairingDelegateInternal, diff --git a/device/bluetooth/test/mock_bluetooth_discovery_session.cc b/device/bluetooth/test/mock_bluetooth_discovery_session.cc new file mode 100644 index 0000000..72449ee --- /dev/null +++ b/device/bluetooth/test/mock_bluetooth_discovery_session.cc @@ -0,0 +1,14 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "device/bluetooth/test/mock_bluetooth_discovery_session.h" + +#include "device/bluetooth/bluetooth_adapter.h" + +namespace device { + +MockBluetoothDiscoverySession::MockBluetoothDiscoverySession() {} +MockBluetoothDiscoverySession::~MockBluetoothDiscoverySession() {} + +} // namespace device diff --git a/device/bluetooth/test/mock_bluetooth_discovery_session.h b/device/bluetooth/test/mock_bluetooth_discovery_session.h new file mode 100644 index 0000000..98f2125 --- /dev/null +++ b/device/bluetooth/test/mock_bluetooth_discovery_session.h @@ -0,0 +1,32 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DISCOVERY_SESSION_H_ +#define DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DISCOVERY_SESSION_H_ + +#include "base/callback.h" +#include "device/bluetooth/bluetooth_discovery_session.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace device { + +class BluetoothAdapter; + +class MockBluetoothDiscoverySession : public BluetoothDiscoverySession { + public: + MockBluetoothDiscoverySession(); + virtual ~MockBluetoothDiscoverySession(); + + MOCK_CONST_METHOD0(IsActive, bool()); + MOCK_METHOD2(Stop, + void(const base::Closure& callback, + const ErrorCallback& error_callback)); + + private: + DISALLOW_COPY_AND_ASSIGN(MockBluetoothDiscoverySession); +}; + +} // namespac device + +#endif // DEVICE_BLUETOOTH_TEST_MOCK_BLUETOOTH_DISCOVERY_SESSION_H_ |