| Index: chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc
|
| diff --git a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc b/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc
|
| similarity index 70%
|
| copy from chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc
|
| copy to chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc
|
| index cad3de4bdbbccf0a2d53bd5d839e7032957789a9..8a4b4c55b1f70012f118e4c3d8c052fa97b0b998 100644
|
| --- a/chrome/browser/chromeos/bluetooth/bluetooth_adapter.cc
|
| +++ b/chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.cc
|
| @@ -2,38 +2,29 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter.h"
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_adapter_chromeos.h"
|
| +
|
| +#include <string>
|
|
|
| #include "base/bind.h"
|
| -#include "base/lazy_instance.h"
|
| #include "base/logging.h"
|
| #include "base/stl_util.h"
|
| #include "base/values.h"
|
| -#include "chrome/browser/chromeos/bluetooth/bluetooth_device.h"
|
| +#include "chrome/browser/chromeos/bluetooth/bluetooth_device_chromeos.h"
|
| #include "chromeos/dbus/bluetooth_adapter_client.h"
|
| #include "chromeos/dbus/bluetooth_device_client.h"
|
| #include "chromeos/dbus/bluetooth_manager_client.h"
|
| #include "chromeos/dbus/bluetooth_out_of_band_client.h"
|
| +#include "chromeos/dbus/bluetooth_out_of_band_pairing_data.h"
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| #include "dbus/object_path.h"
|
|
|
| -namespace {
|
| -
|
| -// Shared default adapter instance, we don't want to keep this class around
|
| -// if nobody is using it so use a WeakPtr and create the object when needed;
|
| -// since Google C++ Style (and clang's static analyzer) forbids us having
|
| -// exit-time destructors we use a leaky lazy instance for it.
|
| -base::LazyInstance<base::WeakPtr<chromeos::BluetoothAdapter> >::Leaky
|
| - default_adapter = LAZY_INSTANCE_INITIALIZER;
|
| -
|
| -} // namespace
|
| -
|
| namespace chromeos {
|
|
|
| -BluetoothAdapter::BluetoothAdapter() : track_default_(false),
|
| - powered_(false),
|
| - discovering_(false),
|
| - weak_ptr_factory_(this) {
|
| +BluetoothAdapterChromeOs::BluetoothAdapterChromeOs() : track_default_(false),
|
| + powered_(false),
|
| + discovering_(false),
|
| + weak_ptr_factory_(this) {
|
| DBusThreadManager::Get()->GetBluetoothManagerClient()->
|
| AddObserver(this);
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| @@ -42,7 +33,7 @@ BluetoothAdapter::BluetoothAdapter() : track_default_(false),
|
| AddObserver(this);
|
| }
|
|
|
| -BluetoothAdapter::~BluetoothAdapter() {
|
| +BluetoothAdapterChromeOs::~BluetoothAdapterChromeOs() {
|
| DBusThreadManager::Get()->GetBluetoothDeviceClient()->
|
| RemoveObserver(this);
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| @@ -53,87 +44,80 @@ BluetoothAdapter::~BluetoothAdapter() {
|
| STLDeleteValues(&devices_);
|
| }
|
|
|
| -void BluetoothAdapter::AddObserver(Observer* observer) {
|
| +void BluetoothAdapterChromeOs::AddObserver(
|
| + BluetoothAdapter::Observer* observer) {
|
| DCHECK(observer);
|
| observers_.AddObserver(observer);
|
| }
|
|
|
| -void BluetoothAdapter::RemoveObserver(Observer* observer) {
|
| +void BluetoothAdapterChromeOs::RemoveObserver(
|
| + BluetoothAdapter::Observer* observer) {
|
| DCHECK(observer);
|
| observers_.RemoveObserver(observer);
|
| }
|
|
|
| -bool BluetoothAdapter::IsPresent() const {
|
| +bool BluetoothAdapterChromeOs::IsPresent() const {
|
| return !object_path_.value().empty() && !address_.empty();
|
| }
|
|
|
| -bool BluetoothAdapter::IsPowered() const {
|
| +bool BluetoothAdapterChromeOs::IsPowered() const {
|
| return powered_;
|
| }
|
|
|
| -void BluetoothAdapter::SetPowered(bool powered,
|
| - const base::Closure& callback,
|
| - const ErrorCallback& error_callback) {
|
| +void BluetoothAdapterChromeOs::SetPowered(bool powered,
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback) {
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| GetProperties(object_path_)->powered.Set(
|
| powered,
|
| - base::Bind(&BluetoothAdapter::OnSetPowered,
|
| + base::Bind(&BluetoothAdapterChromeOs::OnSetPowered,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
| }
|
|
|
| -bool BluetoothAdapter::IsDiscovering() const {
|
| +bool BluetoothAdapterChromeOs::IsDiscovering() const {
|
| return discovering_;
|
| }
|
|
|
| -void BluetoothAdapter::SetDiscovering(bool discovering,
|
| - const base::Closure& callback,
|
| - const ErrorCallback& error_callback) {
|
| +void BluetoothAdapterChromeOs::SetDiscovering(
|
| + bool discovering,
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback) {
|
| if (discovering) {
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| StartDiscovery(object_path_,
|
| - base::Bind(&BluetoothAdapter::OnStartDiscovery,
|
| + base::Bind(&BluetoothAdapterChromeOs::OnStartDiscovery,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
| } else {
|
| DBusThreadManager::Get()->GetBluetoothAdapterClient()->
|
| StopDiscovery(object_path_,
|
| - base::Bind(&BluetoothAdapter::OnStopDiscovery,
|
| + base::Bind(&BluetoothAdapterChromeOs::OnStopDiscovery,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
| }
|
| }
|
|
|
| -BluetoothAdapter::DeviceList BluetoothAdapter::GetDevices() {
|
| - ConstDeviceList const_devices =
|
| - const_cast<const BluetoothAdapter *>(this)->GetDevices();
|
| -
|
| - DeviceList devices;
|
| - for (ConstDeviceList::const_iterator i = const_devices.begin();
|
| - i != const_devices.end(); ++i)
|
| - devices.push_back(const_cast<BluetoothDevice *>(*i));
|
| -
|
| - return devices;
|
| -}
|
| -
|
| -BluetoothAdapter::ConstDeviceList BluetoothAdapter::GetDevices() const {
|
| +BluetoothAdapter::ConstDeviceList BluetoothAdapterChromeOs::GetDevices() const {
|
| ConstDeviceList devices;
|
| for (DevicesMap::const_iterator iter = devices_.begin();
|
| - iter != devices_.end(); ++iter)
|
| + iter != devices_.end();
|
| + ++iter)
|
| devices.push_back(iter->second);
|
|
|
| return devices;
|
| }
|
|
|
| -BluetoothDevice* BluetoothAdapter::GetDevice(const std::string& address) {
|
| +BluetoothDevice* BluetoothAdapterChromeOs::GetDevice(
|
| + const std::string& address) {
|
| return const_cast<BluetoothDevice *>(
|
| - const_cast<const BluetoothAdapter *>(this)->GetDevice(address));
|
| + const_cast<const BluetoothAdapterChromeOs *>(this)->GetDevice(address));
|
| }
|
|
|
| -const BluetoothDevice* BluetoothAdapter::GetDevice(
|
| +const BluetoothDevice* BluetoothAdapterChromeOs::GetDevice(
|
| const std::string& address) const {
|
| DevicesMap::const_iterator iter = devices_.find(address);
|
| if (iter != devices_.end())
|
| @@ -142,36 +126,37 @@ const BluetoothDevice* BluetoothAdapter::GetDevice(
|
| return NULL;
|
| }
|
|
|
| -void BluetoothAdapter::ReadLocalOutOfBandPairingData(
|
| +void BluetoothAdapterChromeOs::ReadLocalOutOfBandPairingData(
|
| const BluetoothOutOfBandPairingDataCallback& callback,
|
| const ErrorCallback& error_callback) {
|
| DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
|
| ReadLocalData(object_path_,
|
| - base::Bind(&BluetoothAdapter::OnReadLocalData,
|
| + base::Bind(&BluetoothAdapterChromeOs::OnReadLocalData,
|
| weak_ptr_factory_.GetWeakPtr(),
|
| callback,
|
| error_callback));
|
| }
|
|
|
| -void BluetoothAdapter::TrackDefaultAdapter() {
|
| +void BluetoothAdapterChromeOs::TrackDefaultAdapter() {
|
| DVLOG(1) << "Tracking default adapter";
|
| track_default_ = true;
|
| DBusThreadManager::Get()->GetBluetoothManagerClient()->
|
| - DefaultAdapter(base::Bind(&BluetoothAdapter::AdapterCallback,
|
| + DefaultAdapter(base::Bind(&BluetoothAdapterChromeOs::AdapterCallback,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| -void BluetoothAdapter::FindAdapter(const std::string& address) {
|
| +void BluetoothAdapterChromeOs::FindAdapter(const std::string& address) {
|
| DVLOG(1) << "Using adapter " << address;
|
| track_default_ = false;
|
| DBusThreadManager::Get()->GetBluetoothManagerClient()->
|
| FindAdapter(address,
|
| - base::Bind(&BluetoothAdapter::AdapterCallback,
|
| + base::Bind(&BluetoothAdapterChromeOs::AdapterCallback,
|
| weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| -void BluetoothAdapter::AdapterCallback(const dbus::ObjectPath& adapter_path,
|
| - bool success) {
|
| +void BluetoothAdapterChromeOs::AdapterCallback(
|
| + const dbus::ObjectPath& adapter_path,
|
| + bool success) {
|
| if (success) {
|
| ChangeAdapter(adapter_path);
|
| } else if (!object_path_.value().empty()) {
|
| @@ -179,18 +164,20 @@ void BluetoothAdapter::AdapterCallback(const dbus::ObjectPath& adapter_path,
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::DefaultAdapterChanged(
|
| +void BluetoothAdapterChromeOs::DefaultAdapterChanged(
|
| const dbus::ObjectPath& adapter_path) {
|
| if (track_default_)
|
| ChangeAdapter(adapter_path);
|
| }
|
|
|
| -void BluetoothAdapter::AdapterRemoved(const dbus::ObjectPath& adapter_path) {
|
| +void BluetoothAdapterChromeOs::AdapterRemoved(
|
| + const dbus::ObjectPath& adapter_path) {
|
| if (adapter_path == object_path_)
|
| RemoveAdapter();
|
| }
|
|
|
| -void BluetoothAdapter::ChangeAdapter(const dbus::ObjectPath& adapter_path) {
|
| +void BluetoothAdapterChromeOs::ChangeAdapter(
|
| + const dbus::ObjectPath& adapter_path) {
|
| if (object_path_.value().empty()) {
|
| DVLOG(1) << "Adapter path initialized to " << adapter_path.value();
|
| } else if (object_path_.value() != adapter_path.value()) {
|
| @@ -226,7 +213,7 @@ void BluetoothAdapter::ChangeAdapter(const dbus::ObjectPath& adapter_path) {
|
| AdapterPresentChanged(this, true));
|
| }
|
|
|
| -void BluetoothAdapter::RemoveAdapter() {
|
| +void BluetoothAdapterChromeOs::RemoveAdapter() {
|
| const bool adapter_was_present = IsPresent();
|
|
|
| DVLOG(1) << "Adapter lost.";
|
| @@ -243,16 +230,16 @@ void BluetoothAdapter::RemoveAdapter() {
|
| AdapterPresentChanged(this, false));
|
| }
|
|
|
| -void BluetoothAdapter::OnSetPowered(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - bool success) {
|
| +void BluetoothAdapterChromeOs::OnSetPowered(const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + bool success) {
|
| if (success)
|
| callback.Run();
|
| else
|
| error_callback.Run();
|
| }
|
|
|
| -void BluetoothAdapter::PoweredChanged(bool powered) {
|
| +void BluetoothAdapterChromeOs::PoweredChanged(bool powered) {
|
| if (powered == powered_)
|
| return;
|
|
|
| @@ -262,10 +249,11 @@ void BluetoothAdapter::PoweredChanged(bool powered) {
|
| AdapterPoweredChanged(this, powered_));
|
| }
|
|
|
| -void BluetoothAdapter::OnStartDiscovery(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - const dbus::ObjectPath& adapter_path,
|
| - bool success) {
|
| +void BluetoothAdapterChromeOs::OnStartDiscovery(
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + const dbus::ObjectPath& adapter_path,
|
| + bool success) {
|
| if (success) {
|
| DVLOG(1) << object_path_.value() << ": started discovery.";
|
|
|
| @@ -279,10 +267,11 @@ void BluetoothAdapter::OnStartDiscovery(const base::Closure& callback,
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::OnStopDiscovery(const base::Closure& callback,
|
| - const ErrorCallback& error_callback,
|
| - const dbus::ObjectPath& adapter_path,
|
| - bool success) {
|
| +void BluetoothAdapterChromeOs::OnStopDiscovery(
|
| + const base::Closure& callback,
|
| + const ErrorCallback& error_callback,
|
| + const dbus::ObjectPath& adapter_path,
|
| + bool success) {
|
| if (success) {
|
| DVLOG(1) << object_path_.value() << ": stopped discovery.";
|
| callback.Run();
|
| @@ -294,7 +283,7 @@ void BluetoothAdapter::OnStopDiscovery(const base::Closure& callback,
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::DiscoveringChanged(bool discovering) {
|
| +void BluetoothAdapterChromeOs::DiscoveringChanged(bool discovering) {
|
| if (discovering == discovering_)
|
| return;
|
|
|
| @@ -304,7 +293,7 @@ void BluetoothAdapter::DiscoveringChanged(bool discovering) {
|
| AdapterDiscoveringChanged(this, discovering_));
|
| }
|
|
|
| -void BluetoothAdapter::OnReadLocalData(
|
| +void BluetoothAdapterChromeOs::OnReadLocalData(
|
| const BluetoothOutOfBandPairingDataCallback& callback,
|
| const ErrorCallback& error_callback,
|
| const BluetoothOutOfBandPairingData& data,
|
| @@ -315,7 +304,7 @@ void BluetoothAdapter::OnReadLocalData(
|
| error_callback.Run();
|
| }
|
|
|
| -void BluetoothAdapter::AdapterPropertyChanged(
|
| +void BluetoothAdapterChromeOs::AdapterPropertyChanged(
|
| const dbus::ObjectPath& adapter_path,
|
| const std::string& property_name) {
|
| if (adapter_path != object_path_)
|
| @@ -345,13 +334,14 @@ void BluetoothAdapter::AdapterPropertyChanged(
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::DevicePropertyChanged(
|
| +void BluetoothAdapterChromeOs::DevicePropertyChanged(
|
| const dbus::ObjectPath& device_path,
|
| const std::string& property_name) {
|
| UpdateDevice(device_path);
|
| }
|
|
|
| -void BluetoothAdapter::UpdateDevice(const dbus::ObjectPath& device_path) {
|
| +void BluetoothAdapterChromeOs::UpdateDevice(
|
| + const dbus::ObjectPath& device_path) {
|
| BluetoothDeviceClient::Properties* properties =
|
| DBusThreadManager::Get()->GetBluetoothDeviceClient()->
|
| GetProperties(device_path);
|
| @@ -367,12 +357,12 @@ void BluetoothAdapter::UpdateDevice(const dbus::ObjectPath& device_path) {
|
| // pairing gaining an object path in the process. In any case, we want
|
| // to update the existing object, not create a new one.
|
| DevicesMap::iterator iter = devices_.find(address);
|
| - BluetoothDevice* device;
|
| + BluetoothDeviceChromeOs* device;
|
| const bool update_device = (iter != devices_.end());
|
| if (update_device) {
|
| device = iter->second;
|
| } else {
|
| - device = BluetoothDevice::Create(this);
|
| + device = BluetoothDeviceChromeOs::Create(this);
|
| devices_[address] = device;
|
| }
|
|
|
| @@ -397,12 +387,12 @@ void BluetoothAdapter::UpdateDevice(const dbus::ObjectPath& device_path) {
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::ClearDevices() {
|
| +void BluetoothAdapterChromeOs::ClearDevices() {
|
| DevicesMap replace;
|
| devices_.swap(replace);
|
| for (DevicesMap::iterator iter = replace.begin();
|
| iter != replace.end(); ++iter) {
|
| - BluetoothDevice* device = iter->second;
|
| + BluetoothDeviceChromeOs* device = iter->second;
|
| if (device->IsSupported() || device->IsPaired())
|
| FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
|
| DeviceRemoved(this, device));
|
| @@ -411,22 +401,24 @@ void BluetoothAdapter::ClearDevices() {
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::DeviceCreated(const dbus::ObjectPath& adapter_path,
|
| - const dbus::ObjectPath& device_path) {
|
| +void BluetoothAdapterChromeOs::DeviceCreated(
|
| + const dbus::ObjectPath& adapter_path,
|
| + const dbus::ObjectPath& device_path) {
|
| if (adapter_path != object_path_)
|
| return;
|
|
|
| UpdateDevice(device_path);
|
| }
|
|
|
| -void BluetoothAdapter::DeviceRemoved(const dbus::ObjectPath& adapter_path,
|
| - const dbus::ObjectPath& device_path) {
|
| +void BluetoothAdapterChromeOs::DeviceRemoved(
|
| + const dbus::ObjectPath& adapter_path,
|
| + const dbus::ObjectPath& device_path) {
|
| if (adapter_path != object_path_)
|
| return;
|
|
|
| DevicesMap::iterator iter = devices_.begin();
|
| while (iter != devices_.end()) {
|
| - BluetoothDevice* device = iter->second;
|
| + BluetoothDeviceChromeOs* device = iter->second;
|
| DevicesMap::iterator temp = iter;
|
| ++iter;
|
|
|
| @@ -461,17 +453,17 @@ void BluetoothAdapter::DeviceRemoved(const dbus::ObjectPath& adapter_path,
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::DevicesChanged(
|
| +void BluetoothAdapterChromeOs::DevicesChanged(
|
| const std::vector<dbus::ObjectPath>& devices) {
|
| for (std::vector<dbus::ObjectPath>::const_iterator iter =
|
| devices.begin(); iter != devices.end(); ++iter)
|
| UpdateDevice(*iter);
|
| }
|
|
|
| -void BluetoothAdapter::ClearDiscoveredDevices() {
|
| +void BluetoothAdapterChromeOs::ClearDiscoveredDevices() {
|
| DevicesMap::iterator iter = devices_.begin();
|
| while (iter != devices_.end()) {
|
| - BluetoothDevice* device = iter->second;
|
| + BluetoothDeviceChromeOs* device = iter->second;
|
| DevicesMap::iterator temp = iter;
|
| ++iter;
|
|
|
| @@ -486,8 +478,9 @@ void BluetoothAdapter::ClearDiscoveredDevices() {
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::DeviceFound(
|
| - const dbus::ObjectPath& adapter_path, const std::string& address,
|
| +void BluetoothAdapterChromeOs::DeviceFound(
|
| + const dbus::ObjectPath& adapter_path,
|
| + const std::string& address,
|
| const BluetoothDeviceClient::Properties& properties) {
|
| if (adapter_path != object_path_)
|
| return;
|
| @@ -495,13 +488,13 @@ void BluetoothAdapter::DeviceFound(
|
| // DeviceFound can also be called to indicate that a device we've
|
| // paired with is now visible to the adapter during discovery, in which
|
| // case we want to update the existing object, not create a new one.
|
| - BluetoothDevice* device;
|
| + BluetoothDeviceChromeOs* device;
|
| DevicesMap::iterator iter = devices_.find(address);
|
| const bool update_device = (iter != devices_.end());
|
| if (update_device) {
|
| device = iter->second;
|
| } else {
|
| - device = BluetoothDevice::Create(this);
|
| + device = BluetoothDeviceChromeOs::Create(this);
|
| devices_[address] = device;
|
| }
|
|
|
| @@ -522,8 +515,9 @@ void BluetoothAdapter::DeviceFound(
|
| }
|
| }
|
|
|
| -void BluetoothAdapter::DeviceDisappeared(const dbus::ObjectPath& adapter_path,
|
| - const std::string& address) {
|
| +void BluetoothAdapterChromeOs::DeviceDisappeared(
|
| + const dbus::ObjectPath& adapter_path,
|
| + const std::string& address) {
|
| if (adapter_path != object_path_)
|
| return;
|
|
|
| @@ -531,7 +525,7 @@ void BluetoothAdapter::DeviceDisappeared(const dbus::ObjectPath& adapter_path,
|
| if (iter == devices_.end())
|
| return;
|
|
|
| - BluetoothDevice* device = iter->second;
|
| + BluetoothDeviceChromeOs* device = 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
|
| @@ -556,23 +550,4 @@ void BluetoothAdapter::DeviceDisappeared(const dbus::ObjectPath& adapter_path,
|
| }
|
| }
|
|
|
| -
|
| -// static
|
| -scoped_refptr<BluetoothAdapter> BluetoothAdapter::DefaultAdapter() {
|
| - if (!default_adapter.Get().get()) {
|
| - BluetoothAdapter* new_adapter = new BluetoothAdapter;
|
| - default_adapter.Get() = new_adapter->weak_ptr_factory_.GetWeakPtr();
|
| - default_adapter.Get()->TrackDefaultAdapter();
|
| - }
|
| -
|
| - return scoped_refptr<BluetoothAdapter>(default_adapter.Get());
|
| -}
|
| -
|
| -// static
|
| -BluetoothAdapter* BluetoothAdapter::Create(const std::string& address) {
|
| - BluetoothAdapter* adapter = new BluetoothAdapter;
|
| - adapter->FindAdapter(address);
|
| - return adapter;
|
| -}
|
| -
|
| } // namespace chromeos
|
|
|