| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
| 14 #include "chromeos/dbus/bluetooth_adapter_client.h" | 14 #include "chromeos/dbus/bluetooth_adapter_client.h" |
| 15 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 15 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
| 16 #include "chromeos/dbus/bluetooth_device_client.h" | 16 #include "chromeos/dbus/bluetooth_device_client.h" |
| 17 #include "chromeos/dbus/bluetooth_input_client.h" | 17 #include "chromeos/dbus/bluetooth_input_client.h" |
| 18 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 18 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
| 19 #include "chromeos/dbus/cras_audio_client.h" | 19 #include "chromeos/dbus/cras_audio_client.h" |
| 20 #include "chromeos/dbus/cros_disks_client.h" | 20 #include "chromeos/dbus/cros_disks_client.h" |
| 21 #include "chromeos/dbus/cryptohome_client.h" | 21 #include "chromeos/dbus/cryptohome_client.h" |
| 22 #include "chromeos/dbus/dbus_client.h" |
| 22 #include "chromeos/dbus/dbus_client_implementation_type.h" | 23 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 23 #include "chromeos/dbus/dbus_thread_manager_observer.h" | 24 #include "chromeos/dbus/dbus_thread_manager_observer.h" |
| 24 #include "chromeos/dbus/debug_daemon_client.h" | 25 #include "chromeos/dbus/debug_daemon_client.h" |
| 26 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 25 #include "chromeos/dbus/gsm_sms_client.h" | 27 #include "chromeos/dbus/gsm_sms_client.h" |
| 26 #include "chromeos/dbus/ibus/ibus_client.h" | 28 #include "chromeos/dbus/ibus/ibus_client.h" |
| 27 #include "chromeos/dbus/image_burner_client.h" | 29 #include "chromeos/dbus/image_burner_client.h" |
| 28 #include "chromeos/dbus/introspectable_client.h" | 30 #include "chromeos/dbus/introspectable_client.h" |
| 29 #include "chromeos/dbus/modem_messaging_client.h" | 31 #include "chromeos/dbus/modem_messaging_client.h" |
| 30 #include "chromeos/dbus/nfc_adapter_client.h" | 32 #include "chromeos/dbus/nfc_adapter_client.h" |
| 31 #include "chromeos/dbus/nfc_device_client.h" | 33 #include "chromeos/dbus/nfc_device_client.h" |
| 32 #include "chromeos/dbus/nfc_manager_client.h" | 34 #include "chromeos/dbus/nfc_manager_client.h" |
| 33 #include "chromeos/dbus/nfc_record_client.h" | 35 #include "chromeos/dbus/nfc_record_client.h" |
| 34 #include "chromeos/dbus/nfc_tag_client.h" | 36 #include "chromeos/dbus/nfc_tag_client.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 49 #include "dbus/dbus_statistics.h" | 51 #include "dbus/dbus_statistics.h" |
| 50 | 52 |
| 51 namespace chromeos { | 53 namespace chromeos { |
| 52 | 54 |
| 53 static DBusThreadManager* g_dbus_thread_manager = NULL; | 55 static DBusThreadManager* g_dbus_thread_manager = NULL; |
| 54 static bool g_dbus_thread_manager_set_for_testing = false; | 56 static bool g_dbus_thread_manager_set_for_testing = false; |
| 55 | 57 |
| 56 // The DBusThreadManager implementation used in production. | 58 // The DBusThreadManager implementation used in production. |
| 57 class DBusThreadManagerImpl : public DBusThreadManager { | 59 class DBusThreadManagerImpl : public DBusThreadManager { |
| 58 public: | 60 public: |
| 59 explicit DBusThreadManagerImpl(DBusClientImplementationType client_type) { | 61 explicit DBusThreadManagerImpl() { |
| 60 DBusClientImplementationType client_type_override = client_type; | |
| 61 // If --dbus-stub was requested, pass STUB to specific components; | |
| 62 // Many components like login are not useful with a stub implementation. | |
| 63 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 64 chromeos::switches::kDbusStub)) { | |
| 65 client_type_override = STUB_DBUS_CLIENT_IMPLEMENTATION; | |
| 66 } | |
| 67 | |
| 68 // Create the D-Bus thread. | 62 // Create the D-Bus thread. |
| 69 base::Thread::Options thread_options; | 63 base::Thread::Options thread_options; |
| 70 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 64 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 71 dbus_thread_.reset(new base::Thread("D-Bus thread")); | 65 dbus_thread_.reset(new base::Thread("D-Bus thread")); |
| 72 dbus_thread_->StartWithOptions(thread_options); | 66 dbus_thread_->StartWithOptions(thread_options); |
| 73 | 67 |
| 74 // Create the connection to the system bus. | 68 // Create the connection to the system bus. |
| 75 dbus::Bus::Options system_bus_options; | 69 dbus::Bus::Options system_bus_options; |
| 76 system_bus_options.bus_type = dbus::Bus::SYSTEM; | 70 system_bus_options.bus_type = dbus::Bus::SYSTEM; |
| 77 system_bus_options.connection_type = dbus::Bus::PRIVATE; | 71 system_bus_options.connection_type = dbus::Bus::PRIVATE; |
| 78 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); | 72 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
| 79 system_bus_ = new dbus::Bus(system_bus_options); | 73 system_bus_ = new dbus::Bus(system_bus_options); |
| 80 | 74 |
| 81 CreateDefaultClients(client_type, client_type_override); | 75 CreateDefaultClients(); |
| 82 } | |
| 83 | |
| 84 // InitializeClients gets called after g_dbus_thread_manager is set. | |
| 85 // NOTE: Clients that access other clients in their Init() must be | |
| 86 // initialized in the correct order. This is the only place where Clients' | |
| 87 // Init() should be called if DBusThreadManager is being used. | |
| 88 void InitializeClients() { | |
| 89 InitClient(bluetooth_adapter_client_.get()); | |
| 90 InitClient(bluetooth_agent_manager_client_.get()); | |
| 91 InitClient(bluetooth_device_client_.get()); | |
| 92 InitClient(bluetooth_input_client_.get()); | |
| 93 InitClient(bluetooth_profile_manager_client_.get()); | |
| 94 InitClient(cras_audio_client_.get()); | |
| 95 InitClient(cros_disks_client_.get()); | |
| 96 InitClient(cryptohome_client_.get()); | |
| 97 InitClient(debug_daemon_client_.get()); | |
| 98 InitClient(shill_manager_client_.get()); | |
| 99 InitClient(shill_device_client_.get()); | |
| 100 InitClient(shill_ipconfig_client_.get()); | |
| 101 InitClient(shill_service_client_.get()); | |
| 102 InitClient(shill_profile_client_.get()); | |
| 103 InitClient(gsm_sms_client_.get()); | |
| 104 InitClient(image_burner_client_.get()); | |
| 105 InitClient(introspectable_client_.get()); | |
| 106 InitClient(modem_messaging_client_.get()); | |
| 107 // Initialize the NFC clients in the correct order. | |
| 108 InitClient(nfc_manager_client_.get()); | |
| 109 InitClient(nfc_adapter_client_.get()); | |
| 110 InitClient(nfc_device_client_.get()); | |
| 111 InitClient(nfc_tag_client_.get()); | |
| 112 InitClient(nfc_record_client_.get()); | |
| 113 InitClient(permission_broker_client_.get()); | |
| 114 InitClient(power_manager_client_.get()); | |
| 115 InitClient(session_manager_client_.get()); | |
| 116 InitClient(sms_client_.get()); | |
| 117 InitClient(system_clock_client_.get()); | |
| 118 InitClient(update_engine_client_.get()); | |
| 119 | |
| 120 // PowerPolicyController is dependent on PowerManagerClient, so | |
| 121 // initialize it after the main list of clients. | |
| 122 power_policy_controller_.reset( | |
| 123 new PowerPolicyController(this, power_manager_client_.get())); | |
| 124 | |
| 125 shill_stub_helper::SetupDefaultEnvironment(); | |
| 126 | |
| 127 // This must be called after the list of clients so they've each had a | |
| 128 // chance to register with their object managers. | |
| 129 system_bus_->GetManagedObjects(); | |
| 130 } | 76 } |
| 131 | 77 |
| 132 virtual ~DBusThreadManagerImpl() { | 78 virtual ~DBusThreadManagerImpl() { |
| 133 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, | 79 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, |
| 134 OnDBusThreadManagerDestroying(this)); | 80 OnDBusThreadManagerDestroying(this)); |
| 135 | 81 |
| 136 // Shut down the bus. During the browser shutdown, it's ok to shut down | 82 // Shut down the bus. During the browser shutdown, it's ok to shut down |
| 137 // the bus synchronously. | 83 // the bus synchronously. |
| 138 system_bus_->ShutdownOnDBusThreadAndBlock(); | 84 system_bus_->ShutdownOnDBusThreadAndBlock(); |
| 139 | 85 |
| 140 // Stop the D-Bus thread. | 86 // Stop the D-Bus thread. |
| 141 dbus_thread_->Stop(); | 87 dbus_thread_->Stop(); |
| 142 } | 88 } |
| 143 | 89 |
| 144 // DBusThreadManager override. | 90 // DBusThreadManager overrides: |
| 145 virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE { | 91 virtual void AddObserver(DBusThreadManagerObserver* observer) OVERRIDE { |
| 146 DCHECK(observer); | 92 DCHECK(observer); |
| 147 observers_.AddObserver(observer); | 93 observers_.AddObserver(observer); |
| 148 } | 94 } |
| 149 | 95 |
| 150 // DBusThreadManager override. | |
| 151 virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE { | 96 virtual void RemoveObserver(DBusThreadManagerObserver* observer) OVERRIDE { |
| 152 DCHECK(observer); | 97 DCHECK(observer); |
| 153 observers_.RemoveObserver(observer); | 98 observers_.RemoveObserver(observer); |
| 154 } | 99 } |
| 155 | 100 |
| 156 // DBusThreadManager override. | |
| 157 virtual void InitIBusBus( | 101 virtual void InitIBusBus( |
| 158 const std::string &ibus_address, | 102 const std::string &ibus_address, |
| 159 const base::Closure& on_disconnected_callback) OVERRIDE { | 103 const base::Closure& on_disconnected_callback) OVERRIDE { |
| 160 ibus_client_.reset(IBusClient::Create()); | 104 ibus_client_.reset(IBusClient::Create()); |
| 161 } | 105 } |
| 162 | 106 |
| 163 // DBusThreadManager overrides: | |
| 164 virtual dbus::Bus* GetSystemBus() OVERRIDE { | 107 virtual dbus::Bus* GetSystemBus() OVERRIDE { |
| 165 return system_bus_.get(); | 108 return system_bus_.get(); |
| 166 } | 109 } |
| 167 | 110 |
| 168 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { | 111 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { |
| 169 return bluetooth_adapter_client_.get(); | 112 return bluetooth_adapter_client_.get(); |
| 170 } | 113 } |
| 171 | 114 |
| 172 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() | 115 virtual BluetoothAgentManagerClient* GetBluetoothAgentManagerClient() |
| 173 OVERRIDE { | 116 OVERRIDE { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 228 |
| 286 virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE { | 229 virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE { |
| 287 return update_engine_client_.get(); | 230 return update_engine_client_.get(); |
| 288 } | 231 } |
| 289 | 232 |
| 290 virtual IBusClient* GetIBusClient() OVERRIDE { | 233 virtual IBusClient* GetIBusClient() OVERRIDE { |
| 291 return ibus_client_.get(); | 234 return ibus_client_.get(); |
| 292 } | 235 } |
| 293 | 236 |
| 294 private: | 237 private: |
| 295 // Initializes |client| with the |system_bus_|. | |
| 296 void InitClient(DBusClient* client) { | |
| 297 client->Init(system_bus_.get()); | |
| 298 } | |
| 299 | |
| 300 // Constructs all clients -- stub or real implementation according to | 238 // Constructs all clients -- stub or real implementation according to |
| 301 // |client_type| and |client_type_override| -- and stores them in the | 239 // |client_type| and |client_type_override| -- and stores them in the |
| 302 // respective *_client_ member variable. | 240 // respective *_client_ member variable. |
| 303 void CreateDefaultClients(DBusClientImplementationType client_type, | 241 void CreateDefaultClients() { |
| 304 DBusClientImplementationType client_type_override) { | 242 DBusClientImplementationType client_type = REAL_DBUS_CLIENT_IMPLEMENTATION; |
| 243 DBusClientImplementationType client_type_override = |
| 244 REAL_DBUS_CLIENT_IMPLEMENTATION; |
| 245 // If --dbus-stub was requested, pass STUB to specific components; |
| 246 // Many components like login are not useful with a stub implementation. |
| 247 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 248 chromeos::switches::kDbusStub)) { |
| 249 client_type_override = STUB_DBUS_CLIENT_IMPLEMENTATION; |
| 250 } |
| 251 |
| 305 bluetooth_adapter_client_.reset( | 252 bluetooth_adapter_client_.reset( |
| 306 BluetoothAdapterClient::Create(client_type)); | 253 BluetoothAdapterClient::Create(client_type)); |
| 307 bluetooth_agent_manager_client_.reset( | 254 bluetooth_agent_manager_client_.reset( |
| 308 BluetoothAgentManagerClient::Create(client_type)); | 255 BluetoothAgentManagerClient::Create(client_type)); |
| 309 bluetooth_device_client_.reset(BluetoothDeviceClient::Create(client_type)); | 256 bluetooth_device_client_.reset(BluetoothDeviceClient::Create(client_type)); |
| 310 bluetooth_input_client_.reset(BluetoothInputClient::Create(client_type)); | 257 bluetooth_input_client_.reset(BluetoothInputClient::Create(client_type)); |
| 311 bluetooth_profile_manager_client_.reset( | 258 bluetooth_profile_manager_client_.reset( |
| 312 BluetoothProfileManagerClient::Create(client_type)); | 259 BluetoothProfileManagerClient::Create(client_type)); |
| 313 cras_audio_client_.reset(CrasAudioClient::Create(client_type)); | 260 cras_audio_client_.reset(CrasAudioClient::Create(client_type)); |
| 314 cros_disks_client_.reset(CrosDisksClient::Create(client_type)); | 261 cros_disks_client_.reset(CrosDisksClient::Create(client_type)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 340 NfcRecordClient::Create( | 287 NfcRecordClient::Create( |
| 341 client_type, nfc_device_client_.get(), nfc_tag_client_.get())); | 288 client_type, nfc_device_client_.get(), nfc_tag_client_.get())); |
| 342 permission_broker_client_.reset( | 289 permission_broker_client_.reset( |
| 343 PermissionBrokerClient::Create(client_type)); | 290 PermissionBrokerClient::Create(client_type)); |
| 344 power_manager_client_.reset( | 291 power_manager_client_.reset( |
| 345 PowerManagerClient::Create(client_type_override)); | 292 PowerManagerClient::Create(client_type_override)); |
| 346 session_manager_client_.reset(SessionManagerClient::Create(client_type)); | 293 session_manager_client_.reset(SessionManagerClient::Create(client_type)); |
| 347 sms_client_.reset(SMSClient::Create(client_type)); | 294 sms_client_.reset(SMSClient::Create(client_type)); |
| 348 system_clock_client_.reset(SystemClockClient::Create(client_type)); | 295 system_clock_client_.reset(SystemClockClient::Create(client_type)); |
| 349 update_engine_client_.reset(UpdateEngineClient::Create(client_type)); | 296 update_engine_client_.reset(UpdateEngineClient::Create(client_type)); |
| 297 |
| 298 power_policy_controller_.reset(new PowerPolicyController); |
| 350 } | 299 } |
| 351 | 300 |
| 352 // Note: Keep this before other members so they can call AddObserver() in | 301 // Note: Keep this before other members so they can call AddObserver() in |
| 353 // their c'tors. | 302 // their c'tors. |
| 354 ObserverList<DBusThreadManagerObserver> observers_; | 303 ObserverList<DBusThreadManagerObserver> observers_; |
| 355 | 304 |
| 356 scoped_ptr<base::Thread> dbus_thread_; | 305 scoped_ptr<base::Thread> dbus_thread_; |
| 357 scoped_refptr<dbus::Bus> system_bus_; | 306 scoped_refptr<dbus::Bus> system_bus_; |
| 358 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; | 307 scoped_ptr<BluetoothAdapterClient> bluetooth_adapter_client_; |
| 359 scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_; | 308 scoped_ptr<BluetoothAgentManagerClient> bluetooth_agent_manager_client_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 380 scoped_ptr<NfcDeviceClient> nfc_device_client_; | 329 scoped_ptr<NfcDeviceClient> nfc_device_client_; |
| 381 scoped_ptr<NfcTagClient> nfc_tag_client_; | 330 scoped_ptr<NfcTagClient> nfc_tag_client_; |
| 382 scoped_ptr<NfcRecordClient> nfc_record_client_; | 331 scoped_ptr<NfcRecordClient> nfc_record_client_; |
| 383 scoped_ptr<PermissionBrokerClient> permission_broker_client_; | 332 scoped_ptr<PermissionBrokerClient> permission_broker_client_; |
| 384 scoped_ptr<SystemClockClient> system_clock_client_; | 333 scoped_ptr<SystemClockClient> system_clock_client_; |
| 385 scoped_ptr<PowerManagerClient> power_manager_client_; | 334 scoped_ptr<PowerManagerClient> power_manager_client_; |
| 386 scoped_ptr<SessionManagerClient> session_manager_client_; | 335 scoped_ptr<SessionManagerClient> session_manager_client_; |
| 387 scoped_ptr<SMSClient> sms_client_; | 336 scoped_ptr<SMSClient> sms_client_; |
| 388 scoped_ptr<UpdateEngineClient> update_engine_client_; | 337 scoped_ptr<UpdateEngineClient> update_engine_client_; |
| 389 scoped_ptr<IBusClient> ibus_client_; | 338 scoped_ptr<IBusClient> ibus_client_; |
| 339 |
| 390 scoped_ptr<PowerPolicyController> power_policy_controller_; | 340 scoped_ptr<PowerPolicyController> power_policy_controller_; |
| 391 | |
| 392 }; | 341 }; |
| 393 | 342 |
| 394 // static | 343 // static |
| 395 void DBusThreadManager::Initialize() { | 344 void DBusThreadManager::Initialize() { |
| 396 // Ignore Initialize() if we set a test DBusThreadManager. | 345 // Ignore Initialize() if we set a test DBusThreadManager. |
| 397 if (g_dbus_thread_manager_set_for_testing) | 346 if (g_dbus_thread_manager_set_for_testing) |
| 398 return; | 347 return; |
| 399 // If we initialize DBusThreadManager twice we may also be shutting it down | 348 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 400 // early; do not allow that. | 349 // early; do not allow that. |
| 401 CHECK(g_dbus_thread_manager == NULL); | 350 CHECK(g_dbus_thread_manager == NULL); |
| 351 |
| 402 // Determine whether we use stub or real client implementations. | 352 // Determine whether we use stub or real client implementations. |
| 403 DBusThreadManagerImpl* dbus_thread_manager_impl; | |
| 404 if (base::SysInfo::IsRunningOnChromeOS()) { | 353 if (base::SysInfo::IsRunningOnChromeOS()) { |
| 405 dbus_thread_manager_impl = | 354 g_dbus_thread_manager = new DBusThreadManagerImpl; |
| 406 new DBusThreadManagerImpl(REAL_DBUS_CLIENT_IMPLEMENTATION); | 355 InitializeClients(); |
| 407 VLOG(1) << "DBusThreadManager initialized for ChromeOS"; | 356 VLOG(1) << "DBusThreadManager initialized for ChromeOS"; |
| 408 } else { | 357 } else { |
| 409 dbus_thread_manager_impl = | 358 InitializeWithStub(); |
| 410 new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION); | 359 return; |
| 411 VLOG(1) << "DBusThreadManager initialized with Stub"; | |
| 412 } | 360 } |
| 413 g_dbus_thread_manager = dbus_thread_manager_impl; | |
| 414 dbus_thread_manager_impl->InitializeClients(); | |
| 415 } | 361 } |
| 416 | 362 |
| 417 // static | 363 // static |
| 418 void DBusThreadManager::InitializeForTesting( | 364 void DBusThreadManager::InitializeForTesting( |
| 419 DBusThreadManager* dbus_thread_manager) { | 365 DBusThreadManager* dbus_thread_manager) { |
| 420 // If we initialize DBusThreadManager twice we may also be shutting it down | 366 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 421 // early; do not allow that. | 367 // early; do not allow that. |
| 422 CHECK(g_dbus_thread_manager == NULL); | 368 CHECK(g_dbus_thread_manager == NULL); |
| 423 CHECK(dbus_thread_manager); | 369 CHECK(dbus_thread_manager); |
| 424 g_dbus_thread_manager = dbus_thread_manager; | 370 g_dbus_thread_manager = dbus_thread_manager; |
| 425 g_dbus_thread_manager_set_for_testing = true; | 371 g_dbus_thread_manager_set_for_testing = true; |
| 372 InitializeClients(); |
| 426 VLOG(1) << "DBusThreadManager initialized with test implementation"; | 373 VLOG(1) << "DBusThreadManager initialized with test implementation"; |
| 427 } | 374 } |
| 428 | 375 |
| 429 // static | 376 // static |
| 430 void DBusThreadManager::InitializeWithStub() { | 377 void DBusThreadManager::InitializeWithStub() { |
| 431 // If we initialize DBusThreadManager twice we may also be shutting it down | 378 // If we initialize DBusThreadManager twice we may also be shutting it down |
| 432 // early; do not allow that. | 379 // early; do not allow that. |
| 433 CHECK(g_dbus_thread_manager == NULL); | 380 CHECK(g_dbus_thread_manager == NULL); |
| 434 DBusThreadManagerImpl* dbus_thread_manager_impl = | 381 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; |
| 435 new DBusThreadManagerImpl(STUB_DBUS_CLIENT_IMPLEMENTATION); | 382 fake_dbus_thread_manager->SetFakeClients(); |
| 436 g_dbus_thread_manager = dbus_thread_manager_impl; | 383 g_dbus_thread_manager = fake_dbus_thread_manager; |
| 437 dbus_thread_manager_impl->InitializeClients(); | 384 InitializeClients(); |
| 385 shill_stub_helper::SetupDefaultEnvironment(); |
| 438 VLOG(1) << "DBusThreadManager initialized with stub implementation"; | 386 VLOG(1) << "DBusThreadManager initialized with stub implementation"; |
| 439 } | 387 } |
| 440 | 388 |
| 441 // static | 389 // static |
| 442 bool DBusThreadManager::IsInitialized() { | 390 bool DBusThreadManager::IsInitialized() { |
| 443 return g_dbus_thread_manager != NULL; | 391 return g_dbus_thread_manager != NULL; |
| 444 } | 392 } |
| 445 | 393 |
| 446 // static | 394 // static |
| 447 void DBusThreadManager::Shutdown() { | 395 void DBusThreadManager::Shutdown() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 473 } | 421 } |
| 474 } | 422 } |
| 475 | 423 |
| 476 // static | 424 // static |
| 477 DBusThreadManager* DBusThreadManager::Get() { | 425 DBusThreadManager* DBusThreadManager::Get() { |
| 478 CHECK(g_dbus_thread_manager) | 426 CHECK(g_dbus_thread_manager) |
| 479 << "DBusThreadManager::Get() called before Initialize()"; | 427 << "DBusThreadManager::Get() called before Initialize()"; |
| 480 return g_dbus_thread_manager; | 428 return g_dbus_thread_manager; |
| 481 } | 429 } |
| 482 | 430 |
| 431 // static |
| 432 void DBusThreadManager::InitializeClients() { |
| 433 InitClient(g_dbus_thread_manager->GetBluetoothAdapterClient()); |
| 434 InitClient(g_dbus_thread_manager->GetBluetoothAgentManagerClient()); |
| 435 InitClient(g_dbus_thread_manager->GetBluetoothDeviceClient()); |
| 436 InitClient(g_dbus_thread_manager->GetBluetoothInputClient()); |
| 437 InitClient(g_dbus_thread_manager->GetBluetoothProfileManagerClient()); |
| 438 InitClient(g_dbus_thread_manager->GetCrasAudioClient()); |
| 439 InitClient(g_dbus_thread_manager->GetCrosDisksClient()); |
| 440 InitClient(g_dbus_thread_manager->GetCryptohomeClient()); |
| 441 InitClient(g_dbus_thread_manager->GetDebugDaemonClient()); |
| 442 InitClient(g_dbus_thread_manager->GetGsmSMSClient()); |
| 443 InitClient(g_dbus_thread_manager->GetImageBurnerClient()); |
| 444 InitClient(g_dbus_thread_manager->GetIntrospectableClient()); |
| 445 InitClient(g_dbus_thread_manager->GetModemMessagingClient()); |
| 446 // Initialize the NFC clients in the correct order. |
| 447 InitClient(g_dbus_thread_manager->GetNfcAdapterClient()); |
| 448 InitClient(g_dbus_thread_manager->GetNfcManagerClient()); |
| 449 InitClient(g_dbus_thread_manager->GetNfcDeviceClient()); |
| 450 InitClient(g_dbus_thread_manager->GetNfcTagClient()); |
| 451 InitClient(g_dbus_thread_manager->GetPermissionBrokerClient()); |
| 452 InitClient(g_dbus_thread_manager->GetPowerManagerClient()); |
| 453 InitClient(g_dbus_thread_manager->GetSessionManagerClient()); |
| 454 InitClient(g_dbus_thread_manager->GetShillDeviceClient()); |
| 455 InitClient(g_dbus_thread_manager->GetShillIPConfigClient()); |
| 456 InitClient(g_dbus_thread_manager->GetShillManagerClient()); |
| 457 InitClient(g_dbus_thread_manager->GetShillServiceClient()); |
| 458 InitClient(g_dbus_thread_manager->GetShillProfileClient()); |
| 459 InitClient(g_dbus_thread_manager->GetSMSClient()); |
| 460 InitClient(g_dbus_thread_manager->GetSystemClockClient()); |
| 461 InitClient(g_dbus_thread_manager->GetUpdateEngineClient()); |
| 462 |
| 463 // PowerPolicyController is dependent on PowerManagerClient, so |
| 464 // initialize it after the main list of clients. |
| 465 if (g_dbus_thread_manager->GetPowerPolicyController()) { |
| 466 g_dbus_thread_manager->GetPowerPolicyController()->Init( |
| 467 g_dbus_thread_manager); |
| 468 } |
| 469 |
| 470 // This must be called after the list of clients so they've each had a |
| 471 // chance to register with their object g_dbus_thread_managers. |
| 472 if (g_dbus_thread_manager->GetSystemBus()) |
| 473 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); |
| 474 } |
| 475 |
| 476 // static |
| 477 void DBusThreadManager::InitClient(DBusClient* client) { |
| 478 if (client) |
| 479 client->Init(g_dbus_thread_manager->GetSystemBus()); |
| 480 } |
| 481 |
| 483 } // namespace chromeos | 482 } // namespace chromeos |
| OLD | NEW |