diff options
author | pneubeck <pneubeck@chromium.org> | 2014-09-11 02:03:49 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-11 09:10:17 +0000 |
commit | ef009f18ca95c0d7b3b4a330c190a2f24b29e003 (patch) | |
tree | 93f52e12c37ce48532dab49276fe52edf12c7c65 /chromeos/dbus | |
parent | f691be3b1bbbfb491e9afd283fe100acda894147 (diff) | |
download | chromium_src-ef009f18ca95c0d7b3b4a330c190a2f24b29e003.zip chromium_src-ef009f18ca95c0d7b3b4a330c190a2f24b29e003.tar.gz chromium_src-ef009f18ca95c0d7b3b4a330c190a2f24b29e003.tar.bz2 |
Fix minor issues about DBusThreadManager.
- Remove the global unstub_client_mask_ and accordingly make DBusThreadManager::IsUsingStub a non-static function. This makes it obvious when it's ok to call this function (and prevents misuse), namely only after the Manager is initialized.
- By moving the mask to the DBusClientBundle, the cyclic dependency between bundle and manager is broken. The Bundle does not know about the Manager anymore.
- Fix the difference between DBusClientTypeMask ("A set of DBusClients") and DBusClientType ("A single DBusClient").
BUG=408617
Review URL: https://codereview.chromium.org/556833003
Cr-Commit-Position: refs/heads/master@{#294361}
Diffstat (limited to 'chromeos/dbus')
-rw-r--r-- | chromeos/dbus/bluetooth_adapter_client.cc | 3 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_agent_service_provider.cc | 2 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_device_client.cc | 3 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc | 2 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc | 2 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_gatt_service_service_provider.cc | 2 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_input_client.cc | 2 | ||||
-rw-r--r-- | chromeos/dbus/bluetooth_profile_service_provider.cc | 2 | ||||
-rw-r--r-- | chromeos/dbus/dbus_client_bundle.cc | 76 | ||||
-rw-r--r-- | chromeos/dbus/dbus_client_bundle.h | 19 | ||||
-rw-r--r-- | chromeos/dbus/dbus_client_bundle_unittest.cc | 3 | ||||
-rw-r--r-- | chromeos/dbus/dbus_thread_manager.cc | 58 | ||||
-rw-r--r-- | chromeos/dbus/dbus_thread_manager.h | 36 |
13 files changed, 108 insertions, 102 deletions
diff --git a/chromeos/dbus/bluetooth_adapter_client.cc b/chromeos/dbus/bluetooth_adapter_client.cc index afc379b..3d8d213 100644 --- a/chromeos/dbus/bluetooth_adapter_client.cc +++ b/chromeos/dbus/bluetooth_adapter_client.cc @@ -50,7 +50,8 @@ class BluetoothAdapterClientImpl : public BluetoothAdapterClient, public dbus::ObjectManager::Interface { public: - BluetoothAdapterClientImpl() : weak_ptr_factory_(this) {} + BluetoothAdapterClientImpl() + : object_manager_(NULL), weak_ptr_factory_(this) {} virtual ~BluetoothAdapterClientImpl() { object_manager_->UnregisterInterface( diff --git a/chromeos/dbus/bluetooth_agent_service_provider.cc b/chromeos/dbus/bluetooth_agent_service_provider.cc index 46117d1..8297dc1 100644 --- a/chromeos/dbus/bluetooth_agent_service_provider.cc +++ b/chromeos/dbus/bluetooth_agent_service_provider.cc @@ -469,7 +469,7 @@ BluetoothAgentServiceProvider* BluetoothAgentServiceProvider::Create( dbus::Bus* bus, const dbus::ObjectPath& object_path, Delegate* delegate) { - if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) { + if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { return new BluetoothAgentServiceProviderImpl(bus, object_path, delegate); } else { return new FakeBluetoothAgentServiceProvider(object_path, delegate); diff --git a/chromeos/dbus/bluetooth_device_client.cc b/chromeos/dbus/bluetooth_device_client.cc index b505401..00e10d3 100644 --- a/chromeos/dbus/bluetooth_device_client.cc +++ b/chromeos/dbus/bluetooth_device_client.cc @@ -56,7 +56,8 @@ class BluetoothDeviceClientImpl : public BluetoothDeviceClient, public dbus::ObjectManager::Interface { public: - BluetoothDeviceClientImpl() : weak_ptr_factory_(this) {} + BluetoothDeviceClientImpl() + : object_manager_(NULL), weak_ptr_factory_(this) {} virtual ~BluetoothDeviceClientImpl() { object_manager_->UnregisterInterface( diff --git a/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc b/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc index c54610c..19e9f42 100644 --- a/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc +++ b/chromeos/dbus/bluetooth_gatt_characteristic_service_provider.cc @@ -464,7 +464,7 @@ BluetoothGattCharacteristicServiceProvider::Create( const std::vector<std::string>& flags, const std::vector<std::string>& permissions, const dbus::ObjectPath& service_path) { - if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) { + if (!DBusThreadManager::Get()->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 5040066..9bdfe1f 100644 --- a/chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc +++ b/chromeos/dbus/bluetooth_gatt_descriptor_service_provider.cc @@ -460,7 +460,7 @@ BluetoothGattDescriptorServiceProvider::Create( const std::string& uuid, const std::vector<std::string>& permissions, const dbus::ObjectPath& characteristic_path) { - if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) { + if (!DBusThreadManager::Get()->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 88fd581..59298d7 100644 --- a/chromeos/dbus/bluetooth_gatt_service_service_provider.cc +++ b/chromeos/dbus/bluetooth_gatt_service_service_provider.cc @@ -269,7 +269,7 @@ BluetoothGattServiceServiceProvider::Create( const dbus::ObjectPath& object_path, const std::string& uuid, const std::vector<dbus::ObjectPath>& includes) { - if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) { + if (!DBusThreadManager::Get()->IsUsingStub(DBusClientBundle::BLUETOOTH)) { return new BluetoothGattServiceServiceProviderImpl( bus, object_path, uuid, includes); } diff --git a/chromeos/dbus/bluetooth_input_client.cc b/chromeos/dbus/bluetooth_input_client.cc index 0cc59a8..5f0cb4f 100644 --- a/chromeos/dbus/bluetooth_input_client.cc +++ b/chromeos/dbus/bluetooth_input_client.cc @@ -34,7 +34,7 @@ class BluetoothInputClientImpl : public BluetoothInputClient, public dbus::ObjectManager::Interface { public: - BluetoothInputClientImpl() : weak_ptr_factory_(this) {} + BluetoothInputClientImpl() : object_manager_(NULL), weak_ptr_factory_(this) {} virtual ~BluetoothInputClientImpl() { object_manager_->UnregisterInterface( diff --git a/chromeos/dbus/bluetooth_profile_service_provider.cc b/chromeos/dbus/bluetooth_profile_service_provider.cc index 1d9f2b5..960ddfb 100644 --- a/chromeos/dbus/bluetooth_profile_service_provider.cc +++ b/chromeos/dbus/bluetooth_profile_service_provider.cc @@ -252,7 +252,7 @@ BluetoothProfileServiceProvider* BluetoothProfileServiceProvider::Create( dbus::Bus* bus, const dbus::ObjectPath& object_path, Delegate* delegate) { - if (!DBusThreadManager::IsUsingStub(DBusClientBundle::BLUETOOTH)) { + if (!DBusThreadManager::Get()->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 index 159b3f2..abfe6ee 100644 --- a/chromeos/dbus/dbus_client_bundle.cc +++ b/chromeos/dbus/dbus_client_bundle.cc @@ -21,7 +21,6 @@ #include "chromeos/dbus/cras_audio_client_stub_impl.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/fake_bluetooth_adapter_client.h" @@ -107,22 +106,22 @@ const struct { { "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. +// Parses single command line param value for dbus subsystem. If successful, +// returns its enum representation. Otherwise returns NO_CLIENT. DBusClientBundle::DBusClientType GetDBusClientType( - const std::string& client_type) { + const std::string& client_type_name) { for (size_t i = 0; i < arraysize(client_type_map); i++) { - if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name)) + if (LowerCaseEqualsASCII(client_type_name, client_type_map[i].param_name)) return client_type_map[i].client_type; } - return DBusClientBundle::NO_CLIENTS; + return DBusClientBundle::NO_CLIENT; } } // namespace -DBusClientBundle::DBusClientBundle() { - if (!DBusThreadManager::IsUsingStub(BLUETOOTH)) { +DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask) + : unstub_client_mask_(unstub_client_mask) { + if (!IsUsingStub(BLUETOOTH)) { bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); bluetooth_agent_manager_client_.reset( BluetoothAgentManagerClient::Create()); @@ -153,37 +152,36 @@ DBusClientBundle::DBusClientBundle() { bluetooth_gatt_service_client_.reset(new FakeBluetoothGattServiceClient); } - if (!DBusThreadManager::IsUsingStub(CRAS)) + if (!IsUsingStub(CRAS)) cras_audio_client_.reset(CrasAudioClient::Create()); else cras_audio_client_.reset(new CrasAudioClientStubImpl); cros_disks_client_.reset(CrosDisksClient::Create( - DBusThreadManager::IsUsingStub(CROS_DISKS) ? - STUB_DBUS_CLIENT_IMPLEMENTATION : - REAL_DBUS_CLIENT_IMPLEMENTATION)); + IsUsingStub(CROS_DISKS) ? STUB_DBUS_CLIENT_IMPLEMENTATION + : REAL_DBUS_CLIENT_IMPLEMENTATION)); - if (!DBusThreadManager::IsUsingStub(CRYPTOHOME)) + if (!IsUsingStub(CRYPTOHOME)) cryptohome_client_.reset(CryptohomeClient::Create()); else cryptohome_client_.reset(new FakeCryptohomeClient); - if (!DBusThreadManager::IsUsingStub(DEBUG_DAEMON)) + if (!IsUsingStub(DEBUG_DAEMON)) debug_daemon_client_.reset(DebugDaemonClient::Create()); else debug_daemon_client_.reset(new FakeDebugDaemonClient); - if (!DBusThreadManager::IsUsingStub(EASY_UNLOCK)) + if (!IsUsingStub(EASY_UNLOCK)) easy_unlock_client_.reset(EasyUnlockClient::Create()); else easy_unlock_client_.reset(new FakeEasyUnlockClient); - if (!DBusThreadManager::IsUsingStub(LORGNETTE_MANAGER)) + if (!IsUsingStub(LORGNETTE_MANAGER)) lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); else lorgnette_manager_client_.reset(new FakeLorgnetteManagerClient); - if (!DBusThreadManager::IsUsingStub(SHILL)) { + if (!IsUsingStub(SHILL)) { shill_manager_client_.reset(ShillManagerClient::Create()); shill_device_client_.reset(ShillDeviceClient::Create()); shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); @@ -197,7 +195,7 @@ DBusClientBundle::DBusClientBundle() { shill_profile_client_.reset(new FakeShillProfileClient); } - if (!DBusThreadManager::IsUsingStub(GSM_SMS)) { + if (!IsUsingStub(GSM_SMS)) { gsm_sms_client_.reset(GsmSMSClient::Create()); } else { FakeGsmSMSClient* gsm_sms_client = new FakeGsmSMSClient(); @@ -207,23 +205,23 @@ DBusClientBundle::DBusClientBundle() { gsm_sms_client_.reset(gsm_sms_client); } - if (!DBusThreadManager::IsUsingStub(IMAGE_BURNER)) + if (!IsUsingStub(IMAGE_BURNER)) image_burner_client_.reset(ImageBurnerClient::Create()); else image_burner_client_.reset(new FakeImageBurnerClient); - if (!DBusThreadManager::IsUsingStub(INTROSPECTABLE)) + if (!IsUsingStub(INTROSPECTABLE)) introspectable_client_.reset(IntrospectableClient::Create()); else introspectable_client_.reset(new FakeIntrospectableClient); - if (!DBusThreadManager::IsUsingStub(MODEM_MESSAGING)) + if (!IsUsingStub(MODEM_MESSAGING)) modem_messaging_client_.reset(ModemMessagingClient::Create()); else modem_messaging_client_.reset(new FakeModemMessagingClient); // Create the NFC clients in the correct order based on their dependencies. - if (!DBusThreadManager::IsUsingStub(NFC)) { + if (!IsUsingStub(NFC)) { nfc_manager_client_.reset(NfcManagerClient::Create()); nfc_adapter_client_.reset( NfcAdapterClient::Create(nfc_manager_client_.get())); @@ -240,40 +238,46 @@ DBusClientBundle::DBusClientBundle() { nfc_record_client_.reset(new FakeNfcRecordClient); } - if (!DBusThreadManager::IsUsingStub(PERMISSION_BROKER)) + if (!IsUsingStub(PERMISSION_BROKER)) permission_broker_client_.reset(PermissionBrokerClient::Create()); else permission_broker_client_.reset(new FakePermissionBrokerClient); power_manager_client_.reset(PowerManagerClient::Create( - DBusThreadManager::IsUsingStub(POWER_MANAGER) ? - STUB_DBUS_CLIENT_IMPLEMENTATION : - REAL_DBUS_CLIENT_IMPLEMENTATION)); + IsUsingStub(POWER_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION + : REAL_DBUS_CLIENT_IMPLEMENTATION)); session_manager_client_.reset(SessionManagerClient::Create( - DBusThreadManager::IsUsingStub(SESSION_MANAGER) ? - STUB_DBUS_CLIENT_IMPLEMENTATION : - REAL_DBUS_CLIENT_IMPLEMENTATION)); + IsUsingStub(SESSION_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION + : REAL_DBUS_CLIENT_IMPLEMENTATION)); - if (!DBusThreadManager::IsUsingStub(SMS)) + if (!IsUsingStub(SMS)) sms_client_.reset(SMSClient::Create()); else sms_client_.reset(new FakeSMSClient); - if (!DBusThreadManager::IsUsingStub(SYSTEM_CLOCK)) + if (!IsUsingStub(SYSTEM_CLOCK)) system_clock_client_.reset(SystemClockClient::Create()); else system_clock_client_.reset(new FakeSystemClockClient); update_engine_client_.reset(UpdateEngineClient::Create( - DBusThreadManager::IsUsingStub(UPDATE_ENGINE) ? - STUB_DBUS_CLIENT_IMPLEMENTATION : - REAL_DBUS_CLIENT_IMPLEMENTATION)); + IsUsingStub(UPDATE_ENGINE) ? STUB_DBUS_CLIENT_IMPLEMENTATION + : REAL_DBUS_CLIENT_IMPLEMENTATION)); } DBusClientBundle::~DBusClientBundle() { } +bool DBusClientBundle::IsUsingStub(DBusClientType client) { + return !(unstub_client_mask_ & client); +} + +bool DBusClientBundle::IsUsingAnyRealClient() { + // 'Using any real client' is equivalent to 'Unstubbed any client'. + return unstub_client_mask_ != 0; +} + void DBusClientBundle::SetupDefaultEnvironment() { ShillManagerClient::TestInterface* manager = shill_manager_client_->GetTestInterface(); @@ -291,7 +295,7 @@ DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList( unstub_components.begin(); iter != unstub_components.end(); ++iter) { DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); - if (client != DBusClientBundle::NO_CLIENTS) { + if (client != NO_CLIENT) { LOG(WARNING) << "Unstubbing dbus client for " << *iter; unstub_mask |= client; } else { diff --git a/chromeos/dbus/dbus_client_bundle.h b/chromeos/dbus/dbus_client_bundle.h index e4710a8..372f04f 100644 --- a/chromeos/dbus/dbus_client_bundle.h +++ b/chromeos/dbus/dbus_client_bundle.h @@ -51,12 +51,12 @@ class UpdateEngineClient; // system bus. See also the comment in the destructor of DBusThreadManagerImpl. class CHROMEOS_EXPORT DBusClientBundle { public: - typedef unsigned int DBusClientTypeMask; + typedef 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, + NO_CLIENT = 0, BLUETOOTH = 1 << 0, CRAS = 1 << 1, CROS_DISKS = 1 << 2, @@ -76,12 +76,17 @@ class CHROMEOS_EXPORT DBusClientBundle { SMS = 1 << 16, SYSTEM_CLOCK = 1 << 17, UPDATE_ENGINE = 1 << 18, - ALL_CLIENTS = ~static_cast<DBusClientTypeMask>(0), }; - DBusClientBundle(); + DBusClientBundle(DBusClientTypeMask unstub_client_mask); ~DBusClientBundle(); + // Returns true if |client| is stubbed. + bool IsUsingStub(DBusClientType client); + + // Returns true if any real DBusClient is used. + bool IsUsingAnyRealClient(); + // Initialize proper runtime environment for its dbus clients. void SetupDefaultEnvironment(); @@ -232,6 +237,10 @@ class CHROMEOS_EXPORT DBusClientBundle { private: friend class DBusThreadManagerSetter; + // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags + // are defined within DBusClientType enum. + DBusClientTypeMask unstub_client_mask_; + scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_; scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_; @@ -258,7 +267,7 @@ class CHROMEOS_EXPORT DBusClientBundle { 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. + // DBusThreadManager::InitializeClients for the dependencies. scoped_ptr<NfcManagerClient> nfc_manager_client_; scoped_ptr<NfcAdapterClient> nfc_adapter_client_; scoped_ptr<NfcDeviceClient> nfc_device_client_; diff --git a/chromeos/dbus/dbus_client_bundle_unittest.cc b/chromeos/dbus/dbus_client_bundle_unittest.cc index 4c05dfd..e7f63bd 100644 --- a/chromeos/dbus/dbus_client_bundle_unittest.cc +++ b/chromeos/dbus/dbus_client_bundle_unittest.cc @@ -11,8 +11,7 @@ namespace chromeos { TEST(DBusClientBundleTest, UnstubFlagParser) { - EXPECT_EQ(DBusClientBundle::NO_CLIENTS, - DBusClientBundle::ParseUnstubList("foo")); + EXPECT_EQ(0, DBusClientBundle::ParseUnstubList("foo")); EXPECT_EQ(DBusClientBundle::BLUETOOTH, DBusClientBundle::ParseUnstubList("BLUETOOTH")); diff --git a/chromeos/dbus/dbus_thread_manager.cc b/chromeos/dbus/dbus_thread_manager.cc index 6175d6b..3e88a50 100644 --- a/chromeos/dbus/dbus_thread_manager.cc +++ b/chromeos/dbus/dbus_thread_manager.cc @@ -54,12 +54,12 @@ namespace chromeos { static DBusThreadManager* g_dbus_thread_manager = NULL; static bool g_using_dbus_thread_manager_for_testing = false; -DBusClientBundle::DBusClientTypeMask - DBusThreadManager::unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; - -DBusThreadManager::DBusThreadManager() { +DBusThreadManager::DBusThreadManager(scoped_ptr<DBusClientBundle> client_bundle) + : client_bundle_(client_bundle.Pass()) { dbus::statistics::Initialize(); - if (!DBusThreadManager::IsUsingStub(DBusClientBundle::ALL_CLIENTS)) { + + if (client_bundle_->IsUsingAnyRealClient()) { + // At least one real DBusClient is used. // Create the D-Bus thread. base::Thread::Options thread_options; thread_options.message_loop_type = base::MessageLoop::TYPE_IO; @@ -74,7 +74,9 @@ DBusThreadManager::DBusThreadManager() { system_bus_ = new dbus::Bus(system_bus_options); } - CreateDefaultClients(); + // TODO(crbug.com/345586): Move PowerPolicyController out of + // DBusThreadManager. + power_policy_controller_.reset(new PowerPolicyController); } DBusThreadManager::~DBusThreadManager() { @@ -95,7 +97,7 @@ DBusThreadManager::~DBusThreadManager() { dbus::statistics::Shutdown(); - if (g_dbus_thread_manager == NULL) + if (!g_dbus_thread_manager) return; // Called form Shutdown() or local test instance. // There should never be both a global instance and a local instance. @@ -268,13 +270,6 @@ PowerPolicyController* DBusThreadManager::GetPowerPolicyController() { return power_policy_controller_.get(); } -void DBusThreadManager::CreateDefaultClients() { - client_bundle_.reset(new DBusClientBundle()); - // TODO(crbug.com/345586): Move PowerPolicyController out of - // DBusThreadManager. - power_policy_controller_.reset(new PowerPolicyController); -} - void DBusThreadManager::InitializeClients() { GetBluetoothAdapterClient()->Init(GetSystemBus()); GetBluetoothAgentManagerClient()->Init(GetSystemBus()); @@ -329,9 +324,8 @@ void DBusThreadManager::InitializeClients() { client_bundle_->SetupDefaultEnvironment(); } -// static bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { - return !(unstub_client_mask_ & client); + return client_bundle_->IsUsingStub(client); } // static @@ -341,7 +335,7 @@ void DBusThreadManager::Initialize() { if (g_using_dbus_thread_manager_for_testing) return; - CHECK(g_dbus_thread_manager == NULL); + CHECK(!g_dbus_thread_manager); bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || CommandLine::ForCurrentProcess()->HasSwitch( chromeos::switches::kDbusStub); @@ -355,7 +349,7 @@ void DBusThreadManager::Initialize() { } else if (use_dbus_stub) { InitializeWithStubs(); } else { - InitializeRegular(); + InitializeWithRealClients(); } } @@ -370,39 +364,37 @@ scoped_ptr<DBusThreadManagerSetter> DBusThreadManager::GetSetterForTesting() { } // static -void DBusThreadManager::CreateGlobalInstance() { +void DBusThreadManager::CreateGlobalInstance( + DBusClientBundle::DBusClientTypeMask unstub_client_mask) { CHECK(!g_dbus_thread_manager); - g_dbus_thread_manager = new DBusThreadManager(); + g_dbus_thread_manager = new DBusThreadManager( + make_scoped_ptr(new DBusClientBundle(unstub_client_mask))); g_dbus_thread_manager->InitializeClients(); } // static -void DBusThreadManager::InitializeRegular() { - unstub_client_mask_ = DBusClientBundle::ALL_CLIENTS; - CreateGlobalInstance(); +void DBusThreadManager::InitializeWithRealClients() { + CreateGlobalInstance(~static_cast<DBusClientBundle::DBusClientTypeMask>(0)); VLOG(1) << "DBusThreadManager initialized for Chrome OS"; } // static void DBusThreadManager::InitializeWithStubs() { - unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; - CreateGlobalInstance(); + CreateGlobalInstance(0 /* unstub_client_mask */); VLOG(1) << "DBusThreadManager created for testing"; } // static void DBusThreadManager::InitializeWithPartialStub( const std::string& unstub_clients) { - unstub_client_mask_ = DBusClientBundle::ParseUnstubList(unstub_clients); + DBusClientBundle::DBusClientTypeMask 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; - } + LOG_IF(FATAL, unstub_client_mask == 0) + << "Switch values for --" << chromeos::switches::kDbusUnstubClients + << " cannot be parsed: " << unstub_clients; VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; - CreateGlobalInstance(); + CreateGlobalInstance(unstub_client_mask); } // static diff --git a/chromeos/dbus/dbus_thread_manager.h b/chromeos/dbus/dbus_thread_manager.h index a66e904..3fcacc3 100644 --- a/chromeos/dbus/dbus_thread_manager.h +++ b/chromeos/dbus/dbus_thread_manager.h @@ -86,6 +86,8 @@ class CHROMEOS_EXPORT DBusThreadManager { // Sets the global instance. Must be called before any calls to Get(). // We explicitly initialize and shut down the global object, rather than // making it a Singleton, to ensure clean startup and shutdown. + // This will initialize real or stub DBusClients depending on command-line + // arguments and whether this process runs in a ChromeOS environment. static void Initialize(); // Returns a DBusThreadManagerSetter instance that allows tests to @@ -104,7 +106,7 @@ class CHROMEOS_EXPORT DBusThreadManager { static DBusThreadManager* Get(); // Returns true if |client| is stubbed. - static bool IsUsingStub(DBusClientBundle::DBusClientType client); + bool IsUsingStub(DBusClientBundle::DBusClientType client); // Returns various D-Bus bus instances, owned by DBusThreadManager. dbus::Bus* GetSystemBus(); @@ -151,36 +153,34 @@ class CHROMEOS_EXPORT DBusThreadManager { private: friend class DBusThreadManagerSetter; - DBusThreadManager(); + // Creates a new DBusThreadManager using the DBusClients set in + // |client_bundle|. + explicit DBusThreadManager(scoped_ptr<DBusClientBundle> client_bundle); ~DBusThreadManager(); - // Creates a global instance of DBusThreadManager. Can not be called more - // than once. - static void CreateGlobalInstance(); + // Creates a global instance of DBusThreadManager with the real + // implementations for all clients that are listed in |unstub_client_mask| and + // stub implementations for all clients that are not included. Cannot be + // called more than once. + static void CreateGlobalInstance( + DBusClientBundle::DBusClientTypeMask unstub_client_mask); - // Initialize global thread manager instance. - static void InitializeRegular(); + // Initialize global thread manager instance with all real dbus client + // implementations. + static void InitializeWithRealClients(); // Initialize global thread manager instance with stubbed-out dbus clients // implementation. static void InitializeWithStubs(); // Initialize with stub implementations for only certain clients that are - // not included in comma-separated |unstub_clients| list. + // not included in the comma-separated |unstub_clients| list. static void InitializeWithPartialStub(const std::string& unstub_clients); - // Constructs all clients and stores them in the respective *_client_ member - // variable. - void CreateDefaultClients(); - - // Constructs all clients and stores them in the respective *_client_ member - // variable. + // Initializes all currently stored DBusClients with the system bus and + // performs additional setup. void InitializeClients(); - // Bitmask that defines which dbus clients are not stubbed out. Bitmap flags - // are defined within DBusClientBundle::DBusClientType enum. - static DBusClientBundle::DBusClientTypeMask unstub_client_mask_; - scoped_ptr<base::Thread> dbus_thread_; scoped_refptr<dbus::Bus> system_bus_; scoped_ptr<DBusClientBundle> client_bundle_; |