[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / chromeos / dbus / dbus_client_bundle.cc
bloba18a611d3b6bf33f1971e2a399917a04ead63561
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/dbus/dbus_client_bundle.h"
7 #include <vector>
9 #include "base/command_line.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
12 #include "chromeos/chromeos_switches.h"
13 #include "chromeos/dbus/amplifier_client.h"
14 #include "chromeos/dbus/ap_manager_client.h"
15 #include "chromeos/dbus/audio_dsp_client.h"
16 #include "chromeos/dbus/bluetooth_adapter_client.h"
17 #include "chromeos/dbus/bluetooth_agent_manager_client.h"
18 #include "chromeos/dbus/bluetooth_device_client.h"
19 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
20 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
21 #include "chromeos/dbus/bluetooth_gatt_manager_client.h"
22 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
23 #include "chromeos/dbus/bluetooth_input_client.h"
24 #include "chromeos/dbus/bluetooth_le_advertising_manager_client.h"
25 #include "chromeos/dbus/bluetooth_media_client.h"
26 #include "chromeos/dbus/bluetooth_media_transport_client.h"
27 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
28 #include "chromeos/dbus/cras_audio_client.h"
29 #include "chromeos/dbus/cros_disks_client.h"
30 #include "chromeos/dbus/cryptohome_client.h"
31 #include "chromeos/dbus/debug_daemon_client.h"
32 #include "chromeos/dbus/easy_unlock_client.h"
33 #include "chromeos/dbus/fake_amplifier_client.h"
34 #include "chromeos/dbus/fake_ap_manager_client.h"
35 #include "chromeos/dbus/fake_audio_dsp_client.h"
36 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
37 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
38 #include "chromeos/dbus/fake_bluetooth_device_client.h"
39 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h"
40 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h"
41 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h"
42 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h"
43 #include "chromeos/dbus/fake_bluetooth_input_client.h"
44 #include "chromeos/dbus/fake_bluetooth_le_advertising_manager_client.h"
45 #include "chromeos/dbus/fake_bluetooth_media_client.h"
46 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
47 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
48 #include "chromeos/dbus/fake_cras_audio_client.h"
49 #include "chromeos/dbus/fake_cryptohome_client.h"
50 #include "chromeos/dbus/fake_debug_daemon_client.h"
51 #include "chromeos/dbus/fake_easy_unlock_client.h"
52 #include "chromeos/dbus/fake_gsm_sms_client.h"
53 #include "chromeos/dbus/fake_image_burner_client.h"
54 #include "chromeos/dbus/fake_introspectable_client.h"
55 #include "chromeos/dbus/fake_leadership_daemon_manager_client.h"
56 #include "chromeos/dbus/fake_lorgnette_manager_client.h"
57 #include "chromeos/dbus/fake_modem_messaging_client.h"
58 #include "chromeos/dbus/fake_nfc_adapter_client.h"
59 #include "chromeos/dbus/fake_nfc_device_client.h"
60 #include "chromeos/dbus/fake_nfc_manager_client.h"
61 #include "chromeos/dbus/fake_nfc_record_client.h"
62 #include "chromeos/dbus/fake_nfc_tag_client.h"
63 #include "chromeos/dbus/fake_peer_daemon_manager_client.h"
64 #include "chromeos/dbus/fake_permission_broker_client.h"
65 #include "chromeos/dbus/fake_privet_daemon_manager_client.h"
66 #include "chromeos/dbus/fake_shill_device_client.h"
67 #include "chromeos/dbus/fake_shill_ipconfig_client.h"
68 #include "chromeos/dbus/fake_shill_manager_client.h"
69 #include "chromeos/dbus/fake_shill_profile_client.h"
70 #include "chromeos/dbus/fake_shill_service_client.h"
71 #include "chromeos/dbus/fake_shill_third_party_vpn_driver_client.h"
72 #include "chromeos/dbus/fake_sms_client.h"
73 #include "chromeos/dbus/fake_system_clock_client.h"
74 #include "chromeos/dbus/gsm_sms_client.h"
75 #include "chromeos/dbus/image_burner_client.h"
76 #include "chromeos/dbus/introspectable_client.h"
77 #include "chromeos/dbus/leadership_daemon_manager_client.h"
78 #include "chromeos/dbus/lorgnette_manager_client.h"
79 #include "chromeos/dbus/metronome_client.h"
80 #include "chromeos/dbus/modem_messaging_client.h"
81 #include "chromeos/dbus/nfc_adapter_client.h"
82 #include "chromeos/dbus/nfc_device_client.h"
83 #include "chromeos/dbus/nfc_manager_client.h"
84 #include "chromeos/dbus/nfc_record_client.h"
85 #include "chromeos/dbus/nfc_tag_client.h"
86 #include "chromeos/dbus/peer_daemon_manager_client.h"
87 #include "chromeos/dbus/permission_broker_client.h"
88 #include "chromeos/dbus/power_manager_client.h"
89 #include "chromeos/dbus/power_policy_controller.h"
90 #include "chromeos/dbus/privet_daemon_manager_client.h"
91 #include "chromeos/dbus/session_manager_client.h"
92 #include "chromeos/dbus/shill_device_client.h"
93 #include "chromeos/dbus/shill_ipconfig_client.h"
94 #include "chromeos/dbus/shill_manager_client.h"
95 #include "chromeos/dbus/shill_profile_client.h"
96 #include "chromeos/dbus/shill_service_client.h"
97 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h"
98 #include "chromeos/dbus/sms_client.h"
99 #include "chromeos/dbus/system_clock_client.h"
100 #include "chromeos/dbus/update_engine_client.h"
102 namespace chromeos {
104 namespace {
106 // Command line switch mapping for --dbus-unstub-clients.
107 const struct {
108 const char* param_name;
109 DBusClientBundle::DBusClientType client_type;
110 } client_type_map[] = {
111 { "amplifier", DBusClientBundle::AMPLIFIER },
112 { "ap", DBusClientBundle::AP_MANAGER },
113 { "audio_dsp", DBusClientBundle::AUDIO_DSP },
114 { "bluetooth", DBusClientBundle::BLUETOOTH },
115 { "cras", DBusClientBundle::CRAS },
116 { "cros_disks", DBusClientBundle::CROS_DISKS },
117 { "cryptohome", DBusClientBundle::CRYPTOHOME },
118 { "debug_daemon", DBusClientBundle::DEBUG_DAEMON },
119 { "easy_unlock", DBusClientBundle::EASY_UNLOCK },
120 { "leadership_daemon", DBusClientBundle::LEADERSHIP_DAEMON },
121 { "lorgnette_manager", DBusClientBundle::LORGNETTE_MANAGER },
122 { "metronome", DBusClientBundle::METRONOME },
123 { "shill", DBusClientBundle::SHILL },
124 { "gsm_sms", DBusClientBundle::GSM_SMS },
125 { "image_burner", DBusClientBundle::IMAGE_BURNER },
126 { "introspectable", DBusClientBundle::INTROSPECTABLE },
127 { "modem_messaging", DBusClientBundle::MODEM_MESSAGING },
128 { "nfc", DBusClientBundle::NFC },
129 { "peer_daemon", DBusClientBundle::PEER_DAEMON },
130 { "permission_broker", DBusClientBundle::PERMISSION_BROKER },
131 { "power_manager", DBusClientBundle::POWER_MANAGER },
132 { "privet_daemon", DBusClientBundle::PRIVET_DAEMON },
133 { "session_manager", DBusClientBundle::SESSION_MANAGER },
134 { "sms", DBusClientBundle::SMS },
135 { "system_clock", DBusClientBundle::SYSTEM_CLOCK },
136 { "update_engine", DBusClientBundle::UPDATE_ENGINE },
139 // Parses single command line param value for dbus subsystem. If successful,
140 // returns its enum representation. Otherwise returns NO_CLIENT.
141 DBusClientBundle::DBusClientType GetDBusClientType(
142 const std::string& client_type_name) {
143 for (size_t i = 0; i < arraysize(client_type_map); i++) {
144 if (base::LowerCaseEqualsASCII(client_type_name,
145 client_type_map[i].param_name))
146 return client_type_map[i].client_type;
148 return DBusClientBundle::NO_CLIENT;
151 } // namespace
153 DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask)
154 : unstub_client_mask_(unstub_client_mask) {
155 if (!IsUsingStub(AMPLIFIER))
156 amplifier_client_.reset(AmplifierClient::Create());
157 else
158 amplifier_client_.reset(new FakeAmplifierClient);
160 if (!IsUsingStub(AUDIO_DSP))
161 audio_dsp_client_.reset(AudioDspClient::Create());
162 else
163 audio_dsp_client_.reset(new FakeAudioDspClient);
165 if (!IsUsingStub(BLUETOOTH)) {
166 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create());
167 bluetooth_le_advertising_manager_client_.reset(
168 BluetoothLEAdvertisingManagerClient::Create());
169 bluetooth_agent_manager_client_.reset(
170 BluetoothAgentManagerClient::Create());
171 bluetooth_device_client_.reset(BluetoothDeviceClient::Create());
172 bluetooth_input_client_.reset(BluetoothInputClient::Create());
173 bluetooth_media_client_.reset(BluetoothMediaClient::Create());
174 bluetooth_media_transport_client_.reset(
175 BluetoothMediaTransportClient::Create());
176 bluetooth_profile_manager_client_.reset(
177 BluetoothProfileManagerClient::Create());
178 bluetooth_gatt_characteristic_client_.reset(
179 BluetoothGattCharacteristicClient::Create());
180 bluetooth_gatt_descriptor_client_.reset(
181 BluetoothGattDescriptorClient::Create());
182 bluetooth_gatt_manager_client_.reset(
183 BluetoothGattManagerClient::Create());
184 bluetooth_gatt_service_client_.reset(
185 BluetoothGattServiceClient::Create());
186 } else {
187 bluetooth_adapter_client_.reset(new FakeBluetoothAdapterClient);
188 bluetooth_le_advertising_manager_client_.reset(
189 new FakeBluetoothLEAdvertisingManagerClient);
190 bluetooth_agent_manager_client_.reset(new FakeBluetoothAgentManagerClient);
191 bluetooth_device_client_.reset(new FakeBluetoothDeviceClient);
192 bluetooth_input_client_.reset(new FakeBluetoothInputClient);
193 bluetooth_media_client_.reset(new FakeBluetoothMediaClient);
194 bluetooth_media_transport_client_.reset(
195 new FakeBluetoothMediaTransportClient);
196 bluetooth_profile_manager_client_.reset(
197 new FakeBluetoothProfileManagerClient);
198 bluetooth_gatt_characteristic_client_.reset(
199 new FakeBluetoothGattCharacteristicClient);
200 bluetooth_gatt_descriptor_client_.reset(
201 new FakeBluetoothGattDescriptorClient);
202 bluetooth_gatt_manager_client_.reset(new FakeBluetoothGattManagerClient);
203 bluetooth_gatt_service_client_.reset(new FakeBluetoothGattServiceClient);
206 if (!IsUsingStub(CRAS))
207 cras_audio_client_.reset(CrasAudioClient::Create());
208 else
209 cras_audio_client_.reset(new FakeCrasAudioClient);
211 cros_disks_client_.reset(CrosDisksClient::Create(
212 IsUsingStub(CROS_DISKS) ? STUB_DBUS_CLIENT_IMPLEMENTATION
213 : REAL_DBUS_CLIENT_IMPLEMENTATION));
215 if (!IsUsingStub(CRYPTOHOME))
216 cryptohome_client_.reset(CryptohomeClient::Create());
217 else
218 cryptohome_client_.reset(new FakeCryptohomeClient);
220 if (!IsUsingStub(DEBUG_DAEMON))
221 debug_daemon_client_.reset(DebugDaemonClient::Create());
222 else
223 debug_daemon_client_.reset(new FakeDebugDaemonClient);
225 if (!IsUsingStub(EASY_UNLOCK))
226 easy_unlock_client_.reset(EasyUnlockClient::Create());
227 else
228 easy_unlock_client_.reset(new FakeEasyUnlockClient);
230 if (!IsUsingStub(LORGNETTE_MANAGER))
231 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create());
232 else
233 lorgnette_manager_client_.reset(new FakeLorgnetteManagerClient);
235 metronome_client_.reset(MetronomeClient::Create(
236 IsUsingStub(METRONOME) ? STUB_DBUS_CLIENT_IMPLEMENTATION
237 : REAL_DBUS_CLIENT_IMPLEMENTATION));
239 if (!IsUsingStub(SHILL)) {
240 shill_manager_client_.reset(ShillManagerClient::Create());
241 shill_device_client_.reset(ShillDeviceClient::Create());
242 shill_ipconfig_client_.reset(ShillIPConfigClient::Create());
243 shill_service_client_.reset(ShillServiceClient::Create());
244 shill_profile_client_.reset(ShillProfileClient::Create());
245 shill_third_party_vpn_driver_client_.reset(
246 ShillThirdPartyVpnDriverClient::Create());
247 } else {
248 shill_manager_client_.reset(new FakeShillManagerClient);
249 shill_device_client_.reset(new FakeShillDeviceClient);
250 shill_ipconfig_client_.reset(new FakeShillIPConfigClient);
251 shill_service_client_.reset(new FakeShillServiceClient);
252 shill_profile_client_.reset(new FakeShillProfileClient);
253 shill_third_party_vpn_driver_client_.reset(
254 new FakeShillThirdPartyVpnDriverClient);
257 if (!IsUsingStub(GSM_SMS)) {
258 gsm_sms_client_.reset(GsmSMSClient::Create());
259 } else {
260 FakeGsmSMSClient* gsm_sms_client = new FakeGsmSMSClient();
261 gsm_sms_client->set_sms_test_message_switch_present(
262 base::CommandLine::ForCurrentProcess()->HasSwitch(
263 chromeos::switches::kSmsTestMessages));
264 gsm_sms_client_.reset(gsm_sms_client);
267 if (!IsUsingStub(IMAGE_BURNER))
268 image_burner_client_.reset(ImageBurnerClient::Create());
269 else
270 image_burner_client_.reset(new FakeImageBurnerClient);
272 if (!IsUsingStub(INTROSPECTABLE))
273 introspectable_client_.reset(IntrospectableClient::Create());
274 else
275 introspectable_client_.reset(new FakeIntrospectableClient);
277 if (!IsUsingStub(MODEM_MESSAGING))
278 modem_messaging_client_.reset(ModemMessagingClient::Create());
279 else
280 modem_messaging_client_.reset(new FakeModemMessagingClient);
282 // Create the NFC clients in the correct order based on their dependencies.
283 if (!IsUsingStub(NFC)) {
284 nfc_manager_client_.reset(NfcManagerClient::Create());
285 nfc_adapter_client_.reset(
286 NfcAdapterClient::Create(nfc_manager_client_.get()));
287 nfc_device_client_.reset(
288 NfcDeviceClient::Create(nfc_adapter_client_.get()));
289 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get()));
290 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(),
291 nfc_tag_client_.get()));
292 } else {
293 nfc_manager_client_.reset(new FakeNfcManagerClient);
294 nfc_adapter_client_.reset(new FakeNfcAdapterClient);
295 nfc_device_client_.reset(new FakeNfcDeviceClient);
296 nfc_tag_client_.reset(new FakeNfcTagClient);
297 nfc_record_client_.reset(new FakeNfcRecordClient);
300 if (!IsUsingStub(PEER_DAEMON))
301 peer_daemon_manager_client_.reset(PeerDaemonManagerClient::Create());
302 else
303 peer_daemon_manager_client_.reset(new FakePeerDaemonManagerClient);
305 if (!IsUsingStub(PERMISSION_BROKER))
306 permission_broker_client_.reset(PermissionBrokerClient::Create());
307 else
308 permission_broker_client_.reset(new FakePermissionBrokerClient);
310 if (!IsUsingStub(PRIVET_DAEMON))
311 privet_daemon_manager_client_.reset(PrivetDaemonManagerClient::Create());
312 else
313 privet_daemon_manager_client_.reset(new FakePrivetDaemonManagerClient);
315 if (!IsUsingStub(LEADERSHIP_DAEMON)) {
316 leadership_daemon_manager_client_.reset(
317 LeadershipDaemonManagerClient::Create());
318 } else {
319 leadership_daemon_manager_client_.reset(
320 new FakeLeadershipDaemonManagerClient);
323 if (!IsUsingStub(AP_MANAGER))
324 ap_manager_client_.reset(ApManagerClient::Create());
325 else
326 ap_manager_client_.reset(new FakeApManagerClient);
328 power_manager_client_.reset(PowerManagerClient::Create(
329 IsUsingStub(POWER_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION
330 : REAL_DBUS_CLIENT_IMPLEMENTATION));
332 session_manager_client_.reset(SessionManagerClient::Create(
333 IsUsingStub(SESSION_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION
334 : REAL_DBUS_CLIENT_IMPLEMENTATION));
336 if (!IsUsingStub(SMS))
337 sms_client_.reset(SMSClient::Create());
338 else
339 sms_client_.reset(new FakeSMSClient);
341 if (!IsUsingStub(SYSTEM_CLOCK))
342 system_clock_client_.reset(SystemClockClient::Create());
343 else
344 system_clock_client_.reset(new FakeSystemClockClient);
346 update_engine_client_.reset(UpdateEngineClient::Create(
347 IsUsingStub(UPDATE_ENGINE) ? STUB_DBUS_CLIENT_IMPLEMENTATION
348 : REAL_DBUS_CLIENT_IMPLEMENTATION));
351 DBusClientBundle::~DBusClientBundle() {
354 bool DBusClientBundle::IsUsingStub(DBusClientType client) {
355 return !(unstub_client_mask_ & client);
358 bool DBusClientBundle::IsUsingAnyRealClient() {
359 // 'Using any real client' is equivalent to 'Unstubbed any client'.
360 return unstub_client_mask_ != 0;
363 void DBusClientBundle::SetupDefaultEnvironment() {
364 ShillManagerClient::TestInterface* manager =
365 shill_manager_client_->GetTestInterface();
366 if (manager)
367 manager->SetupDefaultEnvironment();
370 // static
371 DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList(
372 const std::string& unstub_list) {
373 DBusClientTypeMask unstub_mask = 0;
374 std::vector<std::string> unstub_components;
375 base::SplitString(unstub_list, ',', &unstub_components);
376 for (std::vector<std::string>::const_iterator iter =
377 unstub_components.begin();
378 iter != unstub_components.end(); ++iter) {
379 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter);
380 if (client != NO_CLIENT) {
381 LOG(WARNING) << "Unstubbing dbus client for " << *iter;
382 unstub_mask |= client;
383 } else {
384 LOG(ERROR) << "Unknown dbus client: " << *iter;
388 return unstub_mask;
391 } // namespace chromeos