OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_client_bundle.h" | 5 #include "chromeos/dbus/dbus_client_bundle.h" |
6 | 6 |
| 7 #include "base/command_line.h" |
7 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chromeos/chromeos_switches.h" |
9 #include "chromeos/dbus/bluetooth_adapter_client.h" | 11 #include "chromeos/dbus/bluetooth_adapter_client.h" |
10 #include "chromeos/dbus/bluetooth_agent_manager_client.h" | 12 #include "chromeos/dbus/bluetooth_agent_manager_client.h" |
11 #include "chromeos/dbus/bluetooth_device_client.h" | 13 #include "chromeos/dbus/bluetooth_device_client.h" |
12 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" | 14 #include "chromeos/dbus/bluetooth_gatt_characteristic_client.h" |
13 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" | 15 #include "chromeos/dbus/bluetooth_gatt_descriptor_client.h" |
14 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" | 16 #include "chromeos/dbus/bluetooth_gatt_manager_client.h" |
15 #include "chromeos/dbus/bluetooth_gatt_service_client.h" | 17 #include "chromeos/dbus/bluetooth_gatt_service_client.h" |
16 #include "chromeos/dbus/bluetooth_input_client.h" | 18 #include "chromeos/dbus/bluetooth_input_client.h" |
17 #include "chromeos/dbus/bluetooth_profile_manager_client.h" | 19 #include "chromeos/dbus/bluetooth_profile_manager_client.h" |
18 #include "chromeos/dbus/cras_audio_client.h" | 20 #include "chromeos/dbus/cras_audio_client.h" |
| 21 #include "chromeos/dbus/cras_audio_client_stub_impl.h" |
19 #include "chromeos/dbus/cros_disks_client.h" | 22 #include "chromeos/dbus/cros_disks_client.h" |
20 #include "chromeos/dbus/cryptohome_client.h" | 23 #include "chromeos/dbus/cryptohome_client.h" |
21 #include "chromeos/dbus/dbus_thread_manager.h" | 24 #include "chromeos/dbus/dbus_thread_manager.h" |
22 #include "chromeos/dbus/debug_daemon_client.h" | 25 #include "chromeos/dbus/debug_daemon_client.h" |
23 #include "chromeos/dbus/easy_unlock_client.h" | 26 #include "chromeos/dbus/easy_unlock_client.h" |
| 27 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 28 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| 29 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
| 30 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" |
| 31 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" |
| 32 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h" |
| 33 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" |
| 34 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
| 35 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" |
| 36 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 37 #include "chromeos/dbus/fake_debug_daemon_client.h" |
| 38 #include "chromeos/dbus/fake_easy_unlock_client.h" |
| 39 #include "chromeos/dbus/fake_gsm_sms_client.h" |
| 40 #include "chromeos/dbus/fake_image_burner_client.h" |
| 41 #include "chromeos/dbus/fake_introspectable_client.h" |
| 42 #include "chromeos/dbus/fake_lorgnette_manager_client.h" |
| 43 #include "chromeos/dbus/fake_modem_messaging_client.h" |
| 44 #include "chromeos/dbus/fake_nfc_adapter_client.h" |
| 45 #include "chromeos/dbus/fake_nfc_device_client.h" |
| 46 #include "chromeos/dbus/fake_nfc_manager_client.h" |
| 47 #include "chromeos/dbus/fake_nfc_record_client.h" |
| 48 #include "chromeos/dbus/fake_nfc_tag_client.h" |
| 49 #include "chromeos/dbus/fake_permission_broker_client.h" |
| 50 #include "chromeos/dbus/fake_shill_device_client.h" |
| 51 #include "chromeos/dbus/fake_shill_ipconfig_client.h" |
| 52 #include "chromeos/dbus/fake_shill_manager_client.h" |
| 53 #include "chromeos/dbus/fake_shill_profile_client.h" |
| 54 #include "chromeos/dbus/fake_shill_service_client.h" |
| 55 #include "chromeos/dbus/fake_sms_client.h" |
| 56 #include "chromeos/dbus/fake_system_clock_client.h" |
24 #include "chromeos/dbus/gsm_sms_client.h" | 57 #include "chromeos/dbus/gsm_sms_client.h" |
25 #include "chromeos/dbus/image_burner_client.h" | 58 #include "chromeos/dbus/image_burner_client.h" |
26 #include "chromeos/dbus/introspectable_client.h" | 59 #include "chromeos/dbus/introspectable_client.h" |
27 #include "chromeos/dbus/lorgnette_manager_client.h" | 60 #include "chromeos/dbus/lorgnette_manager_client.h" |
28 #include "chromeos/dbus/modem_messaging_client.h" | 61 #include "chromeos/dbus/modem_messaging_client.h" |
29 #include "chromeos/dbus/nfc_adapter_client.h" | 62 #include "chromeos/dbus/nfc_adapter_client.h" |
30 #include "chromeos/dbus/nfc_device_client.h" | 63 #include "chromeos/dbus/nfc_device_client.h" |
31 #include "chromeos/dbus/nfc_manager_client.h" | 64 #include "chromeos/dbus/nfc_manager_client.h" |
32 #include "chromeos/dbus/nfc_record_client.h" | 65 #include "chromeos/dbus/nfc_record_client.h" |
33 #include "chromeos/dbus/nfc_tag_client.h" | 66 #include "chromeos/dbus/nfc_tag_client.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 for (size_t i = 0; i < arraysize(client_type_map); i++) { | 115 for (size_t i = 0; i < arraysize(client_type_map); i++) { |
83 if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name)) | 116 if (LowerCaseEqualsASCII(client_type, client_type_map[i].param_name)) |
84 return client_type_map[i].client_type; | 117 return client_type_map[i].client_type; |
85 } | 118 } |
86 return DBusClientBundle::NO_CLIENTS; | 119 return DBusClientBundle::NO_CLIENTS; |
87 } | 120 } |
88 | 121 |
89 } // namespace | 122 } // namespace |
90 | 123 |
91 DBusClientBundle::DBusClientBundle() { | 124 DBusClientBundle::DBusClientBundle() { |
92 const DBusClientImplementationType type = REAL_DBUS_CLIENT_IMPLEMENTATION; | |
93 | |
94 if (!DBusThreadManager::IsUsingStub(BLUETOOTH)) { | 125 if (!DBusThreadManager::IsUsingStub(BLUETOOTH)) { |
95 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); | 126 bluetooth_adapter_client_.reset(BluetoothAdapterClient::Create()); |
96 bluetooth_agent_manager_client_.reset( | 127 bluetooth_agent_manager_client_.reset( |
97 BluetoothAgentManagerClient::Create()); | 128 BluetoothAgentManagerClient::Create()); |
98 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); | 129 bluetooth_device_client_.reset(BluetoothDeviceClient::Create()); |
99 bluetooth_input_client_.reset(BluetoothInputClient::Create()); | 130 bluetooth_input_client_.reset(BluetoothInputClient::Create()); |
100 bluetooth_profile_manager_client_.reset( | 131 bluetooth_profile_manager_client_.reset( |
101 BluetoothProfileManagerClient::Create()); | 132 BluetoothProfileManagerClient::Create()); |
102 bluetooth_gatt_characteristic_client_.reset( | 133 bluetooth_gatt_characteristic_client_.reset( |
103 BluetoothGattCharacteristicClient::Create()); | 134 BluetoothGattCharacteristicClient::Create()); |
104 bluetooth_gatt_descriptor_client_.reset( | 135 bluetooth_gatt_descriptor_client_.reset( |
105 BluetoothGattDescriptorClient::Create()); | 136 BluetoothGattDescriptorClient::Create()); |
106 bluetooth_gatt_manager_client_.reset( | 137 bluetooth_gatt_manager_client_.reset( |
107 BluetoothGattManagerClient::Create()); | 138 BluetoothGattManagerClient::Create()); |
108 bluetooth_gatt_service_client_.reset( | 139 bluetooth_gatt_service_client_.reset( |
109 BluetoothGattServiceClient::Create()); | 140 BluetoothGattServiceClient::Create()); |
| 141 } else { |
| 142 bluetooth_adapter_client_.reset(new FakeBluetoothAdapterClient); |
| 143 bluetooth_agent_manager_client_.reset(new FakeBluetoothAgentManagerClient); |
| 144 bluetooth_device_client_.reset(new FakeBluetoothDeviceClient); |
| 145 bluetooth_input_client_.reset(new FakeBluetoothInputClient); |
| 146 bluetooth_profile_manager_client_.reset( |
| 147 new FakeBluetoothProfileManagerClient); |
| 148 bluetooth_gatt_characteristic_client_.reset( |
| 149 new FakeBluetoothGattCharacteristicClient); |
| 150 bluetooth_gatt_descriptor_client_.reset( |
| 151 new FakeBluetoothGattDescriptorClient); |
| 152 bluetooth_gatt_manager_client_.reset(new FakeBluetoothGattManagerClient); |
| 153 bluetooth_gatt_service_client_.reset(new FakeBluetoothGattServiceClient); |
110 } | 154 } |
111 | 155 |
112 if (!DBusThreadManager::IsUsingStub(CRAS)) | 156 if (!DBusThreadManager::IsUsingStub(CRAS)) |
113 cras_audio_client_.reset(CrasAudioClient::Create()); | 157 cras_audio_client_.reset(CrasAudioClient::Create()); |
| 158 else |
| 159 cras_audio_client_.reset(new CrasAudioClientStubImpl); |
114 | 160 |
115 if (!DBusThreadManager::IsUsingStub(CROS_DISKS)) | 161 cros_disks_client_.reset(CrosDisksClient::Create( |
116 cros_disks_client_.reset(CrosDisksClient::Create(type)); | 162 DBusThreadManager::IsUsingStub(CROS_DISKS) ? |
| 163 STUB_DBUS_CLIENT_IMPLEMENTATION : |
| 164 REAL_DBUS_CLIENT_IMPLEMENTATION)); |
117 | 165 |
118 if (!DBusThreadManager::IsUsingStub(CRYPTOHOME)) | 166 if (!DBusThreadManager::IsUsingStub(CRYPTOHOME)) |
119 cryptohome_client_.reset(CryptohomeClient::Create()); | 167 cryptohome_client_.reset(CryptohomeClient::Create()); |
| 168 else |
| 169 cryptohome_client_.reset(new FakeCryptohomeClient); |
120 | 170 |
121 if (!DBusThreadManager::IsUsingStub(DEBUG_DAEMON)) | 171 if (!DBusThreadManager::IsUsingStub(DEBUG_DAEMON)) |
122 debug_daemon_client_.reset(DebugDaemonClient::Create()); | 172 debug_daemon_client_.reset(DebugDaemonClient::Create()); |
| 173 else |
| 174 debug_daemon_client_.reset(new FakeDebugDaemonClient); |
123 | 175 |
124 if (!DBusThreadManager::IsUsingStub(EASY_UNLOCK)) | 176 if (!DBusThreadManager::IsUsingStub(EASY_UNLOCK)) |
125 easy_unlock_client_.reset(EasyUnlockClient::Create()); | 177 easy_unlock_client_.reset(EasyUnlockClient::Create()); |
| 178 else |
| 179 easy_unlock_client_.reset(new FakeEasyUnlockClient); |
126 | 180 |
127 if (!DBusThreadManager::IsUsingStub(LORGNETTE_MANAGER)) | 181 if (!DBusThreadManager::IsUsingStub(LORGNETTE_MANAGER)) |
128 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); | 182 lorgnette_manager_client_.reset(LorgnetteManagerClient::Create()); |
| 183 else |
| 184 lorgnette_manager_client_.reset(new FakeLorgnetteManagerClient); |
129 | 185 |
130 if (!DBusThreadManager::IsUsingStub(SHILL)) { | 186 if (!DBusThreadManager::IsUsingStub(SHILL)) { |
131 shill_manager_client_.reset(ShillManagerClient::Create()); | 187 shill_manager_client_.reset(ShillManagerClient::Create()); |
132 shill_device_client_.reset(ShillDeviceClient::Create()); | 188 shill_device_client_.reset(ShillDeviceClient::Create()); |
133 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); | 189 shill_ipconfig_client_.reset(ShillIPConfigClient::Create()); |
134 shill_service_client_.reset(ShillServiceClient::Create()); | 190 shill_service_client_.reset(ShillServiceClient::Create()); |
135 shill_profile_client_.reset(ShillProfileClient::Create()); | 191 shill_profile_client_.reset(ShillProfileClient::Create()); |
| 192 } else { |
| 193 shill_manager_client_.reset(new FakeShillManagerClient); |
| 194 shill_device_client_.reset(new FakeShillDeviceClient); |
| 195 shill_ipconfig_client_.reset(new FakeShillIPConfigClient); |
| 196 shill_service_client_.reset(new FakeShillServiceClient); |
| 197 shill_profile_client_.reset(new FakeShillProfileClient); |
136 } | 198 } |
137 | 199 |
138 if (!DBusThreadManager::IsUsingStub(GSM_SMS)) | 200 if (!DBusThreadManager::IsUsingStub(GSM_SMS)) { |
139 gsm_sms_client_.reset(GsmSMSClient::Create()); | 201 gsm_sms_client_.reset(GsmSMSClient::Create()); |
| 202 } else { |
| 203 FakeGsmSMSClient* gsm_sms_client = new FakeGsmSMSClient(); |
| 204 gsm_sms_client->set_sms_test_message_switch_present( |
| 205 CommandLine::ForCurrentProcess()->HasSwitch( |
| 206 chromeos::switches::kSmsTestMessages)); |
| 207 gsm_sms_client_.reset(gsm_sms_client); |
| 208 } |
140 | 209 |
141 if (!DBusThreadManager::IsUsingStub(IMAGE_BURNER)) | 210 if (!DBusThreadManager::IsUsingStub(IMAGE_BURNER)) |
142 image_burner_client_.reset(ImageBurnerClient::Create()); | 211 image_burner_client_.reset(ImageBurnerClient::Create()); |
| 212 else |
| 213 image_burner_client_.reset(new FakeImageBurnerClient); |
143 | 214 |
144 if (!DBusThreadManager::IsUsingStub(INTROSPECTABLE)) | 215 if (!DBusThreadManager::IsUsingStub(INTROSPECTABLE)) |
145 introspectable_client_.reset(IntrospectableClient::Create()); | 216 introspectable_client_.reset(IntrospectableClient::Create()); |
| 217 else |
| 218 introspectable_client_.reset(new FakeIntrospectableClient); |
146 | 219 |
147 if (!DBusThreadManager::IsUsingStub(MODEM_MESSAGING)) | 220 if (!DBusThreadManager::IsUsingStub(MODEM_MESSAGING)) |
148 modem_messaging_client_.reset(ModemMessagingClient::Create()); | 221 modem_messaging_client_.reset(ModemMessagingClient::Create()); |
| 222 else |
| 223 modem_messaging_client_.reset(ModemMessagingClient::Create()); |
149 | 224 |
150 // Create the NFC clients in the correct order based on their dependencies. | 225 // Create the NFC clients in the correct order based on their dependencies. |
151 if (!DBusThreadManager::IsUsingStub(NFC)) { | 226 if (!DBusThreadManager::IsUsingStub(NFC)) { |
152 nfc_manager_client_.reset(NfcManagerClient::Create()); | 227 nfc_manager_client_.reset(NfcManagerClient::Create()); |
153 nfc_adapter_client_.reset( | 228 nfc_adapter_client_.reset( |
154 NfcAdapterClient::Create(nfc_manager_client_.get())); | 229 NfcAdapterClient::Create(nfc_manager_client_.get())); |
155 nfc_device_client_.reset( | 230 nfc_device_client_.reset( |
156 NfcDeviceClient::Create(nfc_adapter_client_.get())); | 231 NfcDeviceClient::Create(nfc_adapter_client_.get())); |
157 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); | 232 nfc_tag_client_.reset(NfcTagClient::Create(nfc_adapter_client_.get())); |
158 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), | 233 nfc_record_client_.reset(NfcRecordClient::Create(nfc_device_client_.get(), |
159 nfc_tag_client_.get())); | 234 nfc_tag_client_.get())); |
| 235 } else { |
| 236 nfc_manager_client_.reset(new FakeNfcManagerClient); |
| 237 nfc_adapter_client_.reset(new FakeNfcAdapterClient); |
| 238 nfc_device_client_.reset(new FakeNfcDeviceClient); |
| 239 nfc_tag_client_.reset(new FakeNfcTagClient); |
| 240 nfc_record_client_.reset(new FakeNfcRecordClient); |
160 } | 241 } |
161 | 242 |
162 if (!DBusThreadManager::IsUsingStub(PERMISSION_BROKER)) | 243 if (!DBusThreadManager::IsUsingStub(PERMISSION_BROKER)) |
163 permission_broker_client_.reset(PermissionBrokerClient::Create()); | 244 permission_broker_client_.reset(PermissionBrokerClient::Create()); |
| 245 else |
| 246 permission_broker_client_.reset(new FakePermissionBrokerClient); |
164 | 247 |
165 if (!DBusThreadManager::IsUsingStub(POWER_MANAGER)) | 248 power_manager_client_.reset(PowerManagerClient::Create( |
166 power_manager_client_.reset(PowerManagerClient::Create(type)); | 249 DBusThreadManager::IsUsingStub(CROS_DISKS) ? |
| 250 STUB_DBUS_CLIENT_IMPLEMENTATION : |
| 251 REAL_DBUS_CLIENT_IMPLEMENTATION)); |
167 | 252 |
168 if (!DBusThreadManager::IsUsingStub(SESSION_MANAGER)) | 253 session_manager_client_.reset(SessionManagerClient::Create( |
169 session_manager_client_.reset(SessionManagerClient::Create(type)); | 254 DBusThreadManager::IsUsingStub(CROS_DISKS) ? |
| 255 STUB_DBUS_CLIENT_IMPLEMENTATION : |
| 256 REAL_DBUS_CLIENT_IMPLEMENTATION)); |
170 | 257 |
171 if (!DBusThreadManager::IsUsingStub(SMS)) | 258 if (!DBusThreadManager::IsUsingStub(SMS)) |
172 sms_client_.reset(SMSClient::Create()); | 259 sms_client_.reset(SMSClient::Create()); |
| 260 else |
| 261 sms_client_.reset(new FakeSMSClient); |
173 | 262 |
174 if (!DBusThreadManager::IsUsingStub(SYSTEM_CLOCK)) | 263 if (!DBusThreadManager::IsUsingStub(SYSTEM_CLOCK)) |
175 system_clock_client_.reset(SystemClockClient::Create()); | 264 system_clock_client_.reset(SystemClockClient::Create()); |
| 265 else |
| 266 system_clock_client_.reset(new FakeSystemClockClient); |
176 | 267 |
177 if (!DBusThreadManager::IsUsingStub(UPDATE_ENGINE)) | 268 update_engine_client_.reset(UpdateEngineClient::Create( |
178 update_engine_client_.reset(UpdateEngineClient::Create(type)); | 269 DBusThreadManager::IsUsingStub(CROS_DISKS) ? |
| 270 STUB_DBUS_CLIENT_IMPLEMENTATION : |
| 271 REAL_DBUS_CLIENT_IMPLEMENTATION)); |
179 } | 272 } |
180 | 273 |
181 DBusClientBundle::~DBusClientBundle() { | 274 DBusClientBundle::~DBusClientBundle() { |
182 } | 275 } |
183 | 276 |
| 277 void DBusClientBundle::SetupDefaultEnvironment() { |
| 278 ShillManagerClient::TestInterface* manager = |
| 279 shill_manager_client_->GetTestInterface(); |
| 280 if (manager) |
| 281 manager->SetupDefaultEnvironment(); |
| 282 } |
| 283 |
184 // static | 284 // static |
185 DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList( | 285 DBusClientBundle::DBusClientTypeMask DBusClientBundle::ParseUnstubList( |
186 const std::string& unstub_list) { | 286 const std::string& unstub_list) { |
187 DBusClientTypeMask unstub_mask = 0; | 287 DBusClientTypeMask unstub_mask = 0; |
188 std::vector<std::string> unstub_components; | 288 std::vector<std::string> unstub_components; |
189 base::SplitString(unstub_list, ',', &unstub_components); | 289 base::SplitString(unstub_list, ',', &unstub_components); |
190 for (std::vector<std::string>::const_iterator iter = | 290 for (std::vector<std::string>::const_iterator iter = |
191 unstub_components.begin(); | 291 unstub_components.begin(); |
192 iter != unstub_components.end(); ++iter) { | 292 iter != unstub_components.end(); ++iter) { |
193 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); | 293 DBusClientBundle::DBusClientType client = GetDBusClientType(*iter); |
194 if (client != DBusClientBundle::NO_CLIENTS) { | 294 if (client != DBusClientBundle::NO_CLIENTS) { |
195 LOG(WARNING) << "Unstubbing dbus client for " << *iter; | 295 LOG(WARNING) << "Unstubbing dbus client for " << *iter; |
196 unstub_mask |= client; | 296 unstub_mask |= client; |
197 } else { | 297 } else { |
198 LOG(ERROR) << "Unknown dbus client: " << *iter; | 298 LOG(ERROR) << "Unknown dbus client: " << *iter; |
199 } | 299 } |
200 } | 300 } |
201 | 301 |
202 return unstub_mask; | 302 return unstub_mask; |
203 } | 303 } |
204 | 304 |
205 } // namespace chromeos | 305 } // namespace chromeos |
OLD | NEW |