Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Unified Diff: device/bluetooth/dbus/fake_bluetooth_device_client.cc

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/dbus/fake_bluetooth_device_client.cc
diff --git a/chromeos/dbus/fake_bluetooth_device_client.cc b/device/bluetooth/dbus/fake_bluetooth_device_client.cc
similarity index 94%
rename from chromeos/dbus/fake_bluetooth_device_client.cc
rename to device/bluetooth/dbus/fake_bluetooth_device_client.cc
index 8e086562a55366479c78b9449c4ed07372494d5f..5dd589bf08dbb44ae00402ba9a7540ec07c07506 100644
--- a/chromeos/dbus/fake_bluetooth_device_client.cc
+++ b/device/bluetooth/dbus/fake_bluetooth_device_client.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chromeos/dbus/fake_bluetooth_device_client.h"
+#include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
#include <fcntl.h>
#include <sys/socket.h>
@@ -22,15 +22,15 @@
#include "base/thread_task_runner_handle.h"
#include "base/threading/worker_pool.h"
#include "base/time/time.h"
-#include "chromeos/dbus/dbus_thread_manager.h"
-#include "chromeos/dbus/fake_bluetooth_adapter_client.h"
-#include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
-#include "chromeos/dbus/fake_bluetooth_agent_service_provider.h"
-#include "chromeos/dbus/fake_bluetooth_gatt_service_client.h"
-#include "chromeos/dbus/fake_bluetooth_input_client.h"
-#include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
-#include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
#include "dbus/file_descriptor.h"
+#include "device/bluetooth/dbus/bluez_dbus_manager.h"
+#include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
+#include "device/bluetooth/dbus/fake_bluetooth_agent_manager_client.h"
+#include "device/bluetooth/dbus/fake_bluetooth_agent_service_provider.h"
+#include "device/bluetooth/dbus/fake_bluetooth_gatt_service_client.h"
+#include "device/bluetooth/dbus/fake_bluetooth_input_client.h"
+#include "device/bluetooth/dbus/fake_bluetooth_profile_manager_client.h"
+#include "device/bluetooth/dbus/fake_bluetooth_profile_service_provider.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace {
@@ -94,7 +94,7 @@ void SimpleErrorCallback(const std::string& error_name,
} // namespace
-namespace chromeos {
+namespace bluez {
const char FakeBluetoothDeviceClient::kTestPinCode[] = "123456";
const int FakeBluetoothDeviceClient::kTestPassKey = 123456;
@@ -109,24 +109,20 @@ const char FakeBluetoothDeviceClient::kPairingActionDisplay[] = "Display";
const char FakeBluetoothDeviceClient::kPairingActionFail[] = "Fail";
const char FakeBluetoothDeviceClient::kPairingActionRequest[] = "Request";
-const char FakeBluetoothDeviceClient::kPairedDevicePath[] =
- "/fake/hci0/dev0";
+const char FakeBluetoothDeviceClient::kPairedDevicePath[] = "/fake/hci0/dev0";
const char FakeBluetoothDeviceClient::kPairedDeviceAddress[] =
"00:11:22:33:44:55";
-const char FakeBluetoothDeviceClient::kPairedDeviceName[] =
- "Fake Device";
+const char FakeBluetoothDeviceClient::kPairedDeviceName[] = "Fake Device";
const uint32 FakeBluetoothDeviceClient::kPairedDeviceClass = 0x000104;
-const char FakeBluetoothDeviceClient::kLegacyAutopairPath[] =
- "/fake/hci0/dev1";
+const char FakeBluetoothDeviceClient::kLegacyAutopairPath[] = "/fake/hci0/dev1";
const char FakeBluetoothDeviceClient::kLegacyAutopairAddress[] =
"28:CF:DA:00:00:00";
const char FakeBluetoothDeviceClient::kLegacyAutopairName[] =
"Bluetooth 2.0 Mouse";
const uint32 FakeBluetoothDeviceClient::kLegacyAutopairClass = 0x002580;
-const char FakeBluetoothDeviceClient::kDisplayPinCodePath[] =
- "/fake/hci0/dev2";
+const char FakeBluetoothDeviceClient::kDisplayPinCodePath[] = "/fake/hci0/dev2";
const char FakeBluetoothDeviceClient::kDisplayPinCodeAddress[] =
"28:37:37:00:00:00";
const char FakeBluetoothDeviceClient::kDisplayPinCodeName[] =
@@ -149,36 +145,29 @@ const char FakeBluetoothDeviceClient::kConnectUnpairableName[] =
"Unpairable Device";
const uint32 FakeBluetoothDeviceClient::kConnectUnpairableClass = 0x002580;
-const char FakeBluetoothDeviceClient::kDisplayPasskeyPath[] =
- "/fake/hci0/dev5";
+const char FakeBluetoothDeviceClient::kDisplayPasskeyPath[] = "/fake/hci0/dev5";
const char FakeBluetoothDeviceClient::kDisplayPasskeyAddress[] =
"00:0F:F6:00:00:00";
const char FakeBluetoothDeviceClient::kDisplayPasskeyName[] =
"Bluetooth 2.1+ Keyboard";
const uint32 FakeBluetoothDeviceClient::kDisplayPasskeyClass = 0x002540;
-const char FakeBluetoothDeviceClient::kRequestPinCodePath[] =
- "/fake/hci0/dev6";
+const char FakeBluetoothDeviceClient::kRequestPinCodePath[] = "/fake/hci0/dev6";
const char FakeBluetoothDeviceClient::kRequestPinCodeAddress[] =
"00:24:BE:00:00:00";
-const char FakeBluetoothDeviceClient::kRequestPinCodeName[] =
- "PIN Device";
+const char FakeBluetoothDeviceClient::kRequestPinCodeName[] = "PIN Device";
const uint32 FakeBluetoothDeviceClient::kRequestPinCodeClass = 0x240408;
-const char FakeBluetoothDeviceClient::kConfirmPasskeyPath[] =
- "/fake/hci0/dev7";
+const char FakeBluetoothDeviceClient::kConfirmPasskeyPath[] = "/fake/hci0/dev7";
const char FakeBluetoothDeviceClient::kConfirmPasskeyAddress[] =
"20:7D:74:00:00:00";
-const char FakeBluetoothDeviceClient::kConfirmPasskeyName[] =
- "Phone";
+const char FakeBluetoothDeviceClient::kConfirmPasskeyName[] = "Phone";
const uint32 FakeBluetoothDeviceClient::kConfirmPasskeyClass = 0x7a020c;
-const char FakeBluetoothDeviceClient::kRequestPasskeyPath[] =
- "/fake/hci0/dev8";
+const char FakeBluetoothDeviceClient::kRequestPasskeyPath[] = "/fake/hci0/dev8";
const char FakeBluetoothDeviceClient::kRequestPasskeyAddress[] =
"20:7D:74:00:00:01";
-const char FakeBluetoothDeviceClient::kRequestPasskeyName[] =
- "Passkey Device";
+const char FakeBluetoothDeviceClient::kRequestPasskeyName[] = "Passkey Device";
const uint32 FakeBluetoothDeviceClient::kRequestPasskeyClass = 0x7a020c;
const char FakeBluetoothDeviceClient::kUnconnectableDevicePath[] =
@@ -197,18 +186,13 @@ const char FakeBluetoothDeviceClient::kUnpairableDeviceName[] =
"Unpairable Device";
const uint32 FakeBluetoothDeviceClient::kUnpairableDeviceClass = 0x002540;
-const char FakeBluetoothDeviceClient::kJustWorksPath[] =
- "/fake/hci0/devB";
-const char FakeBluetoothDeviceClient::kJustWorksAddress[] =
- "00:0C:8A:00:00:00";
-const char FakeBluetoothDeviceClient::kJustWorksName[] =
- "Just-Works Device";
+const char FakeBluetoothDeviceClient::kJustWorksPath[] = "/fake/hci0/devB";
+const char FakeBluetoothDeviceClient::kJustWorksAddress[] = "00:0C:8A:00:00:00";
+const char FakeBluetoothDeviceClient::kJustWorksName[] = "Just-Works Device";
const uint32 FakeBluetoothDeviceClient::kJustWorksClass = 0x240428;
-const char FakeBluetoothDeviceClient::kLowEnergyPath[] =
- "/fake/hci0/devC";
-const char FakeBluetoothDeviceClient::kLowEnergyAddress[] =
- "00:1A:11:00:15:30";
+const char FakeBluetoothDeviceClient::kLowEnergyPath[] = "/fake/hci0/devC";
+const char FakeBluetoothDeviceClient::kLowEnergyAddress[] = "00:1A:11:00:15:30";
const char FakeBluetoothDeviceClient::kLowEnergyName[] =
"Bluetooth 4.0 Heart Rate Monitor";
const uint32 FakeBluetoothDeviceClient::kLowEnergyClass =
@@ -228,11 +212,9 @@ FakeBluetoothDeviceClient::Properties::Properties(
: BluetoothDeviceClient::Properties(
NULL,
bluetooth_device::kBluetoothDeviceInterface,
- callback) {
-}
+ callback) {}
-FakeBluetoothDeviceClient::Properties::~Properties() {
-}
+FakeBluetoothDeviceClient::Properties::~Properties() {}
void FakeBluetoothDeviceClient::Properties::Get(
dbus::PropertyBase* property,
@@ -246,7 +228,7 @@ void FakeBluetoothDeviceClient::Properties::GetAll() {
}
void FakeBluetoothDeviceClient::Properties::Set(
- dbus::PropertyBase *property,
+ dbus::PropertyBase* property,
dbus::PropertySet::SetCallback callback) {
VLOG(1) << "Set " << property->name();
if (property->name() == trusted.name()) {
@@ -320,11 +302,9 @@ FakeBluetoothDeviceClient::FakeBluetoothDeviceClient()
device_list_.push_back(dbus::ObjectPath(kPairedUnconnectableDevicePath));
}
-FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() {
-}
+FakeBluetoothDeviceClient::~FakeBluetoothDeviceClient() {}
-void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) {
-}
+void FakeBluetoothDeviceClient::Init(dbus::Bus* bus) {}
void FakeBluetoothDeviceClient::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
@@ -343,8 +323,8 @@ std::vector<dbus::ObjectPath> FakeBluetoothDeviceClient::GetDevicesForAdapter(
return std::vector<dbus::ObjectPath>();
}
-FakeBluetoothDeviceClient::Properties*
-FakeBluetoothDeviceClient::GetProperties(const dbus::ObjectPath& object_path) {
+FakeBluetoothDeviceClient::Properties* FakeBluetoothDeviceClient::GetProperties(
+ const dbus::ObjectPath& object_path) {
PropertiesMap::const_iterator iter = properties_map_.find(object_path);
if (iter != properties_map_.end())
return iter->second;
@@ -361,10 +341,9 @@ FakeBluetoothDeviceClient::GetPairingOptions(
return iter != pairing_options_map_.end() ? iter->second : nullptr;
}
-void FakeBluetoothDeviceClient::Connect(
- const dbus::ObjectPath& object_path,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
+void FakeBluetoothDeviceClient::Connect(const dbus::ObjectPath& object_path,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) {
VLOG(1) << "Connect: " << object_path.value();
Properties* properties = GetProperties(object_path);
@@ -398,7 +377,7 @@ void FakeBluetoothDeviceClient::Connect(
if (object_path == dbus::ObjectPath(kLowEnergyPath)) {
FakeBluetoothGattServiceClient* gatt_service_client =
static_cast<FakeBluetoothGattServiceClient*>(
- DBusThreadManager::Get()->GetBluetoothGattServiceClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient());
gatt_service_client->ExposeHeartRateService(
dbus::ObjectPath(kLowEnergyPath));
}
@@ -422,7 +401,7 @@ void FakeBluetoothDeviceClient::Disconnect(
if (object_path == dbus::ObjectPath(kLowEnergyPath)) {
FakeBluetoothGattServiceClient* gatt_service_client =
static_cast<FakeBluetoothGattServiceClient*>(
- DBusThreadManager::Get()->GetBluetoothGattServiceClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient());
gatt_service_client->HideHeartRateService();
}
@@ -439,7 +418,7 @@ void FakeBluetoothDeviceClient::ConnectProfile(
FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client =
static_cast<FakeBluetoothProfileManagerClient*>(
- DBusThreadManager::Get()->GetBluetoothProfileManagerClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothProfileManagerClient());
FakeBluetoothProfileServiceProvider* profile_service_provider =
fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid);
if (profile_service_provider == NULL) {
@@ -478,10 +457,8 @@ void FakeBluetoothDeviceClient::ConnectProfile(
return;
}
- base::WorkerPool::GetTaskRunner(false)->PostTask(
- FROM_HERE,
- base::Bind(&SimulatedProfileSocket,
- fds[0]));
+ base::WorkerPool::GetTaskRunner(false)
+ ->PostTask(FROM_HERE, base::Bind(&SimulatedProfileSocket, fds[0]));
scoped_ptr<dbus::FileDescriptor> fd(new dbus::FileDescriptor(fds[1]));
@@ -489,13 +466,9 @@ void FakeBluetoothDeviceClient::ConnectProfile(
BluetoothProfileServiceProvider::Delegate::Options options;
profile_service_provider->NewConnection(
- object_path,
- fd.Pass(),
- options,
+ object_path, fd.Pass(), options,
base::Bind(&FakeBluetoothDeviceClient::ConnectionCallback,
- base::Unretained(this),
- object_path,
- callback,
+ base::Unretained(this), object_path, callback,
error_callback));
}
@@ -508,7 +481,7 @@ void FakeBluetoothDeviceClient::DisconnectProfile(
FakeBluetoothProfileManagerClient* fake_bluetooth_profile_manager_client =
static_cast<FakeBluetoothProfileManagerClient*>(
- DBusThreadManager::Get()->GetBluetoothProfileManagerClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothProfileManagerClient());
FakeBluetoothProfileServiceProvider* profile_service_provider =
fake_bluetooth_profile_manager_client->GetProfileServiceProvider(uuid);
if (profile_service_provider == NULL) {
@@ -517,18 +490,14 @@ void FakeBluetoothDeviceClient::DisconnectProfile(
}
profile_service_provider->RequestDisconnection(
- object_path,
- base::Bind(&FakeBluetoothDeviceClient::DisconnectionCallback,
- base::Unretained(this),
- object_path,
- callback,
- error_callback));
+ object_path, base::Bind(&FakeBluetoothDeviceClient::DisconnectionCallback,
+ base::Unretained(this), object_path, callback,
+ error_callback));
}
-void FakeBluetoothDeviceClient::Pair(
- const dbus::ObjectPath& object_path,
- const base::Closure& callback,
- const ErrorCallback& error_callback) {
+void FakeBluetoothDeviceClient::Pair(const dbus::ObjectPath& object_path,
+ const base::Closure& callback,
+ const ErrorCallback& error_callback) {
VLOG(1) << "Pair: " << object_path.value();
Properties* properties = GetProperties(object_path);
@@ -610,8 +579,8 @@ void FakeBluetoothDeviceClient::SetSimulationIntervalMs(int interval_ms) {
void FakeBluetoothDeviceClient::CreateDevice(
const dbus::ObjectPath& adapter_path,
const dbus::ObjectPath& device_path) {
- if (std::find(device_list_.begin(),
- device_list_.end(), device_path) != device_list_.end())
+ if (std::find(device_list_.begin(), device_list_.end(), device_path) !=
+ device_list_.end())
return;
scoped_ptr<Properties> properties(
@@ -713,7 +682,6 @@ void FakeBluetoothDeviceClient::CreateDevice(
} else {
NOTREACHED();
-
}
properties_map_.insert(device_path, properties.Pass());
@@ -994,13 +962,13 @@ void FakeBluetoothDeviceClient::RemoveDevice(
// BluetoothDeviceChromeOS object, including the device_path referenced here.
FakeBluetoothInputClient* fake_bluetooth_input_client =
static_cast<FakeBluetoothInputClient*>(
- DBusThreadManager::Get()->GetBluetoothInputClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothInputClient());
fake_bluetooth_input_client->RemoveInputDevice(device_path);
if (device_path == dbus::ObjectPath(kLowEnergyPath)) {
FakeBluetoothGattServiceClient* gatt_service_client =
static_cast<FakeBluetoothGattServiceClient*>(
- DBusThreadManager::Get()->GetBluetoothGattServiceClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothGattServiceClient());
gatt_service_client->HideHeartRateService();
}
@@ -1083,7 +1051,6 @@ void FakeBluetoothDeviceClient::DiscoverySimulationTimer() {
UpdateDeviceRSSI(dbus::ObjectPath(kLowEnergyPath),
base::RandInt(kMinRSSI, kMaxRSSI));
return;
-
}
++discovery_simulation_step_;
@@ -1165,7 +1132,7 @@ void FakeBluetoothDeviceClient::SimulatePairing(
FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client =
static_cast<FakeBluetoothAgentManagerClient*>(
- DBusThreadManager::Get()->GetBluetoothAgentManagerClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothAgentManagerClient());
FakeBluetoothAgentServiceProvider* agent_service_provider =
fake_bluetooth_agent_manager_client->GetAgentServiceProvider();
CHECK(agent_service_provider != NULL);
@@ -1416,7 +1383,7 @@ void FakeBluetoothDeviceClient::AddInputDeviceIfNeeded(
// simulate the Input interface.
FakeBluetoothInputClient* fake_bluetooth_input_client =
static_cast<FakeBluetoothInputClient*>(
- DBusThreadManager::Get()->GetBluetoothInputClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothInputClient());
if ((properties->bluetooth_class.value() & 0x001f03) == 0x000500)
fake_bluetooth_input_client->AddInputDevice(object_path);
@@ -1586,7 +1553,7 @@ void FakeBluetoothDeviceClient::SimulateKeypress(
FakeBluetoothAgentManagerClient* fake_bluetooth_agent_manager_client =
static_cast<FakeBluetoothAgentManagerClient*>(
- DBusThreadManager::Get()->GetBluetoothAgentManagerClient());
+ bluez::BluezDBusManager::Get()->GetBluetoothAgentManagerClient());
FakeBluetoothAgentServiceProvider* agent_service_provider =
fake_bluetooth_agent_manager_client->GetAgentServiceProvider();
@@ -1649,4 +1616,4 @@ void FakeBluetoothDeviceClient::DisconnectionCallback(
}
}
-} // namespace chromeos
+} // namespace bluez

Powered by Google App Engine
This is Rietveld 408576698