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/dbus_client_bundle.h" |
25 #include "chromeos/dbus/debug_daemon_client.h" | 25 #include "chromeos/dbus/debug_daemon_client.h" |
26 #include "chromeos/dbus/easy_unlock_client.h" | 26 #include "chromeos/dbus/easy_unlock_client.h" |
27 #include "chromeos/dbus/fake_dbus_thread_manager.h" | |
28 #include "chromeos/dbus/gsm_sms_client.h" | 27 #include "chromeos/dbus/gsm_sms_client.h" |
29 #include "chromeos/dbus/image_burner_client.h" | 28 #include "chromeos/dbus/image_burner_client.h" |
30 #include "chromeos/dbus/introspectable_client.h" | 29 #include "chromeos/dbus/introspectable_client.h" |
31 #include "chromeos/dbus/lorgnette_manager_client.h" | 30 #include "chromeos/dbus/lorgnette_manager_client.h" |
32 #include "chromeos/dbus/modem_messaging_client.h" | 31 #include "chromeos/dbus/modem_messaging_client.h" |
33 #include "chromeos/dbus/nfc_adapter_client.h" | 32 #include "chromeos/dbus/nfc_adapter_client.h" |
34 #include "chromeos/dbus/nfc_device_client.h" | 33 #include "chromeos/dbus/nfc_device_client.h" |
35 #include "chromeos/dbus/nfc_manager_client.h" | 34 #include "chromeos/dbus/nfc_manager_client.h" |
36 #include "chromeos/dbus/nfc_record_client.h" | 35 #include "chromeos/dbus/nfc_record_client.h" |
37 #include "chromeos/dbus/nfc_tag_client.h" | 36 #include "chromeos/dbus/nfc_tag_client.h" |
38 #include "chromeos/dbus/permission_broker_client.h" | 37 #include "chromeos/dbus/permission_broker_client.h" |
39 #include "chromeos/dbus/power_manager_client.h" | 38 #include "chromeos/dbus/power_manager_client.h" |
40 #include "chromeos/dbus/power_policy_controller.h" | 39 #include "chromeos/dbus/power_policy_controller.h" |
41 #include "chromeos/dbus/session_manager_client.h" | 40 #include "chromeos/dbus/session_manager_client.h" |
42 #include "chromeos/dbus/shill_device_client.h" | 41 #include "chromeos/dbus/shill_device_client.h" |
43 #include "chromeos/dbus/shill_ipconfig_client.h" | 42 #include "chromeos/dbus/shill_ipconfig_client.h" |
44 #include "chromeos/dbus/shill_manager_client.h" | 43 #include "chromeos/dbus/shill_manager_client.h" |
45 #include "chromeos/dbus/shill_profile_client.h" | 44 #include "chromeos/dbus/shill_profile_client.h" |
46 #include "chromeos/dbus/shill_service_client.h" | 45 #include "chromeos/dbus/shill_service_client.h" |
47 #include "chromeos/dbus/sms_client.h" | 46 #include "chromeos/dbus/sms_client.h" |
48 #include "chromeos/dbus/system_clock_client.h" | 47 #include "chromeos/dbus/system_clock_client.h" |
49 #include "chromeos/dbus/update_engine_client.h" | 48 #include "chromeos/dbus/update_engine_client.h" |
50 #include "dbus/bus.h" | 49 #include "dbus/bus.h" |
51 #include "dbus/dbus_statistics.h" | 50 #include "dbus/dbus_statistics.h" |
52 | 51 |
53 namespace chromeos { | 52 namespace chromeos { |
54 | 53 |
55 static DBusThreadManager* g_dbus_thread_manager = NULL; | 54 static DBusThreadManager* g_dbus_thread_manager = NULL; |
56 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL; | 55 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL; |
hashimoto
2014/08/18 04:55:58
SetInstanceForTesting is removed.
Do we still need
zel
2014/08/18 23:41:52
Yes, it's still used for the exactly the same purp
| |
57 | 56 |
58 DBusClientBundle::DBusClientTypeMask | 57 DBusClientBundle::DBusClientTypeMask |
59 DBusThreadManager::unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; | 58 DBusThreadManager::unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; |
60 | 59 |
61 // The DBusThreadManager implementation used in production. | 60 // The DBusThreadManager implementation used in production. |
62 class DBusThreadManagerImpl : public DBusThreadManager { | 61 class DBusThreadManagerImpl : public DBusThreadManager { |
63 public: | 62 public: |
64 DBusThreadManagerImpl() { | 63 DBusThreadManagerImpl() { |
65 // Create the D-Bus thread. | 64 if (!DBusThreadManager::IsUsingStub(DBusClientBundle::ALL_CLIENTS)) { |
66 base::Thread::Options thread_options; | 65 // Create the D-Bus thread. |
67 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; | 66 base::Thread::Options thread_options; |
68 dbus_thread_.reset(new base::Thread("D-Bus thread")); | 67 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; |
69 dbus_thread_->StartWithOptions(thread_options); | 68 dbus_thread_.reset(new base::Thread("D-Bus thread")); |
69 dbus_thread_->StartWithOptions(thread_options); | |
70 | 70 |
71 // Create the connection to the system bus. | 71 // Create the connection to the system bus. |
72 dbus::Bus::Options system_bus_options; | 72 dbus::Bus::Options system_bus_options; |
73 system_bus_options.bus_type = dbus::Bus::SYSTEM; | 73 system_bus_options.bus_type = dbus::Bus::SYSTEM; |
74 system_bus_options.connection_type = dbus::Bus::PRIVATE; | 74 system_bus_options.connection_type = dbus::Bus::PRIVATE; |
75 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); | 75 system_bus_options.dbus_task_runner = dbus_thread_->message_loop_proxy(); |
76 system_bus_ = new dbus::Bus(system_bus_options); | 76 system_bus_ = new dbus::Bus(system_bus_options); |
77 } | |
77 | 78 |
78 CreateDefaultClients(); | 79 CreateDefaultClients(); |
79 } | 80 } |
80 | 81 |
81 virtual ~DBusThreadManagerImpl() { | 82 virtual ~DBusThreadManagerImpl() { |
82 // PowerPolicyController's destructor depends on PowerManagerClient. | 83 // PowerPolicyController's destructor depends on PowerManagerClient. |
83 power_policy_controller_.reset(); | 84 power_policy_controller_.reset(); |
84 | 85 |
85 // Delete all D-Bus clients before shutting down the system bus. | 86 // Delete all D-Bus clients before shutting down the system bus. |
86 client_bundle_.reset(); | 87 client_bundle_.reset(); |
87 | 88 |
88 // 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 |
89 // the bus synchronously. | 90 // the bus synchronously. |
90 system_bus_->ShutdownOnDBusThreadAndBlock(); | 91 if (system_bus_.get()) |
hashimoto
2014/08/18 04:55:58
nit: No need to have get().
zel
2014/08/18 23:41:52
Done.
| |
92 system_bus_->ShutdownOnDBusThreadAndBlock(); | |
91 | 93 |
92 // Stop the D-Bus thread. | 94 // Stop the D-Bus thread. |
93 dbus_thread_->Stop(); | 95 if (dbus_thread_.get()) |
hashimoto
2014/08/18 04:55:58
ditto.
zel
2014/08/18 23:41:52
Done.
| |
96 dbus_thread_->Stop(); | |
97 } | |
98 | |
99 static DBusThreadManagerImpl* CreateDBusThreadManager() { | |
100 DBusThreadManagerImpl* dbus_thread_manager = new DBusThreadManagerImpl(); | |
101 g_dbus_thread_manager = dbus_thread_manager; | |
102 dbus_thread_manager->InitializeClients(); | |
103 dbus_thread_manager->SetupDefaultEnvironment(); | |
104 return dbus_thread_manager; | |
94 } | 105 } |
95 | 106 |
96 void SetupDefaultEnvironment() { | 107 void SetupDefaultEnvironment() { |
108 // Skip if running in test environment without the message loop. | |
hashimoto
2014/08/18 04:55:58
Why do we need this?
Can't we add MessageLoop for
zel
2014/08/18 23:41:52
Done.
| |
109 if (!base::MessageLoop::current()) | |
110 return; | |
111 | |
97 return client_bundle_->SetupDefaultEnvironment(); | 112 return client_bundle_->SetupDefaultEnvironment(); |
98 } | 113 } |
99 | 114 |
100 virtual dbus::Bus* GetSystemBus() OVERRIDE { | 115 virtual dbus::Bus* GetSystemBus() OVERRIDE { |
101 return system_bus_.get(); | 116 return system_bus_.get(); |
102 } | 117 } |
103 | 118 |
104 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { | 119 virtual BluetoothAdapterClient* GetBluetoothAdapterClient() OVERRIDE { |
105 return client_bundle_->bluetooth_adapter_client(); | 120 return client_bundle_->bluetooth_adapter_client(); |
106 } | 121 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 | 257 |
243 virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE { | 258 virtual UpdateEngineClient* GetUpdateEngineClient() OVERRIDE { |
244 return client_bundle_->update_engine_client(); | 259 return client_bundle_->update_engine_client(); |
245 } | 260 } |
246 | 261 |
247 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { | 262 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { |
248 return power_policy_controller_.get(); | 263 return power_policy_controller_.get(); |
249 } | 264 } |
250 | 265 |
251 private: | 266 private: |
267 friend class DBusThreadManagerTestHelper; | |
252 // Constructs all clients and stores them in the respective *_client_ member | 268 // Constructs all clients and stores them in the respective *_client_ member |
253 // variable. | 269 // variable. |
254 void CreateDefaultClients() { | 270 void CreateDefaultClients() { |
255 client_bundle_.reset(new DBusClientBundle()); | 271 client_bundle_.reset(new DBusClientBundle()); |
256 // TODO(crbug.com/345586): Move PowerPolicyController out of | 272 // TODO(crbug.com/345586): Move PowerPolicyController out of |
257 // DBusThreadManagerImpl. | 273 // DBusThreadManagerImpl. |
258 power_policy_controller_.reset(new PowerPolicyController); | 274 power_policy_controller_.reset(new PowerPolicyController); |
259 } | 275 } |
260 | 276 |
277 // InitializeClients is called after g_dbus_thread_manager is set. | |
278 // NOTE: Clients that access other clients in their Init() must be | |
279 // initialized in the correct order. | |
280 void InitializeClients() { | |
281 InitClient(GetBluetoothAdapterClient()); | |
282 InitClient(GetBluetoothAgentManagerClient()); | |
283 InitClient(GetBluetoothDeviceClient()); | |
284 InitClient(GetBluetoothGattCharacteristicClient()); | |
285 InitClient(GetBluetoothGattDescriptorClient()); | |
286 InitClient(GetBluetoothGattManagerClient()); | |
287 InitClient(GetBluetoothGattServiceClient()); | |
288 InitClient(GetBluetoothInputClient()); | |
289 InitClient(GetBluetoothProfileManagerClient()); | |
290 InitClient(GetCrasAudioClient()); | |
291 InitClient(GetCrosDisksClient()); | |
292 InitClient(GetCryptohomeClient()); | |
293 InitClient(GetDebugDaemonClient()); | |
294 InitClient(GetEasyUnlockClient()); | |
295 InitClient(GetGsmSMSClient()); | |
296 InitClient(GetImageBurnerClient()); | |
297 InitClient(GetIntrospectableClient()); | |
298 InitClient(GetLorgnetteManagerClient()); | |
299 InitClient(GetModemMessagingClient()); | |
300 InitClient(GetPermissionBrokerClient()); | |
301 InitClient(GetPowerManagerClient()); | |
302 InitClient(GetSessionManagerClient()); | |
303 InitClient(GetShillDeviceClient()); | |
304 InitClient(GetShillIPConfigClient()); | |
305 InitClient(GetShillManagerClient()); | |
306 InitClient(GetShillServiceClient()); | |
307 InitClient(GetShillProfileClient()); | |
308 InitClient(GetSMSClient()); | |
309 InitClient(GetSystemClockClient()); | |
310 InitClient(GetUpdateEngineClient()); | |
311 | |
312 // Initialize the NFC clients in the correct order. The order of | |
313 // initialization matters due to dependencies that exist between the | |
314 // client objects. | |
315 InitClient(GetNfcManagerClient()); | |
316 InitClient(GetNfcAdapterClient()); | |
317 InitClient(GetNfcDeviceClient()); | |
318 InitClient(GetNfcTagClient()); | |
319 InitClient(GetNfcRecordClient()); | |
320 | |
321 // PowerPolicyController is dependent on PowerManagerClient, so | |
322 // initialize it after the main list of clients. | |
323 if (GetPowerPolicyController()) { | |
324 GetPowerPolicyController()->Init(this); | |
325 } | |
326 | |
327 // This must be called after the list of clients so they've each had a | |
328 // chance to register with their object g_dbus_thread_managers. | |
329 if (GetSystemBus()) | |
330 GetSystemBus()->GetManagedObjects(); | |
331 } | |
332 | |
333 // Initializes |client| with the |system_bus_|. | |
334 void InitClient(DBusClient* client) { | |
hashimoto
2014/08/18 04:55:58
When the client can be NULL?
Do we need this metho
zel
2014/08/18 23:41:52
Removed InitClient, kept DBusClient (that's a diff
| |
335 if (client) | |
336 client->Init(GetSystemBus()); | |
337 } | |
338 | |
261 scoped_ptr<base::Thread> dbus_thread_; | 339 scoped_ptr<base::Thread> dbus_thread_; |
262 scoped_refptr<dbus::Bus> system_bus_; | 340 scoped_refptr<dbus::Bus> system_bus_; |
263 scoped_ptr<DBusClientBundle> client_bundle_; | 341 scoped_ptr<DBusClientBundle> client_bundle_; |
264 scoped_ptr<PowerPolicyController> power_policy_controller_; | 342 scoped_ptr<PowerPolicyController> power_policy_controller_; |
265 | 343 |
266 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); | 344 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); |
267 }; | 345 }; |
268 | 346 |
269 // static | 347 // static |
270 bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { | 348 bool DBusThreadManager::IsUsingStub(DBusClientBundle::DBusClientType client) { |
271 return !(unstub_client_mask_ & client); | 349 return !(unstub_client_mask_ & client); |
272 } | 350 } |
273 | 351 |
274 // static | 352 // static |
275 void DBusThreadManager::Initialize() { | 353 void DBusThreadManager::Initialize() { |
276 // If we initialize DBusThreadManager twice we may also be shutting it down | 354 // If we initialize DBusThreadManager twice we may also be shutting it down |
277 // early; do not allow that. | 355 // early; do not allow that. |
356 if (g_dbus_thread_manager_for_testing) | |
357 return; | |
358 | |
278 CHECK(g_dbus_thread_manager == NULL); | 359 CHECK(g_dbus_thread_manager == NULL); |
279 | |
280 if (g_dbus_thread_manager_for_testing) { | |
281 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; | |
282 InitializeClients(); | |
283 VLOG(1) << "DBusThreadManager initialized with test implementation"; | |
284 return; | |
285 } | |
286 | |
287 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || | 360 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() || |
288 CommandLine::ForCurrentProcess()->HasSwitch( | 361 CommandLine::ForCurrentProcess()->HasSwitch( |
289 chromeos::switches::kDbusStub); | 362 chromeos::switches::kDbusStub); |
290 bool force_unstub_clients = CommandLine::ForCurrentProcess()->HasSwitch( | 363 bool force_unstub_clients = CommandLine::ForCurrentProcess()->HasSwitch( |
291 chromeos::switches::kDbusUnstubClients); | 364 chromeos::switches::kDbusUnstubClients); |
292 // Determine whether we use stub or real client implementations. | 365 // Determine whether we use stub or real client implementations. |
293 if (force_unstub_clients) { | 366 if (force_unstub_clients) { |
294 InitializeWithPartialStub( | 367 InitializeWithPartialStub( |
295 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 368 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
296 chromeos::switches::kDbusUnstubClients)); | 369 chromeos::switches::kDbusUnstubClients)); |
297 } else if (use_dbus_stub) { | 370 } else if (use_dbus_stub) { |
298 InitializeWithStub(); | 371 InitializeForTesting(); |
299 } else { | 372 } else { |
300 InitializeRegular(); | 373 InitializeRegular(); |
301 } | 374 } |
302 } | 375 } |
303 | 376 |
304 // static | 377 // static |
305 void DBusThreadManager::SetInstanceForTesting( | 378 scoped_ptr<DBusThreadManagerTestHelper> |
306 DBusThreadManager* dbus_thread_manager) { | 379 DBusThreadManager::InitializeForTesting() { |
307 CHECK(!g_dbus_thread_manager); | 380 CHECK(!g_dbus_thread_manager); |
308 CHECK(!g_dbus_thread_manager_for_testing); | 381 CHECK(!g_dbus_thread_manager_for_testing); |
309 g_dbus_thread_manager_for_testing = dbus_thread_manager; | 382 unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; |
383 VLOG(1) << "DBusThreadManager created for testing"; | |
384 DBusThreadManagerImpl* manager = | |
385 DBusThreadManagerImpl::CreateDBusThreadManager(); | |
386 g_dbus_thread_manager_for_testing = manager; | |
387 return make_scoped_ptr(new DBusThreadManagerTestHelper(manager)); | |
310 } | 388 } |
311 | 389 |
312 // static | 390 // static |
313 void DBusThreadManager::InitializeForTesting( | 391 void DBusThreadManager::InitializeWithStub() { |
314 DBusThreadManager* dbus_thread_manager) { | |
315 unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; | 392 unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; |
316 SetInstanceForTesting(dbus_thread_manager); | 393 DBusThreadManagerImpl::CreateDBusThreadManager(); |
317 Initialize(); | 394 VLOG(1) << "DBusThreadManager initialized with stub implementations"; |
318 } | 395 } |
319 | 396 |
320 // static | 397 // static |
321 void DBusThreadManager::InitializeRegular() { | 398 void DBusThreadManager::InitializeRegular() { |
322 unstub_client_mask_ = DBusClientBundle::ALL_CLIENTS; | 399 unstub_client_mask_ = DBusClientBundle::ALL_CLIENTS; |
323 g_dbus_thread_manager = new DBusThreadManagerImpl(); | 400 DBusThreadManagerImpl::CreateDBusThreadManager(); |
324 InitializeClients(); | |
325 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; | 401 VLOG(1) << "DBusThreadManager initialized for Chrome OS"; |
326 } | 402 } |
327 | 403 |
328 // static | 404 // static |
329 void DBusThreadManager::InitializeWithPartialStub( | 405 void DBusThreadManager::InitializeWithPartialStub( |
330 const std::string& unstub_clients) { | 406 const std::string& unstub_clients) { |
331 // If we initialize DBusThreadManager twice we may also be shutting it down | 407 // If we initialize DBusThreadManager twice we may also be shutting it down |
332 // early; do not allow that. | 408 // early; do not allow that. |
333 CHECK(g_dbus_thread_manager == NULL); | 409 CHECK(g_dbus_thread_manager == NULL); |
334 | 410 |
335 unstub_client_mask_ = DBusClientBundle::ParseUnstubList(unstub_clients); | 411 unstub_client_mask_ = DBusClientBundle::ParseUnstubList(unstub_clients); |
336 // We should have something parsed correctly here. | 412 // We should have something parsed correctly here. |
337 if (unstub_client_mask_ == 0) { | 413 if (unstub_client_mask_ == 0) { |
338 LOG(FATAL) << "Switch values for --" | 414 LOG(FATAL) << "Switch values for --" |
339 << chromeos::switches::kDbusUnstubClients | 415 << chromeos::switches::kDbusUnstubClients |
340 << " cannot be parsed: " | 416 << " cannot be parsed: " |
341 << unstub_clients; | 417 << unstub_clients; |
342 } | 418 } |
343 DBusThreadManagerImpl* dbus_thread_manager = new DBusThreadManagerImpl(); | |
344 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; | 419 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment"; |
345 g_dbus_thread_manager = dbus_thread_manager; | 420 DBusThreadManagerImpl::CreateDBusThreadManager(); |
346 InitializeClients(); | |
347 dbus_thread_manager->SetupDefaultEnvironment(); | |
348 } | 421 } |
349 | 422 |
350 // static | 423 // static |
351 void DBusThreadManager::InitializeWithStub() { | |
352 unstub_client_mask_ = DBusClientBundle::NO_CLIENTS; | |
353 // If we initialize DBusThreadManager twice we may also be shutting it down | |
354 // early; do not allow that. | |
355 CHECK(g_dbus_thread_manager == NULL); | |
356 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; | |
357 fake_dbus_thread_manager->SetFakeClients(); | |
358 g_dbus_thread_manager = fake_dbus_thread_manager; | |
359 InitializeClients(); | |
360 fake_dbus_thread_manager->SetupDefaultEnvironment(); | |
361 VLOG(1) << "DBusThreadManager initialized with stub implementation"; | |
362 } | |
363 | |
364 // static | |
365 bool DBusThreadManager::IsInitialized() { | 424 bool DBusThreadManager::IsInitialized() { |
366 return g_dbus_thread_manager != NULL; | 425 return g_dbus_thread_manager != NULL; |
367 } | 426 } |
368 | 427 |
369 // static | 428 // static |
370 void DBusThreadManager::Shutdown() { | 429 void DBusThreadManager::Shutdown() { |
371 // If we called InitializeForTesting, this may get called more than once. | 430 // If we called InitializeForTesting, this may get called more than once. |
372 // Ensure that we only shutdown DBusThreadManager once. | 431 // Ensure that we only shutdown DBusThreadManager once. |
373 CHECK(g_dbus_thread_manager || g_dbus_thread_manager_for_testing); | 432 CHECK(g_dbus_thread_manager); |
374 DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager; | 433 DBusThreadManager* dbus_thread_manager = g_dbus_thread_manager; |
375 g_dbus_thread_manager = NULL; | 434 g_dbus_thread_manager = NULL; |
376 g_dbus_thread_manager_for_testing = NULL; | 435 g_dbus_thread_manager_for_testing = NULL; |
377 delete dbus_thread_manager; | 436 delete dbus_thread_manager; |
378 VLOG(1) << "DBusThreadManager Shutdown completed"; | 437 VLOG(1) << "DBusThreadManager Shutdown completed"; |
379 } | 438 } |
380 | 439 |
381 DBusThreadManager::DBusThreadManager() { | 440 DBusThreadManager::DBusThreadManager() { |
382 dbus::statistics::Initialize(); | 441 dbus::statistics::Initialize(); |
383 } | 442 } |
(...skipping 13 matching lines...) Expand all Loading... | |
397 } | 456 } |
398 } | 457 } |
399 | 458 |
400 // static | 459 // static |
401 DBusThreadManager* DBusThreadManager::Get() { | 460 DBusThreadManager* DBusThreadManager::Get() { |
402 CHECK(g_dbus_thread_manager) | 461 CHECK(g_dbus_thread_manager) |
403 << "DBusThreadManager::Get() called before Initialize()"; | 462 << "DBusThreadManager::Get() called before Initialize()"; |
404 return g_dbus_thread_manager; | 463 return g_dbus_thread_manager; |
405 } | 464 } |
406 | 465 |
407 // static | 466 DBusThreadManagerTestHelper::DBusThreadManagerTestHelper( |
408 void DBusThreadManager::InitializeClients() { | 467 DBusThreadManagerImpl* dbus_thread_manager) |
409 InitClient(g_dbus_thread_manager->GetBluetoothAdapterClient()); | 468 : dbus_thread_manager_(dbus_thread_manager) { |
410 InitClient(g_dbus_thread_manager->GetBluetoothAgentManagerClient()); | 469 } |
411 InitClient(g_dbus_thread_manager->GetBluetoothDeviceClient()); | 470 |
412 InitClient(g_dbus_thread_manager->GetBluetoothGattCharacteristicClient()); | 471 DBusThreadManagerTestHelper::~DBusThreadManagerTestHelper() { |
413 InitClient(g_dbus_thread_manager->GetBluetoothGattDescriptorClient()); | 472 } |
414 InitClient(g_dbus_thread_manager->GetBluetoothGattManagerClient()); | 473 |
415 InitClient(g_dbus_thread_manager->GetBluetoothGattServiceClient()); | 474 void DBusThreadManagerTestHelper::SetBluetoothAdapterClient( |
416 InitClient(g_dbus_thread_manager->GetBluetoothInputClient()); | 475 scoped_ptr<BluetoothAdapterClient> client) { |
417 InitClient(g_dbus_thread_manager->GetBluetoothProfileManagerClient()); | 476 dbus_thread_manager_->client_bundle_->bluetooth_adapter_client_ = |
418 InitClient(g_dbus_thread_manager->GetCrasAudioClient()); | 477 client.Pass(); |
419 InitClient(g_dbus_thread_manager->GetCrosDisksClient()); | 478 } |
420 InitClient(g_dbus_thread_manager->GetCryptohomeClient()); | 479 |
421 InitClient(g_dbus_thread_manager->GetDebugDaemonClient()); | 480 void DBusThreadManagerTestHelper::SetBluetoothAgentManagerClient( |
422 InitClient(g_dbus_thread_manager->GetEasyUnlockClient()); | 481 scoped_ptr<BluetoothAgentManagerClient> client) { |
423 InitClient(g_dbus_thread_manager->GetGsmSMSClient()); | 482 dbus_thread_manager_->client_bundle_->bluetooth_agent_manager_client_ = |
424 InitClient(g_dbus_thread_manager->GetImageBurnerClient()); | 483 client.Pass(); |
425 InitClient(g_dbus_thread_manager->GetIntrospectableClient()); | 484 } |
426 InitClient(g_dbus_thread_manager->GetLorgnetteManagerClient()); | 485 |
427 InitClient(g_dbus_thread_manager->GetModemMessagingClient()); | 486 void DBusThreadManagerTestHelper::SetBluetoothDeviceClient( |
428 InitClient(g_dbus_thread_manager->GetPermissionBrokerClient()); | 487 scoped_ptr<BluetoothDeviceClient> client) { |
429 InitClient(g_dbus_thread_manager->GetPowerManagerClient()); | 488 dbus_thread_manager_->client_bundle_->bluetooth_device_client_ = |
430 InitClient(g_dbus_thread_manager->GetSessionManagerClient()); | 489 client.Pass(); |
431 InitClient(g_dbus_thread_manager->GetShillDeviceClient()); | 490 } |
432 InitClient(g_dbus_thread_manager->GetShillIPConfigClient()); | 491 |
433 InitClient(g_dbus_thread_manager->GetShillManagerClient()); | 492 void DBusThreadManagerTestHelper::SetBluetoothGattCharacteristicClient( |
434 InitClient(g_dbus_thread_manager->GetShillServiceClient()); | 493 scoped_ptr<BluetoothGattCharacteristicClient> client) { |
435 InitClient(g_dbus_thread_manager->GetShillProfileClient()); | 494 dbus_thread_manager_->client_bundle_->bluetooth_gatt_characteristic_client_ = |
436 InitClient(g_dbus_thread_manager->GetSMSClient()); | 495 client.Pass(); |
437 InitClient(g_dbus_thread_manager->GetSystemClockClient()); | 496 } |
438 InitClient(g_dbus_thread_manager->GetUpdateEngineClient()); | 497 |
439 | 498 void DBusThreadManagerTestHelper::SetBluetoothGattDescriptorClient( |
440 // Initialize the NFC clients in the correct order. The order of | 499 scoped_ptr<BluetoothGattDescriptorClient> client) { |
441 // initialization matters due to dependencies that exist between the | 500 dbus_thread_manager_->client_bundle_->bluetooth_gatt_descriptor_client_ = |
442 // client objects. | 501 client.Pass(); |
443 InitClient(g_dbus_thread_manager->GetNfcManagerClient()); | 502 } |
444 InitClient(g_dbus_thread_manager->GetNfcAdapterClient()); | 503 |
445 InitClient(g_dbus_thread_manager->GetNfcDeviceClient()); | 504 void DBusThreadManagerTestHelper::SetBluetoothGattManagerClient( |
446 InitClient(g_dbus_thread_manager->GetNfcTagClient()); | 505 scoped_ptr<BluetoothGattManagerClient> client) { |
447 InitClient(g_dbus_thread_manager->GetNfcRecordClient()); | 506 dbus_thread_manager_->client_bundle_->bluetooth_gatt_manager_client_ = |
448 | 507 client.Pass(); |
449 // PowerPolicyController is dependent on PowerManagerClient, so | 508 } |
450 // initialize it after the main list of clients. | 509 |
451 if (g_dbus_thread_manager->GetPowerPolicyController()) { | 510 void DBusThreadManagerTestHelper::SetBluetoothGattServiceClient( |
452 g_dbus_thread_manager->GetPowerPolicyController()->Init( | 511 scoped_ptr<BluetoothGattServiceClient> client) { |
453 g_dbus_thread_manager); | 512 dbus_thread_manager_->client_bundle_->bluetooth_gatt_service_client_ = |
454 } | 513 client.Pass(); |
455 | 514 } |
456 // This must be called after the list of clients so they've each had a | 515 |
457 // chance to register with their object g_dbus_thread_managers. | 516 void DBusThreadManagerTestHelper::SetBluetoothInputClient( |
458 if (g_dbus_thread_manager->GetSystemBus()) | 517 scoped_ptr<BluetoothInputClient> client) { |
459 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); | 518 dbus_thread_manager_->client_bundle_->bluetooth_input_client_ = client.Pass(); |
460 } | 519 } |
461 | 520 |
462 // static | 521 void DBusThreadManagerTestHelper::SetBluetoothProfileManagerClient( |
463 void DBusThreadManager::InitClient(DBusClient* client) { | 522 scoped_ptr<BluetoothProfileManagerClient> client) { |
464 if (client) | 523 dbus_thread_manager_->client_bundle_->bluetooth_profile_manager_client_ = |
465 client->Init(g_dbus_thread_manager->GetSystemBus()); | 524 client.Pass(); |
525 } | |
526 | |
527 void DBusThreadManagerTestHelper::SetCrasAudioClient( | |
528 scoped_ptr<CrasAudioClient> client) { | |
529 dbus_thread_manager_->client_bundle_->cras_audio_client_ = client.Pass(); | |
530 } | |
531 | |
532 void DBusThreadManagerTestHelper::SetCrosDisksClient( | |
533 scoped_ptr<CrosDisksClient> client) { | |
534 dbus_thread_manager_->client_bundle_->cros_disks_client_ = client.Pass(); | |
535 } | |
536 | |
537 void DBusThreadManagerTestHelper::SetCryptohomeClient( | |
538 scoped_ptr<CryptohomeClient> client) { | |
539 dbus_thread_manager_->client_bundle_->cryptohome_client_ = client.Pass(); | |
540 } | |
541 | |
542 void DBusThreadManagerTestHelper::SetDebugDaemonClient( | |
543 scoped_ptr<DebugDaemonClient> client) { | |
544 dbus_thread_manager_->client_bundle_->debug_daemon_client_ = client.Pass(); | |
545 } | |
546 | |
547 void DBusThreadManagerTestHelper::SetEasyUnlockClient( | |
548 scoped_ptr<EasyUnlockClient> client) { | |
549 dbus_thread_manager_->client_bundle_->easy_unlock_client_ = client.Pass(); | |
550 } | |
551 | |
552 void DBusThreadManagerTestHelper::SetLorgnetteManagerClient( | |
553 scoped_ptr<LorgnetteManagerClient> client) { | |
554 dbus_thread_manager_->client_bundle_->lorgnette_manager_client_ = | |
555 client.Pass(); | |
556 } | |
557 | |
558 void DBusThreadManagerTestHelper::SetShillDeviceClient( | |
559 scoped_ptr<ShillDeviceClient> client) { | |
560 dbus_thread_manager_->client_bundle_->shill_device_client_ = client.Pass(); | |
561 } | |
562 | |
563 void DBusThreadManagerTestHelper::SetShillIPConfigClient( | |
564 scoped_ptr<ShillIPConfigClient> client) { | |
565 dbus_thread_manager_->client_bundle_->shill_ipconfig_client_ = client.Pass(); | |
566 } | |
567 | |
568 void DBusThreadManagerTestHelper::SetShillManagerClient( | |
569 scoped_ptr<ShillManagerClient> client) { | |
570 dbus_thread_manager_->client_bundle_->shill_manager_client_ = client.Pass(); | |
571 } | |
572 | |
573 void DBusThreadManagerTestHelper::SetShillServiceClient( | |
574 scoped_ptr<ShillServiceClient> client) { | |
575 dbus_thread_manager_->client_bundle_->shill_service_client_ = client.Pass(); | |
576 } | |
577 | |
578 void DBusThreadManagerTestHelper::SetShillProfileClient( | |
579 scoped_ptr<ShillProfileClient> client) { | |
580 dbus_thread_manager_->client_bundle_->shill_profile_client_ = client.Pass(); | |
581 } | |
582 | |
583 void DBusThreadManagerTestHelper::SetGsmSMSClient( | |
584 scoped_ptr<GsmSMSClient> client) { | |
585 dbus_thread_manager_->client_bundle_->gsm_sms_client_ = client.Pass(); | |
586 } | |
587 | |
588 void DBusThreadManagerTestHelper::SetImageBurnerClient( | |
589 scoped_ptr<ImageBurnerClient> client) { | |
590 dbus_thread_manager_->client_bundle_->image_burner_client_ = client.Pass(); | |
591 } | |
592 | |
593 void DBusThreadManagerTestHelper::SetIntrospectableClient( | |
594 scoped_ptr<IntrospectableClient> client) { | |
595 dbus_thread_manager_->client_bundle_->introspectable_client_ = client.Pass(); | |
596 } | |
597 | |
598 void DBusThreadManagerTestHelper::SetModemMessagingClient( | |
599 scoped_ptr<ModemMessagingClient> client) { | |
600 dbus_thread_manager_->client_bundle_->modem_messaging_client_ = client.Pass(); | |
601 } | |
602 | |
603 void DBusThreadManagerTestHelper::SetNfcAdapterClient( | |
604 scoped_ptr<NfcAdapterClient> client) { | |
605 dbus_thread_manager_->client_bundle_->nfc_adapter_client_ = client.Pass(); | |
606 } | |
607 | |
608 void DBusThreadManagerTestHelper::SetNfcDeviceClient( | |
609 scoped_ptr<NfcDeviceClient> client) { | |
610 dbus_thread_manager_->client_bundle_->nfc_device_client_ = client.Pass(); | |
611 } | |
612 | |
613 void DBusThreadManagerTestHelper::SetNfcManagerClient( | |
614 scoped_ptr<NfcManagerClient> client) { | |
615 dbus_thread_manager_->client_bundle_->nfc_manager_client_ = client.Pass(); | |
616 } | |
617 | |
618 void DBusThreadManagerTestHelper::SetNfcRecordClient( | |
619 scoped_ptr<NfcRecordClient> client) { | |
620 dbus_thread_manager_->client_bundle_->nfc_record_client_ = client.Pass(); | |
621 } | |
622 | |
623 void DBusThreadManagerTestHelper::SetNfcTagClient( | |
624 scoped_ptr<NfcTagClient> client) { | |
625 dbus_thread_manager_->client_bundle_->nfc_tag_client_ = client.Pass(); | |
626 } | |
627 | |
628 void DBusThreadManagerTestHelper::SetPermissionBrokerClient( | |
629 scoped_ptr<PermissionBrokerClient> client) { | |
630 dbus_thread_manager_->client_bundle_->permission_broker_client_ = | |
631 client.Pass(); | |
632 } | |
633 | |
634 void DBusThreadManagerTestHelper::SetPowerManagerClient( | |
635 scoped_ptr<PowerManagerClient> client) { | |
636 dbus_thread_manager_->power_policy_controller_.reset(); | |
637 dbus_thread_manager_->client_bundle_->power_manager_client_ = client.Pass(); | |
638 dbus_thread_manager_->power_policy_controller_.reset( | |
639 new PowerPolicyController); | |
640 dbus_thread_manager_->power_policy_controller_->Init(dbus_thread_manager_); | |
641 } | |
642 | |
643 void DBusThreadManagerTestHelper::SetPowerPolicyController( | |
644 scoped_ptr<PowerPolicyController> client) { | |
645 dbus_thread_manager_->power_policy_controller_ = client.Pass(); | |
646 } | |
647 | |
648 void DBusThreadManagerTestHelper::SetSessionManagerClient( | |
649 scoped_ptr<SessionManagerClient> client) { | |
650 dbus_thread_manager_->client_bundle_->session_manager_client_ = client.Pass(); | |
651 } | |
652 | |
653 void DBusThreadManagerTestHelper::SetSMSClient(scoped_ptr<SMSClient> client) { | |
654 dbus_thread_manager_->client_bundle_->sms_client_ = client.Pass(); | |
655 } | |
656 | |
657 void DBusThreadManagerTestHelper::SetSystemClockClient( | |
658 scoped_ptr<SystemClockClient> client) { | |
659 dbus_thread_manager_->client_bundle_->system_clock_client_ = client.Pass(); | |
660 } | |
661 | |
662 void DBusThreadManagerTestHelper::SetUpdateEngineClient( | |
663 scoped_ptr<UpdateEngineClient> client) { | |
664 dbus_thread_manager_->client_bundle_->update_engine_client_ = client.Pass(); | |
466 } | 665 } |
467 | 666 |
468 } // namespace chromeos | 667 } // namespace chromeos |
OLD | NEW |