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