summaryrefslogtreecommitdiffstats
path: root/device
diff options
context:
space:
mode:
authorkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-25 14:20:11 +0000
committerkeybuk@chromium.org <keybuk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-25 14:20:11 +0000
commit5fe768daef11cbdafcacf624ef7160758128a18e (patch)
treea6bf7e90cdaaab0a1be517ba3b081a62e1b6cecd /device
parenta079559404596294b1bd7bc3701d2621407e8741 (diff)
downloadchromium_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 'device')
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.cc536
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos.h241
-rw-r--r--device/bluetooth/bluetooth_adapter_chromeos_unittest.cc2226
-rw-r--r--device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc173
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.cc892
-rw-r--r--device/bluetooth/bluetooth_device_chromeos.h466
-rw-r--r--device/bluetooth/bluetooth_service_record_chromeos.cc178
-rw-r--r--device/bluetooth/bluetooth_service_record_chromeos.h37
-rw-r--r--device/bluetooth/bluetooth_service_record_chromeos_unittest.cc92
-rw-r--r--device/bluetooth/bluetooth_socket_chromeos.cc104
-rw-r--r--device/bluetooth/bluetooth_socket_chromeos.h54
-rw-r--r--device/device.gyp8
12 files changed, 0 insertions, 5007 deletions
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.cc b/device/bluetooth/bluetooth_adapter_chromeos.cc
deleted file mode 100644
index c24341b..0000000
--- a/device/bluetooth/bluetooth_adapter_chromeos.cc
+++ /dev/null
@@ -1,536 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "device/bluetooth/bluetooth_adapter_chromeos.h"
-
-#include <string>
-
-#include "base/bind.h"
-#include "base/logging.h"
-#include "base/stl_util.h"
-#include "base/values.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_manager_client.h"
-#include "chromeos/dbus/bluetooth_out_of_band_client.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_device_chromeos.h"
-#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
-
-using device::BluetoothAdapter;
-using device::BluetoothDevice;
-using device::BluetoothOutOfBandPairingData;
-
-namespace chromeos {
-
-BluetoothAdapterChromeOS::BluetoothAdapterChromeOS() : BluetoothAdapter(),
- powered_(false),
- discovering_(false),
- discovering_count_(0),
- weak_ptr_factory_(this) {
- DBusThreadManager::Get()->GetBluetoothManagerClient()->
- AddObserver(this);
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- AddObserver(this);
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- AddObserver(this);
-
- DBusThreadManager::Get()->GetBluetoothManagerClient()->
- DefaultAdapter(base::Bind(&BluetoothAdapterChromeOS::AdapterCallback,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-BluetoothAdapterChromeOS::~BluetoothAdapterChromeOS() {
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- RemoveObserver(this);
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- RemoveObserver(this);
- DBusThreadManager::Get()->GetBluetoothManagerClient()->
- RemoveObserver(this);
-
- STLDeleteValues(&devices_);
-}
-
-void BluetoothAdapterChromeOS::AddObserver(
- BluetoothAdapter::Observer* observer) {
- DCHECK(observer);
- observers_.AddObserver(observer);
-}
-
-void BluetoothAdapterChromeOS::RemoveObserver(
- BluetoothAdapter::Observer* observer) {
- DCHECK(observer);
- observers_.RemoveObserver(observer);
-}
-
-std::string BluetoothAdapterChromeOS::GetAddress() const {
- return address_;
-}
-
-std::string BluetoothAdapterChromeOS::GetName() const {
- return name_;
-}
-
-// TODO(youngki) Return true when object path and properties of the adapter are
-// initialized.
-bool BluetoothAdapterChromeOS::IsInitialized() const {
- return true;
-}
-
-bool BluetoothAdapterChromeOS::IsPresent() const {
- return !object_path_.value().empty() && !address_.empty();
-}
-
-bool BluetoothAdapterChromeOS::IsPowered() const {
- return powered_;
-}
-
-void BluetoothAdapterChromeOS::SetPowered(bool powered,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- GetProperties(object_path_)->powered.Set(
- powered,
- base::Bind(&BluetoothAdapterChromeOS::OnSetPowered,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-bool BluetoothAdapterChromeOS::IsDiscovering() const {
- return discovering_;
-}
-
-void BluetoothAdapterChromeOS::StartDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- // BlueZ counts discovery sessions, and permits multiple sessions for a
- // single connection, so issue a StartDiscovery() call for every use
- // within Chromium for the right behavior.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- StartDiscovery(object_path_,
- base::Bind(
- &BluetoothAdapterChromeOS::OnStartDiscovery,
- weak_ptr_factory_.GetWeakPtr(),
- callback, error_callback));
-}
-
-void BluetoothAdapterChromeOS::StopDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- // Inform BlueZ to stop one of our open discovery sessions.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- StopDiscovery(object_path_,
- base::Bind(
- &BluetoothAdapterChromeOS::OnStopDiscovery,
- weak_ptr_factory_.GetWeakPtr(),
- callback, error_callback));
-}
-
-void BluetoothAdapterChromeOS::ReadLocalOutOfBandPairingData(
- const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
- ReadLocalData(object_path_,
- base::Bind(&BluetoothAdapterChromeOS::OnReadLocalData,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothAdapterChromeOS::AdapterCallback(
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (success) {
- ChangeAdapter(adapter_path);
- } else if (!object_path_.value().empty()) {
- RemoveAdapter();
- }
-}
-
-void BluetoothAdapterChromeOS::DefaultAdapterChanged(
- const dbus::ObjectPath& adapter_path) {
- ChangeAdapter(adapter_path);
-}
-
-void BluetoothAdapterChromeOS::AdapterRemoved(
- const dbus::ObjectPath& adapter_path) {
- if (adapter_path == object_path_)
- RemoveAdapter();
-}
-
-void BluetoothAdapterChromeOS::ChangeAdapter(
- const dbus::ObjectPath& adapter_path) {
- if (object_path_.value().empty()) {
- VLOG(1) << "Adapter path initialized to " << adapter_path.value();
- } else if (object_path_.value() != adapter_path.value()) {
- VLOG(1) << "Adapter path changed from " << object_path_.value()
- << " to " << adapter_path.value();
-
- RemoveAdapter();
- } else {
- VLOG(1) << "Adapter address updated";
- }
-
- object_path_ = adapter_path;
-
- // Update properties to their new values.
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- GetProperties(object_path_);
-
- address_ = properties->address.value();
- name_ = properties->name.value();
-
- // Delay announcing a new adapter until we have an address.
- if (address_.empty()) {
- VLOG(1) << "Adapter address not yet known";
- return;
- }
-
- PoweredChanged(properties->powered.value());
- DiscoveringChanged(properties->discovering.value());
- DevicesChanged(properties->devices.value());
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterPresentChanged(this, true));
-}
-
-void BluetoothAdapterChromeOS::RemoveAdapter() {
- const bool adapter_was_present = IsPresent();
-
- VLOG(1) << "Adapter lost.";
- PoweredChanged(false);
- DiscoveringChanged(false);
- ClearDevices();
-
- object_path_ = dbus::ObjectPath("");
- address_.clear();
- name_.clear();
-
- if (adapter_was_present)
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterPresentChanged(this, false));
-}
-
-void BluetoothAdapterChromeOS::OnSetPowered(const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success) {
- if (success)
- callback.Run();
- else
- error_callback.Run();
-}
-
-void BluetoothAdapterChromeOS::PoweredChanged(bool powered) {
- if (powered == powered_)
- return;
-
- powered_ = powered;
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterPoweredChanged(this, powered_));
-}
-
-void BluetoothAdapterChromeOS::NotifyDeviceChanged(
- BluetoothDeviceChromeOS* device) {
- DCHECK(device->adapter_ == this);
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceChanged(this, device));
-}
-
-void BluetoothAdapterChromeOS::OnStartDiscovery(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (success) {
- if (discovering_count_++ == 0) {
- VLOG(1) << object_path_.value() << ": started discovery.";
-
- // Clear devices found in previous discovery attempts
- ClearDiscoveredDevices();
- }
-
- callback.Run();
- } else {
- error_callback.Run();
- }
-}
-
-void BluetoothAdapterChromeOS::OnStopDiscovery(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (success) {
- if (--discovering_count_ == 0) {
- VLOG(1) << object_path_.value() << ": stopped discovery.";
- } else if (discovering_count_ < 0) {
- LOG(WARNING) << adapter_path.value() << ": call to StopDiscovering "
- << "without matching StartDiscovering.";
- error_callback.Run();
- return;
- }
-
- callback.Run();
-
- // Leave found devices available for perusing.
- } else {
- error_callback.Run();
- }
-}
-
-void BluetoothAdapterChromeOS::DiscoveringChanged(bool discovering) {
- if (discovering == discovering_)
- return;
-
- discovering_ = discovering;
-
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- AdapterDiscoveringChanged(this, discovering_));
-}
-
-void BluetoothAdapterChromeOS::OnReadLocalData(
- const BluetoothAdapter::BluetoothOutOfBandPairingDataCallback& callback,
- const ErrorCallback& error_callback,
- const BluetoothOutOfBandPairingData& data,
- bool success) {
- if (success)
- callback.Run(data);
- else
- error_callback.Run();
-}
-
-void BluetoothAdapterChromeOS::AdapterPropertyChanged(
- const dbus::ObjectPath& adapter_path,
- const std::string& property_name) {
- if (adapter_path != object_path_)
- return;
-
- BluetoothAdapterClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- GetProperties(object_path_);
-
- if (property_name == properties->address.name()) {
- ChangeAdapter(object_path_);
-
- } else if (!address_.empty()) {
- if (property_name == properties->powered.name()) {
- PoweredChanged(properties->powered.value());
-
- } else if (property_name == properties->discovering.name()) {
- DiscoveringChanged(properties->discovering.value());
-
- } else if (property_name == properties->devices.name()) {
- DevicesChanged(properties->devices.value());
-
- } else if (property_name == properties->name.name()) {
- name_ = properties->name.value();
-
- }
- }
-}
-
-void BluetoothAdapterChromeOS::DevicePropertyChanged(
- const dbus::ObjectPath& device_path,
- const std::string& property_name) {
- UpdateDevice(device_path);
-}
-
-void BluetoothAdapterChromeOS::UpdateDevice(
- const dbus::ObjectPath& device_path) {
- BluetoothDeviceClient::Properties* properties =
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- GetProperties(device_path);
-
- // When we first see a device, we may not know the address yet and need to
- // wait for the DevicePropertyChanged signal before adding the device.
- const std::string address = properties->address.value();
- if (address.empty())
- return;
-
- // The device may be already known to us, either because this is an update
- // to properties, or the device going from discovered to connected and
- // pairing gaining an object path in the process. In any case, we want
- // to update the existing object, not create a new one.
- DevicesMap::iterator iter = devices_.find(address);
- BluetoothDeviceChromeOS* device;
- const bool update_device = (iter != devices_.end());
- if (update_device) {
- device = static_cast<BluetoothDeviceChromeOS*>(iter->second);
- } else {
- device = BluetoothDeviceChromeOS::Create(this);
- devices_[address] = device;
- }
-
- if (!device->HasObjectPath()) {
- VLOG(1) << "Assigned object path " << device_path.value() << " to device "
- << address;
- device->SetObjectPath(device_path);
- }
- device->Update(properties, true);
-
- if (update_device)
- NotifyDeviceChanged(device);
- else {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceAdded(this, device));
- }
-}
-
-void BluetoothAdapterChromeOS::ClearDevices() {
- DevicesMap replace;
- devices_.swap(replace);
- for (DevicesMap::iterator iter = replace.begin();
- iter != replace.end(); ++iter) {
- BluetoothDevice* device = iter->second;
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- delete device;
- }
-}
-
-void BluetoothAdapterChromeOS::DeviceCreated(
- const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& device_path) {
- if (adapter_path != object_path_)
- return;
-
- UpdateDevice(device_path);
-}
-
-void BluetoothAdapterChromeOS::DeviceRemoved(
- const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& device_path) {
- if (adapter_path != object_path_)
- return;
-
- DevicesMap::iterator iter = devices_.begin();
- while (iter != devices_.end()) {
- BluetoothDeviceChromeOS* device =
- static_cast<BluetoothDeviceChromeOS*>(iter->second);
- DevicesMap::iterator temp = iter;
- ++iter;
-
- if (device->object_path_ != device_path)
- continue;
-
- // DeviceRemoved can also be called to indicate a device that is visible
- // during discovery has disconnected, but it is still visible to the
- // adapter, so don't remove in that case and only clear the object path.
- if (!device->WasDiscovered()) {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- VLOG(1) << "Removed device " << device->GetAddress();
-
- delete device;
- devices_.erase(temp);
- } else {
- VLOG(1) << "Removed object path from device " << device->GetAddress();
- device->RemoveObjectPath();
-
- NotifyDeviceChanged(device);
- }
- }
-}
-
-void BluetoothAdapterChromeOS::DevicesChanged(
- const std::vector<dbus::ObjectPath>& devices) {
- for (std::vector<dbus::ObjectPath>::const_iterator iter =
- devices.begin(); iter != devices.end(); ++iter)
- UpdateDevice(*iter);
-}
-
-void BluetoothAdapterChromeOS::ClearDiscoveredDevices() {
- DevicesMap::iterator iter = devices_.begin();
- while (iter != devices_.end()) {
- BluetoothDeviceChromeOS* device =
- static_cast<BluetoothDeviceChromeOS*>(iter->second);
- DevicesMap::iterator temp = iter;
- ++iter;
-
- if (!device->HasObjectPath()) {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- delete device;
- devices_.erase(temp);
-
- } else
- device->SetDiscovered(false);
- }
-}
-
-void BluetoothAdapterChromeOS::DeviceFound(
- const dbus::ObjectPath& adapter_path,
- const std::string& address,
- const BluetoothDeviceClient::Properties& properties) {
- if (adapter_path != object_path_)
- return;
-
- // DeviceFound can also be called to indicate that a device we've
- // paired with is now visible to the adapter during discovery, in which
- // case we want to update the existing object, not create a new one.
- BluetoothDeviceChromeOS* device;
- DevicesMap::iterator iter = devices_.find(address);
- const bool update_device = (iter != devices_.end());
- if (update_device) {
- device = static_cast<BluetoothDeviceChromeOS*>(iter->second);
- } else {
- device = BluetoothDeviceChromeOS::Create(this);
- devices_[address] = device;
- }
-
- VLOG(1) << "Device " << address << " is visible to the adapter";
- device->SetDiscovered(true);
- device->Update(&properties, false);
-
- if (update_device)
- NotifyDeviceChanged(device);
- else {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceAdded(this, device));
- }
-}
-
-void BluetoothAdapterChromeOS::DeviceDisappeared(
- const dbus::ObjectPath& adapter_path,
- const std::string& address) {
- if (adapter_path != object_path_)
- return;
-
- DevicesMap::iterator iter = devices_.find(address);
- if (iter == devices_.end())
- return;
-
- BluetoothDeviceChromeOS* device =
- static_cast<BluetoothDeviceChromeOS*>(iter->second);
-
- // DeviceDisappeared can also be called to indicate that a device we've
- // paired with is no longer visible to the adapter, so don't remove
- // in that case and only clear the visible flag.
- if (!device->HasObjectPath()) {
- FOR_EACH_OBSERVER(BluetoothAdapter::Observer, observers_,
- DeviceRemoved(this, device));
-
- VLOG(1) << "Discovered device " << device->GetAddress()
- << " is no longer visible to the adapter";
-
- delete device;
- devices_.erase(iter);
- } else {
- VLOG(1) << "Paired device " << device->GetAddress()
- << " is no longer visible to the adapter";
- device->SetDiscovered(false);
-
- NotifyDeviceChanged(device);
- }
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_adapter_chromeos.h b/device/bluetooth/bluetooth_adapter_chromeos.h
deleted file mode 100644
index 3f422b6..0000000
--- a/device/bluetooth/bluetooth_adapter_chromeos.h
+++ /dev/null
@@ -1,241 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/callback.h"
-#include "base/observer_list.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_manager_client.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter.h"
-
-namespace device {
-
-class BluetoothAdapterFactory;
-class MockBluetoothAdapter;
-struct BluetoothOutOfBandPairingData;
-
-} // namespace device
-
-namespace chromeos {
-
-class BluetoothDeviceChromeOS;
-
-// The BluetoothAdapterChromeOS class is an implementation of BluetoothAdapter
-// for Chrome OS platform.
-class BluetoothAdapterChromeOS
- : public device::BluetoothAdapter,
- public BluetoothManagerClient::Observer,
- public BluetoothAdapterClient::Observer,
- public BluetoothDeviceClient::Observer {
- public:
- // BluetoothAdapter override
- virtual void AddObserver(
- device::BluetoothAdapter::Observer* observer) OVERRIDE;
- virtual void RemoveObserver(
- device::BluetoothAdapter::Observer* observer) OVERRIDE;
- virtual std::string GetAddress() const OVERRIDE;
- virtual std::string GetName() const OVERRIDE;
- virtual bool IsInitialized() const OVERRIDE;
- virtual bool IsPresent() const OVERRIDE;
- virtual bool IsPowered() const OVERRIDE;
- virtual void SetPowered(
- bool powered,
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual bool IsDiscovering() const OVERRIDE;
- virtual void StartDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void StopDiscovering(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void ReadLocalOutOfBandPairingData(
- const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
- callback,
- const ErrorCallback& error_callback) OVERRIDE;
-
- private:
- friend class BluetoothDeviceChromeOS;
- friend class device::BluetoothAdapterFactory;
- friend class device::MockBluetoothAdapter;
-
- BluetoothAdapterChromeOS();
- virtual ~BluetoothAdapterChromeOS();
-
- // Called by dbus:: in response to the method call sent by DefaultAdapter().
- // |object_path| will contain the dbus object path of the requested adapter
- // when |success| is true.
- void AdapterCallback(const dbus::ObjectPath& adapter_path, bool success);
-
- // BluetoothManagerClient::Observer override.
- //
- // Called when the default local bluetooth adapter changes.
- // |object_path| is the dbus object path of the new default adapter.
- // Not called if all adapters are removed.
- virtual void DefaultAdapterChanged(const dbus::ObjectPath& adapter_path)
- OVERRIDE;
-
- // BluetoothManagerClient::Observer override.
- //
- // Called when a local bluetooth adapter is removed.
- // |object_path| is the dbus object path of the adapter.
- virtual void AdapterRemoved(const dbus::ObjectPath& adapter_path) OVERRIDE;
-
- // Changes the tracked adapter to the dbus object path |adapter_path|,
- // clearing information from the previously tracked adapter and updating
- // to the new adapter.
- void ChangeAdapter(const dbus::ObjectPath& adapter_path);
-
- // Clears the tracked adapter information.
- void RemoveAdapter();
-
- // Called by dbus:: in response to the method call send by SetPowered().
- // |callback| and |error_callback| are the callbacks passed to SetPowered().
- void OnSetPowered(const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success);
-
- // Updates the tracked state of the adapter's radio power to |powered|
- // and notifies observers. Called on receipt of a property changed signal,
- // and directly using values obtained from properties.
- void PoweredChanged(bool powered);
-
- // Notifies observers of a change in the device |device|. Used to signal
- // changes initiated from the BluetoothDeviceChromeOS itself.
- void NotifyDeviceChanged(BluetoothDeviceChromeOS* device);
-
- // Called by BluetoothAdapterClient in response to the method call sent
- // by StartDiscovering(), |callback| and |error_callback| are the callbacks
- // provided to that method.
- void OnStartDiscovery(const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success);
-
- // Called by BluetoothAdapterClient in response to the method call sent
- // by StopDiscovering(), |callback| and |error_callback| are the callbacks
- // provided to that method.
- void OnStopDiscovery(const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success);
-
- // Updates the tracked state of the adapter's discovering state to
- // |discovering| and notifies observers. Called on receipt of a property
- // changed signal, and directly using values obtained from properties.
- void DiscoveringChanged(bool discovering);
-
- // Called by dbus:: in response to the ReadLocalData method call.
- void OnReadLocalData(
- const device::BluetoothAdapter::BluetoothOutOfBandPairingDataCallback&
- callback,
- const ErrorCallback& error_callback,
- const device::BluetoothOutOfBandPairingData& data,
- bool success);
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |adapter_path| has a
- // change in value of the property named |property_name|.
- virtual void AdapterPropertyChanged(const dbus::ObjectPath& adapter_path,
- const std::string& property_name)
- OVERRIDE;
-
- // BluetoothDeviceClient::Observer override.
- //
- // Called when the device with object path |device_path| has a
- // change in value of the property named |property_name|.
- virtual void DevicePropertyChanged(const dbus::ObjectPath& device_path,
- const std::string& property_name)
- OVERRIDE;
-
- // Updates information on the device with object path |device_path|,
- // adding it to the |devices_| map if not already present.
- void UpdateDevice(const dbus::ObjectPath& device_path);
-
- // Clears the |devices_| list, notifying obsevers of the device removal.
- void ClearDevices();
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| has a
- // new known device with object path |object_path|.
- virtual void DeviceCreated(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& device_path) OVERRIDE;
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| removes
- // the known device with object path |object_path|.
- virtual void DeviceRemoved(const dbus::ObjectPath& adapter_path,
- const dbus::ObjectPath& device_path) OVERRIDE;
-
- // Updates the adapter |devices_| list, adding or updating devices using
- // the object paths in the|devices| list. This doesn't remove devices,
- // relying instead on the DeviceRemoved() signal for that. Called on
- // receipt of a property changed signal, and directly using values obtained
- // from properties.
- void DevicesChanged(const std::vector<dbus::ObjectPath>& devices);
-
- // Clears discovered devices from the |devices_| list, notifying
- // observers, and leaving only those devices with a dbus object path.
- void ClearDiscoveredDevices();
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| discovers
- // a new remote device with address |address| and properties
- // |properties|, there is no device object path until connected.
- //
- // |properties| supports only value() calls, not Get() or Set(), and
- // should be copied if needed.
- virtual void DeviceFound(
- const dbus::ObjectPath& adapter_path,
- const std::string& address,
- const BluetoothDeviceClient::Properties& properties) OVERRIDE;
-
- // BluetoothAdapterClient::Observer override.
- //
- // Called when the adapter with object path |object_path| can no
- // longer communicate with the discovered removed device with
- // address |address|.
- virtual void DeviceDisappeared(const dbus::ObjectPath& object_path,
- const std::string& address) OVERRIDE;
-
- // List of observers interested in event notifications from us.
- ObserverList<device::BluetoothAdapter::Observer> observers_;
-
- // Object path of adapter for this instance, we update it to always
- // point at the default adapter.
- dbus::ObjectPath object_path_;
-
- // Tracked adapter state, cached locally so we only send change notifications
- // to observers on a genuine change.
- std::string address_;
- std::string name_;
- bool powered_;
- bool discovering_;
-
- // Count of callers to StartDiscovering() and StopDiscovering(), used to
- // track whether to clear the discovered devices list on start.
- int discovering_count_;
-
- // Note: This should remain the last member so it'll be destroyed and
- // invalidate its weak pointers before any other members are destroyed.
- base::WeakPtrFactory<BluetoothAdapterChromeOS> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothAdapterChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_ADAPTER_CHROMEOS_H_
diff --git a/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc b/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc
deleted file mode 100644
index 59cb632..0000000
--- a/device/bluetooth/bluetooth_adapter_chromeos_unittest.cc
+++ /dev/null
@@ -1,2226 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chromeos/dbus/mock_bluetooth_adapter_client.h"
-#include "chromeos/dbus/mock_bluetooth_manager_client.h"
-#include "chromeos/dbus/mock_dbus_thread_manager.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter.h"
-#include "device/bluetooth/bluetooth_adapter_chromeos.h"
-#include "device/bluetooth/bluetooth_adapter_factory.h"
-#include "device/bluetooth/test/mock_bluetooth_adapter.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using device::BluetoothAdapter;
-using device::BluetoothAdapterFactory;
-using device::MockBluetoothAdapter;
-using ::testing::_;
-using ::testing::InSequence;
-using ::testing::Return;
-using ::testing::SaveArg;
-
-namespace chromeos {
-
-class BluetoothAdapterChromeOSTest : public testing::Test {
- public:
- virtual void SetUp() {
- MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
-
- EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
- .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
- DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
-
- mock_manager_client_ =
- mock_dbus_thread_manager->mock_bluetooth_manager_client();
- mock_adapter_client_ =
- mock_dbus_thread_manager->mock_bluetooth_adapter_client();
-
- callback_called_ = false;
- error_callback_called_ = false;
- }
-
- virtual void TearDown() {
- adapter_ = NULL;
- DBusThreadManager::Shutdown();
- }
-
- void Callback() {
- callback_called_ = true;
- }
-
- void ErrorCallback() {
- error_callback_called_ = true;
- }
-
- void SetAdapter(scoped_refptr<device::BluetoothAdapter> adapter) {
- adapter_ = adapter;
- }
-
- protected:
- MockBluetoothManagerClient* mock_manager_client_;
- MockBluetoothAdapterClient* mock_adapter_client_;
-
- bool callback_called_;
- bool error_callback_called_;
-
- scoped_refptr<BluetoothAdapter> adapter_;
-};
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterNotPresent) {
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
- ASSERT_TRUE(adapter_ != NULL);
-
- // Call the adapter callback; make out it failed.
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(dbus::ObjectPath(""), false);
-
- // Adapter should not be present.
- EXPECT_FALSE(adapter_->IsPresent());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged will be called to
- // indicate the adapter is now present.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should be present with the given address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called
- // yet.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should not be present yet.
- EXPECT_FALSE(adapter_->IsPresent());
-
- // Tell the adapter the address now;
- // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should be present with the given address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterBecomesPresentWithAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback; make out it failed.
- adapter_callback.Run(dbus::ObjectPath(""), false);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(adapter_path);
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterReplacedWithAddress) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must be called once
- // with false to indicate the old adapter being removed and once with true
- // to announce the new adapter.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(new_adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterBecomesPresentWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback; make out it failed.
- adapter_callback.Run(dbus::ObjectPath(""), false);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(adapter_path);
-
- // Adapter should not be present yet.
- EXPECT_FALSE(adapter_->IsPresent());
-
- // Tell the adapter the address now;
- // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterReplacedWithoutAddress) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPresentChanged must be called to
- // indicate the adapter has gone away.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should be now marked not present.
- EXPECT_FALSE(adapter_->IsPresent());
-
- // Tell the adapter the address now;
- // BluetoothAdapter::Observer::AdapterPresentChanged now must be called.
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(new_adapter_path,
- new_adapter_properties.address.name());
-
- // Adapter should be present with the new address.
- EXPECT_TRUE(adapter_->IsPresent());
- EXPECT_EQ(new_adapter_address, adapter_->GetAddress());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterRemoved) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterPresentChanged will be called to
- // indicate the adapter is no longer present.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should be no longer present.
- EXPECT_FALSE(adapter_->IsPresent());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterWithoutAddressRemoved) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterPresentChanged must not be called
- // since we never should have announced it in the first place.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should be still no longer present.
- EXPECT_FALSE(adapter_->IsPresent());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyInitiallyFalse) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyInitiallyTrue) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyInitiallyTrueWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.powered.ReplaceValue(true);
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsPowered());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterPoweredPropertyChanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsPowered());
-
- // Report that the property has been changed;
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_properties.powered.ReplaceValue(true);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.powered.name());
-
- // Adapter should have the new property values.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterPoweredPropertyUnchanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-
- // Report that the property has been changed, but don't change the value;
- // BluetoothAdapter::Observer::AdapterPoweredChanged should not be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.powered.name());
-
- // Adapter should still have the same property values.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyChangedWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterPoweredChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Tell the adapter that its powered property changed, the observer
- // method should still not be called because there is no address for
- // the adapter so it is not present.
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.powered.name());
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsPowered());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterPoweredChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should now have the correct property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyResetOnReplace) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "00:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyResetOnReplaceWhenTrue) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
- new_adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called once
- // to set the value to false for the previous adapter and once to set the
- // value to true for the new adapter.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
- }
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_TRUE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterPoweredPropertyResetOnRemove) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterPoweredChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPoweredChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsPowered());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSetPowered) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Request that the powered property be changed;
- // MockBluetoothAdapterClient::Set should be called, passing the address
- // of the powered property and a callback to receive the response.
- dbus::PropertySet::SetCallback set_callback;
- EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _))
- .WillOnce(SaveArg<1>(&set_callback));
-
- adapter_->SetPowered(true,
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Reply to the callback to indicate success, the set callback we provided
- // should be called but the properties should not be refetched.
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .Times(0);
-
- set_callback.Run(true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSetPoweredError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Request that the powered property be changed;
- // MockBluetoothAdapterClient::Set should be called, passing the address
- // of the powered property and a callback to receive the response.
- dbus::PropertySet::SetCallback set_callback;
- EXPECT_CALL(adapter_properties, Set(&adapter_properties.powered, _))
- .WillOnce(SaveArg<1>(&set_callback));
-
- adapter_->SetPowered(true,
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Reply to the callback to indicate failure, the error callback we provided
- // should be called but the properties should not be refetched.
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .Times(0);
-
- set_callback.Run(false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyInitiallyFalse) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyInitiallyTrue) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyInitiallyTrueWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.discovering.ReplaceValue(true);
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterDiscoveringPropertyChanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(false);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-
- // Report that the property has been changed;
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_properties.discovering.ReplaceValue(true);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.discovering.name());
-
- // Adapter should have the new property values.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyUnchanged) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-
- // Report that the property has been changed, but don't change the value;
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged should not be
- // called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.discovering.name());
-
- // Adapter should still have the same property values.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyChangedWithoutAddress) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set but BluetoothAdapter::Observer::AdapterDiscoveringChanged
- // should not yet be called.
- MockBluetoothAdapterClient::Properties adapter_properties;
-
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- adapter_callback.Run(adapter_path, true);
-
- // Tell the adapter that its discovering property changed, the observer
- // method should still not be called because there is no address for
- // the adapter so it is not present.
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), _))
- .Times(0);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.discovering.name());
-
- // Adapter should not yet have the property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-
- // Tell the adapter the address now,
- // BluetoothAdapter::Observer::AdapterPresentChanged and
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged now must be called.
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(), true))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->AdapterPropertyChanged(adapter_path,
- adapter_properties.address.name());
-
- // Adapter should now have the correct property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyResetOnReplace) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- EXPECT_CALL(adapter_observer,
- AdapterDiscoveringChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyResetOnReplaceWhenTrue) {
- const dbus::ObjectPath initial_adapter_path("/fake/hci0");
- const dbus::ObjectPath new_adapter_path("/fake/hci1");
- const std::string initial_adapter_address = "CA:FE:4A:C0:FE:FE";
- const std::string new_adapter_address = "BA:C0:11:CO:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties initial_adapter_properties;
- initial_adapter_properties.address.ReplaceValue(initial_adapter_address);
- initial_adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(initial_adapter_path))
- .WillRepeatedly(Return(&initial_adapter_properties));
-
- adapter_callback.Run(initial_adapter_path, true);
-
- // Tell the adapter the default adapter changed;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties new_adapter_properties;
- new_adapter_properties.address.ReplaceValue(new_adapter_address);
- new_adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(new_adapter_path))
- .WillRepeatedly(Return(&new_adapter_properties));
-
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called once
- // to set the value to false for the previous adapter and once to set the
- // value to true for the new adapter.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- }
-
- {
- InSequence s;
-
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(),
- false))
- .Times(1);
- EXPECT_CALL(adapter_observer, AdapterDiscoveringChanged(adapter_.get(),
- true))
- .Times(1);
- }
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->DefaultAdapterChanged(new_adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_TRUE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterDiscoveringPropertyResetOnRemove) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
- adapter_properties.discovering.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Report that the adapter has been removed;
- // BluetoothAdapter::Observer::AdapterDiscoveringChanged will be called.
- MockBluetoothAdapter::Observer adapter_observer;
- adapter_->AddObserver(&adapter_observer);
-
- EXPECT_CALL(adapter_observer, AdapterPresentChanged(adapter_.get(), false))
- .Times(1);
- EXPECT_CALL(adapter_observer,
- AdapterDiscoveringChanged(adapter_.get(), false))
- .Times(1);
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
-
- static_cast<BluetoothManagerClient::Observer*>(adapter_chromeos)
- ->AdapterRemoved(adapter_path);
-
- // Adapter should have the new property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterNotInitiallyDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Adapter should have the correct property value.
- EXPECT_FALSE(adapter_->IsDiscovering());
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStartDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStartDiscoveringError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- start_discovery_callback.Run(adapter_path, false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterSecondStartDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success again.
- start_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterSecondStartDiscoveringError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- start_discovery_callback.Run(adapter_path, false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStopDiscovering) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest, DefaultAdapterStopDiscoveringError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- stop_discovery_callback.Run(adapter_path, false);
-
- EXPECT_FALSE(callback_called_);
- EXPECT_TRUE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterStopDiscoveringAfterSecondStart) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterStopDiscoveringAfterSecondStartError) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate failure.
- start_discovery_callback.Run(adapter_path, false);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-TEST_F(BluetoothAdapterChromeOSTest,
- DefaultAdapterSecondStopDiscoveringAfterSecondStart) {
- const dbus::ObjectPath adapter_path("/fake/hci0");
- const std::string adapter_address = "CA:FE:4A:C0:FE:FE";
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterChromeOSTest::SetAdapter,
- base::Unretained(this)));
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path))
- .WillRepeatedly(Return(&adapter_properties));
-
- adapter_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices;
- // BluetoothAdapterClient::StartDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback start_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to start discovering devices again;
- // BluetoothAdapterClient::StartDiscovery will be called again.
- EXPECT_CALL(*mock_adapter_client_, StartDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&start_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StartDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- start_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices;
- // BluetoothAdapterClient::StopDiscovery will be called.
- BluetoothAdapterClient::AdapterCallback stop_discovery_callback;
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- // Ask the adapter to stop discovering devices again;
- // BluetoothAdapterClient::StopDiscovery will be called.
- EXPECT_CALL(*mock_adapter_client_, StopDiscovery(adapter_path, _))
- .WillOnce(SaveArg<1>(&stop_discovery_callback));
-
- callback_called_ = false;
- error_callback_called_ = false;
-
- adapter_->StopDiscovering(
- base::Bind(&BluetoothAdapterChromeOSTest::Callback,
- base::Unretained(this)),
- base::Bind(&BluetoothAdapterChromeOSTest::ErrorCallback,
- base::Unretained(this)));
-
- // Return to indicate success.
- stop_discovery_callback.Run(adapter_path, true);
-
- EXPECT_TRUE(callback_called_);
- EXPECT_FALSE(error_callback_called_);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc b/device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc
deleted file mode 100644
index 723941a..0000000
--- a/device/bluetooth/bluetooth_adapter_devices_chromeos_unittest.cc
+++ /dev/null
@@ -1,173 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chromeos/dbus/mock_bluetooth_adapter_client.h"
-#include "chromeos/dbus/mock_bluetooth_device_client.h"
-#include "chromeos/dbus/mock_bluetooth_manager_client.h"
-#include "chromeos/dbus/mock_dbus_thread_manager.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter.h"
-#include "device/bluetooth/bluetooth_adapter_chromeos.h"
-#include "device/bluetooth/bluetooth_adapter_factory.h"
-#include "device/bluetooth/test/mock_bluetooth_adapter.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using device::BluetoothAdapter;
-using device::BluetoothAdapterFactory;
-using device::BluetoothDevice;
-using device::MockBluetoothAdapter;
-using ::testing::_;
-using ::testing::Mock;
-using ::testing::Return;
-using ::testing::SaveArg;
-
-namespace chromeos {
-
-class BluetoothAdapterDevicesChromeOSTest : public testing::Test {
- public:
- virtual void SetUp() {
- MockDBusThreadManager* mock_dbus_thread_manager = new MockDBusThreadManager;
-
- EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus())
- .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL)));
- DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager);
-
- mock_manager_client_ =
- mock_dbus_thread_manager->mock_bluetooth_manager_client();
- mock_adapter_client_ =
- mock_dbus_thread_manager->mock_bluetooth_adapter_client();
- mock_device_client_ =
- mock_dbus_thread_manager->mock_bluetooth_device_client();
-
- // Create the default adapter instance;
- // BluetoothManagerClient::DefaultAdapter will be called once, passing
- // a callback to obtain the adapter path.
- BluetoothManagerClient::AdapterCallback adapter_callback;
- EXPECT_CALL(*mock_manager_client_, DefaultAdapter(_))
- .WillOnce(SaveArg<0>(&adapter_callback));
-
- EXPECT_CALL(*mock_manager_client_, AddObserver(_))
- .Times(1);
- EXPECT_CALL(*mock_adapter_client_, AddObserver(_))
- .Times(1);
-
- BluetoothAdapterFactory::GetAdapter(
- base::Bind(&BluetoothAdapterDevicesChromeOSTest::SetAdapter,
- base::Unretained(this)));
- ASSERT_TRUE(adapter_ != NULL);
-
- // Call the adapter callback;
- // BluetoothAdapterClient::GetProperties will be called once to obtain
- // the property set.
- MockBluetoothAdapterClient::Properties adapter_properties;
- adapter_properties.address.ReplaceValue(adapter_address_);
- adapter_properties.powered.ReplaceValue(true);
-
- EXPECT_CALL(*mock_adapter_client_, GetProperties(adapter_path_))
- .WillRepeatedly(Return(&adapter_properties));
-
- // Add an observer to the adapter; expect the usual set of changes to
- // an adapter becoming present and then clear to clean up for the test.
- adapter_->AddObserver(&adapter_observer_);
-
- EXPECT_CALL(adapter_observer_, AdapterPresentChanged(adapter_.get(), true))
- .Times(1);
- EXPECT_CALL(adapter_observer_, AdapterPoweredChanged(adapter_.get(), true))
- .Times(1);
-
- adapter_callback.Run(adapter_path_, true);
-
- Mock::VerifyAndClearExpectations(mock_manager_client_);
- Mock::VerifyAndClearExpectations(mock_adapter_client_);
- Mock::VerifyAndClearExpectations(mock_device_client_);
- Mock::VerifyAndClearExpectations(&adapter_observer_);
- }
-
- virtual void TearDown() {
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
- EXPECT_CALL(*mock_device_client_, RemoveObserver(adapter_chromeos))
- .Times(1);
- EXPECT_CALL(*mock_adapter_client_, RemoveObserver(adapter_chromeos))
- .Times(1);
- EXPECT_CALL(*mock_manager_client_, RemoveObserver(adapter_chromeos))
- .Times(1);
-
- adapter_ = NULL;
- DBusThreadManager::Shutdown();
- }
-
- void SetAdapter(scoped_refptr<device::BluetoothAdapter> adapter) {
- adapter_ = adapter;
- }
-
- protected:
- MockBluetoothManagerClient* mock_manager_client_;
- MockBluetoothAdapterClient* mock_adapter_client_;
- MockBluetoothDeviceClient* mock_device_client_;
-
- static const dbus::ObjectPath adapter_path_;
- static const std::string adapter_address_;
- scoped_refptr<BluetoothAdapter> adapter_;
-
- MockBluetoothAdapter::Observer adapter_observer_;
-};
-
-const dbus::ObjectPath BluetoothAdapterDevicesChromeOSTest::adapter_path_(
- "/fake/hci0");
-const std::string BluetoothAdapterDevicesChromeOSTest::adapter_address_ =
- "CA:FE:4A:C0:FE:FE";
-
-TEST_F(BluetoothAdapterDevicesChromeOSTest, DeviceRemovedAfterFound) {
- const dbus::ObjectPath device_path("/fake/hci0/dev_ba_c0_11_00_00_01");
- const std::string device_address = "BA:C0:11:00:00:01";
-
- MockBluetoothDeviceClient::Properties device_properties;
- device_properties.address.ReplaceValue(device_address);
- device_properties.name.ReplaceValue("Fake Keyboard");
- device_properties.bluetooth_class.ReplaceValue(0x2540);
-
- // Inform the adapter that the device has been found;
- // BluetoothAdapterClient::Observer::DeviceAdded will be called, passing
- // the device object.
- BluetoothDevice* device;
- EXPECT_CALL(adapter_observer_, DeviceAdded(adapter_.get(), _))
- .Times(1)
- .WillOnce(SaveArg<1>(&device));
-
- BluetoothAdapterChromeOS* adapter_chromeos =
- static_cast<BluetoothAdapterChromeOS*>(adapter_.get());
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->DeviceFound(adapter_path_, device_address, device_properties);
-
- // Now inform the adapter that the device has been added and assigned an
- // object path; BluetoothDeviceClient::GetProperties will be called to
- // obtain the property set; and
- // BluetoothAdapterClient::Observer::DeviceChanged will be called passing
- // the same device object as before.
- EXPECT_CALL(*mock_device_client_, GetProperties(device_path))
- .WillRepeatedly(Return(&device_properties));
-
- EXPECT_CALL(adapter_observer_, DeviceChanged(adapter_chromeos, device))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->DeviceCreated(adapter_path_, device_path);
-
- // Finally remove the device again;
- // BluetoothAdapterClient::Observer::DeviceRemoved should be not called,
- // instead BluetoothAdapterClient::Observer::DeviceChanged will be called.
- EXPECT_CALL(adapter_observer_, DeviceRemoved(adapter_.get(), device))
- .Times(0);
- EXPECT_CALL(adapter_observer_, DeviceChanged(adapter_.get(), device))
- .Times(1);
-
- static_cast<BluetoothAdapterClient::Observer*>(adapter_chromeos)
- ->DeviceRemoved(adapter_path_, device_path);
-
- // Verify that the device is still visible, just no longer paired.
- EXPECT_FALSE(device->IsPaired());
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_device_chromeos.cc b/device/bluetooth/bluetooth_device_chromeos.cc
deleted file mode 100644
index 06ffc79..0000000
--- a/device/bluetooth/bluetooth_device_chromeos.cc
+++ /dev/null
@@ -1,892 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "device/bluetooth/bluetooth_device_chromeos.h"
-
-#include <map>
-#include <string>
-#include <vector>
-
-#include "base/bind.h"
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "base/memory/scoped_vector.h"
-#include "base/memory/weak_ptr.h"
-#include "base/string16.h"
-#include "base/string_util.h"
-#include "base/values.h"
-#include "chromeos/dbus/bluetooth_adapter_client.h"
-#include "chromeos/dbus/bluetooth_agent_service_provider.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "chromeos/dbus/bluetooth_input_client.h"
-#include "chromeos/dbus/bluetooth_out_of_band_client.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/introspectable_client.h"
-#include "dbus/bus.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_adapter_chromeos.h"
-#include "device/bluetooth/bluetooth_out_of_band_pairing_data.h"
-#include "device/bluetooth/bluetooth_service_record.h"
-#include "device/bluetooth/bluetooth_service_record_chromeos.h"
-#include "device/bluetooth/bluetooth_socket_chromeos.h"
-#include "device/bluetooth/bluetooth_utils.h"
-#include "third_party/cros_system_api/dbus/service_constants.h"
-
-using device::BluetoothDevice;
-using device::BluetoothOutOfBandPairingData;
-using device::BluetoothServiceRecord;
-using device::BluetoothSocket;
-
-namespace {
-
-void DoNothingServiceRecordList(const BluetoothDevice::ServiceRecordList&) {}
-
-} // namespace
-
-namespace chromeos {
-
-BluetoothDeviceChromeOS::BluetoothDeviceChromeOS(
- BluetoothAdapterChromeOS* adapter)
- : BluetoothDevice(),
- adapter_(adapter),
- bluetooth_class_(0),
- paired_(false),
- trusted_(false),
- connected_(false),
- connectable_(true),
- connecting_(false),
- pairing_delegate_(NULL),
- connecting_applications_counter_(0),
- connecting_calls_(0),
- service_records_loaded_(false),
- weak_ptr_factory_(this) {
-}
-
-BluetoothDeviceChromeOS::~BluetoothDeviceChromeOS() {
-}
-
-uint32 BluetoothDeviceChromeOS::GetBluetoothClass() const {
- return bluetooth_class_;
-}
-
-std::string BluetoothDeviceChromeOS::GetDeviceName() const {
- return name_;
-}
-
-std::string BluetoothDeviceChromeOS::GetAddress() const {
- return address_;
-}
-
-uint16 BluetoothDeviceChromeOS::GetVendorID() const {
- return 0;
-}
-
-uint16 BluetoothDeviceChromeOS::GetProductID() const {
- return 0;
-}
-
-uint16 BluetoothDeviceChromeOS::GetDeviceID() const {
- return 0;
-}
-
-bool BluetoothDeviceChromeOS::IsPaired() const {
- return paired_ || trusted_;
-}
-
-bool BluetoothDeviceChromeOS::IsConnected() const {
- return connected_;
-}
-
-bool BluetoothDeviceChromeOS::IsConnectable() const {
- return connectable_;
-}
-
-bool BluetoothDeviceChromeOS::IsConnecting() const {
- return connecting_;
-}
-
-BluetoothDeviceChromeOS::ServiceList
-BluetoothDeviceChromeOS::GetServices() const {
- return service_uuids_;
-}
-
-void BluetoothDeviceChromeOS::GetServiceRecords(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- DiscoverServices(
- object_path_,
- "", // empty pattern to browse all services
- base::Bind(&BluetoothDeviceChromeOS::CollectServiceRecordsCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- base::Bind(
- &BluetoothDeviceChromeOS::OnGetServiceRecordsError,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback)));
-}
-
-void BluetoothDeviceChromeOS::ProvidesServiceWithName(
- const std::string& name,
- const ProvidesServiceCallback& callback) {
- GetServiceRecords(
- base::Bind(&BluetoothDeviceChromeOS::SearchServicesForNameCallback,
- weak_ptr_factory_.GetWeakPtr(),
- name,
- callback),
- base::Bind(&BluetoothDeviceChromeOS::SearchServicesForNameErrorCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
-}
-
-bool BluetoothDeviceChromeOS::ExpectingPinCode() const {
- return !pincode_callback_.is_null();
-}
-
-bool BluetoothDeviceChromeOS::ExpectingPasskey() const {
- return !passkey_callback_.is_null();
-}
-
-bool BluetoothDeviceChromeOS::ExpectingConfirmation() const {
- return !confirmation_callback_.is_null();
-}
-
-void BluetoothDeviceChromeOS::Connect(
- PairingDelegate* pairing_delegate,
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) {
- // This is safe because Connect() and its callbacks are called in the same
- // thread.
- connecting_calls_++;
- if (!connecting_) {
- connecting_ = true;
- adapter_->NotifyDeviceChanged(this);
- }
- connecting_ = !!connecting_calls_;
- // Set the decrement to be issued when either callback is called.
- base::Closure wrapped_callback = base::Bind(
- &BluetoothDeviceChromeOS::OnConnectCallbackCalled,
- weak_ptr_factory_.GetWeakPtr(),
- callback);
- ConnectErrorCallback wrapped_error_callback = base::Bind(
- &BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled,
- weak_ptr_factory_.GetWeakPtr(),
- error_callback);
-
- if (IsPaired()) {
- // Connection to already paired device.
- ConnectApplications(wrapped_callback, wrapped_error_callback);
-
- } else if (!pairing_delegate || !IsPairable()) {
- // No pairing delegate supplied, or unpairable device; initiate
- // low-security connection only.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- CreateDevice(adapter_->object_path_,
- address_,
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_callback,
- wrapped_error_callback),
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_error_callback));
- } else {
- // Initiate high-security connection with pairing.
- DCHECK(!pairing_delegate_);
- pairing_delegate_ = pairing_delegate;
-
- // The agent path is relatively meaningless, we use the device address
- // to generate it as we only support one pairing attempt at a time for
- // a given bluetooth device.
- DCHECK(agent_.get() == NULL);
-
- std::string agent_path_basename;
- ReplaceChars(address_, ":", "_", &agent_path_basename);
- dbus::ObjectPath agent_path("/org/chromium/bluetooth_agent/" +
- agent_path_basename);
-
- dbus::Bus* system_bus = DBusThreadManager::Get()->GetSystemBus();
- if (system_bus) {
- agent_.reset(BluetoothAgentServiceProvider::Create(system_bus,
- agent_path,
- this));
- } else {
- agent_.reset(NULL);
- }
-
- VLOG(1) << "Pairing: " << address_;
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- CreatePairedDevice(
- adapter_->object_path_,
- address_,
- agent_path,
- bluetooth_agent::kDisplayYesNoCapability,
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDevice,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_callback,
- wrapped_error_callback),
- base::Bind(&BluetoothDeviceChromeOS::OnCreateDeviceError,
- weak_ptr_factory_.GetWeakPtr(),
- wrapped_error_callback));
- }
-}
-
-void BluetoothDeviceChromeOS::SetPinCode(const std::string& pincode) {
- if (!agent_.get() || pincode_callback_.is_null())
- return;
-
- pincode_callback_.Run(SUCCESS, pincode);
- pincode_callback_.Reset();
-}
-
-void BluetoothDeviceChromeOS::SetPasskey(uint32 passkey) {
- if (!agent_.get() || passkey_callback_.is_null())
- return;
-
- passkey_callback_.Run(SUCCESS, passkey);
- passkey_callback_.Reset();
-}
-
-void BluetoothDeviceChromeOS::ConfirmPairing() {
- if (!agent_.get() || confirmation_callback_.is_null())
- return;
-
- confirmation_callback_.Run(SUCCESS);
- confirmation_callback_.Reset();
-}
-
-void BluetoothDeviceChromeOS::RejectPairing() {
- if (!agent_.get())
- return;
-
- if (!pincode_callback_.is_null()) {
- pincode_callback_.Run(REJECTED, "");
- pincode_callback_.Reset();
- }
- if (!passkey_callback_.is_null()) {
- passkey_callback_.Run(REJECTED, 0);
- passkey_callback_.Reset();
- }
- if (!confirmation_callback_.is_null()) {
- confirmation_callback_.Run(REJECTED);
- confirmation_callback_.Reset();
- }
-}
-
-void BluetoothDeviceChromeOS::CancelPairing() {
- bool have_callback = false;
- if (agent_.get()) {
- if (!pincode_callback_.is_null()) {
- pincode_callback_.Run(CANCELLED, "");
- pincode_callback_.Reset();
- have_callback = true;
- }
- if (!passkey_callback_.is_null()) {
- passkey_callback_.Run(CANCELLED, 0);
- passkey_callback_.Reset();
- have_callback = true;
- }
- if (!confirmation_callback_.is_null()) {
- confirmation_callback_.Run(CANCELLED);
- confirmation_callback_.Reset();
- have_callback = true;
- }
- }
-
- if (!have_callback) {
- // User cancels the pairing process.
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->CancelDeviceCreation(
- adapter_->object_path_,
- address_,
- base::Bind(&BluetoothDeviceChromeOS::OnCancelDeviceCreation,
- weak_ptr_factory_.GetWeakPtr()));
-
- pairing_delegate_ = NULL;
- agent_.reset();
- }
-}
-
-void BluetoothDeviceChromeOS::Disconnect(const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- Disconnect(object_path_,
- base::Bind(&BluetoothDeviceChromeOS::DisconnectCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-
-}
-
-void BluetoothDeviceChromeOS::Forget(const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothAdapterClient()->
- RemoveDevice(adapter_->object_path_,
- object_path_,
- base::Bind(&BluetoothDeviceChromeOS::ForgetCallback,
- weak_ptr_factory_.GetWeakPtr(),
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::ConnectToService(const std::string& service_uuid,
- const SocketCallback& callback) {
- GetServiceRecords(
- base::Bind(&BluetoothDeviceChromeOS::GetServiceRecordsForConnectCallback,
- weak_ptr_factory_.GetWeakPtr(),
- service_uuid,
- callback),
- base::Bind(
- &BluetoothDeviceChromeOS::GetServiceRecordsForConnectErrorCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback));
-}
-
-void BluetoothDeviceChromeOS::ConnectToProfile(
- device::BluetoothProfile* profile,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- // TODO(keybuk): implement
-}
-
-void BluetoothDeviceChromeOS::SetOutOfBandPairingData(
- const BluetoothOutOfBandPairingData& data,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
- AddRemoteData(
- object_path_,
- address_,
- data,
- base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::ClearOutOfBandPairingData(
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
- DBusThreadManager::Get()->GetBluetoothOutOfBandClient()->
- RemoveRemoteData(
- object_path_,
- address_,
- base::Bind(&BluetoothDeviceChromeOS::OnRemoteDataCallback,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::SetObjectPath(
- const dbus::ObjectPath& object_path) {
- DCHECK(object_path_ == dbus::ObjectPath(""));
- object_path_ = object_path;
-}
-
-void BluetoothDeviceChromeOS::RemoveObjectPath() {
- DCHECK(object_path_ != dbus::ObjectPath(""));
- object_path_ = dbus::ObjectPath("");
-}
-
-void BluetoothDeviceChromeOS::Update(
- const BluetoothDeviceClient::Properties* properties,
- bool update_state) {
- std::string address = properties->address.value();
- std::string name = properties->name.value();
- uint32 bluetooth_class = properties->bluetooth_class.value();
- const std::vector<std::string>& uuids = properties->uuids.value();
-
- if (!address.empty())
- address_ = address;
- if (!name.empty())
- name_ = name;
- if (bluetooth_class)
- bluetooth_class_ = bluetooth_class;
- if (!uuids.empty()) {
- service_uuids_.clear();
- service_uuids_.assign(uuids.begin(), uuids.end());
- }
-
- if (update_state) {
- // When the device reconnects and we don't have any service records for it,
- // try to update the cache or fail silently.
- if (!service_records_loaded_ && !connected_ &&
- properties->connected.value())
- GetServiceRecords(base::Bind(&DoNothingServiceRecordList),
- base::Bind(&base::DoNothing));
-
- paired_ = properties->paired.value();
- trusted_ = properties->trusted.value();
- connected_ = properties->connected.value();
- }
-}
-
-void BluetoothDeviceChromeOS::OnCreateDevice(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const dbus::ObjectPath& device_path) {
- VLOG(1) << "Connection successful: " << device_path.value();
- if (object_path_.value().empty()) {
- object_path_ = device_path;
- } else {
- LOG_IF(WARNING, object_path_ != device_path)
- << "Conflicting device paths for objects, result gave: "
- << device_path.value() << " but signal gave: "
- << object_path_.value();
- }
-
- SetTrusted();
-
- // In parallel with the |trusted| property change, call GetServiceRecords to
- // retrieve the SDP from the device and then, either on success or failure,
- // call ConnectApplications.
- GetServiceRecords(
- base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecords,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback),
- base::Bind(&BluetoothDeviceChromeOS::OnInitialGetServiceRecordsError,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::OnCreateDeviceError(
- const ConnectErrorCallback& error_callback,
- const std::string& error_name,
- const std::string& error_message) {
- // The default |error_code| is an unknown error.
- ConnectErrorCode error_code = ERROR_UNKNOWN;
-
- // Report any error in the log, even if we know the possible source of it.
- LOG(WARNING) << "Connection failed (on CreatePairedDevice): "
- << "\"" << name_ << "\" (" << address_ << "): "
- << error_name << ": \"" << error_message << "\"";
-
- // Determines the right error code from error_name, assuming the error name
- // comes from CreatePairedDevice bluez function.
- if (error_name == bluetooth_adapter::kErrorConnectionAttemptFailed) {
- error_code = ERROR_FAILED;
- } else if (error_name == bluetooth_adapter::kErrorAuthenticationFailed) {
- error_code = ERROR_AUTH_FAILED;
- } else if (error_name == bluetooth_adapter::kErrorAuthenticationRejected) {
- error_code = ERROR_AUTH_REJECTED;
- } else if (error_name == bluetooth_adapter::kErrorAuthenticationTimeout) {
- error_code = ERROR_AUTH_TIMEOUT;
- }
- error_callback.Run(error_code);
-}
-
-void BluetoothDeviceChromeOS::CollectServiceRecordsCallback(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path,
- const BluetoothDeviceClient::ServiceMap& service_map,
- bool success) {
- if (!success) {
- error_callback.Run();
- return;
- }
-
- // Update the cache. No other thread is executing a GetServiceRecords
- // callback, so it is safe to delete the previous objects here.
- service_records_.clear();
- // TODO(deymo): Perhaps don't update the cache if the new SDP information is
- // empty and we had something before. Some devices only answer this
- // information while paired, and this callback could be called in any order if
- // several calls to GetServiceRecords are made while initial pairing with the
- // device. This requires more investigation.
- for (BluetoothDeviceClient::ServiceMap::const_iterator i =
- service_map.begin(); i != service_map.end(); ++i) {
- service_records_.push_back(
- new BluetoothServiceRecordChromeOS(address_, i->second));
- }
- service_records_loaded_ = true;
-
- callback.Run(service_records_);
-}
-
-void BluetoothDeviceChromeOS::SetTrusted() {
- // Unconditionally send the property change, rather than checking the value
- // first; there's no harm in doing this and it solves any race conditions
- // with the property becoming true or false and this call happening before
- // we get the D-Bus signal about the earlier change.
- DBusThreadManager::Get()->GetBluetoothDeviceClient()->
- GetProperties(object_path_)->trusted.Set(
- true,
- base::Bind(
- &BluetoothDeviceChromeOS::OnSetTrusted,
- weak_ptr_factory_.GetWeakPtr()));
-}
-
-void BluetoothDeviceChromeOS::OnSetTrusted(bool success) {
- LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_;
-}
-
-void BluetoothDeviceChromeOS::OnInitialGetServiceRecords(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const ServiceRecordList& list) {
- // Connect application-layer protocols.
- ConnectApplications(callback, error_callback);
-}
-
-void BluetoothDeviceChromeOS::OnInitialGetServiceRecordsError(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) {
- // Ignore the error retrieving the service records and continue.
- LOG(WARNING) << "Error retrieving SDP for " << address_ << " after pairing.";
- // Connect application-layer protocols.
- ConnectApplications(callback, error_callback);
-}
-
-void BluetoothDeviceChromeOS::OnGetServiceRecordsError(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback) {
- if (service_records_loaded_) {
- callback.Run(service_records_);
- } else {
- error_callback.Run();
- }
-}
-
-void BluetoothDeviceChromeOS::OnConnectCallbackCalled(
- const base::Closure& callback) {
- // Update the connecting status.
- bool prev_connecting = connecting_;
- connecting_calls_--;
- connecting_ = !!connecting_calls_;
- callback.Run();
- if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this);
-}
-
-void BluetoothDeviceChromeOS::OnConnectErrorCallbackCalled(
- const ConnectErrorCallback& error_callback,
- enum ConnectErrorCode error_code) {
- // Update the connecting status.
- bool prev_connecting = connecting_;
- connecting_calls_--;
- connecting_ = !!connecting_calls_;
- error_callback.Run(error_code);
- if (prev_connecting != connecting_) adapter_->NotifyDeviceChanged(this);
-}
-
-void BluetoothDeviceChromeOS::ConnectApplications(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) {
- // Introspect the device object to determine supported applications.
- DBusThreadManager::Get()->GetIntrospectableClient()->
- Introspect(bluetooth_device::kBluetoothDeviceServiceName,
- object_path_,
- base::Bind(&BluetoothDeviceChromeOS::OnIntrospect,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- error_callback));
-}
-
-void BluetoothDeviceChromeOS::OnIntrospect(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const std::string& service_name,
- const dbus::ObjectPath& device_path,
- const std::string& xml_data,
- bool success) {
- if (!success) {
- LOG(WARNING) << "Failed to determine supported applications: " << address_;
- error_callback.Run(ERROR_UNKNOWN);
- return;
- }
-
- // The introspection data for the device object may list one or more
- // additional D-Bus interfaces that BlueZ supports for this particular
- // device. Send appropraite Connect calls for each of those interfaces
- // to connect all of the application protocols for this device.
- std::vector<std::string> interfaces =
- IntrospectableClient::GetInterfacesFromIntrospectResult(xml_data);
-
- DCHECK_EQ(0, connecting_applications_counter_);
- connecting_applications_counter_ = 0;
- for (std::vector<std::string>::iterator iter = interfaces.begin();
- iter != interfaces.end(); ++iter) {
- if (*iter == bluetooth_input::kBluetoothInputInterface) {
- connecting_applications_counter_++;
- // Supports Input interface.
- DBusThreadManager::Get()->GetBluetoothInputClient()->
- Connect(object_path_,
- base::Bind(&BluetoothDeviceChromeOS::OnConnect,
- weak_ptr_factory_.GetWeakPtr(),
- callback,
- *iter),
- base::Bind(&BluetoothDeviceChromeOS::OnConnectError,
- weak_ptr_factory_.GetWeakPtr(),
- error_callback, *iter));
- }
- }
-
- // If OnConnect has been called for every call to Connect above, then this
- // will decrement the counter to -1. In that case, call the callback
- // directly as it has not been called by any of the OnConnect callbacks.
- // This is safe because OnIntrospect and OnConnect run on the same thread.
- connecting_applications_counter_--;
- if (connecting_applications_counter_ == -1)
- callback.Run();
-}
-
-void BluetoothDeviceChromeOS::OnConnect(const base::Closure& callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path) {
- VLOG(1) << "Application connection successful: " << device_path.value()
- << ": " << interface_name;
-
- connecting_applications_counter_--;
- // |callback| should only be called once, meaning it cannot be called before
- // all requests have been started. The extra decrement after all requests
- // have been started, and the check for -1 instead of 0 below, insure only a
- // single call to |callback| will occur (provided OnConnect and OnIntrospect
- // run on the same thread, which is true).
- if (connecting_applications_counter_ == -1) {
- connecting_applications_counter_ = 0;
- SetTrusted();
- callback.Run();
- }
-}
-
-void BluetoothDeviceChromeOS::OnConnectError(
- const ConnectErrorCallback& error_callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path,
- const std::string& error_name,
- const std::string& error_message) {
- // The default |error_code| is an unknown error.
- ConnectErrorCode error_code = ERROR_UNKNOWN;
-
- // Report any error in the log, even if we know the possible source of it.
- LOG(WARNING) << "Connection failed (on Connect): "
- << interface_name << ": "
- << "\"" << name_ << "\" (" << address_ << "): "
- << error_name << ": \"" << error_message << "\"";
-
- // Determines the right error code from error_name, assuming the error name
- // comes from Connect bluez function.
- if (error_name == bluetooth_adapter::kErrorFailed) {
- error_code = ERROR_FAILED;
- } else if (error_name == bluetooth_adapter::kErrorInProgress) {
- error_code = ERROR_INPROGRESS;
- } else if (error_name == bluetooth_adapter::kErrorNotSupported) {
- error_code = ERROR_UNSUPPORTED_DEVICE;
- }
-
- error_callback.Run(error_code);
-}
-
-void BluetoothDeviceChromeOS::DisconnectCallback(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path,
- bool success) {
- DCHECK(device_path == object_path_);
- if (success) {
- VLOG(1) << "Disconnection successful: " << address_;
- callback.Run();
- } else {
- if (connected_) {
- LOG(WARNING) << "Disconnection failed: " << address_;
- error_callback.Run();
- } else {
- VLOG(1) << "Disconnection failed on a already disconnected device: "
- << address_;
- callback.Run();
- }
- }
-}
-
-void BluetoothDeviceChromeOS::ForgetCallback(
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path,
- bool success) {
- // It's quite normal that this path never gets called on success; we use a
- // weak pointer, and bluetoothd might send the DeviceRemoved signal before
- // the method reply, in which case this object is deleted and the
- // callback never takes place. Therefore don't do anything here for the
- // success case.
- if (!success) {
- LOG(WARNING) << "Forget failed: " << address_;
- error_callback.Run();
- }
-}
-
-void BluetoothDeviceChromeOS::OnCancelDeviceCreation(
- const dbus::ObjectPath& adapter_path,
- bool success) {
- if (!success)
- LOG(WARNING) << "CancelDeviceCreation failed: " << address_;
-}
-
-void BluetoothDeviceChromeOS::SearchServicesForNameErrorCallback(
- const ProvidesServiceCallback& callback) {
- callback.Run(false);
-}
-
-void BluetoothDeviceChromeOS::SearchServicesForNameCallback(
- const std::string& name,
- const ProvidesServiceCallback& callback,
- const ServiceRecordList& list) {
- for (ServiceRecordList::const_iterator i = list.begin();
- i != list.end(); ++i) {
- if ((*i)->name() == name) {
- callback.Run(true);
- return;
- }
- }
- callback.Run(false);
-}
-
-void BluetoothDeviceChromeOS::GetServiceRecordsForConnectErrorCallback(
- const SocketCallback& callback) {
- callback.Run(NULL);
-}
-
-void BluetoothDeviceChromeOS::GetServiceRecordsForConnectCallback(
- const std::string& service_uuid,
- const SocketCallback& callback,
- const ServiceRecordList& list) {
- for (ServiceRecordList::const_iterator i = list.begin();
- i != list.end(); ++i) {
- if ((*i)->uuid() == service_uuid) {
- // If multiple service records are found, use the first one that works.
- scoped_refptr<BluetoothSocket> socket(
- BluetoothSocketChromeOS::CreateBluetoothSocket(**i));
- if (socket.get() != NULL) {
- callback.Run(socket);
- return;
- }
- }
- }
- callback.Run(NULL);
-}
-
-void BluetoothDeviceChromeOS::OnRemoteDataCallback(
- const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success) {
- if (success)
- callback.Run();
- else
- error_callback.Run();
-}
-
-void BluetoothDeviceChromeOS::DisconnectRequested(
- const dbus::ObjectPath& object_path) {
- DCHECK(object_path == object_path_);
-}
-
-void BluetoothDeviceChromeOS::Release() {
- DCHECK(agent_.get());
- VLOG(1) << "Release: " << address_;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DismissDisplayOrConfirm();
- pairing_delegate_ = NULL;
-
- pincode_callback_.Reset();
- passkey_callback_.Reset();
- confirmation_callback_.Reset();
-
- agent_.reset();
-}
-
-void BluetoothDeviceChromeOS::RequestPinCode(
- const dbus::ObjectPath& device_path,
- const PinCodeCallback& callback) {
- DCHECK(agent_.get());
- VLOG(1) << "RequestPinCode: " << device_path.value();
-
- DCHECK(pairing_delegate_);
- DCHECK(pincode_callback_.is_null());
- pincode_callback_ = callback;
- pairing_delegate_->RequestPinCode(this);
-}
-
-void BluetoothDeviceChromeOS::RequestPasskey(
- const dbus::ObjectPath& device_path,
- const PasskeyCallback& callback) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "RequestPasskey: " << device_path.value();
-
- DCHECK(pairing_delegate_);
- DCHECK(passkey_callback_.is_null());
- passkey_callback_ = callback;
- pairing_delegate_->RequestPasskey(this);
-}
-
-void BluetoothDeviceChromeOS::DisplayPinCode(
- const dbus::ObjectPath& device_path,
- const std::string& pincode) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "DisplayPinCode: " << device_path.value() << " " << pincode;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DisplayPinCode(this, pincode);
-}
-
-void BluetoothDeviceChromeOS::DisplayPasskey(
- const dbus::ObjectPath& device_path,
- uint32 passkey) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "DisplayPasskey: " << device_path.value() << " " << passkey;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DisplayPasskey(this, passkey);
-}
-
-void BluetoothDeviceChromeOS::RequestConfirmation(
- const dbus::ObjectPath& device_path,
- uint32 passkey,
- const ConfirmationCallback& callback) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- VLOG(1) << "RequestConfirmation: " << device_path.value() << " " << passkey;
-
- DCHECK(pairing_delegate_);
- DCHECK(confirmation_callback_.is_null());
- confirmation_callback_ = callback;
- pairing_delegate_->ConfirmPasskey(this, passkey);
-}
-
-void BluetoothDeviceChromeOS::Authorize(const dbus::ObjectPath& device_path,
- const std::string& uuid,
- const ConfirmationCallback& callback) {
- DCHECK(agent_.get());
- DCHECK(device_path == object_path_);
- LOG(WARNING) << "Rejected authorization for service: " << uuid
- << " requested from device: " << device_path.value();
- callback.Run(REJECTED);
-}
-
-void BluetoothDeviceChromeOS::ConfirmModeChange(
- Mode mode,
- const ConfirmationCallback& callback) {
- DCHECK(agent_.get());
- LOG(WARNING) << "Rejected adapter-level mode change: " << mode
- << " made on agent for device: " << address_;
- callback.Run(REJECTED);
-}
-
-void BluetoothDeviceChromeOS::Cancel() {
- DCHECK(agent_.get());
- VLOG(1) << "Cancel: " << address_;
-
- DCHECK(pairing_delegate_);
- pairing_delegate_->DismissDisplayOrConfirm();
-}
-
-
-// static
-BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create(
- BluetoothAdapterChromeOS* adapter) {
- return new BluetoothDeviceChromeOS(adapter);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_device_chromeos.h b/device/bluetooth/bluetooth_device_chromeos.h
deleted file mode 100644
index 72718b2..0000000
--- a/device/bluetooth/bluetooth_device_chromeos.h
+++ /dev/null
@@ -1,466 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
-
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
-#include "base/memory/weak_ptr.h"
-#include "base/string16.h"
-#include "chromeos/dbus/bluetooth_agent_service_provider.h"
-#include "chromeos/dbus/bluetooth_device_client.h"
-#include "dbus/object_path.h"
-#include "device/bluetooth/bluetooth_device.h"
-
-namespace device {
-
-class BluetoothServiceRecord;
-class MockBluetoothDevice;
-struct BluetoothOutOfBandPairingData;
-
-} // namespace device
-
-namespace chromeos {
-
-class BluetoothAdapterChromeOS;
-
-// The BluetoothDeviceChromeOS class is an implementation of BluetoothDevice
-// for Chrome OS platform.
-class BluetoothDeviceChromeOS
- : public device::BluetoothDevice,
- public BluetoothDeviceClient::Observer,
- public BluetoothAgentServiceProvider::Delegate {
- public:
- virtual ~BluetoothDeviceChromeOS();
-
- // BluetoothDevice override
- virtual uint32 GetBluetoothClass() const OVERRIDE;
- virtual std::string GetAddress() const OVERRIDE;
- virtual uint16 GetVendorID() const OVERRIDE;
- virtual uint16 GetProductID() const OVERRIDE;
- virtual uint16 GetDeviceID() const OVERRIDE;
- virtual bool IsPaired() const OVERRIDE;
- virtual bool IsConnected() const OVERRIDE;
- virtual bool IsConnectable() const OVERRIDE;
- virtual bool IsConnecting() const OVERRIDE;
- virtual ServiceList GetServices() const OVERRIDE;
- virtual void GetServiceRecords(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void ProvidesServiceWithName(
- const std::string& name,
- const ProvidesServiceCallback& callback) OVERRIDE;
- virtual bool ExpectingPinCode() const OVERRIDE;
- virtual bool ExpectingPasskey() const OVERRIDE;
- virtual bool ExpectingConfirmation() const OVERRIDE;
- virtual void Connect(
- device::BluetoothDevice::PairingDelegate* pairing_delegate,
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback) OVERRIDE;
- virtual void SetPinCode(const std::string& pincode) OVERRIDE;
- virtual void SetPasskey(uint32 passkey) OVERRIDE;
- virtual void ConfirmPairing() OVERRIDE;
- virtual void RejectPairing() OVERRIDE;
- virtual void CancelPairing() OVERRIDE;
- virtual void Disconnect(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void Forget(const ErrorCallback& error_callback) OVERRIDE;
- virtual void ConnectToService(
- const std::string& service_uuid,
- const SocketCallback& callback) OVERRIDE;
- virtual void ConnectToProfile(
- device::BluetoothProfile* profile,
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void SetOutOfBandPairingData(
- const device::BluetoothOutOfBandPairingData& data,
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
- virtual void ClearOutOfBandPairingData(
- const base::Closure& callback,
- const ErrorCallback& error_callback) OVERRIDE;
-
- protected:
- // BluetoothDevice override
- virtual std::string GetDeviceName() const OVERRIDE;
-
- private:
- friend class BluetoothAdapterChromeOS;
- friend class device::MockBluetoothDevice;
-
- explicit BluetoothDeviceChromeOS(BluetoothAdapterChromeOS* adapter);
-
- // Returns whether this device has an object path.
- bool HasObjectPath() const { return !object_path_.value().empty(); }
-
- // Sets the dbus object path for the device to |object_path|, indicating
- // that the device has gone from being discovered to paired or connected.
- void SetObjectPath(const dbus::ObjectPath& object_path);
-
- // Removes the dbus object path from the device, indicating that the
- // device is no longer paired or connected, but perhaps still visible.
- void RemoveObjectPath();
-
- // Returns whether this was a discovered device.
- bool WasDiscovered() const { return discovered_; }
-
- // Sets whether the device was discovered.
- void SetDiscovered(bool discovered) { discovered_ = discovered; }
-
- // Updates device information from the properties in |properties|, device
- // state properties such as |paired_| and |connected_| are ignored unless
- // |update_state| is true.
- void Update(const BluetoothDeviceClient::Properties* properties,
- bool update_state);
-
- // Called by BluetoothAdapterClient when a call to CreateDevice() or
- // CreatePairedDevice() succeeds, provides the new object path for the remote
- // device in |device_path|. |callback| and |error_callback| are the callbacks
- // provided to Connect().
- void OnCreateDevice(const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const dbus::ObjectPath& device_path);
-
- // Called by BluetoothAdapterClient when a call to CreateDevice() or
- // CreatePairedDevice() fails with the error named |error_name| and
- // optional message |error_message|, |error_callback| is the callback
- // provided to Connect().
- void OnCreateDeviceError(const ConnectErrorCallback& error_callback,
- const std::string& error_name,
- const std::string& error_message);
-
- // Called by BluetoothAdapterClient when a call to GetServiceRecords()
- // completes. |callback| and |error_callback| are the callbacks provided to
- // GetServiceRecords.
- void CollectServiceRecordsCallback(
- const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path,
- const BluetoothDeviceClient::ServiceMap& service_map,
- bool success);
-
- // Set the device as trusted. Trusted devices can connect to us automatically,
- // and we can connect to them after rebooting. This also causes the device to
- // be remembered by the stack even if not paired. |success| to the callback
- // indicates whether or not the request succeeded.
- void SetTrusted();
- void OnSetTrusted(bool success);
-
- // Called by BluetoothAdapterClient when a call to GetServiceRecords()
- // fails. |callback| and |error_callback| are the callbacks provided to
- // GetServiceRecords().
- void OnGetServiceRecordsError(const ServiceRecordsCallback& callback,
- const ErrorCallback& error_callback);
-
- // Called by BluetoothAdapterClient when the initial call to
- // GetServiceRecords() after pairing completes. |callback| and
- // |error_callback| are the callbacks provided to Connect().
- void OnInitialGetServiceRecords(const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const ServiceRecordList& list);
-
- // Called by BluetoothAdapterClient when the initial call to
- // GetServiceRecords() after pairing fails. |callback| and |error_callback|
- // are the callbacks provided to Connect().
- void OnInitialGetServiceRecordsError(
- const base::Closure& callback,
- const ConnectErrorCallback& error_callback);
-
- // Called by Connect() when it succeeds. The |callback| is the value passed to
- // the Connect() call.
- void OnConnectCallbackCalled(const base::Closure& callback);
-
- // Called by Connect() when it fails. The |error_callback| is the value passed
- // to the Connect() call.
- void OnConnectErrorCallbackCalled(const ConnectErrorCallback& error_callback,
- enum ConnectErrorCode error_code);
-
- // Connect application-level protocols of the device to the system, called
- // on a successful connection or to reconnect to a device that is already
- // paired or previously connected. |error_callback| is called on failure.
- // Otherwise, |callback| is called when the request is complete.
- void ConnectApplications(const base::Closure& callback,
- const ConnectErrorCallback& error_callback);
-
- // Called by IntrospectableClient when a call to Introspect() completes.
- // |success| indicates whether or not the request succeeded, |callback| and
- // |error_callback| are the callbacks provided to ConnectApplications(),
- // |service_name| and |device_path| specify the remote object being
- // introspected and |xml_data| contains the XML-formatted protocol data.
- void OnIntrospect(const base::Closure& callback,
- const ConnectErrorCallback& error_callback,
- const std::string& service_name,
- const dbus::ObjectPath& device_path,
- const std::string& xml_data, bool success);
-
- // Called by BluetoothInputClient when the call to Connect() succeeds.
- // |error_callback| is the callback provided to ConnectApplications(),
- // |interface_name| specifies the interface being connected and
- // |device_path| the remote object path.
- void OnConnect(const base::Closure& callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path);
-
- // Called by BluetoothInputClient when the call to Connect() fails.
- // |error_callback| is the callback provided to ConnectApplications(),
- // |interface_name| specifies the interface being connected,
- // |device_path| the remote object path,
- // |error_name| the error name and |error_message| the optional message.
- void OnConnectError(const ConnectErrorCallback& error_callback,
- const std::string& interface_name,
- const dbus::ObjectPath& device_path,
- const std::string& error_name,
- const std::string& error_message);
-
- // Called by BluetoothDeviceClient when a call to Disconnect() completes,
- // |success| indicates whether or not the request succeeded, |callback| and
- // |error_callback| are the callbacks provided to Disconnect() and
- // |device_path| is the device disconnected.
- void DisconnectCallback(const base::Closure& callback,
- const ErrorCallback& error_callback,
- const dbus::ObjectPath& device_path, bool success);
-
- // Called by BluetoothAdapterClient when a call to RemoveDevice()
- // completes, |success| indicates whether or not the request succeeded,
- // |error_callback| is the callback provided to Forget() and |adapter_path| is
- // the d-bus object path of the adapter that performed the removal.
- void ForgetCallback(const ErrorCallback& error_callback,
- const dbus::ObjectPath& adapter_path, bool success);
-
- // Called by BluetoothAdapterClient when a call to CancelDeviceCreation()
- // completes, |success| indicates whether or not the request succeeded.
- void OnCancelDeviceCreation(const dbus::ObjectPath& adapter_path,
- bool success);
-
- // Called if the call to GetServiceRecords from ProvidesServiceWithName fails.
- void SearchServicesForNameErrorCallback(
- const ProvidesServiceCallback& callback);
-
- // Called by GetServiceRecords with the list of BluetoothServiceRecords to
- // search for |name|. |callback| is the callback from
- // ProvidesServiceWithName.
- void SearchServicesForNameCallback(
- const std::string& name,
- const ProvidesServiceCallback& callback,
- const ServiceRecordList& list);
-
- // Called if the call to GetServiceRecords from Connect fails.
- void GetServiceRecordsForConnectErrorCallback(
- const SocketCallback& callback);
-
- // Called by GetServiceRecords with the list of BluetoothServiceRecords.
- // Connections are attempted to each service in the list matching
- // |service_uuid|, and the socket from the first successful connection is
- // passed to |callback|.
- void GetServiceRecordsForConnectCallback(
- const std::string& service_uuid,
- const SocketCallback& callback,
- const ServiceRecordList& list);
-
- // Called by BlueoothDeviceClient in response to the AddRemoteData and
- // RemoveRemoteData method calls.
- void OnRemoteDataCallback(const base::Closure& callback,
- const ErrorCallback& error_callback,
- bool success);
-
- // BluetoothDeviceClient::Observer override.
- //
- // Called when the device with object path |object_path| is about
- // to be disconnected, giving a chance for application layers to
- // shut down cleanly.
- virtual void DisconnectRequested(
- const dbus::ObjectPath& object_path) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the agent is unregistered from the
- // Bluetooth daemon, generally at the end of a pairing request. It may be
- // used to perform cleanup tasks.
- virtual void Release() OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires a
- // PIN Code for authentication of the device with object path |device_path|,
- // the agent should obtain the code from the user and call |callback|
- // to provide it, or indicate rejection or cancellation of the request.
- //
- // PIN Codes are generally required for Bluetooth 2.0 and earlier devices
- // for which there is no automatic pairing or special handling.
- virtual void RequestPinCode(const dbus::ObjectPath& device_path,
- const PinCodeCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires a
- // Passkey for authentication of the device with object path |device_path|,
- // the agent should obtain the passkey from the user (a numeric in the
- // range 0-999999) and call |callback| to provide it, or indicate
- // rejection or cancellation of the request.
- //
- // Passkeys are generally required for Bluetooth 2.1 and later devices
- // which cannot provide input or display on their own, and don't accept
- // passkey-less pairing.
- virtual void RequestPasskey(const dbus::ObjectPath& device_path,
- const PasskeyCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user enter the PIN code |pincode| into the device with object path
- // |device_path| so that it may be authenticated. The Cancel() method
- // will be called to dismiss the display once pairing is complete or
- // cancelled.
- //
- // This is used for Bluetooth 2.0 and earlier keyboard devices, the
- // |pincode| will always be a six-digit numeric in the range 000000-999999
- // for compatibilty with later specifications.
- virtual void DisplayPinCode(const dbus::ObjectPath& device_path,
- const std::string& pincode) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user enter the Passkey |passkey| into the device with object path
- // |device_path| so that it may be authenticated. The Cancel() method
- // will be called to dismiss the display once pairing is complete or
- // cancelled.
- //
- // This is used for Bluetooth 2.1 and later devices that support input
- // but not display, such as keyboards. The Passkey is a numeric in the
- // range 0-999999 and should be always presented zero-padded to six
- // digits.
- virtual void DisplayPasskey(const dbus::ObjectPath& device_path,
- uint32 passkey) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the Passkey |passkey| is displayed on the screen
- // of the device with object path |object_path| so that it may be
- // authentication. The agent should display to the user and ask for
- // confirmation, then call |callback| to provide their response (success,
- // rejected or cancelled).
- //
- // This is used for Bluetooth 2.1 and later devices that support display,
- // such as other computers or phones. The Passkey is a numeric in the
- // range 0-999999 and should be always present zero-padded to six
- // digits.
- virtual void RequestConfirmation(
- const dbus::ObjectPath& device_path,
- uint32 passkey,
- const ConfirmationCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the device with object path |object_path| is
- // authorized to connect to the service with UUID |uuid|. The agent should
- // confirm with the user and call |callback| to provide their response
- // (success, rejected or cancelled).
- virtual void Authorize(const dbus::ObjectPath& device_path,
- const std::string& uuid,
- const ConfirmationCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called when the Bluetooth daemon requires that the
- // user confirm that the device adapter may switch to mode |mode|. The
- // agent should confirm with the user and call |callback| to provide
- // their response (success, rejected or cancelled).
- virtual void ConfirmModeChange(Mode mode,
- const ConfirmationCallback& callback) OVERRIDE;
-
- // BluetoothAgentServiceProvider::Delegate override.
- //
- // This method will be called by the Bluetooth daemon to indicate that
- // the request failed before a reply was returned from the device.
- virtual void Cancel() OVERRIDE;
-
- // Creates a new BluetoothDeviceChromeOS object bound to the adapter
- // |adapter|.
- static BluetoothDeviceChromeOS* Create(BluetoothAdapterChromeOS* adapter);
-
- // The adapter that owns this device instance.
- BluetoothAdapterChromeOS* adapter_;
-
- // The dbus object path of the device, will be empty if the device has only
- // been discovered and not yet paired with.
- dbus::ObjectPath object_path_;
-
- // The Bluetooth class of the device, a bitmask that may be decoded using
- // https://www.bluetooth.org/Technical/AssignedNumbers/baseband.htm
- uint32 bluetooth_class_;
-
- // The name of the device, as supplied by the remote device.
- std::string name_;
-
- // The Bluetooth address of the device.
- std::string address_;
-
- // Tracked device state, updated by the adapter managing the lifecyle of
- // the device.
- bool paired_;
- bool trusted_;
- bool connected_;
-
- // Indicates whether the device normally accepts connections initiated from
- // the adapter once paired.
- bool connectable_;
-
- // Indicated whether the device is in a connecting status.
- bool connecting_;
-
- // Used by BluetoothAdapterChromeOS (a friend) to avoid removing discovered
- // devices when they are unpaired.
- bool discovered_;
-
- // The services (identified by UUIDs) that this device provides.
- ServiceList service_uuids_;
-
- // During pairing this is set to an object that we don't own, but on which
- // we can make method calls to request, display or confirm PIN Codes and
- // Passkeys. Generally it is the object that owns this one.
- device::BluetoothDevice::PairingDelegate* pairing_delegate_;
-
- // During pairing this is set to an instance of a D-Bus agent object
- // intialized with our own class as its delegate.
- scoped_ptr<BluetoothAgentServiceProvider> agent_;
-
- // During pairing these callbacks are set to those provided by method calls
- // made on us by |agent_| and are called by our own method calls such as
- // SetPinCode() and SetPasskey().
- PinCodeCallback pincode_callback_;
- PasskeyCallback passkey_callback_;
- ConfirmationCallback confirmation_callback_;
-
- // Used to keep track of pending application connection requests.
- int connecting_applications_counter_;
-
- // Used to keep track of ongoing calls to Connect().
- int connecting_calls_;
-
- // A service records cache.
- ServiceRecordList service_records_;
-
- // This says whether the |service_records_| cache is initialized. Note that an
- // empty |service_records_| list can be a valid list.
- bool service_records_loaded_;
-
- // Note: This should remain the last member so it'll be destroyed and
- // invalidate its weak pointers before any other members are destroyed.
- base::WeakPtrFactory<BluetoothDeviceChromeOS> weak_ptr_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_CHROMEOS_H_
diff --git a/device/bluetooth/bluetooth_service_record_chromeos.cc b/device/bluetooth/bluetooth_service_record_chromeos.cc
deleted file mode 100644
index b7ab878..0000000
--- a/device/bluetooth/bluetooth_service_record_chromeos.cc
+++ /dev/null
@@ -1,178 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "device/bluetooth/bluetooth_service_record_chromeos.h"
-
-#include <bluetooth/bluetooth.h>
-
-#include <string>
-#include <vector>
-
-#include "base/logging.h"
-#include "base/string_number_conversions.h"
-#include "device/bluetooth/bluetooth_utils.h"
-#include "third_party/libxml/chromium/libxml_utils.h"
-
-namespace {
-
-static const char* kAttributeNode = "attribute";
-static const char* kBooleanNode = "boolean";
-static const char* kSequenceNode = "sequence";
-static const char* kTextNode = "text";
-static const char* kUint8Node = "uint8";
-static const char* kUuidNode = "uuid";
-
-static const char* kIdAttribute = "id";
-static const char* kValueAttribute = "value";
-static const char* kValueTrue = "true";
-
-static const char* kHidNormallyConnectableId = "0x020d";
-static const char* kHidReconnectInitiateId = "0x0205";
-static const char* kProtocolDescriptorListId = "0x0004";
-static const char* kSdpNameId = "0x0100";
-static const char* kServiceClassUuidId = "0x0001";
-
-static const char* kProtocolRfcommUuid = "0x0003";
-static const char* kProtocolHidpUuid = "0x0011";
-
-bool AdvanceToTag(XmlReader* reader, const char* node_type) {
- do {
- if (!reader->Read())
- return false;
- } while (reader->NodeName() != node_type);
- return true;
-}
-
-bool ExtractTextValue(XmlReader* reader, std::string* value_out) {
- if (AdvanceToTag(reader, kTextNode)) {
- reader->NodeAttribute(kValueAttribute, value_out);
- return true;
- }
- return false;
-}
-
-bool ExtractBooleanValue(XmlReader* reader, bool* value_out) {
- if (AdvanceToTag(reader, kBooleanNode)) {
- std::string str_value;
- if (!reader->NodeAttribute(kValueAttribute, &str_value))
- return false;
- *value_out = str_value == kValueTrue;
- return true;
- }
- return false;
-}
-
-} // namespace
-
-namespace chromeos {
-
-BluetoothServiceRecordChromeOS::BluetoothServiceRecordChromeOS(
- const std::string& address,
- const std::string& xml_data) {
- address_ = address;
- supports_rfcomm_ = false;
- supports_hid_ = false;
-
- // For HID services the default is false when the attribute is not present.
- hid_reconnect_initiate_ = false;
- hid_normally_connectable_ = false;
-
- XmlReader reader;
- if (!reader.Load(xml_data))
- return;
-
- while (AdvanceToTag(&reader, kAttributeNode)) {
- std::string id;
- if (reader.NodeAttribute(kIdAttribute, &id)) {
- if (id == kSdpNameId) {
- ExtractTextValue(&reader, &name_);
- } else if (id == kProtocolDescriptorListId) {
- if (AdvanceToTag(&reader, kSequenceNode)) {
- ExtractProtocolDescriptors(&reader);
- }
- } else if (id == kServiceClassUuidId) {
- if (AdvanceToTag(&reader, kSequenceNode)) {
- ExtractServiceClassUuid(&reader);
- }
- } else if (id == kHidNormallyConnectableId) {
- ExtractBooleanValue(&reader, &hid_normally_connectable_);
- } else if (id == kHidReconnectInitiateId) {
- ExtractBooleanValue(&reader, &hid_reconnect_initiate_);
- }
- }
- // We don't care about anything else here, so find the closing tag
- AdvanceToTag(&reader, kAttributeNode);
- }
- if (!supports_hid_) {
- // For non-HID services the default is true.
- hid_normally_connectable_ = true;
- hid_reconnect_initiate_ = true;
- }
-}
-
-void BluetoothServiceRecordChromeOS::GetBluetoothAddress(
- bdaddr_t* out_address) const {
- std::string numbers_only;
- for (int i = 0; i < 6; ++i)
- numbers_only += address_.substr(i * 3, 2);
-
- std::vector<uint8> address_bytes;
- base::HexStringToBytes(numbers_only, &address_bytes);
- for (int i = 0; i < 6; ++i)
- out_address->b[5 - i] = address_bytes[i];
-}
-
-void BluetoothServiceRecordChromeOS::ExtractProtocolDescriptors(
- XmlReader* reader) {
- const int start_depth = reader->Depth();
- // The ProtocolDescriptorList can have one or more sequence of sequence of
- // stack, where each stack starts with an UUID and the remaining tags (if
- // present) are protocol-specific.
- do {
- if (reader->NodeName() == kSequenceNode) {
- if (AdvanceToTag(reader, kUuidNode)) {
- std::string protocolUuid;
- if (reader->NodeAttribute(kValueAttribute, &protocolUuid)) {
- // Per protocol parameters parsing.
- if (protocolUuid == kProtocolRfcommUuid) {
- if (AdvanceToTag(reader, kUint8Node)) {
- std::string channel_string;
- if (reader->NodeAttribute(kValueAttribute, &channel_string)) {
- std::vector<uint8> channel_bytes;
- if (base::HexStringToBytes(channel_string.substr(2),
- &channel_bytes)) {
- if (channel_bytes.size() == 1) {
- rfcomm_channel_ = channel_bytes[0];
- supports_rfcomm_ = true;
- }
- }
- }
- }
- } else if (protocolUuid == kProtocolHidpUuid) {
- supports_hid_ = true;
- }
- }
- }
- }
- } while (AdvanceToTag(reader, kSequenceNode) &&
- reader->Depth() != start_depth);
-}
-
-void BluetoothServiceRecordChromeOS::ExtractServiceClassUuid(
- XmlReader* reader) {
- const int start_depth = reader->Depth();
- do {
- if (reader->NodeName() == kSequenceNode) {
- if (AdvanceToTag(reader, kUuidNode)) {
- if (!reader->NodeAttribute(kValueAttribute, &uuid_))
- uuid_.clear();
- }
- }
- } while (AdvanceToTag(reader, kSequenceNode) &&
- reader->Depth() != start_depth);
-
- uuid_ = device::bluetooth_utils::CanonicalUuid(uuid_);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_service_record_chromeos.h b/device/bluetooth/bluetooth_service_record_chromeos.h
deleted file mode 100644
index 5d0ce9b..0000000
--- a/device/bluetooth/bluetooth_service_record_chromeos.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_CHROMEOS_H_
-
-#include <bluetooth/bluetooth.h>
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "device/bluetooth/bluetooth_service_record.h"
-
-class XmlReader;
-
-namespace chromeos {
-
-// BluetoothServiceRecordChromeOS is an implementation of BluetoothServiceRecord
-// for the ChromeOS platform.
-class BluetoothServiceRecordChromeOS : public device::BluetoothServiceRecord {
- public:
- BluetoothServiceRecordChromeOS(const std::string& address,
- const std::string& xml_data);
-
- void GetBluetoothAddress(bdaddr_t* out_address) const;
-
- private:
- void ExtractProtocolDescriptors(XmlReader* reader);
- void ExtractServiceClassUuid(XmlReader* reader);
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothServiceRecordChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_SERVICE_RECORD_CHROMEOS_H_
diff --git a/device/bluetooth/bluetooth_service_record_chromeos_unittest.cc b/device/bluetooth/bluetooth_service_record_chromeos_unittest.cc
deleted file mode 100644
index df4bab7..0000000
--- a/device/bluetooth/bluetooth_service_record_chromeos_unittest.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <bluetooth/bluetooth.h>
-
-#include <string>
-
-#include "base/base_paths.h"
-#include "base/basictypes.h"
-#include "base/file_util.h"
-#include "base/files/file_path.h"
-#include "base/path_service.h"
-#include "device/bluetooth/bluetooth_service_record_chromeos.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace {
-
-static const char* kAddress = "01:02:03:0A:10:A0";
-static const char* kCustomUuid = "01234567-89ab-cdef-0123-456789abcdef";
-static const char* kSerialUuid = "00001101-0000-1000-8000-00805f9b34fb";
-
-} // namespace
-
-namespace chromeos {
-
-class BluetoothServiceRecordChromeOSTest : public testing::Test {
- public:
- base::FilePath GetTestDataFilePath(const char* file) {
- base::FilePath path;
- PathService::Get(base::DIR_SOURCE_ROOT, &path);
- path = path.AppendASCII("device");
- path = path.AppendASCII("test");
- path = path.AppendASCII("data");
- path = path.AppendASCII("bluetooth");
- path = path.AppendASCII(file);
- return path;
- }
-};
-
-TEST_F(BluetoothServiceRecordChromeOSTest, RfcommService) {
- std::string xml_data;
- file_util::ReadFileToString(GetTestDataFilePath("rfcomm.xml"), &xml_data);
-
- BluetoothServiceRecordChromeOS service_record(kAddress, xml_data);
- EXPECT_EQ(kAddress, service_record.address());
- EXPECT_EQ("Headset Audio Gateway", service_record.name());
- EXPECT_TRUE(service_record.SupportsRfcomm());
- EXPECT_EQ((uint8)12, service_record.rfcomm_channel());
- EXPECT_EQ(kCustomUuid, service_record.uuid());
-}
-
-TEST_F(BluetoothServiceRecordChromeOSTest, ShortUuid) {
- std::string xml_data;
- file_util::ReadFileToString(GetTestDataFilePath("short_uuid.xml"), &xml_data);
- BluetoothServiceRecordChromeOS short_uuid_service_record(kAddress, xml_data);
- EXPECT_EQ(kSerialUuid, short_uuid_service_record.uuid());
-
- xml_data.clear();
- file_util::ReadFileToString(
- GetTestDataFilePath("medium_uuid.xml"), &xml_data);
- BluetoothServiceRecordChromeOS medium_uuid_service_record(kAddress, xml_data);
- EXPECT_EQ(kSerialUuid, medium_uuid_service_record.uuid());
-}
-
-TEST_F(BluetoothServiceRecordChromeOSTest, CleanUuid) {
- std::string xml_data;
- file_util::ReadFileToString(GetTestDataFilePath("uppercase_uuid.xml"),
- &xml_data);
- BluetoothServiceRecordChromeOS service_record(kAddress, xml_data);
- EXPECT_EQ(kCustomUuid, service_record.uuid());
-
- xml_data.clear();
- file_util::ReadFileToString(GetTestDataFilePath("invalid_uuid.xml"),
- &xml_data);
- BluetoothServiceRecordChromeOS invalid_service_record(kAddress, xml_data);
- EXPECT_EQ("", invalid_service_record.uuid());
-}
-
-TEST_F(BluetoothServiceRecordChromeOSTest, BluetoothAddress) {
- BluetoothServiceRecordChromeOS service_record(kAddress, "");
- bdaddr_t bluetooth_address;
- service_record.GetBluetoothAddress(&bluetooth_address);
- EXPECT_EQ(1, bluetooth_address.b[5]);
- EXPECT_EQ(2, bluetooth_address.b[4]);
- EXPECT_EQ(3, bluetooth_address.b[3]);
- EXPECT_EQ(10, bluetooth_address.b[2]);
- EXPECT_EQ(16, bluetooth_address.b[1]);
- EXPECT_EQ(160, bluetooth_address.b[0]);
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_socket_chromeos.cc b/device/bluetooth/bluetooth_socket_chromeos.cc
deleted file mode 100644
index 1558148..0000000
--- a/device/bluetooth/bluetooth_socket_chromeos.cc
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "device/bluetooth/bluetooth_socket_chromeos.h"
-
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <string>
-
-#include <bluetooth/bluetooth.h>
-#include <bluetooth/rfcomm.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-
-#include "base/logging.h"
-#include "base/safe_strerror_posix.h"
-#include "device/bluetooth/bluetooth_service_record_chromeos.h"
-#include "device/bluetooth/bluetooth_utils.h"
-#include "net/base/io_buffer.h"
-
-using device::BluetoothServiceRecord;
-using device::BluetoothSocket;
-
-namespace chromeos {
-
-BluetoothSocketChromeOS::BluetoothSocketChromeOS(int fd) : fd_(fd) {
-}
-
-BluetoothSocketChromeOS::~BluetoothSocketChromeOS() {
- close(fd_);
-}
-
-// static
-scoped_refptr<BluetoothSocket> BluetoothSocketChromeOS::CreateBluetoothSocket(
- const BluetoothServiceRecord& service_record) {
- BluetoothSocketChromeOS* bluetooth_socket = NULL;
- if (service_record.SupportsRfcomm()) {
- int socket_fd = socket(
- AF_BLUETOOTH, SOCK_STREAM | SOCK_NONBLOCK, BTPROTO_RFCOMM);
- struct sockaddr_rc socket_address = { 0 };
- socket_address.rc_family = AF_BLUETOOTH;
- socket_address.rc_channel = service_record.rfcomm_channel();
- const BluetoothServiceRecordChromeOS* service_record_chromeos =
- static_cast<const BluetoothServiceRecordChromeOS*>(&service_record);
- service_record_chromeos->GetBluetoothAddress(&socket_address.rc_bdaddr);
-
- int status = connect(socket_fd, (struct sockaddr *)&socket_address,
- sizeof(socket_address));
- int errsv = errno;
- if (status == 0 || errno == EINPROGRESS) {
- bluetooth_socket = new BluetoothSocketChromeOS(socket_fd);
- } else {
- LOG(ERROR) << "Failed to connect bluetooth socket "
- << "(" << service_record.address() << "): "
- << "(" << errsv << ") " << strerror(errsv);
- close(socket_fd);
- }
- }
- // TODO(bryeung): add support for L2CAP sockets as well.
-
- return scoped_refptr<BluetoothSocketChromeOS>(bluetooth_socket);
-}
-
-bool BluetoothSocketChromeOS::Receive(net::GrowableIOBuffer* buffer) {
- buffer->SetCapacity(1024);
- ssize_t bytes_read;
- do {
- if (buffer->RemainingCapacity() == 0)
- buffer->SetCapacity(buffer->capacity() * 2);
- bytes_read = read(fd_, buffer->data(), buffer->RemainingCapacity());
- if (bytes_read > 0)
- buffer->set_offset(buffer->offset() + bytes_read);
- } while (bytes_read > 0);
-
- if (bytes_read < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
- error_message_ = safe_strerror(errno);
- return false;
- }
- return true;
-}
-
-bool BluetoothSocketChromeOS::Send(net::DrainableIOBuffer* buffer) {
- ssize_t bytes_written;
- do {
- bytes_written = write(fd_, buffer->data(), buffer->BytesRemaining());
- if (bytes_written > 0)
- buffer->DidConsume(bytes_written);
- } while (buffer->BytesRemaining() > 0 && bytes_written > 0);
-
- if (bytes_written < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
- error_message_ = safe_strerror(errno);
- return false;
- }
- return true;
-}
-
-std::string BluetoothSocketChromeOS::GetLastErrorMessage() const {
- return error_message_;
-}
-
-} // namespace chromeos
diff --git a/device/bluetooth/bluetooth_socket_chromeos.h b/device/bluetooth/bluetooth_socket_chromeos.h
deleted file mode 100644
index d9e89fa..0000000
--- a/device/bluetooth/bluetooth_socket_chromeos.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
-#define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
-
-#include <string>
-
-#include "base/memory/ref_counted.h"
-#include "device/bluetooth/bluetooth_socket.h"
-
-namespace device {
-
-class BluetoothServiceRecord;
-
-} // namespace device
-
-namespace net {
-
-class DrainableIOBuffer;
-class GrowableIOBuffer;
-
-} // namespace net
-
-namespace chromeos {
-
-// This class is an implementation of BluetoothSocket class for Chrome OS
-// platform.
-class BluetoothSocketChromeOS : public device::BluetoothSocket {
- public:
- static scoped_refptr<device::BluetoothSocket> CreateBluetoothSocket(
- const device::BluetoothServiceRecord& service_record);
-
- // BluetoothSocket override
- virtual bool Receive(net::GrowableIOBuffer* buffer) OVERRIDE;
- virtual bool Send(net::DrainableIOBuffer* buffer) OVERRIDE;
- virtual std::string GetLastErrorMessage() const OVERRIDE;
-
- protected:
- virtual ~BluetoothSocketChromeOS();
-
- private:
- BluetoothSocketChromeOS(int fd);
-
- const int fd_;
- std::string error_message_;
-
- DISALLOW_COPY_AND_ASSIGN(BluetoothSocketChromeOS);
-};
-
-} // namespace chromeos
-
-#endif // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_CHROMEOS_H_
diff --git a/device/device.gyp b/device/device.gyp
index 4999705..7b26e34 100644
--- a/device/device.gyp
+++ b/device/device.gyp
@@ -21,8 +21,6 @@
'sources': [
'bluetooth/bluetooth_adapter.cc',
'bluetooth/bluetooth_adapter.h',
- 'bluetooth/bluetooth_adapter_chromeos.cc',
- 'bluetooth/bluetooth_adapter_chromeos.h',
'bluetooth/bluetooth_adapter_experimental_chromeos.cc',
'bluetooth/bluetooth_adapter_experimental_chromeos.h',
'bluetooth/bluetooth_adapter_factory.cc',
@@ -33,8 +31,6 @@
'bluetooth/bluetooth_adapter_win.h',
'bluetooth/bluetooth_device.cc',
'bluetooth/bluetooth_device.h',
- 'bluetooth/bluetooth_device_chromeos.cc',
- 'bluetooth/bluetooth_device_chromeos.h',
'bluetooth/bluetooth_device_experimental_chromeos.cc',
'bluetooth/bluetooth_device_experimental_chromeos.h',
'bluetooth/bluetooth_device_mac.h',
@@ -54,15 +50,11 @@
'bluetooth/bluetooth_profile_win.h',
'bluetooth/bluetooth_service_record.cc',
'bluetooth/bluetooth_service_record.h',
- 'bluetooth/bluetooth_service_record_chromeos.cc',
- 'bluetooth/bluetooth_service_record_chromeos.h',
'bluetooth/bluetooth_service_record_mac.h',
'bluetooth/bluetooth_service_record_mac.mm',
'bluetooth/bluetooth_service_record_win.cc',
'bluetooth/bluetooth_service_record_win.h',
'bluetooth/bluetooth_socket.h',
- 'bluetooth/bluetooth_socket_chromeos.cc',
- 'bluetooth/bluetooth_socket_chromeos.h',
'bluetooth/bluetooth_socket_experimental_chromeos.cc',
'bluetooth/bluetooth_socket_experimental_chromeos.h',
'bluetooth/bluetooth_socket_mac.h',