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