summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authorzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-14 08:00:37 +0000
committerzelidrag@chromium.org <zelidrag@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-14 08:02:12 +0000
commit944882dbc1c4c66e8f3aa730ce2f8d1d814d62e6 (patch)
treecb131779692e1c50ac68565799a2631062debc60 /chromeos
parent24cf7612a20b8a219524facffff076be1450fba5 (diff)
downloadchromium_src-944882dbc1c4c66e8f3aa730ce2f8d1d814d62e6.zip
chromium_src-944882dbc1c4c66e8f3aa730ce2f8d1d814d62e6.tar.gz
chromium_src-944882dbc1c4c66e8f3aa730ce2f8d1d814d62e6.tar.bz2
Added switch that let us 'un-stub' certain dbus clients.
Usage: chrome --dbus-stub --dbus-unstub-clients=client_1[,client_2[,...]] where <client_n> is in from the set of (bluetooth, cras, cros_disks, cryptohome, debug_daemon, easy_unlock, lorgnette_manager, shill, gsm_sms, imageburner, introspectable, modem_messaging, nfc, permission_broker, power_manager, session_manager, sms, system_clock, update_engine) BUG=401192 TEST=manual + DBusClientBundle.UnstubFlagParser Review URL: https://codereview.chromium.org/444263002 Cr-Commit-Position: refs/heads/master@{#289485} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/chromeos.gyp5
-rw-r--r--chromeos/chromeos_switches.cc4
-rw-r--r--chromeos/chromeos_switches.h1
-rw-r--r--chromeos/dbus/bluetooth_agent_service_provider.cc4
-rw-r--r--chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc4
-rw-r--r--chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc4
-rw-r--r--chromeos/dbus/bluetooth_gatt_service_service_provider.cc4
-rw-r--r--chromeos/dbus/bluetooth_profile_service_provider.cc4
-rw-r--r--chromeos/dbus/dbus_client_bundle.cc205
-rw-r--r--chromeos/dbus/dbus_client_bundle.h274
-rw-r--r--chromeos/dbus/dbus_client_bundle_unittest.cc40
-rw-r--r--chromeos/dbus/dbus_thread_manager.cc270
-rw-r--r--chromeos/dbus/dbus_thread_manager.h15
-rw-r--r--chromeos/dbus/mixed_dbus_thread_manager.cc205
-rw-r--r--chromeos/dbus/mixed_dbus_thread_manager.h81
15 files changed, 900 insertions, 220 deletions
diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp
index 872a782..0cf0cf2 100644
--- a/chromeos/chromeos.gyp
+++ b/chromeos/chromeos.gyp
@@ -114,6 +114,8 @@
'dbus/cros_disks_client.h',
'dbus/cryptohome_client.cc',
'dbus/cryptohome_client.h',
+ 'dbus/dbus_client_bundle.h',
+ 'dbus/dbus_client_bundle.cc',
'dbus/dbus_client_implementation_type.h',
'dbus/dbus_method_call_status.cc',
'dbus/dbus_method_call_status.h',
@@ -203,6 +205,8 @@
'dbus/introspectable_client.h',
'dbus/lorgnette_manager_client.cc',
'dbus/lorgnette_manager_client.h',
+ 'dbus/mixed_dbus_thread_manager.cc',
+ 'dbus/mixed_dbus_thread_manager.h',
'dbus/modem_messaging_client.cc',
'dbus/modem_messaging_client.h',
'dbus/nfc_adapter_client.cc',
@@ -534,6 +538,7 @@
'cryptohome/system_salt_getter_unittest.cc',
'dbus/blocking_method_caller_unittest.cc',
'dbus/cros_disks_client_unittest.cc',
+ 'dbus/dbus_client_bundle_unittest.cc',
'dbus/gsm_sms_client_unittest.cc',
'dbus/introspectable_client_unittest.cc',
'dbus/modem_messaging_client_unittest.cc',
diff --git a/chromeos/chromeos_switches.cc b/chromeos/chromeos_switches.cc
index 295f673..ac0e50c 100644
--- a/chromeos/chromeos_switches.cc
+++ b/chromeos/chromeos_switches.cc
@@ -21,6 +21,10 @@ const char kConsumerDeviceManagementUrl[] = "consumer-device-management-url";
// Forces the stub implementation of dbus clients.
const char kDbusStub[] = "dbus-stub";
+// Comma-spearated list of dbus clients that should be unstubbed.
+// See chromeos/dbus/dbus_client_bundle.cc for the names of the dbus clients.
+const char kDbusUnstubClients[] = "dbus-unstub-clients";
+
// Time before a machine at OOBE is considered derelict.
const char kDerelictDetectionTimeout[] = "derelict-detection-timeout";
diff --git a/chromeos/chromeos_switches.h b/chromeos/chromeos_switches.h
index 3de104e..4dc5a2c 100644
--- a/chromeos/chromeos_switches.h
+++ b/chromeos/chromeos_switches.h
@@ -24,6 +24,7 @@ CHROMEOS_EXPORT extern const char kAppOemManifestFile[];
CHROMEOS_EXPORT extern const char kAshWebUIInit[];
CHROMEOS_EXPORT extern const char kConsumerDeviceManagementUrl[];
CHROMEOS_EXPORT extern const char kDbusStub[];
+CHROMEOS_EXPORT extern const char kDbusUnstubClients[];
CHROMEOS_EXPORT extern const char kDerelictDetectionTimeout[];
CHROMEOS_EXPORT extern const char kDerelictIdleTimeout[];
CHROMEOS_EXPORT extern const char kDisableBootAnimation[];
diff --git a/chromeos/dbus/bluetooth_agent_service_provider.cc b/chromeos/dbus/bluetooth_agent_service_provider.cc
index 63e6d77..46117d1 100644
--- a/chromeos/dbus/bluetooth_agent_service_provider.cc
+++ b/chromeos/dbus/bluetooth_agent_service_provider.cc
@@ -9,8 +9,8 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
-#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_bluetooth_agent_service_provider.h"
#include "dbus/bus.h"
#include "dbus/exported_object.h"
@@ -469,7 +469,7 @@ BluetoothAgentServiceProvider* BluetoothAgentServiceProvider::Create(
dbus::Bus* bus,
const dbus::ObjectPath& object_path,
Delegate* delegate) {
- if (base::SysInfo::IsRunningOnChromeOS()) {
+ if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) {
return new BluetoothAgentServiceProviderImpl(bus, object_path, delegate);
} else {
return new FakeBluetoothAgentServiceProvider(object_path, delegate);
diff --git a/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc b/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc
index 6270854..c54610c 100644
--- a/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc
+++ b/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc
@@ -8,8 +8,8 @@
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_util.h"
-#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_bluetooth_gatt_characteristic_service_provider.h"
#include "dbus/exported_object.h"
#include "dbus/message.h"
@@ -464,7 +464,7 @@ BluetoothGattCharacteristicServiceProvider::Create(
const std::vector<std::string>& flags,
const std::vector<std::string>& permissions,
const dbus::ObjectPath& service_path) {
- if (base::SysInfo::IsRunningOnChromeOS()) {
+ if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) {
return new BluetoothGattCharacteristicServiceProviderImpl(
bus, object_path, delegate, uuid, flags, permissions, service_path);
}
diff --git a/chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc b/chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc
index 2dfe7a1..5040066 100644
--- a/chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc
+++ b/chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc
@@ -8,8 +8,8 @@
#include "base/logging.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string_util.h"
-#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_bluetooth_gatt_descriptor_service_provider.h"
#include "dbus/exported_object.h"
#include "dbus/message.h"
@@ -460,7 +460,7 @@ BluetoothGattDescriptorServiceProvider::Create(
const std::string& uuid,
const std::vector<std::string>& permissions,
const dbus::ObjectPath& characteristic_path) {
- if (base::SysInfo::IsRunningOnChromeOS()) {
+ if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) {
return new BluetoothGattDescriptorServiceProviderImpl(
bus, object_path, delegate, uuid, permissions, characteristic_path);
}
diff --git a/chromeos/dbus/bluetooth_gatt_service_service_provider.cc b/chromeos/dbus/bluetooth_gatt_service_service_provider.cc
index 545ccfc..88fd581 100644
--- a/chromeos/dbus/bluetooth_gatt_service_service_provider.cc
+++ b/chromeos/dbus/bluetooth_gatt_service_service_provider.cc
@@ -8,8 +8,8 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
-#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_bluetooth_gatt_service_service_provider.h"
#include "dbus/exported_object.h"
#include "dbus/message.h"
@@ -269,7 +269,7 @@ BluetoothGattServiceServiceProvider::Create(
const dbus::ObjectPath& object_path,
const std::string& uuid,
const std::vector<dbus::ObjectPath>& includes) {
- if (base::SysInfo::IsRunningOnChromeOS()) {
+ if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) {
return new BluetoothGattServiceServiceProviderImpl(
bus, object_path, uuid, includes);
}
diff --git a/chromeos/dbus/bluetooth_profile_service_provider.cc b/chromeos/dbus/bluetooth_profile_service_provider.cc
index e30fada..1d9f2b5 100644
--- a/chromeos/dbus/bluetooth_profile_service_provider.cc
+++ b/chromeos/dbus/bluetooth_profile_service_provider.cc
@@ -9,8 +9,8 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
-#include "base/sys_info.h"
#include "base/threading/platform_thread.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_bluetooth_profile_service_provider.h"
#include "dbus/bus.h"
#include "dbus/exported_object.h"
@@ -252,7 +252,7 @@ BluetoothProfileServiceProvider* BluetoothProfileServiceProvider::Create(
dbus::Bus* bus,
const dbus::ObjectPath& object_path,
Delegate* delegate) {
- if (base::SysInfo::IsRunningOnChromeOS()) {
+ if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) {
return new BluetoothProfileServiceProviderImpl(bus, object_path, delegate);
} else {
return new FakeBluetoothProfileServiceProvider(object_path, delegate);
diff --git a/chromeos/dbus/dbus_client_bundle.cc b/chromeos/dbus/dbus_client_bundle.cc
new file mode 100644
index 0000000..b5ccb8e
--- /dev/null
+++ b/chromeos/dbus/dbus_client_bundle.cc
@@ -0,0 +1,205 @@
+// Copyright 2014 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/dbus_client_bundle.h"
+
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
+#include "chromeos/dbus/bluetooth_adapter_client.h"
+#include "chromeos/dbus/bluetooth_agent_manager_client.h"
+#include "chromeos/dbus/bluetooth_device_client.h"
+#include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
+#include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
+#include "chromeos/dbus/bluetooth_gatt_manager_client.h"
+#include "chromeos/dbus/bluetooth_gatt_service_client.h"
+#include "chromeos/dbus/bluetooth_input_client.h"
+#include "chromeos/dbus/bluetooth_profile_manager_client.h"
+#include "chromeos/dbus/cras_audio_client.h"
+#include "chromeos/dbus/cros_disks_client.h"
+#include "chromeos/dbus/cryptohome_client.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/debug_daemon_client.h"
+#include "chromeos/dbus/easy_unlock_client.h"
+#include "chromeos/dbus/gsm_sms_client.h"
+#include "chromeos/dbus/image_burner_client.h"
+#include "chromeos/dbus/introspectable_client.h"
+#include "chromeos/dbus/lorgnette_manager_client.h"
+#include "chromeos/dbus/modem_messaging_client.h"
+#include "chromeos/dbus/nfc_adapter_client.h"
+#include "chromeos/dbus/nfc_device_client.h"
+#include "chromeos/dbus/nfc_manager_client.h"
+#include "chromeos/dbus/nfc_record_client.h"
+#include "chromeos/dbus/nfc_tag_client.h"
+#include "chromeos/dbus/permission_broker_client.h"
+#include "chromeos/dbus/power_manager_client.h"
+#include "chromeos/dbus/power_policy_controller.h"
+#include "chromeos/dbus/session_manager_client.h"
+#include "chromeos/dbus/shill_device_client.h"
+#include "chromeos/dbus/shill_ipconfig_client.h"
+#include "chromeos/dbus/shill_manager_client.h"
+#include "chromeos/dbus/shill_profile_client.h"
+#include "chromeos/dbus/shill_service_client.h"
+#include "chromeos/dbus/sms_client.h"
+#include "chromeos/dbus/system_clock_client.h"
+#include "chromeos/dbus/update_engine_client.h"
+
+namespace chromeos {
+
+namespace {
+
+// Command line switch mapping for --dbus-unstub-clients.
+const struct {
+ const char* param_name;
+ DBusClientBundle::DBusClientType client_type;
+} client_type_map[] = {
+ { "bluetooth", DBusClientBundle::BLUETOOTH },
+ { "cras", DBusClientBundle::CRAS },
+ { "cros_disks", DBusClientBundle::CROS_DISKS },
+ { "cryptohome", DBusClientBundle::CRYPTOHOME },
+ { "debug_daemon", DBusClientBundle::DEBUG_DAEMON },
+ { "easy_unlock", DBusClientBundle::EASY_UNLOCK },
+ { "lorgnette_manager", DBusClientBundle::LORGNETTE_MANAGER },
+ { "shill", DBusClientBundle::SHILL },
+ { "gsm_sms", DBusClientBundle::GSM_SMS },
+ { "image_burner", DBusClientBundle::IMAGE_BURNER },
+ { "introspectable", DBusClientBundle::INTROSPECTABLE },
+ { "modem_messaging", DBusClientBundle::MODEM_MESSAGING },
+ { "nfc", DBusClientBundle::NFC },
+ { "permission_broker", DBusClientBundle::PERMISSION_BROKER },
+ { "power_manager", DBusClientBundle::POWER_MANAGER },
+ { "session_manager", DBusClientBundle::SESSION_MANAGER },
+ { "sms", DBusClientBundle::SMS },
+ { "system_clock", DBusClientBundle::SYSTEM_CLOCK },
+ { "update_engine", DBusClientBundle::UPDATE_ENGINE },
+};
+
+// Parses single command line param value for dbus subsystem and returns its
+// enum representation. DBusClientType::UNKWNOWN is returned if |client_type|
+// does not match any known dbus client.
+DBusClientBundle::DBusClientType GetDBusClientType(
+ const std::string& client_type) {
+ for (size_t i = 0; i < arraysize(client_type_map); i++) {
+ if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name))
+ return client_type_map[i].client_type;
+ }
+ return DBusClientBundle::NO_CLIENTS;
+}
+
+} // namespace
+
+DBusClientBundle::DBusClientBundle() {
+ const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION;
+
+ if (!DBusThreadManager::IsUsingStub(BLUETOOTH)) {
+ bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create());
+ bluetooth_agent_manager_client_.reset(
+ BluetoothAgentManagerClient::Create());
+ bluetooth_device_client_.reset(BluetoothDeviceClient::Create());
+ bluetooth_input_client_.reset(BluetoothInputClient::Create());
+ bluetooth_profile_manager_client_.reset(
+ BluetoothProfileManagerClient::Create());
+ bluetooth_gatt_characteristic_client_.reset(
+ BluetoothGattCharacteristicClient::Create());
+ bluetooth_gatt_descriptor_client_.reset(
+ BluetoothGattDescriptorClient::Create());
+ bluetooth_gatt_manager_client_.reset(
+ BluetoothGattManagerClient::Create());
+ bluetooth_gatt_service_client_.reset(
+ BluetoothGattServiceClient::Create());
+ }
+
+ if (!DBusThreadManager::IsUsingStub(CRAS))
+ cras_audio_client_.reset(CrasAudioClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(CROS_DISKS))
+ cros_disks_client_.reset(CrosDisksClient::Create(type));
+
+ if (!DBusThreadManager::IsUsingStub(CRYPTOHOME))
+ cryptohome_client_.reset(CryptohomeClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(DEBUG_DAEMON))
+ debug_daemon_client_.reset(DebugDaemonClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(EASY_UNLOCK))
+ easy_unlock_client_.reset(EasyUnlockClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(LORGNETTE_MANAGER))
+ lorgnette_manager_client_.reset(LorgnetteManagerClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(SHILL)) {
+ shill_manager_client_.reset(ShillManagerClient::Create());
+ shill_device_client_.reset(ShillDeviceClient::Create());
+ shill_ipconfig_client_.reset(ShillIPConfigClient::Create());
+ shill_service_client_.reset(ShillServiceClient::Create());
+ shill_profile_client_.reset(ShillProfileClient::Create());
+ }
+
+ if (!DBusThreadManager::IsUsingStub(GSM_SMS))
+ gsm_sms_client_.reset(GsmSMSClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(IMAGE_BURNER))
+ image_burner_client_.reset(ImageBurnerClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(INTROSPECTABLE))
+ introspectable_client_.reset(IntrospectableClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(MODEM_MESSAGING))
+ modem_messaging_client_.reset(ModemMessagingClient::Create());
+
+ // Create the NFC clients in the correct order based on their dependencies.
+ if (!DBusThreadManager::IsUsingStub(NFC)) {
+ nfc_manager_client_.reset(NfcManagerClient::Create());
+ nfc_adapter_client_.reset(
+ NfcAdapterClient::Create(nfc_manager_client_.get()));
+ nfc_device_client_.reset(
+ NfcDeviceClient::Create(nfc_adapter_client_.get()));
+ nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get()));
+ nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(),
+ nfc_tag_client_.get()));
+ }
+
+ if (!DBusThreadManager::IsUsingStub(PERMISSION_BROKER))
+ permission_broker_client_.reset(PermissionBrokerClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(POWER_MANAGER))
+ power_manager_client_.reset(PowerManagerClient::Create(type));
+
+ if (!DBusThreadManager::IsUsingStub(SESSION_MANAGER))
+ session_manager_client_.reset(SessionManagerClient::Create(type));
+
+ if (!DBusThreadManager::IsUsingStub(SMS))
+ sms_client_.reset(SMSClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(SYSTEM_CLOCK))
+ system_clock_client_.reset(SystemClockClient::Create());
+
+ if (!DBusThreadManager::IsUsingStub(UPDATE_ENGINE))
+ update_engine_client_.reset(UpdateEngineClient::Create(type));
+}
+
+DBusClientBundle::~DBusClientBundle() {
+}
+
+// static
+DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList(
+ const std::string& unstub_list) {
+ DBusClientTypeMask unstub_mask = 0;
+ std::vector<std::string> unstub_components;
+ base::SplitString(unstub_list, ',', &unstub_components);
+ for (std::vector<std::string>::const_iterator iter =
+ unstub_components.begin();
+ iter != unstub_components.end(); ++iter) {
+ DBusClientBundle::DBusClientType client = GetDBusClientType(*iter);
+ if (client != DBusClientBundle::NO_CLIENTS) {
+ LOG(WARNING) << "Unstubbing dbus client for " << *iter;
+ unstub_mask |= client;
+ } else {
+ LOG(ERROR) << "Unknown dbus client: " << *iter;
+ }
+ }
+
+ return unstub_mask;
+}
+
+} // namespace chromeos
diff --git a/chromeos/dbus/dbus_client_bundle.h b/chromeos/dbus/dbus_client_bundle.h
new file mode 100644
index 0000000..44f3f7b
--- /dev/null
+++ b/chromeos/dbus/dbus_client_bundle.h
@@ -0,0 +1,274 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_DBUS_DBUS_CLIENT_BUNDLE_H_
+#define CHROMEOS_DBUS_DBUS_CLIENT_BUNDLE_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "chromeos/chromeos_export.h"
+
+namespace chromeos {
+
+class BluetoothAdapterClient;
+class BluetoothAgentManagerClient;
+class BluetoothDeviceClient;
+class BluetoothGattCharacteristicClient;
+class BluetoothGattDescriptorClient;
+class BluetoothGattManagerClient;
+class BluetoothGattServiceClient;
+class BluetoothInputClient;
+class BluetoothProfileManagerClient;
+class CrasAudioClient;
+class CrosDisksClient;
+class CryptohomeClient;
+class DebugDaemonClient;
+class EasyUnlockClient;
+class LorgnetteManagerClient;
+class ShillDeviceClient;
+class ShillIPConfigClient;
+class ShillManagerClient;
+class ShillServiceClient;
+class ShillProfileClient;
+class GsmSMSClient;
+class ImageBurnerClient;
+class IntrospectableClient;
+class ModemMessagingClient;
+class NfcManagerClient;
+class NfcAdapterClient;
+class NfcDeviceClient;
+class NfcTagClient;
+class NfcRecordClient;
+class PermissionBrokerClient;
+class SystemClockClient;
+class PowerManagerClient;
+class SessionManagerClient;
+class SMSClient;
+class UpdateEngineClient;
+
+// The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle
+// is used to delete them at once in the right order before shutting down the
+// system bus. See also the comment in the destructor of DBusThreadManagerImpl.
+class CHROMEOS_EXPORT DBusClientBundle {
+ public:
+ typedef unsigned int DBusClientTypeMask;
+
+ // TODO(zelidrag): We might want to collapse few more of these subsystems if
+ // their dbus interfaced correspond to the same daemon.
+ enum DBusClientType {
+ NO_CLIENTS = 0,
+ BLUETOOTH = 1 << 0,
+ CRAS = 1 << 1,
+ CROS_DISKS = 1 << 2,
+ CRYPTOHOME = 1 << 3,
+ DEBUG_DAEMON = 1 << 4,
+ EASY_UNLOCK = 1 << 5,
+ LORGNETTE_MANAGER = 1 << 6,
+ SHILL = 1 << 7,
+ GSM_SMS = 1 << 8,
+ IMAGE_BURNER = 1 << 9,
+ INTROSPECTABLE = 1 << 10,
+ MODEM_MESSAGING = 1 << 11,
+ NFC = 1 << 12,
+ PERMISSION_BROKER = 1 << 13,
+ POWER_MANAGER = 1 << 14,
+ SESSION_MANAGER = 1 << 15,
+ SMS = 1 << 16,
+ SYSTEM_CLOCK = 1 << 17,
+ UPDATE_ENGINE = 1 << 18,
+ ALL_CLIENTS = ~static_cast<DBusClientTypeMask>(0),
+ };
+
+ DBusClientBundle();
+ virtual ~DBusClientBundle();
+
+ // Parses command line param values for dbus subsystem that should be
+ // un-stubbed.
+ static DBusClientTypeMask ParseUnstubList(const std::string& unstub_list);
+
+ BluetoothAdapterClient* bluetooth_adapter_client() {
+ return bluetooth_adapter_client_.get();
+ }
+
+ BluetoothAgentManagerClient* bluetooth_agent_manager_client() {
+ return bluetooth_agent_manager_client_.get();
+ }
+
+ BluetoothDeviceClient* bluetooth_device_client() {
+ return bluetooth_device_client_.get();
+ }
+
+ BluetoothGattCharacteristicClient* bluetooth_gatt_characteristic_client() {
+ return bluetooth_gatt_characteristic_client_.get();
+ }
+
+ BluetoothGattDescriptorClient* bluetooth_gatt_descriptor_client() {
+ return bluetooth_gatt_descriptor_client_.get();
+
+ }
+ BluetoothGattManagerClient* bluetooth_gatt_manager_client() {
+ return bluetooth_gatt_manager_client_.get();
+ }
+
+ BluetoothGattServiceClient* bluetooth_gatt_service_client() {
+ return bluetooth_gatt_service_client_.get();
+ }
+
+ BluetoothInputClient* bluetooth_input_client() {
+ return bluetooth_input_client_.get();
+ }
+
+ BluetoothProfileManagerClient* bluetooth_profile_manager_client() {
+ return bluetooth_profile_manager_client_.get();
+ }
+
+ CrasAudioClient* cras_audio_client() {
+ return cras_audio_client_.get();
+ }
+
+ CrosDisksClient* cros_disks_client() {
+ return cros_disks_client_.get();
+ }
+
+ CryptohomeClient* cryptohome_client() {
+ return cryptohome_client_.get();
+ }
+
+ DebugDaemonClient* debug_daemon_client() {
+ return debug_daemon_client_.get();
+ }
+
+ EasyUnlockClient* easy_unlock_client() {
+ return easy_unlock_client_.get();
+ }
+
+ LorgnetteManagerClient* lorgnette_manager_client() {
+ return lorgnette_manager_client_.get();
+ }
+
+ ShillDeviceClient* shill_device_client() {
+ return shill_device_client_.get();
+ }
+
+ ShillIPConfigClient* shill_ipconfig_client() {
+ return shill_ipconfig_client_.get();
+ }
+
+ ShillManagerClient* shill_manager_client() {
+ return shill_manager_client_.get();
+ }
+
+ ShillServiceClient* shill_service_client() {
+ return shill_service_client_.get();
+ }
+
+ ShillProfileClient* shill_profile_client() {
+ return shill_profile_client_.get();
+ }
+
+ GsmSMSClient* gsm_sms_client() {
+ return gsm_sms_client_.get();
+ }
+
+ ImageBurnerClient* image_burner_client() {
+ return image_burner_client_.get();
+ }
+
+ IntrospectableClient* introspectable_client() {
+ return introspectable_client_.get();
+ }
+
+ ModemMessagingClient* modem_messaging_client() {
+ return modem_messaging_client_.get();
+ }
+
+ NfcManagerClient* nfc_manager_client() {
+ return nfc_manager_client_.get();
+ }
+
+ NfcAdapterClient* nfc_adapter_client() {
+ return nfc_adapter_client_.get();
+ }
+
+ NfcDeviceClient* nfc_device_client() {
+ return nfc_device_client_.get();
+ }
+
+ NfcTagClient* nfc_tag_client() {
+ return nfc_tag_client_.get();
+ }
+
+ NfcRecordClient* nfc_record_client() {
+ return nfc_record_client_.get();
+ }
+
+ PermissionBrokerClient* permission_broker_client() {
+ return permission_broker_client_.get();
+ }
+
+ SystemClockClient* system_clock_client() {
+ return system_clock_client_.get();
+ }
+
+ PowerManagerClient* power_manager_client() {
+ return power_manager_client_.get();
+ }
+
+ SessionManagerClient* session_manager_client() {
+ return session_manager_client_.get();
+ }
+
+ SMSClient* sms_client() {
+ return sms_client_.get();
+ }
+
+ UpdateEngineClient* update_engine_client() {
+ return update_engine_client_.get();
+ }
+
+ private:
+ scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
+ scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_;
+ scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_;
+ scoped_ptr<BluetoothGattCharacteristicClient>
+ bluetooth_gatt_characteristic_client_;
+ scoped_ptr<BluetoothGattDescriptorClient> bluetooth_gatt_descriptor_client_;
+ scoped_ptr<BluetoothGattManagerClient> bluetooth_gatt_manager_client_;
+ scoped_ptr<BluetoothGattServiceClient> bluetooth_gatt_service_client_;
+ scoped_ptr<BluetoothInputClient> bluetooth_input_client_;
+ scoped_ptr<BluetoothProfileManagerClient> bluetooth_profile_manager_client_;
+ scoped_ptr<CrasAudioClient> cras_audio_client_;
+ scoped_ptr<CrosDisksClient> cros_disks_client_;
+ scoped_ptr<CryptohomeClient> cryptohome_client_;
+ scoped_ptr<DebugDaemonClient> debug_daemon_client_;
+ scoped_ptr<EasyUnlockClient> easy_unlock_client_;
+ scoped_ptr<LorgnetteManagerClient> lorgnette_manager_client_;
+ scoped_ptr<ShillDeviceClient> shill_device_client_;
+ scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_;
+ scoped_ptr<ShillManagerClient> shill_manager_client_;
+ scoped_ptr<ShillServiceClient> shill_service_client_;
+ scoped_ptr<ShillProfileClient> shill_profile_client_;
+ scoped_ptr<GsmSMSClient> gsm_sms_client_;
+ scoped_ptr<ImageBurnerClient> image_burner_client_;
+ scoped_ptr<IntrospectableClient> introspectable_client_;
+ scoped_ptr<ModemMessagingClient> modem_messaging_client_;
+ // The declaration order for NFC client objects is important. See
+ // DBusThreadManager::CreateDefaultClients for the dependencies.
+ scoped_ptr<NfcManagerClient> nfc_manager_client_;
+ scoped_ptr<NfcAdapterClient> nfc_adapter_client_;
+ scoped_ptr<NfcDeviceClient> nfc_device_client_;
+ scoped_ptr<NfcTagClient> nfc_tag_client_;
+ scoped_ptr<NfcRecordClient> nfc_record_client_;
+ scoped_ptr<PermissionBrokerClient> permission_broker_client_;
+ scoped_ptr<SystemClockClient> system_clock_client_;
+ scoped_ptr<PowerManagerClient> power_manager_client_;
+ scoped_ptr<SessionManagerClient> session_manager_client_;
+ scoped_ptr<SMSClient> sms_client_;
+ scoped_ptr<UpdateEngineClient> update_engine_client_;
+
+ DISALLOW_COPY_AND_ASSIGN(DBusClientBundle);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_DBUS_CLIENT_BUNDLE_H_
diff --git a/chromeos/dbus/dbus_client_bundle_unittest.cc b/chromeos/dbus/dbus_client_bundle_unittest.cc
new file mode 100644
index 0000000..4c05dfd
--- /dev/null
+++ b/chromeos/dbus/dbus_client_bundle_unittest.cc
@@ -0,0 +1,40 @@
+// Copyright 2014 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/dbus_client_bundle.h"
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+TEST(DBusClientBundleTest, UnstubFlagParser) {
+ EXPECT_EQ(DBusClientBundle::NO_CLIENTS,
+ DBusClientBundle::ParseUnstubList("foo"));
+
+ EXPECT_EQ(DBusClientBundle::BLUETOOTH,
+ DBusClientBundle::ParseUnstubList("BLUETOOTH"));
+
+ EXPECT_EQ(DBusClientBundle::BLUETOOTH,
+ DBusClientBundle::ParseUnstubList("bluetooth"));
+
+ EXPECT_EQ(
+ DBusClientBundle::CRAS |
+ DBusClientBundle::CROS_DISKS |
+ DBusClientBundle::DEBUG_DAEMON |
+ DBusClientBundle::SHILL,
+ DBusClientBundle::ParseUnstubList(
+ "Cras,Cros_Disks,debug_daemon,Shill"));
+
+ EXPECT_EQ(
+ DBusClientBundle::CRAS |
+ DBusClientBundle::CROS_DISKS |
+ DBusClientBundle::DEBUG_DAEMON |
+ DBusClientBundle::SHILL,
+ DBusClientBundle::ParseUnstubList(
+ "foo,Cras,Cros_Disks,debug_daemon,Shill"));
+}
+
+} // namespace chromeos
diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc
index ecd1018..08044b5 100644
--- a/chromeos/dbus/dbus_thread_manager.cc
+++ b/chromeos/dbus/dbus_thread_manager.cc
@@ -21,6 +21,7 @@
#include "chromeos/dbus/cros_disks_client.h"
#include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_client.h"
+#include "chromeos/dbus/dbus_client_bundle.h"
#include "chromeos/dbus/debug_daemon_client.h"
#include "chromeos/dbus/easy_unlock_client.h"
#include "chromeos/dbus/fake_dbus_thread_manager.h"
@@ -28,6 +29,7 @@
#include "chromeos/dbus/image_burner_client.h"
#include "chromeos/dbus/introspectable_client.h"
#include "chromeos/dbus/lorgnette_manager_client.h"
+#include "chromeos/dbus/mixed_dbus_thread_manager.h"
#include "chromeos/dbus/modem_messaging_client.h"
#include "chromeos/dbus/nfc_adapter_client.h"
#include "chromeos/dbus/nfc_device_client.h"
@@ -54,207 +56,8 @@ namespace chromeos {
static DBusThreadManager* g_dbus_thread_manager = NULL;
static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL;
-// The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle
-// is used to delete them at once in the right order before shutting down the
-// system bus. See also the comment in the destructor of DBusThreadManagerImpl.
-class DBusClientBundle {
- public:
- DBusClientBundle() {
- const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION;
-
- bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create());
- bluetooth_agent_manager_client_.reset(
- BluetoothAgentManagerClient::Create());
- bluetooth_device_client_.reset(BluetoothDeviceClient::Create());
- bluetooth_gatt_characteristic_client_.reset(
- BluetoothGattCharacteristicClient::Create());
- bluetooth_gatt_descriptor_client_.reset(
- BluetoothGattDescriptorClient::Create());
- bluetooth_gatt_manager_client_.reset(BluetoothGattManagerClient::Create());
- bluetooth_gatt_service_client_.reset(BluetoothGattServiceClient::Create());
- bluetooth_input_client_.reset(BluetoothInputClient::Create());
- bluetooth_profile_manager_client_.reset(
- BluetoothProfileManagerClient::Create());
- cras_audio_client_.reset(CrasAudioClient::Create());
- cros_disks_client_.reset(CrosDisksClient::Create(type));
- cryptohome_client_.reset(CryptohomeClient::Create());
- debug_daemon_client_.reset(DebugDaemonClient::Create());
- easy_unlock_client_.reset(EasyUnlockClient::Create());
- lorgnette_manager_client_.reset(LorgnetteManagerClient::Create());
- shill_manager_client_.reset(ShillManagerClient::Create());
- shill_device_client_.reset(ShillDeviceClient::Create());
- shill_ipconfig_client_.reset(ShillIPConfigClient::Create());
- shill_service_client_.reset(ShillServiceClient::Create());
- shill_profile_client_.reset(ShillProfileClient::Create());
- gsm_sms_client_.reset(GsmSMSClient::Create());
- image_burner_client_.reset(ImageBurnerClient::Create());
- introspectable_client_.reset(IntrospectableClient::Create());
- modem_messaging_client_.reset(ModemMessagingClient::Create());
- // Create the NFC clients in the correct order based on their dependencies.
- nfc_manager_client_.reset(NfcManagerClient::Create());
- nfc_adapter_client_.reset(
- NfcAdapterClient::Create(nfc_manager_client_.get()));
- nfc_device_client_.reset(
- NfcDeviceClient::Create(nfc_adapter_client_.get()));
- nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get()));
- nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(),
- nfc_tag_client_.get()));
- permission_broker_client_.reset(PermissionBrokerClient::Create());
- power_manager_client_.reset(PowerManagerClient::Create(type));
- session_manager_client_.reset(SessionManagerClient::Create(type));
- sms_client_.reset(SMSClient::Create());
- system_clock_client_.reset(SystemClockClient::Create());
- update_engine_client_.reset(UpdateEngineClient::Create(type));
- }
-
- BluetoothAdapterClient* bluetooth_adapter_client() {
- return bluetooth_adapter_client_.get();
- }
- BluetoothAgentManagerClient* bluetooth_agent_manager_client() {
- return bluetooth_agent_manager_client_.get();
- }
- BluetoothDeviceClient* bluetooth_device_client() {
- return bluetooth_device_client_.get();
- }
- BluetoothGattCharacteristicClient* bluetooth_gatt_characteristic_client() {
- return bluetooth_gatt_characteristic_client_.get();
- }
- BluetoothGattDescriptorClient* bluetooth_gatt_descriptor_client() {
- return bluetooth_gatt_descriptor_client_.get();
- }
- BluetoothGattManagerClient* bluetooth_gatt_manager_client() {
- return bluetooth_gatt_manager_client_.get();
- }
- BluetoothGattServiceClient* bluetooth_gatt_service_client() {
- return bluetooth_gatt_service_client_.get();
- }
- BluetoothInputClient* bluetooth_input_client() {
- return bluetooth_input_client_.get();
- }
- BluetoothProfileManagerClient* bluetooth_profile_manager_client() {
- return bluetooth_profile_manager_client_.get();
- }
- CrasAudioClient* cras_audio_client() {
- return cras_audio_client_.get();
- }
- CrosDisksClient* cros_disks_client() {
- return cros_disks_client_.get();
- }
- CryptohomeClient* cryptohome_client() {
- return cryptohome_client_.get();
- }
- DebugDaemonClient* debug_daemon_client() {
- return debug_daemon_client_.get();
- }
- EasyUnlockClient* easy_unlock_client() {
- return easy_unlock_client_.get();
- }
- LorgnetteManagerClient* lorgnette_manager_client() {
- return lorgnette_manager_client_.get();
- }
- ShillDeviceClient* shill_device_client() {
- return shill_device_client_.get();
- }
- ShillIPConfigClient* shill_ipconfig_client() {
- return shill_ipconfig_client_.get();
- }
- ShillManagerClient* shill_manager_client() {
- return shill_manager_client_.get();
- }
- ShillServiceClient* shill_service_client() {
- return shill_service_client_.get();
- }
- ShillProfileClient* shill_profile_client() {
- return shill_profile_client_.get();
- }
- GsmSMSClient* gsm_sms_client() {
- return gsm_sms_client_.get();
- }
- ImageBurnerClient* image_burner_client() {
- return image_burner_client_.get();
- }
- IntrospectableClient* introspectable_client() {
- return introspectable_client_.get();
- }
- ModemMessagingClient* modem_messaging_client() {
- return modem_messaging_client_.get();
- }
- NfcManagerClient* nfc_manager_client() {
- return nfc_manager_client_.get();
- }
- NfcAdapterClient* nfc_adapter_client() {
- return nfc_adapter_client_.get();
- }
- NfcDeviceClient* nfc_device_client() {
- return nfc_device_client_.get();
- }
- NfcTagClient* nfc_tag_client() {
- return nfc_tag_client_.get();
- }
- NfcRecordClient* nfc_record_client() {
- return nfc_record_client_.get();
- }
- PermissionBrokerClient* permission_broker_client() {
- return permission_broker_client_.get();
- }
- SystemClockClient* system_clock_client() {
- return system_clock_client_.get();
- }
- PowerManagerClient* power_manager_client() {
- return power_manager_client_.get();
- }
- SessionManagerClient* session_manager_client() {
- return session_manager_client_.get();
- }
- SMSClient* sms_client() {
- return sms_client_.get();
- }
- UpdateEngineClient* update_engine_client() {
- return update_engine_client_.get();
- }
-
- private:
- scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_;
- scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_;
- scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_;
- scoped_ptr<BluetoothGattCharacteristicClient>
- bluetooth_gatt_characteristic_client_;
- scoped_ptr<BluetoothGattDescriptorClient> bluetooth_gatt_descriptor_client_;
- scoped_ptr<BluetoothGattManagerClient> bluetooth_gatt_manager_client_;
- scoped_ptr<BluetoothGattServiceClient> bluetooth_gatt_service_client_;
- scoped_ptr<BluetoothInputClient> bluetooth_input_client_;
- scoped_ptr<BluetoothProfileManagerClient> bluetooth_profile_manager_client_;
- scoped_ptr<CrasAudioClient> cras_audio_client_;
- scoped_ptr<CrosDisksClient> cros_disks_client_;
- scoped_ptr<CryptohomeClient> cryptohome_client_;
- scoped_ptr<DebugDaemonClient> debug_daemon_client_;
- scoped_ptr<EasyUnlockClient> easy_unlock_client_;
- scoped_ptr<LorgnetteManagerClient> lorgnette_manager_client_;
- scoped_ptr<ShillDeviceClient> shill_device_client_;
- scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_;
- scoped_ptr<ShillManagerClient> shill_manager_client_;
- scoped_ptr<ShillServiceClient> shill_service_client_;
- scoped_ptr<ShillProfileClient> shill_profile_client_;
- scoped_ptr<GsmSMSClient> gsm_sms_client_;
- scoped_ptr<ImageBurnerClient> image_burner_client_;
- scoped_ptr<IntrospectableClient> introspectable_client_;
- scoped_ptr<ModemMessagingClient> modem_messaging_client_;
- // The declaration order for NFC client objects is important. See
- // DBusThreadManager::CreateDefaultClients for the dependencies.
- scoped_ptr<NfcManagerClient> nfc_manager_client_;
- scoped_ptr<NfcAdapterClient> nfc_adapter_client_;
- scoped_ptr<NfcDeviceClient> nfc_device_client_;
- scoped_ptr<NfcTagClient> nfc_tag_client_;
- scoped_ptr<NfcRecordClient> nfc_record_client_;
- scoped_ptr<PermissionBrokerClient> permission_broker_client_;
- scoped_ptr<SystemClockClient> system_clock_client_;
- scoped_ptr<PowerManagerClient> power_manager_client_;
- scoped_ptr<SessionManagerClient> session_manager_client_;
- scoped_ptr<SMSClient> sms_client_;
- scoped_ptr<UpdateEngineClient> update_engine_client_;
-
- DISALLOW_COPY_AND_ASSIGN(DBusClientBundle);
-};
+DBusClientBundle::DBusClientTypeMask
+ DBusThreadManager::unstub_client_mask_ = DBusClientBundle::NO_CLIENTS;
// The DBusThreadManager implementation used in production.
class DBusThreadManagerImpl : public DBusThreadManager {
@@ -291,7 +94,6 @@ class DBusThreadManagerImpl : public DBusThreadManager {
dbus_thread_->Stop();
}
- // DBusThreadManager overrides:
virtual dbus::Bus* GetSystemBus() OVERRIDE {
return system_bus_.get();
}
@@ -447,8 +249,11 @@ class DBusThreadManagerImpl : public DBusThreadManager {
// Constructs all clients and stores them in the respective *_client_ member
// variable.
void CreateDefaultClients() {
- client_bundle_.reset(new DBusClientBundle);
- power_policy_controller_.reset(new PowerPolicyController);
+ client_bundle_.reset(new DBusClientBundle());
+ // TODO(crbug.com/345586): Move PowerPolicyController out of
+ // DBusThreadManagerImpl.
+ if (!DBusThreadManager::IsUsingStub(DBusClientBundle::POWER_MANAGER))
+ power_policy_controller_.reset(new PowerPolicyController);
}
scoped_ptr<base::Thread> dbus_thread_;
@@ -460,6 +265,11 @@ class DBusThreadManagerImpl : public DBusThreadManager {
};
// static
+bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) {
+ return !(unstub_client_mask_ & client);
+}
+
+// static
void DBusThreadManager::Initialize() {
// If we initialize DBusThreadManager twice we may also be shutting it down
// early; do not allow that.
@@ -472,15 +282,20 @@ void DBusThreadManager::Initialize() {
return;
}
- // Determine whether we use stub or real client implementations.
- if (!base::SysInfo::IsRunningOnChromeOS() ||
+ bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() ||
CommandLine::ForCurrentProcess()->HasSwitch(
- chromeos::switches::kDbusStub)) {
+ chromeos::switches::kDbusStub);
+ bool force_unstub_clients = CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kDbusUnstubClients);
+ // Determine whether we use stub or real client implementations.
+ if (force_unstub_clients) {
+ InitializeWithPartialStub(
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ chromeos::switches::kDbusUnstubClients));
+ } else if (use_dbus_stub) {
InitializeWithStub();
} else {
- g_dbus_thread_manager = new DBusThreadManagerImpl;
- InitializeClients();
- VLOG(1) << "DBusThreadManager initialized for Chrome OS";
+ InitializeRegular();
}
}
@@ -495,12 +310,47 @@ void DBusThreadManager::SetInstanceForTesting(
// static
void DBusThreadManager::InitializeForTesting(
DBusThreadManager* dbus_thread_manager) {
+ unstub_client_mask_ = DBusClientBundle::NO_CLIENTS;
SetInstanceForTesting(dbus_thread_manager);
Initialize();
}
// static
+void DBusThreadManager::InitializeRegular() {
+ unstub_client_mask_ = DBusClientBundle::ALL_CLIENTS;
+ g_dbus_thread_manager = new DBusThreadManagerImpl();
+ InitializeClients();
+ VLOG(1) << "DBusThreadManager initialized for Chrome OS";
+}
+
+// static
+void DBusThreadManager::InitializeWithPartialStub(
+ const std::string& unstub_clients) {
+ // If we initialize DBusThreadManager twice we may also be shutting it down
+ // early; do not allow that.
+ CHECK(g_dbus_thread_manager == NULL);
+
+ unstub_client_mask_ = DBusClientBundle::ParseUnstubList(unstub_clients);
+ // We should have something parsed correctly here.
+ if (unstub_client_mask_ == 0) {
+ LOG(FATAL) << "Switch values for --"
+ << chromeos::switches::kDbusUnstubClients
+ << " cannot be parsed: "
+ << unstub_clients;
+ }
+ DBusThreadManager* real_thread_manager = new DBusThreadManagerImpl();
+ FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
+ fake_dbus_thread_manager->SetFakeClients();
+ VLOG(1) << "DBusThreadManager initialized for mixed runtime environment";
+ g_dbus_thread_manager = new MixedDBusThreadManager(real_thread_manager,
+ fake_dbus_thread_manager);
+ InitializeClients();
+ fake_dbus_thread_manager->SetupDefaultEnvironment();
+}
+
+// static
void DBusThreadManager::InitializeWithStub() {
+ unstub_client_mask_ = DBusClientBundle::NO_CLIENTS;
// If we initialize DBusThreadManager twice we may also be shutting it down
// early; do not allow that.
CHECK(g_dbus_thread_manager == NULL);
diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h
index 2a5e335b..053763c 100644
--- a/chromeos/dbus/dbus_thread_manager.h
+++ b/chromeos/dbus/dbus_thread_manager.h
@@ -9,6 +9,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chromeos/chromeos_export.h"
+#include "chromeos/dbus/dbus_client_bundle.h"
namespace base {
class Thread;
@@ -114,6 +115,9 @@ class CHROMEOS_EXPORT DBusThreadManager {
// Gets the global instance. Initialize() must be called first.
static DBusThreadManager* Get();
+ // Returns true if |client| is stubbed.
+ static bool IsUsingStub(DBusClientBundle::DBusClientType client);
+
// Returns various D-Bus bus instances, owned by DBusThreadManager.
virtual dbus::Bus* GetSystemBus() = 0;
@@ -163,6 +167,13 @@ class CHROMEOS_EXPORT DBusThreadManager {
DBusThreadManager();
private:
+ // Initialize global thread manager instance.
+ static void InitializeRegular();
+
+ // Initialize with stub implementations for only certain clients that are
+ // not included in comma-separated |unstub_clients| list.
+ static void InitializeWithPartialStub(const std::string& unstub_clients);
+
// InitializeClients is called after g_dbus_thread_manager is set.
// NOTE: Clients that access other clients in their Init() must be
// initialized in the correct order.
@@ -171,6 +182,10 @@ class CHROMEOS_EXPORT DBusThreadManager {
// Initializes |client| with the |system_bus_|.
static void InitClient(DBusClient* client);
+ // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags
+ // are defined within DBusClientBundle::DBusClientType enum.
+ static DBusClientBundle::DBusClientTypeMask unstub_client_mask_;
+
DISALLOW_COPY_AND_ASSIGN(DBusThreadManager);
};
diff --git a/chromeos/dbus/mixed_dbus_thread_manager.cc b/chromeos/dbus/mixed_dbus_thread_manager.cc
new file mode 100644
index 0000000..3ca5d09
--- /dev/null
+++ b/chromeos/dbus/mixed_dbus_thread_manager.cc
@@ -0,0 +1,205 @@
+// Copyright 2014 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/mixed_dbus_thread_manager.h"
+
+namespace chromeos {
+
+MixedDBusThreadManager::MixedDBusThreadManager(
+ DBusThreadManager* real_thread_manager,
+ DBusThreadManager* fake_thread_manager)
+ : real_thread_manager_(real_thread_manager),
+ fake_thread_manager_(fake_thread_manager) {
+}
+
+MixedDBusThreadManager::~MixedDBusThreadManager() {
+}
+
+// DBusThreadManager overrides.
+ dbus::Bus* MixedDBusThreadManager::GetSystemBus() {
+ return real_thread_manager_->GetSystemBus();
+}
+
+ BluetoothAdapterClient* MixedDBusThreadManager::GetBluetoothAdapterClient() {
+ return GetThreadManager(
+ DBusClientBundle::BLUETOOTH)->GetBluetoothAdapterClient();
+}
+
+ BluetoothAgentManagerClient*
+ MixedDBusThreadManager::GetBluetoothAgentManagerClient() {
+ return GetThreadManager(
+ DBusClientBundle::BLUETOOTH)->GetBluetoothAgentManagerClient();
+}
+
+ BluetoothDeviceClient* MixedDBusThreadManager::GetBluetoothDeviceClient() {
+ return GetThreadManager(
+ DBusClientBundle::BLUETOOTH)->GetBluetoothDeviceClient();
+}
+
+ BluetoothGattCharacteristicClient*
+ MixedDBusThreadManager::GetBluetoothGattCharacteristicClient() {
+ return GetThreadManager(DBusClientBundle::BLUETOOTH)->
+ GetBluetoothGattCharacteristicClient();
+}
+
+ BluetoothGattDescriptorClient*
+ MixedDBusThreadManager::GetBluetoothGattDescriptorClient() {
+ return GetThreadManager(DBusClientBundle::BLUETOOTH)->
+ GetBluetoothGattDescriptorClient();
+}
+
+ BluetoothGattManagerClient*
+ MixedDBusThreadManager::GetBluetoothGattManagerClient() {
+ return GetThreadManager(
+ DBusClientBundle::BLUETOOTH)->GetBluetoothGattManagerClient();
+}
+
+ BluetoothGattServiceClient*
+ MixedDBusThreadManager::GetBluetoothGattServiceClient() {
+ return GetThreadManager(
+ DBusClientBundle::BLUETOOTH)->GetBluetoothGattServiceClient();
+}
+
+ BluetoothInputClient* MixedDBusThreadManager::GetBluetoothInputClient() {
+ return GetThreadManager(
+ DBusClientBundle::BLUETOOTH)->GetBluetoothInputClient();
+}
+
+ BluetoothProfileManagerClient*
+ MixedDBusThreadManager::GetBluetoothProfileManagerClient() {
+ return GetThreadManager(
+ DBusClientBundle::BLUETOOTH)->GetBluetoothProfileManagerClient();
+}
+
+ CrasAudioClient* MixedDBusThreadManager::GetCrasAudioClient() {
+ return GetThreadManager(
+ DBusClientBundle::CRAS)->GetCrasAudioClient();
+}
+
+ CrosDisksClient* MixedDBusThreadManager::GetCrosDisksClient() {
+ return GetThreadManager(DBusClientBundle::CROS_DISKS)->GetCrosDisksClient();
+}
+
+ CryptohomeClient* MixedDBusThreadManager::GetCryptohomeClient() {
+ return GetThreadManager(
+ DBusClientBundle::CRYPTOHOME)->GetCryptohomeClient();
+}
+
+ DebugDaemonClient* MixedDBusThreadManager::GetDebugDaemonClient() {
+ return GetThreadManager(
+ DBusClientBundle::DEBUG_DAEMON)->GetDebugDaemonClient();
+}
+
+ EasyUnlockClient* MixedDBusThreadManager::GetEasyUnlockClient() {
+ return GetThreadManager(
+ DBusClientBundle::EASY_UNLOCK)->GetEasyUnlockClient();
+}
+
+ LorgnetteManagerClient* MixedDBusThreadManager::GetLorgnetteManagerClient() {
+ return GetThreadManager(
+ DBusClientBundle::LORGNETTE_MANAGER)->GetLorgnetteManagerClient();
+}
+
+ ShillDeviceClient* MixedDBusThreadManager::GetShillDeviceClient() {
+ return GetThreadManager(DBusClientBundle::SHILL)->GetShillDeviceClient();
+}
+
+ShillIPConfigClient* MixedDBusThreadManager::GetShillIPConfigClient() {
+ return GetThreadManager(DBusClientBundle::SHILL)->GetShillIPConfigClient();
+}
+
+ShillManagerClient* MixedDBusThreadManager::GetShillManagerClient() {
+ return GetThreadManager(DBusClientBundle::SHILL)->GetShillManagerClient();
+}
+
+ShillProfileClient* MixedDBusThreadManager::GetShillProfileClient() {
+ return GetThreadManager(DBusClientBundle::SHILL)->GetShillProfileClient();
+}
+
+ShillServiceClient* MixedDBusThreadManager::GetShillServiceClient() {
+ return GetThreadManager(DBusClientBundle::SHILL)->GetShillServiceClient();
+}
+
+GsmSMSClient* MixedDBusThreadManager::GetGsmSMSClient() {
+ return GetThreadManager(DBusClientBundle::GSM_SMS)->GetGsmSMSClient();
+}
+
+ImageBurnerClient* MixedDBusThreadManager::GetImageBurnerClient() {
+ return GetThreadManager(
+ DBusClientBundle::IMAGE_BURNER)->GetImageBurnerClient();
+}
+
+IntrospectableClient* MixedDBusThreadManager::GetIntrospectableClient() {
+ return GetThreadManager(
+ DBusClientBundle::INTROSPECTABLE)->GetIntrospectableClient();
+}
+
+ModemMessagingClient* MixedDBusThreadManager::GetModemMessagingClient() {
+ return GetThreadManager(
+ DBusClientBundle::MODEM_MESSAGING)->GetModemMessagingClient();
+}
+
+NfcAdapterClient* MixedDBusThreadManager::GetNfcAdapterClient() {
+ return GetThreadManager(DBusClientBundle::NFC)->GetNfcAdapterClient();
+}
+
+NfcDeviceClient* MixedDBusThreadManager::GetNfcDeviceClient() {
+ return GetThreadManager(DBusClientBundle::NFC)->GetNfcDeviceClient();
+}
+
+NfcManagerClient* MixedDBusThreadManager::GetNfcManagerClient() {
+ return GetThreadManager(DBusClientBundle::NFC)->GetNfcManagerClient();
+}
+
+NfcRecordClient* MixedDBusThreadManager::GetNfcRecordClient() {
+ return GetThreadManager(DBusClientBundle::NFC)->GetNfcRecordClient();
+}
+
+NfcTagClient* MixedDBusThreadManager::GetNfcTagClient() {
+ return GetThreadManager(DBusClientBundle::NFC)->GetNfcTagClient();
+}
+
+PermissionBrokerClient* MixedDBusThreadManager::GetPermissionBrokerClient() {
+ return GetThreadManager(
+ DBusClientBundle::PERMISSION_BROKER)->GetPermissionBrokerClient();
+}
+
+PowerManagerClient* MixedDBusThreadManager::GetPowerManagerClient() {
+ return GetThreadManager(
+ DBusClientBundle::POWER_MANAGER)->GetPowerManagerClient();
+}
+
+PowerPolicyController* MixedDBusThreadManager::GetPowerPolicyController() {
+ return GetThreadManager(
+ DBusClientBundle::POWER_MANAGER)->GetPowerPolicyController();
+}
+
+SessionManagerClient* MixedDBusThreadManager::GetSessionManagerClient() {
+ return GetThreadManager(
+ DBusClientBundle::SESSION_MANAGER)->GetSessionManagerClient();
+}
+
+SMSClient* MixedDBusThreadManager::GetSMSClient() {
+ return GetThreadManager(DBusClientBundle::SMS)->GetSMSClient();
+}
+
+SystemClockClient* MixedDBusThreadManager::GetSystemClockClient() {
+ return GetThreadManager(
+ DBusClientBundle::SYSTEM_CLOCK)->GetSystemClockClient();
+}
+
+UpdateEngineClient* MixedDBusThreadManager::GetUpdateEngineClient() {
+ return GetThreadManager(
+ DBusClientBundle::UPDATE_ENGINE)->GetUpdateEngineClient();
+}
+
+DBusThreadManager* MixedDBusThreadManager::GetThreadManager(
+ DBusClientBundle::DBusClientType client) {
+ if (DBusThreadManager::IsUsingStub(client))
+ return fake_thread_manager_.get();
+
+ return real_thread_manager_.get();
+}
+
+} // namespace chromeos
diff --git a/chromeos/dbus/mixed_dbus_thread_manager.h b/chromeos/dbus/mixed_dbus_thread_manager.h
new file mode 100644
index 0000000..7ae8bb9
--- /dev/null
+++ b/chromeos/dbus/mixed_dbus_thread_manager.h
@@ -0,0 +1,81 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_DBUS_MIXED_DBUS_THREAD_MANAGER_H_
+#define CHROMEOS_DBUS_MIXED_DBUS_THREAD_MANAGER_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "chromeos/chromeos_export.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+
+namespace chromeos {
+
+// This class permits mixing DBusThreadManagerImpl and FakeDBusThreadManager
+// implementation and allow us to selectively activate some dbus clients while
+// others remain stubbed out.
+class CHROMEOS_EXPORT MixedDBusThreadManager : public DBusThreadManager {
+ public:
+ explicit MixedDBusThreadManager(
+ DBusThreadManager* real_thread_manager,
+ DBusThreadManager* fake_thread_manager);
+
+ virtual ~MixedDBusThreadManager();
+
+ // DBusThreadManager overrides.
+ virtual dbus::Bus* GetSystemBus() OVERRIDE;
+ virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE;
+ virtual BluetoothAgentManagerClient*
+ GetBluetoothAgentManagerClient() OVERRIDE;
+ virtual BluetoothDeviceClient* GetBluetoothDeviceClient() OVERRIDE;
+ virtual BluetoothGattCharacteristicClient*
+ GetBluetoothGattCharacteristicClient() OVERRIDE;
+ virtual BluetoothGattDescriptorClient*
+ GetBluetoothGattDescriptorClient() OVERRIDE;
+ virtual BluetoothGattManagerClient* GetBluetoothGattManagerClient() OVERRIDE;
+ virtual BluetoothGattServiceClient* GetBluetoothGattServiceClient() OVERRIDE;
+ virtual BluetoothInputClient* GetBluetoothInputClient() OVERRIDE;
+ virtual BluetoothProfileManagerClient*
+ GetBluetoothProfileManagerClient() OVERRIDE;
+ virtual CrasAudioClient* GetCrasAudioClient() OVERRIDE;
+ virtual CrosDisksClient* GetCrosDisksClient() OVERRIDE;
+ virtual CryptohomeClient* GetCryptohomeClient() OVERRIDE;
+ virtual DebugDaemonClient* GetDebugDaemonClient() OVERRIDE;
+ virtual EasyUnlockClient* GetEasyUnlockClient() OVERRIDE;
+ virtual LorgnetteManagerClient* GetLorgnetteManagerClient() OVERRIDE;
+ virtual ShillDeviceClient* GetShillDeviceClient() OVERRIDE;
+ virtual ShillIPConfigClient* GetShillIPConfigClient() OVERRIDE;
+ virtual ShillManagerClient* GetShillManagerClient() OVERRIDE;
+ virtual ShillProfileClient* GetShillProfileClient() OVERRIDE;
+ virtual ShillServiceClient* GetShillServiceClient() OVERRIDE;
+ virtual GsmSMSClient* GetGsmSMSClient() OVERRIDE;
+ virtual ImageBurnerClient* GetImageBurnerClient() OVERRIDE;
+ virtual IntrospectableClient* GetIntrospectableClient() OVERRIDE;
+ virtual ModemMessagingClient* GetModemMessagingClient() OVERRIDE;
+ virtual NfcAdapterClient* GetNfcAdapterClient() OVERRIDE;
+ virtual NfcDeviceClient* GetNfcDeviceClient() OVERRIDE;
+ virtual NfcManagerClient* GetNfcManagerClient() OVERRIDE;
+ virtual NfcRecordClient* GetNfcRecordClient() OVERRIDE;
+ virtual NfcTagClient* GetNfcTagClient() OVERRIDE;
+ virtual PermissionBrokerClient* GetPermissionBrokerClient() OVERRIDE;
+ virtual PowerManagerClient* GetPowerManagerClient() OVERRIDE;
+ virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE;
+ virtual SessionManagerClient* GetSessionManagerClient() OVERRIDE;
+ virtual SMSClient* GetSMSClient() OVERRIDE;
+ virtual SystemClockClient* GetSystemClockClient() OVERRIDE;
+ virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE;
+
+ private:
+ // Returns either the real or fake DBusThreadManager implementation based on
+ // |client| and |unstub_mask_|.
+ DBusThreadManager* GetThreadManager(DBusClientBundle::DBusClientType client);
+
+ scoped_ptr<DBusThreadManager> real_thread_manager_;
+ scoped_ptr<DBusThreadManager> fake_thread_manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(MixedDBusThreadManager);
+};
+
+} // namespace chromeos
+
+#endif // CHROMEOS_DBUS_MIXED_DBUS_THREAD_MANAGER_H_