| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/dbus_thread_manager.h" | 5 #include "chromeos/dbus/dbus_thread_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/sys_info.h" | 8 #include "base/sys_info.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "chromeos/chromeos_switches.h" | 10 #include "chromeos/chromeos_switches.h" |
| 11 #include "chromeos/dbus/bluetooth_adapter_client.h" | 11 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 12 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 12 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| 13 #include "chromeos/dbus/bluetooth_device_client.h" | 13 #include "chromeos/dbus/bluetooth_device_client.h" |
| 14 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" | 14 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
| 15 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | 15 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" |
| 16 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" | 16 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" |
| 17 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 17 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
| 18 #include "chromeos/dbus/bluetooth_input_client.h" | 18 #include "chromeos/dbus/bluetooth_input_client.h" |
| 19 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 19 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
| 20 #include "chromeos/dbus/cras_audio_client.h" | 20 #include "chromeos/dbus/cras_audio_client.h" |
| 21 #include "chromeos/dbus/cros_disks_client.h" | 21 #include "chromeos/dbus/cros_disks_client.h" |
| 22 #include "chromeos/dbus/cryptohome_client.h" | 22 #include "chromeos/dbus/cryptohome_client.h" |
| 23 #include "chromeos/dbus/dbus_client.h" | 23 #include "chromeos/dbus/dbus_client.h" |
| 24 #include "chromeos/dbus/dbus_client_bundle.h" |
| 24 #include "chromeos/dbus/debug_daemon_client.h" | 25 #include "chromeos/dbus/debug_daemon_client.h" |
| 25 #include "chromeos/dbus/easy_unlock_client.h" | 26 #include "chromeos/dbus/easy_unlock_client.h" |
| 26 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 27 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 27 #include "chromeos/dbus/gsm_sms_client.h" | 28 #include "chromeos/dbus/gsm_sms_client.h" |
| 28 #include "chromeos/dbus/image_burner_client.h" | 29 #include "chromeos/dbus/image_burner_client.h" |
| 29 #include "chromeos/dbus/introspectable_client.h" | 30 #include "chromeos/dbus/introspectable_client.h" |
| 30 #include "chromeos/dbus/lorgnette_manager_client.h" | 31 #include "chromeos/dbus/lorgnette_manager_client.h" |
| 32 #include "chromeos/dbus/mixed_dbus_thread_manager.h" |
| 31 #include "chromeos/dbus/modem_messaging_client.h" | 33 #include "chromeos/dbus/modem_messaging_client.h" |
| 32 #include "chromeos/dbus/nfc_adapter_client.h" | 34 #include "chromeos/dbus/nfc_adapter_client.h" |
| 33 #include "chromeos/dbus/nfc_device_client.h" | 35 #include "chromeos/dbus/nfc_device_client.h" |
| 34 #include "chromeos/dbus/nfc_manager_client.h" | 36 #include "chromeos/dbus/nfc_manager_client.h" |
| 35 #include "chromeos/dbus/nfc_record_client.h" | 37 #include "chromeos/dbus/nfc_record_client.h" |
| 36 #include "chromeos/dbus/nfc_tag_client.h" | 38 #include "chromeos/dbus/nfc_tag_client.h" |
| 37 #include "chromeos/dbus/permission_broker_client.h" | 39 #include "chromeos/dbus/permission_broker_client.h" |
| 38 #include "chromeos/dbus/power_manager_client.h" | 40 #include "chromeos/dbus/power_manager_client.h" |
| 39 #include "chromeos/dbus/power_policy_controller.h" | 41 #include "chromeos/dbus/power_policy_controller.h" |
| 40 #include "chromeos/dbus/session_manager_client.h" | 42 #include "chromeos/dbus/session_manager_client.h" |
| 41 #include "chromeos/dbus/shill_device_client.h" | 43 #include "chromeos/dbus/shill_device_client.h" |
| 42 #include "chromeos/dbus/shill_ipconfig_client.h" | 44 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 43 #include "chromeos/dbus/shill_manager_client.h" | 45 #include "chromeos/dbus/shill_manager_client.h" |
| 44 #include "chromeos/dbus/shill_profile_client.h" | 46 #include "chromeos/dbus/shill_profile_client.h" |
| 45 #include "chromeos/dbus/shill_service_client.h" | 47 #include "chromeos/dbus/shill_service_client.h" |
| 46 #include "chromeos/dbus/sms_client.h" | 48 #include "chromeos/dbus/sms_client.h" |
| 47 #include "chromeos/dbus/system_clock_client.h" | 49 #include "chromeos/dbus/system_clock_client.h" |
| 48 #include "chromeos/dbus/update_engine_client.h" | 50 #include "chromeos/dbus/update_engine_client.h" |
| 49 #include "dbus/bus.h" | 51 #include "dbus/bus.h" |
| 50 #include "dbus/dbus_statistics.h" | 52 #include "dbus/dbus_statistics.h" |
| 51 | 53 |
| 52 namespace chromeos { | 54 namespace chromeos { |
| 53 | 55 |
| 54 static DBusThreadManager* g_dbus_thread_manager = NULL; | 56 static DBusThreadManager* g_dbus_thread_manager = NULL; |
| 55 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL; | 57 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL; |
| 56 | 58 |
| 57 // The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle | 59 DBusClientBundle::DBusClientTypeMask |
| 58 // is used to delete them at once in the right order before shutting down the | 60 DBusThreadManager::unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; |
| 59 // system bus. See also the comment in the destructor of DBusThreadManagerImpl. | |
| 60 class DBusClientBundle { | |
| 61 public: | |
| 62 DBusClientBundle() { | |
| 63 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; | |
| 64 | |
| 65 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); | |
| 66 bluetooth_agent_manager_client_.reset( | |
| 67 BluetoothAgentManagerClient::Create()); | |
| 68 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); | |
| 69 bluetooth_gatt_characteristic_client_.reset( | |
| 70 BluetoothGattCharacteristicClient::Create()); | |
| 71 bluetooth_gatt_descriptor_client_.reset( | |
| 72 BluetoothGattDescriptorClient::Create()); | |
| 73 bluetooth_gatt_manager_client_.reset(BluetoothGattManagerClient::Create()); | |
| 74 bluetooth_gatt_service_client_.reset(BluetoothGattServiceClient::Create()); | |
| 75 bluetooth_input_client_.reset(BluetoothInputClient::Create()); | |
| 76 bluetooth_profile_manager_client_.reset( | |
| 77 BluetoothProfileManagerClient::Create()); | |
| 78 cras_audio_client_.reset(CrasAudioClient::Create()); | |
| 79 cros_disks_client_.reset(CrosDisksClient::Create(type)); | |
| 80 cryptohome_client_.reset(CryptohomeClient::Create()); | |
| 81 debug_daemon_client_.reset(DebugDaemonClient::Create()); | |
| 82 easy_unlock_client_.reset(EasyUnlockClient::Create()); | |
| 83 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); | |
| 84 shill_manager_client_.reset(ShillManagerClient::Create()); | |
| 85 shill_device_client_.reset(ShillDeviceClient::Create()); | |
| 86 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); | |
| 87 shill_service_client_.reset(ShillServiceClient::Create()); | |
| 88 shill_profile_client_.reset(ShillProfileClient::Create()); | |
| 89 gsm_sms_client_.reset(GsmSMSClient::Create()); | |
| 90 image_burner_client_.reset(ImageBurnerClient::Create()); | |
| 91 introspectable_client_.reset(IntrospectableClient::Create()); | |
| 92 modem_messaging_client_.reset(ModemMessagingClient::Create()); | |
| 93 // Create the NFC clients in the correct order based on their dependencies. | |
| 94 nfc_manager_client_.reset(NfcManagerClient::Create()); | |
| 95 nfc_adapter_client_.reset( | |
| 96 NfcAdapterClient::Create(nfc_manager_client_.get())); | |
| 97 nfc_device_client_.reset( | |
| 98 NfcDeviceClient::Create(nfc_adapter_client_.get())); | |
| 99 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); | |
| 100 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), | |
| 101 nfc_tag_client_.get())); | |
| 102 permission_broker_client_.reset(PermissionBrokerClient::Create()); | |
| 103 power_manager_client_.reset(PowerManagerClient::Create(type)); | |
| 104 session_manager_client_.reset(SessionManagerClient::Create(type)); | |
| 105 sms_client_.reset(SMSClient::Create()); | |
| 106 system_clock_client_.reset(SystemClockClient::Create()); | |
| 107 update_engine_client_.reset(UpdateEngineClient::Create(type)); | |
| 108 } | |
| 109 | |
| 110 BluetoothAdapterClient* bluetooth_adapter_client() { | |
| 111 return bluetooth_adapter_client_.get(); | |
| 112 } | |
| 113 BluetoothAgentManagerClient* bluetooth_agent_manager_client() { | |
| 114 return bluetooth_agent_manager_client_.get(); | |
| 115 } | |
| 116 BluetoothDeviceClient* bluetooth_device_client() { | |
| 117 return bluetooth_device_client_.get(); | |
| 118 } | |
| 119 BluetoothGattCharacteristicClient* bluetooth_gatt_characteristic_client() { | |
| 120 return bluetooth_gatt_characteristic_client_.get(); | |
| 121 } | |
| 122 BluetoothGattDescriptorClient* bluetooth_gatt_descriptor_client() { | |
| 123 return bluetooth_gatt_descriptor_client_.get(); | |
| 124 } | |
| 125 BluetoothGattManagerClient* bluetooth_gatt_manager_client() { | |
| 126 return bluetooth_gatt_manager_client_.get(); | |
| 127 } | |
| 128 BluetoothGattServiceClient* bluetooth_gatt_service_client() { | |
| 129 return bluetooth_gatt_service_client_.get(); | |
| 130 } | |
| 131 BluetoothInputClient* bluetooth_input_client() { | |
| 132 return bluetooth_input_client_.get(); | |
| 133 } | |
| 134 BluetoothProfileManagerClient* bluetooth_profile_manager_client() { | |
| 135 return bluetooth_profile_manager_client_.get(); | |
| 136 } | |
| 137 CrasAudioClient* cras_audio_client() { | |
| 138 return cras_audio_client_.get(); | |
| 139 } | |
| 140 CrosDisksClient* cros_disks_client() { | |
| 141 return cros_disks_client_.get(); | |
| 142 } | |
| 143 CryptohomeClient* cryptohome_client() { | |
| 144 return cryptohome_client_.get(); | |
| 145 } | |
| 146 DebugDaemonClient* debug_daemon_client() { | |
| 147 return debug_daemon_client_.get(); | |
| 148 } | |
| 149 EasyUnlockClient* easy_unlock_client() { | |
| 150 return easy_unlock_client_.get(); | |
| 151 } | |
| 152 LorgnetteManagerClient* lorgnette_manager_client() { | |
| 153 return lorgnette_manager_client_.get(); | |
| 154 } | |
| 155 ShillDeviceClient* shill_device_client() { | |
| 156 return shill_device_client_.get(); | |
| 157 } | |
| 158 ShillIPConfigClient* shill_ipconfig_client() { | |
| 159 return shill_ipconfig_client_.get(); | |
| 160 } | |
| 161 ShillManagerClient* shill_manager_client() { | |
| 162 return shill_manager_client_.get(); | |
| 163 } | |
| 164 ShillServiceClient* shill_service_client() { | |
| 165 return shill_service_client_.get(); | |
| 166 } | |
| 167 ShillProfileClient* shill_profile_client() { | |
| 168 return shill_profile_client_.get(); | |
| 169 } | |
| 170 GsmSMSClient* gsm_sms_client() { | |
| 171 return gsm_sms_client_.get(); | |
| 172 } | |
| 173 ImageBurnerClient* image_burner_client() { | |
| 174 return image_burner_client_.get(); | |
| 175 } | |
| 176 IntrospectableClient* introspectable_client() { | |
| 177 return introspectable_client_.get(); | |
| 178 } | |
| 179 ModemMessagingClient* modem_messaging_client() { | |
| 180 return modem_messaging_client_.get(); | |
| 181 } | |
| 182 NfcManagerClient* nfc_manager_client() { | |
| 183 return nfc_manager_client_.get(); | |
| 184 } | |
| 185 NfcAdapterClient* nfc_adapter_client() { | |
| 186 return nfc_adapter_client_.get(); | |
| 187 } | |
| 188 NfcDeviceClient* nfc_device_client() { | |
| 189 return nfc_device_client_.get(); | |
| 190 } | |
| 191 NfcTagClient* nfc_tag_client() { | |
| 192 return nfc_tag_client_.get(); | |
| 193 } | |
| 194 NfcRecordClient* nfc_record_client() { | |
| 195 return nfc_record_client_.get(); | |
| 196 } | |
| 197 PermissionBrokerClient* permission_broker_client() { | |
| 198 return permission_broker_client_.get(); | |
| 199 } | |
| 200 SystemClockClient* system_clock_client() { | |
| 201 return system_clock_client_.get(); | |
| 202 } | |
| 203 PowerManagerClient* power_manager_client() { | |
| 204 return power_manager_client_.get(); | |
| 205 } | |
| 206 SessionManagerClient* session_manager_client() { | |
| 207 return session_manager_client_.get(); | |
| 208 } | |
| 209 SMSClient* sms_client() { | |
| 210 return sms_client_.get(); | |
| 211 } | |
| 212 UpdateEngineClient* update_engine_client() { | |
| 213 return update_engine_client_.get(); | |
| 214 } | |
| 215 | |
| 216 private: | |
| 217 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; | |
| 218 scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_; | |
| 219 scoped_ptr<BluetoothDeviceClient> bluetooth_device_client_; | |
| 220 scoped_ptr<BluetoothGattCharacteristicClient> | |
| 221 bluetooth_gatt_characteristic_client_; | |
| 222 scoped_ptr<BluetoothGattDescriptorClient> bluetooth_gatt_descriptor_client_; | |
| 223 scoped_ptr<BluetoothGattManagerClient> bluetooth_gatt_manager_client_; | |
| 224 scoped_ptr<BluetoothGattServiceClient> bluetooth_gatt_service_client_; | |
| 225 scoped_ptr<BluetoothInputClient> bluetooth_input_client_; | |
| 226 scoped_ptr<BluetoothProfileManagerClient> bluetooth_profile_manager_client_; | |
| 227 scoped_ptr<CrasAudioClient> cras_audio_client_; | |
| 228 scoped_ptr<CrosDisksClient> cros_disks_client_; | |
| 229 scoped_ptr<CryptohomeClient> cryptohome_client_; | |
| 230 scoped_ptr<DebugDaemonClient> debug_daemon_client_; | |
| 231 scoped_ptr<EasyUnlockClient> easy_unlock_client_; | |
| 232 scoped_ptr<LorgnetteManagerClient> lorgnette_manager_client_; | |
| 233 scoped_ptr<ShillDeviceClient> shill_device_client_; | |
| 234 scoped_ptr<ShillIPConfigClient> shill_ipconfig_client_; | |
| 235 scoped_ptr<ShillManagerClient> shill_manager_client_; | |
| 236 scoped_ptr<ShillServiceClient> shill_service_client_; | |
| 237 scoped_ptr<ShillProfileClient> shill_profile_client_; | |
| 238 scoped_ptr<GsmSMSClient> gsm_sms_client_; | |
| 239 scoped_ptr<ImageBurnerClient> image_burner_client_; | |
| 240 scoped_ptr<IntrospectableClient> introspectable_client_; | |
| 241 scoped_ptr<ModemMessagingClient> modem_messaging_client_; | |
| 242 // The declaration order for NFC client objects is important. See | |
| 243 // DBusThreadManager::CreateDefaultClients for the dependencies. | |
| 244 scoped_ptr<NfcManagerClient> nfc_manager_client_; | |
| 245 scoped_ptr<NfcAdapterClient> nfc_adapter_client_; | |
| 246 scoped_ptr<NfcDeviceClient> nfc_device_client_; | |
| 247 scoped_ptr<NfcTagClient> nfc_tag_client_; | |
| 248 scoped_ptr<NfcRecordClient> nfc_record_client_; | |
| 249 scoped_ptr<PermissionBrokerClient> permission_broker_client_; | |
| 250 scoped_ptr<SystemClockClient> system_clock_client_; | |
| 251 scoped_ptr<PowerManagerClient> power_manager_client_; | |
| 252 scoped_ptr<SessionManagerClient> session_manager_client_; | |
| 253 scoped_ptr<SMSClient> sms_client_; | |
| 254 scoped_ptr<UpdateEngineClient> update_engine_client_; | |
| 255 | |
| 256 DISALLOW_COPY_AND_ASSIGN(DBusClientBundle); | |
| 257 }; | |
| 258 | 61 |
| 259 // The DBusThreadManager implementation used in production. | 62 // The DBusThreadManager implementation used in production. |
| 260 class DBusThreadManagerImpl : public DBusThreadManager { | 63 class DBusThreadManagerImpl : public DBusThreadManager { |
| 261 public: | 64 public: |
| 262 DBusThreadManagerImpl() { | 65 DBusThreadManagerImpl() { |
| 263 // Create the D-Bus thread. | 66 // Create the D-Bus thread. |
| 264 base::Thread::Options thread_options; | 67 base::Thread::Options thread_options; |
| 265 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 68 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 266 dbus_thread_.reset(new base::Thread("D-Bus thread")); | 69 dbus_thread_.reset(new base::Thread("D-Bus thread")); |
| 267 dbus_thread_->StartWithOptions(thread_options); | 70 dbus_thread_->StartWithOptions(thread_options); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 284 client_bundle_.reset(); | 87 client_bundle_.reset(); |
| 285 | 88 |
| 286 // Shut down the bus. During the browser shutdown, it's ok to shut down | 89 // Shut down the bus. During the browser shutdown, it's ok to shut down |
| 287 // the bus synchronously. | 90 // the bus synchronously. |
| 288 system_bus_->ShutdownOnDBusThreadAndBlock(); | 91 system_bus_->ShutdownOnDBusThreadAndBlock(); |
| 289 | 92 |
| 290 // Stop the D-Bus thread. | 93 // Stop the D-Bus thread. |
| 291 dbus_thread_->Stop(); | 94 dbus_thread_->Stop(); |
| 292 } | 95 } |
| 293 | 96 |
| 294 // DBusThreadManager overrides: | |
| 295 virtual dbus::Bus* GetSystemBus() OVERRIDE { | 97 virtual dbus::Bus* GetSystemBus() OVERRIDE { |
| 296 return system_bus_.get(); | 98 return system_bus_.get(); |
| 297 } | 99 } |
| 298 | 100 |
| 299 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { | 101 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { |
| 300 return client_bundle_->bluetooth_adapter_client(); | 102 return client_bundle_->bluetooth_adapter_client(); |
| 301 } | 103 } |
| 302 | 104 |
| 303 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() | 105 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() |
| 304 OVERRIDE { | 106 OVERRIDE { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 } | 242 } |
| 441 | 243 |
| 442 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { | 244 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { |
| 443 return power_policy_controller_.get(); | 245 return power_policy_controller_.get(); |
| 444 } | 246 } |
| 445 | 247 |
| 446 private: | 248 private: |
| 447 // Constructs all clients and stores them in the respective *_client_ member | 249 // Constructs all clients and stores them in the respective *_client_ member |
| 448 // variable. | 250 // variable. |
| 449 void CreateDefaultClients() { | 251 void CreateDefaultClients() { |
| 450 client_bundle_.reset(new DBusClientBundle); | 252 client_bundle_.reset(new DBusClientBundle()); |
| 451 power_policy_controller_.reset(new PowerPolicyController); | 253 // TODO(crbug.com/345586): Move PowerPolicyController out of |
| 254 // DBusThreadManagerImpl. |
| 255 if (!DBusThreadManager::IsUsingStub(DBusClientBundle::POWER_MANAGER)) |
| 256 power_policy_controller_.reset(new PowerPolicyController); |
| 452 } | 257 } |
| 453 | 258 |
| 454 scoped_ptr<base::Thread> dbus_thread_; | 259 scoped_ptr<base::Thread> dbus_thread_; |
| 455 scoped_refptr<dbus::Bus> system_bus_; | 260 scoped_refptr<dbus::Bus> system_bus_; |
| 456 scoped_ptr<DBusClientBundle> client_bundle_; | 261 scoped_ptr<DBusClientBundle> client_bundle_; |
| 457 scoped_ptr<PowerPolicyController> power_policy_controller_; | 262 scoped_ptr<PowerPolicyController> power_policy_controller_; |
| 458 | 263 |
| 459 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); | 264 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); |
| 460 }; | 265 }; |
| 461 | 266 |
| 462 // static | 267 // static |
| 268 bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { |
| 269 return !(unstub_client_mask_ & client); |
| 270 } |
| 271 |
| 272 // static |
| 463 void DBusThreadManager::Initialize() { | 273 void DBusThreadManager::Initialize() { |
| 464 // If we initialize DBusThreadManager twice we may also be shutting it down | 274 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 465 // early; do not allow that. | 275 // early; do not allow that. |
| 466 CHECK(g_dbus_thread_manager == NULL); | 276 CHECK(g_dbus_thread_manager == NULL); |
| 467 | 277 |
| 468 if (g_dbus_thread_manager_for_testing) { | 278 if (g_dbus_thread_manager_for_testing) { |
| 469 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; | 279 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; |
| 470 InitializeClients(); | 280 InitializeClients(); |
| 471 VLOG(1) << "DBusThreadManager initialized with test implementation"; | 281 VLOG(1) << "DBusThreadManager initialized with test implementation"; |
| 472 return; | 282 return; |
| 473 } | 283 } |
| 474 | 284 |
| 285 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || |
| 286 CommandLine::ForCurrentProcess()->HasSwitch( |
| 287 chromeos::switches::kDbusStub); |
| 288 bool force_unstub_clients = CommandLine::ForCurrentProcess()->HasSwitch( |
| 289 chromeos::switches::kDbusUnstubClients); |
| 475 // Determine whether we use stub or real client implementations. | 290 // Determine whether we use stub or real client implementations. |
| 476 if (!base::SysInfo::IsRunningOnChromeOS() || | 291 if (force_unstub_clients) { |
| 477 CommandLine::ForCurrentProcess()->HasSwitch( | 292 InitializeWithPartialStub( |
| 478 chromeos::switches::kDbusStub)) { | 293 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 294 chromeos::switches::kDbusUnstubClients)); |
| 295 } else if (use_dbus_stub) { |
| 479 InitializeWithStub(); | 296 InitializeWithStub(); |
| 480 } else { | 297 } else { |
| 481 g_dbus_thread_manager = new DBusThreadManagerImpl; | 298 InitializeRegular(); |
| 482 InitializeClients(); | |
| 483 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | |
| 484 } | 299 } |
| 485 } | 300 } |
| 486 | 301 |
| 487 // static | 302 // static |
| 488 void DBusThreadManager::SetInstanceForTesting( | 303 void DBusThreadManager::SetInstanceForTesting( |
| 489 DBusThreadManager* dbus_thread_manager) { | 304 DBusThreadManager* dbus_thread_manager) { |
| 490 CHECK(!g_dbus_thread_manager); | 305 CHECK(!g_dbus_thread_manager); |
| 491 CHECK(!g_dbus_thread_manager_for_testing); | 306 CHECK(!g_dbus_thread_manager_for_testing); |
| 492 g_dbus_thread_manager_for_testing = dbus_thread_manager; | 307 g_dbus_thread_manager_for_testing = dbus_thread_manager; |
| 493 } | 308 } |
| 494 | 309 |
| 495 // static | 310 // static |
| 496 void DBusThreadManager::InitializeForTesting( | 311 void DBusThreadManager::InitializeForTesting( |
| 497 DBusThreadManager* dbus_thread_manager) { | 312 DBusThreadManager* dbus_thread_manager) { |
| 313 unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; |
| 498 SetInstanceForTesting(dbus_thread_manager); | 314 SetInstanceForTesting(dbus_thread_manager); |
| 499 Initialize(); | 315 Initialize(); |
| 500 } | 316 } |
| 501 | 317 |
| 502 // static | 318 // static |
| 503 void DBusThreadManager::InitializeWithStub() { | 319 void DBusThreadManager::InitializeRegular() { |
| 320 unstub_client_mask_ = DBusClientBundle::ALL_CLIENTS; |
| 321 g_dbus_thread_manager = new DBusThreadManagerImpl(); |
| 322 InitializeClients(); |
| 323 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; |
| 324 } |
| 325 |
| 326 // static |
| 327 void DBusThreadManager::InitializeWithPartialStub( |
| 328 const std::string& unstub_clients) { |
| 504 // If we initialize DBusThreadManager twice we may also be shutting it down | 329 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 505 // early; do not allow that. | 330 // early; do not allow that. |
| 506 CHECK(g_dbus_thread_manager == NULL); | 331 CHECK(g_dbus_thread_manager == NULL); |
| 332 |
| 333 unstub_client_mask_ = DBusClientBundle::ParseUnstubList(unstub_clients); |
| 334 // We should have something parsed correctly here. |
| 335 if (unstub_client_mask_ == 0) { |
| 336 LOG(FATAL) << "Switch values for --" |
| 337 << chromeos::switches::kDbusUnstubClients |
| 338 << " cannot be parsed: " |
| 339 << unstub_clients; |
| 340 } |
| 341 DBusThreadManager* real_thread_manager = new DBusThreadManagerImpl(); |
| 342 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; |
| 343 fake_dbus_thread_manager->SetFakeClients(); |
| 344 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; |
| 345 g_dbus_thread_manager = new MixedDBusThreadManager(real_thread_manager, |
| 346 fake_dbus_thread_manager); |
| 347 InitializeClients(); |
| 348 fake_dbus_thread_manager->SetupDefaultEnvironment(); |
| 349 } |
| 350 |
| 351 // static |
| 352 void DBusThreadManager::InitializeWithStub() { |
| 353 unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; |
| 354 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 355 // early; do not allow that. |
| 356 CHECK(g_dbus_thread_manager == NULL); |
| 507 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; | 357 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; |
| 508 fake_dbus_thread_manager->SetFakeClients(); | 358 fake_dbus_thread_manager->SetFakeClients(); |
| 509 g_dbus_thread_manager = fake_dbus_thread_manager; | 359 g_dbus_thread_manager = fake_dbus_thread_manager; |
| 510 InitializeClients(); | 360 InitializeClients(); |
| 511 fake_dbus_thread_manager->SetupDefaultEnvironment(); | 361 fake_dbus_thread_manager->SetupDefaultEnvironment(); |
| 512 VLOG(1) << "DBusThreadManager initialized with stub implementation"; | 362 VLOG(1) << "DBusThreadManager initialized with stub implementation"; |
| 513 } | 363 } |
| 514 | 364 |
| 515 // static | 365 // static |
| 516 bool DBusThreadManager::IsInitialized() { | 366 bool DBusThreadManager::IsInitialized() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); | 460 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); |
| 611 } | 461 } |
| 612 | 462 |
| 613 // static | 463 // static |
| 614 void DBusThreadManager::InitClient(DBusClient* client) { | 464 void DBusThreadManager::InitClient(DBusClient* client) { |
| 615 if (client) | 465 if (client) |
| 616 client->Init(g_dbus_thread_manager->GetSystemBus()); | 466 client->Init(g_dbus_thread_manager->GetSystemBus()); |
| 617 } | 467 } |
| 618 | 468 |
| 619 } // namespace chromeos | 469 } // namespace chromeos |
| OLD | NEW |