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

Unified Diff: device/bluetooth/dbus/bluez_dbus_manager.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/bluez_dbus_manager.cc
diff --git a/device/bluetooth/dbus/bluez_dbus_manager.cc b/device/bluetooth/dbus/bluez_dbus_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c83bcebc1caa7c8c64b5110725075d965fb31643
--- /dev/null
+++ b/device/bluetooth/dbus/bluez_dbus_manager.cc
@@ -0,0 +1,273 @@
+// 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/dbus/bluez_dbus_manager.h"
+
+#include "base/command_line.h"
+#include "base/sys_info.h"
+#include "base/threading/thread.h"
+#include "chromeos/chromeos_switches.h"
stevenjb 2015/09/17 21:48:01 Not needed
rkc 2015/09/21 18:54:22 Done.
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "dbus/bus.h"
+#include "dbus/dbus_statistics.h"
+#include "device/bluetooth/dbus/bluetooth_adapter_client.h"
+#include "device/bluetooth/dbus/bluetooth_agent_manager_client.h"
+#include "device/bluetooth/dbus/bluetooth_device_client.h"
+#include "device/bluetooth/dbus/bluetooth_gatt_characteristic_client.h"
+#include "device/bluetooth/dbus/bluetooth_gatt_descriptor_client.h"
+#include "device/bluetooth/dbus/bluetooth_gatt_manager_client.h"
+#include "device/bluetooth/dbus/bluetooth_gatt_service_client.h"
+#include "device/bluetooth/dbus/bluetooth_input_client.h"
+#include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h"
+#include "device/bluetooth/dbus/bluetooth_media_client.h"
+#include "device/bluetooth/dbus/bluetooth_media_transport_client.h"
+#include "device/bluetooth/dbus/bluetooth_profile_manager_client.h"
+
+namespace bluez {
+
+static BluezDBusManager* g_dbus_thread_manager = NULL;
+static bool g_using_dbus_thread_manager_for_testing = false;
+
+BluezDBusManager::BluezDBusManager(
+ scoped_ptr<BluetoothDBusClientBundle> client_bundle)
+ : client_bundle_(client_bundle.Pass()) {
+ // Make sure DBusThreadManager was initialized before us.
+ DCHECK(chromeos::DBusThreadManager::Get());
+}
+
+BluezDBusManager::~BluezDBusManager() {
+ // Delete all D-Bus clients before shutting down the system bus.
+ client_bundle_.reset();
+}
+
+dbus::Bus* bluez::BluezDBusManager::GetSystemBus() {
+ DCHECK(chromeos::DBusThreadManager::Get());
+ return chromeos::DBusThreadManager::Get()->GetSystemBus();
stevenjb 2015/09/17 21:48:01 Rather than depending on DBusThreadManager (which
rkc 2015/09/21 18:54:22 Done.
+}
+
+BluetoothAdapterClient* bluez::BluezDBusManager::GetBluetoothAdapterClient() {
+ return client_bundle_->bluetooth_adapter_client();
+}
+
+BluetoothLEAdvertisingManagerClient*
+bluez::BluezDBusManager::GetBluetoothLEAdvertisingManagerClient() {
+ return client_bundle_->bluetooth_le_advertising_manager_client();
+}
+
+BluetoothAgentManagerClient*
+bluez::BluezDBusManager::GetBluetoothAgentManagerClient() {
+ return client_bundle_->bluetooth_agent_manager_client();
+}
+
+BluetoothDeviceClient* bluez::BluezDBusManager::GetBluetoothDeviceClient() {
+ return client_bundle_->bluetooth_device_client();
+}
+
+BluetoothGattCharacteristicClient*
+bluez::BluezDBusManager::GetBluetoothGattCharacteristicClient() {
+ return client_bundle_->bluetooth_gatt_characteristic_client();
+}
+
+BluetoothGattDescriptorClient*
+bluez::BluezDBusManager::GetBluetoothGattDescriptorClient() {
+ return client_bundle_->bluetooth_gatt_descriptor_client();
+}
+
+BluetoothGattManagerClient*
+bluez::BluezDBusManager::GetBluetoothGattManagerClient() {
+ return client_bundle_->bluetooth_gatt_manager_client();
+}
+
+BluetoothGattServiceClient*
+bluez::BluezDBusManager::GetBluetoothGattServiceClient() {
+ return client_bundle_->bluetooth_gatt_service_client();
+}
+
+BluetoothInputClient* bluez::BluezDBusManager::GetBluetoothInputClient() {
+ return client_bundle_->bluetooth_input_client();
+}
+
+BluetoothMediaClient* bluez::BluezDBusManager::GetBluetoothMediaClient() {
+ return client_bundle_->bluetooth_media_client();
+}
+
+BluetoothMediaTransportClient*
+bluez::BluezDBusManager::GetBluetoothMediaTransportClient() {
+ return client_bundle_->bluetooth_media_transport_client();
+}
+
+BluetoothProfileManagerClient*
+bluez::BluezDBusManager::GetBluetoothProfileManagerClient() {
+ return client_bundle_->bluetooth_profile_manager_client();
+}
+
+void BluezDBusManager::InitializeClients() {
+ GetBluetoothAdapterClient()->Init(GetSystemBus());
+ GetBluetoothAgentManagerClient()->Init(GetSystemBus());
+ GetBluetoothDeviceClient()->Init(GetSystemBus());
+ GetBluetoothGattCharacteristicClient()->Init(GetSystemBus());
+ GetBluetoothGattDescriptorClient()->Init(GetSystemBus());
+ GetBluetoothGattManagerClient()->Init(GetSystemBus());
+ GetBluetoothGattServiceClient()->Init(GetSystemBus());
+ GetBluetoothInputClient()->Init(GetSystemBus());
+ GetBluetoothLEAdvertisingManagerClient()->Init(GetSystemBus());
+ GetBluetoothMediaClient()->Init(GetSystemBus());
+ GetBluetoothMediaTransportClient()->Init(GetSystemBus());
+ GetBluetoothProfileManagerClient()->Init(GetSystemBus());
+
+ // This must be called after the list of clients so they've each had a
+ // chance to register with their object g_dbus_thread_managers.
+ if (GetSystemBus())
+ GetSystemBus()->GetManagedObjects();
+}
+
+// static
+void BluezDBusManager::Initialize() {
+ // If we initialize BluezDBusManager twice we may also be shutting it down
+ // early; do not allow that.
+ if (g_using_dbus_thread_manager_for_testing)
+ return;
+
+ CHECK(!g_dbus_thread_manager);
+ bool use_dbus_stub = chromeos::DBusThreadManager::Get()->IsUsingStub(
+ chromeos::DBusClientBundle::BLUETOOTH);
stevenjb 2015/09/17 21:48:01 Pass |use_stub| here explicitly instead.
rkc 2015/09/21 18:54:22 Done.
+ if (use_dbus_stub) {
+ InitializeWithStubs();
+ } else {
+ InitializeWithRealClients();
+ }
+}
+
+// static
+scoped_ptr<BluezDBusManagerSetter>
+bluez::BluezDBusManager::GetSetterForTesting() {
+ if (!g_using_dbus_thread_manager_for_testing) {
+ g_using_dbus_thread_manager_for_testing = true;
+ InitializeWithStubs();
+ }
+
+ return make_scoped_ptr(new BluezDBusManagerSetter());
+}
+
+// static
+void BluezDBusManager::CreateGlobalInstance(bool use_stubs) {
+ CHECK(!g_dbus_thread_manager);
+ g_dbus_thread_manager = new BluezDBusManager(
+ make_scoped_ptr(new BluetoothDBusClientBundle(use_stubs)));
+ g_dbus_thread_manager->InitializeClients();
+}
+
+// static
+void BluezDBusManager::InitializeWithRealClients() {
+ CreateGlobalInstance(false);
+ VLOG(1) << "BluezDBusManager initialized for Chrome OS";
+}
+
+// static
+void BluezDBusManager::InitializeWithStubs() {
+ CreateGlobalInstance(true);
+ VLOG(1) << "BluezDBusManager created for testing";
+}
+
+// static
+bool BluezDBusManager::IsInitialized() {
+ return g_dbus_thread_manager != NULL;
+}
+
+// static
+void BluezDBusManager::Shutdown() {
+ // Ensure that we only shutdown BluezDBusManager once.
+ CHECK(g_dbus_thread_manager);
+ BluezDBusManager* dbus_thread_manager = g_dbus_thread_manager;
+ g_dbus_thread_manager = NULL;
+ g_using_dbus_thread_manager_for_testing = false;
+ delete dbus_thread_manager;
+ VLOG(1) << "BluezDBusManager Shutdown completed";
+}
+
+// static
+BluezDBusManager* bluez::BluezDBusManager::Get() {
+ CHECK(g_dbus_thread_manager)
+ << "bluez::BluezDBusManager::Get() called before Initialize()";
+ return g_dbus_thread_manager;
+}
+
+BluezDBusManagerSetter::BluezDBusManagerSetter() {}
+
+BluezDBusManagerSetter::~BluezDBusManagerSetter() {}
+
+void BluezDBusManagerSetter::SetBluetoothAdapterClient(
+ scoped_ptr<BluetoothAdapterClient> client) {
+ bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_adapter_client_ =
+ client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothLEAdvertisingManagerClient(
+ scoped_ptr<BluetoothLEAdvertisingManagerClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_le_advertising_manager_client_ =
+ client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothAgentManagerClient(
+ scoped_ptr<BluetoothAgentManagerClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_agent_manager_client_ = client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothDeviceClient(
+ scoped_ptr<BluetoothDeviceClient> client) {
+ bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_device_client_ =
+ client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothGattCharacteristicClient(
+ scoped_ptr<BluetoothGattCharacteristicClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_gatt_characteristic_client_ = client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothGattDescriptorClient(
+ scoped_ptr<BluetoothGattDescriptorClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_gatt_descriptor_client_ = client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothGattManagerClient(
+ scoped_ptr<BluetoothGattManagerClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_gatt_manager_client_ = client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothGattServiceClient(
+ scoped_ptr<BluetoothGattServiceClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_gatt_service_client_ = client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothInputClient(
+ scoped_ptr<BluetoothInputClient> client) {
+ bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_input_client_ =
+ client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothMediaClient(
+ scoped_ptr<BluetoothMediaClient> client) {
+ bluez::BluezDBusManager::Get()->client_bundle_->bluetooth_media_client_ =
+ client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothMediaTransportClient(
+ scoped_ptr<BluetoothMediaTransportClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_media_transport_client_ = client.Pass();
+}
+
+void BluezDBusManagerSetter::SetBluetoothProfileManagerClient(
+ scoped_ptr<BluetoothProfileManagerClient> client) {
+ bluez::BluezDBusManager::Get()
+ ->client_bundle_->bluetooth_profile_manager_client_ = client.Pass();
+}
+
+} // namespace bluez

Powered by Google App Engine
This is Rietveld 408576698