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 3 // found in the LICENSE file. 4 5 #include "chromeos/dbus/fake_dbus_thread_manager.h" 6 7 #include "base/command_line.h" 8 #include "chromeos/chromeos_switches.h" 9 #include "chromeos/dbus/cras_audio_client_stub_impl.h" 10 #include "chromeos/dbus/cros_disks_client.h" 11 #include "chromeos/dbus/dbus_client.h" 12 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager_observer.h" 14 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" 15 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" 16 #include "chromeos/dbus/fake_bluetooth_device_client.h" 17 #include "chromeos/dbus/fake_bluetooth_gatt_characteristic_client.h" 18 #include "chromeos/dbus/fake_bluetooth_gatt_descriptor_client.h" 19 #include "chromeos/dbus/fake_bluetooth_gatt_manager_client.h" 20 #include "chromeos/dbus/fake_bluetooth_gatt_service_client.h" 21 #include "chromeos/dbus/fake_bluetooth_input_client.h" 22 #include "chromeos/dbus/fake_bluetooth_profile_manager_client.h" 23 #include "chromeos/dbus/fake_cryptohome_client.h" 24 #include "chromeos/dbus/fake_debug_daemon_client.h" 25 #include "chromeos/dbus/fake_gsm_sms_client.h" 26 #include "chromeos/dbus/fake_image_burner_client.h" 27 #include "chromeos/dbus/fake_introspectable_client.h" 28 #include "chromeos/dbus/fake_lorgnette_manager_client.h" 29 #include "chromeos/dbus/fake_modem_messaging_client.h" 30 #include "chromeos/dbus/fake_nfc_adapter_client.h" 31 #include "chromeos/dbus/fake_nfc_device_client.h" 32 #include "chromeos/dbus/fake_nfc_manager_client.h" 33 #include "chromeos/dbus/fake_nfc_record_client.h" 34 #include "chromeos/dbus/fake_nfc_tag_client.h" 35 #include "chromeos/dbus/fake_permission_broker_client.h" 36 #include "chromeos/dbus/fake_shill_device_client.h" 37 #include "chromeos/dbus/fake_shill_ipconfig_client.h" 38 #include "chromeos/dbus/fake_shill_manager_client.h" 39 #include "chromeos/dbus/fake_shill_profile_client.h" 40 #include "chromeos/dbus/fake_shill_service_client.h" 41 #include "chromeos/dbus/fake_sms_client.h" 42 #include "chromeos/dbus/fake_system_clock_client.h" 43 #include "chromeos/dbus/power_manager_client.h" 44 #include "chromeos/dbus/power_policy_controller.h" 45 #include "chromeos/dbus/session_manager_client.h" 46 #include "chromeos/dbus/update_engine_client.h" 47 48 namespace chromeos { 49 50 FakeDBusThreadManager::FakeDBusThreadManager() { 51 } 52 53 FakeDBusThreadManager::~FakeDBusThreadManager() { 54 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, 55 OnDBusThreadManagerDestroying(this)); 56 } 57 58 void FakeDBusThreadManager::SetFakeClients() { 59 const DBusClientImplementationType client_type = 60 STUB_DBUS_CLIENT_IMPLEMENTATION; 61 SetBluetoothAdapterClient( 62 scoped_ptr<BluetoothAdapterClient>(new FakeBluetoothAdapterClient)); 63 SetBluetoothAgentManagerClient(scoped_ptr<BluetoothAgentManagerClient>( 64 new FakeBluetoothAgentManagerClient)); 65 SetBluetoothDeviceClient( 66 scoped_ptr<BluetoothDeviceClient>(new FakeBluetoothDeviceClient)); 67 SetBluetoothGattCharacteristicClient( 68 scoped_ptr<BluetoothGattCharacteristicClient>( 69 new FakeBluetoothGattCharacteristicClient)); 70 SetBluetoothGattDescriptorClient(scoped_ptr<BluetoothGattDescriptorClient>( 71 new FakeBluetoothGattDescriptorClient)); 72 SetBluetoothGattManagerClient(scoped_ptr<BluetoothGattManagerClient>( 73 new FakeBluetoothGattManagerClient)); 74 SetBluetoothGattServiceClient(scoped_ptr<BluetoothGattServiceClient>( 75 new FakeBluetoothGattServiceClient)); 76 SetBluetoothInputClient( 77 scoped_ptr<BluetoothInputClient>(new FakeBluetoothInputClient)); 78 SetBluetoothProfileManagerClient(scoped_ptr<BluetoothProfileManagerClient>( 79 new FakeBluetoothProfileManagerClient)); 80 SetCrosDisksClient( 81 scoped_ptr<CrosDisksClient>(CrosDisksClient::Create(client_type))); 82 SetCrasAudioClient(scoped_ptr<CrasAudioClient>(new CrasAudioClientStubImpl)); 83 SetCryptohomeClient(scoped_ptr<CryptohomeClient>(new FakeCryptohomeClient)); 84 SetDebugDaemonClient( 85 scoped_ptr<DebugDaemonClient>(new FakeDebugDaemonClient)); 86 SetLorgnetteManagerClient( 87 scoped_ptr<LorgnetteManagerClient>(new FakeLorgnetteManagerClient)); 88 89 SetFakeShillClients(); 90 91 FakeGsmSMSClient* gsm_sms_client = new FakeGsmSMSClient(); 92 gsm_sms_client->set_sms_test_message_switch_present( 93 CommandLine::ForCurrentProcess()->HasSwitch( 94 chromeos::switches::kSmsTestMessages)); 95 SetGsmSMSClient(scoped_ptr<GsmSMSClient>(gsm_sms_client)); 96 97 SetImageBurnerClient( 98 scoped_ptr<ImageBurnerClient>(new FakeImageBurnerClient)); 99 SetIntrospectableClient( 100 scoped_ptr<IntrospectableClient>(new FakeIntrospectableClient)); 101 SetModemMessagingClient( 102 scoped_ptr<ModemMessagingClient>(new FakeModemMessagingClient)); 103 SetNfcAdapterClient(scoped_ptr<NfcAdapterClient>(new FakeNfcAdapterClient)); 104 SetNfcDeviceClient(scoped_ptr<NfcDeviceClient>(new FakeNfcDeviceClient)); 105 SetNfcManagerClient(scoped_ptr<NfcManagerClient>(new FakeNfcManagerClient)); 106 SetNfcRecordClient(scoped_ptr<NfcRecordClient>(new FakeNfcRecordClient)); 107 SetNfcTagClient(scoped_ptr<NfcTagClient>(new FakeNfcTagClient)); 108 SetPermissionBrokerClient( 109 scoped_ptr<PermissionBrokerClient>(new FakePermissionBrokerClient)); 110 SetPowerManagerClient( 111 scoped_ptr<PowerManagerClient>(PowerManagerClient::Create(client_type))); 112 SetSessionManagerClient(scoped_ptr<SessionManagerClient>( 113 SessionManagerClient::Create(client_type))); 114 SetSMSClient(scoped_ptr<SMSClient>(new FakeSMSClient)); 115 SetSystemClockClient( 116 scoped_ptr<SystemClockClient>(new FakeSystemClockClient)); 117 SetUpdateEngineClient( 118 scoped_ptr<UpdateEngineClient>(UpdateEngineClient::Create(client_type))); 119 120 SetPowerPolicyController(make_scoped_ptr(new PowerPolicyController)); 121 } 122 123 void FakeDBusThreadManager::SetFakeShillClients() { 124 SetShillManagerClient( 125 scoped_ptr<ShillManagerClient>(new FakeShillManagerClient)); 126 SetShillDeviceClient( 127 scoped_ptr<ShillDeviceClient>(new FakeShillDeviceClient)); 128 SetShillIPConfigClient( 129 scoped_ptr<ShillIPConfigClient>(new FakeShillIPConfigClient)); 130 SetShillServiceClient( 131 scoped_ptr<ShillServiceClient>(new FakeShillServiceClient)); 132 SetShillProfileClient( 133 scoped_ptr<ShillProfileClient>(new FakeShillProfileClient)); 134 } 135 136 void FakeDBusThreadManager::SetupDefaultEnvironment() { 137 ShillManagerClient::TestInterface* manager = 138 shill_manager_client_->GetTestInterface(); 139 if (manager) 140 manager->SetupDefaultEnvironment(); 141 } 142 143 void FakeDBusThreadManager::SetBluetoothAdapterClient( 144 scoped_ptr<BluetoothAdapterClient> client) { 145 bluetooth_adapter_client_ = client.Pass(); 146 } 147 148 void FakeDBusThreadManager::SetBluetoothAgentManagerClient( 149 scoped_ptr<BluetoothAgentManagerClient> client) { 150 bluetooth_agent_manager_client_ = client.Pass(); 151 } 152 153 void FakeDBusThreadManager::SetBluetoothDeviceClient( 154 scoped_ptr<BluetoothDeviceClient> client) { 155 bluetooth_device_client_ = client.Pass(); 156 } 157 158 void FakeDBusThreadManager::SetBluetoothGattCharacteristicClient( 159 scoped_ptr<BluetoothGattCharacteristicClient> client) { 160 bluetooth_gatt_characteristic_client_ = client.Pass(); 161 } 162 163 void FakeDBusThreadManager::SetBluetoothGattDescriptorClient( 164 scoped_ptr<BluetoothGattDescriptorClient> client) { 165 bluetooth_gatt_descriptor_client_ = client.Pass(); 166 } 167 168 void FakeDBusThreadManager::SetBluetoothGattManagerClient( 169 scoped_ptr<BluetoothGattManagerClient> client) { 170 bluetooth_gatt_manager_client_ = client.Pass(); 171 } 172 173 void FakeDBusThreadManager::SetBluetoothGattServiceClient( 174 scoped_ptr<BluetoothGattServiceClient> client) { 175 bluetooth_gatt_service_client_ = client.Pass(); 176 } 177 178 void FakeDBusThreadManager::SetBluetoothInputClient( 179 scoped_ptr<BluetoothInputClient> client) { 180 bluetooth_input_client_ = client.Pass(); 181 } 182 183 void FakeDBusThreadManager::SetBluetoothProfileManagerClient( 184 scoped_ptr<BluetoothProfileManagerClient> client) { 185 bluetooth_profile_manager_client_ = client.Pass(); 186 } 187 188 void FakeDBusThreadManager::SetCrasAudioClient( 189 scoped_ptr<CrasAudioClient> client) { 190 cras_audio_client_ = client.Pass(); 191 } 192 193 void FakeDBusThreadManager::SetCrosDisksClient( 194 scoped_ptr<CrosDisksClient> client) { 195 cros_disks_client_ = client.Pass(); 196 } 197 198 void FakeDBusThreadManager::SetCryptohomeClient( 199 scoped_ptr<CryptohomeClient> client) { 200 cryptohome_client_ = client.Pass(); 201 } 202 203 void FakeDBusThreadManager::SetDebugDaemonClient( 204 scoped_ptr<DebugDaemonClient> client) { 205 debug_daemon_client_ = client.Pass(); 206 } 207 208 void FakeDBusThreadManager::SetLorgnetteManagerClient( 209 scoped_ptr<LorgnetteManagerClient> client) { 210 lorgnette_manager_client_ = client.Pass(); 211 } 212 213 void FakeDBusThreadManager::SetShillDeviceClient( 214 scoped_ptr<ShillDeviceClient> client) { 215 shill_device_client_ = client.Pass(); 216 } 217 218 void FakeDBusThreadManager::SetShillIPConfigClient( 219 scoped_ptr<ShillIPConfigClient> client) { 220 shill_ipconfig_client_ = client.Pass(); 221 } 222 223 void FakeDBusThreadManager::SetShillManagerClient( 224 scoped_ptr<ShillManagerClient> client) { 225 shill_manager_client_ = client.Pass(); 226 } 227 228 void FakeDBusThreadManager::SetShillServiceClient( 229 scoped_ptr<ShillServiceClient> client) { 230 shill_service_client_ = client.Pass(); 231 } 232 233 void FakeDBusThreadManager::SetShillProfileClient( 234 scoped_ptr<ShillProfileClient> client) { 235 shill_profile_client_ = client.Pass(); 236 } 237 238 void FakeDBusThreadManager::SetGsmSMSClient( 239 scoped_ptr<GsmSMSClient> client) { 240 gsm_sms_client_ = client.Pass(); 241 } 242 243 void FakeDBusThreadManager::SetImageBurnerClient( 244 scoped_ptr<ImageBurnerClient> client) { 245 image_burner_client_ = client.Pass(); 246 } 247 248 void FakeDBusThreadManager::SetIntrospectableClient( 249 scoped_ptr<IntrospectableClient> client) { 250 introspectable_client_ = client.Pass(); 251 } 252 253 void FakeDBusThreadManager::SetModemMessagingClient( 254 scoped_ptr<ModemMessagingClient> client) { 255 modem_messaging_client_ = client.Pass(); 256 } 257 258 void FakeDBusThreadManager::SetNfcAdapterClient( 259 scoped_ptr<NfcAdapterClient> client) { 260 nfc_adapter_client_ = client.Pass(); 261 } 262 263 void FakeDBusThreadManager::SetNfcDeviceClient( 264 scoped_ptr<NfcDeviceClient> client) { 265 nfc_device_client_ = client.Pass(); 266 } 267 268 void FakeDBusThreadManager::SetNfcManagerClient( 269 scoped_ptr<NfcManagerClient> client) { 270 nfc_manager_client_ = client.Pass(); 271 } 272 273 void FakeDBusThreadManager::SetNfcRecordClient( 274 scoped_ptr<NfcRecordClient> client) { 275 nfc_record_client_ = client.Pass(); 276 } 277 278 void FakeDBusThreadManager::SetNfcTagClient( 279 scoped_ptr<NfcTagClient> client) { 280 nfc_tag_client_ = client.Pass(); 281 } 282 283 void FakeDBusThreadManager::SetPermissionBrokerClient( 284 scoped_ptr<PermissionBrokerClient> client) { 285 permission_broker_client_ = client.Pass(); 286 } 287 288 void FakeDBusThreadManager::SetPowerManagerClient( 289 scoped_ptr<PowerManagerClient> client) { 290 power_manager_client_ = client.Pass(); 291 } 292 293 void FakeDBusThreadManager::SetPowerPolicyController( 294 scoped_ptr<PowerPolicyController> client) { 295 power_policy_controller_ = client.Pass(); 296 } 297 298 void FakeDBusThreadManager::SetSessionManagerClient( 299 scoped_ptr<SessionManagerClient> client) { 300 session_manager_client_ = client.Pass(); 301 } 302 303 void FakeDBusThreadManager::SetSMSClient(scoped_ptr<SMSClient> client) { 304 sms_client_ = client.Pass(); 305 } 306 307 void FakeDBusThreadManager::SetSystemClockClient( 308 scoped_ptr<SystemClockClient> client) { 309 system_clock_client_ = client.Pass(); 310 } 311 312 void FakeDBusThreadManager::SetUpdateEngineClient( 313 scoped_ptr<UpdateEngineClient> client) { 314 update_engine_client_ = client.Pass(); 315 } 316 317 void FakeDBusThreadManager::AddObserver( 318 DBusThreadManagerObserver* observer) { 319 DCHECK(observer); 320 observers_.AddObserver(observer); 321 } 322 323 void FakeDBusThreadManager::RemoveObserver( 324 DBusThreadManagerObserver* observer) { 325 DCHECK(observer); 326 observers_.RemoveObserver(observer); 327 } 328 329 dbus::Bus* FakeDBusThreadManager::GetSystemBus() { 330 return NULL; 331 } 332 333 BluetoothAdapterClient* 334 FakeDBusThreadManager::GetBluetoothAdapterClient() { 335 return bluetooth_adapter_client_.get(); 336 } 337 338 BluetoothAgentManagerClient* 339 FakeDBusThreadManager::GetBluetoothAgentManagerClient() { 340 return bluetooth_agent_manager_client_.get(); 341 } 342 343 BluetoothDeviceClient* 344 FakeDBusThreadManager::GetBluetoothDeviceClient() { 345 return bluetooth_device_client_.get(); 346 } 347 348 BluetoothGattCharacteristicClient* 349 FakeDBusThreadManager::GetBluetoothGattCharacteristicClient() { 350 return bluetooth_gatt_characteristic_client_.get(); 351 } 352 353 BluetoothGattDescriptorClient* 354 FakeDBusThreadManager::GetBluetoothGattDescriptorClient() { 355 return bluetooth_gatt_descriptor_client_.get(); 356 } 357 358 BluetoothGattManagerClient* 359 FakeDBusThreadManager::GetBluetoothGattManagerClient() { 360 return bluetooth_gatt_manager_client_.get(); 361 } 362 363 BluetoothGattServiceClient* 364 FakeDBusThreadManager::GetBluetoothGattServiceClient() { 365 return bluetooth_gatt_service_client_.get(); 366 } 367 368 BluetoothInputClient* 369 FakeDBusThreadManager::GetBluetoothInputClient() { 370 return bluetooth_input_client_.get(); 371 } 372 373 BluetoothProfileManagerClient* 374 FakeDBusThreadManager::GetBluetoothProfileManagerClient() { 375 return bluetooth_profile_manager_client_.get(); 376 } 377 378 CrasAudioClient* FakeDBusThreadManager::GetCrasAudioClient() { 379 return cras_audio_client_.get(); 380 } 381 382 CrosDisksClient* FakeDBusThreadManager::GetCrosDisksClient() { 383 return cros_disks_client_.get(); 384 } 385 386 CryptohomeClient* FakeDBusThreadManager::GetCryptohomeClient() { 387 return cryptohome_client_.get(); 388 } 389 390 DebugDaemonClient* FakeDBusThreadManager::GetDebugDaemonClient() { 391 return debug_daemon_client_.get(); 392 } 393 394 LorgnetteManagerClient* FakeDBusThreadManager::GetLorgnetteManagerClient() { 395 return lorgnette_manager_client_.get(); 396 } 397 398 ShillDeviceClient* 399 FakeDBusThreadManager::GetShillDeviceClient() { 400 return shill_device_client_.get(); 401 } 402 403 ShillIPConfigClient* 404 FakeDBusThreadManager::GetShillIPConfigClient() { 405 return shill_ipconfig_client_.get(); 406 } 407 408 ShillManagerClient* 409 FakeDBusThreadManager::GetShillManagerClient() { 410 return shill_manager_client_.get(); 411 } 412 413 ShillProfileClient* 414 FakeDBusThreadManager::GetShillProfileClient() { 415 return shill_profile_client_.get(); 416 } 417 418 ShillServiceClient* 419 FakeDBusThreadManager::GetShillServiceClient() { 420 return shill_service_client_.get(); 421 } 422 423 GsmSMSClient* FakeDBusThreadManager::GetGsmSMSClient() { 424 return gsm_sms_client_.get(); 425 } 426 427 ImageBurnerClient* FakeDBusThreadManager::GetImageBurnerClient() { 428 return image_burner_client_.get(); 429 } 430 431 IntrospectableClient* 432 FakeDBusThreadManager::GetIntrospectableClient() { 433 return introspectable_client_.get(); 434 } 435 436 ModemMessagingClient* 437 FakeDBusThreadManager::GetModemMessagingClient() { 438 return modem_messaging_client_.get(); 439 } 440 441 NfcAdapterClient* FakeDBusThreadManager::GetNfcAdapterClient() { 442 return nfc_adapter_client_.get(); 443 } 444 445 NfcDeviceClient* FakeDBusThreadManager::GetNfcDeviceClient() { 446 return nfc_device_client_.get(); 447 } 448 449 NfcManagerClient* FakeDBusThreadManager::GetNfcManagerClient() { 450 return nfc_manager_client_.get(); 451 } 452 453 NfcTagClient* FakeDBusThreadManager::GetNfcTagClient() { 454 return nfc_tag_client_.get(); 455 } 456 457 NfcRecordClient* FakeDBusThreadManager::GetNfcRecordClient() { 458 return nfc_record_client_.get(); 459 } 460 461 PermissionBrokerClient* 462 FakeDBusThreadManager::GetPermissionBrokerClient() { 463 return permission_broker_client_.get(); 464 } 465 466 PowerManagerClient* FakeDBusThreadManager::GetPowerManagerClient() { 467 return power_manager_client_.get(); 468 } 469 470 PowerPolicyController* 471 FakeDBusThreadManager::GetPowerPolicyController() { 472 return power_policy_controller_.get(); 473 } 474 475 SessionManagerClient* 476 FakeDBusThreadManager::GetSessionManagerClient() { 477 return session_manager_client_.get(); 478 } 479 480 SMSClient* FakeDBusThreadManager::GetSMSClient() { 481 return sms_client_.get(); 482 } 483 484 SystemClockClient* FakeDBusThreadManager::GetSystemClockClient() { 485 return system_clock_client_.get(); 486 } 487 488 UpdateEngineClient* FakeDBusThreadManager::GetUpdateEngineClient() { 489 return update_engine_client_.get(); 490 } 491 492 } // namespace chromeos 493