summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chromeos/chromeos.gyp42
-rw-r--r--chromeos/dbus/DEPS1
-rw-r--r--chromeos/dbus/bluetooth_adapter_client.cc755
-rw-r--r--chromeos/dbus/bluetooth_adapter_client.h265
-rw-r--r--chromeos/dbus/bluetooth_agent_service_provider.cc573
-rw-r--r--chromeos/dbus/bluetooth_agent_service_provider.h178
-rw-r--r--chromeos/dbus/bluetooth_device_client.cc483
-rw-r--r--chromeos/dbus/bluetooth_device_client.h211
-rw-r--r--chromeos/dbus/bluetooth_input_client.cc301
-rw-r--r--chromeos/dbus/bluetooth_input_client.h113
-rw-r--r--chromeos/dbus/bluetooth_manager_client.cc289
-rw-r--r--chromeos/dbus/bluetooth_manager_client.h100
-rw-r--r--chromeos/dbus/bluetooth_node_client.cc203
-rw-r--r--chromeos/dbus/bluetooth_node_client.h81
-rw-r--r--chromeos/dbus/bluetooth_out_of_band_client.cc203
-rw-r--r--chromeos/dbus/bluetooth_out_of_band_client.h71
-rw-r--r--chromeos/dbus/bluetooth_property.cc66
-rw-r--r--chromeos/dbus/bluetooth_property.h61
-rw-r--r--chromeos/dbus/dbus_thread_manager.cc48
-rw-r--r--chromeos/dbus/dbus_thread_manager.h12
-rw-r--r--chromeos/dbus/experimental_bluetooth_input_client.cc1
-rw-r--r--chromeos/dbus/fake_bluetooth_input_client.cc1
-rw-r--r--chromeos/dbus/fake_old_bluetooth_adapter_client.cc176
-rw-r--r--chromeos/dbus/fake_old_bluetooth_adapter_client.h87
-rw-r--r--chromeos/dbus/fake_old_bluetooth_device_client.cc122
-rw-r--r--chromeos/dbus/fake_old_bluetooth_device_client.h67
-rw-r--r--chromeos/dbus/fake_old_bluetooth_manager_client.cc84
-rw-r--r--chromeos/dbus/fake_old_bluetooth_manager_client.h53
-rw-r--r--chromeos/dbus/mock_bluetooth_adapter_client.cc19
-rw-r--r--chromeos/dbus/mock_bluetooth_adapter_client.h76
-rw-r--r--chromeos/dbus/mock_bluetooth_device_client.cc19
-rw-r--r--chromeos/dbus/mock_bluetooth_device_client.h55
-rw-r--r--chromeos/dbus/mock_bluetooth_input_client.cc19
-rw-r--r--chromeos/dbus/mock_bluetooth_input_client.h47
-rw-r--r--chromeos/dbus/mock_bluetooth_manager_client.cc19
-rw-r--r--chromeos/dbus/mock_bluetooth_manager_client.h45
-rw-r--r--chromeos/dbus/mock_bluetooth_node_client.cc19
-rw-r--r--chromeos/dbus/mock_bluetooth_node_client.h42
-rw-r--r--chromeos/dbus/mock_bluetooth_out_of_band_client.cc13
-rw-r--r--chromeos/dbus/mock_bluetooth_out_of_band_client.h38
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.cc48
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager.h36
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc42
-rw-r--r--chromeos/dbus/mock_dbus_thread_manager_without_gmock.h15
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.cc536
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.h241
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos_unittest.cc2226
-rw-r--r--device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc173
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.cc892
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.h466
-rw-r--r--device/bluetooth/bluetooth_service_record_chromeos.cc178
-rw-r--r--device/bluetooth/bluetooth_service_record_chromeos.h37
-rw-r--r--device/bluetooth/bluetooth_service_record_chromeos_unittest.cc92
-rw-r--r--device/bluetooth/bluetooth_socket_chromeos.cc104
-rw-r--r--device/bluetooth/bluetooth_socket_chromeos.h54
-rw-r--r--device/device.gyp8
56 files changed, 0 insertions, 10206 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index f23e9c9..475f04b 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -62,22 +62,6 @@
'dbus/audio_node.h',
'dbus/blocking_method_caller.cc',
'dbus/blocking_method_caller.h',
- 'dbus/bluetooth_adapter_client.cc',
- 'dbus/bluetooth_adapter_client.h',
- 'dbus/bluetooth_agent_service_provider.cc',
- 'dbus/bluetooth_agent_service_provider.h',
- 'dbus/bluetooth_device_client.cc',
- 'dbus/bluetooth_device_client.h',
- 'dbus/bluetooth_input_client.cc',
- 'dbus/bluetooth_input_client.h',
- 'dbus/bluetooth_manager_client.cc',
- 'dbus/bluetooth_manager_client.h',
- 'dbus/bluetooth_node_client.cc',
- 'dbus/bluetooth_node_client.h',
- 'dbus/bluetooth_out_of_band_client.cc',
- 'dbus/bluetooth_out_of_band_client.h',
- 'dbus/bluetooth_property.cc',
- 'dbus/bluetooth_property.h',
'dbus/cras_audio_client.cc',
'dbus/cras_audio_client.h',
'dbus/cros_disks_client.cc',
@@ -122,12 +106,6 @@
'dbus/fake_gsm_sms_client.h',
'dbus/fake_image_burner_client.cc',
'dbus/fake_image_burner_client.h',
- 'dbus/fake_old_bluetooth_adapter_client.cc',
- 'dbus/fake_old_bluetooth_adapter_client.h',
- 'dbus/fake_old_bluetooth_device_client.cc',
- 'dbus/fake_old_bluetooth_device_client.h',
- 'dbus/fake_old_bluetooth_manager_client.cc',
- 'dbus/fake_old_bluetooth_manager_client.h',
'dbus/fake_system_clock_client.cc',
'dbus/fake_system_clock_client.h',
'dbus/gsm_sms_client.cc',
@@ -360,18 +338,6 @@
'cryptohome/mock_async_method_caller.h',
'cryptohome/mock_cryptohome_library.cc',
'cryptohome/mock_cryptohome_library.h',
- 'dbus/mock_bluetooth_adapter_client.cc',
- 'dbus/mock_bluetooth_adapter_client.h',
- 'dbus/mock_bluetooth_device_client.cc',
- 'dbus/mock_bluetooth_device_client.h',
- 'dbus/mock_bluetooth_input_client.cc',
- 'dbus/mock_bluetooth_input_client.h',
- 'dbus/mock_bluetooth_manager_client.cc',
- 'dbus/mock_bluetooth_manager_client.h',
- 'dbus/mock_bluetooth_node_client.cc',
- 'dbus/mock_bluetooth_node_client.h',
- 'dbus/mock_bluetooth_out_of_band_client.cc',
- 'dbus/mock_bluetooth_out_of_band_client.h',
'dbus/mock_cryptohome_client.cc',
'dbus/mock_cryptohome_client.h',
'dbus/mock_dbus_thread_manager.cc',
@@ -415,8 +381,6 @@
'power_manager_proto',
],
'sources': [
- 'dbus/bluetooth_property.cc',
- 'dbus/bluetooth_property.h',
'dbus/fake_cros_disks_client.cc',
'dbus/fake_cros_disks_client.h',
'dbus/fake_cryptohome_client.cc',
@@ -425,12 +389,6 @@
'dbus/fake_gsm_sms_client.h',
'dbus/fake_image_burner_client.cc',
'dbus/fake_image_burner_client.h',
- 'dbus/fake_old_bluetooth_adapter_client.cc',
- 'dbus/fake_old_bluetooth_adapter_client.h',
- 'dbus/fake_old_bluetooth_device_client.cc',
- 'dbus/fake_old_bluetooth_device_client.h',
- 'dbus/fake_old_bluetooth_manager_client.cc',
- 'dbus/fake_old_bluetooth_manager_client.h',
'dbus/fake_power_manager_client.cc',
'dbus/fake_power_manager_client.h',
'dbus/fake_session_manager_client.cc',
diff --git a/chromeos/dbus/DEPS b/chromeos/dbus/DEPS
index 2b3c5e1..d6abdda 100644
--- a/chromeos/dbus/DEPS
+++ b/chromeos/dbus/DEPS
@@ -1,4 +1,3 @@
include_rules = [
"+dbus",
- "+device/bluetooth/bluetooth_out_of_band_pairing_data.h",
]
diff --git a/chromeos/dbus/bluetooth_adapter_client.cc b/chromeos/dbus/bluetooth_adapter_client.cc
deleted file mode 100644
index aa6e3e9..0000000
--- a/chromeos/dbus/bluetooth_adapter_client.cc
+++ /dev/null
@@ -1,755 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_adapter_client.h"
-
-#include <map>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/stl_util.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_manager_client.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/fake_old_bluetooth_adapter_client.h"
-#include "dbus/bus.h"
-#include "dbus/message.h"
-#include "dbus/object_path.h"
-#include "dbus/object_proxy.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace {
-
-// The |CreatePairedDevice| DBus call needs a longer timeout than the default
-// in order to allow BlueZ to timeout this call first. See crosbug.com/37387.
-const int kCreatePairedDeviceTimeoutMs = 120 * 1000;
-
-} // namespace
-
-namespace chromeos {
-
-const char BluetoothAdapterClient::kNoResponseError[] =
- "org.chromium.Error.NoResponse";
-const char BluetoothAdapterClient::kBadResponseError[] =
- "org.chromium.Error.BadResponse";
-
-BluetoothAdapterClient::Properties::Properties(
- dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback)
- : BluetoothPropertySet(object_proxy,
- bluetooth_adapter::kBluetoothAdapterInterface,
- callback) {
- RegisterProperty(bluetooth_adapter::kAddressProperty, &address);
- RegisterProperty(bluetooth_adapter::kNameProperty, &name);
- RegisterProperty(bluetooth_adapter::kClassProperty, &bluetooth_class);
- RegisterProperty(bluetooth_adapter::kPoweredProperty, &powered);
- RegisterProperty(bluetooth_adapter::kDiscoverableProperty, &discoverable);
- RegisterProperty(bluetooth_adapter::kPairableProperty, &pairable);
- RegisterProperty(bluetooth_adapter::kPairableTimeoutProperty,
- &pairable_timeout);
- RegisterProperty(bluetooth_adapter::kDiscoverableTimeoutProperty,
- &discoverable_timeout);
- RegisterProperty(bluetooth_adapter::kDiscoveringProperty, &discovering);
- RegisterProperty(bluetooth_adapter::kDevicesProperty, &devices);
- RegisterProperty(bluetooth_adapter::kUUIDsProperty, &uuids);
-}
-
-BluetoothAdapterClient::Properties::~Properties() {
-}
-
-
-// The BluetoothAdapterClient implementation used in production.
-class BluetoothAdapterClientImpl: public BluetoothAdapterClient,
- private BluetoothManagerClient::Observer {
- public:
- explicit BluetoothAdapterClientImpl(dbus::Bus* bus,
- BluetoothManagerClient* manager_client)
- : bus_(bus),
- weak_ptr_factory_(this) {
- DCHECK(manager_client);
- manager_client->AddObserver(this);
- }
-
- virtual ~BluetoothAdapterClientImpl() {
- // Clean up Properties structures
- for (ObjectMap::iterator iter = object_map_.begin();
- iter != object_map_.end(); ++iter) {
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
- }
- }
-
- // BluetoothAdapterClient override.
- virtual void AddObserver(BluetoothAdapterClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.AddObserver(observer);
- }
-
- // BluetoothAdapterClient override.
- virtual void RemoveObserver(BluetoothAdapterClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.RemoveObserver(observer);
- }
-
- // BluetoothAdapterClient override.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
- OVERRIDE {
- return GetObject(object_path).second;
- }
-
- // BluetoothAdapterClient override.
- virtual void RequestSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kRequestSession);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnRequestSession,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void ReleaseSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kReleaseSession);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnReleaseSession,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void StartDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kStartDiscovery);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnStartDiscovery,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void StopDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kStopDiscovery);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnStopDiscovery,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void FindDevice(const dbus::ObjectPath& object_path,
- const std::string& address,
- const DeviceCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kFindDevice);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(address);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnFindDevice,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void CreateDevice(const dbus::ObjectPath& object_path,
- const std::string& address,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback)
- OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kCreateDevice);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(address);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethodWithErrorCallback(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnCreateDevice,
- weak_ptr_factory_.GetWeakPtr(), object_path,
- callback, error_callback),
- base::Bind(&BluetoothAdapterClientImpl::OnCreateDeviceError,
- weak_ptr_factory_.GetWeakPtr(), object_path,
- error_callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void CreatePairedDevice(
- const dbus::ObjectPath& object_path, const std::string& address,
- const dbus::ObjectPath& agent_path, const std::string& capability,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kCreatePairedDevice);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(address);
- writer.AppendObjectPath(agent_path);
- writer.AppendString(capability);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethodWithErrorCallback(
- &method_call,
- kCreatePairedDeviceTimeoutMs,
- base::Bind(&BluetoothAdapterClientImpl::OnCreatePairedDevice,
- weak_ptr_factory_.GetWeakPtr(), object_path,
- callback, error_callback),
- base::Bind(&BluetoothAdapterClientImpl::OnCreatePairedDeviceError,
- weak_ptr_factory_.GetWeakPtr(), object_path,
- error_callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void CancelDeviceCreation(const dbus::ObjectPath& object_path,
- const std::string& address,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kCancelDeviceCreation);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(address);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnCancelDeviceCreation,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void RemoveDevice(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& device_path,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kRemoveDevice);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendObjectPath(device_path);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnRemoveDevice,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void RegisterAgent(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const std::string& capability,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kRegisterAgent);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendObjectPath(agent_path);
- writer.AppendString(capability);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnRegisterAgent,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothAdapterClient override.
- virtual void UnregisterAgent(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kUnregisterAgent);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendObjectPath(agent_path);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothAdapterClientImpl::OnUnregisterAgent,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- private:
- // We maintain a collection of dbus object proxies and properties structures
- // for each adapter.
- typedef std::pair<dbus::ObjectProxy*, Properties*> Object;
- typedef std::map<const dbus::ObjectPath, Object> ObjectMap;
- ObjectMap object_map_;
-
- // BluetoothManagerClient::Observer override.
- virtual void AdapterAdded(const dbus::ObjectPath& object_path) OVERRIDE {
- }
-
- // BluetoothManagerClient::Observer override.
- virtual void AdapterRemoved(const dbus::ObjectPath& object_path) OVERRIDE {
- RemoveObject(object_path);
- }
-
- // Ensures that we have an object proxy and properties structure for
- // an adapter with object path |object_path|, creating it if not and
- // storing in our |object_map_| map.
- Object GetObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end())
- return iter->second;
-
- // Create the object proxy.
- DCHECK(bus_);
- dbus::ObjectProxy* object_proxy = bus_->GetObjectProxy(
- bluetooth_adapter::kBluetoothAdapterServiceName, object_path);
-
- object_proxy->ConnectToSignal(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kDeviceCreatedSignal,
- base::Bind(&BluetoothAdapterClientImpl::DeviceCreatedReceived,
- weak_ptr_factory_.GetWeakPtr(), object_path),
- base::Bind(&BluetoothAdapterClientImpl::DeviceCreatedConnected,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- object_proxy->ConnectToSignal(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kDeviceRemovedSignal,
- base::Bind(&BluetoothAdapterClientImpl::DeviceRemovedReceived,
- weak_ptr_factory_.GetWeakPtr(), object_path),
- base::Bind(&BluetoothAdapterClientImpl::DeviceRemovedConnected,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- object_proxy->ConnectToSignal(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kDeviceFoundSignal,
- base::Bind(&BluetoothAdapterClientImpl::DeviceFoundReceived,
- weak_ptr_factory_.GetWeakPtr(), object_path),
- base::Bind(&BluetoothAdapterClientImpl::DeviceFoundConnected,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- object_proxy->ConnectToSignal(
- bluetooth_adapter::kBluetoothAdapterInterface,
- bluetooth_adapter::kDeviceDisappearedSignal,
- base::Bind(&BluetoothAdapterClientImpl::DeviceDisappearedReceived,
- weak_ptr_factory_.GetWeakPtr(), object_path),
- base::Bind(&BluetoothAdapterClientImpl::DeviceDisappearedConnected,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- // Create the properties structure.
- Properties* properties = new Properties(
- object_proxy,
- base::Bind(&BluetoothAdapterClientImpl::OnPropertyChanged,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- properties->ConnectSignals();
- properties->GetAll();
-
- Object object = std::make_pair(object_proxy, properties);
- object_map_[object_path] = object;
- return object;
- }
-
- // Removes the dbus object proxy and properties for the adapter with
- // dbus object path |object_path| from our |object_map_| map.
- void RemoveObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end()) {
- // Clean up the Properties structure.
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
-
- object_map_.erase(iter);
- }
- }
-
- // Returns a pointer to the object proxy for |object_path|, creating
- // it if necessary.
- dbus::ObjectProxy* GetObjectProxy(const dbus::ObjectPath& object_path) {
- return GetObject(object_path).first;
- }
-
- // Called by BluetoothPropertySet when a property value is changed,
- // either by result of a signal or response to a GetAll() or Get()
- // call. Informs observers.
- void OnPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {
- FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
- AdapterPropertyChanged(object_path, property_name));
- }
-
- // Called by dbus:: when a DeviceCreated signal is received.
- void DeviceCreatedReceived(const dbus::ObjectPath& object_path,
- dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- dbus::ObjectPath device_path;
- if (!reader.PopObjectPath(&device_path)) {
- LOG(WARNING) << object_path.value()
- << ": DeviceCreated signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << object_path.value() << ": Device created: "
- << device_path.value();
- FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
- DeviceCreated(object_path, device_path));
- }
-
- // Called by dbus:: when the DeviceCreated signal is initially connected.
- void DeviceCreatedConnected(const dbus::ObjectPath& object_path,
- const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << object_path.value()
- << ": Failed to connect to DeviceCreated signal.";
- }
-
- // Called by dbus:: when a DeviceRemoved signal is received.
- void DeviceRemovedReceived(const dbus::ObjectPath& object_path,
- dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- dbus::ObjectPath device_path;
- if (!reader.PopObjectPath(&device_path)) {
- LOG(WARNING) << object_path.value()
- << ": DeviceRemoved signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << object_path.value() << ": Device removed: "
- << device_path.value();
- FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
- DeviceRemoved(object_path, device_path));
- }
-
- // Called by dbus:: when the DeviceRemoved signal is initially connected.
- void DeviceRemovedConnected(const dbus::ObjectPath& object_path,
- const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << object_path.value()
- << ": Failed to connect to DeviceRemoved signal.";
- }
-
- // Called by dbus:: when a DeviceFound signal is received.
- void DeviceFoundReceived(const dbus::ObjectPath& object_path,
- dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- std::string address;
- if (!reader.PopString(&address)) {
- LOG(WARNING) << object_path.value()
- << ": DeviceFound signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- // Create device properties structure without an attached object_proxy
- // and a NULL callback; value() functions will work on this, but not
- // Get() or Set() calls.
- BluetoothDeviceClient::Properties device_properties(
- NULL, BluetoothDeviceClient::Properties::PropertyChangedCallback());
- if (!device_properties.UpdatePropertiesFromReader(&reader)) {
- LOG(WARNING) << object_path.value()
- << ": DeviceFound signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << object_path.value() << ": Device found: " << address;
- FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
- DeviceFound(object_path, address, device_properties));
- }
-
- // Called by dbus:: when the DeviceFound signal is initially connected.
- void DeviceFoundConnected(const dbus::ObjectPath& object_path,
- const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << object_path.value()
- << ": Failed to connect to DeviceFound signal.";
- }
-
- // Called by dbus:: when a DeviceDisappeared signal is received.
- void DeviceDisappearedReceived(const dbus::ObjectPath& object_path,
- dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- std::string address;
- if (!reader.PopString(&address)) {
- LOG(WARNING) << object_path.value()
- << ": DeviceDisappeared signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << object_path.value() << ": Device disappeared: " << address;
- FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
- DeviceDisappeared(object_path, address));
- }
-
- // Called by dbus:: when the DeviceDisappeared signal is initially connected.
- void DeviceDisappearedConnected(const dbus::ObjectPath& object_path,
- const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success)
- << object_path.value()
- << ": Failed to connect to DeviceDisappeared signal.";
- }
-
- // Called when a response for RequestSession() is received.
- void OnRequestSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnRequestSession: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for ReleaseSession() is received.
- void OnReleaseSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnReleaseSession: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for StartDiscovery() is received.
- void OnStartDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnStartDiscovery: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for StopDiscovery() is received.
- void OnStopDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnStopDiscovery: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for FindDevice() is received.
- void OnFindDevice(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback,
- dbus::Response* response) {
- // Parse response.
- bool success = false;
- dbus::ObjectPath device_path;
- if (response != NULL) {
- dbus::MessageReader reader(response);
- if (!reader.PopObjectPath(&device_path)) {
- LOG(WARNING) << "FindDevice response has incorrect parameters: "
- << response->ToString();
- } else {
- success = true;
- }
- } else {
- LOG(WARNING) << "Failed to find device.";
- }
-
- // Notify client.
- callback.Run(device_path, success);
- }
-
- // Called when a response for CreateDevice() is received.
- void OnCreateDevice(const dbus::ObjectPath& object_path,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback,
- dbus::Response* response) {
- // Parse response.
- DCHECK(response);
- dbus::ObjectPath device_path;
- dbus::MessageReader reader(response);
- if (!reader.PopObjectPath(&device_path)) {
- LOG(WARNING) << "CreateDevice response has incorrect parameters: "
- << response->ToString();
- error_callback.Run(kBadResponseError, "");
- return;
- }
-
- // Notify client.
- callback.Run(device_path);
- }
-
- // Called when an error for CreateDevice() is received.
- void OnCreateDeviceError(const dbus::ObjectPath& object_path,
- const CreateDeviceErrorCallback& error_callback,
- dbus::ErrorResponse* response) {
- // Error response has optional error message argument.
- std::string error_name;
- std::string error_message;
- if (response) {
- dbus::MessageReader reader(response);
- error_name = response->GetErrorName();
- reader.PopString(&error_message);
- } else {
- error_name = kNoResponseError;
- error_message = "";
- }
- error_callback.Run(error_name, error_message);
- }
-
- // Called when a response for CreatePairedDevice() is received.
- void OnCreatePairedDevice(const dbus::ObjectPath& object_path,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback,
- dbus::Response* response) {
- // Parse response.
- DCHECK(response);
- dbus::ObjectPath device_path;
- dbus::MessageReader reader(response);
- if (!reader.PopObjectPath(&device_path)) {
- LOG(WARNING) << "CreatePairedDevice response has incorrect parameters: "
- << response->ToString();
- error_callback.Run(kBadResponseError, "");
- return;
- }
-
- // Notify client.
- callback.Run(device_path);
- }
-
- // Called when an error for CreatePairedDevice() is received.
- void OnCreatePairedDeviceError(
- const dbus::ObjectPath& object_path,
- const CreateDeviceErrorCallback& error_callback,
- dbus::ErrorResponse* response) {
- // Error response has optional error message argument.
- std::string error_name;
- std::string error_message;
- if (response) {
- dbus::MessageReader reader(response);
- error_name = response->GetErrorName();
- reader.PopString(&error_message);
- } else {
- error_name = kNoResponseError;
- error_message = "";
- }
- error_callback.Run(error_name, error_message);
- }
-
- // Called when a response for CancelDeviceCreation() is received.
- void OnCancelDeviceCreation(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnCancelDeviceCreation: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for RemoveDevice() is received.
- void OnRemoveDevice(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnRemoveDevice: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for RegisterAgent() is received.
- void OnRegisterAgent(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnRegisterAgent: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for UnregisterAgent() is received.
- void OnUnregisterAgent(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnUnregisterAgent: failed.";
- callback.Run(object_path, response);
- }
-
- dbus::Bus* bus_;
-
- // List of observers interested in event notifications from us.
- ObserverList<BluetoothAdapterClient::Observer> observers_;
-
- // Weak pointer factory for generating 'this' pointers that might live longer
- // than we do.
- // 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<BluetoothAdapterClientImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClientImpl);
-};
-
-BluetoothAdapterClient::BluetoothAdapterClient() {
-}
-
-BluetoothAdapterClient::~BluetoothAdapterClient() {
-}
-
-BluetoothAdapterClient* BluetoothAdapterClient::Create(
- DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothManagerClient* manager_client) {
- if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
- return new BluetoothAdapterClientImpl(bus, manager_client);
- DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new FakeOldBluetoothAdapterClient();
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_adapter_client.h b/chromeos/dbus/bluetooth_adapter_client.h
deleted file mode 100644
index 1e85c95..0000000
--- a/chromeos/dbus/bluetooth_adapter_client.h
+++ /dev/null
@@ -1,265 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_ADAPTER_CLIENT_H_
-#define CHROMEOS_DBUS_BLUETOOTH_ADAPTER_CLIENT_H_
-
-#include <string>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/observer_list.h"
-#include "base/values.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/dbus_client_implementation_type.h"
-#include "dbus/object_path.h"
-
-namespace dbus {
-class Bus;
-} // namespace dbus
-
-namespace chromeos {
-
-class BluetoothManagerClient;
-
-// BluetoothAdapterClient is used to communicate with a bluetooth Adapter
-// interface.
-class CHROMEOS_EXPORT BluetoothAdapterClient {
- public:
- // Structure of properties associated with bluetooth adapters.
- struct Properties : public BluetoothPropertySet {
- // The Bluetooth device address of the adapter. Read-only.
- dbus::Property<std::string> address;
-
- // The Bluetooth friendly name of the adapter, unlike remote devices,
- // this property can be changed to change the presentation for when
- // the adapter is discoverable.
- dbus::Property<std::string> name;
-
- // The Bluetooth class of the adapter device. Read-only.
- dbus::Property<uint32> bluetooth_class;
-
- // Whether the adapter radio is powered.
- dbus::Property<bool> powered;
-
- // Whether the adapter is discoverable by other Bluetooth devices.
- // |discovering_timeout| is used to automatically disable after a time
- // period.
- dbus::Property<bool> discoverable;
-
- // Whether the adapter accepts incoming pairing requests from other
- // Bluetooth devices. |pairable_timeout| is used to automatically disable
- // after a time period.
- dbus::Property<bool> pairable;
-
- // The timeout in seconds to cease accepting incoming pairing requests
- // after |pairable| is set to true. Zero means adapter remains pairable
- // forever.
- dbus::Property<uint32> pairable_timeout;
-
- // The timeout in seconds to cease the adapter being discoverable by
- // other Bluetooth devices after |discoverable| is set to true. Zero
- // means adapter remains discoverable forever.
- dbus::Property<uint32> discoverable_timeout;
-
- // Indicates that the adapter is discovering other Bluetooth Devices.
- // Read-only. Use StartDiscovery() to begin discovery.
- dbus::Property<bool> discovering;
-
- // List of object paths of known Bluetooth devices, known devices are
- // those that have previously been connected or paired or are currently
- // connected or paired. Read-only.
- dbus::Property<std::vector<dbus::ObjectPath> > devices;
-
- // List of 128-bit UUIDs that represent the available local services.
- // Read-only.
- dbus::Property<std::vector<std::string> > uuids;
-
- Properties(dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback);
- virtual ~Properties();
- };
-
- // Interface for observing changes from a local bluetooth adapter.
- class Observer {
- public:
- virtual ~Observer() {}
-
- // Called when the adapter with object path |object_path| has a
- // change in value of the property named |property_name|.
- virtual void AdapterPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {}
-
- // Called when the adapter with object path |object_path| has a
- // new known device with object path |object_path|.
- virtual void DeviceCreated(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& device_path) {}
-
- // Called when the adapter with object path |object_path| removes
- // the known device with object path |object_path|.
- virtual void DeviceRemoved(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& device_path) {}
-
- // Called when the adapter with object path |object_path| discovers
- // a new remote device with address |address| and properties
- // |properties|, there is no device object path until connected.
- //
- // |properties| supports only value() calls, not Get() or Set(), and
- // should be copied if needed.
- virtual void DeviceFound(
- const dbus::ObjectPath& object_path, const std::string& address,
- const BluetoothDeviceClient::Properties& properties) {}
-
- // Called when the adapter with object path |object_path| can no
- // longer communicate with the discovered removed device with
- // address |address|.
- virtual void DeviceDisappeared(const dbus::ObjectPath& object_path,
- const std::string& address) {}
- };
-
- virtual ~BluetoothAdapterClient();
-
- // Adds and removes observers for events on all local bluetooth
- // adapters. Check the |object_path| parameter of observer methods to
- // determine which adapter is issuing the event.
- virtual void AddObserver(Observer* observer) = 0;
- virtual void RemoveObserver(Observer* observer) = 0;
-
- // Obtain the properties for the adapter with object path |object_path|,
- // any values should be copied if needed.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
-
- // The AdapterCallback is used for adapter methods that only return to
- // indicate success. It receives two arguments, the |object_path| of the
- // adapter the call was made on and |success| which indicates whether
- // or not the request succeeded.
- typedef base::Callback<void(const dbus::ObjectPath&, bool)> AdapterCallback;
-
- // Request a client session for the adapter with object path |object_path|,
- // possible mode changes must be confirmed by the user via a registered
- // agent.
- virtual void RequestSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) = 0;
-
- // Release a previously requested session, restoring the adapter mode to
- // that prior to the original request.
- virtual void ReleaseSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) = 0;
-
- // Starts a device discovery on the adapter with object path |object_path|.
- virtual void StartDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) = 0;
-
- // Cancels any previous device discovery on the adapter with object path
- // |object_path|.
- virtual void StopDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) = 0;
-
- // The DeviceCallback is used for adapter methods that return a dbus
- // object path for a remote device, as well as success. It receives two
- // arguments, the |object_path| of the device returned by the method and
- // |success| which indicates whether or not the request succeeded.
- typedef base::Callback<void(const dbus::ObjectPath&, bool)> DeviceCallback;
-
- // Retrieves the dbus object path from the adapter with object path
- // |object_path| for the known device with the address |address|.
- virtual void FindDevice(const dbus::ObjectPath& object_path,
- const std::string& address,
- const DeviceCallback& callback) = 0;
-
- // The CreateDeviceCallback is used for the CreateDevice and
- // CreatePairedDevice adapter methods that return a dbus object path for
- // a remote device on success. It receives a single argument, the
- // |object_path| of the device returned by the method.
- typedef base::Callback<void(const dbus::ObjectPath&)> CreateDeviceCallback;
-
- // The CreateDeviceErrorCallback is used for the CreateDevice and
- // CreatePairedDevices adapter methods to indicate failure. It receives
- // two arguments, the name of the error in |error_name| and an optional
- // message in |error_message|.
- typedef base::Callback<void(const std::string& error_name,
- const std::string& error_message)>
- CreateDeviceErrorCallback;
-
- // Creates a new dbus object from the adapter with object path |object_path|
- // to the remote device with address |address|, connecting to it and
- // retrieving all SDP records. After a successful call, the device is known
- // and appear's in the adapter's |devices| interface. This is a low-security
- // connection which may not be accepted by the device.
- virtual void CreateDevice(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback) = 0;
-
- // Creates a new dbus object from the adapter with object path |object_path|
- // to the remote device with address |address|, connecting to it, retrieving
- // all SDP records and then initiating a pairing. If CreateDevice() has been
- // previously called for this device, this only initiates the pairing.
- //
- // The dbus object path |agent_path| of an agent within the local process
- // must be specified to negotiate the pairing, |capability| specifies the
- // input and display capabilities of that agent and should be one of the
- // constants declared in the bluetooth_agent:: namespace.
- virtual void CreatePairedDevice(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const dbus::ObjectPath& agent_path,
- const std::string& capability,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback) = 0;
-
- // Cancels the currently in progress call to CreateDevice() or
- // CreatePairedDevice() on the adapter with object path |object_path|
- // for the remote device with address |address|.
- virtual void CancelDeviceCreation(const dbus::ObjectPath& object_path,
- const std::string& address,
- const AdapterCallback& callback) = 0;
-
- // Removes from the adapter with object path |object_path| the remote
- // device with object path |object_path| from the list of known devices
- // and discards any pairing information.
- virtual void RemoveDevice(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& device_path,
- const AdapterCallback& callback) = 0;
-
- // Registers an adapter-wide agent for the adapter with object path
- // |object_path|. This agent is used for incoming pairing connections
- // and confirmation of adapter mode changes. The dbus object path
- // |agent_path| of an agent within the local process must be specified,
- // |capability| specifies the input and display capabilities of that
- // agent and should be one of the constants declared in the
- // bluetooth_agent:: namespace.
- virtual void RegisterAgent(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const std::string& capability,
- const AdapterCallback& callback) = 0;
-
- // Unregisters an adapter-wide agent with object path |agent_path| from
- // the adapter with object path |object_path|.
- virtual void UnregisterAgent(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const AdapterCallback& callback) = 0;
-
- // Creates the instance.
- static BluetoothAdapterClient* Create(DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothManagerClient* manager_client);
-
- // Constants used to indicate exceptional error conditions.
- static const char kNoResponseError[];
- static const char kBadResponseError[];
-
- protected:
- BluetoothAdapterClient();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_ADAPTER_CLIENT_H_
diff --git a/chromeos/dbus/bluetooth_agent_service_provider.cc b/chromeos/dbus/bluetooth_agent_service_provider.cc
deleted file mode 100644
index 786935c..0000000
--- a/chromeos/dbus/bluetooth_agent_service_provider.cc
+++ /dev/null
@@ -1,573 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_agent_service_provider.h"
-
-#include <string>
-
-#include "base/bind.h"
-#include "base/chromeos/chromeos_version.h"
-#include "base/logging.h"
-#include "base/memory/ref_counted.h"
-#include "base/threading/platform_thread.h"
-#include "dbus/bus.h"
-#include "dbus/exported_object.h"
-#include "dbus/message.h"
-#include "dbus/object_path.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace {
-
-// Constants used by BlueZ for the ConfirmModeChange method.
-const char kModeOff[] = "off";
-const char kModeConnectable[] = "connectable";
-const char kModeDiscoverable[] = "discoverable";
-
-} // namespace
-
-namespace chromeos {
-
-// The BluetoothAgentServiceProvider implementation used in production.
-class BluetoothAgentServiceProviderImpl : public BluetoothAgentServiceProvider {
- public:
- BluetoothAgentServiceProviderImpl(dbus::Bus* bus,
- const dbus::ObjectPath& object_path,
- Delegate* delegate)
- : origin_thread_id_(base::PlatformThread::CurrentId()),
- bus_(bus),
- delegate_(delegate),
- object_path_(object_path),
- weak_ptr_factory_(this) {
- VLOG(1) << "Creating BluetoothAdapterClientImpl for "
- << object_path.value();
-
- exported_object_ = bus_->GetExportedObject(object_path_);
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kRelease,
- base::Bind(&BluetoothAgentServiceProviderImpl::Release,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAgentServiceProviderImpl::ReleaseExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kRequestPinCode,
- base::Bind(&BluetoothAgentServiceProviderImpl::RequestPinCode,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAgentServiceProviderImpl::RequestPinCodeExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kRequestPasskey,
- base::Bind(&BluetoothAgentServiceProviderImpl::RequestPasskey,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAgentServiceProviderImpl::RequestPasskeyExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kDisplayPinCode,
- base::Bind(&BluetoothAgentServiceProviderImpl::DisplayPinCode,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAgentServiceProviderImpl::DisplayPinCodeExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kDisplayPasskey,
- base::Bind(&BluetoothAgentServiceProviderImpl::DisplayPasskey,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAgentServiceProviderImpl::DisplayPasskeyExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kRequestConfirmation,
- base::Bind(&BluetoothAgentServiceProviderImpl::RequestConfirmation,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(
- &BluetoothAgentServiceProviderImpl::RequestConfirmationExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kAuthorize,
- base::Bind(&BluetoothAgentServiceProviderImpl::Authorize,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAgentServiceProviderImpl::AuthorizeExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kConfirmModeChange,
- base::Bind(&BluetoothAgentServiceProviderImpl::ConfirmModeChange,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(
- &BluetoothAgentServiceProviderImpl::ConfirmModeChangeExported,
- weak_ptr_factory_.GetWeakPtr()));
-
- exported_object_->ExportMethod(
- bluetooth_agent::kBluetoothAgentInterface,
- bluetooth_agent::kCancel,
- base::Bind(&BluetoothAgentServiceProviderImpl::Cancel,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothAgentServiceProviderImpl::CancelExported,
- weak_ptr_factory_.GetWeakPtr()));
- }
-
- virtual ~BluetoothAgentServiceProviderImpl() {
- // Unregister the object path so we can reuse with a new agent.
- bus_->UnregisterExportedObject(object_path_);
- }
-
- private:
- // Returns true if the current thread is on the origin thread.
- bool OnOriginThread() {
- return base::PlatformThread::CurrentId() == origin_thread_id_;
- }
-
- // Called by dbus:: when the agent is unregistered from the Bluetooth
- // daemon, generally at the end of a pairing request.
- void Release(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- delegate_->Release();
-
- response_sender.Run(dbus::Response::FromMethodCall(method_call));
- }
-
- // Called by dbus:: when the Release method is exported.
- void ReleaseExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the Bluetooth daemon requires a PIN Code for
- // device authentication.
- void RequestPinCode(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- dbus::MessageReader reader(method_call);
- dbus::ObjectPath device_path;
- if (!reader.PopObjectPath(&device_path)) {
- LOG(WARNING) << "RequestPinCode called with incorrect paramters: "
- << method_call->ToString();
- return;
- }
-
- Delegate::PinCodeCallback callback = base::Bind(
- &BluetoothAgentServiceProviderImpl::OnPinCode,
- weak_ptr_factory_.GetWeakPtr(),
- method_call,
- response_sender);
-
- delegate_->RequestPinCode(device_path, callback);
- }
-
- // Called by dbus:: when the RequestPinCode method is exported.
- void RequestPinCodeExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the Bluetooth daemon requires a Passkey for
- // device authentication.
- void RequestPasskey(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- dbus::MessageReader reader(method_call);
- dbus::ObjectPath device_path;
- if (!reader.PopObjectPath(&device_path)) {
- LOG(WARNING) << "RequestPasskey called with incorrect paramters: "
- << method_call->ToString();
- return;
- }
-
- Delegate::PasskeyCallback callback = base::Bind(
- &BluetoothAgentServiceProviderImpl::OnPasskey,
- weak_ptr_factory_.GetWeakPtr(),
- method_call,
- response_sender);
-
- delegate_->RequestPasskey(device_path, callback);
- }
-
- // Called by dbus:: when the RequestPasskey method is exported.
- void RequestPasskeyExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the Bluetooth daemon requires that the user
- // enter a PIN Code into the remote device so that it may be
- // authenticated.
- void DisplayPinCode(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- dbus::MessageReader reader(method_call);
- dbus::ObjectPath device_path;
- std::string pincode;
- if (!reader.PopObjectPath(&device_path) ||
- !reader.PopString(&pincode)) {
- LOG(WARNING) << "DisplayPinCode called with incorrect paramters: "
- << method_call->ToString();
- return;
- }
-
- delegate_->DisplayPinCode(device_path, pincode);
-
- response_sender.Run(dbus::Response::FromMethodCall(method_call));
- }
-
- // Called by dbus:: when the DisplayPinCode method is exported.
- void DisplayPinCodeExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the Bluetooth daemon requires that the user
- // enter a Passkey into the remote device so that it may be
- // authenticated.
- void DisplayPasskey(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- dbus::MessageReader reader(method_call);
- dbus::ObjectPath device_path;
- uint32 passkey;
- if (!reader.PopObjectPath(&device_path) ||
- !reader.PopUint32(&passkey)) {
- LOG(WARNING) << "DisplayPasskey called with incorrect paramters: "
- << method_call->ToString();
- return;
- }
-
- delegate_->DisplayPasskey(device_path, passkey);
-
- response_sender.Run(dbus::Response::FromMethodCall(method_call));
- }
-
- // Called by dbus:: when the DisplayPasskey method is exported.
- void DisplayPasskeyExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the Bluetooth daemon requires that the user
- // confirm that a Passkey is displayed on the screen of the remote
- // device so that it may be authenticated.
- void RequestConfirmation(
- dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- dbus::MessageReader reader(method_call);
- dbus::ObjectPath device_path;
- uint32 passkey;
- if (!reader.PopObjectPath(&device_path) ||
- !reader.PopUint32(&passkey)) {
- LOG(WARNING) << "RequestConfirmation called with incorrect paramters: "
- << method_call->ToString();
- return;
- }
-
- Delegate::ConfirmationCallback callback = base::Bind(
- &BluetoothAgentServiceProviderImpl::OnConfirmation,
- weak_ptr_factory_.GetWeakPtr(),
- method_call,
- response_sender);
-
- delegate_->RequestConfirmation(device_path, passkey, callback);
- }
-
- // Called by dbus:: when the RequestConfirmation method is exported.
- void RequestConfirmationExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the Bluetooth daemon requires that the user
- // confirm that that a remote device is authorized to connect to a service
- // UUID.
- void Authorize(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- dbus::MessageReader reader(method_call);
- dbus::ObjectPath device_path;
- std::string uuid;
- if (!reader.PopObjectPath(&device_path) ||
- !reader.PopString(&uuid)) {
- LOG(WARNING) << "Authorize called with incorrect paramters: "
- << method_call->ToString();
- return;
- }
-
- Delegate::ConfirmationCallback callback = base::Bind(
- &BluetoothAgentServiceProviderImpl::OnConfirmation,
- weak_ptr_factory_.GetWeakPtr(),
- method_call,
- response_sender);
-
- delegate_->Authorize(device_path, uuid, callback);
- }
-
- // Called by dbus:: when the Authorize method is exported.
- void AuthorizeExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the Bluetooth daemon requires that the user
- // confirm that the adapter may change mode.
- void ConfirmModeChange(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- dbus::MessageReader reader(method_call);
- std::string mode_str;
- if (!reader.PopString(&mode_str)) {
- LOG(WARNING) << "ConfirmModeChange called with incorrect paramters: "
- << method_call->ToString();
- return;
- }
-
- Delegate::Mode mode;
- if (mode_str == kModeOff) {
- mode = Delegate::OFF;
- } else if (mode_str == kModeConnectable) {
- mode = Delegate::CONNECTABLE;
- } else if (mode_str == kModeDiscoverable) {
- mode = Delegate::DISCOVERABLE;
- } else {
- LOG(WARNING) << "ConfirmModeChange called with unknown mode: "
- << mode_str;
- return;
- }
-
- Delegate::ConfirmationCallback callback = base::Bind(
- &BluetoothAgentServiceProviderImpl::OnConfirmation,
- weak_ptr_factory_.GetWeakPtr(),
- method_call,
- response_sender);
-
- delegate_->ConfirmModeChange(mode, callback);
- }
-
- // Called by dbus:: when the ConfirmModeChange method is exported.
- void ConfirmModeChangeExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by dbus:: when the request failed before a reply was returned
- // from the device.
- void Cancel(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender) {
- DCHECK(OnOriginThread());
- DCHECK(delegate_);
-
- delegate_->Cancel();
-
- response_sender.Run(dbus::Response::FromMethodCall(method_call));
- }
-
- // Called by dbus:: when the Cancel method is exported.
- void CancelExported(const std::string& interface_name,
- const std::string& method_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to export "
- << interface_name << "." << method_name;
- }
-
- // Called by the Delegate to response to a method requesting a PIN code.
- void OnPinCode(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender,
- Delegate::Status status,
- const std::string& pincode) {
- DCHECK(OnOriginThread());
-
- switch (status) {
- case Delegate::SUCCESS: {
- scoped_ptr<dbus::Response> response(
- dbus::Response::FromMethodCall(method_call));
- dbus::MessageWriter writer(response.get());
- writer.AppendString(pincode);
- response_sender.Run(response.Pass());
- break;
- }
- case Delegate::REJECTED: {
- response_sender.Run(
- dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorRejected, "rejected")
- .PassAs<dbus::Response>());
- break;
- }
- case Delegate::CANCELLED: {
- response_sender.Run(
- dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorCanceled, "canceled")
- .PassAs<dbus::Response>());
- break;
- }
- default:
- NOTREACHED() << "Unexpected status code from delegate: " << status;
- }
- }
-
- // Called by the Delegate to response to a method requesting a Passkey.
- void OnPasskey(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender,
- Delegate::Status status,
- uint32 passkey) {
- DCHECK(OnOriginThread());
-
- switch (status) {
- case Delegate::SUCCESS: {
- scoped_ptr<dbus::Response> response(
- dbus::Response::FromMethodCall(method_call));
- dbus::MessageWriter writer(response.get());
- writer.AppendUint32(passkey);
- response_sender.Run(response.Pass());
- break;
- }
- case Delegate::REJECTED: {
- response_sender.Run(
- dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorRejected, "rejected")
- .PassAs<dbus::Response>());
- break;
- }
- case Delegate::CANCELLED: {
- response_sender.Run(
- dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorCanceled, "canceled")
- .PassAs<dbus::Response>());
- break;
- }
- default:
- NOTREACHED() << "Unexpected status code from delegate: " << status;
- }
- }
-
- // Called by the Delegate in response to a method requiring confirmation.
- void OnConfirmation(dbus::MethodCall* method_call,
- dbus::ExportedObject::ResponseSender response_sender,
- Delegate::Status status) {
- DCHECK(OnOriginThread());
-
- switch (status) {
- case Delegate::SUCCESS: {
- response_sender.Run(dbus::Response::FromMethodCall(method_call));
- break;
- }
- case Delegate::REJECTED: {
- response_sender.Run(
- dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorRejected, "rejected")
- .PassAs<dbus::Response>());
- break;
- }
- case Delegate::CANCELLED: {
- response_sender.Run(
- dbus::ErrorResponse::FromMethodCall(
- method_call, bluetooth_agent::kErrorCanceled, "canceled")
- .PassAs<dbus::Response>());
- break;
- }
- default:
- NOTREACHED() << "Unexpected status code from delegate: " << status;
- }
- }
-
- // Origin thread (i.e. the UI thread in production).
- base::PlatformThreadId origin_thread_id_;
-
- // D-Bus bus object is exported on, not owned by this object and must
- // outlive it.
- dbus::Bus* bus_;
-
- // All incoming method calls are passed on to the Delegate and a callback
- // passed to generate the reply. |delegate_| is generally the object that
- // owns this one, and must outlive it.
- Delegate* delegate_;
-
- // D-Bus object path of object we are exporting, kept so we can unregister
- // again in our destructor.
- dbus::ObjectPath object_path_;
-
- // D-Bus object we are exporting, owned by this object.
- scoped_refptr<dbus::ExportedObject> exported_object_;
-
- // Weak pointer factory for generating 'this' pointers that might live longer
- // than we do.
- // 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<BluetoothAgentServiceProviderImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothAgentServiceProviderImpl);
-};
-
-// The BluetoothAgentServiceProvider implementation used on Linux desktop,
-// which does nothing.
-class BluetoothAgentServiceProviderStubImpl
- : public BluetoothAgentServiceProvider {
- public:
- explicit BluetoothAgentServiceProviderStubImpl(Delegate* delegate_) {
- }
-
- virtual ~BluetoothAgentServiceProviderStubImpl() {
- }
-};
-
-BluetoothAgentServiceProvider::BluetoothAgentServiceProvider() {
-}
-
-BluetoothAgentServiceProvider::~BluetoothAgentServiceProvider() {
-}
-
-// static
-BluetoothAgentServiceProvider* BluetoothAgentServiceProvider::Create(
- dbus::Bus* bus,
- const dbus::ObjectPath& object_path,
- Delegate* delegate) {
- if (base::chromeos::IsRunningOnChromeOS()) {
- return new BluetoothAgentServiceProviderImpl(bus, object_path, delegate);
- } else {
- return new BluetoothAgentServiceProviderStubImpl(delegate);
- }
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_agent_service_provider.h b/chromeos/dbus/bluetooth_agent_service_provider.h
deleted file mode 100644
index fbf4dac..0000000
--- a/chromeos/dbus/bluetooth_agent_service_provider.h
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_
-#define CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/callback.h"
-#include "chromeos/chromeos_export.h"
-#include "dbus/bus.h"
-#include "dbus/object_path.h"
-
-namespace chromeos {
-
-// BluetoothAgentServiceProvider is used to provide a D-Bus object that BlueZ
-// can communicate with during a remote device pairing request.
-//
-// Instantiate with a chosen D-Bus object path and delegate object, and pass
-// the D-Bus object path as the |agent_path| argument to the
-// chromeos::BluetoothAdapterClient::CreatePairedDevice() method. Calls made
-// to the agent by the Bluetooth daemon will be passed on to your Delegate
-// object for handling, and responses returned using the callbacks supplied
-// to those methods.
-class CHROMEOS_EXPORT BluetoothAgentServiceProvider {
- public:
- // Interface for reacting to agent requests.
- class Delegate {
- public:
- virtual ~Delegate() {}
-
- // Possible status values that may be returned to callbacks. Success
- // indicates that a pincode or passkey has been obtained, or permission
- // granted; rejected indicates the user rejected the request or denied
- // permission; cancelled indicates the user cancelled the request
- // without confirming either way.
- enum Status {
- SUCCESS,
- REJECTED,
- CANCELLED
- };
-
- // Possible values for the |mode| parameter of the ConfirmModeChange()
- // method. Off indicates that the adapter is to be turned off, connectable
- // indicates that the adapter is to be turned on and accept incoming
- // connections, and discoverable indicates the adapter is to be turned
- // on and discoverable by remote devices.
- enum Mode {
- OFF,
- CONNECTABLE,
- DISCOVERABLE
- };
-
- // The PinCodeCallback is used for the RequestPinCode() method, it should
- // be called with two arguments, the |status| of the request (success,
- // rejected or cancelled) and the |pincode| requested.
- typedef base::Callback<void(Status, const std::string&)> PinCodeCallback;
-
- // The PasskeyCallback is used for the RequestPasskey() method, it should
- // be called with two arguments, the |status| of the request (success,
- // rejected or cancelled) and the |passkey| requested, a numeric in the
- // range 0-999999,
- typedef base::Callback<void(Status, uint32)> PasskeyCallback;
-
- // The ConfirmationCallback is used for methods which request confirmation
- // or authorization, it should be called with one argument, the |status|
- // of the request (success, rejected or cancelled).
- typedef base::Callback<void(Status)> ConfirmationCallback;
-
- // This method will be called when the agent is unregistered from the
- // Bluetooth daemon, generally at the end of a pairing request. It may be
- // used to perform cleanup tasks.
- virtual void Release() = 0;
-
- // This method will be called when the Bluetooth daemon requires a
- // PIN Code for authentication of the device with object path |device_path|,
- // the agent should obtain the code from the user and call |callback|
- // to provide it, or indicate rejection or cancellation of the request.
- //
- // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
- // for which there is no automatic pairing or special handling.
- virtual void RequestPinCode(const dbus::ObjectPath& device_path,
- const PinCodeCallback& callback) = 0;
-
- // This method will be called when the Bluetooth daemon requires a
- // Passkey for authentication of the device with object path |device_path|,
- // the agent should obtain the passkey from the user (a numeric in the
- // range 0-999999) and call |callback| to provide it, or indicate
- // rejection or cancellation of the request.
- //
- // Passkeys are generally required for Bluetooth 2.1 and later devices
- // which cannot provide input or display on their own, and don't accept
- // passkey-less pairing.
- virtual void RequestPasskey(const dbus::ObjectPath& device_path,
- const PasskeyCallback& callback) = 0;
-
- // This method will be called when the Bluetooth daemon requires that the
- // user enter the PIN code |pincode| into the device with object path
- // |device_path| so that it may be authenticated. The Cancel() method
- // will be called to dismiss the display once pairing is complete or
- // cancelled.
- //
- // This is used for Bluetooth 2.0 and earlier keyboard devices, the
- // |pincode| will always be a six-digit numeric in the range 000000-999999
- // for compatibilty with later specifications.
- virtual void DisplayPinCode(const dbus::ObjectPath& device_path,
- const std::string& pincode) = 0;
-
- // This method will be called when the Bluetooth daemon requires that the
- // user enter the Passkey |passkey| into the device with object path
- // |device_path| so that it may be authenticated. The Cancel() method
- // will be called to dismiss the display once pairing is complete or
- // cancelled.
- //
- // This is used for Bluetooth 2.1 and later devices that support input
- // but not display, such as keyboards. The Passkey is a numeric in the
- // range 0-999999 and should be always presented zero-padded to six
- // digits.
- virtual void DisplayPasskey(const dbus::ObjectPath& device_path,
- uint32 passkey) = 0;
-
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the Passkey |passkey| is displayed on the screen
- // of the device with object path |object_path| so that it may be
- // authenticated. The agent should display to the user and ask for
- // confirmation, then call |callback| to provide their response (success,
- // rejected or cancelled).
- //
- // This is used for Bluetooth 2.1 and later devices that support display,
- // such as other computers or phones. The Passkey is a numeric in the
- // range 0-999999 and should be always present zero-padded to six
- // digits.
- virtual void RequestConfirmation(const dbus::ObjectPath& device_path,
- uint32 passkey,
- const ConfirmationCallback& callback) = 0;
-
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the device with object path |object_path| is
- // authorized to connect to the service with UUID |uuid|. The agent should
- // confirm with the user and call |callback| to provide their response
- // (success, rejected or cancelled).
- virtual void Authorize(const dbus::ObjectPath& device_path,
- const std::string& uuid,
- const ConfirmationCallback& callback) = 0;
-
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the device adapter may switch to mode |mode|. The
- // agent should confirm with the user and call |callback| to provide
- // their response (success, rejected or cancelled).
- virtual void ConfirmModeChange(Mode mode,
- const ConfirmationCallback& callback) = 0;
-
- // This method will be called by the Bluetooth daemon to indicate that
- // the request failed before a reply was returned from the device.
- virtual void Cancel() = 0;
- };
-
- virtual ~BluetoothAgentServiceProvider();
-
- // Creates the instance where |bus| is the D-Bus bus connection to export
- // the object onto, |object_path| is the object path that it should have
- // and |delegate| is the object to which all method calls will be passed
- // and responses generated from.
- static BluetoothAgentServiceProvider* Create(
- dbus::Bus* bus, const dbus::ObjectPath& object_path, Delegate* delegate);
-
- protected:
- BluetoothAgentServiceProvider();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BluetoothAgentServiceProvider);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_AGENT_SERVICE_PROVIDER_H_
diff --git a/chromeos/dbus/bluetooth_device_client.cc b/chromeos/dbus/bluetooth_device_client.cc
deleted file mode 100644
index 69f8072..0000000
--- a/chromeos/dbus/bluetooth_device_client.cc
+++ /dev/null
@@ -1,483 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_device_client.h"
-
-#include <map>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/fake_old_bluetooth_device_client.h"
-#include "dbus/bus.h"
-#include "dbus/message.h"
-#include "dbus/object_path.h"
-#include "dbus/object_proxy.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-BluetoothDeviceClient::Properties::Properties(
- dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback)
- : BluetoothPropertySet(object_proxy,
- bluetooth_device::kBluetoothDeviceInterface,
- callback) {
- RegisterProperty(bluetooth_device::kAddressProperty, &address);
- RegisterProperty(bluetooth_device::kNameProperty, &name);
- RegisterProperty(bluetooth_device::kVendorProperty, &vendor);
- RegisterProperty(bluetooth_device::kProductProperty, &product);
- RegisterProperty(bluetooth_device::kVersionProperty, &version);
- RegisterProperty(bluetooth_device::kIconProperty, &icon);
- RegisterProperty(bluetooth_device::kClassProperty, &bluetooth_class);
- RegisterProperty(bluetooth_device::kUUIDsProperty, &uuids);
- RegisterProperty(bluetooth_device::kServicesProperty, &services);
- RegisterProperty(bluetooth_device::kPairedProperty, &paired);
- RegisterProperty(bluetooth_device::kConnectedProperty, &connected);
- RegisterProperty(bluetooth_device::kTrustedProperty, &trusted);
- RegisterProperty(bluetooth_device::kBlockedProperty, &blocked);
- RegisterProperty(bluetooth_device::kAliasProperty, &alias);
- RegisterProperty(bluetooth_device::kNodesProperty, &nodes);
- RegisterProperty(bluetooth_device::kAdapterProperty, &adapter);
- RegisterProperty(bluetooth_device::kLegacyPairingProperty, &legacy_pairing);
-}
-
-BluetoothDeviceClient::Properties::~Properties() {
-}
-
-
-// The BluetoothDeviceClient implementation used in production.
-class BluetoothDeviceClientImpl: public BluetoothDeviceClient,
- private BluetoothAdapterClient::Observer {
- public:
- BluetoothDeviceClientImpl(dbus::Bus* bus,
- BluetoothAdapterClient* adapter_client)
- : bus_(bus),
- weak_ptr_factory_(this) {
- VLOG(1) << "Creating BluetoothDeviceClientImpl";
-
- DCHECK(adapter_client);
- adapter_client->AddObserver(this);
- }
-
- virtual ~BluetoothDeviceClientImpl() {
- // Clean up Properties structures
- for (ObjectMap::iterator iter = object_map_.begin();
- iter != object_map_.end(); ++iter) {
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
- }
- }
-
- // BluetoothDeviceClient override.
- virtual void AddObserver(BluetoothDeviceClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.AddObserver(observer);
- }
-
- // BluetoothDeviceClient override.
- virtual void RemoveObserver(BluetoothDeviceClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.RemoveObserver(observer);
- }
-
- // BluetoothDeviceClient override.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
- OVERRIDE {
- return GetObject(object_path).second;
- }
-
- // BluetoothDeviceClient override.
- virtual void DiscoverServices(const dbus::ObjectPath& object_path,
- const std::string& pattern,
- const ServicesCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kDiscoverServices);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(pattern);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothDeviceClientImpl::OnDiscoverServices,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothDeviceClient override.
- virtual void CancelDiscovery(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kCancelDiscovery);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothDeviceClientImpl::OnCancelDiscovery,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothDeviceClient override.
- virtual void Disconnect(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kDisconnect);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothDeviceClientImpl::OnDisconnect,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothDeviceClient override.
- virtual void CreateNode(const dbus::ObjectPath& object_path,
- const std::string& uuid,
- const NodeCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kCreateNode);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(uuid);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothDeviceClientImpl::OnCreateNode,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- // BluetoothDeviceClient override.
- virtual void RemoveNode(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& node_path,
- const DeviceCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kRemoveNode);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendObjectPath(node_path);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothDeviceClientImpl::OnRemoveNode,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- private:
- // We maintain a collection of dbus object proxies and properties structures
- // for each device.
- typedef std::pair<dbus::ObjectProxy*, Properties*> Object;
- typedef std::map<const dbus::ObjectPath, Object> ObjectMap;
- ObjectMap object_map_;
-
- // BluetoothAdapterClient::Observer override.
- virtual void DeviceCreated(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& object_path) OVERRIDE {
- }
-
- // BluetoothAdapterClient::Observer override.
- virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& object_path) OVERRIDE {
- RemoveObject(object_path);
- }
-
- // Ensures that we have an object proxy and properties structure for
- // a device with object path |object_path|, creating it if not and
- // storing it in our |object_map_| map.
- Object GetObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end())
- return iter->second;
-
- // Create the object proxy.
- DCHECK(bus_);
- dbus::ObjectProxy* object_proxy = bus_->GetObjectProxy(
- bluetooth_device::kBluetoothDeviceServiceName, object_path);
-
- object_proxy->ConnectToSignal(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kDisconnectRequestedSignal,
- base::Bind(&BluetoothDeviceClientImpl::DisconnectRequestedReceived,
- weak_ptr_factory_.GetWeakPtr(), object_path),
- base::Bind(&BluetoothDeviceClientImpl::DisconnectRequestedConnected,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- object_proxy->ConnectToSignal(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kNodeCreatedSignal,
- base::Bind(&BluetoothDeviceClientImpl::NodeCreatedReceived,
- weak_ptr_factory_.GetWeakPtr(), object_path),
- base::Bind(&BluetoothDeviceClientImpl::NodeCreatedConnected,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- object_proxy->ConnectToSignal(
- bluetooth_device::kBluetoothDeviceInterface,
- bluetooth_device::kNodeRemovedSignal,
- base::Bind(&BluetoothDeviceClientImpl::NodeRemovedReceived,
- weak_ptr_factory_.GetWeakPtr(), object_path),
- base::Bind(&BluetoothDeviceClientImpl::NodeRemovedConnected,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- // Create the properties structure.
- Properties* properties = new Properties(
- object_proxy,
- base::Bind(&BluetoothDeviceClientImpl::OnPropertyChanged,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- properties->ConnectSignals();
- properties->GetAll();
-
- Object object = std::make_pair(object_proxy, properties);
- object_map_[object_path] = object;
- return object;
- }
-
- // Removes the dbus object proxy and properties for the device with
- // dbus object path |object_path| from our |object_map_| map.
- void RemoveObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end()) {
- // Clean up the Properties structure.
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
-
- object_map_.erase(iter);
- }
- }
-
- // Returns a pointer to the object proxy for |object_path|, creating
- // it if necessary.
- dbus::ObjectProxy* GetObjectProxy(const dbus::ObjectPath& object_path) {
- return GetObject(object_path).first;
- }
-
- // Called by BluetoothPropertySet when a property value is changed,
- // either by result of a signal or response to a GetAll() or Get()
- // call. Informs observers.
- void OnPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- DevicePropertyChanged(object_path, property_name));
- }
-
- // Called by dbus:: when a DisconnectRequested signal is received.
- void DisconnectRequestedReceived(const dbus::ObjectPath& object_path,
- dbus::Signal* signal) {
- DCHECK(signal);
-
- VLOG(1) << object_path.value() << ": Disconnect requested.";
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- DisconnectRequested(object_path));
- }
-
- // Called by dbus:: when the DisconnectRequested signal is initially
- // connected.
- void DisconnectRequestedConnected(const dbus::ObjectPath& object_path,
- const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << object_path.value()
- << ": Failed to connect to "
- "DisconnectRequested signal.";
- }
-
- // Called by dbus:: when a NodeCreated signal is received.
- void NodeCreatedReceived(const dbus::ObjectPath& object_path,
- dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- dbus::ObjectPath node_path;
- if (!reader.PopObjectPath(&node_path)) {
- LOG(WARNING) << object_path.value()
- << ": NodeCreated signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << object_path.value() << ": Node created: "
- << node_path.value();
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- NodeCreated(object_path, node_path));
- }
-
- // Called by dbus:: when the NodeCreated signal is initially connected.
- void NodeCreatedConnected(const dbus::ObjectPath& object_path,
- const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << object_path.value()
- << ": Failed to connect to NodeCreated signal.";
- }
-
- // Called by dbus:: when a NodeRemoved signal is received.
- void NodeRemovedReceived(const dbus::ObjectPath& object_path,
- dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- dbus::ObjectPath node_path;
- if (!reader.PopObjectPath(&node_path)) {
- LOG(WARNING) << object_path.value()
- << ": NodeRemoved signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << object_path.value() << ": Node removed: "
- << node_path.value();
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- NodeRemoved(object_path, node_path));
- }
-
- // Called by dbus:: when the NodeRemoved signal is initially connected.
- void NodeRemovedConnected(const dbus::ObjectPath& object_path,
- const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << object_path.value()
- << ": Failed to connect to NodeRemoved signal.";
- }
-
- // Called when a response for DiscoverServices() is received.
- void OnDiscoverServices(const dbus::ObjectPath& object_path,
- const ServicesCallback& callback,
- dbus::Response* response) {
- // Parse response.
- bool success = false;
- ServiceMap services;
- if (response != NULL) {
- dbus::MessageReader reader(response);
-
- dbus::MessageReader array_reader(NULL);
- if (!reader.PopArray(&array_reader)) {
- LOG(WARNING) << "DiscoverServices response has incorrect parameters: "
- << response->ToString();
- } else {
- while (array_reader.HasMoreData()) {
- dbus::MessageReader dict_entry_reader(NULL);
- uint32 key = 0;
- std::string value;
- if (!array_reader.PopDictEntry(&dict_entry_reader)
- || !dict_entry_reader.PopUint32(&key)
- || !dict_entry_reader.PopString(&value)) {
- LOG(WARNING) << "DiscoverServices response has "
- "incorrect parameters: " << response->ToString();
- } else {
- services[key] = value;
- }
- }
-
- success = true;
- }
- } else {
- LOG(WARNING) << "Failed to discover services.";
- }
-
- // Notify client.
- callback.Run(object_path, services, success);
- }
-
- // Called when a response for CancelDiscovery() is received.
- void OnCancelDiscovery(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnCancelDiscovery: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for Disconnect() is received.
- void OnDisconnect(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnDisconnect: failed.";
- callback.Run(object_path, response);
- }
-
- // Called when a response for CreateNode() is received.
- void OnCreateNode(const dbus::ObjectPath& object_path,
- const NodeCallback& callback,
- dbus::Response* response) {
- // Parse response.
- bool success = false;
- dbus::ObjectPath node_path;
- if (response != NULL) {
- dbus::MessageReader reader(response);
- if (!reader.PopObjectPath(&node_path)) {
- LOG(WARNING) << "CreateNode response has incorrect parameters: "
- << response->ToString();
- } else {
- success = true;
- }
- } else {
- LOG(WARNING) << "Failed to create node.";
- }
-
- // Notify client.
- callback.Run(node_path, success);
- }
-
- // Called when a response for RemoveNode() is received.
- void OnRemoveNode(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnRemoveNode: failed.";
- callback.Run(object_path, response);
- }
-
- dbus::Bus* bus_;
-
- // List of observers interested in event notifications from us.
- ObserverList<BluetoothDeviceClient::Observer> observers_;
-
- // Weak pointer factory for generating 'this' pointers that might live longer
- // than we do.
- // 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<BluetoothDeviceClientImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClientImpl);
-};
-
-BluetoothDeviceClient::BluetoothDeviceClient() {
-}
-
-BluetoothDeviceClient::~BluetoothDeviceClient() {
-}
-
-BluetoothDeviceClient* BluetoothDeviceClient::Create(
- DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothAdapterClient* adapter_client) {
- if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
- return new BluetoothDeviceClientImpl(bus, adapter_client);
- DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new FakeOldBluetoothDeviceClient();
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_device_client.h b/chromeos/dbus/bluetooth_device_client.h
deleted file mode 100644
index e36fa46..0000000
--- a/chromeos/dbus/bluetooth_device_client.h
+++ /dev/null
@@ -1,211 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_DEVICE_CLIENT_H_
-#define CHROMEOS_DBUS_BLUETOOTH_DEVICE_CLIENT_H_
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/observer_list.h"
-#include "base/values.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/dbus_client_implementation_type.h"
-#include "dbus/object_path.h"
-
-namespace dbus {
-class Bus;
-} // namespace dbus
-
-namespace chromeos {
-
-class BluetoothAdapterClient;
-
-// BluetoothDeviceClient is used to communicate with a bluetooth Device
-// interface.
-class CHROMEOS_EXPORT BluetoothDeviceClient {
- public:
- // Structure of properties associated with bluetooth devices.
- struct Properties : public BluetoothPropertySet {
- // The Bluetooth device address of the device. Read-only.
- dbus::Property<std::string> address;
-
- // The Bluetooth friendly name of the device. Read-only, to give a
- // different local name, use the |alias| property.
- dbus::Property<std::string> name;
-
- // Unique numeric identifier for the vendor of the device. Read-only.
- dbus::Property<uint16> vendor;
-
- // Unique vendor-assigned product identifier for the product of the
- // device. Read-only.
- dbus::Property<uint16> product;
-
- // Unique vendor-assigned version identifier for the device. Read-only.
- dbus::Property<uint16> version;
-
- // Proposed icon name for the device according to the freedesktop.org
- // icon naming specification. Read-only.
- dbus::Property<std::string> icon;
-
- // The Bluetooth class of the device. Read-only.
- dbus::Property<uint32> bluetooth_class;
-
- // List of 128-bit UUIDs that represent the available remote services.
- // Raed-only.
- dbus::Property<std::vector<std::string> > uuids;
-
- // List of characteristics-based available remote services. Read-only.
- dbus::Property<std::vector<dbus::ObjectPath> > services;
-
- // Indicates that the device is currently paired. Read-only.
- dbus::Property<bool> paired;
-
- // Indicates that the device is currently connected. Read-only.
- dbus::Property<bool> connected;
-
- // Whether the device is trusted, and connections should be always
- // accepted and attempted when the device is visible.
- dbus::Property<bool> trusted;
-
- // Whether the device is blocked, connections will be always rejected
- // and the device will not be visible.
- dbus::Property<bool> blocked;
-
- // Local alias for the device, if not set, is equal to |name|.
- dbus::Property<std::string> alias;
-
- // List of object paths of nodes the device provides. Read-only.
- dbus::Property<std::vector<dbus::ObjectPath> > nodes;
-
- // Object path of the adapter the device belongs to. Read-only.
- dbus::Property<dbus::ObjectPath> adapter;
-
- // Indicates whether the device is likely to only support pre-2.1
- // PIN Code pairing rather than 2.1 Secure Simple Pairing, this can
- // give false positives. Read-only.
- dbus::Property<bool> legacy_pairing;
-
- Properties(dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback);
- virtual ~Properties();
- };
-
- // Interface for observing changes from a remote bluetooth device.
- class Observer {
- public:
- virtual ~Observer() {}
-
- // Called when the device with object path |object_path| has a
- // change in value of the property named |property_name|.
- virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {}
-
- // Called when the device with object path |object_path| is about
- // to be disconnected, giving a chance for application layers to
- // shut down cleanly.
- virtual void DisconnectRequested(const dbus::ObjectPath& object_path) {}
-
- // Called when the device with object path |object_path| has a new
- // persistent device node with object path |node_path|.
- virtual void NodeCreated(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& node_path) {}
-
- // Called when the device with object path |object_path| removes
- // the persistent device node with object path |node_path|.
- virtual void NodeRemoved(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& node_path) {}
- };
-
- virtual ~BluetoothDeviceClient();
-
- // Adds and removes observers for events on all remote bluetooth
- // devices. Check the |object_path| parameter of observer methods to
- // determine which device is issuing the event.
- virtual void AddObserver(Observer* observer) = 0;
- virtual void RemoveObserver(Observer* observer) = 0;
-
- // Obtain the properties for the device with object path |object_path|,
- // any values should be copied if needed.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
-
- // The Services map is used to convey the set of services discovered
- // on a device. The keys are unique record handles and the values are
- // XML-formatted service records. Both can be generated using the
- // sdptool(1) binary distributed with bluetoothd.
- typedef std::map<const uint32, std::string> ServiceMap;
-
- // The ServicesCallback is used for the DiscoverServices() method. It
- // receives three arguments, the |object_path| of the device, the
- // dictionary of the |services| discovered where the keys are unique
- // record handles and the values are XML formatted service records,
- // and |success| which indicates whether or not the request succeded.
- typedef base::Callback<void(const dbus::ObjectPath&, const ServiceMap&,
- bool)> ServicesCallback;
-
- // Starts the service discovery process for the device with object path
- // |object_path|, the |pattern| paramter can be used to specify specific
- // UUIDs while an empty string will look for the public browse group.
- virtual void DiscoverServices(const dbus::ObjectPath& object_path,
- const std::string& pattern,
- const ServicesCallback& callback) = 0;
-
- // The DeviceCallback is used for device methods that only return to
- // indicate success. It receives two arguments, the |object_path| of the
- // device the call was made on and |success| which indicates whether or
- // not the request succeeded.
- typedef base::Callback<void(const dbus::ObjectPath&, bool)> DeviceCallback;
-
- // Cancels any previous service discovery processes for the device with
- // object path |object_path|.
- virtual void CancelDiscovery(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) = 0;
-
- // Disconnects the device with object path |object_path|, terminating
- // the low-level ACL connection and any application connections using it.
- // Actual disconnection takes place after two seconds during which a
- // DisconnectRequested signal is emitted by the device to allow those
- // applications to terminate gracefully.
- virtual void Disconnect(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) = 0;
-
- // The NodeCallback is used for device methods that return a dbus
- // object path for a persistent device node binding, as well as success.
- // It receives two arguments, the |object_path| of the persistent device
- // node binding object returned by the method and |success} which indicates
- // whether or not the request succeeded.
- typedef base::Callback<void(const dbus::ObjectPath&, bool)> NodeCallback;
-
- // Creates a persistent device node binding with the device with object path
- // |object_path| using the specified service |uuid|. The actual support
- // depends on the device driver, at the moment only RFCOMM TTY nodes are
- // supported.
- virtual void CreateNode(const dbus::ObjectPath& object_path,
- const std::string& uuid,
- const NodeCallback& callback) = 0;
-
- // Removes the persistent device node binding with the dbus object path
- // |node_path| from the device with object path |object_path|.
- virtual void RemoveNode(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& node_path,
- const DeviceCallback& callback) = 0;
-
- // Creates the instance.
- static BluetoothDeviceClient* Create(DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothAdapterClient* adapter_client);
-
- protected:
- BluetoothDeviceClient();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_DEVICE_CLIENT_H_
diff --git a/chromeos/dbus/bluetooth_input_client.cc b/chromeos/dbus/bluetooth_input_client.cc
deleted file mode 100644
index 4c7863a..0000000
--- a/chromeos/dbus/bluetooth_input_client.cc
+++ /dev/null
@@ -1,301 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_input_client.h"
-
-#include <map>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "dbus/bus.h"
-#include "dbus/message.h"
-#include "dbus/object_path.h"
-#include "dbus/object_proxy.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace {
-
-// The |Connect| DBus call needs a longer timeout than the default in order to
-// give BlueZ enough time to return the timeout error response.
-// See crosbug.com/37607
-const int kConnectTimeoutMs = 50 * 1000;
-
-} // namespace
-
-namespace chromeos {
-
-const char BluetoothInputClient::kNoResponseError[] =
- "org.chromium.Error.NoResponse";
-
-BluetoothInputClient::Properties::Properties(
- dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback)
- : BluetoothPropertySet(object_proxy,
- bluetooth_input::kBluetoothInputInterface,
- callback) {
- RegisterProperty(bluetooth_input::kConnectedProperty, &connected);
-}
-
-BluetoothInputClient::Properties::~Properties() {
-}
-
-
-// The BluetoothInputClient implementation used in production.
-class BluetoothInputClientImpl: public BluetoothInputClient,
- private BluetoothAdapterClient::Observer {
- public:
- BluetoothInputClientImpl(dbus::Bus* bus,
- BluetoothAdapterClient* adapter_client)
- : bus_(bus),
- weak_ptr_factory_(this) {
- DCHECK(adapter_client);
- adapter_client->AddObserver(this);
- }
-
- virtual ~BluetoothInputClientImpl() {
- // Clean up Properties structures
- for (ObjectMap::iterator iter = object_map_.begin();
- iter != object_map_.end(); ++iter) {
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
- }
- }
-
- // BluetoothInputClient override.
- virtual void AddObserver(BluetoothInputClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.AddObserver(observer);
- }
-
- // BluetoothInputClient override.
- virtual void RemoveObserver(BluetoothInputClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.RemoveObserver(observer);
- }
-
- // BluetoothInputClient override.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
- OVERRIDE {
- return GetObject(object_path).second;
- }
-
- // BluetoothInputClient override.
- virtual void Connect(const dbus::ObjectPath& object_path,
- const ConnectCallback& callback,
- const ConnectErrorCallback& error_callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_input::kBluetoothInputInterface,
- bluetooth_input::kConnect);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethodWithErrorCallback(
- &method_call,
- kConnectTimeoutMs,
- base::Bind(&BluetoothInputClientImpl::OnConnect,
- weak_ptr_factory_.GetWeakPtr(), object_path,
- callback),
- base::Bind(&BluetoothInputClientImpl::OnConnectError,
- weak_ptr_factory_.GetWeakPtr(), object_path,
- error_callback));
- }
-
- // BluetoothInputClient override.
- virtual void Disconnect(const dbus::ObjectPath& object_path,
- const InputCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_input::kBluetoothInputInterface,
- bluetooth_input::kDisconnect);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothInputClientImpl::OnDisconnect,
- weak_ptr_factory_.GetWeakPtr(), object_path, callback));
- }
-
- private:
- // We maintain a collection of dbus object proxies and properties structures
- // for each input device.
- typedef std::pair<dbus::ObjectProxy*, Properties*> Object;
- typedef std::map<const dbus::ObjectPath, Object> ObjectMap;
- ObjectMap object_map_;
-
- // BluetoothAdapterClient::Observer override.
- virtual void DeviceCreated(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& object_path) OVERRIDE {
- }
-
- // BluetoothAdapterClient::Observer override.
- virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& object_path) OVERRIDE {
- RemoveObject(object_path);
- }
-
- // Ensures that we have an object proxy and properties structure for
- // an input device with object path |object_path|, creating it if not and
- // storing it in our |object_map_| map.
- Object GetObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end())
- return iter->second;
-
- // Create the object proxy.
- DCHECK(bus_);
- dbus::ObjectProxy* object_proxy = bus_->GetObjectProxy(
- bluetooth_input::kBluetoothInputServiceName, object_path);
-
- // Create the properties structure.
- Properties* properties = new Properties(
- object_proxy,
- base::Bind(&BluetoothInputClientImpl::OnPropertyChanged,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- properties->ConnectSignals();
- properties->GetAll();
-
- Object object = std::make_pair(object_proxy, properties);
- object_map_[object_path] = object;
- return object;
- }
-
- // Removes the dbus object proxy and properties for the input device with
- // dbus object path |object_path| from our |object_map_| map.
- void RemoveObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end()) {
- // Clean up the Properties structure.
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
-
- object_map_.erase(iter);
- }
- }
-
- // Returns a pointer to the object proxy for |object_path|, creating
- // it if necessary.
- dbus::ObjectProxy* GetObjectProxy(const dbus::ObjectPath& object_path) {
- return GetObject(object_path).first;
- }
-
- // Called by BluetoothPropertySet when a property value is changed,
- // either by result of a signal or response to a GetAll() or Get()
- // call. Informs observers.
- void OnPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {
- FOR_EACH_OBSERVER(BluetoothInputClient::Observer, observers_,
- InputPropertyChanged(object_path, property_name));
- }
-
- // Called when a response for Connect() is received.
- void OnConnect(const dbus::ObjectPath& object_path,
- const ConnectCallback& callback,
- dbus::Response* response) {
- DCHECK(response);
- callback.Run(object_path);
- }
-
- // Called when an error for Connect() is received.
- void OnConnectError(const dbus::ObjectPath& object_path,
- const ConnectErrorCallback& error_callback,
- dbus::ErrorResponse* response) {
- // Error response has optional error message argument.
- std::string error_name;
- std::string error_message;
- if (response) {
- dbus::MessageReader reader(response);
- error_name = response->GetErrorName();
- reader.PopString(&error_message);
- } else {
- error_name = kNoResponseError;
- error_message = "";
- }
- error_callback.Run(object_path, error_name, error_message);
- }
-
- // Called when a response for Disconnect() is received.
- void OnDisconnect(const dbus::ObjectPath& object_path,
- const InputCallback& callback,
- dbus::Response* response) {
- LOG_IF(WARNING, !response) << object_path.value()
- << ": OnDisconnect: failed.";
- callback.Run(object_path, response);
- }
-
- dbus::Bus* bus_;
-
- // List of observers interested in event notifications from us.
- ObserverList<BluetoothInputClient::Observer> observers_;
-
- // Weak pointer factory for generating 'this' pointers that might live longer
- // than we do.
- // 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<BluetoothInputClientImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothInputClientImpl);
-};
-
-// The BluetoothInputClient implementation used on Linux desktop, which does
-// nothing.
-class BluetoothInputClientStubImpl : public BluetoothInputClient {
- public:
- // BluetoothInputClient override.
- virtual void AddObserver(Observer* observer) OVERRIDE {
- }
-
- // BluetoothInputClient override.
- virtual void RemoveObserver(Observer* observer) OVERRIDE {
- }
-
- // BluetoothInputClient override.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
- OVERRIDE {
- VLOG(1) << "GetProperties: " << object_path.value();
- return NULL;
- }
-
- // BluetoothInputClient override.
- virtual void Connect(const dbus::ObjectPath& object_path,
- const ConnectCallback& callback,
- const ConnectErrorCallback& error_callback) OVERRIDE {
- VLOG(1) << "Connect: " << object_path.value();
- error_callback.Run(object_path, "", "");
- }
-
- // BluetoothInputClient override.
- virtual void Disconnect(const dbus::ObjectPath& object_path,
- const InputCallback& callback) OVERRIDE {
- VLOG(1) << "Disconnect: " << object_path.value();
- callback.Run(object_path, false);
- }
-};
-
-BluetoothInputClient::BluetoothInputClient() {
-}
-
-BluetoothInputClient::~BluetoothInputClient() {
-}
-
-BluetoothInputClient* BluetoothInputClient::Create(
- DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothAdapterClient* adapter_client) {
- if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
- return new BluetoothInputClientImpl(bus, adapter_client);
- DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new BluetoothInputClientStubImpl();
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_input_client.h b/chromeos/dbus/bluetooth_input_client.h
deleted file mode 100644
index 6d0c76b..0000000
--- a/chromeos/dbus/bluetooth_input_client.h
+++ /dev/null
@@ -1,113 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_INPUT_CLIENT_H_
-#define CHROMEOS_DBUS_BLUETOOTH_INPUT_CLIENT_H_
-
-#include <string>
-
-#include "base/callback.h"
-#include "base/observer_list.h"
-#include "base/values.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/dbus_client_implementation_type.h"
-#include "dbus/object_path.h"
-
-namespace dbus {
-class Bus;
-} // namespace dbus
-
-namespace chromeos {
-
-class BluetoothAdapterClient;
-
-// BluetoothInputClient is used to communicate with the Input interface
-// of a bluetooth device, rather than the generic device interface. Input
-// devices are those conforming to the Bluetooth SIG HID (Human Interface
-// Device) Profile such as keyboards, mice, trackpads and joysticks.
-class CHROMEOS_EXPORT BluetoothInputClient {
- public:
- // Structure of properties associated with bluetooth input devices.
- struct Properties : public BluetoothPropertySet {
- // Indicates that the device is currently connected. Read-only.
- dbus::Property<bool> connected;
-
- Properties(dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback);
- virtual ~Properties();
- };
-
- // Interface for observing changes from a bluetooth input device.
- class Observer {
- public:
- virtual ~Observer() {}
-
- // Called when the device with object path |object_path| has a
- // change in value of the input property named |property_name|.
- virtual void InputPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {}
- };
-
- virtual ~BluetoothInputClient();
-
- // Adds and removes observers for events on all bluetooth input
- // devices. Check the |object_path| parameter of observer methods to
- // determine which device is issuing the event.
- virtual void AddObserver(Observer* observer) = 0;
- virtual void RemoveObserver(Observer* observer) = 0;
-
- // Obtain the input properties for the device with object path |object_path|,
- // any values should be copied if needed.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
-
- // The InputCallback is used for input device methods that only return to
- // indicate success. It receives two arguments, the |object_path| of the
- // input device the call was made on and |success| which indicates whether
- // or not the request succeeded.
- typedef base::Callback<void(const dbus::ObjectPath&, bool)> InputCallback;
-
- // The ConnectCallback is used for the Connect input device method to
- // indicate success. It receives a single argument, the |object_path| of
- // the input device the call was made on.
- typedef base::Callback<void(const dbus::ObjectPath&)> ConnectCallback;
-
- // The ConnectErrorCallback is used for the Connect input device method
- // to indicate failure. It receives three arguments, the |object_path| of
- // the input device the call was made on, the name of the error in
- // |error_name| and an optional message in |error_message|.
- typedef base::Callback<void(const dbus::ObjectPath& object_path,
- const std::string& error_name,
- const std::string& error_message)>
- ConnectErrorCallback;
-
- // Connects the input subsystem to the device with object path
- // |object_path|, which should already be a known device on the adapter.
- virtual void Connect(const dbus::ObjectPath& object_path,
- const ConnectCallback& callback,
- const ConnectErrorCallback& error_callback) = 0;
-
- // Disconnects the input subsystem from the device with object path
- // |object_path| without terminating the low-level ACL connection,
- virtual void Disconnect(const dbus::ObjectPath& object_path,
- const InputCallback& callback) = 0;
-
- // Creates the instance.
- static BluetoothInputClient* Create(DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothAdapterClient* adapter_client);
-
- // Constants used to indicate exceptional error conditions.
- static const char kNoResponseError[];
-
- protected:
- BluetoothInputClient();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BluetoothInputClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_INPUT_CLIENT_H_
diff --git a/chromeos/dbus/bluetooth_manager_client.cc b/chromeos/dbus/bluetooth_manager_client.cc
deleted file mode 100644
index f278160..0000000
--- a/chromeos/dbus/bluetooth_manager_client.cc
+++ /dev/null
@@ -1,289 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_manager_client.h"
-
-#include <vector>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/fake_old_bluetooth_manager_client.h"
-#include "dbus/bus.h"
-#include "dbus/message.h"
-#include "dbus/object_path.h"
-#include "dbus/object_proxy.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-BluetoothManagerClient::Properties::Properties(
- dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback)
- : BluetoothPropertySet(object_proxy,
- bluetooth_manager::kBluetoothManagerInterface,
- callback) {
- RegisterProperty(bluetooth_manager::kAdaptersProperty, &adapters);
-}
-
-BluetoothManagerClient::Properties::~Properties() {
-}
-
-
-// The BluetoothManagerClient implementation used in production.
-class BluetoothManagerClientImpl : public BluetoothManagerClient {
- public:
- explicit BluetoothManagerClientImpl(dbus::Bus* bus)
- : object_proxy_(NULL),
- weak_ptr_factory_(this) {
- // Create the object proxy.
- DCHECK(bus);
- object_proxy_ = bus->GetObjectProxy(
- bluetooth_manager::kBluetoothManagerServiceName,
- dbus::ObjectPath(bluetooth_manager::kBluetoothManagerServicePath));
-
- object_proxy_->ConnectToSignal(
- bluetooth_manager::kBluetoothManagerInterface,
- bluetooth_manager::kAdapterAddedSignal,
- base::Bind(&BluetoothManagerClientImpl::AdapterAddedReceived,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothManagerClientImpl::AdapterAddedConnected,
- weak_ptr_factory_.GetWeakPtr()));
-
- object_proxy_->ConnectToSignal(
- bluetooth_manager::kBluetoothManagerInterface,
- bluetooth_manager::kAdapterRemovedSignal,
- base::Bind(&BluetoothManagerClientImpl::AdapterRemovedReceived,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothManagerClientImpl::AdapterRemovedConnected,
- weak_ptr_factory_.GetWeakPtr()));
-
- object_proxy_->ConnectToSignal(
- bluetooth_manager::kBluetoothManagerInterface,
- bluetooth_manager::kDefaultAdapterChangedSignal,
- base::Bind(&BluetoothManagerClientImpl::DefaultAdapterChangedReceived,
- weak_ptr_factory_.GetWeakPtr()),
- base::Bind(&BluetoothManagerClientImpl::DefaultAdapterChangedConnected,
- weak_ptr_factory_.GetWeakPtr()));
-
- // Create the properties structure.
- properties_ = new Properties(
- object_proxy_,
- base::Bind(&BluetoothManagerClientImpl::OnPropertyChanged,
- weak_ptr_factory_.GetWeakPtr()));
-
- properties_->ConnectSignals();
- properties_->GetAll();
- }
-
- virtual ~BluetoothManagerClientImpl() {
- // Clean up the Properties structure.
- delete properties_;
- }
-
- // BluetoothManagerClient override.
- virtual void AddObserver(Observer* observer) OVERRIDE {
- DCHECK(observer);
- observers_.AddObserver(observer);
- }
-
- // BluetoothManagerClient override.
- virtual void RemoveObserver(Observer* observer) OVERRIDE {
- DCHECK(observer);
- observers_.RemoveObserver(observer);
- }
-
- // BluetoothManagerClient override.
- virtual Properties* GetProperties() OVERRIDE {
- return properties_;
- }
-
- // BluetoothManagerClient override.
- virtual void DefaultAdapter(const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_manager::kBluetoothManagerInterface,
- bluetooth_manager::kDefaultAdapter);
-
- DCHECK(object_proxy_);
- object_proxy_->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothManagerClientImpl::OnDefaultAdapter,
- weak_ptr_factory_.GetWeakPtr(), callback));
- }
-
- // BluetoothManagerClient override.
- virtual void FindAdapter(const std::string& address,
- const AdapterCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_manager::kBluetoothManagerInterface,
- bluetooth_manager::kFindAdapter);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(address);
-
- DCHECK(object_proxy_);
- object_proxy_->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothManagerClientImpl::OnFindAdapter,
- weak_ptr_factory_.GetWeakPtr(), callback));
- }
-
- private:
- // Called by BluetoothPropertySet when a property value is changed,
- // either by result of a signal or response to a GetAll() or Get()
- // call. Informs observers.
- void OnPropertyChanged(const std::string& property_name) {
- FOR_EACH_OBSERVER(BluetoothManagerClient::Observer, observers_,
- ManagerPropertyChanged(property_name));
- }
-
- // Called by dbus:: when an AdapterAdded signal is received.
- void AdapterAddedReceived(dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- dbus::ObjectPath object_path;
- if (!reader.PopObjectPath(&object_path)) {
- LOG(WARNING) << "AdapterAdded signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << "Adapter added: " << object_path.value();
- FOR_EACH_OBSERVER(Observer, observers_, AdapterAdded(object_path));
- }
-
- // Called by dbus:: when the AdapterAdded signal is initially connected.
- void AdapterAddedConnected(const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to connect to AdapterAdded signal.";
- }
-
- // Called by dbus:: when an AdapterRemoved signal is received.
- void AdapterRemovedReceived(dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- dbus::ObjectPath object_path;
- if (!reader.PopObjectPath(&object_path)) {
- LOG(WARNING) << "AdapterRemoved signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << "Adapter removed: " << object_path.value();
- FOR_EACH_OBSERVER(Observer, observers_, AdapterRemoved(object_path));
- }
-
- // Called by dbus:: when the AdapterRemoved signal is initially connected.
- void AdapterRemovedConnected(const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success) << "Failed to connect to AdapterRemoved signal.";
- }
-
- // Called by dbus:: when a DefaultAdapterChanged signal is received.
- void DefaultAdapterChangedReceived(dbus::Signal* signal) {
- DCHECK(signal);
- dbus::MessageReader reader(signal);
- dbus::ObjectPath object_path;
- if (!reader.PopObjectPath(&object_path)) {
- LOG(WARNING) << "DefaultAdapterChanged signal has incorrect parameters: "
- << signal->ToString();
- return;
- }
-
- VLOG(1) << "Default adapter changed: " << object_path.value();
- FOR_EACH_OBSERVER(Observer, observers_, DefaultAdapterChanged(object_path));
- }
-
- // Called by dbus:: when the DefaultAdapterChanged signal is initially
- // connected.
- void DefaultAdapterChangedConnected(const std::string& interface_name,
- const std::string& signal_name,
- bool success) {
- LOG_IF(WARNING, !success)
- << "Failed to connect to DefaultAdapterChanged signal.";
- }
-
- // Called when a response for DefaultAdapter() is received.
- void OnDefaultAdapter(const AdapterCallback& callback,
- dbus::Response* response) {
- // Parse response.
- bool success = false;
- dbus::ObjectPath object_path;
- if (response != NULL) {
- dbus::MessageReader reader(response);
- if (!reader.PopObjectPath(&object_path)) {
- LOG(WARNING) << "DefaultAdapter response has incorrect parameters: "
- << response->ToString();
- } else {
- success = true;
- }
- } else {
- LOG(WARNING) << "Failed to get default adapter.";
- }
-
- // Notify client.
- callback.Run(object_path, success);
- }
-
- // Called when a response for FindAdapter() is received.
- void OnFindAdapter(const AdapterCallback& callback,
- dbus::Response* response) {
- // Parse response.
- bool success = false;
- dbus::ObjectPath object_path;
- if (response != NULL) {
- dbus::MessageReader reader(response);
- if (!reader.PopObjectPath(&object_path)) {
- LOG(WARNING) << "FindAdapter response has incorrect parameters: "
- << response->ToString();
- } else {
- success = true;
- }
- } else {
- LOG(WARNING) << "Failed to find adapter.";
- }
-
- // Notify client.
- callback.Run(object_path, success);
- }
-
- // D-Bus proxy for BlueZ Manager interface.
- dbus::ObjectProxy* object_proxy_;
-
- // Properties for BlueZ Manager interface.
- Properties* properties_;
-
- // List of observers interested in event notifications from us.
- ObserverList<Observer> observers_;
-
- // Weak pointer factory for generating 'this' pointers that might live longer
- // than we do.
- // 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<BluetoothManagerClientImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClientImpl);
-};
-
-BluetoothManagerClient::BluetoothManagerClient() {
-}
-
-BluetoothManagerClient::~BluetoothManagerClient() {
-}
-
-BluetoothManagerClient* BluetoothManagerClient::Create(
- DBusClientImplementationType type,
- dbus::Bus* bus) {
- if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
- return new BluetoothManagerClientImpl(bus);
- DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new FakeOldBluetoothManagerClient();
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_manager_client.h b/chromeos/dbus/bluetooth_manager_client.h
deleted file mode 100644
index 1d0cde9..0000000
--- a/chromeos/dbus/bluetooth_manager_client.h
+++ /dev/null
@@ -1,100 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_MANAGER_CLIENT_H_
-#define CHROMEOS_DBUS_BLUETOOTH_MANAGER_CLIENT_H_
-
-#include <string>
-#include <vector>
-
-#include "base/callback.h"
-#include "base/observer_list.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/dbus_client_implementation_type.h"
-#include "dbus/object_path.h"
-
-namespace dbus {
-class Bus;
-} // namespace dbus
-
-namespace chromeos {
-
-// BluetoothManagerClient is used to communicate with the bluetooth
-// daemon's Manager interface.
-class CHROMEOS_EXPORT BluetoothManagerClient {
- public:
- // Structure of properties associated with the bluetooth manager.
- struct Properties : public BluetoothPropertySet {
- // List of object paths of local Bluetooth adapters. Read-only.
- dbus::Property<std::vector<dbus::ObjectPath> > adapters;
-
- Properties(dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback);
- virtual ~Properties();
- };
-
- // Interface for observing changes from the bluetooth manager.
- class Observer {
- public:
- virtual ~Observer() {}
-
- // Called when the manager has a change in value of the property
- // named |property_name|.
- virtual void ManagerPropertyChanged(const std::string& property_name) {}
-
- // Called when a local bluetooth adapter is added.
- // |object_path| is the dbus object path of the adapter.
- virtual void AdapterAdded(const dbus::ObjectPath& object_path) {}
-
- // Called when a local bluetooth adapter is removed.
- // |object_path| is the dbus object path of the adapter.
- virtual void AdapterRemoved(const dbus::ObjectPath& object_path) {}
-
- // Called when the default local bluetooth adapter changes.
- // |object_path| is the dbus object path of the new default adapter.
- // Not called if all adapters are removed.
- virtual void DefaultAdapterChanged(const dbus::ObjectPath& object_path) {}
- };
-
- virtual ~BluetoothManagerClient();
-
- // Adds and removes observers.
- virtual void AddObserver(Observer* observer) = 0;
- virtual void RemoveObserver(Observer* observer) = 0;
-
- // Obtain the properties for the manager, any values should be copied
- // if needed.
- virtual Properties* GetProperties() = 0;
-
- // The AdapterCallback is used for both the DefaultAdapter() and
- // FindAdapter() methods. It receives two arguments, the |object_path|
- // of the adapter and |success| which indicates whether or not the request
- // succeeded.
- typedef base::Callback<void(const dbus::ObjectPath&, bool)> AdapterCallback;
-
- // Retrieves the dbus object path for the default adapter.
- // The default adapter is the preferred local bluetooth interface when a
- // client does not specify a particular interface.
- virtual void DefaultAdapter(const AdapterCallback& callback) = 0;
-
- // Retrieves the dbus object path for the adapter with the address |address|,
- // which may also be an interface name.
- virtual void FindAdapter(const std::string& address,
- const AdapterCallback& callback) = 0;
-
- // Creates the instance.
- static BluetoothManagerClient* Create(DBusClientImplementationType type,
- dbus::Bus* bus);
-
- protected:
- BluetoothManagerClient();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BluetoothManagerClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_MANAGER_CLIENT_H_
diff --git a/chromeos/dbus/bluetooth_node_client.cc b/chromeos/dbus/bluetooth_node_client.cc
deleted file mode 100644
index b421e27..0000000
--- a/chromeos/dbus/bluetooth_node_client.cc
+++ /dev/null
@@ -1,203 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_node_client.h"
-
-#include <map>
-#include <utility>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "dbus/bus.h"
-#include "dbus/message.h"
-#include "dbus/object_path.h"
-#include "dbus/object_proxy.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-BluetoothNodeClient::Properties::Properties(
- dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback)
- : BluetoothPropertySet(object_proxy,
- bluetooth_node::kBluetoothNodeInterface,
- callback) {
- RegisterProperty(bluetooth_node::kNameProperty, &name);
- RegisterProperty(bluetooth_node::kDeviceProperty, &device);
-}
-
-BluetoothNodeClient::Properties::~Properties() {
-}
-
-
-// The BluetoothNodeClient implementation used in production.
-class BluetoothNodeClientImpl: public BluetoothNodeClient,
- private BluetoothDeviceClient::Observer {
- public:
- BluetoothNodeClientImpl(dbus::Bus* bus,
- BluetoothDeviceClient* device_client)
- : bus_(bus),
- weak_ptr_factory_(this) {
- DCHECK(device_client);
- device_client->AddObserver(this);
- }
-
- virtual ~BluetoothNodeClientImpl() {
- // Clean up Properties structures
- for (ObjectMap::iterator iter = object_map_.begin();
- iter != object_map_.end(); ++iter) {
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
- }
- }
-
- // BluetoothNodeClient override.
- virtual void AddObserver(BluetoothNodeClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.AddObserver(observer);
- }
-
- // BluetoothNodeClient override.
- virtual void RemoveObserver(BluetoothNodeClient::Observer* observer)
- OVERRIDE {
- DCHECK(observer);
- observers_.RemoveObserver(observer);
- }
-
- // BluetoothNodeClient override.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
- OVERRIDE {
- return GetObject(object_path).second;
- }
-
- private:
- // We maintain a collection of dbus object proxies and properties structures
- // for each node binding.
- typedef std::pair<dbus::ObjectProxy*, Properties*> Object;
- typedef std::map<const dbus::ObjectPath, Object> ObjectMap;
- ObjectMap object_map_;
-
- // BluetoothDeviceClient::Observer override.
- virtual void NodeCreated(const dbus::ObjectPath& device_path,
- const dbus::ObjectPath& object_path) OVERRIDE {
- }
-
- // BluetoothDeviceClient::Observer override.
- virtual void NodeRemoved(const dbus::ObjectPath& device_path,
- const dbus::ObjectPath& object_path) OVERRIDE {
- RemoveObject(object_path);
- }
-
- // Ensures that we have an object proxy and properties structure for
- // a node binding with object path |object_path|, creating it if not and
- // storing it in our |object_map_| map.
- Object GetObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end())
- return iter->second;
-
- // Create the object proxy.
- DCHECK(bus_);
- dbus::ObjectProxy* object_proxy = bus_->GetObjectProxy(
- bluetooth_node::kBluetoothNodeServiceName, object_path);
-
- // Create the properties structure.
- Properties* properties = new Properties(
- object_proxy,
- base::Bind(&BluetoothNodeClientImpl::OnPropertyChanged,
- weak_ptr_factory_.GetWeakPtr(), object_path));
-
- properties->ConnectSignals();
- properties->GetAll();
-
- Object object = std::make_pair(object_proxy, properties);
- object_map_[object_path] = object;
- return object;
- }
-
- // Removes the dbus object proxy and properties for the node binding with
- // dbus object path |object_path| from our |object_map_| map.
- void RemoveObject(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end()) {
- // Clean up the Properties structure.
- Object object = iter->second;
- Properties* properties = object.second;
- delete properties;
-
- object_map_.erase(iter);
- }
- }
-
- // Returns a pointer to the object proxy for |object_path|, creating
- // it if necessary.
- dbus::ObjectProxy* GetObjectProxy(const dbus::ObjectPath& object_path) {
- return GetObject(object_path).first;
- }
-
- // Called by BluetoothPropertySet when a property value is changed,
- // either by result of a signal or response to a GetAll() or Get()
- // call. Informs observers.
- void OnPropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {
- FOR_EACH_OBSERVER(BluetoothNodeClient::Observer, observers_,
- NodePropertyChanged(object_path, property_name));
- }
-
- dbus::Bus* bus_;
-
- // List of observers interested in event notifications from us.
- ObserverList<BluetoothNodeClient::Observer> observers_;
-
- // Weak pointer factory for generating 'this' pointers that might live longer
- // than we do.
- // 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<BluetoothNodeClientImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothNodeClientImpl);
-};
-
-// The BluetoothNodeClient implementation used on Linux desktop, which does
-// nothing.
-class BluetoothNodeClientStubImpl : public BluetoothNodeClient {
- public:
- // BluetoothNodeClient override.
- virtual void AddObserver(Observer* observer) OVERRIDE {
- }
-
- // BluetoothNodeClient override.
- virtual void RemoveObserver(Observer* observer) OVERRIDE {
- }
-
- // BluetoothNodeClient override.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path)
- OVERRIDE {
- VLOG(1) << "GetProperties: " << object_path.value();
- return NULL;
- }
-};
-
-BluetoothNodeClient::BluetoothNodeClient() {
-}
-
-BluetoothNodeClient::~BluetoothNodeClient() {
-}
-
-BluetoothNodeClient* BluetoothNodeClient::Create(
- DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothDeviceClient* adapter_client) {
- if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
- return new BluetoothNodeClientImpl(bus, adapter_client);
- DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new BluetoothNodeClientStubImpl();
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_node_client.h b/chromeos/dbus/bluetooth_node_client.h
deleted file mode 100644
index 7f4d116..0000000
--- a/chromeos/dbus/bluetooth_node_client.h
+++ /dev/null
@@ -1,81 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_NODE_CLIENT_H_
-#define CHROMEOS_DBUS_BLUETOOTH_NODE_CLIENT_H_
-
-#include <string>
-
-#include "base/callback.h"
-#include "base/observer_list.h"
-#include "base/values.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/bluetooth_property.h"
-#include "chromeos/dbus/dbus_client_implementation_type.h"
-#include "dbus/object_path.h"
-
-namespace dbus {
-class Bus;
-} // namespace dbus
-
-namespace chromeos {
-
-class BluetoothDeviceClient;
-
-// BluetoothNodeClient is used to represent persistent device nodes
-// bound to bluetooth devices, such as RFCOMM TTY bindings to ttyX devices
-// in Linux.
-class CHROMEOS_EXPORT BluetoothNodeClient {
- public:
- // Structure of properties associated with persistent device nodes.
- struct Properties : public BluetoothPropertySet {
- // The name of the device node under /dev. Read-only.
- dbus::Property<std::string> name;
-
- // Object path of the device the node binding belongs to. Read-only.
- dbus::Property<dbus::ObjectPath> device;
-
- Properties(dbus::ObjectProxy* object_proxy,
- const PropertyChangedCallback& callback);
- virtual ~Properties();
- };
-
- // Interface for observing changes from a persistent device node binding.
- class Observer {
- public:
- virtual ~Observer() {}
-
- // Called when the node binding with object path |object_path| has a
- // change in value of the property named |property_name|.
- virtual void NodePropertyChanged(const dbus::ObjectPath& object_path,
- const std::string& property_name) {}
- };
-
- virtual ~BluetoothNodeClient();
-
- // Adds and removes observers for events on all persistent device node
- // bindings. Check the |object_path| parameter of observer methods to
- // determine which device node binding is issuing the event.
- virtual void AddObserver(Observer* observer) = 0;
- virtual void RemoveObserver(Observer* observer) = 0;
-
- // Obtain the properties for the node binding with object path |object_path|,
- // any values should be copied if needed.
- virtual Properties* GetProperties(const dbus::ObjectPath& object_path) = 0;
-
- // Creates the instance.
- static BluetoothNodeClient* Create(DBusClientImplementationType type,
- dbus::Bus* bus,
- BluetoothDeviceClient* device_client);
-
- protected:
- BluetoothNodeClient();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BluetoothNodeClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_NODE_CLIENT_H_
diff --git a/chromeos/dbus/bluetooth_out_of_band_client.cc b/chromeos/dbus/bluetooth_out_of_band_client.cc
deleted file mode 100644
index 457cf82..0000000
--- a/chromeos/dbus/bluetooth_out_of_band_client.cc
+++ /dev/null
@@ -1,203 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_out_of_band_client.h"
-
-#include <map>
-#include <string>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "dbus/bus.h"
-#include "dbus/message.h"
-#include "dbus/object_path.h"
-#include "dbus/object_proxy.h"
-#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-// The BluetoothOutOfBandClient implementation used in production.
-class BluetoothOutOfBandClientImpl: public BluetoothOutOfBandClient {
- public:
- explicit BluetoothOutOfBandClientImpl(dbus::Bus* bus)
- : bus_(bus),
- weak_ptr_factory_(this) {}
-
- virtual ~BluetoothOutOfBandClientImpl() {}
-
- // BluetoothOutOfBandClient override.
- virtual void ReadLocalData(
- const dbus::ObjectPath& object_path,
- const DataCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_outofband::kBluetoothOutOfBandInterface,
- bluetooth_outofband::kReadLocalData);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothOutOfBandClientImpl::OnReadLocalData,
- weak_ptr_factory_.GetWeakPtr(), callback));
- }
-
- // BluetoothOutOfBandClient override.
- virtual void AddRemoteData(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const device::BluetoothOutOfBandPairingData& data,
- const SuccessCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_outofband::kBluetoothOutOfBandInterface,
- bluetooth_outofband::kAddRemoteData);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(address);
- writer.AppendArrayOfBytes(
- data.hash, device::kBluetoothOutOfBandPairingDataSize);
- writer.AppendArrayOfBytes(
- data.randomizer, device::kBluetoothOutOfBandPairingDataSize);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothOutOfBandClientImpl::ResponseToSuccessCallback,
- weak_ptr_factory_.GetWeakPtr(), callback));
- }
-
- // BluetoothOutOfBandClient override.
- virtual void RemoveRemoteData(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const SuccessCallback& callback) OVERRIDE {
- dbus::MethodCall method_call(
- bluetooth_outofband::kBluetoothOutOfBandInterface,
- bluetooth_outofband::kRemoveRemoteData);
-
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(address);
-
- dbus::ObjectProxy* object_proxy = GetObjectProxy(object_path);
-
- object_proxy->CallMethod(
- &method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&BluetoothOutOfBandClientImpl::ResponseToSuccessCallback,
- weak_ptr_factory_.GetWeakPtr(), callback));
- }
-
- private:
- // We maintain a collection of dbus object proxies for each binding.
- typedef std::map<const dbus::ObjectPath, dbus::ObjectProxy*> ObjectMap;
- ObjectMap object_map_;
-
- // Returns a pointer to the object proxy for |object_path|, creating
- // it if necessary. This is cached in the ObjectMap.
- dbus::ObjectProxy* GetObjectProxy(const dbus::ObjectPath& object_path) {
- ObjectMap::iterator iter = object_map_.find(object_path);
- if (iter != object_map_.end())
- return iter->second;
-
- DCHECK(bus_);
- dbus::ObjectProxy* object_proxy = bus_->GetObjectProxy(
- bluetooth_outofband::kBluetoothOutOfBandServiceName, object_path);
-
- object_map_[object_path] = object_proxy;
- return object_proxy;
- }
-
- // Called when a response from ReadLocalOutOfBandPairingData() is received.
- void OnReadLocalData(const DataCallback& callback,
- dbus::Response* response) {
- bool success = false;
- device::BluetoothOutOfBandPairingData data;
- if (response != NULL) {
- dbus::MessageReader reader(response);
- uint8_t* bytes = NULL;
- size_t length = device::kBluetoothOutOfBandPairingDataSize;
- if (reader.PopArrayOfBytes(&bytes, &length)) {
- if (length == device::kBluetoothOutOfBandPairingDataSize) {
- memcpy(&data.hash, bytes, length);
- if (reader.PopArrayOfBytes(&bytes, &length)) {
- if (length == device::kBluetoothOutOfBandPairingDataSize) {
- memcpy(&data.randomizer, bytes, length);
- success = true;
- }
- }
- }
- }
- }
- callback.Run(data, success);
- }
-
- // Translates a dbus::Response to a SuccessCallback by assuming success if
- // |response| is not NULL.
- void ResponseToSuccessCallback(const SuccessCallback& callback,
- dbus::Response* response) {
- callback.Run(response != NULL);
- }
-
- dbus::Bus* bus_;
-
- // Weak pointer factory for generating 'this' pointers that might live longer
- // than we do.
- // 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<BluetoothOutOfBandClientImpl> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothOutOfBandClientImpl);
-};
-
-// The BluetoothOutOfBandClient implementation used on Linux desktop, which does
-// nothing.
-class BluetoothOutOfBandClientStubImpl : public BluetoothOutOfBandClient {
- public:
- // BluetoothOutOfBandClient override.
- virtual void ReadLocalData(
- const dbus::ObjectPath& object_path,
- const DataCallback& callback) OVERRIDE {
- VLOG(1) << "ReadLocalData: " << object_path.value();
- device::BluetoothOutOfBandPairingData data;
- callback.Run(data, false);
- }
-
- // BluetoothOutOfBandClient override.
- virtual void AddRemoteData(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const device::BluetoothOutOfBandPairingData& data,
- const SuccessCallback& callback) OVERRIDE {
- VLOG(1) << "AddRemoteData: " << object_path.value();
- callback.Run(false);
- }
-
- // BluetoothOutOfBandClient override.
- virtual void RemoveRemoteData(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const SuccessCallback& callback) OVERRIDE {
- VLOG(1) << "RemoveRemoteData: " << object_path.value();
- callback.Run(false);
- }
-};
-
-BluetoothOutOfBandClient::BluetoothOutOfBandClient() {}
-
-BluetoothOutOfBandClient::~BluetoothOutOfBandClient() {}
-
-BluetoothOutOfBandClient* BluetoothOutOfBandClient::Create(
- DBusClientImplementationType type,
- dbus::Bus* bus) {
- if (type == REAL_DBUS_CLIENT_IMPLEMENTATION)
- return new BluetoothOutOfBandClientImpl(bus);
- DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type);
- return new BluetoothOutOfBandClientStubImpl();
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_out_of_band_client.h b/chromeos/dbus/bluetooth_out_of_band_client.h
deleted file mode 100644
index e39cd61..0000000
--- a/chromeos/dbus/bluetooth_out_of_band_client.h
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_OUT_OF_BAND_CLIENT_H_
-#define CHROMEOS_DBUS_BLUETOOTH_OUT_OF_BAND_CLIENT_H_
-
-#include <string>
-
-#include "base/callback.h"
-#include "chromeos/chromeos_export.h"
-#include "chromeos/dbus/dbus_client_implementation_type.h"
-#include "dbus/object_path.h"
-
-namespace dbus {
-class Bus;
-} // namespace dbus
-
-namespace device {
-struct BluetoothOutOfBandPairingData;
-} // namespace device
-
-namespace chromeos {
-
-// BluetoothOutOfBandClient is used to manage Out Of Band Pairing
-// Data for the local adapter and remote devices.
-class CHROMEOS_EXPORT BluetoothOutOfBandClient {
- public:
- virtual ~BluetoothOutOfBandClient();
-
- typedef base::Callback<void(
- const device::BluetoothOutOfBandPairingData& data,
- bool success)> DataCallback;
-
- typedef base::Callback<void(bool success)> SuccessCallback;
-
- // Reads the local Out Of Band Pairing Data and return it in |callback|.
- virtual void ReadLocalData(
- const dbus::ObjectPath& object_path,
- const DataCallback& callback) = 0;
-
- // Sets the Out Of Band Pairing Data for the device at |address| to |data|,
- // indicating success via |callback|. Makes a copy of |data|.
- virtual void AddRemoteData(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const device::BluetoothOutOfBandPairingData& data,
- const SuccessCallback& callback) = 0;
-
- // Clears the Out Of Band Pairing Data for the device at |address|, indicating
- // success via |callback|.
- virtual void RemoveRemoteData(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const SuccessCallback& callback) = 0;
-
- // Creates the instance.
- static BluetoothOutOfBandClient* Create(
- DBusClientImplementationType type,
- dbus::Bus* bus);
-
- protected:
- BluetoothOutOfBandClient();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(BluetoothOutOfBandClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_OUT_OF_BAND_CLIENT_H_
diff --git a/chromeos/dbus/bluetooth_property.cc b/chromeos/dbus/bluetooth_property.cc
deleted file mode 100644
index 73c67b0..0000000
--- a/chromeos/dbus/bluetooth_property.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/bluetooth_property.h"
-
-#include "base/bind.h"
-#include "dbus/message.h"
-#include "dbus/object_proxy.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-void BluetoothPropertySet::ConnectSignals() {
- dbus::ObjectProxy* object_proxy = this->object_proxy();
- DCHECK(object_proxy);
- object_proxy->ConnectToSignal(
- interface(),
- bluetooth_common::kPropertyChangedSignal,
- base::Bind(&dbus::PropertySet::ChangedReceived, GetWeakPtr()),
- base::Bind(&dbus::PropertySet::ChangedConnected, GetWeakPtr()));
-}
-
-void BluetoothPropertySet::ChangedReceived(dbus::Signal* signal) {
- DCHECK(signal);
-
- dbus::MessageReader reader(signal);
- UpdatePropertyFromReader(&reader);
-}
-
-void BluetoothPropertySet::Get(dbus::PropertyBase* property,
- GetCallback callback) {
- NOTREACHED() << "BlueZ does not implement Get for properties";
-}
-
-void BluetoothPropertySet::GetAll() {
- dbus::MethodCall method_call(interface(),
- bluetooth_common::kGetProperties);
-
- dbus::ObjectProxy* object_proxy = this->object_proxy();
- DCHECK(object_proxy);
- object_proxy->CallMethod(&method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&dbus::PropertySet::OnGetAll,
- GetWeakPtr()));
-}
-
-void BluetoothPropertySet::Set(dbus::PropertyBase* property,
- SetCallback callback) {
- dbus::MethodCall method_call(interface(),
- bluetooth_common::kSetProperty);
- dbus::MessageWriter writer(&method_call);
- writer.AppendString(property->name());
- property->AppendSetValueToWriter(&writer);
-
- dbus::ObjectProxy *object_proxy = this->object_proxy();
- DCHECK(object_proxy);
- object_proxy->CallMethod(&method_call,
- dbus::ObjectProxy::TIMEOUT_USE_DEFAULT,
- base::Bind(&dbus::PropertySet::OnSet,
- this->GetWeakPtr(),
- property,
- callback));
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/bluetooth_property.h b/chromeos/dbus/bluetooth_property.h
deleted file mode 100644
index 303b8cd..0000000
--- a/chromeos/dbus/bluetooth_property.h
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_BLUETOOTH_PROPERTY_H_
-#define CHROMEOS_DBUS_BLUETOOTH_PROPERTY_H_
-
-#include <string>
-
-#include "base/compiler_specific.h"
-#include "dbus/message.h"
-#include "dbus/object_proxy.h"
-#include "dbus/property.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-namespace chromeos {
-
-// BlueZ predates the common D-Bus Properties API (though it inspired it),
-// override dbus::PropertySet to generate the correct method call to get
-// all properties, conenect to the correct signal and parse it correctly.
-class BluetoothPropertySet : public dbus::PropertySet {
- public:
- BluetoothPropertySet(dbus::ObjectProxy* object_proxy,
- const std::string& interface,
- const PropertyChangedCallback& callback)
- : dbus::PropertySet(object_proxy, interface, callback) {}
-
- // dbus::PropertySet override.
- //
- // Call after construction to connect property change notification
- // signals. Sub-classes may override to use different D-Bus signals.
- virtual void ConnectSignals() OVERRIDE;
-
- // dbus::PropertySet override.
- //
- // Requests an updated value from the remote object incurring a round-trip.
- virtual void Get(dbus::PropertyBase* property,
- GetCallback callback) OVERRIDE;
-
- // dbus::PropertySet override.
- //
- // Queries the remote object for values of all properties and updates
- // initial values.
- virtual void GetAll() OVERRIDE;
-
- // dbus::PropertySet override.
- //
- // Requests that the remote object change the property to its new value.
- virtual void Set(dbus::PropertyBase* property,
- SetCallback callback) OVERRIDE;
-
- // dbus::PropertySet override.
- //
- // Method connected by ConnectSignals() and called by dbus:: when
- // a property is changed.
- virtual void ChangedReceived(dbus::Signal* signal) OVERRIDE;
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_BLUETOOTH_PROPERTY_H_
diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc
index 8b521e5..ed6e2c8 100644
--- a/chromeos/dbus/dbus_thread_manager.cc
+++ b/chromeos/dbus/dbus_thread_manager.cc
@@ -11,12 +11,6 @@
#include "base/observer_list.h"
#include "base/threading/thread.h"
#include "chromeos/chromeos_switches.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_input_client.h"
-#include "chromeos/dbus/bluetooth_manager_client.h"
-#include "chromeos/dbus/bluetooth_node_client.h"
-#include "chromeos/dbus/bluetooth_out_of_band_client.h"
#include "chromeos/dbus/cras_audio_client.h"
#include "chromeos/dbus/cros_disks_client.h"
#include "chromeos/dbus/cryptohome_client.h"
@@ -89,18 +83,6 @@ class DBusThreadManagerImpl : public DBusThreadManager {
// NOTE: Clients that access other clients in their constructor must be
// construced in the correct order.
void InitializeClients() {
- bluetooth_manager_client_.reset(BluetoothManagerClient::Create(
- client_type_, system_bus_.get()));
- bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create(
- client_type_, system_bus_.get(), bluetooth_manager_client_.get()));
- bluetooth_device_client_.reset(BluetoothDeviceClient::Create(
- client_type_, system_bus_.get(), bluetooth_adapter_client_.get()));
- bluetooth_input_client_.reset(BluetoothInputClient::Create(
- client_type_, system_bus_.get(), bluetooth_adapter_client_.get()));
- bluetooth_node_client_.reset(BluetoothNodeClient::Create(
- client_type_, system_bus_.get(), bluetooth_device_client_.get()));
- bluetooth_out_of_band_client_.reset(BluetoothOutOfBandClient::Create(
- client_type_, system_bus_.get()));
cras_audio_client_.reset(CrasAudioClient::Create(
client_type_, system_bus_.get()));
cros_disks_client_.reset(
@@ -245,30 +227,6 @@ class DBusThreadManagerImpl : public DBusThreadManager {
return ibus_bus_.get();
}
- virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE {
- return bluetooth_adapter_client_.get();
- }
-
- virtual BluetoothDeviceClient* GetBluetoothDeviceClient() OVERRIDE {
- return bluetooth_device_client_.get();
- }
-
- virtual BluetoothInputClient* GetBluetoothInputClient() OVERRIDE {
- return bluetooth_input_client_.get();
- }
-
- virtual BluetoothManagerClient* GetBluetoothManagerClient() OVERRIDE {
- return bluetooth_manager_client_.get();
- }
-
- virtual BluetoothNodeClient* GetBluetoothNodeClient() OVERRIDE {
- return bluetooth_node_client_.get();
- }
-
- virtual BluetoothOutOfBandClient* GetBluetoothOutOfBandClient() OVERRIDE {
- return bluetooth_out_of_band_client_.get();
- }
-
virtual CrasAudioClient* GetCrasAudioClient() OVERRIDE {
return cras_audio_client_.get();
}
@@ -429,12 +387,6 @@ class DBusThreadManagerImpl : public DBusThreadManager {
scoped_ptr<base::Thread> dbus_thread_;
scoped_refptr<dbus::Bus> system_bus_;
scoped_refptr<dbus::Bus> ibus_bus_;
- scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
- scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_;
- scoped_ptr<BluetoothInputClient> bluetooth_input_client_;
- scoped_ptr<BluetoothManagerClient> bluetooth_manager_client_;
- scoped_ptr<BluetoothNodeClient> bluetooth_node_client_;
- scoped_ptr<BluetoothOutOfBandClient> bluetooth_out_of_band_client_;
scoped_ptr<CrasAudioClient> cras_audio_client_;
scoped_ptr<CrosDisksClient> cros_disks_client_;
scoped_ptr<CryptohomeClient> cryptohome_client_;
diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h
index 30fe91b..89f23b6 100644
--- a/chromeos/dbus/dbus_thread_manager.h
+++ b/chromeos/dbus/dbus_thread_manager.h
@@ -26,12 +26,6 @@ namespace chromeos {
class DBusThreadManagerObserver;
// Style Note: Clients are sorted by names.
-class BluetoothAdapterClient;
-class BluetoothDeviceClient;
-class BluetoothInputClient;
-class BluetoothManagerClient;
-class BluetoothNodeClient;
-class BluetoothOutOfBandClient;
class CrasAudioClient;
class CrosDisksClient;
class CryptohomeClient;
@@ -126,12 +120,6 @@ class CHROMEOS_EXPORT DBusThreadManager {
// All returned objects are owned by DBusThreadManager. Do not cache these
// pointers and use them after DBusThreadManager has been shut down.
- virtual BluetoothAdapterClient* GetBluetoothAdapterClient() = 0;
- virtual BluetoothDeviceClient* GetBluetoothDeviceClient() = 0;
- virtual BluetoothInputClient* GetBluetoothInputClient() = 0;
- virtual BluetoothManagerClient* GetBluetoothManagerClient() = 0;
- virtual BluetoothNodeClient* GetBluetoothNodeClient() = 0;
- virtual BluetoothOutOfBandClient* GetBluetoothOutOfBandClient() = 0;
virtual CrasAudioClient* GetCrasAudioClient() = 0;
virtual CrosDisksClient* GetCrosDisksClient() = 0;
virtual CryptohomeClient* GetCryptohomeClient() = 0;
diff --git a/chromeos/dbus/experimental_bluetooth_input_client.cc b/chromeos/dbus/experimental_bluetooth_input_client.cc
index e4febed..aee73c3 100644
--- a/chromeos/dbus/experimental_bluetooth_input_client.cc
+++ b/chromeos/dbus/experimental_bluetooth_input_client.cc
@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "base/stl_util.h"
-#include "chromeos/dbus/bluetooth_property.h"
#include "chromeos/dbus/fake_bluetooth_input_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
diff --git a/chromeos/dbus/fake_bluetooth_input_client.cc b/chromeos/dbus/fake_bluetooth_input_client.cc
index a52831b..841eae3 100644
--- a/chromeos/dbus/fake_bluetooth_input_client.cc
+++ b/chromeos/dbus/fake_bluetooth_input_client.cc
@@ -8,7 +8,6 @@
#include "base/logging.h"
#include "base/stl_util.h"
-#include "chromeos/dbus/bluetooth_property.h"
#include "chromeos/dbus/fake_bluetooth_device_client.h"
#include "dbus/bus.h"
#include "dbus/message.h"
diff --git a/chromeos/dbus/fake_old_bluetooth_adapter_client.cc b/chromeos/dbus/fake_old_bluetooth_adapter_client.cc
deleted file mode 100644
index 12ca37c..0000000
--- a/chromeos/dbus/fake_old_bluetooth_adapter_client.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright (c) 2013 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 "chromeos/dbus/fake_old_bluetooth_adapter_client.h"
-
-namespace chromeos {
-
-FakeOldBluetoothAdapterClient::Properties::Properties(
- const PropertyChangedCallback& callback) :
- BluetoothAdapterClient::Properties(NULL, callback) {
-}
-
-FakeOldBluetoothAdapterClient::Properties::~Properties() {
-}
-
-void FakeOldBluetoothAdapterClient::Properties::Get(
- dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback) {
- VLOG(1)<< "Get " << property->name();
- callback.Run(false);
-}
-
-void FakeOldBluetoothAdapterClient::Properties::GetAll() {
- VLOG(1) << "GetAll";
-}
-
-void FakeOldBluetoothAdapterClient::Properties::Set(
- dbus::PropertyBase *property,
- dbus::PropertySet::SetCallback callback) {
- VLOG(1) << "Set " << property->name();
- if (property->name() == "Powered") {
- property->ReplaceValueWithSetValue();
- callback.Run(true);
- } else {
- callback.Run(false);
- }
-}
-
-FakeOldBluetoothAdapterClient::FakeOldBluetoothAdapterClient() {
- properties_.reset(new Properties(base::Bind(
- &FakeOldBluetoothAdapterClient::OnPropertyChanged,
- base::Unretained(this))));
-
- properties_->address.ReplaceValue("hci0");
- properties_->name.ReplaceValue("Fake Adapter");
- properties_->pairable.ReplaceValue(true);
-
- std::vector<dbus::ObjectPath> devices;
- devices.push_back(dbus::ObjectPath("/fake/hci0/dev0"));
- properties_->devices.ReplaceValue(devices);
-}
-
-FakeOldBluetoothAdapterClient::~FakeOldBluetoothAdapterClient() {
-}
-
-void FakeOldBluetoothAdapterClient::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
-}
-
-void FakeOldBluetoothAdapterClient::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-FakeOldBluetoothAdapterClient::Properties*
-FakeOldBluetoothAdapterClient::GetProperties(
- const dbus::ObjectPath& object_path) {
- VLOG(1) << "GetProperties: " << object_path.value();
- if (object_path.value() == "/fake/hci0")
- return properties_.get();
- else
- return NULL;
-}
-
-void FakeOldBluetoothAdapterClient::RequestSession(
- const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) {
- VLOG(1) << "RequestSession: " << object_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::ReleaseSession(
- const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) {
- VLOG(1) << "ReleaseSession: " << object_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::StartDiscovery(
- const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) {
- VLOG(1) << "StartDiscovery: " << object_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::StopDiscovery(
- const dbus::ObjectPath & object_path,
- const AdapterCallback& callback) {
- VLOG(1) << "StopDiscovery: " << object_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::FindDevice(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const DeviceCallback& callback) {
- VLOG(1) << "FindDevice: " << object_path.value() << " " << address;
- callback.Run(dbus::ObjectPath(), false);
-}
-
-void FakeOldBluetoothAdapterClient::CreateDevice(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback) {
- VLOG(1) << "CreateDevice: " << object_path.value() << " " << address;
- error_callback.Run("", "");
-}
-
-void FakeOldBluetoothAdapterClient::CreatePairedDevice(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const dbus::ObjectPath& agent_path,
- const std::string& capability,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback) {
- VLOG(1) << "CreatePairedDevice: " << object_path.value() << " " << address
- << " " << agent_path.value() << " " << capability;
- error_callback.Run("", "");
-}
-
-void FakeOldBluetoothAdapterClient::CancelDeviceCreation(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const AdapterCallback& callback) {
- VLOG(1) << "CancelDeviceCreation: " << object_path.value()
- << " " << address;
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::RemoveDevice(
- const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& device_path,
- const AdapterCallback& callback) {
- VLOG(1) << "RemoveDevice: " << object_path.value()
- << " " << device_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::RegisterAgent(
- const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const std::string& capability,
- const AdapterCallback& callback) {
- VLOG(1) << "RegisterAgent: " << object_path.value()
- << " " << agent_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::UnregisterAgent(
- const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const AdapterCallback& callback) {
- VLOG(1) << "UnregisterAgent: " << object_path.value()
- << " " << agent_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothAdapterClient::OnPropertyChanged(
- const std::string&property_name) {
- FOR_EACH_OBSERVER(BluetoothAdapterClient::Observer, observers_,
- AdapterPropertyChanged(dbus::ObjectPath("/fake/hci0"),
- property_name));
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/fake_old_bluetooth_adapter_client.h b/chromeos/dbus/fake_old_bluetooth_adapter_client.h
deleted file mode 100644
index fc73f4f..0000000
--- a/chromeos/dbus/fake_old_bluetooth_adapter_client.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright (c) 2013 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 CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_ADAPTER_CLIENT_H_
-#define CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_ADAPTER_CLIENT_H_
-
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-
-namespace chromeos {
-
-// A fake implementation of BluetoothAdapterClient used on Linux desktop and for
-// tests. This class does nothing.
-class FakeOldBluetoothAdapterClient : public BluetoothAdapterClient {
- public:
- struct Properties : public BluetoothAdapterClient::Properties {
- explicit Properties(const PropertyChangedCallback& callback);
- virtual ~Properties();
-
- // BluetoothAdapterClient::Properties overrides.
- virtual void Get(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback) OVERRIDE;
- virtual void GetAll() OVERRIDE;
- virtual void Set(dbus::PropertyBase *property,
- dbus::PropertySet::SetCallback callback) OVERRIDE;
- };
-
- FakeOldBluetoothAdapterClient();
- virtual ~FakeOldBluetoothAdapterClient();
-
- // BluetoothAdapterClient overrides.
- virtual void AddObserver(Observer* observer) OVERRIDE;
- virtual void RemoveObserver(Observer* observer) OVERRIDE;
- virtual Properties* GetProperties(
- const dbus::ObjectPath& object_path) OVERRIDE;
- virtual void RequestSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE;
- virtual void ReleaseSession(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE;
- virtual void StartDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE;
- virtual void StopDiscovery(const dbus::ObjectPath& object_path,
- const AdapterCallback& callback) OVERRIDE;
- virtual void FindDevice(const dbus::ObjectPath& object_path,
- const std::string& address,
- const DeviceCallback& callback) OVERRIDE;
- virtual void CreateDevice(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback) OVERRIDE;
- virtual void CreatePairedDevice(
- const dbus::ObjectPath& object_path,
- const std::string& address,
- const dbus::ObjectPath& agent_path,
- const std::string& capability,
- const CreateDeviceCallback& callback,
- const CreateDeviceErrorCallback& error_callback) OVERRIDE;
- virtual void CancelDeviceCreation(const dbus::ObjectPath& object_path,
- const std::string& address,
- const AdapterCallback& callback) OVERRIDE;
- virtual void RemoveDevice(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& device_path,
- const AdapterCallback& callback) OVERRIDE;
- virtual void RegisterAgent(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const std::string& capability,
- const AdapterCallback& callback) OVERRIDE;
- virtual void UnregisterAgent(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& agent_path,
- const AdapterCallback& callback) OVERRIDE;
-
- // List of observers interested in event notifications from us.
- ObserverList<Observer> observers_;
-
- // Static properties we return.
- scoped_ptr<Properties> properties_;
-
- private:
- void OnPropertyChanged(const std::string& property_name);
-
- DISALLOW_COPY_AND_ASSIGN(FakeOldBluetoothAdapterClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_ADAPTER_CLIENT_H_
diff --git a/chromeos/dbus/fake_old_bluetooth_device_client.cc b/chromeos/dbus/fake_old_bluetooth_device_client.cc
deleted file mode 100644
index a06a426..0000000
--- a/chromeos/dbus/fake_old_bluetooth_device_client.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright (c) 2013 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 "base/stl_util.h"
-#include "chromeos/dbus/fake_old_bluetooth_device_client.h"
-
-namespace chromeos {
-
-FakeOldBluetoothDeviceClient::Properties::Properties(
- const PropertyChangedCallback& callback) :
- BluetoothDeviceClient::Properties(NULL, callback) {
-}
-
-FakeOldBluetoothDeviceClient::Properties::~Properties() {
-}
-
-void FakeOldBluetoothDeviceClient::Properties::Get(
- dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback) {
- VLOG(1)<< "Get " << property->name();
- callback.Run(false);
-}
-
-void FakeOldBluetoothDeviceClient::Properties::GetAll() {
- VLOG(1) << "GetAll";
-}
-
-void FakeOldBluetoothDeviceClient::Properties::Set(
- dbus::PropertyBase *property,
- dbus::PropertySet::SetCallback callback) {
- VLOG(1) << "Set " << property->name();
- callback.Run(false);
-}
-
-FakeOldBluetoothDeviceClient::FakeOldBluetoothDeviceClient() {
- dbus::ObjectPath dev0("/fake/hci0/dev0");
-
- Properties* properties = new Properties(base::Bind(
- &FakeOldBluetoothDeviceClient::OnPropertyChanged,
- base::Unretained(this),
- dev0));
- properties->address.ReplaceValue("00:11:22:33:44:55");
- properties->name.ReplaceValue("Fake Device");
- properties->paired.ReplaceValue(true);
- properties->trusted.ReplaceValue(true);
-
- properties_map_[dev0] = properties;
-}
-
-FakeOldBluetoothDeviceClient::~FakeOldBluetoothDeviceClient() {
- // Clean up Properties structures
- STLDeleteValues(&properties_map_);
-}
-
-void FakeOldBluetoothDeviceClient::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
-}
-
-void FakeOldBluetoothDeviceClient::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-FakeOldBluetoothDeviceClient::Properties*
-FakeOldBluetoothDeviceClient::GetProperties(
- const dbus::ObjectPath& object_path) {
- VLOG(1)<< "GetProperties: " << object_path.value();
- PropertiesMap::iterator iter = properties_map_.find(object_path);
- if (iter != properties_map_.end())
- return iter->second;
- return NULL;
-}
-
-void FakeOldBluetoothDeviceClient::DiscoverServices(
- const dbus::ObjectPath& object_path,
- const std::string& pattern,
- const ServicesCallback& callback) {
- VLOG(1) << "DiscoverServices: " << object_path.value() << " " << pattern;
-
- ServiceMap services;
- callback.Run(object_path, services, false);
-}
-
-void FakeOldBluetoothDeviceClient::CancelDiscovery(
- const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) {
- VLOG(1) << "CancelDiscovery: " << object_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothDeviceClient::Disconnect(
- const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) {
- VLOG(1) << "Disconnect: " << object_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothDeviceClient::CreateNode(
- const dbus::ObjectPath& object_path,
- const std::string& uuid,
- const NodeCallback& callback) {
- VLOG(1) << "CreateNode: " << object_path.value() << " " << uuid;
- callback.Run(dbus::ObjectPath(), false);
-}
-
-void FakeOldBluetoothDeviceClient::RemoveNode(
- const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& node_path,
- const DeviceCallback& callback) {
- VLOG(1) << "RemoveNode: " << object_path.value()
- << " " << node_path.value();
- callback.Run(object_path, false);
-}
-
-void FakeOldBluetoothDeviceClient::OnPropertyChanged(
- dbus::ObjectPath object_path,
- const std::string& property_name) {
- FOR_EACH_OBSERVER(BluetoothDeviceClient::Observer, observers_,
- DevicePropertyChanged(object_path, property_name));
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/fake_old_bluetooth_device_client.h b/chromeos/dbus/fake_old_bluetooth_device_client.h
deleted file mode 100644
index e957d47..0000000
--- a/chromeos/dbus/fake_old_bluetooth_device_client.h
+++ /dev/null
@@ -1,67 +0,0 @@
-// Copyright (c) 2013 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 CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_DEVICE_CLIENT_H_
-#define CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_DEVICE_CLIENT_H_
-
-#include "chromeos/dbus/bluetooth_device_client.h"
-
-namespace chromeos {
-
-// A fake implementation of BluetoothDeviceClient used on Linux desktop and for
-// tests. . This class does nothing.
-class FakeOldBluetoothDeviceClient : public BluetoothDeviceClient {
- public:
- struct Properties : public BluetoothDeviceClient::Properties {
- explicit Properties(const PropertyChangedCallback& callback);
-
- virtual ~Properties();
-
- // BluetoothDeviceClient::Properties overrides.
- virtual void Get(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback) OVERRIDE;
- virtual void GetAll() OVERRIDE;
- virtual void Set(dbus::PropertyBase *property,
- dbus::PropertySet::SetCallback callback) OVERRIDE;
- };
-
- FakeOldBluetoothDeviceClient();
- virtual ~FakeOldBluetoothDeviceClient();
-
- // BluetoothDeviceClient overrides.
- virtual void AddObserver(Observer* observer) OVERRIDE;
- virtual void RemoveObserver(Observer* observer) OVERRIDE;
- virtual Properties* GetProperties(
- const dbus::ObjectPath& object_path) OVERRIDE;
- virtual void DiscoverServices(const dbus::ObjectPath& object_path,
- const std::string& pattern,
- const ServicesCallback& callback) OVERRIDE;
- virtual void CancelDiscovery(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) OVERRIDE;
- virtual void Disconnect(const dbus::ObjectPath& object_path,
- const DeviceCallback& callback) OVERRIDE;
- virtual void CreateNode(const dbus::ObjectPath& object_path,
- const std::string& uuid,
- const NodeCallback& callback) OVERRIDE;
- virtual void RemoveNode(const dbus::ObjectPath& object_path,
- const dbus::ObjectPath& node_path,
- const DeviceCallback& callback) OVERRIDE;
-
- private:
- void OnPropertyChanged(dbus::ObjectPath object_path,
- const std::string& property_name);
-
- // List of observers interested in event notifications from us.
- ObserverList<Observer> observers_;
-
- // Static properties we typedef.
- typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap;
- PropertiesMap properties_map_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeOldBluetoothDeviceClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_DEVICE_CLIENT_H_
diff --git a/chromeos/dbus/fake_old_bluetooth_manager_client.cc b/chromeos/dbus/fake_old_bluetooth_manager_client.cc
deleted file mode 100644
index b26c80a..0000000
--- a/chromeos/dbus/fake_old_bluetooth_manager_client.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright (c) 2013 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 "chromeos/dbus/fake_old_bluetooth_manager_client.h"
-
-namespace chromeos {
-
-FakeOldBluetoothManagerClient::Properties::Properties(
- const PropertyChangedCallback& callback) :
- BluetoothManagerClient::Properties(NULL, callback) {
-}
-
-FakeOldBluetoothManagerClient::Properties::~Properties() {
-}
-
-void FakeOldBluetoothManagerClient::Properties::Get(
- dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback) {
- VLOG(1)<< "Get " << property->name();
- callback.Run(false);
-}
-
-void FakeOldBluetoothManagerClient::Properties::GetAll() {
- VLOG(1) << "GetAll";
-}
-
-void FakeOldBluetoothManagerClient::Properties::Set(
- dbus::PropertyBase*property,
- dbus::PropertySet::SetCallback callback) {
- VLOG(1) << "Set " << property->name();
- callback.Run(false);
-}
-
-FakeOldBluetoothManagerClient::FakeOldBluetoothManagerClient() {
- properties_.reset(new Properties(base::Bind(
- &FakeOldBluetoothManagerClient::OnPropertyChanged,
- base::Unretained(this))));
-
- std::vector<dbus::ObjectPath> adapters;
- adapters.push_back(dbus::ObjectPath("/fake/hci0"));
- properties_->adapters.ReplaceValue(adapters);
-}
-
-FakeOldBluetoothManagerClient::~FakeOldBluetoothManagerClient() {
-}
-
-void FakeOldBluetoothManagerClient::AddObserver(Observer* observer) {
- observers_.AddObserver(observer);
-}
-
-void FakeOldBluetoothManagerClient::RemoveObserver(Observer* observer) {
- observers_.RemoveObserver(observer);
-}
-
-FakeOldBluetoothManagerClient::Properties*
-FakeOldBluetoothManagerClient::GetProperties() {
- VLOG(1) << "GetProperties";
- return properties_.get();
-}
-
-void FakeOldBluetoothManagerClient::DefaultAdapter(
- const AdapterCallback& callback) {
- VLOG(1) << "DefaultAdapter.";
- callback.Run(dbus::ObjectPath("/fake/hci0"), true);
-}
-
-void FakeOldBluetoothManagerClient::FindAdapter(
- const std::string& address,
- const AdapterCallback& callback) {
- VLOG(1) << "FindAdapter: " << address;
- if (address == "hci0")
- callback.Run(dbus::ObjectPath("/fake/hci0"), true);
- else
- callback.Run(dbus::ObjectPath(), false);
-}
-
-void FakeOldBluetoothManagerClient::OnPropertyChanged(
- const std::string& property_name) {
- FOR_EACH_OBSERVER(BluetoothManagerClient::Observer, observers_,
- ManagerPropertyChanged(property_name));
-}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/fake_old_bluetooth_manager_client.h b/chromeos/dbus/fake_old_bluetooth_manager_client.h
deleted file mode 100644
index bbf3edb..0000000
--- a/chromeos/dbus/fake_old_bluetooth_manager_client.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright (c) 2013 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 CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_MANAGER_CLIENT_H_
-#define CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_MANAGER_CLIENT_H_
-
-#include "chromeos/dbus/bluetooth_manager_client.h"
-
-namespace chromeos {
-
-// A fake implementation of BluetoothManagerClient used on Linux desktop and for
-// tests. This class does nothing.
-class FakeOldBluetoothManagerClient : public BluetoothManagerClient {
- public:
- struct Properties : public BluetoothManagerClient::Properties {
- explicit Properties(const PropertyChangedCallback& callback);
- virtual ~Properties();
-
- // BluetoothManagerClient::Properties overrides.
- virtual void Get(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback) OVERRIDE;
- virtual void GetAll() OVERRIDE;
- virtual void Set(dbus::PropertyBase* property,
- dbus::PropertySet::SetCallback callback) OVERRIDE;
- };
-
- FakeOldBluetoothManagerClient();
- virtual ~FakeOldBluetoothManagerClient();
-
- // BluetoothManagerClient overrides.
- virtual void AddObserver(Observer* observer) OVERRIDE;
- virtual void RemoveObserver(Observer* observer) OVERRIDE;
- virtual Properties* GetProperties() OVERRIDE;
- virtual void DefaultAdapter(const AdapterCallback& callback) OVERRIDE;
- virtual void FindAdapter(const std::string& address,
- const AdapterCallback& callback) OVERRIDE;
-
- private:
- void OnPropertyChanged(const std::string& property_name);
-
- // List of observers interested in event notifications from us.
- ObserverList<Observer> observers_;
-
- // Static properties we return.
- scoped_ptr<Properties> properties_;
-
- DISALLOW_COPY_AND_ASSIGN(FakeOldBluetoothManagerClient);
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_FAKE_OLD_BLUETOOTH_MANAGER_CLIENT_H_
diff --git a/chromeos/dbus/mock_bluetooth_adapter_client.cc b/chromeos/dbus/mock_bluetooth_adapter_client.cc
deleted file mode 100644
index 73b3d54..0000000
--- a/chromeos/dbus/mock_bluetooth_adapter_client.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_adapter_client.h"
-
-namespace chromeos {
-
-MockBluetoothAdapterClient::Properties::Properties()
- : BluetoothAdapterClient::Properties::Properties(
- NULL, PropertyChangedCallback()) {}
-
-MockBluetoothAdapterClient::Properties::~Properties() {}
-
-MockBluetoothAdapterClient::MockBluetoothAdapterClient() {}
-
-MockBluetoothAdapterClient::~MockBluetoothAdapterClient() {}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/mock_bluetooth_adapter_client.h b/chromeos/dbus/mock_bluetooth_adapter_client.h
deleted file mode 100644
index c1d5f1e..0000000
--- a/chromeos/dbus/mock_bluetooth_adapter_client.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_MOCK_BLUETOOTH_ADAPTER_CLIENT_H_
-#define CHROMEOS_DBUS_MOCK_BLUETOOTH_ADAPTER_CLIENT_H_
-
-#include <string>
-
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace chromeos {
-
-class MockBluetoothAdapterClient : public BluetoothAdapterClient {
- public:
- struct Properties : public BluetoothAdapterClient::Properties {
- Properties();
- virtual ~Properties();
-
- MOCK_METHOD0(ConnectSignals, void());
-
- MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback));
- MOCK_METHOD0(GetAll, void());
- MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
- dbus::PropertySet::SetCallback callback));
-
- MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
- };
-
- MockBluetoothAdapterClient();
- virtual ~MockBluetoothAdapterClient();
-
- MOCK_METHOD1(AddObserver, void(Observer*));
- MOCK_METHOD1(RemoveObserver, void(Observer*));
- MOCK_METHOD1(GetProperties, Properties*(const dbus::ObjectPath&));
- MOCK_METHOD2(RequestSession, void(const dbus::ObjectPath&,
- const AdapterCallback&));
- MOCK_METHOD2(ReleaseSession, void(const dbus::ObjectPath&,
- const AdapterCallback&));
- MOCK_METHOD2(StartDiscovery, void(const dbus::ObjectPath&,
- const AdapterCallback&));
- MOCK_METHOD2(StopDiscovery, void(const dbus::ObjectPath&,
- const AdapterCallback&));
- MOCK_METHOD3(FindDevice, void(const dbus::ObjectPath&,
- const std::string&,
- const DeviceCallback&));
- MOCK_METHOD4(CreateDevice, void(const dbus::ObjectPath&,
- const std::string&,
- const CreateDeviceCallback&,
- const CreateDeviceErrorCallback&));
- MOCK_METHOD6(CreatePairedDevice, void(const dbus::ObjectPath&,
- const std::string&,
- const dbus::ObjectPath&,
- const std::string&,
- const CreateDeviceCallback&,
- const CreateDeviceErrorCallback&));
- MOCK_METHOD3(CancelDeviceCreation, void(const dbus::ObjectPath&,
- const std::string&,
- const AdapterCallback&));
- MOCK_METHOD3(RemoveDevice, void(const dbus::ObjectPath&,
- const dbus::ObjectPath&,
- const AdapterCallback&));
- MOCK_METHOD4(RegisterAgent, void(const dbus::ObjectPath&,
- const dbus::ObjectPath&,
- const std::string&,
- const AdapterCallback&));
- MOCK_METHOD3(UnregisterAgent, void(const dbus::ObjectPath&,
- const dbus::ObjectPath&,
- const AdapterCallback&));
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_MOCK_BLUETOOTH_ADAPTER_CLIENT_H_
diff --git a/chromeos/dbus/mock_bluetooth_device_client.cc b/chromeos/dbus/mock_bluetooth_device_client.cc
deleted file mode 100644
index f595daa..0000000
--- a/chromeos/dbus/mock_bluetooth_device_client.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_device_client.h"
-
-namespace chromeos {
-
-MockBluetoothDeviceClient::Properties::Properties()
- : BluetoothDeviceClient::Properties::Properties(
- NULL, PropertyChangedCallback()) {}
-
-MockBluetoothDeviceClient::Properties::~Properties() {}
-
-MockBluetoothDeviceClient::MockBluetoothDeviceClient() {}
-
-MockBluetoothDeviceClient::~MockBluetoothDeviceClient() {}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/mock_bluetooth_device_client.h b/chromeos/dbus/mock_bluetooth_device_client.h
deleted file mode 100644
index 94cb8c4..0000000
--- a/chromeos/dbus/mock_bluetooth_device_client.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_MOCK_BLUETOOTH_DEVICE_CLIENT_H_
-#define CHROMEOS_DBUS_MOCK_BLUETOOTH_DEVICE_CLIENT_H_
-
-#include <string>
-
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace chromeos {
-
-class MockBluetoothDeviceClient : public BluetoothDeviceClient {
- public:
- struct Properties : public BluetoothDeviceClient::Properties {
- Properties();
- virtual ~Properties();
-
- MOCK_METHOD0(ConnectSignals, void());
-
- MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback));
- MOCK_METHOD0(GetAll, void());
- MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
- dbus::PropertySet::SetCallback callback));
-
- MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
- };
-
- MockBluetoothDeviceClient();
- virtual ~MockBluetoothDeviceClient();
-
- MOCK_METHOD1(AddObserver, void(Observer*));
- MOCK_METHOD1(RemoveObserver, void(Observer*));
- MOCK_METHOD1(GetProperties, Properties*(const dbus::ObjectPath&));
- MOCK_METHOD3(DiscoverServices, void(const dbus::ObjectPath&,
- const std::string&,
- const ServicesCallback&));
- MOCK_METHOD2(CancelDiscovery, void(const dbus::ObjectPath&,
- const DeviceCallback&));
- MOCK_METHOD2(Disconnect, void(const dbus::ObjectPath&,
- const DeviceCallback&));
- MOCK_METHOD3(CreateNode, void(const dbus::ObjectPath&,
- const std::string&,
- const NodeCallback&));
- MOCK_METHOD3(RemoveNode, void(const dbus::ObjectPath&,
- const dbus::ObjectPath&,
- const NodeCallback&));
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_MOCK_BLUETOOTH_DEVICE_CLIENT_H_
diff --git a/chromeos/dbus/mock_bluetooth_input_client.cc b/chromeos/dbus/mock_bluetooth_input_client.cc
deleted file mode 100644
index 54cc0a0..0000000
--- a/chromeos/dbus/mock_bluetooth_input_client.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_input_client.h"
-
-namespace chromeos {
-
-MockBluetoothInputClient::Properties::Properties()
- : BluetoothInputClient::Properties::Properties(
- NULL, PropertyChangedCallback()) {}
-
-MockBluetoothInputClient::Properties::~Properties() {}
-
-MockBluetoothInputClient::MockBluetoothInputClient() {}
-
-MockBluetoothInputClient::~MockBluetoothInputClient() {}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/mock_bluetooth_input_client.h b/chromeos/dbus/mock_bluetooth_input_client.h
deleted file mode 100644
index 19bfaee..0000000
--- a/chromeos/dbus/mock_bluetooth_input_client.h
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_MOCK_BLUETOOTH_INPUT_CLIENT_H_
-#define CHROMEOS_DBUS_MOCK_BLUETOOTH_INPUT_CLIENT_H_
-
-#include <string>
-
-#include "chromeos/dbus/bluetooth_input_client.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace chromeos {
-
-class MockBluetoothInputClient : public BluetoothInputClient {
- public:
- struct Properties : public BluetoothInputClient::Properties {
- Properties();
- virtual ~Properties();
-
- MOCK_METHOD0(ConnectSignals, void());
-
- MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback));
- MOCK_METHOD0(GetAll, void());
- MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
- dbus::PropertySet::SetCallback callback));
-
- MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
- };
-
- MockBluetoothInputClient();
- virtual ~MockBluetoothInputClient();
-
- MOCK_METHOD1(AddObserver, void(Observer*));
- MOCK_METHOD1(RemoveObserver, void(Observer*));
- MOCK_METHOD1(GetProperties, Properties*(const dbus::ObjectPath&));
- MOCK_METHOD3(Connect, void(const dbus::ObjectPath&,
- const ConnectCallback&,
- const ConnectErrorCallback&));
- MOCK_METHOD2(Disconnect, void(const dbus::ObjectPath&,
- const InputCallback&));
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_MOCK_BLUETOOTH_INPUT_CLIENT_H_
diff --git a/chromeos/dbus/mock_bluetooth_manager_client.cc b/chromeos/dbus/mock_bluetooth_manager_client.cc
deleted file mode 100644
index 3b31d72..0000000
--- a/chromeos/dbus/mock_bluetooth_manager_client.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_manager_client.h"
-
-namespace chromeos {
-
-MockBluetoothManagerClient::Properties::Properties()
- : BluetoothManagerClient::Properties::Properties(
- NULL, PropertyChangedCallback()) {}
-
-MockBluetoothManagerClient::Properties::~Properties() {}
-
-MockBluetoothManagerClient::MockBluetoothManagerClient() {}
-
-MockBluetoothManagerClient::~MockBluetoothManagerClient() {}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/mock_bluetooth_manager_client.h b/chromeos/dbus/mock_bluetooth_manager_client.h
deleted file mode 100644
index b6175c2..0000000
--- a/chromeos/dbus/mock_bluetooth_manager_client.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_MOCK_BLUETOOTH_MANAGER_CLIENT_H_
-#define CHROMEOS_DBUS_MOCK_BLUETOOTH_MANAGER_CLIENT_H_
-
-#include <string>
-
-#include "chromeos/dbus/bluetooth_manager_client.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace chromeos {
-
-class MockBluetoothManagerClient : public BluetoothManagerClient {
- public:
- struct Properties : public BluetoothManagerClient::Properties {
- Properties();
- virtual ~Properties();
-
- MOCK_METHOD0(ConnectSignals, void());
-
- MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback));
- MOCK_METHOD0(GetAll, void());
- MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
- dbus::PropertySet::SetCallback callback));
-
- MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
- };
-
- MockBluetoothManagerClient();
- virtual ~MockBluetoothManagerClient();
-
- MOCK_METHOD1(AddObserver, void(Observer*));
- MOCK_METHOD1(RemoveObserver, void(Observer*));
- MOCK_METHOD0(GetProperties, Properties*());
- MOCK_METHOD1(DefaultAdapter, void(const AdapterCallback& callback));
- MOCK_METHOD2(FindAdapter, void(const std::string&,
- const AdapterCallback& callback));
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_MOCK_BLUETOOTH_MANAGER_CLIENT_H_
diff --git a/chromeos/dbus/mock_bluetooth_node_client.cc b/chromeos/dbus/mock_bluetooth_node_client.cc
deleted file mode 100644
index 9c5efa9..0000000
--- a/chromeos/dbus/mock_bluetooth_node_client.cc
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_node_client.h"
-
-namespace chromeos {
-
-MockBluetoothNodeClient::Properties::Properties()
- : BluetoothNodeClient::Properties::Properties(
- NULL, PropertyChangedCallback()) {}
-
-MockBluetoothNodeClient::Properties::~Properties() {}
-
-MockBluetoothNodeClient::MockBluetoothNodeClient() {}
-
-MockBluetoothNodeClient::~MockBluetoothNodeClient() {}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/mock_bluetooth_node_client.h b/chromeos/dbus/mock_bluetooth_node_client.h
deleted file mode 100644
index dd0b591..0000000
--- a/chromeos/dbus/mock_bluetooth_node_client.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_MOCK_BLUETOOTH_NODE_CLIENT_H_
-#define CHROMEOS_DBUS_MOCK_BLUETOOTH_NODE_CLIENT_H_
-
-#include <string>
-
-#include "chromeos/dbus/bluetooth_node_client.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace chromeos {
-
-class MockBluetoothNodeClient : public BluetoothNodeClient {
- public:
- struct Properties : public BluetoothNodeClient::Properties {
- Properties();
- virtual ~Properties();
-
- MOCK_METHOD0(ConnectSignals, void());
-
- MOCK_METHOD2(Get, void(dbus::PropertyBase* property,
- dbus::PropertySet::GetCallback callback));
- MOCK_METHOD0(GetAll, void());
- MOCK_METHOD2(Set, void(dbus::PropertyBase* property,
- dbus::PropertySet::SetCallback callback));
-
- MOCK_METHOD1(ChangedReceived, void(dbus::Signal*));
- };
-
- MockBluetoothNodeClient();
- virtual ~MockBluetoothNodeClient();
-
- MOCK_METHOD1(AddObserver, void(Observer*));
- MOCK_METHOD1(RemoveObserver, void(Observer*));
- MOCK_METHOD1(GetProperties, Properties*(const dbus::ObjectPath&));
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_MOCK_BLUETOOTH_NODE_CLIENT_H_
diff --git a/chromeos/dbus/mock_bluetooth_out_of_band_client.cc b/chromeos/dbus/mock_bluetooth_out_of_band_client.cc
deleted file mode 100644
index da6ef011..0000000
--- a/chromeos/dbus/mock_bluetooth_out_of_band_client.cc
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_out_of_band_client.h"
-
-namespace chromeos {
-
-MockBluetoothOutOfBandClient::MockBluetoothOutOfBandClient() {}
-
-MockBluetoothOutOfBandClient::~MockBluetoothOutOfBandClient() {}
-
-} // namespace chromeos
diff --git a/chromeos/dbus/mock_bluetooth_out_of_band_client.h b/chromeos/dbus/mock_bluetooth_out_of_band_client.h
deleted file mode 100644
index 9b4be7f..0000000
--- a/chromeos/dbus/mock_bluetooth_out_of_band_client.h
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright (c) 2012 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 CHROMEOS_DBUS_MOCK_BLUETOOTH_OUT_OF_BAND_CLIENT_H_
-#define CHROMEOS_DBUS_MOCK_BLUETOOTH_OUT_OF_BAND_CLIENT_H_
-
-#include <string>
-
-#include "base/memory/scoped_ptr.h"
-#include "chromeos/dbus/bluetooth_out_of_band_client.h"
-#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
-#include "testing/gmock/include/gmock/gmock.h"
-
-namespace chromeos {
-
-class MockBluetoothOutOfBandClient : public BluetoothOutOfBandClient {
- public:
- MockBluetoothOutOfBandClient();
- virtual ~MockBluetoothOutOfBandClient();
-
- MOCK_METHOD2(ReadLocalData,
- void(const dbus::ObjectPath&,
- const DataCallback&));
- MOCK_METHOD4(AddRemoteData,
- void(const dbus::ObjectPath&,
- const std::string&,
- const device::BluetoothOutOfBandPairingData&,
- const SuccessCallback&));
- MOCK_METHOD3(RemoveRemoteData,
- void(const dbus::ObjectPath&,
- const std::string&,
- const SuccessCallback&));
-};
-
-} // namespace chromeos
-
-#endif // CHROMEOS_DBUS_MOCK_BLUETOOTH_OUT_OF_BAND_CLIENT_H_
diff --git a/chromeos/dbus/mock_dbus_thread_manager.cc b/chromeos/dbus/mock_dbus_thread_manager.cc
index cdf7d0c..518e745 100644
--- a/chromeos/dbus/mock_dbus_thread_manager.cc
+++ b/chromeos/dbus/mock_dbus_thread_manager.cc
@@ -16,12 +16,6 @@
#include "chromeos/dbus/ibus/mock_ibus_engine_service.h"
#include "chromeos/dbus/ibus/mock_ibus_input_context_client.h"
#include "chromeos/dbus/ibus/mock_ibus_panel_service.h"
-#include "chromeos/dbus/mock_bluetooth_adapter_client.h"
-#include "chromeos/dbus/mock_bluetooth_device_client.h"
-#include "chromeos/dbus/mock_bluetooth_input_client.h"
-#include "chromeos/dbus/mock_bluetooth_manager_client.h"
-#include "chromeos/dbus/mock_bluetooth_node_client.h"
-#include "chromeos/dbus/mock_bluetooth_out_of_band_client.h"
#include "chromeos/dbus/mock_cryptohome_client.h"
#include "chromeos/dbus/mock_shill_device_client.h"
#include "chromeos/dbus/mock_shill_ipconfig_client.h"
@@ -63,12 +57,6 @@ MockDBusThreadManager::MockDBusThreadManager()
fake_bluetooth_input_client_(new FakeBluetoothInputClient()),
fake_bluetooth_profile_manager_client_(
new FakeBluetoothProfileManagerClient()),
- mock_bluetooth_adapter_client_(new MockBluetoothAdapterClient),
- mock_bluetooth_device_client_(new MockBluetoothDeviceClient),
- mock_bluetooth_input_client_(new MockBluetoothInputClient),
- mock_bluetooth_manager_client_(new MockBluetoothManagerClient),
- mock_bluetooth_node_client_(new MockBluetoothNodeClient),
- mock_bluetooth_out_of_band_client_(new MockBluetoothOutOfBandClient),
mock_cryptohome_client_(new MockCryptohomeClient),
mock_shill_device_client_(new MockShillDeviceClient),
mock_shill_ipconfig_client_(new MockShillIPConfigClient),
@@ -77,18 +65,6 @@ MockDBusThreadManager::MockDBusThreadManager()
mock_shill_service_client_(new MockShillServiceClient),
mock_gsm_sms_client_(new MockGsmSMSClient),
mock_session_manager_client_(new MockSessionManagerClient) {
- EXPECT_CALL(*this, GetBluetoothAdapterClient())
- .WillRepeatedly(Return(mock_bluetooth_adapter_client_.get()));
- EXPECT_CALL(*this, GetBluetoothDeviceClient())
- .WillRepeatedly(Return(mock_bluetooth_device_client_.get()));
- EXPECT_CALL(*this, GetBluetoothInputClient())
- .WillRepeatedly(Return(mock_bluetooth_input_client_.get()));
- EXPECT_CALL(*this, GetBluetoothManagerClient())
- .WillRepeatedly(Return(mock_bluetooth_manager_client()));
- EXPECT_CALL(*this, GetBluetoothNodeClient())
- .WillRepeatedly(Return(mock_bluetooth_node_client_.get()));
- EXPECT_CALL(*this, GetBluetoothOutOfBandClient())
- .WillRepeatedly(Return(mock_bluetooth_out_of_band_client_.get()));
EXPECT_CALL(*this, GetCryptohomeClient())
.WillRepeatedly(Return(mock_cryptohome_client()));
EXPECT_CALL(*this, GetExperimentalBluetoothAdapterClient())
@@ -128,30 +104,6 @@ MockDBusThreadManager::MockDBusThreadManager()
.Times(AnyNumber());
EXPECT_CALL(*mock_session_manager_client_.get(), HasObserver(_))
.Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_manager_client_.get(), AddObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_manager_client_.get(), RemoveObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_adapter_client_.get(), AddObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_adapter_client_.get(), RemoveObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_device_client_.get(), AddObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_device_client_.get(), RemoveObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_input_client_.get(), AddObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_input_client_.get(), RemoveObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_node_client_.get(), AddObserver(_))
- .Times(AnyNumber());
- EXPECT_CALL(*mock_bluetooth_node_client_.get(), RemoveObserver(_))
- .Times(AnyNumber());
-
- // Called from BluetoothManagerImpl ctor.
- EXPECT_CALL(*mock_bluetooth_manager_client_.get(), DefaultAdapter(_))
- .Times(AnyNumber());
// Called from AsyncMethodCaller ctor and dtor.
EXPECT_CALL(*mock_cryptohome_client_.get(), SetAsyncCallStatusHandlers(_, _))
diff --git a/chromeos/dbus/mock_dbus_thread_manager.h b/chromeos/dbus/mock_dbus_thread_manager.h
index 3759692..33cb2f1 100644
--- a/chromeos/dbus/mock_dbus_thread_manager.h
+++ b/chromeos/dbus/mock_dbus_thread_manager.h
@@ -25,12 +25,6 @@ class FakeBluetoothAgentManagerClient;
class FakeBluetoothDeviceClient;
class FakeBluetoothInputClient;
class FakeBluetoothProfileManagerClient;
-class MockBluetoothAdapterClient;
-class MockBluetoothDeviceClient;
-class MockBluetoothInputClient;
-class MockBluetoothManagerClient;
-class MockBluetoothNodeClient;
-class MockBluetoothOutOfBandClient;
class MockCryptohomeClient;
class MockShillDeviceClient;
class MockShillIPConfigClient;
@@ -57,12 +51,6 @@ class MockDBusThreadManager : public DBusThreadManager {
const base::Closure& closure));
MOCK_METHOD0(GetSystemBus, dbus::Bus*(void));
MOCK_METHOD0(GetIBusBus, dbus::Bus*(void));
- MOCK_METHOD0(GetBluetoothAdapterClient, BluetoothAdapterClient*(void));
- MOCK_METHOD0(GetBluetoothDeviceClient, BluetoothDeviceClient*(void));
- MOCK_METHOD0(GetBluetoothInputClient, BluetoothInputClient*(void));
- MOCK_METHOD0(GetBluetoothManagerClient, BluetoothManagerClient*(void));
- MOCK_METHOD0(GetBluetoothNodeClient, BluetoothNodeClient*(void));
- MOCK_METHOD0(GetBluetoothOutOfBandClient, BluetoothOutOfBandClient*(void));
MOCK_METHOD0(GetCrasAudioClient, CrasAudioClient*(void));
MOCK_METHOD0(GetCrosDisksClient, CrosDisksClient*(void));
MOCK_METHOD0(GetCryptohomeClient, CryptohomeClient*(void));
@@ -118,24 +106,6 @@ class MockDBusThreadManager : public DBusThreadManager {
FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client() {
return fake_bluetooth_profile_manager_client_.get();
}
- MockBluetoothAdapterClient* mock_bluetooth_adapter_client() {
- return mock_bluetooth_adapter_client_.get();
- }
- MockBluetoothDeviceClient* mock_bluetooth_device_client() {
- return mock_bluetooth_device_client_.get();
- }
- MockBluetoothInputClient* mock_bluetooth_input_client() {
- return mock_bluetooth_input_client_.get();
- }
- MockBluetoothManagerClient* mock_bluetooth_manager_client() {
- return mock_bluetooth_manager_client_.get();
- }
- MockBluetoothNodeClient* mock_bluetooth_node_client() {
- return mock_bluetooth_node_client_.get();
- }
- MockBluetoothOutOfBandClient* mock_bluetooth_out_of_band_client() {
- return mock_bluetooth_out_of_band_client_.get();
- }
MockCryptohomeClient* mock_cryptohome_client() {
return mock_cryptohome_client_.get();
}
@@ -173,12 +143,6 @@ class MockDBusThreadManager : public DBusThreadManager {
scoped_ptr<FakeBluetoothInputClient> fake_bluetooth_input_client_;
scoped_ptr<FakeBluetoothProfileManagerClient>
fake_bluetooth_profile_manager_client_;
- scoped_ptr<MockBluetoothAdapterClient> mock_bluetooth_adapter_client_;
- scoped_ptr<MockBluetoothDeviceClient> mock_bluetooth_device_client_;
- scoped_ptr<MockBluetoothInputClient> mock_bluetooth_input_client_;
- scoped_ptr<MockBluetoothManagerClient> mock_bluetooth_manager_client_;
- scoped_ptr<MockBluetoothNodeClient> mock_bluetooth_node_client_;
- scoped_ptr<MockBluetoothOutOfBandClient> mock_bluetooth_out_of_band_client_;
scoped_ptr<MockCryptohomeClient> mock_cryptohome_client_;
scoped_ptr<MockShillDeviceClient> mock_shill_device_client_;
scoped_ptr<MockShillIPConfigClient> mock_shill_ipconfig_client_;
diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
index a9fb3de..6d38aca 100644
--- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
+++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.cc
@@ -4,9 +4,6 @@
#include "chromeos/dbus/mock_dbus_thread_manager_without_gmock.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/dbus_thread_manager_observer.h"
#include "chromeos/dbus/fake_bluetooth_adapter_client.h"
#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
@@ -17,9 +14,6 @@
#include "chromeos/dbus/fake_cryptohome_client.h"
#include "chromeos/dbus/fake_gsm_sms_client.h"
#include "chromeos/dbus/fake_image_burner_client.h"
-#include "chromeos/dbus/fake_old_bluetooth_adapter_client.h"
-#include "chromeos/dbus/fake_old_bluetooth_device_client.h"
-#include "chromeos/dbus/fake_old_bluetooth_manager_client.h"
#include "chromeos/dbus/fake_power_manager_client.h"
#include "chromeos/dbus/fake_session_manager_client.h"
#include "chromeos/dbus/fake_shill_manager_client.h"
@@ -51,9 +45,6 @@ MockDBusThreadManagerWithoutGMock::MockDBusThreadManagerWithoutGMock()
fake_system_clock_client_(new FakeSystemClockClient),
fake_power_manager_client_(new FakePowerManagerClient),
fake_update_engine_client_(new FakeUpdateEngineClient),
- fake_old_bluetooth_manager_client_(new FakeOldBluetoothManagerClient),
- fake_old_bluetooth_adapter_client_(new FakeOldBluetoothAdapterClient),
- fake_old_bluetooth_device_client_(new FakeOldBluetoothDeviceClient),
ibus_bus_(NULL) {
power_policy_controller_.reset(
new PowerPolicyController(this, fake_power_manager_client_.get()));
@@ -97,33 +88,6 @@ dbus::Bus* MockDBusThreadManagerWithoutGMock::GetIBusBus() {
return ibus_bus_;
}
-BluetoothAdapterClient*
- MockDBusThreadManagerWithoutGMock::GetBluetoothAdapterClient() {
- return fake_old_bluetooth_adapter_client_.get();
-}
-
-BluetoothDeviceClient*
- MockDBusThreadManagerWithoutGMock::GetBluetoothDeviceClient() {
- return fake_old_bluetooth_device_client_.get();
-}
-
-BluetoothInputClient*
- MockDBusThreadManagerWithoutGMock::GetBluetoothInputClient() {
- NOTIMPLEMENTED();
- return NULL;
-}
-
-BluetoothManagerClient*
- MockDBusThreadManagerWithoutGMock::GetBluetoothManagerClient() {
- return fake_old_bluetooth_manager_client_.get();
-}
-
-BluetoothNodeClient*
- MockDBusThreadManagerWithoutGMock::GetBluetoothNodeClient() {
- NOTIMPLEMENTED();
- return NULL;
-}
-
CrasAudioClient* MockDBusThreadManagerWithoutGMock::GetCrasAudioClient() {
return NULL;
}
@@ -250,12 +214,6 @@ UpdateEngineClient* MockDBusThreadManagerWithoutGMock::GetUpdateEngineClient() {
return fake_update_engine_client_.get();
}
-BluetoothOutOfBandClient*
- MockDBusThreadManagerWithoutGMock::GetBluetoothOutOfBandClient() {
- NOTIMPLEMENTED();
- return NULL;
-}
-
IBusClient* MockDBusThreadManagerWithoutGMock::GetIBusClient() {
return mock_ibus_client_.get();
}
diff --git a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
index effa2cb..3810cea 100644
--- a/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
+++ b/chromeos/dbus/mock_dbus_thread_manager_without_gmock.h
@@ -27,9 +27,6 @@ class FakeBluetoothProfileManagerClient;
class FakeCrosDisksClient;
class FakeCryptohomeClient;
class FakeGsmSMSClient;
-class FakeOldBluetoothAdapterClient;
-class FakeOldBluetoothDeviceClient;
-class FakeOldBluetoothManagerClient;
class FakePowerManagerClient;
class FakeImageBurnerClient;
class FakeSessionManagerClient;
@@ -60,11 +57,6 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager {
virtual dbus::Bus* GetSystemBus() OVERRIDE;
virtual dbus::Bus* GetIBusBus() OVERRIDE;
- virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE;
- virtual BluetoothDeviceClient* GetBluetoothDeviceClient() OVERRIDE;
- virtual BluetoothInputClient* GetBluetoothInputClient() OVERRIDE;
- virtual BluetoothManagerClient* GetBluetoothManagerClient() OVERRIDE;
- virtual BluetoothNodeClient* GetBluetoothNodeClient() OVERRIDE;
virtual CrasAudioClient* GetCrasAudioClient() OVERRIDE;
virtual CrosDisksClient* GetCrosDisksClient() OVERRIDE;
virtual CryptohomeClient* GetCryptohomeClient() OVERRIDE;
@@ -95,7 +87,6 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager {
virtual SMSClient* GetSMSClient() OVERRIDE;
virtual SystemClockClient* GetSystemClockClient() OVERRIDE;
virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE;
- virtual BluetoothOutOfBandClient* GetBluetoothOutOfBandClient() OVERRIDE;
virtual IBusClient* GetIBusClient() OVERRIDE;
virtual IBusConfigClient* GetIBusConfigClient() OVERRIDE;
virtual IBusInputContextClient* GetIBusInputContextClient() OVERRIDE;
@@ -213,12 +204,6 @@ class MockDBusThreadManagerWithoutGMock : public DBusThreadManager {
scoped_ptr<FakePowerManagerClient> fake_power_manager_client_;
scoped_ptr<FakeUpdateEngineClient> fake_update_engine_client_;
- // These fake_old_bluetooth_*_client_ are for old Bluetooth*Client.
- // Will be removed once http://crbug.com/221813 is resolved.
- scoped_ptr<FakeOldBluetoothManagerClient> fake_old_bluetooth_manager_client_;
- scoped_ptr<FakeOldBluetoothAdapterClient> fake_old_bluetooth_adapter_client_;
- scoped_ptr<FakeOldBluetoothDeviceClient> fake_old_bluetooth_device_client_;
-
scoped_ptr<MockIBusClient> mock_ibus_client_;
scoped_ptr<MockIBusConfigClient> mock_ibus_config_client_;
scoped_ptr<MockIBusInputContextClient> mock_ibus_input_context_client_;
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
deleted file mode 100644
index c24341b..0000000
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc
+++ /dev/null
@@ -1,536 +0,0 @@
-// Copyright (c) 2012 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/bluetooth_adapter_chromeos.h"
-
-#include <string>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "base/values.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/dbus_thread_manager.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_device_chromeos.h"
-#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
-
-using device::BluetoothAdapter;
-using device::BluetoothDevice;
-using device::BluetoothOutOfBandPairingData;
-
-namespace chromeos {
-
-BluetoothAdapterChromeOS::BluetoothAdapterChromeOS() : BluetoothAdapter(),
- powered_(false),
- discovering_(false),
- discovering_count_(0),
- weak_ptr_factory_(this) {
- DBusThreadManager::Get()->GetBluetoothManagerClient()->
- AddObserver(this);
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- AddObserver(this);
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- AddObserver(this);
-
- DBusThreadManager::Get()->GetBluetoothManagerClient()->
- DefaultAdapter(base::Bind(&BluetoothAdapterChromeOS::AdapterCallback,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() {
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- RemoveObserver(this);
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- RemoveObserver(this);
- DBusThreadManager::Get()->GetBluetoothManagerClient()->
- RemoveObserver(this);
-
- STLDeleteValues(&devices_);
-}
-
-void BluetoothAdapterChromeOS::AddObserver(
- BluetoothAdapter::Observer* observer) {
- DCHECK(observer);
- observers_.AddObserver(observer);
-}
-
-void BluetoothAdapterChromeOS::RemoveObserver(
- BluetoothAdapter::Observer* observer) {
- DCHECK(observer);
- observers_.RemoveObserver(observer);
-}
-
-std::string BluetoothAdapterChromeOS::GetAddress() const {
- return address_;
-}
-
-std::string BluetoothAdapterChromeOS::GetName() const {
- return name_;
-}
-
-// 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();
-}
-
-bool BluetoothAdapterChromeOS::IsPowered() const {
- return powered_;
-}
-
-void BluetoothAdapterChromeOS::SetPowered(bool powered,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- GetProperties(object_path_)->powered.Set(
- powered,
- base::Bind(&BluetoothAdapterChromeOS::OnSetPowered,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-bool BluetoothAdapterChromeOS::IsDiscovering() const {
- return discovering_;
-}
-
-void BluetoothAdapterChromeOS::StartDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- // BlueZ counts discovery sessions, and permits multiple sessions for a
- // single connection, so issue a StartDiscovery() call for every use
- // within Chromium for the right behavior.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- StartDiscovery(object_path_,
- base::Bind(
- &BluetoothAdapterChromeOS::OnStartDiscovery,
- weak_ptr_factory_.GetWeakPtr(),
- callback, error_callback));
-}
-
-void BluetoothAdapterChromeOS::StopDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- // Inform BlueZ to stop one of our open discovery sessions.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- StopDiscovery(object_path_,
- base::Bind(
- &BluetoothAdapterChromeOS::OnStopDiscovery,
- weak_ptr_factory_.GetWeakPtr(),
- callback, error_callback));
-}
-
-void BluetoothAdapterChromeOS::ReadLocalOutOfBandPairingData(
- const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
- ReadLocalData(object_path_,
- base::Bind(&BluetoothAdapterChromeOS::OnReadLocalData,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothAdapterChromeOS::AdapterCallback(
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (success) {
- ChangeAdapter(adapter_path);
- } else if (!object_path_.value().empty()) {
- RemoveAdapter();
- }
-}
-
-void BluetoothAdapterChromeOS::DefaultAdapterChanged(
- const dbus::ObjectPath& adapter_path) {
- ChangeAdapter(adapter_path);
-}
-
-void BluetoothAdapterChromeOS::AdapterRemoved(
- const dbus::ObjectPath& adapter_path) {
- if (adapter_path == object_path_)
- RemoveAdapter();
-}
-
-void BluetoothAdapterChromeOS::ChangeAdapter(
- const dbus::ObjectPath& adapter_path) {
- if (object_path_.value().empty()) {
- VLOG(1) << "Adapter path initialized to " << adapter_path.value();
- } else if (object_path_.value() != adapter_path.value()) {
- VLOG(1) << "Adapter path changed from " << object_path_.value()
- << " to " << adapter_path.value();
-
- RemoveAdapter();
- } else {
- VLOG(1) << "Adapter address updated";
- }
-
- object_path_ = adapter_path;
-
- // Update properties to their new values.
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- GetProperties(object_path_);
-
- address_ = properties->address.value();
- name_ = properties->name.value();
-
- // Delay announcing a new adapter until we have an address.
- if (address_.empty()) {
- VLOG(1) << "Adapter address not yet known";
- return;
- }
-
- PoweredChanged(properties->powered.value());
- DiscoveringChanged(properties->discovering.value());
- DevicesChanged(properties->devices.value());
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterPresentChanged(this, true));
-}
-
-void BluetoothAdapterChromeOS::RemoveAdapter() {
- const bool adapter_was_present = IsPresent();
-
- VLOG(1) << "Adapter lost.";
- PoweredChanged(false);
- DiscoveringChanged(false);
- ClearDevices();
-
- object_path_ = dbus::ObjectPath("");
- address_.clear();
- name_.clear();
-
- if (adapter_was_present)
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterPresentChanged(this, false));
-}
-
-void BluetoothAdapterChromeOS::OnSetPowered(const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success) {
- if (success)
- callback.Run();
- else
- error_callback.Run();
-}
-
-void BluetoothAdapterChromeOS::PoweredChanged(bool powered) {
- if (powered == powered_)
- return;
-
- powered_ = powered;
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterPoweredChanged(this, powered_));
-}
-
-void BluetoothAdapterChromeOS::NotifyDeviceChanged(
- BluetoothDeviceChromeOS* device) {
- DCHECK(device->adapter_ == this);
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceChanged(this, device));
-}
-
-void BluetoothAdapterChromeOS::OnStartDiscovery(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (success) {
- if (discovering_count_++ == 0) {
- VLOG(1) << object_path_.value() << ": started discovery.";
-
- // Clear devices found in previous discovery attempts
- ClearDiscoveredDevices();
- }
-
- callback.Run();
- } else {
- error_callback.Run();
- }
-}
-
-void BluetoothAdapterChromeOS::OnStopDiscovery(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (success) {
- if (--discovering_count_ == 0) {
- VLOG(1) << object_path_.value() << ": stopped discovery.";
- } else if (discovering_count_ < 0) {
- LOG(WARNING) << adapter_path.value() << ": call to StopDiscovering "
- << "without matching StartDiscovering.";
- error_callback.Run();
- return;
- }
-
- callback.Run();
-
- // Leave found devices available for perusing.
- } else {
- error_callback.Run();
- }
-}
-
-void BluetoothAdapterChromeOS::DiscoveringChanged(bool discovering) {
- if (discovering == discovering_)
- return;
-
- discovering_ = discovering;
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterDiscoveringChanged(this, discovering_));
-}
-
-void BluetoothAdapterChromeOS::OnReadLocalData(
- const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback,
- const ErrorCallback& error_callback,
- const BluetoothOutOfBandPairingData& data,
- bool success) {
- if (success)
- callback.Run(data);
- else
- error_callback.Run();
-}
-
-void BluetoothAdapterChromeOS::AdapterPropertyChanged(
- const dbus::ObjectPath& adapter_path,
- const std::string& property_name) {
- if (adapter_path != object_path_)
- return;
-
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- GetProperties(object_path_);
-
- if (property_name == properties->address.name()) {
- ChangeAdapter(object_path_);
-
- } else if (!address_.empty()) {
- if (property_name == properties->powered.name()) {
- PoweredChanged(properties->powered.value());
-
- } else if (property_name == properties->discovering.name()) {
- DiscoveringChanged(properties->discovering.value());
-
- } else if (property_name == properties->devices.name()) {
- DevicesChanged(properties->devices.value());
-
- } else if (property_name == properties->name.name()) {
- name_ = properties->name.value();
-
- }
- }
-}
-
-void BluetoothAdapterChromeOS::DevicePropertyChanged(
- const dbus::ObjectPath& device_path,
- const std::string& property_name) {
- UpdateDevice(device_path);
-}
-
-void BluetoothAdapterChromeOS::UpdateDevice(
- const dbus::ObjectPath& device_path) {
- BluetoothDeviceClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- GetProperties(device_path);
-
- // When we first see a device, we may not know the address yet and need to
- // wait for the DevicePropertyChanged signal before adding the device.
- const std::string address = properties->address.value();
- if (address.empty())
- return;
-
- // The device may be already known to us, either because this is an update
- // to properties, or the device going from discovered to connected and
- // 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);
- BluetoothDeviceChromeOS* device;
- const bool update_device = (iter != devices_.end());
- if (update_device) {
- device = static_cast<BluetoothDeviceChromeOS*>(iter->second);
- } else {
- device = BluetoothDeviceChromeOS::Create(this);
- devices_[address] = device;
- }
-
- if (!device->HasObjectPath()) {
- VLOG(1) << "Assigned object path " << device_path.value() << " to device "
- << address;
- device->SetObjectPath(device_path);
- }
- device->Update(properties, true);
-
- if (update_device)
- NotifyDeviceChanged(device);
- else {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceAdded(this, device));
- }
-}
-
-void BluetoothAdapterChromeOS::ClearDevices() {
- DevicesMap replace;
- devices_.swap(replace);
- for (DevicesMap::iterator iter = replace.begin();
- iter != replace.end(); ++iter) {
- BluetoothDevice* device = iter->second;
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- delete device;
- }
-}
-
-void BluetoothAdapterChromeOS::DeviceCreated(
- const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& device_path) {
- if (adapter_path != object_path_)
- return;
-
- UpdateDevice(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()) {
- BluetoothDeviceChromeOS* device =
- static_cast<BluetoothDeviceChromeOS*>(iter->second);
- DevicesMap::iterator temp = iter;
- ++iter;
-
- if (device->object_path_ != device_path)
- continue;
-
- // DeviceRemoved can also be called to indicate a device that is visible
- // during discovery has disconnected, but it is still visible to the
- // adapter, so don't remove in that case and only clear the object path.
- if (!device->WasDiscovered()) {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- VLOG(1) << "Removed device " << device->GetAddress();
-
- delete device;
- devices_.erase(temp);
- } else {
- VLOG(1) << "Removed object path from device " << device->GetAddress();
- device->RemoveObjectPath();
-
- NotifyDeviceChanged(device);
- }
- }
-}
-
-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 BluetoothAdapterChromeOS::ClearDiscoveredDevices() {
- DevicesMap::iterator iter = devices_.begin();
- while (iter != devices_.end()) {
- BluetoothDeviceChromeOS* device =
- static_cast<BluetoothDeviceChromeOS*>(iter->second);
- DevicesMap::iterator temp = iter;
- ++iter;
-
- if (!device->HasObjectPath()) {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- delete device;
- devices_.erase(temp);
-
- } else
- device->SetDiscovered(false);
- }
-}
-
-void BluetoothAdapterChromeOS::DeviceFound(
- const dbus::ObjectPath& adapter_path,
- const std::string& address,
- const BluetoothDeviceClient::Properties& properties) {
- if (adapter_path != object_path_)
- return;
-
- // 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.
- BluetoothDeviceChromeOS* device;
- DevicesMap::iterator iter = devices_.find(address);
- const bool update_device = (iter != devices_.end());
- if (update_device) {
- device = static_cast<BluetoothDeviceChromeOS*>(iter->second);
- } else {
- device = BluetoothDeviceChromeOS::Create(this);
- devices_[address] = device;
- }
-
- VLOG(1) << "Device " << address << " is visible to the adapter";
- device->SetDiscovered(true);
- device->Update(&properties, false);
-
- if (update_device)
- NotifyDeviceChanged(device);
- else {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceAdded(this, device));
- }
-}
-
-void BluetoothAdapterChromeOS::DeviceDisappeared(
- const dbus::ObjectPath& adapter_path,
- const std::string& address) {
- if (adapter_path != object_path_)
- return;
-
- DevicesMap::iterator iter = devices_.find(address);
- if (iter == devices_.end())
- return;
-
- 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
- // in that case and only clear the visible flag.
- if (!device->HasObjectPath()) {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- VLOG(1) << "Discovered device " << device->GetAddress()
- << " is no longer visible to the adapter";
-
- delete device;
- devices_.erase(iter);
- } else {
- VLOG(1) << "Paired device " << device->GetAddress()
- << " is no longer visible to the adapter";
- device->SetDiscovered(false);
-
- NotifyDeviceChanged(device);
- }
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h
deleted file mode 100644
index 3f422b6..0000000
--- a/device/bluetooth/bluetooth_adapter_chromeos.h
+++ /dev/null
@@ -1,241 +0,0 @@
-// Copyright (c) 2012 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_BLUETOOTH_ADAPTER_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/callback.h"
-#include "base/observer_list.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_manager_client.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter.h"
-
-namespace device {
-
-class BluetoothAdapterFactory;
-class MockBluetoothAdapter;
-struct BluetoothOutOfBandPairingData;
-
-} // namespace device
-
-namespace chromeos {
-
-class BluetoothDeviceChromeOS;
-
-// The BluetoothAdapterChromeOS class is an implementation of BluetoothAdapter
-// for Chrome OS platform.
-class BluetoothAdapterChromeOS
- : public device::BluetoothAdapter,
- public BluetoothManagerClient::Observer,
- public BluetoothAdapterClient::Observer,
- public BluetoothDeviceClient::Observer {
- public:
- // BluetoothAdapter override
- virtual void AddObserver(
- device::BluetoothAdapter::Observer* observer) OVERRIDE;
- virtual void RemoveObserver(
- device::BluetoothAdapter::Observer* observer) OVERRIDE;
- virtual std::string GetAddress() const OVERRIDE;
- virtual std::string GetName() const OVERRIDE;
- virtual bool IsInitialized() const OVERRIDE;
- virtual bool IsPresent() const OVERRIDE;
- virtual bool IsPowered() const OVERRIDE;
- virtual void SetPowered(
- bool powered,
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual bool IsDiscovering() const OVERRIDE;
- virtual void StartDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void StopDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void ReadLocalOutOfBandPairingData(
- const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
- callback,
- const ErrorCallback& error_callback) OVERRIDE;
-
- private:
- friend class BluetoothDeviceChromeOS;
- friend class device::BluetoothAdapterFactory;
- friend class device::MockBluetoothAdapter;
-
- BluetoothAdapterChromeOS();
- virtual ~BluetoothAdapterChromeOS();
-
- // Called by dbus:: in response to the method call sent by DefaultAdapter().
- // |object_path| will contain the dbus object path of the requested adapter
- // when |success| is true.
- void AdapterCallback(const dbus::ObjectPath& adapter_path, bool success);
-
- // BluetoothManagerClient::Observer override.
- //
- // Called when the default local bluetooth adapter changes.
- // |object_path| is the dbus object path of the new default adapter.
- // Not called if all adapters are removed.
- virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter_path)
- OVERRIDE;
-
- // BluetoothManagerClient::Observer override.
- //
- // Called when a local bluetooth adapter is removed.
- // |object_path| is the dbus object path of the adapter.
- virtual void AdapterRemoved(const dbus::ObjectPath& adapter_path) OVERRIDE;
-
- // Changes the tracked adapter to the dbus object path |adapter_path|,
- // clearing information from the previously tracked adapter and updating
- // to the new adapter.
- void ChangeAdapter(const dbus::ObjectPath& adapter_path);
-
- // Clears the tracked adapter information.
- void RemoveAdapter();
-
- // Called by dbus:: in response to the method call send by SetPowered().
- // |callback| and |error_callback| are the callbacks passed to SetPowered().
- void OnSetPowered(const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success);
-
- // Updates the tracked state of the adapter's radio power to |powered|
- // and notifies observers. Called on receipt of a property changed signal,
- // and directly using values obtained from properties.
- void PoweredChanged(bool powered);
-
- // Notifies observers of a change in the device |device|. Used to signal
- // changes initiated from the BluetoothDeviceChromeOS itself.
- void NotifyDeviceChanged(BluetoothDeviceChromeOS* device);
-
- // Called by BluetoothAdapterClient in response to the method call sent
- // by StartDiscovering(), |callback| and |error_callback| are the callbacks
- // provided to that method.
- void OnStartDiscovery(const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success);
-
- // Called by BluetoothAdapterClient in response to the method call sent
- // by StopDiscovering(), |callback| and |error_callback| are the callbacks
- // provided to that method.
- void OnStopDiscovery(const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success);
-
- // Updates the tracked state of the adapter's discovering state to
- // |discovering| and notifies observers. Called on receipt of a property
- // changed signal, and directly using values obtained from properties.
- void DiscoveringChanged(bool discovering);
-
- // Called by dbus:: in response to the ReadLocalData method call.
- void OnReadLocalData(
- const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
- callback,
- const ErrorCallback& error_callback,
- const device::BluetoothOutOfBandPairingData& data,
- bool success);
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |adapter_path| has a
- // change in value of the property named |property_name|.
- virtual void AdapterPropertyChanged(const dbus::ObjectPath& adapter_path,
- const std::string& property_name)
- OVERRIDE;
-
- // BluetoothDeviceClient::Observer override.
- //
- // Called when the device with object path |device_path| has a
- // change in value of the property named |property_name|.
- virtual void DevicePropertyChanged(const dbus::ObjectPath& device_path,
- const std::string& property_name)
- OVERRIDE;
-
- // Updates information on the device with object path |device_path|,
- // adding it to the |devices_| map if not already present.
- void UpdateDevice(const dbus::ObjectPath& device_path);
-
- // Clears the |devices_| list, notifying obsevers of the device removal.
- void ClearDevices();
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| has a
- // new known device with object path |object_path|.
- virtual void DeviceCreated(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& device_path) OVERRIDE;
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| removes
- // the known device with object path |object_path|.
- virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& device_path) OVERRIDE;
-
- // Updates the adapter |devices_| list, adding or updating devices using
- // the object paths in the|devices| list. This doesn't remove devices,
- // relying instead on the DeviceRemoved() signal for that. Called on
- // receipt of a property changed signal, and directly using values obtained
- // from properties.
- void DevicesChanged(const std::vector<dbus::ObjectPath>& devices);
-
- // Clears discovered devices from the |devices_| list, notifying
- // observers, and leaving only those devices with a dbus object path.
- void ClearDiscoveredDevices();
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| discovers
- // a new remote device with address |address| and properties
- // |properties|, there is no device object path until connected.
- //
- // |properties| supports only value() calls, not Get() or Set(), and
- // should be copied if needed.
- virtual void DeviceFound(
- const dbus::ObjectPath& adapter_path,
- const std::string& address,
- const BluetoothDeviceClient::Properties& properties) OVERRIDE;
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| can no
- // longer communicate with the discovered removed device with
- // address |address|.
- virtual void DeviceDisappeared(const dbus::ObjectPath& object_path,
- const std::string& address) OVERRIDE;
-
- // List of observers interested in event notifications from us.
- ObserverList<device::BluetoothAdapter::Observer> observers_;
-
- // Object path of adapter for this instance, we update it to always
- // point at the default adapter.
- dbus::ObjectPath object_path_;
-
- // Tracked adapter state, cached locally so we only send change notifications
- // to observers on a genuine change.
- std::string address_;
- std::string name_;
- bool powered_;
- bool discovering_;
-
- // Count of callers to StartDiscovering() and StopDiscovering(), used to
- // track whether to clear the discovered devices list on start.
- int discovering_count_;
-
- // 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_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
diff --git a/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc b/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc
deleted file mode 100644
index 59cb632..0000000
--- a/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc
+++ /dev/null
@@ -1,2226 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_adapter_client.h"
-#include "chromeos/dbus/mock_bluetooth_manager_client.h"
-#include "chromeos/dbus/mock_dbus_thread_manager.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter.h"
-#include "device/bluetooth/bluetooth_adapter_chromeos.h"
-#include "device/bluetooth/bluetooth_adapter_factory.h"
-#include "device/bluetooth/test/mock_bluetooth_adapter.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using device::BluetoothAdapter;
-using device::BluetoothAdapterFactory;
-using device::MockBluetoothAdapter;
-using ::testing::_;
-using ::testing::InSequence;
-using ::testing::Return;
-using ::testing::SaveArg;
-
-namespace chromeos {
-
-class BluetoothAdapterChromeOSTest : public testing::Test {
- public:
- virtual void SetUp() {
- MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
-
- EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
- .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
- DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
-
- mock_manager_client_ =
- mock_dbus_thread_manager->mock_bluetooth_manager_client();
- mock_adapter_client_ =
- mock_dbus_thread_manager->mock_bluetooth_adapter_client();
-
- callback_called_ = false;
- error_callback_called_ = false;
- }
-
- virtual void TearDown() {
- adapter_ = NULL;
- DBusThreadManager::Shutdown();
- }
-
- void Callback() {
- callback_called_ = true;
- }
-
- void ErrorCallback() {
- error_callback_called_ = true;
- }
-
- void SetAdapter(scoped_refptr<device::BluetoothAdapter> adapter) {
- adapter_ = adapter;
- }
-
- protected:
- MockBluetoothManagerClient* mock_manager_client_;
- MockBluetoothAdapterClient* mock_adapter_client_;
-
- bool callback_called_;
- bool error_callback_called_;
-
- scoped_refptr<BluetoothAdapter> adapter_;
-};
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterNotPresent) {
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
- ASSERT_TRUE(adapter_ != NULL);
-
- // Call the adapter callback; make out it failed.
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(dbus::ObjectPath(""), false);
-
- // Adapter should not be present.
- EXPECT_FALSE(adapter_->IsPresent());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged will be called to
- // indicate the adapter is now present.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should be present with the given address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called
- // yet.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should not be present yet.
- EXPECT_FALSE(adapter_->IsPresent());
-
- // Tell the adapter the address now;
- // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should be present with the given address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterBecomesPresentWithAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback; make out it failed.
- adapter_callback.Run(dbus::ObjectPath(""), false);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(adapter_path);
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterReplacedWithAddress) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must be called once
- // with false to indicate the old adapter being removed and once with true
- // to announce the new adapter.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(new_adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterBecomesPresentWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback; make out it failed.
- adapter_callback.Run(dbus::ObjectPath(""), false);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(adapter_path);
-
- // Adapter should not be present yet.
- EXPECT_FALSE(adapter_->IsPresent());
-
- // Tell the adapter the address now;
- // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterReplacedWithoutAddress) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must be called to
- // indicate the adapter has gone away.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should be now marked not present.
- EXPECT_FALSE(adapter_->IsPresent());
-
- // Tell the adapter the address now;
- // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(new_adapter_path,
- new_adapter_properties.address.name());
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(new_adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterRemoved) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterPresentChanged will be called to
- // indicate the adapter is no longer present.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should be no longer present.
- EXPECT_FALSE(adapter_->IsPresent());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithoutAddressRemoved) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called
- // since we never should have announced it in the first place.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should be still no longer present.
- EXPECT_FALSE(adapter_->IsPresent());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyInitiallyFalse) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyInitiallyTrue) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyInitiallyTrueWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.powered.ReplaceValue(true);
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsPowered());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterPoweredPropertyChanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsPowered());
-
- // Report that the property has been changed;
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_properties.powered.ReplaceValue(true);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.powered.name());
-
- // Adapter should have the new property values.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterPoweredPropertyUnchanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-
- // Report that the property has been changed, but don't change the value;
- // BluetoothAdapter::Observer::AdapterPoweredChanged should not be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.powered.name());
-
- // Adapter should still have the same property values.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyChangedWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Tell the adapter that its powered property changed, the observer
- // method should still not be called because there is no address for
- // the adapter so it is not present.
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.powered.name());
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsPowered());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should now have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyResetOnReplace) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "00:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyResetOnReplaceWhenTrue) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
- new_adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called once
- // to set the value to false for the previous adapter and once to set the
- // value to true for the new adapter.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
- }
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyResetOnRemove) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSetPowered) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Request that the powered property be changed;
- // MockBluetoothAdapterClient::Set should be called, passing the address
- // of the powered property and a callback to receive the response.
- dbus::PropertySet::SetCallback set_callback;
- EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _))
- .WillOnce(SaveArg<1>(&set_callback));
-
- adapter_->SetPowered(true,
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Reply to the callback to indicate success, the set callback we provided
- // should be called but the properties should not be refetched.
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .Times(0);
-
- set_callback.Run(true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSetPoweredError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Request that the powered property be changed;
- // MockBluetoothAdapterClient::Set should be called, passing the address
- // of the powered property and a callback to receive the response.
- dbus::PropertySet::SetCallback set_callback;
- EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _))
- .WillOnce(SaveArg<1>(&set_callback));
-
- adapter_->SetPowered(true,
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Reply to the callback to indicate failure, the error callback we provided
- // should be called but the properties should not be refetched.
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .Times(0);
-
- set_callback.Run(false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyInitiallyFalse) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyInitiallyTrue) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyInitiallyTrueWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.discovering.ReplaceValue(true);
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterDiscoveringPropertyChanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-
- // Report that the property has been changed;
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_properties.discovering.ReplaceValue(true);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.discovering.name());
-
- // Adapter should have the new property values.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyUnchanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-
- // Report that the property has been changed, but don't change the value;
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged should not be
- // called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.discovering.name());
-
- // Adapter should still have the same property values.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyChangedWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Tell the adapter that its discovering property changed, the observer
- // method should still not be called because there is no address for
- // the adapter so it is not present.
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.discovering.name());
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should now have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyResetOnReplace) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- EXPECT_CALL(adapter_observer,
- AdapterDiscoveringChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyResetOnReplaceWhenTrue) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
- new_adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called once
- // to set the value to false for the previous adapter and once to set the
- // value to true for the new adapter.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(),
- false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(),
- true))
- .Times(1);
- }
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyResetOnRemove) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer,
- AdapterDiscoveringChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterNotInitiallyDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStartDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStartDiscoveringError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- start_discovery_callback.Run(adapter_path, false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSecondStartDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success again.
- start_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterSecondStartDiscoveringError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- start_discovery_callback.Run(adapter_path, false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStopDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStopDiscoveringError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- stop_discovery_callback.Run(adapter_path, false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterStopDiscoveringAfterSecondStart) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterStopDiscoveringAfterSecondStartError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- start_discovery_callback.Run(adapter_path, false);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterSecondStopDiscoveringAfterSecondStart) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices again;
- // BluetoothAdapterClient::StopDiscovery will be called.
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc b/device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc
deleted file mode 100644
index 723941a..0000000
--- a/device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc
+++ /dev/null
@@ -1,173 +0,0 @@
-// Copyright (c) 2012 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 "chromeos/dbus/mock_bluetooth_adapter_client.h"
-#include "chromeos/dbus/mock_bluetooth_device_client.h"
-#include "chromeos/dbus/mock_bluetooth_manager_client.h"
-#include "chromeos/dbus/mock_dbus_thread_manager.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter.h"
-#include "device/bluetooth/bluetooth_adapter_chromeos.h"
-#include "device/bluetooth/bluetooth_adapter_factory.h"
-#include "device/bluetooth/test/mock_bluetooth_adapter.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using device::BluetoothAdapter;
-using device::BluetoothAdapterFactory;
-using device::BluetoothDevice;
-using device::MockBluetoothAdapter;
-using ::testing::_;
-using ::testing::Mock;
-using ::testing::Return;
-using ::testing::SaveArg;
-
-namespace chromeos {
-
-class BluetoothAdapterDevicesChromeOSTest : public testing::Test {
- public:
- virtual void SetUp() {
- MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
-
- EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
- .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
- DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
-
- mock_manager_client_ =
- mock_dbus_thread_manager->mock_bluetooth_manager_client();
- mock_adapter_client_ =
- mock_dbus_thread_manager->mock_bluetooth_adapter_client();
- mock_device_client_ =
- mock_dbus_thread_manager->mock_bluetooth_device_client();
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- EXPECT_CALL(*mock_manager_client_, AddObserver(_))
- .Times(1);
- EXPECT_CALL(*mock_adapter_client_, AddObserver(_))
- .Times(1);
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterDevicesChromeOSTest::SetAdapter,
- base::Unretained(this)));
- ASSERT_TRUE(adapter_ != NULL);
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address_);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path_))
- .WillRepeatedly(Return(&adapter_properties));
-
- // Add an observer to the adapter; expect the usual set of changes to
- // an adapter becoming present and then clear to clean up for the test.
- adapter_->AddObserver(&adapter_observer_);
-
- EXPECT_CALL(adapter_observer_, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- EXPECT_CALL(adapter_observer_, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path_, true);
-
- Mock::VerifyAndClearExpectations(mock_manager_client_);
- Mock::VerifyAndClearExpectations(mock_adapter_client_);
- Mock::VerifyAndClearExpectations(mock_device_client_);
- Mock::VerifyAndClearExpectations(&adapter_observer_);
- }
-
- virtual void TearDown() {
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
- EXPECT_CALL(*mock_device_client_, RemoveObserver(adapter_chromeos))
- .Times(1);
- EXPECT_CALL(*mock_adapter_client_, RemoveObserver(adapter_chromeos))
- .Times(1);
- EXPECT_CALL(*mock_manager_client_, RemoveObserver(adapter_chromeos))
- .Times(1);
-
- adapter_ = NULL;
- DBusThreadManager::Shutdown();
- }
-
- void SetAdapter(scoped_refptr<device::BluetoothAdapter> adapter) {
- adapter_ = adapter;
- }
-
- protected:
- MockBluetoothManagerClient* mock_manager_client_;
- MockBluetoothAdapterClient* mock_adapter_client_;
- MockBluetoothDeviceClient* mock_device_client_;
-
- static const dbus::ObjectPath adapter_path_;
- static const std::string adapter_address_;
- scoped_refptr<BluetoothAdapter> adapter_;
-
- MockBluetoothAdapter::Observer adapter_observer_;
-};
-
-const dbus::ObjectPath BluetoothAdapterDevicesChromeOSTest::adapter_path_(
- "/fake/hci0");
-const std::string BluetoothAdapterDevicesChromeOSTest::adapter_address_ =
- "CA:FE:4A:C0:FE:FE";
-
-TEST_F(BluetoothAdapterDevicesChromeOSTest, DeviceRemovedAfterFound) {
- const dbus::ObjectPath device_path("/fake/hci0/dev_ba_c0_11_00_00_01");
- const std::string device_address = "BA:C0:11:00:00:01";
-
- MockBluetoothDeviceClient::Properties device_properties;
- device_properties.address.ReplaceValue(device_address);
- device_properties.name.ReplaceValue("Fake Keyboard");
- device_properties.bluetooth_class.ReplaceValue(0x2540);
-
- // Inform the adapter that the device has been found;
- // BluetoothAdapterClient::Observer::DeviceAdded will be called, passing
- // the device object.
- BluetoothDevice* device;
- EXPECT_CALL(adapter_observer_, DeviceAdded(adapter_.get(), _))
- .Times(1)
- .WillOnce(SaveArg<1>(&device));
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->DeviceFound(adapter_path_, device_address, device_properties);
-
- // Now inform the adapter that the device has been added and assigned an
- // object path; BluetoothDeviceClient::GetProperties will be called to
- // obtain the property set; and
- // BluetoothAdapterClient::Observer::DeviceChanged will be called passing
- // the same device object as before.
- EXPECT_CALL(*mock_device_client_, GetProperties(device_path))
- .WillRepeatedly(Return(&device_properties));
-
- EXPECT_CALL(adapter_observer_, DeviceChanged(adapter_chromeos, device))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->DeviceCreated(adapter_path_, device_path);
-
- // Finally remove the device again;
- // BluetoothAdapterClient::Observer::DeviceRemoved should be not called,
- // instead BluetoothAdapterClient::Observer::DeviceChanged will be called.
- EXPECT_CALL(adapter_observer_, DeviceRemoved(adapter_.get(), device))
- .Times(0);
- EXPECT_CALL(adapter_observer_, DeviceChanged(adapter_.get(), device))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->DeviceRemoved(adapter_path_, device_path);
-
- // Verify that the device is still visible, just no longer paired.
- EXPECT_FALSE(device->IsPaired());
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc
deleted file mode 100644
index 06ffc79..0000000
--- a/device/bluetooth/bluetooth_device_chromeos.cc
+++ /dev/null
@@ -1,892 +0,0 @@
-// Copyright (c) 2012 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/bluetooth_device_chromeos.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "base/memory/scoped_vector.h"
-#include "base/memory/weak_ptr.h"
-#include "base/string16.h"
-#include "base/string_util.h"
-#include "base/values.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_agent_service_provider.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_input_client.h"
-#include "chromeos/dbus/bluetooth_out_of_band_client.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/introspectable_client.h"
-#include "dbus/bus.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter_chromeos.h"
-#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
-#include "device/bluetooth/bluetooth_service_record.h"
-#include "device/bluetooth/bluetooth_service_record_chromeos.h"
-#include "device/bluetooth/bluetooth_socket_chromeos.h"
-#include "device/bluetooth/bluetooth_utils.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-using device::BluetoothDevice;
-using device::BluetoothOutOfBandPairingData;
-using device::BluetoothServiceRecord;
-using device::BluetoothSocket;
-
-namespace {
-
-void DoNothingServiceRecordList(const BluetoothDevice::ServiceRecordList&) {}
-
-} // namespace
-
-namespace chromeos {
-
-BluetoothDeviceChromeOS::BluetoothDeviceChromeOS(
- BluetoothAdapterChromeOS* adapter)
- : BluetoothDevice(),
- adapter_(adapter),
- bluetooth_class_(0),
- paired_(false),
- trusted_(false),
- connected_(false),
- connectable_(true),
- connecting_(false),
- pairing_delegate_(NULL),
- connecting_applications_counter_(0),
- connecting_calls_(0),
- service_records_loaded_(false),
- weak_ptr_factory_(this) {
-}
-
-BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() {
-}
-
-uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const {
- return bluetooth_class_;
-}
-
-std::string BluetoothDeviceChromeOS::GetDeviceName() const {
- return name_;
-}
-
-std::string BluetoothDeviceChromeOS::GetAddress() const {
- return address_;
-}
-
-uint16 BluetoothDeviceChromeOS::GetVendorID() const {
- return 0;
-}
-
-uint16 BluetoothDeviceChromeOS::GetProductID() const {
- return 0;
-}
-
-uint16 BluetoothDeviceChromeOS::GetDeviceID() const {
- return 0;
-}
-
-bool BluetoothDeviceChromeOS::IsPaired() const {
- return paired_ || trusted_;
-}
-
-bool BluetoothDeviceChromeOS::IsConnected() const {
- return connected_;
-}
-
-bool BluetoothDeviceChromeOS::IsConnectable() const {
- return connectable_;
-}
-
-bool BluetoothDeviceChromeOS::IsConnecting() const {
- return connecting_;
-}
-
-BluetoothDeviceChromeOS::ServiceList
-BluetoothDeviceChromeOS::GetServices() const {
- return service_uuids_;
-}
-
-void BluetoothDeviceChromeOS::GetServiceRecords(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- DiscoverServices(
- object_path_,
- "", // empty pattern to browse all services
- base::Bind(&BluetoothDeviceChromeOS::CollectServiceRecordsCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- base::Bind(
- &BluetoothDeviceChromeOS::OnGetServiceRecordsError,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback)));
-}
-
-void BluetoothDeviceChromeOS::ProvidesServiceWithName(
- const std::string& name,
- const ProvidesServiceCallback& callback) {
- GetServiceRecords(
- base::Bind(&BluetoothDeviceChromeOS::SearchServicesForNameCallback,
- weak_ptr_factory_.GetWeakPtr(),
- name,
- callback),
- base::Bind(&BluetoothDeviceChromeOS::SearchServicesForNameErrorCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
-}
-
-bool BluetoothDeviceChromeOS::ExpectingPinCode() const {
- return !pincode_callback_.is_null();
-}
-
-bool BluetoothDeviceChromeOS::ExpectingPasskey() const {
- return !passkey_callback_.is_null();
-}
-
-bool BluetoothDeviceChromeOS::ExpectingConfirmation() const {
- return !confirmation_callback_.is_null();
-}
-
-void BluetoothDeviceChromeOS::Connect(
- PairingDelegate* pairing_delegate,
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) {
- // This is safe because Connect() and its callbacks are called in the same
- // thread.
- connecting_calls_++;
- if (!connecting_) {
- connecting_ = true;
- adapter_->NotifyDeviceChanged(this);
- }
- connecting_ = !!connecting_calls_;
- // Set the decrement to be issued when either callback is called.
- base::Closure wrapped_callback = base::Bind(
- &BluetoothDeviceChromeOS::OnConnectCallbackCalled,
- weak_ptr_factory_.GetWeakPtr(),
- callback);
- ConnectErrorCallback wrapped_error_callback = base::Bind(
- &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled,
- weak_ptr_factory_.GetWeakPtr(),
- error_callback);
-
- if (IsPaired()) {
- // Connection to already paired device.
- ConnectApplications(wrapped_callback, wrapped_error_callback);
-
- } else if (!pairing_delegate || !IsPairable()) {
- // No pairing delegate supplied, or unpairable device; initiate
- // low-security connection only.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- CreateDevice(adapter_->object_path_,
- address_,
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_callback,
- wrapped_error_callback),
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_error_callback));
- } else {
- // Initiate high-security connection with pairing.
- DCHECK(!pairing_delegate_);
- pairing_delegate_ = pairing_delegate;
-
- // The agent path is relatively meaningless, we use the device address
- // to generate it as we only support one pairing attempt at a time for
- // a given bluetooth device.
- DCHECK(agent_.get() == NULL);
-
- std::string agent_path_basename;
- ReplaceChars(address_, ":", "_", &agent_path_basename);
- dbus::ObjectPath agent_path("/org/chromium/bluetooth_agent/" +
- agent_path_basename);
-
- dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus();
- if (system_bus) {
- agent_.reset(BluetoothAgentServiceProvider::Create(system_bus,
- agent_path,
- this));
- } else {
- agent_.reset(NULL);
- }
-
- VLOG(1) << "Pairing: " << address_;
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- CreatePairedDevice(
- adapter_->object_path_,
- address_,
- agent_path,
- bluetooth_agent::kDisplayYesNoCapability,
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_callback,
- wrapped_error_callback),
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_error_callback));
- }
-}
-
-void BluetoothDeviceChromeOS::SetPinCode(const std::string& pincode) {
- if (!agent_.get() || pincode_callback_.is_null())
- return;
-
- pincode_callback_.Run(SUCCESS, pincode);
- pincode_callback_.Reset();
-}
-
-void BluetoothDeviceChromeOS::SetPasskey(uint32 passkey) {
- if (!agent_.get() || passkey_callback_.is_null())
- return;
-
- passkey_callback_.Run(SUCCESS, passkey);
- passkey_callback_.Reset();
-}
-
-void BluetoothDeviceChromeOS::ConfirmPairing() {
- if (!agent_.get() || confirmation_callback_.is_null())
- return;
-
- confirmation_callback_.Run(SUCCESS);
- confirmation_callback_.Reset();
-}
-
-void BluetoothDeviceChromeOS::RejectPairing() {
- if (!agent_.get())
- return;
-
- if (!pincode_callback_.is_null()) {
- pincode_callback_.Run(REJECTED, "");
- pincode_callback_.Reset();
- }
- if (!passkey_callback_.is_null()) {
- passkey_callback_.Run(REJECTED, 0);
- passkey_callback_.Reset();
- }
- if (!confirmation_callback_.is_null()) {
- confirmation_callback_.Run(REJECTED);
- confirmation_callback_.Reset();
- }
-}
-
-void BluetoothDeviceChromeOS::CancelPairing() {
- bool have_callback = false;
- if (agent_.get()) {
- if (!pincode_callback_.is_null()) {
- pincode_callback_.Run(CANCELLED, "");
- pincode_callback_.Reset();
- have_callback = true;
- }
- if (!passkey_callback_.is_null()) {
- passkey_callback_.Run(CANCELLED, 0);
- passkey_callback_.Reset();
- have_callback = true;
- }
- if (!confirmation_callback_.is_null()) {
- confirmation_callback_.Run(CANCELLED);
- confirmation_callback_.Reset();
- have_callback = true;
- }
- }
-
- if (!have_callback) {
- // User cancels the pairing process.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->CancelDeviceCreation(
- adapter_->object_path_,
- address_,
- base::Bind(&BluetoothDeviceChromeOS::OnCancelDeviceCreation,
- weak_ptr_factory_.GetWeakPtr()));
-
- pairing_delegate_ = NULL;
- agent_.reset();
- }
-}
-
-void BluetoothDeviceChromeOS::Disconnect(const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- Disconnect(object_path_,
- base::Bind(&BluetoothDeviceChromeOS::DisconnectCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-
-}
-
-void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- RemoveDevice(adapter_->object_path_,
- object_path_,
- base::Bind(&BluetoothDeviceChromeOS::ForgetCallback,
- weak_ptr_factory_.GetWeakPtr(),
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::ConnectToService(const std::string& service_uuid,
- const SocketCallback& callback) {
- GetServiceRecords(
- base::Bind(&BluetoothDeviceChromeOS::GetServiceRecordsForConnectCallback,
- weak_ptr_factory_.GetWeakPtr(),
- service_uuid,
- callback),
- base::Bind(
- &BluetoothDeviceChromeOS::GetServiceRecordsForConnectErrorCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
-}
-
-void BluetoothDeviceChromeOS::ConnectToProfile(
- device::BluetoothProfile* profile,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- // TODO(keybuk): implement
-}
-
-void BluetoothDeviceChromeOS::SetOutOfBandPairingData(
- const BluetoothOutOfBandPairingData& data,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
- AddRemoteData(
- object_path_,
- address_,
- data,
- base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::ClearOutOfBandPairingData(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
- RemoveRemoteData(
- object_path_,
- address_,
- base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::SetObjectPath(
- const dbus::ObjectPath& object_path) {
- DCHECK(object_path_ == dbus::ObjectPath(""));
- object_path_ = object_path;
-}
-
-void BluetoothDeviceChromeOS::RemoveObjectPath() {
- DCHECK(object_path_ != dbus::ObjectPath(""));
- object_path_ = dbus::ObjectPath("");
-}
-
-void BluetoothDeviceChromeOS::Update(
- const BluetoothDeviceClient::Properties* properties,
- bool update_state) {
- std::string address = properties->address.value();
- std::string name = properties->name.value();
- uint32 bluetooth_class = properties->bluetooth_class.value();
- const std::vector<std::string>& uuids = properties->uuids.value();
-
- if (!address.empty())
- address_ = address;
- if (!name.empty())
- name_ = name;
- if (bluetooth_class)
- bluetooth_class_ = bluetooth_class;
- if (!uuids.empty()) {
- service_uuids_.clear();
- service_uuids_.assign(uuids.begin(), uuids.end());
- }
-
- if (update_state) {
- // When the device reconnects and we don't have any service records for it,
- // try to update the cache or fail silently.
- if (!service_records_loaded_ && !connected_ &&
- properties->connected.value())
- GetServiceRecords(base::Bind(&DoNothingServiceRecordList),
- base::Bind(&base::DoNothing));
-
- paired_ = properties->paired.value();
- trusted_ = properties->trusted.value();
- connected_ = properties->connected.value();
- }
-}
-
-void BluetoothDeviceChromeOS::OnCreateDevice(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const dbus::ObjectPath& device_path) {
- VLOG(1) << "Connection successful: " << device_path.value();
- if (object_path_.value().empty()) {
- object_path_ = device_path;
- } else {
- LOG_IF(WARNING, object_path_ != device_path)
- << "Conflicting device paths for objects, result gave: "
- << device_path.value() << " but signal gave: "
- << object_path_.value();
- }
-
- SetTrusted();
-
- // In parallel with the |trusted| property change, call GetServiceRecords to
- // retrieve the SDP from the device and then, either on success or failure,
- // call ConnectApplications.
- GetServiceRecords(
- base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecords,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback),
- base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecordsError,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::OnCreateDeviceError(
- const ConnectErrorCallback& error_callback,
- const std::string& error_name,
- const std::string& error_message) {
- // The default |error_code| is an unknown error.
- ConnectErrorCode error_code = ERROR_UNKNOWN;
-
- // Report any error in the log, even if we know the possible source of it.
- LOG(WARNING) << "Connection failed (on CreatePairedDevice): "
- << "\"" << name_ << "\" (" << address_ << "): "
- << error_name << ": \"" << error_message << "\"";
-
- // Determines the right error code from error_name, assuming the error name
- // comes from CreatePairedDevice bluez function.
- if (error_name == bluetooth_adapter::kErrorConnectionAttemptFailed) {
- error_code = ERROR_FAILED;
- } else if (error_name == bluetooth_adapter::kErrorAuthenticationFailed) {
- error_code = ERROR_AUTH_FAILED;
- } else if (error_name == bluetooth_adapter::kErrorAuthenticationRejected) {
- error_code = ERROR_AUTH_REJECTED;
- } else if (error_name == bluetooth_adapter::kErrorAuthenticationTimeout) {
- error_code = ERROR_AUTH_TIMEOUT;
- }
- error_callback.Run(error_code);
-}
-
-void BluetoothDeviceChromeOS::CollectServiceRecordsCallback(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path,
- const BluetoothDeviceClient::ServiceMap& service_map,
- bool success) {
- if (!success) {
- error_callback.Run();
- return;
- }
-
- // Update the cache. No other thread is executing a GetServiceRecords
- // callback, so it is safe to delete the previous objects here.
- service_records_.clear();
- // TODO(deymo): Perhaps don't update the cache if the new SDP information is
- // empty and we had something before. Some devices only answer this
- // information while paired, and this callback could be called in any order if
- // several calls to GetServiceRecords are made while initial pairing with the
- // device. This requires more investigation.
- for (BluetoothDeviceClient::ServiceMap::const_iterator i =
- service_map.begin(); i != service_map.end(); ++i) {
- service_records_.push_back(
- new BluetoothServiceRecordChromeOS(address_, i->second));
- }
- service_records_loaded_ = true;
-
- callback.Run(service_records_);
-}
-
-void BluetoothDeviceChromeOS::SetTrusted() {
- // Unconditionally send the property change, rather than checking the value
- // first; there's no harm in doing this and it solves any race conditions
- // with the property becoming true or false and this call happening before
- // we get the D-Bus signal about the earlier change.
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- GetProperties(object_path_)->trusted.Set(
- true,
- base::Bind(
- &BluetoothDeviceChromeOS::OnSetTrusted,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void BluetoothDeviceChromeOS::OnSetTrusted(bool success) {
- LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_;
-}
-
-void BluetoothDeviceChromeOS::OnInitialGetServiceRecords(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const ServiceRecordList& list) {
- // Connect application-layer protocols.
- ConnectApplications(callback, error_callback);
-}
-
-void BluetoothDeviceChromeOS::OnInitialGetServiceRecordsError(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) {
- // Ignore the error retrieving the service records and continue.
- LOG(WARNING) << "Error retrieving SDP for " << address_ << " after pairing.";
- // Connect application-layer protocols.
- ConnectApplications(callback, error_callback);
-}
-
-void BluetoothDeviceChromeOS::OnGetServiceRecordsError(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback) {
- if (service_records_loaded_) {
- callback.Run(service_records_);
- } else {
- error_callback.Run();
- }
-}
-
-void BluetoothDeviceChromeOS::OnConnectCallbackCalled(
- const base::Closure& callback) {
- // Update the connecting status.
- bool prev_connecting = connecting_;
- connecting_calls_--;
- connecting_ = !!connecting_calls_;
- callback.Run();
- if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this);
-}
-
-void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled(
- const ConnectErrorCallback& error_callback,
- enum ConnectErrorCode error_code) {
- // Update the connecting status.
- bool prev_connecting = connecting_;
- connecting_calls_--;
- connecting_ = !!connecting_calls_;
- error_callback.Run(error_code);
- if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this);
-}
-
-void BluetoothDeviceChromeOS::ConnectApplications(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) {
- // Introspect the device object to determine supported applications.
- DBusThreadManager::Get()->GetIntrospectableClient()->
- Introspect(bluetooth_device::kBluetoothDeviceServiceName,
- object_path_,
- base::Bind(&BluetoothDeviceChromeOS::OnIntrospect,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::OnIntrospect(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const std::string& service_name,
- const dbus::ObjectPath& device_path,
- const std::string& xml_data,
- bool success) {
- if (!success) {
- LOG(WARNING) << "Failed to determine supported applications: " << address_;
- error_callback.Run(ERROR_UNKNOWN);
- return;
- }
-
- // The introspection data for the device object may list one or more
- // additional D-Bus interfaces that BlueZ supports for this particular
- // device. Send appropraite Connect calls for each of those interfaces
- // to connect all of the application protocols for this device.
- std::vector<std::string> interfaces =
- IntrospectableClient::GetInterfacesFromIntrospectResult(xml_data);
-
- DCHECK_EQ(0, connecting_applications_counter_);
- connecting_applications_counter_ = 0;
- for (std::vector<std::string>::iterator iter = interfaces.begin();
- iter != interfaces.end(); ++iter) {
- if (*iter == bluetooth_input::kBluetoothInputInterface) {
- connecting_applications_counter_++;
- // Supports Input interface.
- DBusThreadManager::Get()->GetBluetoothInputClient()->
- Connect(object_path_,
- base::Bind(&BluetoothDeviceChromeOS::OnConnect,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- *iter),
- base::Bind(&BluetoothDeviceChromeOS::OnConnectError,
- weak_ptr_factory_.GetWeakPtr(),
- error_callback, *iter));
- }
- }
-
- // If OnConnect has been called for every call to Connect above, then this
- // will decrement the counter to -1. In that case, call the callback
- // directly as it has not been called by any of the OnConnect callbacks.
- // This is safe because OnIntrospect and OnConnect run on the same thread.
- connecting_applications_counter_--;
- if (connecting_applications_counter_ == -1)
- callback.Run();
-}
-
-void BluetoothDeviceChromeOS::OnConnect(const base::Closure& callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path) {
- VLOG(1) << "Application connection successful: " << device_path.value()
- << ": " << interface_name;
-
- connecting_applications_counter_--;
- // |callback| should only be called once, meaning it cannot be called before
- // all requests have been started. The extra decrement after all requests
- // have been started, and the check for -1 instead of 0 below, insure only a
- // single call to |callback| will occur (provided OnConnect and OnIntrospect
- // run on the same thread, which is true).
- if (connecting_applications_counter_ == -1) {
- connecting_applications_counter_ = 0;
- SetTrusted();
- callback.Run();
- }
-}
-
-void BluetoothDeviceChromeOS::OnConnectError(
- const ConnectErrorCallback& error_callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path,
- const std::string& error_name,
- const std::string& error_message) {
- // The default |error_code| is an unknown error.
- ConnectErrorCode error_code = ERROR_UNKNOWN;
-
- // Report any error in the log, even if we know the possible source of it.
- LOG(WARNING) << "Connection failed (on Connect): "
- << interface_name << ": "
- << "\"" << name_ << "\" (" << address_ << "): "
- << error_name << ": \"" << error_message << "\"";
-
- // Determines the right error code from error_name, assuming the error name
- // comes from Connect bluez function.
- if (error_name == bluetooth_adapter::kErrorFailed) {
- error_code = ERROR_FAILED;
- } else if (error_name == bluetooth_adapter::kErrorInProgress) {
- error_code = ERROR_INPROGRESS;
- } else if (error_name == bluetooth_adapter::kErrorNotSupported) {
- error_code = ERROR_UNSUPPORTED_DEVICE;
- }
-
- error_callback.Run(error_code);
-}
-
-void BluetoothDeviceChromeOS::DisconnectCallback(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path,
- bool success) {
- DCHECK(device_path == object_path_);
- if (success) {
- VLOG(1) << "Disconnection successful: " << address_;
- callback.Run();
- } else {
- if (connected_) {
- LOG(WARNING) << "Disconnection failed: " << address_;
- error_callback.Run();
- } else {
- VLOG(1) << "Disconnection failed on a already disconnected device: "
- << address_;
- callback.Run();
- }
- }
-}
-
-void BluetoothDeviceChromeOS::ForgetCallback(
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success) {
- // It's quite normal that this path never gets called on success; we use a
- // weak pointer, and bluetoothd might send the DeviceRemoved signal before
- // the method reply, in which case this object is deleted and the
- // callback never takes place. Therefore don't do anything here for the
- // success case.
- if (!success) {
- LOG(WARNING) << "Forget failed: " << address_;
- error_callback.Run();
- }
-}
-
-void BluetoothDeviceChromeOS::OnCancelDeviceCreation(
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (!success)
- LOG(WARNING) << "CancelDeviceCreation failed: " << address_;
-}
-
-void BluetoothDeviceChromeOS::SearchServicesForNameErrorCallback(
- const ProvidesServiceCallback& callback) {
- callback.Run(false);
-}
-
-void BluetoothDeviceChromeOS::SearchServicesForNameCallback(
- const std::string& name,
- const ProvidesServiceCallback& callback,
- const ServiceRecordList& list) {
- for (ServiceRecordList::const_iterator i = list.begin();
- i != list.end(); ++i) {
- if ((*i)->name() == name) {
- callback.Run(true);
- return;
- }
- }
- callback.Run(false);
-}
-
-void BluetoothDeviceChromeOS::GetServiceRecordsForConnectErrorCallback(
- const SocketCallback& callback) {
- callback.Run(NULL);
-}
-
-void BluetoothDeviceChromeOS::GetServiceRecordsForConnectCallback(
- const std::string& service_uuid,
- const SocketCallback& callback,
- const ServiceRecordList& list) {
- for (ServiceRecordList::const_iterator i = list.begin();
- i != list.end(); ++i) {
- if ((*i)->uuid() == service_uuid) {
- // If multiple service records are found, use the first one that works.
- scoped_refptr<BluetoothSocket> socket(
- BluetoothSocketChromeOS::CreateBluetoothSocket(**i));
- if (socket.get() != NULL) {
- callback.Run(socket);
- return;
- }
- }
- }
- callback.Run(NULL);
-}
-
-void BluetoothDeviceChromeOS::OnRemoteDataCallback(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success) {
- if (success)
- callback.Run();
- else
- error_callback.Run();
-}
-
-void BluetoothDeviceChromeOS::DisconnectRequested(
- const dbus::ObjectPath& object_path) {
- DCHECK(object_path == object_path_);
-}
-
-void BluetoothDeviceChromeOS::Release() {
- DCHECK(agent_.get());
- VLOG(1) << "Release: " << address_;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DismissDisplayOrConfirm();
- pairing_delegate_ = NULL;
-
- pincode_callback_.Reset();
- passkey_callback_.Reset();
- confirmation_callback_.Reset();
-
- agent_.reset();
-}
-
-void BluetoothDeviceChromeOS::RequestPinCode(
- const dbus::ObjectPath& device_path,
- const PinCodeCallback& callback) {
- DCHECK(agent_.get());
- VLOG(1) << "RequestPinCode: " << device_path.value();
-
- DCHECK(pairing_delegate_);
- DCHECK(pincode_callback_.is_null());
- pincode_callback_ = callback;
- pairing_delegate_->RequestPinCode(this);
-}
-
-void BluetoothDeviceChromeOS::RequestPasskey(
- const dbus::ObjectPath& device_path,
- const PasskeyCallback& callback) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "RequestPasskey: " << device_path.value();
-
- DCHECK(pairing_delegate_);
- DCHECK(passkey_callback_.is_null());
- passkey_callback_ = callback;
- pairing_delegate_->RequestPasskey(this);
-}
-
-void BluetoothDeviceChromeOS::DisplayPinCode(
- const dbus::ObjectPath& device_path,
- const std::string& pincode) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "DisplayPinCode: " << device_path.value() << " " << pincode;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DisplayPinCode(this, pincode);
-}
-
-void BluetoothDeviceChromeOS::DisplayPasskey(
- const dbus::ObjectPath& device_path,
- uint32 passkey) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "DisplayPasskey: " << device_path.value() << " " << passkey;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DisplayPasskey(this, passkey);
-}
-
-void BluetoothDeviceChromeOS::RequestConfirmation(
- const dbus::ObjectPath& device_path,
- uint32 passkey,
- const ConfirmationCallback& callback) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "RequestConfirmation: " << device_path.value() << " " << passkey;
-
- DCHECK(pairing_delegate_);
- DCHECK(confirmation_callback_.is_null());
- confirmation_callback_ = callback;
- pairing_delegate_->ConfirmPasskey(this, passkey);
-}
-
-void BluetoothDeviceChromeOS::Authorize(const dbus::ObjectPath& device_path,
- const std::string& uuid,
- const ConfirmationCallback& callback) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- LOG(WARNING) << "Rejected authorization for service: " << uuid
- << " requested from device: " << device_path.value();
- callback.Run(REJECTED);
-}
-
-void BluetoothDeviceChromeOS::ConfirmModeChange(
- Mode mode,
- const ConfirmationCallback& callback) {
- DCHECK(agent_.get());
- LOG(WARNING) << "Rejected adapter-level mode change: " << mode
- << " made on agent for device: " << address_;
- callback.Run(REJECTED);
-}
-
-void BluetoothDeviceChromeOS::Cancel() {
- DCHECK(agent_.get());
- VLOG(1) << "Cancel: " << address_;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DismissDisplayOrConfirm();
-}
-
-
-// static
-BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create(
- BluetoothAdapterChromeOS* adapter) {
- return new BluetoothDeviceChromeOS(adapter);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h
deleted file mode 100644
index 72718b2..0000000
--- a/device/bluetooth/bluetooth_device_chromeos.h
+++ /dev/null
@@ -1,466 +0,0 @@
-// Copyright (c) 2012 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_BLUETOOTH_DEVICE_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
-#include "base/memory/weak_ptr.h"
-#include "base/string16.h"
-#include "chromeos/dbus/bluetooth_agent_service_provider.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_device.h"
-
-namespace device {
-
-class BluetoothServiceRecord;
-class MockBluetoothDevice;
-struct BluetoothOutOfBandPairingData;
-
-} // namespace device
-
-namespace chromeos {
-
-class BluetoothAdapterChromeOS;
-
-// The BluetoothDeviceChromeOS class is an implementation of BluetoothDevice
-// for Chrome OS platform.
-class BluetoothDeviceChromeOS
- : public device::BluetoothDevice,
- public BluetoothDeviceClient::Observer,
- public BluetoothAgentServiceProvider::Delegate {
- public:
- virtual ~BluetoothDeviceChromeOS();
-
- // BluetoothDevice override
- virtual uint32 GetBluetoothClass() const OVERRIDE;
- virtual std::string GetAddress() const OVERRIDE;
- virtual uint16 GetVendorID() const OVERRIDE;
- virtual uint16 GetProductID() const OVERRIDE;
- virtual uint16 GetDeviceID() const OVERRIDE;
- virtual bool IsPaired() const OVERRIDE;
- virtual bool IsConnected() const OVERRIDE;
- virtual bool IsConnectable() const OVERRIDE;
- virtual bool IsConnecting() const OVERRIDE;
- virtual ServiceList GetServices() const OVERRIDE;
- virtual void GetServiceRecords(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void ProvidesServiceWithName(
- const std::string& name,
- const ProvidesServiceCallback& callback) OVERRIDE;
- virtual bool ExpectingPinCode() const OVERRIDE;
- virtual bool ExpectingPasskey() const OVERRIDE;
- virtual bool ExpectingConfirmation() const OVERRIDE;
- virtual void Connect(
- device::BluetoothDevice::PairingDelegate* pairing_delegate,
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) OVERRIDE;
- virtual void SetPinCode(const std::string& pincode) OVERRIDE;
- virtual void SetPasskey(uint32 passkey) OVERRIDE;
- virtual void ConfirmPairing() OVERRIDE;
- virtual void RejectPairing() OVERRIDE;
- virtual void CancelPairing() OVERRIDE;
- virtual void Disconnect(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void Forget(const ErrorCallback& error_callback) OVERRIDE;
- virtual void ConnectToService(
- const std::string& service_uuid,
- const SocketCallback& callback) OVERRIDE;
- virtual void ConnectToProfile(
- device::BluetoothProfile* profile,
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void SetOutOfBandPairingData(
- const device::BluetoothOutOfBandPairingData& data,
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void ClearOutOfBandPairingData(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
-
- protected:
- // BluetoothDevice override
- virtual std::string GetDeviceName() const OVERRIDE;
-
- private:
- friend class BluetoothAdapterChromeOS;
- friend class device::MockBluetoothDevice;
-
- explicit BluetoothDeviceChromeOS(BluetoothAdapterChromeOS* adapter);
-
- // Returns whether this device has an object path.
- bool HasObjectPath() const { return !object_path_.value().empty(); }
-
- // Sets the dbus object path for the device to |object_path|, indicating
- // that the device has gone from being discovered to paired or connected.
- void SetObjectPath(const dbus::ObjectPath& object_path);
-
- // Removes the dbus object path from the device, indicating that the
- // device is no longer paired or connected, but perhaps still visible.
- void RemoveObjectPath();
-
- // Returns whether this was a discovered device.
- bool WasDiscovered() const { return discovered_; }
-
- // Sets whether the device was discovered.
- void SetDiscovered(bool discovered) { discovered_ = discovered; }
-
- // Updates device information from the properties in |properties|, device
- // state properties such as |paired_| and |connected_| are ignored unless
- // |update_state| is true.
- void Update(const BluetoothDeviceClient::Properties* properties,
- bool update_state);
-
- // Called by BluetoothAdapterClient when a call to CreateDevice() or
- // CreatePairedDevice() succeeds, provides the new object path for the remote
- // device in |device_path|. |callback| and |error_callback| are the callbacks
- // provided to Connect().
- void OnCreateDevice(const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const dbus::ObjectPath& device_path);
-
- // Called by BluetoothAdapterClient when a call to CreateDevice() or
- // CreatePairedDevice() fails with the error named |error_name| and
- // optional message |error_message|, |error_callback| is the callback
- // provided to Connect().
- void OnCreateDeviceError(const ConnectErrorCallback& error_callback,
- const std::string& error_name,
- const std::string& error_message);
-
- // Called by BluetoothAdapterClient when a call to GetServiceRecords()
- // completes. |callback| and |error_callback| are the callbacks provided to
- // GetServiceRecords.
- void CollectServiceRecordsCallback(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path,
- const BluetoothDeviceClient::ServiceMap& service_map,
- bool success);
-
- // Set the device as trusted. Trusted devices can connect to us automatically,
- // and we can connect to them after rebooting. This also causes the device to
- // be remembered by the stack even if not paired. |success| to the callback
- // indicates whether or not the request succeeded.
- void SetTrusted();
- void OnSetTrusted(bool success);
-
- // Called by BluetoothAdapterClient when a call to GetServiceRecords()
- // fails. |callback| and |error_callback| are the callbacks provided to
- // GetServiceRecords().
- void OnGetServiceRecordsError(const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback);
-
- // Called by BluetoothAdapterClient when the initial call to
- // GetServiceRecords() after pairing completes. |callback| and
- // |error_callback| are the callbacks provided to Connect().
- void OnInitialGetServiceRecords(const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const ServiceRecordList& list);
-
- // Called by BluetoothAdapterClient when the initial call to
- // GetServiceRecords() after pairing fails. |callback| and |error_callback|
- // are the callbacks provided to Connect().
- void OnInitialGetServiceRecordsError(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback);
-
- // Called by Connect() when it succeeds. The |callback| is the value passed to
- // the Connect() call.
- void OnConnectCallbackCalled(const base::Closure& callback);
-
- // Called by Connect() when it fails. The |error_callback| is the value passed
- // to the Connect() call.
- void OnConnectErrorCallbackCalled(const ConnectErrorCallback& error_callback,
- enum ConnectErrorCode error_code);
-
- // Connect application-level protocols of the device to the system, called
- // on a successful connection or to reconnect to a device that is already
- // paired or previously connected. |error_callback| is called on failure.
- // Otherwise, |callback| is called when the request is complete.
- void ConnectApplications(const base::Closure& callback,
- const ConnectErrorCallback& error_callback);
-
- // Called by IntrospectableClient when a call to Introspect() completes.
- // |success| indicates whether or not the request succeeded, |callback| and
- // |error_callback| are the callbacks provided to ConnectApplications(),
- // |service_name| and |device_path| specify the remote object being
- // introspected and |xml_data| contains the XML-formatted protocol data.
- void OnIntrospect(const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const std::string& service_name,
- const dbus::ObjectPath& device_path,
- const std::string& xml_data, bool success);
-
- // Called by BluetoothInputClient when the call to Connect() succeeds.
- // |error_callback| is the callback provided to ConnectApplications(),
- // |interface_name| specifies the interface being connected and
- // |device_path| the remote object path.
- void OnConnect(const base::Closure& callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path);
-
- // Called by BluetoothInputClient when the call to Connect() fails.
- // |error_callback| is the callback provided to ConnectApplications(),
- // |interface_name| specifies the interface being connected,
- // |device_path| the remote object path,
- // |error_name| the error name and |error_message| the optional message.
- void OnConnectError(const ConnectErrorCallback& error_callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path,
- const std::string& error_name,
- const std::string& error_message);
-
- // Called by BluetoothDeviceClient when a call to Disconnect() completes,
- // |success| indicates whether or not the request succeeded, |callback| and
- // |error_callback| are the callbacks provided to Disconnect() and
- // |device_path| is the device disconnected.
- void DisconnectCallback(const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path, bool success);
-
- // Called by BluetoothAdapterClient when a call to RemoveDevice()
- // completes, |success| indicates whether or not the request succeeded,
- // |error_callback| is the callback provided to Forget() and |adapter_path| is
- // the d-bus object path of the adapter that performed the removal.
- void ForgetCallback(const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path, bool success);
-
- // Called by BluetoothAdapterClient when a call to CancelDeviceCreation()
- // completes, |success| indicates whether or not the request succeeded.
- void OnCancelDeviceCreation(const dbus::ObjectPath& adapter_path,
- bool success);
-
- // Called if the call to GetServiceRecords from ProvidesServiceWithName fails.
- void SearchServicesForNameErrorCallback(
- const ProvidesServiceCallback& callback);
-
- // Called by GetServiceRecords with the list of BluetoothServiceRecords to
- // search for |name|. |callback| is the callback from
- // ProvidesServiceWithName.
- void SearchServicesForNameCallback(
- const std::string& name,
- const ProvidesServiceCallback& callback,
- const ServiceRecordList& list);
-
- // Called if the call to GetServiceRecords from Connect fails.
- void GetServiceRecordsForConnectErrorCallback(
- const SocketCallback& callback);
-
- // Called by GetServiceRecords with the list of BluetoothServiceRecords.
- // Connections are attempted to each service in the list matching
- // |service_uuid|, and the socket from the first successful connection is
- // passed to |callback|.
- void GetServiceRecordsForConnectCallback(
- const std::string& service_uuid,
- const SocketCallback& callback,
- const ServiceRecordList& list);
-
- // Called by BlueoothDeviceClient in response to the AddRemoteData and
- // RemoveRemoteData method calls.
- void OnRemoteDataCallback(const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success);
-
- // BluetoothDeviceClient::Observer override.
- //
- // Called when the device with object path |object_path| is about
- // to be disconnected, giving a chance for application layers to
- // shut down cleanly.
- virtual void DisconnectRequested(
- const dbus::ObjectPath& object_path) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the agent is unregistered from the
- // Bluetooth daemon, generally at the end of a pairing request. It may be
- // used to perform cleanup tasks.
- virtual void Release() OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires a
- // PIN Code for authentication of the device with object path |device_path|,
- // the agent should obtain the code from the user and call |callback|
- // to provide it, or indicate rejection or cancellation of the request.
- //
- // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
- // for which there is no automatic pairing or special handling.
- virtual void RequestPinCode(const dbus::ObjectPath& device_path,
- const PinCodeCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires a
- // Passkey for authentication of the device with object path |device_path|,
- // the agent should obtain the passkey from the user (a numeric in the
- // range 0-999999) and call |callback| to provide it, or indicate
- // rejection or cancellation of the request.
- //
- // Passkeys are generally required for Bluetooth 2.1 and later devices
- // which cannot provide input or display on their own, and don't accept
- // passkey-less pairing.
- virtual void RequestPasskey(const dbus::ObjectPath& device_path,
- const PasskeyCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user enter the PIN code |pincode| into the device with object path
- // |device_path| so that it may be authenticated. The Cancel() method
- // will be called to dismiss the display once pairing is complete or
- // cancelled.
- //
- // This is used for Bluetooth 2.0 and earlier keyboard devices, the
- // |pincode| will always be a six-digit numeric in the range 000000-999999
- // for compatibilty with later specifications.
- virtual void DisplayPinCode(const dbus::ObjectPath& device_path,
- const std::string& pincode) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user enter the Passkey |passkey| into the device with object path
- // |device_path| so that it may be authenticated. The Cancel() method
- // will be called to dismiss the display once pairing is complete or
- // cancelled.
- //
- // This is used for Bluetooth 2.1 and later devices that support input
- // but not display, such as keyboards. The Passkey is a numeric in the
- // range 0-999999 and should be always presented zero-padded to six
- // digits.
- virtual void DisplayPasskey(const dbus::ObjectPath& device_path,
- uint32 passkey) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the Passkey |passkey| is displayed on the screen
- // of the device with object path |object_path| so that it may be
- // authentication. The agent should display to the user and ask for
- // confirmation, then call |callback| to provide their response (success,
- // rejected or cancelled).
- //
- // This is used for Bluetooth 2.1 and later devices that support display,
- // such as other computers or phones. The Passkey is a numeric in the
- // range 0-999999 and should be always present zero-padded to six
- // digits.
- virtual void RequestConfirmation(
- const dbus::ObjectPath& device_path,
- uint32 passkey,
- const ConfirmationCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the device with object path |object_path| is
- // authorized to connect to the service with UUID |uuid|. The agent should
- // confirm with the user and call |callback| to provide their response
- // (success, rejected or cancelled).
- virtual void Authorize(const dbus::ObjectPath& device_path,
- const std::string& uuid,
- const ConfirmationCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the device adapter may switch to mode |mode|. The
- // agent should confirm with the user and call |callback| to provide
- // their response (success, rejected or cancelled).
- virtual void ConfirmModeChange(Mode mode,
- const ConfirmationCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called by the Bluetooth daemon to indicate that
- // the request failed before a reply was returned from the device.
- virtual void Cancel() OVERRIDE;
-
- // Creates a new BluetoothDeviceChromeOS object bound to the adapter
- // |adapter|.
- static BluetoothDeviceChromeOS* Create(BluetoothAdapterChromeOS* adapter);
-
- // The adapter that owns this device instance.
- BluetoothAdapterChromeOS* adapter_;
-
- // The dbus object path of the device, will be empty if the device has only
- // been discovered and not yet paired with.
- dbus::ObjectPath object_path_;
-
- // The Bluetooth class of the device, a bitmask that may be decoded using
- // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
- uint32 bluetooth_class_;
-
- // The name of the device, as supplied by the remote device.
- std::string name_;
-
- // The Bluetooth address of the device.
- std::string address_;
-
- // Tracked device state, updated by the adapter managing the lifecyle of
- // the device.
- bool paired_;
- bool trusted_;
- bool connected_;
-
- // Indicates whether the device normally accepts connections initiated from
- // the adapter once paired.
- bool connectable_;
-
- // Indicated whether the device is in a connecting status.
- bool connecting_;
-
- // Used by BluetoothAdapterChromeOS (a friend) to avoid removing discovered
- // devices when they are unpaired.
- bool discovered_;
-
- // The services (identified by UUIDs) that this device provides.
- ServiceList service_uuids_;
-
- // During pairing this is set to an object that we don't own, but on which
- // we can make method calls to request, display or confirm PIN Codes and
- // Passkeys. Generally it is the object that owns this one.
- device::BluetoothDevice::PairingDelegate* pairing_delegate_;
-
- // During pairing this is set to an instance of a D-Bus agent object
- // intialized with our own class as its delegate.
- scoped_ptr<BluetoothAgentServiceProvider> agent_;
-
- // During pairing these callbacks are set to those provided by method calls
- // made on us by |agent_| and are called by our own method calls such as
- // SetPinCode() and SetPasskey().
- PinCodeCallback pincode_callback_;
- PasskeyCallback passkey_callback_;
- ConfirmationCallback confirmation_callback_;
-
- // Used to keep track of pending application connection requests.
- int connecting_applications_counter_;
-
- // Used to keep track of ongoing calls to Connect().
- int connecting_calls_;
-
- // A service records cache.
- ServiceRecordList service_records_;
-
- // This says whether the |service_records_| cache is initialized. Note that an
- // empty |service_records_| list can be a valid list.
- bool service_records_loaded_;
-
- // 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<BluetoothDeviceChromeOS> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
diff --git a/device/bluetooth/bluetooth_service_record_chromeos.cc b/device/bluetooth/bluetooth_service_record_chromeos.cc
deleted file mode 100644
index b7ab878..0000000
--- a/device/bluetooth/bluetooth_service_record_chromeos.cc
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright (c) 2013 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/bluetooth_service_record_chromeos.h"
-
-#include <bluetooth/bluetooth.h>
-
-#include <string>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/string_number_conversions.h"
-#include "device/bluetooth/bluetooth_utils.h"
-#include "third_party/libxml/chromium/libxml_utils.h"
-
-namespace {
-
-static const char* kAttributeNode = "attribute";
-static const char* kBooleanNode = "boolean";
-static const char* kSequenceNode = "sequence";
-static const char* kTextNode = "text";
-static const char* kUint8Node = "uint8";
-static const char* kUuidNode = "uuid";
-
-static const char* kIdAttribute = "id";
-static const char* kValueAttribute = "value";
-static const char* kValueTrue = "true";
-
-static const char* kHidNormallyConnectableId = "0x020d";
-static const char* kHidReconnectInitiateId = "0x0205";
-static const char* kProtocolDescriptorListId = "0x0004";
-static const char* kSdpNameId = "0x0100";
-static const char* kServiceClassUuidId = "0x0001";
-
-static const char* kProtocolRfcommUuid = "0x0003";
-static const char* kProtocolHidpUuid = "0x0011";
-
-bool AdvanceToTag(XmlReader* reader, const char* node_type) {
- do {
- if (!reader->Read())
- return false;
- } while (reader->NodeName() != node_type);
- return true;
-}
-
-bool ExtractTextValue(XmlReader* reader, std::string* value_out) {
- if (AdvanceToTag(reader, kTextNode)) {
- reader->NodeAttribute(kValueAttribute, value_out);
- return true;
- }
- return false;
-}
-
-bool ExtractBooleanValue(XmlReader* reader, bool* value_out) {
- if (AdvanceToTag(reader, kBooleanNode)) {
- std::string str_value;
- if (!reader->NodeAttribute(kValueAttribute, &str_value))
- return false;
- *value_out = str_value == kValueTrue;
- return true;
- }
- return false;
-}
-
-} // namespace
-
-namespace chromeos {
-
-BluetoothServiceRecordChromeOS::BluetoothServiceRecordChromeOS(
- const std::string& address,
- const std::string& xml_data) {
- address_ = address;
- supports_rfcomm_ = false;
- supports_hid_ = false;
-
- // For HID services the default is false when the attribute is not present.
- hid_reconnect_initiate_ = false;
- hid_normally_connectable_ = false;
-
- XmlReader reader;
- if (!reader.Load(xml_data))
- return;
-
- while (AdvanceToTag(&reader, kAttributeNode)) {
- std::string id;
- if (reader.NodeAttribute(kIdAttribute, &id)) {
- if (id == kSdpNameId) {
- ExtractTextValue(&reader, &name_);
- } else if (id == kProtocolDescriptorListId) {
- if (AdvanceToTag(&reader, kSequenceNode)) {
- ExtractProtocolDescriptors(&reader);
- }
- } else if (id == kServiceClassUuidId) {
- if (AdvanceToTag(&reader, kSequenceNode)) {
- ExtractServiceClassUuid(&reader);
- }
- } else if (id == kHidNormallyConnectableId) {
- ExtractBooleanValue(&reader, &hid_normally_connectable_);
- } else if (id == kHidReconnectInitiateId) {
- ExtractBooleanValue(&reader, &hid_reconnect_initiate_);
- }
- }
- // We don't care about anything else here, so find the closing tag
- AdvanceToTag(&reader, kAttributeNode);
- }
- if (!supports_hid_) {
- // For non-HID services the default is true.
- hid_normally_connectable_ = true;
- hid_reconnect_initiate_ = true;
- }
-}
-
-void BluetoothServiceRecordChromeOS::GetBluetoothAddress(
- bdaddr_t* out_address) const {
- std::string numbers_only;
- for (int i = 0; i < 6; ++i)
- numbers_only += address_.substr(i * 3, 2);
-
- std::vector<uint8> address_bytes;
- base::HexStringToBytes(numbers_only, &address_bytes);
- for (int i = 0; i < 6; ++i)
- out_address->b[5 - i] = address_bytes[i];
-}
-
-void BluetoothServiceRecordChromeOS::ExtractProtocolDescriptors(
- XmlReader* reader) {
- const int start_depth = reader->Depth();
- // The ProtocolDescriptorList can have one or more sequence of sequence of
- // stack, where each stack starts with an UUID and the remaining tags (if
- // present) are protocol-specific.
- do {
- if (reader->NodeName() == kSequenceNode) {
- if (AdvanceToTag(reader, kUuidNode)) {
- std::string protocolUuid;
- if (reader->NodeAttribute(kValueAttribute, &protocolUuid)) {
- // Per protocol parameters parsing.
- if (protocolUuid == kProtocolRfcommUuid) {
- if (AdvanceToTag(reader, kUint8Node)) {
- std::string channel_string;
- if (reader->NodeAttribute(kValueAttribute, &channel_string)) {
- std::vector<uint8> channel_bytes;
- if (base::HexStringToBytes(channel_string.substr(2),
- &channel_bytes)) {
- if (channel_bytes.size() == 1) {
- rfcomm_channel_ = channel_bytes[0];
- supports_rfcomm_ = true;
- }
- }
- }
- }
- } else if (protocolUuid == kProtocolHidpUuid) {
- supports_hid_ = true;
- }
- }
- }
- }
- } while (AdvanceToTag(reader, kSequenceNode) &&
- reader->Depth() != start_depth);
-}
-
-void BluetoothServiceRecordChromeOS::ExtractServiceClassUuid(
- XmlReader* reader) {
- const int start_depth = reader->Depth();
- do {
- if (reader->NodeName() == kSequenceNode) {
- if (AdvanceToTag(reader, kUuidNode)) {
- if (!reader->NodeAttribute(kValueAttribute, &uuid_))
- uuid_.clear();
- }
- }
- } while (AdvanceToTag(reader, kSequenceNode) &&
- reader->Depth() != start_depth);
-
- uuid_ = device::bluetooth_utils::CanonicalUuid(uuid_);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_service_record_chromeos.h b/device/bluetooth/bluetooth_service_record_chromeos.h
deleted file mode 100644
index 5d0ce9b..0000000
--- a/device/bluetooth/bluetooth_service_record_chromeos.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2013 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_BLUETOOTH_SERVICE_RECORD_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_CHROMEOS_H_
-
-#include <bluetooth/bluetooth.h>
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "device/bluetooth/bluetooth_service_record.h"
-
-class XmlReader;
-
-namespace chromeos {
-
-// BluetoothServiceRecordChromeOS is an implementation of BluetoothServiceRecord
-// for the ChromeOS platform.
-class BluetoothServiceRecordChromeOS : public device::BluetoothServiceRecord {
- public:
- BluetoothServiceRecordChromeOS(const std::string& address,
- const std::string& xml_data);
-
- void GetBluetoothAddress(bdaddr_t* out_address) const;
-
- private:
- void ExtractProtocolDescriptors(XmlReader* reader);
- void ExtractServiceClassUuid(XmlReader* reader);
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothServiceRecordChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_CHROMEOS_H_
diff --git a/device/bluetooth/bluetooth_service_record_chromeos_unittest.cc b/device/bluetooth/bluetooth_service_record_chromeos_unittest.cc
deleted file mode 100644
index df4bab7..0000000
--- a/device/bluetooth/bluetooth_service_record_chromeos_unittest.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) 2012 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 <bluetooth/bluetooth.h>
-
-#include <string>
-
-#include "base/base_paths.h"
-#include "base/basictypes.h"
-#include "base/file_util.h"
-#include "base/files/file_path.h"
-#include "base/path_service.h"
-#include "device/bluetooth/bluetooth_service_record_chromeos.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-
-static const char* kAddress = "01:02:03:0A:10:A0";
-static const char* kCustomUuid = "01234567-89ab-cdef-0123-456789abcdef";
-static const char* kSerialUuid = "00001101-0000-1000-8000-00805f9b34fb";
-
-} // namespace
-
-namespace chromeos {
-
-class BluetoothServiceRecordChromeOSTest : public testing::Test {
- public:
- base::FilePath GetTestDataFilePath(const char* file) {
- base::FilePath path;
- PathService::Get(base::DIR_SOURCE_ROOT, &path);
- path = path.AppendASCII("device");
- path = path.AppendASCII("test");
- path = path.AppendASCII("data");
- path = path.AppendASCII("bluetooth");
- path = path.AppendASCII(file);
- return path;
- }
-};
-
-TEST_F(BluetoothServiceRecordChromeOSTest, RfcommService) {
- std::string xml_data;
- file_util::ReadFileToString(GetTestDataFilePath("rfcomm.xml"), &xml_data);
-
- BluetoothServiceRecordChromeOS service_record(kAddress, xml_data);
- EXPECT_EQ(kAddress, service_record.address());
- EXPECT_EQ("Headset Audio Gateway", service_record.name());
- EXPECT_TRUE(service_record.SupportsRfcomm());
- EXPECT_EQ((uint8)12, service_record.rfcomm_channel());
- EXPECT_EQ(kCustomUuid, service_record.uuid());
-}
-
-TEST_F(BluetoothServiceRecordChromeOSTest, ShortUuid) {
- std::string xml_data;
- file_util::ReadFileToString(GetTestDataFilePath("short_uuid.xml"), &xml_data);
- BluetoothServiceRecordChromeOS short_uuid_service_record(kAddress, xml_data);
- EXPECT_EQ(kSerialUuid, short_uuid_service_record.uuid());
-
- xml_data.clear();
- file_util::ReadFileToString(
- GetTestDataFilePath("medium_uuid.xml"), &xml_data);
- BluetoothServiceRecordChromeOS medium_uuid_service_record(kAddress, xml_data);
- EXPECT_EQ(kSerialUuid, medium_uuid_service_record.uuid());
-}
-
-TEST_F(BluetoothServiceRecordChromeOSTest, CleanUuid) {
- std::string xml_data;
- file_util::ReadFileToString(GetTestDataFilePath("uppercase_uuid.xml"),
- &xml_data);
- BluetoothServiceRecordChromeOS service_record(kAddress, xml_data);
- EXPECT_EQ(kCustomUuid, service_record.uuid());
-
- xml_data.clear();
- file_util::ReadFileToString(GetTestDataFilePath("invalid_uuid.xml"),
- &xml_data);
- BluetoothServiceRecordChromeOS invalid_service_record(kAddress, xml_data);
- EXPECT_EQ("", invalid_service_record.uuid());
-}
-
-TEST_F(BluetoothServiceRecordChromeOSTest, BluetoothAddress) {
- BluetoothServiceRecordChromeOS service_record(kAddress, "");
- bdaddr_t bluetooth_address;
- service_record.GetBluetoothAddress(&bluetooth_address);
- EXPECT_EQ(1, bluetooth_address.b[5]);
- EXPECT_EQ(2, bluetooth_address.b[4]);
- EXPECT_EQ(3, bluetooth_address.b[3]);
- EXPECT_EQ(10, bluetooth_address.b[2]);
- EXPECT_EQ(16, bluetooth_address.b[1]);
- EXPECT_EQ(160, bluetooth_address.b[0]);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_socket_chromeos.cc b/device/bluetooth/bluetooth_socket_chromeos.cc
deleted file mode 100644
index 1558148..0000000
--- a/device/bluetooth/bluetooth_socket_chromeos.cc
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c) 2012 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/bluetooth_socket_chromeos.h"
-
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <string>
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/rfcomm.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include "base/logging.h"
-#include "base/safe_strerror_posix.h"
-#include "device/bluetooth/bluetooth_service_record_chromeos.h"
-#include "device/bluetooth/bluetooth_utils.h"
-#include "net/base/io_buffer.h"
-
-using device::BluetoothServiceRecord;
-using device::BluetoothSocket;
-
-namespace chromeos {
-
-BluetoothSocketChromeOS::BluetoothSocketChromeOS(int fd) : fd_(fd) {
-}
-
-BluetoothSocketChromeOS::~BluetoothSocketChromeOS() {
- close(fd_);
-}
-
-// static
-scoped_refptr<BluetoothSocket> BluetoothSocketChromeOS::CreateBluetoothSocket(
- const BluetoothServiceRecord& service_record) {
- BluetoothSocketChromeOS* bluetooth_socket = NULL;
- if (service_record.SupportsRfcomm()) {
- int socket_fd = socket(
- AF_BLUETOOTH, SOCK_STREAM | SOCK_NONBLOCK, BTPROTO_RFCOMM);
- struct sockaddr_rc socket_address = { 0 };
- socket_address.rc_family = AF_BLUETOOTH;
- socket_address.rc_channel = service_record.rfcomm_channel();
- const BluetoothServiceRecordChromeOS* service_record_chromeos =
- static_cast<const BluetoothServiceRecordChromeOS*>(&service_record);
- service_record_chromeos->GetBluetoothAddress(&socket_address.rc_bdaddr);
-
- int status = connect(socket_fd, (struct sockaddr *)&socket_address,
- sizeof(socket_address));
- int errsv = errno;
- if (status == 0 || errno == EINPROGRESS) {
- bluetooth_socket = new BluetoothSocketChromeOS(socket_fd);
- } else {
- LOG(ERROR) << "Failed to connect bluetooth socket "
- << "(" << service_record.address() << "): "
- << "(" << errsv << ") " << strerror(errsv);
- close(socket_fd);
- }
- }
- // TODO(bryeung): add support for L2CAP sockets as well.
-
- return scoped_refptr<BluetoothSocketChromeOS>(bluetooth_socket);
-}
-
-bool BluetoothSocketChromeOS::Receive(net::GrowableIOBuffer* buffer) {
- buffer->SetCapacity(1024);
- ssize_t bytes_read;
- do {
- if (buffer->RemainingCapacity() == 0)
- buffer->SetCapacity(buffer->capacity() * 2);
- bytes_read = read(fd_, buffer->data(), buffer->RemainingCapacity());
- if (bytes_read > 0)
- buffer->set_offset(buffer->offset() + bytes_read);
- } while (bytes_read > 0);
-
- if (bytes_read < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
- error_message_ = safe_strerror(errno);
- return false;
- }
- return true;
-}
-
-bool BluetoothSocketChromeOS::Send(net::DrainableIOBuffer* buffer) {
- ssize_t bytes_written;
- do {
- bytes_written = write(fd_, buffer->data(), buffer->BytesRemaining());
- if (bytes_written > 0)
- buffer->DidConsume(bytes_written);
- } while (buffer->BytesRemaining() > 0 && bytes_written > 0);
-
- if (bytes_written < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
- error_message_ = safe_strerror(errno);
- return false;
- }
- return true;
-}
-
-std::string BluetoothSocketChromeOS::GetLastErrorMessage() const {
- return error_message_;
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_socket_chromeos.h b/device/bluetooth/bluetooth_socket_chromeos.h
deleted file mode 100644
index d9e89fa..0000000
--- a/device/bluetooth/bluetooth_socket_chromeos.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2012 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_BLUETOOTH_SOCKET_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
-
-#include <string>
-
-#include "base/memory/ref_counted.h"
-#include "device/bluetooth/bluetooth_socket.h"
-
-namespace device {
-
-class BluetoothServiceRecord;
-
-} // namespace device
-
-namespace net {
-
-class DrainableIOBuffer;
-class GrowableIOBuffer;
-
-} // namespace net
-
-namespace chromeos {
-
-// This class is an implementation of BluetoothSocket class for Chrome OS
-// platform.
-class BluetoothSocketChromeOS : public device::BluetoothSocket {
- public:
- static scoped_refptr<device::BluetoothSocket> CreateBluetoothSocket(
- const device::BluetoothServiceRecord& service_record);
-
- // BluetoothSocket override
- virtual bool Receive(net::GrowableIOBuffer* buffer) OVERRIDE;
- virtual bool Send(net::DrainableIOBuffer* buffer) OVERRIDE;
- virtual std::string GetLastErrorMessage() const OVERRIDE;
-
- protected:
- virtual ~BluetoothSocketChromeOS();
-
- private:
- BluetoothSocketChromeOS(int fd);
-
- const int fd_;
- std::string error_message_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
diff --git a/device/device.gyp b/device/device.gyp
index 4999705..7b26e34 100644
--- a/device/device.gyp
+++ b/device/device.gyp
@@ -21,8 +21,6 @@
'sources': [
'bluetooth/bluetooth_adapter.cc',
'bluetooth/bluetooth_adapter.h',
- 'bluetooth/bluetooth_adapter_chromeos.cc',
- 'bluetooth/bluetooth_adapter_chromeos.h',
'bluetooth/bluetooth_adapter_experimental_chromeos.cc',
'bluetooth/bluetooth_adapter_experimental_chromeos.h',
'bluetooth/bluetooth_adapter_factory.cc',
@@ -33,8 +31,6 @@
'bluetooth/bluetooth_adapter_win.h',
'bluetooth/bluetooth_device.cc',
'bluetooth/bluetooth_device.h',
- 'bluetooth/bluetooth_device_chromeos.cc',
- 'bluetooth/bluetooth_device_chromeos.h',
'bluetooth/bluetooth_device_experimental_chromeos.cc',
'bluetooth/bluetooth_device_experimental_chromeos.h',
'bluetooth/bluetooth_device_mac.h',
@@ -54,15 +50,11 @@
'bluetooth/bluetooth_profile_win.h',
'bluetooth/bluetooth_service_record.cc',
'bluetooth/bluetooth_service_record.h',
- 'bluetooth/bluetooth_service_record_chromeos.cc',
- 'bluetooth/bluetooth_service_record_chromeos.h',
'bluetooth/bluetooth_service_record_mac.h',
'bluetooth/bluetooth_service_record_mac.mm',
'bluetooth/bluetooth_service_record_win.cc',
'bluetooth/bluetooth_service_record_win.h',
'bluetooth/bluetooth_socket.h',
- 'bluetooth/bluetooth_socket_chromeos.cc',
- 'bluetooth/bluetooth_socket_chromeos.h',
'bluetooth/bluetooth_socket_experimental_chromeos.cc',
'bluetooth/bluetooth_socket_experimental_chromeos.h',
'bluetooth/bluetooth_socket_mac.h',