diff options
author | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-25 14:20:11 +0000 |
---|---|---|
committer | keybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-25 14:20:11 +0000 |
commit | 5fe768daef11cbdafcacf624ef7160758128a18e (patch) | |
tree | a6bf7e90cdaaab0a1be517ba3b081a62e1b6cecd /chromeos | |
parent | a079559404596294b1bd7bc3701d2621407e8741 (diff) | |
download | chromium_src-5fe768daef11cbdafcacf624ef7160758128a18e.zip chromium_src-5fe768daef11cbdafcacf624ef7160758128a18e.tar.gz chromium_src-5fe768daef11cbdafcacf624ef7160758128a18e.tar.bz2 |
Bluetooth: remove legacy backend
BUG=221813
TEST=device_unittests
Review URL: https://chromiumcodereview.appspot.com/15020009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202281 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
44 files changed, 0 insertions, 5199 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_; |