diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-02 01:50:00 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-07-02 01:50:00 +0000 |
commit | d233ff7eadb909914779089770dfb2e70f8beddf (patch) | |
tree | 6900058787fa41b1d50fc22cae44eab3a471a665 /device/bluetooth | |
parent | 5ca3c2c9c7bed1cfe7cdf2413893e40dab56d718 (diff) | |
download | chromium_src-d233ff7eadb909914779089770dfb2e70f8beddf.zip chromium_src-d233ff7eadb909914779089770dfb2e70f8beddf.tar.gz chromium_src-d233ff7eadb909914779089770dfb2e70f8beddf.tar.bz2 |
Clean up BluetoothDiscoverySession a bit.
* Avoid unhelpful logging for a common path through the destructor.
* Remove the need for a test-only constructor.
BUG=none
TEST=none
R=armansito@chromium.org
Review URL: https://codereview.chromium.org/368493002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device/bluetooth')
4 files changed, 14 insertions, 17 deletions
diff --git a/device/bluetooth/bluetooth_discovery_session.cc b/device/bluetooth/bluetooth_discovery_session.cc index ba5f5fd..bfcc59f 100644 --- a/device/bluetooth/bluetooth_discovery_session.cc +++ b/device/bluetooth/bluetooth_discovery_session.cc @@ -15,17 +15,11 @@ BluetoothDiscoverySession::BluetoothDiscoverySession( 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; + if (active_) { + Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); + MarkAsInactive(); } - Stop(base::Bind(&base::DoNothing), base::Bind(&base::DoNothing)); - MarkAsInactive(); } bool BluetoothDiscoverySession::IsActive() const { @@ -41,7 +35,6 @@ void BluetoothDiscoverySession::Stop( return; } VLOG(1) << "Stopping device discovery session."; - DCHECK(adapter_.get()); adapter_->RemoveDiscoverySession( base::Bind(&BluetoothDiscoverySession::OnStop, weak_ptr_factory_.GetWeakPtr(), @@ -58,7 +51,6 @@ void BluetoothDiscoverySession::MarkAsInactive() { if (!active_) return; active_ = false; - DCHECK(adapter_.get()); adapter_->DiscoverySessionBecameInactive(this); } diff --git a/device/bluetooth/bluetooth_discovery_session.h b/device/bluetooth/bluetooth_discovery_session.h index 666538b..08a1de8 100644 --- a/device/bluetooth/bluetooth_discovery_session.h +++ b/device/bluetooth/bluetooth_discovery_session.h @@ -58,11 +58,10 @@ class BluetoothDiscoverySession { const ErrorCallback& error_callback); protected: - BluetoothDiscoverySession(); // Called by mock. + explicit BluetoothDiscoverySession(scoped_refptr<BluetoothAdapter> adapter); 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_discovery_session.cc b/device/bluetooth/test/mock_bluetooth_discovery_session.cc index 72449ee..295f954 100644 --- a/device/bluetooth/test/mock_bluetooth_discovery_session.cc +++ b/device/bluetooth/test/mock_bluetooth_discovery_session.cc @@ -4,11 +4,19 @@ #include "device/bluetooth/test/mock_bluetooth_discovery_session.h" -#include "device/bluetooth/bluetooth_adapter.h" +#include "device/bluetooth/test/mock_bluetooth_adapter.h" namespace device { -MockBluetoothDiscoverySession::MockBluetoothDiscoverySession() {} +// Note: Because |this| class mocks out all the interesting method calls, the +// mock BluetoothAdapter will not be used, except for a trivial call from the +// destructor. It's passed in simply because the base class expects one, and +// it's nice not to need to complicate production code for the sake of simpler +// test code. +MockBluetoothDiscoverySession::MockBluetoothDiscoverySession() + : BluetoothDiscoverySession( + scoped_refptr<BluetoothAdapter>( + new testing::NiceMock<MockBluetoothAdapter>())) {} MockBluetoothDiscoverySession::~MockBluetoothDiscoverySession() {} } // namespace device diff --git a/device/bluetooth/test/mock_bluetooth_discovery_session.h b/device/bluetooth/test/mock_bluetooth_discovery_session.h index 98f2125..bd724a7 100644 --- a/device/bluetooth/test/mock_bluetooth_discovery_session.h +++ b/device/bluetooth/test/mock_bluetooth_discovery_session.h @@ -11,8 +11,6 @@ namespace device { -class BluetoothAdapter; - class MockBluetoothDiscoverySession : public BluetoothDiscoverySession { public: MockBluetoothDiscoverySession(); |