Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: chromeos/dbus/dbus_thread_manager.cc

Issue 444263002: Added switch that let us 'un-stub' certain dbus clients. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/strings/string_split.h"
10 #include "base/strings/string_util.h"
9 #include "base/sys_info.h" 11 #include "base/sys_info.h"
10 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
11 #include "chromeos/chromeos_switches.h" 13 #include "chromeos/chromeos_switches.h"
12 #include "chromeos/dbus/bluetooth_adapter_client.h" 14 #include "chromeos/dbus/bluetooth_adapter_client.h"
13 #include "chromeos/dbus/bluetooth_agent_manager_client.h" 15 #include "chromeos/dbus/bluetooth_agent_manager_client.h"
14 #include "chromeos/dbus/bluetooth_device_client.h" 16 #include "chromeos/dbus/bluetooth_device_client.h"
15 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" 17 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
16 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" 18 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
17 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" 19 #include "chromeos/dbus/bluetooth_gatt_manager_client.h"
18 #include "chromeos/dbus/bluetooth_gatt_service_client.h" 20 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
19 #include "chromeos/dbus/bluetooth_input_client.h" 21 #include "chromeos/dbus/bluetooth_input_client.h"
20 #include "chromeos/dbus/bluetooth_profile_manager_client.h" 22 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
21 #include "chromeos/dbus/cras_audio_client.h" 23 #include "chromeos/dbus/cras_audio_client.h"
22 #include "chromeos/dbus/cros_disks_client.h" 24 #include "chromeos/dbus/cros_disks_client.h"
23 #include "chromeos/dbus/cryptohome_client.h" 25 #include "chromeos/dbus/cryptohome_client.h"
24 #include "chromeos/dbus/dbus_client.h" 26 #include "chromeos/dbus/dbus_client.h"
27 #include "chromeos/dbus/dbus_client_bundle.h"
25 #include "chromeos/dbus/dbus_thread_manager_observer.h" 28 #include "chromeos/dbus/dbus_thread_manager_observer.h"
26 #include "chromeos/dbus/debug_daemon_client.h" 29 #include "chromeos/dbus/debug_daemon_client.h"
27 #include "chromeos/dbus/easy_unlock_client.h" 30 #include "chromeos/dbus/easy_unlock_client.h"
28 #include "chromeos/dbus/fake_dbus_thread_manager.h" 31 #include "chromeos/dbus/fake_dbus_thread_manager.h"
29 #include "chromeos/dbus/gsm_sms_client.h" 32 #include "chromeos/dbus/gsm_sms_client.h"
30 #include "chromeos/dbus/image_burner_client.h" 33 #include "chromeos/dbus/image_burner_client.h"
31 #include "chromeos/dbus/introspectable_client.h" 34 #include "chromeos/dbus/introspectable_client.h"
32 #include "chromeos/dbus/lorgnette_manager_client.h" 35 #include "chromeos/dbus/lorgnette_manager_client.h"
36 #include "chromeos/dbus/mixed_dbus_thread_manager.h"
33 #include "chromeos/dbus/modem_messaging_client.h" 37 #include "chromeos/dbus/modem_messaging_client.h"
34 #include "chromeos/dbus/nfc_adapter_client.h" 38 #include "chromeos/dbus/nfc_adapter_client.h"
35 #include "chromeos/dbus/nfc_device_client.h" 39 #include "chromeos/dbus/nfc_device_client.h"
36 #include "chromeos/dbus/nfc_manager_client.h" 40 #include "chromeos/dbus/nfc_manager_client.h"
37 #include "chromeos/dbus/nfc_record_client.h" 41 #include "chromeos/dbus/nfc_record_client.h"
38 #include "chromeos/dbus/nfc_tag_client.h" 42 #include "chromeos/dbus/nfc_tag_client.h"
39 #include "chromeos/dbus/permission_broker_client.h" 43 #include "chromeos/dbus/permission_broker_client.h"
40 #include "chromeos/dbus/power_manager_client.h" 44 #include "chromeos/dbus/power_manager_client.h"
41 #include "chromeos/dbus/power_policy_controller.h" 45 #include "chromeos/dbus/power_policy_controller.h"
42 #include "chromeos/dbus/session_manager_client.h" 46 #include "chromeos/dbus/session_manager_client.h"
43 #include "chromeos/dbus/shill_device_client.h" 47 #include "chromeos/dbus/shill_device_client.h"
44 #include "chromeos/dbus/shill_ipconfig_client.h" 48 #include "chromeos/dbus/shill_ipconfig_client.h"
45 #include "chromeos/dbus/shill_manager_client.h" 49 #include "chromeos/dbus/shill_manager_client.h"
46 #include "chromeos/dbus/shill_profile_client.h" 50 #include "chromeos/dbus/shill_profile_client.h"
47 #include "chromeos/dbus/shill_service_client.h" 51 #include "chromeos/dbus/shill_service_client.h"
48 #include "chromeos/dbus/sms_client.h" 52 #include "chromeos/dbus/sms_client.h"
49 #include "chromeos/dbus/system_clock_client.h" 53 #include "chromeos/dbus/system_clock_client.h"
50 #include "chromeos/dbus/update_engine_client.h" 54 #include "chromeos/dbus/update_engine_client.h"
51 #include "dbus/bus.h" 55 #include "dbus/bus.h"
52 #include "dbus/dbus_statistics.h" 56 #include "dbus/dbus_statistics.h"
53 57
54 namespace chromeos { 58 namespace chromeos {
55 59
56 static DBusThreadManager* g_dbus_thread_manager = NULL; 60 static DBusThreadManager* g_dbus_thread_manager = NULL;
57 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL; 61 static DBusThreadManager* g_dbus_thread_manager_for_testing = NULL;
58 62
59 // The bundle of all D-Bus clients used in DBusThreadManagerImpl. The bundle 63 namespace {
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 64
67 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); 65 // Command line switch mapping for --dbus-unstub-clients.
68 bluetooth_agent_manager_client_.reset( 66 struct {
69 BluetoothAgentManagerClient::Create()); 67 const char* param_name;
70 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); 68 DBusClientBundle::DBusClientType client_type;
71 bluetooth_gatt_characteristic_client_.reset( 69 } client_type_map[] = {
72 BluetoothGattCharacteristicClient::Create()); 70 { "bluetooth", DBusClientBundle::BLUETOOTH },
73 bluetooth_gatt_descriptor_client_.reset( 71 { "bluetoothlowenergy", DBusClientBundle::BLUETOOTH_LOW_ENERGY },
74 BluetoothGattDescriptorClient::Create()); 72 { "cras", DBusClientBundle::CRAS },
75 bluetooth_gatt_manager_client_.reset(BluetoothGattManagerClient::Create()); 73 { "crosdisks", DBusClientBundle::CROS_DISKS },
76 bluetooth_gatt_service_client_.reset(BluetoothGattServiceClient::Create()); 74 { "cryptohome", DBusClientBundle::CRYPTOHOME },
77 bluetooth_input_client_.reset(BluetoothInputClient::Create()); 75 { "debugdaemon", DBusClientBundle::DEBUG_DAEMON },
78 bluetooth_profile_manager_client_.reset( 76 { "easyunlock", DBusClientBundle::EASY_UNLOCK },
79 BluetoothProfileManagerClient::Create()); 77 { "lorgnettemanager", DBusClientBundle::LORGNETTE_MANAGER },
80 cras_audio_client_.reset(CrasAudioClient::Create()); 78 { "shill", DBusClientBundle::SHILL },
81 cros_disks_client_.reset(CrosDisksClient::Create(type)); 79 { "gsmsms", DBusClientBundle::GSM_SMS },
82 cryptohome_client_.reset(CryptohomeClient::Create()); 80 { "imageburner", DBusClientBundle::IMAGE_BURNER },
83 debug_daemon_client_.reset(DebugDaemonClient::Create()); 81 { "introspectable", DBusClientBundle::INTROSPECTABLE },
84 easy_unlock_client_.reset(EasyUnlockClient::Create()); 82 { "modemmessaging", DBusClientBundle::MODEM_MESSAGING },
85 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); 83 { "nfc", DBusClientBundle::NFC },
86 shill_manager_client_.reset(ShillManagerClient::Create()); 84 { "permissionbroker", DBusClientBundle::PERMISSION_BROKER },
87 shill_device_client_.reset(ShillDeviceClient::Create()); 85 { "powermanager", DBusClientBundle::POWER_MANAGER },
88 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); 86 { "powerpolicy", DBusClientBundle::POWER_POLICY },
89 shill_service_client_.reset(ShillServiceClient::Create()); 87 { "sessionmanager", DBusClientBundle::SESSION_MANAGER },
90 shill_profile_client_.reset(ShillProfileClient::Create()); 88 { "sms", DBusClientBundle::SMS },
91 gsm_sms_client_.reset(GsmSMSClient::Create()); 89 { "systemclock", DBusClientBundle::SYSTEM_CLOCK },
92 image_burner_client_.reset(ImageBurnerClient::Create()); 90 { "updateengine", DBusClientBundle::UPDATE_ENGINE },
93 introspectable_client_.reset(IntrospectableClient::Create()); 91 };
94 modem_messaging_client_.reset(ModemMessagingClient::Create()); 92
95 // Create the NFC clients in the correct order based on their dependencies. 93 // Parses single command line param value for dbus subsystem and returns its
96 nfc_manager_client_.reset(NfcManagerClient::Create()); 94 // enum representation. DBusClientType::UNKWNOWN is returned if |client_type|
97 nfc_adapter_client_.reset( 95 // does not match any known dbus client.
98 NfcAdapterClient::Create(nfc_manager_client_.get())); 96 DBusClientBundle::DBusClientType GetDBusClientType(
99 nfc_device_client_.reset( 97 const std::string& client_type) {
100 NfcDeviceClient::Create(nfc_adapter_client_.get())); 98 for (size_t i = 0; i < arraysize(client_type_map); i++) {
101 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); 99 if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name))
102 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), 100 return client_type_map[i].client_type;
103 nfc_tag_client_.get())); 101 }
104 permission_broker_client_.reset(PermissionBrokerClient::Create()); 102 return DBusClientBundle::UNKNOWN;
105 power_manager_client_.reset(PowerManagerClient::Create(type)); 103 }
106 session_manager_client_.reset(SessionManagerClient::Create(type)); 104
107 sms_client_.reset(SMSClient::Create()); 105 // Parses command line param values for dbus subsystem that should be
108 system_clock_client_.reset(SystemClockClient::Create()); 106 // un-stubbed.
109 update_engine_client_.reset(UpdateEngineClient::Create(type)); 107 int ParseUnstubList(const std::string& unstub_list) {
108 int unstub_mask = 0;
109 std::vector<std::string> unstub_components;
110 base::SplitString(unstub_list, ',', &unstub_components);
111 for (std::vector<std::string>::const_iterator iter =
112 unstub_components.begin();
113 iter != unstub_components.end(); ++iter) {
114 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter);
115 if (client != DBusClientBundle::UNKNOWN) {
116 LOG(WARNING) << "Unstubbing dbus client for " << *iter;
117 unstub_mask |= client;
118 }
110 } 119 }
111 120
112 BluetoothAdapterClient* bluetooth_adapter_client() { 121 return unstub_mask;
113 return bluetooth_adapter_client_.get(); 122 }
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 123
218 private: 124 } // namespace
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 125
261 // The DBusThreadManager implementation used in production. 126 // The DBusThreadManager implementation used in production.
262 class DBusThreadManagerImpl : public DBusThreadManager { 127 class DBusThreadManagerImpl : public DBusThreadManager {
263 public: 128 public:
264 DBusThreadManagerImpl() { 129 explicit DBusThreadManagerImpl(int client_mask) : client_mask_(client_mask) {
265 // Create the D-Bus thread. 130 // Create the D-Bus thread.
266 base::Thread::Options thread_options; 131 base::Thread::Options thread_options;
267 thread_options.message_loop_type = base::MessageLoop::TYPE_IO; 132 thread_options.message_loop_type = base::MessageLoop::TYPE_IO;
268 dbus_thread_.reset(new base::Thread("D-Bus thread")); 133 dbus_thread_.reset(new base::Thread("D-Bus thread"));
269 dbus_thread_->StartWithOptions(thread_options); 134 dbus_thread_->StartWithOptions(thread_options);
270 135
271 // Create the connection to the system bus. 136 // Create the connection to the system bus.
272 dbus::Bus::Options system_bus_options; 137 dbus::Bus::Options system_bus_options;
273 system_bus_options.bus_type = dbus::Bus::SYSTEM; 138 system_bus_options.bus_type = dbus::Bus::SYSTEM;
274 system_bus_options.connection_type = dbus::Bus::PRIVATE; 139 system_bus_options.connection_type = dbus::Bus::PRIVATE;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 } 320 }
456 321
457 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE { 322 virtual PowerPolicyController* GetPowerPolicyController() OVERRIDE {
458 return power_policy_controller_.get(); 323 return power_policy_controller_.get();
459 } 324 }
460 325
461 private: 326 private:
462 // Constructs all clients and stores them in the respective *_client_ member 327 // Constructs all clients and stores them in the respective *_client_ member
463 // variable. 328 // variable.
464 void CreateDefaultClients() { 329 void CreateDefaultClients() {
465 client_bundle_.reset(new DBusClientBundle); 330 client_bundle_.reset(new DBusClientBundle(client_mask_));
466 power_policy_controller_.reset(new PowerPolicyController); 331 if (client_mask_ & DBusClientBundle::POWER_POLICY)
332 power_policy_controller_.reset(new PowerPolicyController);
467 } 333 }
468 334
469 // Note: Keep this before other members so they can call AddObserver() in 335 // Note: Keep this before other members so they can call AddObserver() in
470 // their c'tors. 336 // their c'tors.
471 ObserverList<DBusThreadManagerObserver> observers_; 337 ObserverList<DBusThreadManagerObserver> observers_;
472 338
473 scoped_ptr<base::Thread> dbus_thread_; 339 scoped_ptr<base::Thread> dbus_thread_;
474 scoped_refptr<dbus::Bus> system_bus_; 340 scoped_refptr<dbus::Bus> system_bus_;
475 scoped_ptr<DBusClientBundle> client_bundle_; 341 scoped_ptr<DBusClientBundle> client_bundle_;
476 scoped_ptr<PowerPolicyController> power_policy_controller_; 342 scoped_ptr<PowerPolicyController> power_policy_controller_;
343 int client_mask_;
477 344
478 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl); 345 DISALLOW_COPY_AND_ASSIGN(DBusThreadManagerImpl);
479 }; 346 };
480 347
348
481 // static 349 // static
482 void DBusThreadManager::Initialize() { 350 void DBusThreadManager::Initialize() {
483 // If we initialize DBusThreadManager twice we may also be shutting it down 351 // If we initialize DBusThreadManager twice we may also be shutting it down
484 // early; do not allow that. 352 // early; do not allow that.
485 CHECK(g_dbus_thread_manager == NULL); 353 CHECK(g_dbus_thread_manager == NULL);
486 354
487 if (g_dbus_thread_manager_for_testing) { 355 if (g_dbus_thread_manager_for_testing) {
488 g_dbus_thread_manager = g_dbus_thread_manager_for_testing; 356 g_dbus_thread_manager = g_dbus_thread_manager_for_testing;
489 InitializeClients(); 357 InitializeClients();
490 VLOG(1) << "DBusThreadManager initialized with test implementation"; 358 VLOG(1) << "DBusThreadManager initialized with test implementation";
491 return; 359 return;
492 } 360 }
493 361
362 bool use_dbus_stub = !base::SysInfo::IsRunningOnChromeOS() ||
363 CommandLine::ForCurrentProcess()->HasSwitch(
364 chromeos::switches::kDbusStub);
365 bool force_unstub_clients = CommandLine::ForCurrentProcess()->HasSwitch(
366 chromeos::switches::kDbusUnstubClients);
494 // Determine whether we use stub or real client implementations. 367 // Determine whether we use stub or real client implementations.
495 if (!base::SysInfo::IsRunningOnChromeOS() || 368 if (force_unstub_clients) {
496 CommandLine::ForCurrentProcess()->HasSwitch( 369 InitializeThreadManagerWithPartialStub(
497 chromeos::switches::kDbusStub)) { 370 CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
498 InitializeWithStub(); 371 chromeos::switches::kDbusUnstubClients));
372 } else if (use_dbus_stub) {
373 InitializeThreadManagerWithStub();
499 } else { 374 } else {
500 g_dbus_thread_manager = new DBusThreadManagerImpl; 375 InitializeThreadManager();
501 InitializeClients();
502 VLOG(1) << "DBusThreadManager initialized for Chrome OS";
503 } 376 }
504 } 377 }
505 378
506 // static 379 // static
507 void DBusThreadManager::SetInstanceForTesting( 380 void DBusThreadManager::SetInstanceForTesting(
508 DBusThreadManager* dbus_thread_manager) { 381 DBusThreadManager* dbus_thread_manager) {
509 CHECK(!g_dbus_thread_manager); 382 CHECK(!g_dbus_thread_manager);
510 CHECK(!g_dbus_thread_manager_for_testing); 383 CHECK(!g_dbus_thread_manager_for_testing);
511 g_dbus_thread_manager_for_testing = dbus_thread_manager; 384 g_dbus_thread_manager_for_testing = dbus_thread_manager;
512 } 385 }
513 386
514 // static 387 // static
515 void DBusThreadManager::InitializeForTesting( 388 void DBusThreadManager::InitializeForTesting(
516 DBusThreadManager* dbus_thread_manager) { 389 DBusThreadManager* dbus_thread_manager) {
517 SetInstanceForTesting(dbus_thread_manager); 390 SetInstanceForTesting(dbus_thread_manager);
518 Initialize(); 391 Initialize();
519 } 392 }
520 393
521 // static 394 // static
522 void DBusThreadManager::InitializeWithStub() { 395 void DBusThreadManager::InitializeThreadManagerWithPartialStub(
396 const std::string& unstub_clients) {
523 // If we initialize DBusThreadManager twice we may also be shutting it down 397 // If we initialize DBusThreadManager twice we may also be shutting it down
524 // early; do not allow that. 398 // early; do not allow that.
525 CHECK(g_dbus_thread_manager == NULL); 399 CHECK(g_dbus_thread_manager == NULL);
400
401 int unstub_mask = ParseUnstubList(unstub_clients);
402 // We should have something parsed correctly here.
403 if (unstub_mask == 0) {
404 LOG(FATAL) << "Switch values for --"
405 << chromeos::switches::kDbusUnstubClients
406 << " cannot be parsed: "
407 << unstub_clients;
408 }
409 DBusThreadManager* real_thread_manager =
410 new DBusThreadManagerImpl(unstub_mask);
411 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
412 fake_dbus_thread_manager->SetFakeClients();
413 VLOG(1) << "DBusThreadManager initialized for mixed runtime environment";
414 g_dbus_thread_manager = new MixedDBusThreadManager(unstub_mask,
415 real_thread_manager,
416 fake_dbus_thread_manager);
417 InitializeClients();
418 }
419
420 // static
421 void DBusThreadManager::InitializeThreadManager() {
422 g_dbus_thread_manager = new DBusThreadManagerImpl(DBusClientBundle::All);
423 InitializeClients();
424 VLOG(1) << "DBusThreadManager initialized for Chrome OS";
425 }
426
427 // static
428 void DBusThreadManager::InitializeThreadManagerWithStub() {
429 // If we initialize DBusThreadManager twice we may also be shutting it down
430 // early; do not allow that.
431 CHECK(g_dbus_thread_manager == NULL);
526 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager; 432 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
527 fake_dbus_thread_manager->SetFakeClients(); 433 fake_dbus_thread_manager->SetFakeClients();
528 g_dbus_thread_manager = fake_dbus_thread_manager; 434 g_dbus_thread_manager = fake_dbus_thread_manager;
529 InitializeClients(); 435 InitializeClients();
530 fake_dbus_thread_manager->SetupDefaultEnvironment(); 436 fake_dbus_thread_manager->SetupDefaultEnvironment();
531 VLOG(1) << "DBusThreadManager initialized with stub implementation"; 437 VLOG(1) << "DBusThreadManager initialized with stub implementation";
532 } 438 }
533 439
534 // static 440 // static
535 bool DBusThreadManager::IsInitialized() { 441 bool DBusThreadManager::IsInitialized() {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects(); 535 g_dbus_thread_manager->GetSystemBus()->GetManagedObjects();
630 } 536 }
631 537
632 // static 538 // static
633 void DBusThreadManager::InitClient(DBusClient* client) { 539 void DBusThreadManager::InitClient(DBusClient* client) {
634 if (client) 540 if (client)
635 client->Init(g_dbus_thread_manager->GetSystemBus()); 541 client->Init(g_dbus_thread_manager->GetSystemBus());
636 } 542 }
637 543
638 } // namespace chromeos 544 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698