diff options
author | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-17 01:59:48 +0000 |
---|---|---|
committer | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-17 01:59:48 +0000 |
commit | ec9b06712a3cd52def1e8543178487a170fde46b (patch) | |
tree | 3cc0d41d3bf32c37c49fa1ffb8b415b200a65f6d /device | |
parent | 4ccfea6321a0aaf93dc92ced179f4ade6f4f28e5 (diff) | |
download | chromium_src-ec9b06712a3cd52def1e8543178487a170fde46b.zip chromium_src-ec9b06712a3cd52def1e8543178487a170fde46b.tar.gz chromium_src-ec9b06712a3cd52def1e8543178487a170fde46b.tar.bz2 |
Created BluetoothAdapter::IsInitialized() and BluetoothAdapter::QueueAdapterCallback().
These methods are created to make sure the adapter is used only after it is initialized.
For now both ChromeOS and Windows implementations return true for
BluetoothAdpater::IsInitialized(), so nothing has been changed in terms of
functionalities.
BUG=135470
Review URL: https://chromiumcodereview.appspot.com/11959003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177308 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_adapter.cc | 4 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter.h | 11 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.cc | 6 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.h | 1 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_factory.cc | 8 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_factory.h | 9 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_win.cc | 6 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_win.h | 1 | ||||
-rw-r--r-- | device/bluetooth/test/mock_bluetooth_adapter.h | 1 |
9 files changed, 39 insertions, 8 deletions
diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc index 6f036b3..78b556e 100644 --- a/device/bluetooth/bluetooth_adapter.cc +++ b/device/bluetooth/bluetooth_adapter.cc @@ -22,6 +22,10 @@ const std::string& BluetoothAdapter::name() const { return name_; } +void BluetoothAdapter::QueueAdapterCallback(const AdapterCallback& callback) { + adapter_callbacks_.push_back(callback); +} + BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() { ConstDeviceList const_devices = const_cast<const BluetoothAdapter *>(this)->GetDevices(); diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h index ca2cbd5..30d7a95 100644 --- a/device/bluetooth/bluetooth_adapter.h +++ b/device/bluetooth/bluetooth_adapter.h @@ -79,6 +79,9 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { typedef base::Callback<void(const BluetoothOutOfBandPairingData& data)> BluetoothOutOfBandPairingDataCallback; + typedef base::Callback<void(scoped_refptr<BluetoothAdapter> adapter)> + AdapterCallback; + // Adds and removes observers for events on this bluetooth adapter, // if monitoring multiple adapters check the |adapter| parameter of // observer methods to determine which adapter is issuing the event. @@ -93,6 +96,12 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { // The name of the adapter. virtual const std::string& name() const; + // Queue adapter callbacks to be run when the adapter is initialized. + virtual void QueueAdapterCallback(const AdapterCallback& callback); + + // Indicates whether the adapter is initialized and ready to use. + virtual bool IsInitialized() const = 0; + // Indicates whether the adapter is actually present on the system, for // the default adapter this indicates whether any adapter is present. An // adapter is only considered present if the address has been obtained. @@ -151,6 +160,8 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { // Name of the adapter. std::string name_; + std::vector<AdapterCallback> adapter_callbacks_; + // Devices paired with, connected to, discovered by, or visible to the // adapter. The key is the Bluetooth address of the device and the value // is the BluetoothDevice object whose lifetime is managed by the diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc index 508cc21..badbcd0 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc @@ -61,6 +61,12 @@ void BluetoothAdapterChromeOs::RemoveObserver( observers_.RemoveObserver(observer); } +// TODO(youngki) Return true when object path and properties of the adapter are +// initialized. +bool BluetoothAdapterChromeOs::IsInitialized() const { + return true; +} + bool BluetoothAdapterChromeOs::IsPresent() const { return !object_path_.value().empty() && !address_.empty(); } diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h index dc1d0da..79108f9 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_chromeos.h @@ -42,6 +42,7 @@ class BluetoothAdapterChromeOs device::BluetoothAdapter::Observer* observer) OVERRIDE; virtual void RemoveObserver( device::BluetoothAdapter::Observer* observer) OVERRIDE; + virtual bool IsInitialized() const OVERRIDE; virtual bool IsPresent() const OVERRIDE; virtual bool IsPowered() const OVERRIDE; virtual void SetPowered( diff --git a/device/bluetooth/bluetooth_adapter_factory.cc b/device/bluetooth/bluetooth_adapter_factory.cc index 23bb07d3..e26f642 100644 --- a/device/bluetooth/bluetooth_adapter_factory.cc +++ b/device/bluetooth/bluetooth_adapter_factory.cc @@ -40,7 +40,7 @@ bool BluetoothAdapterFactory::IsBluetoothAdapterAvailable() { // static void BluetoothAdapterFactory::RunCallbackOnAdapterReady( - const AdapterCallback& callback) { + const BluetoothAdapter::AdapterCallback& callback) { if (!default_adapter.Get().get()) { #if defined(OS_CHROMEOS) chromeos::BluetoothAdapterChromeOs* new_adapter = @@ -54,7 +54,11 @@ void BluetoothAdapterFactory::RunCallbackOnAdapterReady( #endif } - callback.Run(scoped_refptr<BluetoothAdapter>(default_adapter.Get())); + if (default_adapter.Get()->IsInitialized()) { + callback.Run(scoped_refptr<BluetoothAdapter>(default_adapter.Get())); + } else { + default_adapter.Get()->QueueAdapterCallback(callback); + } } // static diff --git a/device/bluetooth/bluetooth_adapter_factory.h b/device/bluetooth/bluetooth_adapter_factory.h index 6923f7a..f2203aa 100644 --- a/device/bluetooth/bluetooth_adapter_factory.h +++ b/device/bluetooth/bluetooth_adapter_factory.h @@ -9,26 +9,23 @@ #include "base/callback.h" #include "base/memory/ref_counted.h" +#include "device/bluetooth/bluetooth_adapter.h" namespace device { -class BluetoothAdapter; - // BluetoothAdapterFactory is a class that contains static methods, which // instantiate either a specific Bluetooth adapter, or the generic "default // adapter" which may change depending on availability. class BluetoothAdapterFactory { public: - typedef base::Callback<void(scoped_refptr<device::BluetoothAdapter> adapter)> - AdapterCallback; - // Returns true if the Bluetooth adapter is available for the current // platform. static bool IsBluetoothAdapterAvailable(); // Runs the callback with the shared instance for the default adapter when the // adapter is available to be used. - static void RunCallbackOnAdapterReady(const AdapterCallback& callback); + static void RunCallbackOnAdapterReady( + const BluetoothAdapter::AdapterCallback& callback); // Returns the shared instance of the adapter that has already been created. // It returns NULL if no adapter has been created at the time. diff --git a/device/bluetooth/bluetooth_adapter_win.cc b/device/bluetooth/bluetooth_adapter_win.cc index 1f0efce..410478a 100644 --- a/device/bluetooth/bluetooth_adapter_win.cc +++ b/device/bluetooth/bluetooth_adapter_win.cc @@ -35,6 +35,12 @@ void BluetoothAdapterWin::RemoveObserver(BluetoothAdapter::Observer* observer) { NOTIMPLEMENTED(); } +// TODO(youngki): Return true when |task_manager_| initializes the adapter +// state. +bool BluetoothAdapterWin::IsInitialized() const { + return true; +} + bool BluetoothAdapterWin::IsPresent() const { return !address_.empty(); } diff --git a/device/bluetooth/bluetooth_adapter_win.h b/device/bluetooth/bluetooth_adapter_win.h index 7519aee..b5a3187 100644 --- a/device/bluetooth/bluetooth_adapter_win.h +++ b/device/bluetooth/bluetooth_adapter_win.h @@ -25,6 +25,7 @@ class BluetoothAdapterWin : public BluetoothAdapter, // BluetoothAdapter override virtual void AddObserver(BluetoothAdapter::Observer* observer) OVERRIDE; virtual void RemoveObserver(BluetoothAdapter::Observer* observer) OVERRIDE; + virtual bool IsInitialized() const OVERRIDE; virtual bool IsPresent() const OVERRIDE; virtual bool IsPowered() const OVERRIDE; virtual void SetPowered( diff --git a/device/bluetooth/test/mock_bluetooth_adapter.h b/device/bluetooth/test/mock_bluetooth_adapter.h index 33f7afb..3e3619e 100644 --- a/device/bluetooth/test/mock_bluetooth_adapter.h +++ b/device/bluetooth/test/mock_bluetooth_adapter.h @@ -33,6 +33,7 @@ class MockBluetoothAdapter : public BluetoothAdapter { MOCK_METHOD1(AddObserver, void(BluetoothAdapter::Observer*)); MOCK_METHOD1(RemoveObserver, void(BluetoothAdapter::Observer*)); + MOCK_CONST_METHOD0(IsInitialized, bool()); MOCK_CONST_METHOD0(IsPresent, bool()); MOCK_CONST_METHOD0(IsPowered, bool()); MOCK_METHOD3(SetPowered, |