Chromium Code Reviews| Index: chromeos/dbus/fake_dbus_thread_manager.cc |
| diff --git a/chromeos/dbus/fake_dbus_thread_manager.cc b/chromeos/dbus/fake_dbus_thread_manager.cc |
| index a57a7c2f14ac49293cbfcef14d0e3cbe92cfaa1a..ebcf5a9da805d5ff4d2903206bde0237b73910d0 100644 |
| --- a/chromeos/dbus/fake_dbus_thread_manager.cc |
| +++ b/chromeos/dbus/fake_dbus_thread_manager.cc |
| @@ -5,6 +5,9 @@ |
| #include "chromeos/dbus/fake_dbus_thread_manager.h" |
| #include "base/command_line.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| +#include "base/strings/string_util.h" |
| #include "chromeos/chromeos_switches.h" |
| #include "chromeos/dbus/cras_audio_client_stub_impl.h" |
| #include "chromeos/dbus/cros_disks_client.h" |
| @@ -39,10 +42,13 @@ |
| #include "chromeos/dbus/power_policy_controller.h" |
| #include "chromeos/dbus/session_manager_client.h" |
| #include "chromeos/dbus/update_engine_client.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| namespace chromeos { |
| -FakeDBusThreadManager::FakeDBusThreadManager() { |
| +FakeDBusThreadManager::FakeDBusThreadManager() |
| + : power_cycle_delay_(0), |
| + shill_interactive_delay_(0) { |
| } |
| FakeDBusThreadManager::~FakeDBusThreadManager() { |
| @@ -91,8 +97,11 @@ void FakeDBusThreadManager::SetFakeClients() { |
| SetNfcTagClient(scoped_ptr<NfcTagClient>(new FakeNfcTagClient)); |
| SetPermissionBrokerClient( |
| scoped_ptr<PermissionBrokerClient>(new FakePermissionBrokerClient)); |
| + |
| + ParsePowerCommandLineSwitch(); |
| SetPowerManagerClient( |
| scoped_ptr<PowerManagerClient>(PowerManagerClient::Create(client_type))); |
| + |
| SetSessionManagerClient(scoped_ptr<SessionManagerClient>( |
| SessionManagerClient::Create(client_type))); |
| SetSMSClient(scoped_ptr<SMSClient>(new FakeSMSClient)); |
| @@ -105,6 +114,8 @@ void FakeDBusThreadManager::SetFakeClients() { |
| } |
| void FakeDBusThreadManager::SetFakeShillClients() { |
| + ParseShillCommandLineSwitch(); |
| + |
| SetShillManagerClient( |
| 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.
|
| SetShillDeviceClient( |
| @@ -417,4 +428,137 @@ UpdateEngineClient* FakeDBusThreadManager::GetUpdateEngineClient() { |
| return update_engine_client_.get(); |
| } |
| +int FakeDBusThreadManager::GetPowerCycleDelay() const { |
| + return power_cycle_delay_; |
| +} |
| + |
| +int FakeDBusThreadManager::GetShillInteractiveDelay() const { |
| + return shill_interactive_delay_; |
| +} |
| + |
| +std::string FakeDBusThreadManager::GetShillInitialState( |
| + const std::string& type) const { |
| + std::map<std::string, std::string>::const_iterator iter = |
| + shill_initial_state_map_.find(type); |
| + if (iter == shill_initial_state_map_.end()) |
| + return shill::kStateOffline; // Not available |
| + return iter->second; |
| +} |
| + |
| +// Private methods |
| + |
| +void FakeDBusThreadManager::ParsePowerCommandLineSwitch() { |
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + std::string option_str = |
| + command_line->GetSwitchValueASCII(switches::kPowerStub); |
| + VLOG(1) << "Power stub switches: " << option_str; |
| + std::vector<std::string> tokens; |
| + base::SplitString(option_str, ',', &tokens); |
| + for (std::vector<std::string>::iterator iter = tokens.begin(); |
| + iter != tokens.end(); ++iter) { |
| + std::string arg0, arg1; |
| + if (!GetOptionArgs(*iter, &arg0, &arg1)) |
| + continue; |
| + if (arg0 == "cycle" || arg0 == "interactive") { |
| + int seconds = 1; |
| + if (!arg1.empty()) |
| + base::StringToInt(arg1, &seconds); |
| + power_cycle_delay_ = seconds; |
| + } else { |
| + LOG(WARNING) << "Unrecognized option: " << *iter; |
| + } |
| + } |
| +} |
| + |
| +void FakeDBusThreadManager::ParseShillCommandLineSwitch() { |
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (!command_line->HasSwitch(switches::kShillStub)) { |
| + // Default setup |
| + SetShillInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); |
| + SetShillInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); |
| + SetShillInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); |
| + SetShillInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); |
| + return; |
| + } |
| + std::string option_str = |
| + command_line->GetSwitchValueASCII(switches::kShillStub); |
| + VLOG(1) << "Shill stub switches: " << option_str; |
| + std::vector<std::string> tokens; |
| + base::SplitString(option_str, ',', &tokens); |
| + for (std::vector<std::string>::iterator iter = tokens.begin(); |
| + iter != tokens.end(); ++iter) { |
| + std::string arg0, arg1; |
| + if (!GetOptionArgs(*iter, &arg0, &arg1)) |
| + continue; |
| + if (arg0 == "interactive") { |
| + int seconds = 3; |
| + if (!arg1.empty()) |
| + base::StringToInt(arg1, &seconds); |
| + shill_interactive_delay_ = seconds; |
| + } else { |
| + SetShillInitialNetworkState(arg0, arg1); |
| + } |
| + } |
| +} |
| + |
| +bool FakeDBusThreadManager::GetOptionArgs(const std::string& option, |
| + std::string* arg0, |
| + std::string* arg1) { |
| + std::vector<std::string> args; |
| + base::SplitString(option, '=', &args); |
| + if (args.size() < 1) { |
| + LOG(WARNING) << " Invalid option: " << option; |
| + arg0->clear(); |
| + arg1->clear(); |
| + return false; |
| + } |
| + *arg0 = args[0]; |
| + if (args.size() >= 2) |
| + *arg1 = args[1]; |
| + else |
| + arg1->clear(); |
| + VLOG(2) << " Option: " << *arg0 << " = " << *arg1; |
| + return true; |
| +} |
| + |
| +void FakeDBusThreadManager::SetShillInitialNetworkState(std::string type_arg, |
| + std::string state_arg) { |
| + std::string state; |
| + state_arg = StringToLowerASCII(state_arg); |
| + if (state_arg == "0" || state_arg == "off" || state_arg == "inactive" || |
| + state_arg == shill::kStateIdle) |
| + state = shill::kStateIdle; // Enabled but not connected |
| + else if (state_arg == "disabled" || state_arg == "disconnect") |
| + state = shill::kStateDisconnect; // Diabled but available |
| + else if (state_arg == "none" || state_arg == "offline") |
| + state = shill::kStateOffline; // Not available |
| + else if (state_arg == "portal") |
| + state = shill::kStatePortal; // Connected to portal |
| + else if (state_arg == "active" || state_arg == "activated") |
| + state = shill::kActivationStateActivated; // Connected and activated |
| + else |
| + state = shill::kStateOnline; // Connected |
| + |
| + std::string type; |
| + type_arg = StringToLowerASCII(type_arg); |
| + if (type_arg == "ethernet" || type_arg == "eth") { |
| + if (state == shill::kStateIdle || state == shill::kStateDisconnect) |
| + state = shill::kStateOffline; // No unconnected or disabled ethernet. |
| + shill_initial_state_map_[shill::kTypeEthernet] = state; |
| + } else if (type_arg == "wifi") { |
| + shill_initial_state_map_[shill::kTypeWifi] = state; |
| + } else if (type_arg == "cellular") { |
| + shill_initial_state_map_[shill::kTypeCellular] = state; |
| + } else if (type_arg == "wireless") { |
| + shill_initial_state_map_[shill::kTypeWifi] = state; |
| + shill_initial_state_map_[shill::kTypeCellular] = state; |
| + } else if (type_arg == "wimax") { |
| + shill_initial_state_map_[shill::kTypeWimax] = state; |
| + } else if (type_arg == "vpn") { |
| + shill_initial_state_map_[shill::kTypeVPN] = state; |
| + } else { |
| + LOG(WARNING) << "Unrecognized type: " << type_arg; |
| + } |
| +} |
| + |
| } // namespace chromeos |