diff options
author | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 22:12:56 +0000 |
---|---|---|
committer | youngki@chromium.org <youngki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-15 22:12:56 +0000 |
commit | 58dcad5d93d5532d3cd56d4e7e529918ca87badd (patch) | |
tree | 96030b6671287e94ba554c9fa364d812acac4dfe /device | |
parent | 0b2e64bb47d8615e783d37ca6027294bce5ceceb (diff) | |
download | chromium_src-58dcad5d93d5532d3cd56d4e7e529918ca87badd.zip chromium_src-58dcad5d93d5532d3cd56d4e7e529918ca87badd.tar.gz chromium_src-58dcad5d93d5532d3cd56d4e7e529918ca87badd.tar.bz2 |
Moved GetDevice* method implementation from BluetoothAdapterChromeOs to BluetoothAdapter.
These implementations can be shared across the platform.
BUG=135470
Review URL: https://chromiumcodereview.appspot.com/11366259
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@168047 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'device')
-rw-r--r-- | device/bluetooth/bluetooth_adapter.cc | 27 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter.h | 15 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.cc | 42 | ||||
-rw-r--r-- | device/bluetooth/bluetooth_adapter_chromeos.h | 13 |
4 files changed, 49 insertions, 48 deletions
diff --git a/device/bluetooth/bluetooth_adapter.cc b/device/bluetooth/bluetooth_adapter.cc index b36cd0b..6f036b3 100644 --- a/device/bluetooth/bluetooth_adapter.cc +++ b/device/bluetooth/bluetooth_adapter.cc @@ -8,6 +8,9 @@ namespace device { +BluetoothAdapter::BluetoothAdapter() { +} + BluetoothAdapter::~BluetoothAdapter() { } @@ -31,4 +34,28 @@ BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() { return devices; } +BluetoothAdapter::ConstDeviceList BluetoothAdapter::GetDevices() const { + ConstDeviceList devices; + for (DevicesMap::const_iterator iter = devices_.begin(); + iter != devices_.end(); + ++iter) + devices.push_back(iter->second); + + return devices; +} + +BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) { + return const_cast<BluetoothDevice *>( + const_cast<const BluetoothAdapter *>(this)->GetDevice(address)); +} + +const BluetoothDevice* BluetoothAdapter::GetDevice( + const std::string& address) const { + DevicesMap::const_iterator iter = devices_.find(address); + if (iter != devices_.end()) + return iter->second; + + return NULL; +} + } // namespace device diff --git a/device/bluetooth/bluetooth_adapter.h b/device/bluetooth/bluetooth_adapter.h index 86de361..ca2cbd5 100644 --- a/device/bluetooth/bluetooth_adapter.h +++ b/device/bluetooth/bluetooth_adapter.h @@ -5,6 +5,7 @@ #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_H_ +#include <map> #include <string> #include <vector> @@ -126,13 +127,13 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { typedef std::vector<BluetoothDevice*> DeviceList; virtual DeviceList GetDevices(); typedef std::vector<const BluetoothDevice*> ConstDeviceList; - virtual ConstDeviceList GetDevices() const = 0; + virtual ConstDeviceList GetDevices() const; // Returns a pointer to the device with the given address |address| or // NULL if no such device is known. - virtual BluetoothDevice* GetDevice(const std::string& address) = 0; + virtual BluetoothDevice* GetDevice(const std::string& address); virtual const BluetoothDevice* GetDevice( - const std::string& address) const = 0; + const std::string& address) const; // Requests the local Out Of Band pairing data. virtual void ReadLocalOutOfBandPairingData( @@ -141,6 +142,7 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { protected: friend class base::RefCounted<BluetoothAdapter>; + BluetoothAdapter(); virtual ~BluetoothAdapter(); // Address of the adapter. @@ -148,6 +150,13 @@ class BluetoothAdapter : public base::RefCounted<BluetoothAdapter> { // Name of the adapter. std::string name_; + + // 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 + // adapter instance. + typedef std::map<const std::string, BluetoothDevice*> DevicesMap; + DevicesMap devices_; }; } // namespace device diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc index 36699e5..508cc21 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.cc +++ b/device/bluetooth/bluetooth_adapter_chromeos.cc @@ -25,7 +25,8 @@ using device::BluetoothOutOfBandPairingData; namespace chromeos { -BluetoothAdapterChromeOs::BluetoothAdapterChromeOs() : track_default_(false), +BluetoothAdapterChromeOs::BluetoothAdapterChromeOs() : BluetoothAdapter(), + track_default_(false), powered_(false), discovering_(false), weak_ptr_factory_(this) { @@ -105,31 +106,6 @@ void BluetoothAdapterChromeOs::SetDiscovering( } } -BluetoothAdapter::ConstDeviceList BluetoothAdapterChromeOs::GetDevices() const { - ConstDeviceList devices; - for (DevicesMap::const_iterator iter = devices_.begin(); - iter != devices_.end(); - ++iter) - devices.push_back(iter->second); - - return devices; -} - -BluetoothDevice* BluetoothAdapterChromeOs::GetDevice( - const std::string& address) { - return const_cast<BluetoothDevice *>( - const_cast<const BluetoothAdapterChromeOs *>(this)->GetDevice(address)); -} - -const BluetoothDevice* BluetoothAdapterChromeOs::GetDevice( - const std::string& address) const { - DevicesMap::const_iterator iter = devices_.find(address); - if (iter != devices_.end()) - return iter->second; - - return NULL; -} - void BluetoothAdapterChromeOs::ReadLocalOutOfBandPairingData( const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, const ErrorCallback& error_callback) { @@ -364,7 +340,7 @@ void BluetoothAdapterChromeOs::UpdateDevice( BluetoothDeviceChromeOs* device; const bool update_device = (iter != devices_.end()); if (update_device) { - device = iter->second; + device = static_cast<BluetoothDeviceChromeOs*>(iter->second); } else { device = BluetoothDeviceChromeOs::Create(this); devices_[address] = device; @@ -392,7 +368,7 @@ void BluetoothAdapterChromeOs::ClearDevices() { devices_.swap(replace); for (DevicesMap::iterator iter = replace.begin(); iter != replace.end(); ++iter) { - BluetoothDeviceChromeOs* device = iter->second; + BluetoothDevice* device = iter->second; FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_, DeviceRemoved(this, device)); @@ -417,7 +393,8 @@ void BluetoothAdapterChromeOs::DeviceRemoved( DevicesMap::iterator iter = devices_.begin(); while (iter != devices_.end()) { - BluetoothDeviceChromeOs* device = iter->second; + BluetoothDeviceChromeOs* device = + static_cast<BluetoothDeviceChromeOs*>(iter->second); DevicesMap::iterator temp = iter; ++iter; @@ -455,7 +432,7 @@ void BluetoothAdapterChromeOs::DevicesChanged( void BluetoothAdapterChromeOs::ClearDiscoveredDevices() { DevicesMap::iterator iter = devices_.begin(); while (iter != devices_.end()) { - BluetoothDeviceChromeOs* device = iter->second; + BluetoothDevice* device = iter->second; DevicesMap::iterator temp = iter; ++iter; @@ -483,7 +460,7 @@ void BluetoothAdapterChromeOs::DeviceFound( DevicesMap::iterator iter = devices_.find(address); const bool update_device = (iter != devices_.end()); if (update_device) { - device = iter->second; + device = static_cast<BluetoothDeviceChromeOs*>(iter->second); } else { device = BluetoothDeviceChromeOs::Create(this); devices_[address] = device; @@ -512,7 +489,8 @@ void BluetoothAdapterChromeOs::DeviceDisappeared( if (iter == devices_.end()) return; - BluetoothDeviceChromeOs* device = iter->second; + BluetoothDeviceChromeOs* device = + static_cast<BluetoothDeviceChromeOs*>(iter->second); // DeviceDisappeared can also be called to indicate that a device we've // paired with is no longer visible to the adapter, so don't remove diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h index 18cb7aa..dc1d0da 100644 --- a/device/bluetooth/bluetooth_adapter_chromeos.h +++ b/device/bluetooth/bluetooth_adapter_chromeos.h @@ -5,7 +5,6 @@ #ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ #define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_ -#include <map> #include <string> #include <vector> @@ -54,11 +53,6 @@ class BluetoothAdapterChromeOs bool discovering, const base::Closure& callback, const ErrorCallback& error_callback) OVERRIDE; - virtual ConstDeviceList GetDevices() const OVERRIDE; - virtual device::BluetoothDevice* GetDevice( - const std::string& address) OVERRIDE; - virtual const device::BluetoothDevice* GetDevice( - const std::string& address) const OVERRIDE; virtual void ReadLocalOutOfBandPairingData( const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback, @@ -226,13 +220,6 @@ class BluetoothAdapterChromeOs bool powered_; bool discovering_; - // 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 BluetoothDeviceChromeOs object whose lifetime is managed by the - // adapter instance. - typedef std::map<const std::string, BluetoothDeviceChromeOs*> DevicesMap; - DevicesMap devices_; - // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<BluetoothAdapterChromeOs> weak_ptr_factory_; |