ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chromeos / dbus / dbus_client_bundle.cc
blob77a7010c8012c65f970fcc406f52a9a89d9c75b3
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/bluetooth_adapter_client.h"
14 #include "chromeos/dbus/bluetooth_agent_manager_client.h"
15 #include "chromeos/dbus/bluetooth_device_client.h"
16 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h"
17 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h"
18 #include "chromeos/dbus/bluetooth_gatt_manager_client.h"
19 #include "chromeos/dbus/bluetooth_gatt_service_client.h"
20 #include "chromeos/dbus/bluetooth_input_client.h"
21 #include "chromeos/dbus/bluetooth_media_client.h"
22 #include "chromeos/dbus/bluetooth_media_transport_client.h"
23 #include "chromeos/dbus/bluetooth_profile_manager_client.h"
24 #include "chromeos/dbus/cras_audio_client.h"
25 #include "chromeos/dbus/cros_disks_client.h"
26 #include "chromeos/dbus/cryptohome_client.h"
27 #include "chromeos/dbus/debug_daemon_client.h"
28 #include "chromeos/dbus/easy_unlock_client.h"
29 #include "chromeos/dbus/fake_bluetooth_adapter_client.h"
30 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h"
31 #include "chromeos/dbus/fake_bluetooth_device_client.h"
32 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h"
33 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h"
34 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h"
35 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h"
36 #include "chromeos/dbus/fake_bluetooth_input_client.h"
37 #include "chromeos/dbus/fake_bluetooth_media_client.h"
38 #include "chromeos/dbus/fake_bluetooth_media_transport_client.h"
39 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h"
40 #include "chromeos/dbus/fake_cras_audio_client.h"
41 #include "chromeos/dbus/fake_cryptohome_client.h"
42 #include "chromeos/dbus/fake_debug_daemon_client.h"
43 #include "chromeos/dbus/fake_easy_unlock_client.h"
44 #include "chromeos/dbus/fake_gsm_sms_client.h"
45 #include "chromeos/dbus/fake_image_burner_client.h"
46 #include "chromeos/dbus/fake_introspectable_client.h"
47 #include "chromeos/dbus/fake_leadership_daemon_manager_client.h"
48 #include "chromeos/dbus/fake_lorgnette_manager_client.h"
49 #include "chromeos/dbus/fake_modem_messaging_client.h"
50 #include "chromeos/dbus/fake_nfc_adapter_client.h"
51 #include "chromeos/dbus/fake_nfc_device_client.h"
52 #include "chromeos/dbus/fake_nfc_manager_client.h"
53 #include "chromeos/dbus/fake_nfc_record_client.h"
54 #include "chromeos/dbus/fake_nfc_tag_client.h"
55 #include "chromeos/dbus/fake_peer_daemon_manager_client.h"
56 #include "chromeos/dbus/fake_permission_broker_client.h"
57 #include "chromeos/dbus/fake_shill_device_client.h"
58 #include "chromeos/dbus/fake_shill_ipconfig_client.h"
59 #include "chromeos/dbus/fake_shill_manager_client.h"
60 #include "chromeos/dbus/fake_shill_profile_client.h"
61 #include "chromeos/dbus/fake_shill_service_client.h"
62 #include "chromeos/dbus/fake_shill_third_party_vpn_driver_client.h"
63 #include "chromeos/dbus/fake_sms_client.h"
64 #include "chromeos/dbus/fake_system_clock_client.h"
65 #include "chromeos/dbus/gsm_sms_client.h"
66 #include "chromeos/dbus/image_burner_client.h"
67 #include "chromeos/dbus/introspectable_client.h"
68 #include "chromeos/dbus/leadership_daemon_manager_client.h"
69 #include "chromeos/dbus/lorgnette_manager_client.h"
70 #include "chromeos/dbus/modem_messaging_client.h"
71 #include "chromeos/dbus/nfc_adapter_client.h"
72 #include "chromeos/dbus/nfc_device_client.h"
73 #include "chromeos/dbus/nfc_manager_client.h"
74 #include "chromeos/dbus/nfc_record_client.h"
75 #include "chromeos/dbus/nfc_tag_client.h"
76 #include "chromeos/dbus/peer_daemon_manager_client.h"
77 #include "chromeos/dbus/permission_broker_client.h"
78 #include "chromeos/dbus/power_manager_client.h"
79 #include "chromeos/dbus/power_policy_controller.h"
80 #include "chromeos/dbus/session_manager_client.h"
81 #include "chromeos/dbus/shill_device_client.h"
82 #include "chromeos/dbus/shill_ipconfig_client.h"
83 #include "chromeos/dbus/shill_manager_client.h"
84 #include "chromeos/dbus/shill_profile_client.h"
85 #include "chromeos/dbus/shill_service_client.h"
86 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h"
87 #include "chromeos/dbus/sms_client.h"
88 #include "chromeos/dbus/system_clock_client.h"
89 #include "chromeos/dbus/update_engine_client.h"
91 namespace chromeos {
93 namespace {
95 // Command line switch mapping for --dbus-unstub-clients.
96 const struct {
97 const char* param_name;
98 DBusClientBundle::DBusClientType client_type;
99 } client_type_map[] = {
100 { "bluetooth", DBusClientBundle::BLUETOOTH },
101 { "cras", DBusClientBundle::CRAS },
102 { "cros_disks", DBusClientBundle::CROS_DISKS },
103 { "cryptohome", DBusClientBundle::CRYPTOHOME },
104 { "debug_daemon", DBusClientBundle::DEBUG_DAEMON },
105 { "easy_unlock", DBusClientBundle::EASY_UNLOCK },
106 { "leadership_daemon", DBusClientBundle::LEADERSHIP_DAEMON },
107 { "lorgnette_manager", DBusClientBundle::LORGNETTE_MANAGER },
108 { "shill", DBusClientBundle::SHILL },
109 { "gsm_sms", DBusClientBundle::GSM_SMS },
110 { "image_burner", DBusClientBundle::IMAGE_BURNER },
111 { "introspectable", DBusClientBundle::INTROSPECTABLE },
112 { "modem_messaging", DBusClientBundle::MODEM_MESSAGING },
113 { "nfc", DBusClientBundle::NFC },
114 { "peer_daemon", DBusClientBundle::PEER_DAEMON },
115 { "permission_broker", DBusClientBundle::PERMISSION_BROKER },
116 { "power_manager", DBusClientBundle::POWER_MANAGER },
117 { "session_manager", DBusClientBundle::SESSION_MANAGER },
118 { "sms", DBusClientBundle::SMS },
119 { "system_clock", DBusClientBundle::SYSTEM_CLOCK },
120 { "update_engine", DBusClientBundle::UPDATE_ENGINE },
123 // Parses single command line param value for dbus subsystem. If successful,
124 // returns its enum representation. Otherwise returns NO_CLIENT.
125 DBusClientBundle::DBusClientType GetDBusClientType(
126 const std::string& client_type_name) {
127 for (size_t i = 0; i < arraysize(client_type_map); i++) {
128 if (LowerCaseEqualsASCII(client_type_name, client_type_map[i].param_name))
129 return client_type_map[i].client_type;
131 return DBusClientBundle::NO_CLIENT;
134 } // namespace
136 DBusClientBundle::DBusClientBundle(DBusClientTypeMask unstub_client_mask)
137 : unstub_client_mask_(unstub_client_mask) {
138 if (!IsUsingStub(BLUETOOTH)) {
139 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create());
140 bluetooth_agent_manager_client_.reset(
141 BluetoothAgentManagerClient::Create());
142 bluetooth_device_client_.reset(BluetoothDeviceClient::Create());
143 bluetooth_input_client_.reset(BluetoothInputClient::Create());
144 bluetooth_media_client_.reset(BluetoothMediaClient::Create());
145 bluetooth_media_transport_client_.reset(
146 BluetoothMediaTransportClient::Create());
147 bluetooth_profile_manager_client_.reset(
148 BluetoothProfileManagerClient::Create());
149 bluetooth_gatt_characteristic_client_.reset(
150 BluetoothGattCharacteristicClient::Create());
151 bluetooth_gatt_descriptor_client_.reset(
152 BluetoothGattDescriptorClient::Create());
153 bluetooth_gatt_manager_client_.reset(
154 BluetoothGattManagerClient::Create());
155 bluetooth_gatt_service_client_.reset(
156 BluetoothGattServiceClient::Create());
157 } else {
158 bluetooth_adapter_client_.reset(new FakeBluetoothAdapterClient);
159 bluetooth_agent_manager_client_.reset(new FakeBluetoothAgentManagerClient);
160 bluetooth_device_client_.reset(new FakeBluetoothDeviceClient);
161 bluetooth_input_client_.reset(new FakeBluetoothInputClient);
162 bluetooth_media_client_.reset(new FakeBluetoothMediaClient);
163 bluetooth_media_transport_client_.reset(
164 new FakeBluetoothMediaTransportClient);
165 bluetooth_profile_manager_client_.reset(
166 new FakeBluetoothProfileManagerClient);
167 bluetooth_gatt_characteristic_client_.reset(
168 new FakeBluetoothGattCharacteristicClient);
169 bluetooth_gatt_descriptor_client_.reset(
170 new FakeBluetoothGattDescriptorClient);
171 bluetooth_gatt_manager_client_.reset(new FakeBluetoothGattManagerClient);
172 bluetooth_gatt_service_client_.reset(new FakeBluetoothGattServiceClient);
175 if (!IsUsingStub(CRAS))
176 cras_audio_client_.reset(CrasAudioClient::Create());
177 else
178 cras_audio_client_.reset(new FakeCrasAudioClient);
180 cros_disks_client_.reset(CrosDisksClient::Create(
181 IsUsingStub(CROS_DISKS) ? STUB_DBUS_CLIENT_IMPLEMENTATION
182 : REAL_DBUS_CLIENT_IMPLEMENTATION));
184 if (!IsUsingStub(CRYPTOHOME))
185 cryptohome_client_.reset(CryptohomeClient::Create());
186 else
187 cryptohome_client_.reset(new FakeCryptohomeClient);
189 if (!IsUsingStub(DEBUG_DAEMON))
190 debug_daemon_client_.reset(DebugDaemonClient::Create());
191 else
192 debug_daemon_client_.reset(new FakeDebugDaemonClient);
194 if (!IsUsingStub(EASY_UNLOCK))
195 easy_unlock_client_.reset(EasyUnlockClient::Create());
196 else
197 easy_unlock_client_.reset(new FakeEasyUnlockClient);
199 if (!IsUsingStub(LORGNETTE_MANAGER))
200 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create());
201 else
202 lorgnette_manager_client_.reset(new FakeLorgnetteManagerClient);
204 if (!IsUsingStub(SHILL)) {
205 shill_manager_client_.reset(ShillManagerClient::Create());
206 shill_device_client_.reset(ShillDeviceClient::Create());
207 shill_ipconfig_client_.reset(ShillIPConfigClient::Create());
208 shill_service_client_.reset(ShillServiceClient::Create());
209 shill_profile_client_.reset(ShillProfileClient::Create());
210 shill_third_party_vpn_driver_client_.reset(
211 ShillThirdPartyVpnDriverClient::Create());
212 } else {
213 shill_manager_client_.reset(new FakeShillManagerClient);
214 shill_device_client_.reset(new FakeShillDeviceClient);
215 shill_ipconfig_client_.reset(new FakeShillIPConfigClient);
216 shill_service_client_.reset(new FakeShillServiceClient);
217 shill_profile_client_.reset(new FakeShillProfileClient);
218 shill_third_party_vpn_driver_client_.reset(
219 new FakeShillThirdPartyVpnDriverClient);
222 if (!IsUsingStub(GSM_SMS)) {
223 gsm_sms_client_.reset(GsmSMSClient::Create());
224 } else {
225 FakeGsmSMSClient* gsm_sms_client = new FakeGsmSMSClient();
226 gsm_sms_client->set_sms_test_message_switch_present(
227 base::CommandLine::ForCurrentProcess()->HasSwitch(
228 chromeos::switches::kSmsTestMessages));
229 gsm_sms_client_.reset(gsm_sms_client);
232 if (!IsUsingStub(IMAGE_BURNER))
233 image_burner_client_.reset(ImageBurnerClient::Create());
234 else
235 image_burner_client_.reset(new FakeImageBurnerClient);
237 if (!IsUsingStub(INTROSPECTABLE))
238 introspectable_client_.reset(IntrospectableClient::Create());
239 else
240 introspectable_client_.reset(new FakeIntrospectableClient);
242 if (!IsUsingStub(MODEM_MESSAGING))
243 modem_messaging_client_.reset(ModemMessagingClient::Create());
244 else
245 modem_messaging_client_.reset(new FakeModemMessagingClient);
247 // Create the NFC clients in the correct order based on their dependencies.
248 if (!IsUsingStub(NFC)) {
249 nfc_manager_client_.reset(NfcManagerClient::Create());
250 nfc_adapter_client_.reset(
251 NfcAdapterClient::Create(nfc_manager_client_.get()));
252 nfc_device_client_.reset(
253 NfcDeviceClient::Create(nfc_adapter_client_.get()));
254 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get()));
255 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(),
256 nfc_tag_client_.get()));
257 } else {
258 nfc_manager_client_.reset(new FakeNfcManagerClient);
259 nfc_adapter_client_.reset(new FakeNfcAdapterClient);
260 nfc_device_client_.reset(new FakeNfcDeviceClient);
261 nfc_tag_client_.reset(new FakeNfcTagClient);
262 nfc_record_client_.reset(new FakeNfcRecordClient);
265 if (!IsUsingStub(PEER_DAEMON))
266 peer_daemon_manager_client_.reset(PeerDaemonManagerClient::Create());
267 else
268 peer_daemon_manager_client_.reset(new FakePeerDaemonManagerClient);
270 if (!IsUsingStub(PERMISSION_BROKER))
271 permission_broker_client_.reset(PermissionBrokerClient::Create());
272 else
273 permission_broker_client_.reset(new FakePermissionBrokerClient);
275 if (!IsUsingStub(LEADERSHIP_DAEMON)) {
276 leadership_daemon_manager_client_.reset(
277 LeadershipDaemonManagerClient::Create());
278 } else {
279 leadership_daemon_manager_client_.reset(
280 new FakeLeadershipDaemonManagerClient);
283 power_manager_client_.reset(PowerManagerClient::Create(
284 IsUsingStub(POWER_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION
285 : REAL_DBUS_CLIENT_IMPLEMENTATION));
287 session_manager_client_.reset(SessionManagerClient::Create(
288 IsUsingStub(SESSION_MANAGER) ? STUB_DBUS_CLIENT_IMPLEMENTATION
289 : REAL_DBUS_CLIENT_IMPLEMENTATION));
291 if (!IsUsingStub(SMS))
292 sms_client_.reset(SMSClient::Create());
293 else
294 sms_client_.reset(new FakeSMSClient);
296 if (!IsUsingStub(SYSTEM_CLOCK))
297 system_clock_client_.reset(SystemClockClient::Create());
298 else
299 system_clock_client_.reset(new FakeSystemClockClient);
301 update_engine_client_.reset(UpdateEngineClient::Create(
302 IsUsingStub(UPDATE_ENGINE) ? STUB_DBUS_CLIENT_IMPLEMENTATION
303 : REAL_DBUS_CLIENT_IMPLEMENTATION));
306 DBusClientBundle::~DBusClientBundle() {
309 bool DBusClientBundle::IsUsingStub(DBusClientType client) {
310 return !(unstub_client_mask_ & client);
313 bool DBusClientBundle::IsUsingAnyRealClient() {
314 // 'Using any real client' is equivalent to 'Unstubbed any client'.
315 return unstub_client_mask_ != 0;
318 void DBusClientBundle::SetupDefaultEnvironment() {
319 ShillManagerClient::TestInterface* manager =
320 shill_manager_client_->GetTestInterface();
321 if (manager)
322 manager->SetupDefaultEnvironment();
325 // static
326 DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList(
327 const std::string& unstub_list) {
328 DBusClientTypeMask unstub_mask = 0;
329 std::vector<std::string> unstub_components;
330 base::SplitString(unstub_list, ',', &unstub_components);
331 for (std::vector<std::string>::const_iterator iter =
332 unstub_components.begin();
333 iter != unstub_components.end(); ++iter) {
334 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter);
335 if (client != NO_CLIENT) {
336 LOG(WARNING) << "Unstubbing dbus client for " << *iter;
337 unstub_mask |= client;
338 } else {
339 LOG(ERROR) << "Unknown dbus client: " << *iter;
343 return unstub_mask;
346 } // namespace chromeos