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