Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/fake_dbus_thread_manager.h" | 5 #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" | |
| 9 #include "base/strings/string_split.h" | |
| 10 #include "base/strings/string_util.h" | |
| 8 #include "chromeos/chromeos_switches.h" | 11 #include "chromeos/chromeos_switches.h" |
| 9 #include "chromeos/dbus/cras_audio_client_stub_impl.h" | 12 #include "chromeos/dbus/cras_audio_client_stub_impl.h" |
| 10 #include "chromeos/dbus/cros_disks_client.h" | 13 #include "chromeos/dbus/cros_disks_client.h" |
| 11 #include "chromeos/dbus/dbus_client.h" | 14 #include "chromeos/dbus/dbus_client.h" |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager_observer.h" | 16 #include "chromeos/dbus/dbus_thread_manager_observer.h" |
| 14 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" | 17 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
| 15 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" | 18 #include "chromeos/dbus/fake_bluetooth_agent_manager_client.h" |
| 16 #include "chromeos/dbus/fake_bluetooth_device_client.h" | 19 #include "chromeos/dbus/fake_bluetooth_device_client.h" |
| 17 #include "chromeos/dbus/fake_bluetooth_input_client.h" | 20 #include "chromeos/dbus/fake_bluetooth_input_client.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 32 #include "chromeos/dbus/fake_shill_ipconfig_client.h" | 35 #include "chromeos/dbus/fake_shill_ipconfig_client.h" |
| 33 #include "chromeos/dbus/fake_shill_manager_client.h" | 36 #include "chromeos/dbus/fake_shill_manager_client.h" |
| 34 #include "chromeos/dbus/fake_shill_profile_client.h" | 37 #include "chromeos/dbus/fake_shill_profile_client.h" |
| 35 #include "chromeos/dbus/fake_shill_service_client.h" | 38 #include "chromeos/dbus/fake_shill_service_client.h" |
| 36 #include "chromeos/dbus/fake_sms_client.h" | 39 #include "chromeos/dbus/fake_sms_client.h" |
| 37 #include "chromeos/dbus/fake_system_clock_client.h" | 40 #include "chromeos/dbus/fake_system_clock_client.h" |
| 38 #include "chromeos/dbus/power_manager_client.h" | 41 #include "chromeos/dbus/power_manager_client.h" |
| 39 #include "chromeos/dbus/power_policy_controller.h" | 42 #include "chromeos/dbus/power_policy_controller.h" |
| 40 #include "chromeos/dbus/session_manager_client.h" | 43 #include "chromeos/dbus/session_manager_client.h" |
| 41 #include "chromeos/dbus/update_engine_client.h" | 44 #include "chromeos/dbus/update_engine_client.h" |
| 45 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 42 | 46 |
| 43 namespace chromeos { | 47 namespace chromeos { |
| 44 | 48 |
| 45 FakeDBusThreadManager::FakeDBusThreadManager() { | 49 FakeDBusThreadManager::FakeDBusThreadManager() |
| 50 : power_cycle_delay_(0), | |
| 51 shill_interactive_delay_(0) { | |
| 46 } | 52 } |
| 47 | 53 |
| 48 FakeDBusThreadManager::~FakeDBusThreadManager() { | 54 FakeDBusThreadManager::~FakeDBusThreadManager() { |
| 49 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, | 55 FOR_EACH_OBSERVER(DBusThreadManagerObserver, observers_, |
| 50 OnDBusThreadManagerDestroying(this)); | 56 OnDBusThreadManagerDestroying(this)); |
| 51 } | 57 } |
| 52 | 58 |
| 53 void FakeDBusThreadManager::SetFakeClients() { | 59 void FakeDBusThreadManager::SetFakeClients() { |
| 54 const DBusClientImplementationType client_type = | 60 const DBusClientImplementationType client_type = |
| 55 STUB_DBUS_CLIENT_IMPLEMENTATION; | 61 STUB_DBUS_CLIENT_IMPLEMENTATION; |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 84 scoped_ptr<IntrospectableClient>(new FakeIntrospectableClient)); | 90 scoped_ptr<IntrospectableClient>(new FakeIntrospectableClient)); |
| 85 SetModemMessagingClient( | 91 SetModemMessagingClient( |
| 86 scoped_ptr<ModemMessagingClient>(new FakeModemMessagingClient)); | 92 scoped_ptr<ModemMessagingClient>(new FakeModemMessagingClient)); |
| 87 SetNfcAdapterClient(scoped_ptr<NfcAdapterClient>(new FakeNfcAdapterClient)); | 93 SetNfcAdapterClient(scoped_ptr<NfcAdapterClient>(new FakeNfcAdapterClient)); |
| 88 SetNfcDeviceClient(scoped_ptr<NfcDeviceClient>(new FakeNfcDeviceClient)); | 94 SetNfcDeviceClient(scoped_ptr<NfcDeviceClient>(new FakeNfcDeviceClient)); |
| 89 SetNfcManagerClient(scoped_ptr<NfcManagerClient>(new FakeNfcManagerClient)); | 95 SetNfcManagerClient(scoped_ptr<NfcManagerClient>(new FakeNfcManagerClient)); |
| 90 SetNfcRecordClient(scoped_ptr<NfcRecordClient>(new FakeNfcRecordClient)); | 96 SetNfcRecordClient(scoped_ptr<NfcRecordClient>(new FakeNfcRecordClient)); |
| 91 SetNfcTagClient(scoped_ptr<NfcTagClient>(new FakeNfcTagClient)); | 97 SetNfcTagClient(scoped_ptr<NfcTagClient>(new FakeNfcTagClient)); |
| 92 SetPermissionBrokerClient( | 98 SetPermissionBrokerClient( |
| 93 scoped_ptr<PermissionBrokerClient>(new FakePermissionBrokerClient)); | 99 scoped_ptr<PermissionBrokerClient>(new FakePermissionBrokerClient)); |
| 100 | |
| 101 ParsePowerCommandLineSwitch(); | |
| 94 SetPowerManagerClient( | 102 SetPowerManagerClient( |
| 95 scoped_ptr<PowerManagerClient>(PowerManagerClient::Create(client_type))); | 103 scoped_ptr<PowerManagerClient>(PowerManagerClient::Create(client_type))); |
| 104 | |
| 96 SetSessionManagerClient(scoped_ptr<SessionManagerClient>( | 105 SetSessionManagerClient(scoped_ptr<SessionManagerClient>( |
| 97 SessionManagerClient::Create(client_type))); | 106 SessionManagerClient::Create(client_type))); |
| 98 SetSMSClient(scoped_ptr<SMSClient>(new FakeSMSClient)); | 107 SetSMSClient(scoped_ptr<SMSClient>(new FakeSMSClient)); |
| 99 SetSystemClockClient( | 108 SetSystemClockClient( |
| 100 scoped_ptr<SystemClockClient>(new FakeSystemClockClient)); | 109 scoped_ptr<SystemClockClient>(new FakeSystemClockClient)); |
| 101 SetUpdateEngineClient( | 110 SetUpdateEngineClient( |
| 102 scoped_ptr<UpdateEngineClient>(UpdateEngineClient::Create(client_type))); | 111 scoped_ptr<UpdateEngineClient>(UpdateEngineClient::Create(client_type))); |
| 103 | 112 |
| 104 SetPowerPolicyController(make_scoped_ptr(new PowerPolicyController)); | 113 SetPowerPolicyController(make_scoped_ptr(new PowerPolicyController)); |
| 105 } | 114 } |
| 106 | 115 |
| 107 void FakeDBusThreadManager::SetFakeShillClients() { | 116 void FakeDBusThreadManager::SetFakeShillClients() { |
| 117 ParseShillCommandLineSwitch(); | |
| 118 | |
| 108 SetShillManagerClient( | 119 SetShillManagerClient( |
| 109 scoped_ptr<ShillManagerClient>(new FakeShillManagerClient)); | 120 scoped_ptr<ShillManagerClient>(new FakeShillManagerClient)); |
|
pneubeck (no reviews)
2014/02/27 09:04:37
here you could pass the options or 'this'.
stevenjb
2014/02/28 02:44:06
Implementation moved.
| |
| 110 SetShillDeviceClient( | 121 SetShillDeviceClient( |
| 111 scoped_ptr<ShillDeviceClient>(new FakeShillDeviceClient)); | 122 scoped_ptr<ShillDeviceClient>(new FakeShillDeviceClient)); |
| 112 SetShillIPConfigClient( | 123 SetShillIPConfigClient( |
| 113 scoped_ptr<ShillIPConfigClient>(new FakeShillIPConfigClient)); | 124 scoped_ptr<ShillIPConfigClient>(new FakeShillIPConfigClient)); |
| 114 SetShillServiceClient( | 125 SetShillServiceClient( |
| 115 scoped_ptr<ShillServiceClient>(new FakeShillServiceClient)); | 126 scoped_ptr<ShillServiceClient>(new FakeShillServiceClient)); |
| 116 SetShillProfileClient( | 127 SetShillProfileClient( |
| 117 scoped_ptr<ShillProfileClient>(new FakeShillProfileClient)); | 128 scoped_ptr<ShillProfileClient>(new FakeShillProfileClient)); |
| 118 } | 129 } |
| 119 | 130 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 } | 421 } |
| 411 | 422 |
| 412 SystemClockClient* FakeDBusThreadManager::GetSystemClockClient() { | 423 SystemClockClient* FakeDBusThreadManager::GetSystemClockClient() { |
| 413 return system_clock_client_.get(); | 424 return system_clock_client_.get(); |
| 414 } | 425 } |
| 415 | 426 |
| 416 UpdateEngineClient* FakeDBusThreadManager::GetUpdateEngineClient() { | 427 UpdateEngineClient* FakeDBusThreadManager::GetUpdateEngineClient() { |
| 417 return update_engine_client_.get(); | 428 return update_engine_client_.get(); |
| 418 } | 429 } |
| 419 | 430 |
| 431 int FakeDBusThreadManager::GetPowerCycleDelay() const { | |
| 432 return power_cycle_delay_; | |
| 433 } | |
| 434 | |
| 435 int FakeDBusThreadManager::GetShillInteractiveDelay() const { | |
| 436 return shill_interactive_delay_; | |
| 437 } | |
| 438 | |
| 439 std::string FakeDBusThreadManager::GetShillInitialState( | |
| 440 const std::string& type) const { | |
| 441 std::map<std::string, std::string>::const_iterator iter = | |
| 442 shill_initial_state_map_.find(type); | |
| 443 if (iter == shill_initial_state_map_.end()) | |
| 444 return shill::kStateOffline; // Not available | |
| 445 return iter->second; | |
| 446 } | |
| 447 | |
| 448 // Private methods | |
| 449 | |
| 450 void FakeDBusThreadManager::ParsePowerCommandLineSwitch() { | |
| 451 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 452 std::string option_str = | |
| 453 command_line->GetSwitchValueASCII(switches::kPowerStub); | |
| 454 VLOG(1) << "Power stub switches: " << option_str; | |
| 455 std::vector<std::string> tokens; | |
| 456 base::SplitString(option_str, ',', &tokens); | |
| 457 for (std::vector<std::string>::iterator iter = tokens.begin(); | |
| 458 iter != tokens.end(); ++iter) { | |
| 459 std::string arg0, arg1; | |
| 460 if (!GetOptionArgs(*iter, &arg0, &arg1)) | |
| 461 continue; | |
| 462 if (arg0 == "cycle" || arg0 == "interactive") { | |
| 463 int seconds = 1; | |
| 464 if (!arg1.empty()) | |
| 465 base::StringToInt(arg1, &seconds); | |
| 466 power_cycle_delay_ = seconds; | |
| 467 } else { | |
| 468 LOG(WARNING) << "Unrecognized option: " << *iter; | |
| 469 } | |
| 470 } | |
| 471 } | |
| 472 | |
| 473 void FakeDBusThreadManager::ParseShillCommandLineSwitch() { | |
| 474 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 475 if (!command_line->HasSwitch(switches::kShillStub)) { | |
| 476 // Default setup | |
| 477 SetShillInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); | |
| 478 SetShillInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); | |
| 479 SetShillInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); | |
| 480 SetShillInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); | |
| 481 return; | |
| 482 } | |
| 483 std::string option_str = | |
| 484 command_line->GetSwitchValueASCII(switches::kShillStub); | |
| 485 VLOG(1) << "Shill stub switches: " << option_str; | |
| 486 std::vector<std::string> tokens; | |
| 487 base::SplitString(option_str, ',', &tokens); | |
| 488 for (std::vector<std::string>::iterator iter = tokens.begin(); | |
| 489 iter != tokens.end(); ++iter) { | |
| 490 std::string arg0, arg1; | |
| 491 if (!GetOptionArgs(*iter, &arg0, &arg1)) | |
| 492 continue; | |
| 493 if (arg0 == "interactive") { | |
| 494 int seconds = 3; | |
| 495 if (!arg1.empty()) | |
| 496 base::StringToInt(arg1, &seconds); | |
| 497 shill_interactive_delay_ = seconds; | |
| 498 } else { | |
| 499 SetShillInitialNetworkState(arg0, arg1); | |
| 500 } | |
| 501 } | |
| 502 } | |
| 503 | |
| 504 bool FakeDBusThreadManager::GetOptionArgs(const std::string& option, | |
| 505 std::string* arg0, | |
| 506 std::string* arg1) { | |
| 507 std::vector<std::string> args; | |
| 508 base::SplitString(option, '=', &args); | |
| 509 if (args.size() < 1) { | |
| 510 LOG(WARNING) << " Invalid option: " << option; | |
| 511 arg0->clear(); | |
| 512 arg1->clear(); | |
| 513 return false; | |
| 514 } | |
| 515 *arg0 = args[0]; | |
| 516 if (args.size() >= 2) | |
| 517 *arg1 = args[1]; | |
| 518 else | |
| 519 arg1->clear(); | |
| 520 VLOG(2) << " Option: " << *arg0 << " = " << *arg1; | |
| 521 return true; | |
| 522 } | |
| 523 | |
| 524 void FakeDBusThreadManager::SetShillInitialNetworkState(std::string type_arg, | |
| 525 std::string state_arg) { | |
| 526 std::string state; | |
| 527 state_arg = StringToLowerASCII(state_arg); | |
| 528 if (state_arg == "0" || state_arg == "off" || state_arg == "inactive" || | |
| 529 state_arg == shill::kStateIdle) | |
| 530 state = shill::kStateIdle; // Enabled but not connected | |
| 531 else if (state_arg == "disabled" || state_arg == "disconnect") | |
| 532 state = shill::kStateDisconnect; // Diabled but available | |
| 533 else if (state_arg == "none" || state_arg == "offline") | |
| 534 state = shill::kStateOffline; // Not available | |
| 535 else if (state_arg == "portal") | |
| 536 state = shill::kStatePortal; // Connected to portal | |
| 537 else if (state_arg == "active" || state_arg == "activated") | |
| 538 state = shill::kActivationStateActivated; // Connected and activated | |
| 539 else | |
| 540 state = shill::kStateOnline; // Connected | |
| 541 | |
| 542 std::string type; | |
| 543 type_arg = StringToLowerASCII(type_arg); | |
| 544 if (type_arg == "ethernet" || type_arg == "eth") { | |
| 545 if (state == shill::kStateIdle || state == shill::kStateDisconnect) | |
| 546 state = shill::kStateOffline; // No unconnected or disabled ethernet. | |
| 547 shill_initial_state_map_[shill::kTypeEthernet] = state; | |
| 548 } else if (type_arg == "wifi") { | |
| 549 shill_initial_state_map_[shill::kTypeWifi] = state; | |
| 550 } else if (type_arg == "cellular") { | |
| 551 shill_initial_state_map_[shill::kTypeCellular] = state; | |
| 552 } else if (type_arg == "wireless") { | |
| 553 shill_initial_state_map_[shill::kTypeWifi] = state; | |
| 554 shill_initial_state_map_[shill::kTypeCellular] = state; | |
| 555 } else if (type_arg == "wimax") { | |
| 556 shill_initial_state_map_[shill::kTypeWimax] = state; | |
| 557 } else if (type_arg == "vpn") { | |
| 558 shill_initial_state_map_[shill::kTypeVPN] = state; | |
| 559 } else { | |
| 560 LOG(WARNING) << "Unrecognized type: " << type_arg; | |
| 561 } | |
| 562 } | |
| 563 | |
| 420 } // namespace chromeos | 564 } // namespace chromeos |
| OLD | NEW |