Index: chromeos/dbus/fake_shill_manager_client.cc |
diff --git a/chromeos/dbus/fake_shill_manager_client.cc b/chromeos/dbus/fake_shill_manager_client.cc |
index d3ad56641aa07e74879092b1a6ad95559420655a..b21ef9660682709c17c23ca9059b1da57294f668 100644 |
--- a/chromeos/dbus/fake_shill_manager_client.cc |
+++ b/chromeos/dbus/fake_shill_manager_client.cc |
@@ -5,10 +5,12 @@ |
#include "chromeos/dbus/fake_shill_manager_client.h" |
#include "base/bind.h" |
-#include "base/command_line.h" |
#include "base/message_loop/message_loop.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "base/strings/string_util.h" |
#include "base/values.h" |
#include "chromeos/chromeos_switches.h" |
+#include "chromeos/dbus/dbus_command_line_helper.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "chromeos/dbus/shill_device_client.h" |
#include "chromeos/dbus/shill_profile_client.h" |
@@ -73,10 +75,23 @@ void AppendServicesForType( |
} |
} |
+void UpdatePortaledWifiState(const std::string& service_path) { |
+ DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface() |
+ ->SetServiceProperty(service_path, |
+ shill::kStateProperty, |
+ base::StringValue(shill::kStatePortal)); |
+} |
+ |
+const char* kTechnologyUnavailable = "unavailable"; |
+const char* kNetworkActivated = "activated"; |
+const char* kNetworkDisabled = "disabled"; |
+ |
} // namespace |
FakeShillManagerClient::FakeShillManagerClient() |
- : weak_ptr_factory_(this) { |
+ : interactive_delay_(0), |
+ weak_ptr_factory_(this) { |
+ ParseCommandLineSwitch(); |
} |
FakeShillManagerClient::~FakeShillManagerClient() {} |
@@ -118,7 +133,7 @@ void FakeShillManagerClient::SetProperty(const std::string& name, |
const base::Closure& callback, |
const ErrorCallback& error_callback) { |
stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); |
- CallNotifyObserversPropertyChanged(name, 0); |
+ CallNotifyObserversPropertyChanged(name); |
base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
} |
@@ -133,21 +148,16 @@ void FakeShillManagerClient::RequestScan(const std::string& type, |
DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface(); |
std::string device_path = device_client->GetDevicePathForType(device_type); |
if (!device_path.empty()) { |
- device_client->SetDeviceProperty(device_path, |
- shill::kScanningProperty, |
- base::FundamentalValue(true)); |
- } |
- const int kScanDurationSeconds = 3; |
- int scan_duration_seconds = kScanDurationSeconds; |
- if (!CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kEnableStubInteractive)) { |
- scan_duration_seconds = 0; |
+ device_client->SetDeviceProperty( |
+ device_path, shill::kScanningProperty, base::FundamentalValue(true)); |
} |
base::MessageLoop::current()->PostDelayedTask( |
FROM_HERE, |
base::Bind(&FakeShillManagerClient::ScanCompleted, |
- weak_ptr_factory_.GetWeakPtr(), device_path, callback), |
- base::TimeDelta::FromSeconds(scan_duration_seconds)); |
+ weak_ptr_factory_.GetWeakPtr(), |
+ device_path, |
+ callback), |
+ base::TimeDelta::FromSeconds(interactive_delay_)); |
} |
void FakeShillManagerClient::EnableTechnology( |
@@ -156,24 +166,21 @@ void FakeShillManagerClient::EnableTechnology( |
const ErrorCallback& error_callback) { |
base::ListValue* enabled_list = NULL; |
if (!stub_properties_.GetListWithoutPathExpansion( |
- shill::kEnabledTechnologiesProperty, &enabled_list)) { |
+ shill::kAvailableTechnologiesProperty, &enabled_list)) { |
base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
base::MessageLoop::current()->PostTask( |
FROM_HERE, |
base::Bind(error_callback, "StubError", "Property not found")); |
return; |
} |
- if (CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kEnableStubInteractive)) { |
- const int kEnableTechnologyDelaySeconds = 3; |
- base::MessageLoop::current()->PostDelayedTask( |
- FROM_HERE, |
- base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, |
- weak_ptr_factory_.GetWeakPtr(), type, callback, true), |
- base::TimeDelta::FromSeconds(kEnableTechnologyDelaySeconds)); |
- } else { |
- SetTechnologyEnabled(type, callback, true); |
- } |
+ base::MessageLoop::current()->PostDelayedTask( |
+ FROM_HERE, |
+ base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ type, |
+ callback, |
+ true), |
+ base::TimeDelta::FromSeconds(interactive_delay_)); |
} |
void FakeShillManagerClient::DisableTechnology( |
@@ -182,20 +189,21 @@ void FakeShillManagerClient::DisableTechnology( |
const ErrorCallback& error_callback) { |
base::ListValue* enabled_list = NULL; |
if (!stub_properties_.GetListWithoutPathExpansion( |
- shill::kEnabledTechnologiesProperty, &enabled_list)) { |
+ shill::kAvailableTechnologiesProperty, &enabled_list)) { |
base::MessageLoop::current()->PostTask( |
FROM_HERE, |
base::Bind(error_callback, "StubError", "Property not found")); |
return; |
} |
- if (CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kEnableStubInteractive)) { |
- const int kDisableTechnologyDelaySeconds = 3; |
+ if (interactive_delay_) { |
base::MessageLoop::current()->PostDelayedTask( |
FROM_HERE, |
base::Bind(&FakeShillManagerClient::SetTechnologyEnabled, |
- weak_ptr_factory_.GetWeakPtr(), type, callback, false), |
- base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); |
+ weak_ptr_factory_.GetWeakPtr(), |
+ type, |
+ callback, |
+ false), |
+ base::TimeDelta::FromSeconds(interactive_delay_)); |
} else { |
SetTechnologyEnabled(type, callback, false); |
} |
@@ -306,8 +314,8 @@ void FakeShillManagerClient::VerifyAndEncryptData( |
const std::string& data, |
const StringCallback& callback, |
const ErrorCallback& error_callback) { |
- base::MessageLoop::current()->PostTask(FROM_HERE, |
- base::Bind(callback, "encrypted_data")); |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, base::Bind(callback, "encrypted_data")); |
} |
void FakeShillManagerClient::ConnectToBestServices( |
@@ -322,71 +330,87 @@ ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { |
// ShillManagerClient::TestInterface overrides. |
void FakeShillManagerClient::AddDevice(const std::string& device_path) { |
- if (GetListProperty(shill::kDevicesProperty)->AppendIfNotPresent( |
- base::Value::CreateStringValue(device_path))) { |
- CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); |
+ if (GetListProperty(shill::kDevicesProperty) |
+ ->AppendIfNotPresent(base::Value::CreateStringValue(device_path))) { |
+ CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
} |
} |
void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { |
base::StringValue device_path_value(device_path); |
- if (GetListProperty(shill::kDevicesProperty)->Remove( |
- device_path_value, NULL)) { |
- CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); |
+ if (GetListProperty(shill::kDevicesProperty) |
+ ->Remove(device_path_value, NULL)) { |
+ CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
} |
} |
void FakeShillManagerClient::ClearDevices() { |
GetListProperty(shill::kDevicesProperty)->Clear(); |
- CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); |
+ CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
} |
void FakeShillManagerClient::AddTechnology(const std::string& type, |
bool enabled) { |
- if (GetListProperty(shill::kAvailableTechnologiesProperty)-> |
- AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
- CallNotifyObserversPropertyChanged( |
- shill::kAvailableTechnologiesProperty, 0); |
+ if (GetListProperty(shill::kAvailableTechnologiesProperty) |
+ ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
+ CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty); |
} |
if (enabled && |
- GetListProperty(shill::kEnabledTechnologiesProperty)-> |
- AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
- CallNotifyObserversPropertyChanged( |
- shill::kEnabledTechnologiesProperty, 0); |
+ GetListProperty(shill::kEnabledTechnologiesProperty) |
+ ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
+ CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
} |
} |
void FakeShillManagerClient::RemoveTechnology(const std::string& type) { |
base::StringValue type_value(type); |
- if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove( |
- type_value, NULL)) { |
- CallNotifyObserversPropertyChanged( |
- shill::kAvailableTechnologiesProperty, 0); |
+ if (GetListProperty(shill::kAvailableTechnologiesProperty) |
+ ->Remove(type_value, NULL)) { |
+ CallNotifyObserversPropertyChanged(shill::kAvailableTechnologiesProperty); |
} |
- if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove( |
- type_value, NULL)) { |
- CallNotifyObserversPropertyChanged( |
- shill::kEnabledTechnologiesProperty, 0); |
+ if (GetListProperty(shill::kEnabledTechnologiesProperty) |
+ ->Remove(type_value, NULL)) { |
+ CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
} |
} |
void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, |
bool initializing) { |
if (initializing) { |
- if (GetListProperty(shill::kUninitializedTechnologiesProperty)-> |
- AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
+ if (GetListProperty(shill::kUninitializedTechnologiesProperty) |
+ ->AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
CallNotifyObserversPropertyChanged( |
- shill::kUninitializedTechnologiesProperty, 0); |
+ shill::kUninitializedTechnologiesProperty); |
} |
} else { |
- if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( |
- base::StringValue(type), NULL)) { |
+ if (GetListProperty(shill::kUninitializedTechnologiesProperty) |
+ ->Remove(base::StringValue(type), NULL)) { |
CallNotifyObserversPropertyChanged( |
- shill::kUninitializedTechnologiesProperty, 0); |
+ shill::kUninitializedTechnologiesProperty); |
} |
} |
} |
+void FakeShillManagerClient::AddGeoNetwork( |
+ const std::string& technology, |
+ const base::DictionaryValue& network) { |
+ base::ListValue* list_value = NULL; |
+ if (!stub_geo_networks_.GetListWithoutPathExpansion(technology, |
+ &list_value)) { |
+ list_value = new base::ListValue; |
+ stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
+ } |
+ list_value->Append(network.DeepCopy()); |
+} |
+ |
+void FakeShillManagerClient::AddProfile(const std::string& profile_path) { |
+ const char* key = shill::kProfilesProperty; |
+ if (GetListProperty(key) |
+ ->AppendIfNotPresent(new base::StringValue(profile_path))) { |
+ CallNotifyObserversPropertyChanged(key); |
+ } |
+} |
+ |
void FakeShillManagerClient::ClearProperties() { |
stub_properties_.Clear(); |
} |
@@ -399,9 +423,9 @@ void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
base::Value::CreateStringValue(service_path)); |
// If visible, add to Services and notify if new. |
if (add_to_visible_list && |
- GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( |
- base::Value::CreateStringValue(service_path))) { |
- CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
+ GetListProperty(shill::kServicesProperty) |
+ ->AppendIfNotPresent(base::Value::CreateStringValue(service_path))) { |
+ CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
} |
if (add_to_watch_list) |
AddServiceToWatchList(service_path); |
@@ -410,16 +434,15 @@ void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
void FakeShillManagerClient::RemoveManagerService( |
const std::string& service_path) { |
base::StringValue service_path_value(service_path); |
- if (GetListProperty(shill::kServicesProperty)->Remove( |
- service_path_value, NULL)) { |
- CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
+ if (GetListProperty(shill::kServicesProperty) |
+ ->Remove(service_path_value, NULL)) { |
+ CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
} |
- GetListProperty(shill::kServiceCompleteListProperty)->Remove( |
- service_path_value, NULL); |
- if (GetListProperty(shill::kServiceWatchListProperty)->Remove( |
- service_path_value, NULL)) { |
- CallNotifyObserversPropertyChanged( |
- shill::kServiceWatchListProperty, 0); |
+ GetListProperty(shill::kServiceCompleteListProperty) |
+ ->Remove(service_path_value, NULL); |
+ if (GetListProperty(shill::kServiceWatchListProperty) |
+ ->Remove(service_path_value, NULL)) { |
+ CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
} |
} |
@@ -427,8 +450,8 @@ void FakeShillManagerClient::ClearManagerServices() { |
GetListProperty(shill::kServicesProperty)->Clear(); |
GetListProperty(shill::kServiceCompleteListProperty)->Clear(); |
GetListProperty(shill::kServiceWatchListProperty)->Clear(); |
- CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
- CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); |
+ CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
+ CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
} |
void FakeShillManagerClient::SortManagerServices() { |
@@ -454,38 +477,205 @@ void FakeShillManagerClient::SortManagerServices() { |
for (size_t i = 0; i < inactive_services.size(); ++i) |
service_list->AppendString(inactive_services[i]); |
- CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
+ CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
} |
-void FakeShillManagerClient::AddGeoNetwork( |
- const std::string& technology, |
- const base::DictionaryValue& network) { |
- base::ListValue* list_value = NULL; |
- if (!stub_geo_networks_.GetListWithoutPathExpansion( |
- technology, &list_value)) { |
- list_value = new base::ListValue; |
- stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
- } |
- list_value->Append(network.DeepCopy()); |
+ |
+int FakeShillManagerClient::GetInteractiveDelay() const { |
+ return interactive_delay_; |
} |
-void FakeShillManagerClient::AddProfile(const std::string& profile_path) { |
- const char* key = shill::kProfilesProperty; |
- if (GetListProperty(key)->AppendIfNotPresent( |
- new base::StringValue(profile_path))) { |
- CallNotifyObserversPropertyChanged(key, 0); |
+void FakeShillManagerClient::SetupDefaultEnvironment() { |
+ DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
+ ShillServiceClient::TestInterface* services = |
+ dbus_manager->GetShillServiceClient()->GetTestInterface(); |
+ ShillProfileClient::TestInterface* profiles = |
+ dbus_manager->GetShillProfileClient()->GetTestInterface(); |
+ ShillDeviceClient::TestInterface* devices = |
+ dbus_manager->GetShillDeviceClient()->GetTestInterface(); |
+ if (!services || !profiles || !devices) |
+ return; |
+ |
+ const std::string shared_profile = ShillProfileClient::GetSharedProfilePath(); |
+ profiles->AddProfile(shared_profile, std::string()); |
+ |
+ const bool add_to_visible = true; |
+ const bool add_to_watchlist = true; |
+ |
+ bool enabled; |
+ std::string state; |
+ |
+ // Ethernet |
+ state = GetInitialStateForType(shill::kTypeEthernet, &enabled); |
+ if (state == shill::kStateOnline) { |
+ AddTechnology(shill::kTypeEthernet, enabled); |
+ devices->AddDevice( |
+ "/device/eth1", shill::kTypeEthernet, "stub_eth_device1"); |
+ services->AddService("eth1", "eth1", |
+ shill::kTypeEthernet, |
+ state, |
+ add_to_visible, add_to_watchlist); |
+ profiles->AddService(shared_profile, "eth1"); |
+ } |
+ |
+ // Wifi |
+ state = GetInitialStateForType(shill::kTypeWifi, &enabled); |
+ if (state != kTechnologyUnavailable) { |
+ bool portaled = false; |
+ if (state == shill::kStatePortal) { |
+ portaled = true; |
+ state = shill::kStateIdle; |
+ } |
+ AddTechnology(shill::kTypeWifi, enabled); |
+ devices->AddDevice("/device/wifi1", shill::kTypeWifi, "stub_wifi_device1"); |
+ |
+ services->AddService("wifi1", |
+ "wifi1", |
+ shill::kTypeWifi, |
+ state, |
+ add_to_visible, add_to_watchlist); |
+ services->SetServiceProperty("wifi1", |
+ shill::kSecurityProperty, |
+ base::StringValue(shill::kSecurityWep)); |
+ profiles->AddService(shared_profile, "wifi1"); |
+ |
+ services->AddService("wifi2", |
+ "wifi2_PSK", |
+ shill::kTypeWifi, |
+ shill::kStateIdle, |
+ add_to_visible, add_to_watchlist); |
+ services->SetServiceProperty("wifi2", |
+ shill::kSecurityProperty, |
+ base::StringValue(shill::kSecurityPsk)); |
+ |
+ base::FundamentalValue strength_value(80); |
+ services->SetServiceProperty( |
+ "wifi2", shill::kSignalStrengthProperty, strength_value); |
+ profiles->AddService(shared_profile, "wifi2"); |
+ |
+ if (portaled) { |
+ const std::string kPortaledWifiPath = "portaled_wifi"; |
+ services->AddService(kPortaledWifiPath, |
+ "Portaled Wifi", |
+ shill::kTypeWifi, |
+ shill::kStatePortal, |
+ add_to_visible, add_to_watchlist); |
+ services->SetServiceProperty(kPortaledWifiPath, |
+ shill::kSecurityProperty, |
+ base::StringValue(shill::kSecurityNone)); |
+ services->SetConnectBehavior(kPortaledWifiPath, |
+ base::Bind(&UpdatePortaledWifiState, |
+ "portaled_wifi")); |
+ services->SetServiceProperty(kPortaledWifiPath, |
+ shill::kConnectableProperty, |
+ base::FundamentalValue(true)); |
+ profiles->AddService(shared_profile, kPortaledWifiPath); |
+ } |
} |
+ |
+ // Wimax |
+ state = GetInitialStateForType(shill::kTypeWimax, &enabled); |
+ if (state != kTechnologyUnavailable) { |
+ AddTechnology(shill::kTypeWimax, enabled); |
+ devices->AddDevice( |
+ "/device/wimax1", shill::kTypeWimax, "stub_wimax_device1"); |
+ |
+ services->AddService("wimax1", |
+ "wimax1", |
+ shill::kTypeWimax, |
+ state, |
+ add_to_visible, add_to_watchlist); |
+ services->SetServiceProperty( |
+ "wimax1", shill::kConnectableProperty, base::FundamentalValue(true)); |
+ } |
+ |
+ // Cellular |
+ state = GetInitialStateForType(shill::kTypeCellular, &enabled); |
+ if (state != kTechnologyUnavailable) { |
+ bool activated = false; |
+ if (state == kNetworkActivated) { |
+ activated = true; |
+ state = shill::kStateIdle; |
+ } |
+ AddTechnology(shill::kTypeCellular, enabled); |
+ devices->AddDevice( |
+ "/device/cellular1", shill::kTypeCellular, "stub_cellular_device1"); |
+ devices->SetDeviceProperty("/device/cellular1", |
+ shill::kCarrierProperty, |
+ base::StringValue(shill::kCarrierSprint)); |
+ |
+ services->AddService("cellular1", |
+ "cellular1", |
+ shill::kTypeCellular, |
+ state, |
+ add_to_visible, add_to_watchlist); |
+ base::StringValue technology_value(shill::kNetworkTechnologyGsm); |
+ services->SetServiceProperty( |
+ "cellular1", shill::kNetworkTechnologyProperty, technology_value); |
+ |
+ if (activated) { |
+ services->SetServiceProperty( |
+ "cellular1", |
+ shill::kActivationStateProperty, |
+ base::StringValue(shill::kActivationStateActivated)); |
+ services->SetServiceProperty("cellular1", |
+ shill::kConnectableProperty, |
+ base::FundamentalValue(true)); |
+ } else { |
+ services->SetServiceProperty( |
+ "cellular1", |
+ shill::kActivationStateProperty, |
+ base::StringValue(shill::kActivationStateNotActivated)); |
+ } |
+ |
+ services->SetServiceProperty("cellular1", |
+ shill::kRoamingStateProperty, |
+ base::StringValue(shill::kRoamingStateHome)); |
+ } |
+ |
+ // VPN |
+ state = GetInitialStateForType(shill::kTypeVPN, &enabled); |
+ if (state != kTechnologyUnavailable) { |
+ // Set the "Provider" dictionary properties. Note: when setting these in |
+ // Shill, "Provider.Type", etc keys are used, but when reading the values |
+ // "Provider" . "Type", etc keys are used. Here we are setting the values |
+ // that will be read (by the UI, tests, etc). |
+ base::DictionaryValue provider_properties; |
+ provider_properties.SetString(shill::kTypeProperty, |
+ shill::kProviderOpenVpn); |
+ provider_properties.SetString(shill::kHostProperty, "vpn_host"); |
+ |
+ services->AddService("vpn1", |
+ "vpn1", |
+ shill::kTypeVPN, |
+ state, |
+ add_to_visible, add_to_watchlist); |
+ services->SetServiceProperty( |
+ "vpn1", shill::kProviderProperty, provider_properties); |
+ profiles->AddService(shared_profile, "vpn1"); |
+ |
+ services->AddService("vpn2", |
+ "vpn2", |
+ shill::kTypeVPN, |
+ shill::kStateIdle, |
+ add_to_visible, add_to_watchlist); |
+ services->SetServiceProperty( |
+ "vpn2", shill::kProviderProperty, provider_properties); |
+ } |
+ |
+ SortManagerServices(); |
} |
+// Private methods |
+ |
void FakeShillManagerClient::AddServiceToWatchList( |
const std::string& service_path) { |
// Remove and insert the service, moving it to the front of the watch list. |
- GetListProperty(shill::kServiceWatchListProperty)->Remove( |
- base::StringValue(service_path), NULL); |
- GetListProperty(shill::kServiceWatchListProperty)->Insert( |
- 0, base::Value::CreateStringValue(service_path)); |
- CallNotifyObserversPropertyChanged( |
- shill::kServiceWatchListProperty, 0); |
+ GetListProperty(shill::kServiceWatchListProperty) |
+ ->Remove(base::StringValue(service_path), NULL); |
+ GetListProperty(shill::kServiceWatchListProperty) |
+ ->Insert(0, base::Value::CreateStringValue(service_path)); |
+ CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
} |
void FakeShillManagerClient::PassStubProperties( |
@@ -508,22 +698,16 @@ void FakeShillManagerClient::PassStubGeoNetworks( |
} |
void FakeShillManagerClient::CallNotifyObserversPropertyChanged( |
- const std::string& property, |
- int delay_ms) { |
+ const std::string& property) { |
// Avoid unnecessary delayed task if we have no observers (e.g. during |
// initial setup). |
if (!observer_list_.might_have_observers()) |
return; |
- if (!CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kEnableStubInteractive)) { |
- delay_ms = 0; |
- } |
- base::MessageLoop::current()->PostDelayedTask( |
+ base::MessageLoop::current()->PostTask( |
FROM_HERE, |
base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, |
weak_ptr_factory_.GetWeakPtr(), |
- property), |
- base::TimeDelta::FromMilliseconds(delay_ms)); |
+ property)); |
} |
void FakeShillManagerClient::NotifyObserversPropertyChanged( |
@@ -585,20 +769,17 @@ void FakeShillManagerClient::SetTechnologyEnabled( |
const std::string& type, |
const base::Closure& callback, |
bool enabled) { |
- base::ListValue* enabled_list = NULL; |
- stub_properties_.GetListWithoutPathExpansion( |
- shill::kEnabledTechnologiesProperty, &enabled_list); |
- DCHECK(enabled_list); |
+ base::ListValue* enabled_list = |
+ GetListProperty(shill::kEnabledTechnologiesProperty); |
if (enabled) |
enabled_list->AppendIfNotPresent(new base::StringValue(type)); |
else |
enabled_list->Remove(base::StringValue(type), NULL); |
- CallNotifyObserversPropertyChanged( |
- shill::kEnabledTechnologiesProperty, 0 /* already delayed */); |
+ CallNotifyObserversPropertyChanged(shill::kEnabledTechnologiesProperty); |
base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
// May affect available services |
- CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
- CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); |
+ CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
+ CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
} |
base::ListValue* FakeShillManagerClient::GetEnabledServiceList( |
@@ -638,9 +819,113 @@ void FakeShillManagerClient::ScanCompleted(const std::string& device_path, |
shill::kScanningProperty, |
base::FundamentalValue(false)); |
} |
- CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
- CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); |
+ CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
+ CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
} |
+void FakeShillManagerClient::ParseCommandLineSwitch() { |
+ if (dbus_command_line_helper::ParseOptions( |
+ switches::kShillStub, |
+ base::Bind(&FakeShillManagerClient::ParseOption, |
+ base::Unretained(this)))) { |
+ return; |
+ } |
+ // Default setup |
+ SetInitialNetworkState(shill::kTypeEthernet, shill::kStateOnline); |
+ SetInitialNetworkState(shill::kTypeWifi, shill::kStateOnline); |
+ SetInitialNetworkState(shill::kTypeCellular, shill::kStateIdle); |
+ SetInitialNetworkState(shill::kTypeVPN, shill::kStateIdle); |
+} |
+ |
+bool FakeShillManagerClient::ParseOption(const std::string& arg0, |
+ const std::string& arg1) { |
+ if (arg0 == "interactive") { |
+ int seconds = 3; |
+ if (!arg1.empty()) |
+ base::StringToInt(arg1, &seconds); |
+ interactive_delay_ = seconds; |
+ return true; |
+ } |
+ return SetInitialNetworkState(arg0, arg1); |
+} |
+ |
+bool FakeShillManagerClient::SetInitialNetworkState(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) { |
+ // Technology enabled, services are created but are not connected. |
+ state = shill::kStateIdle; |
+ } else if (state_arg == "disabled" || state_arg == "disconnect") { |
+ // Technology diabled but available, services are created but not connected. |
pneubeck (no reviews)
2014/03/05 18:47:09
nit: diabled -> disabled
stevenjb
2014/03/05 20:38:17
Done.
|
+ state = kNetworkDisabled; |
+ } else if (state_arg == "none" || state_arg == "offline") { |
+ // Technology not available, do not create services. |
+ state = kTechnologyUnavailable; |
+ } else if (state_arg == "portal") { |
+ // Technology is enabled, a service is connected and in Portal state. |
+ state = shill::kStatePortal; |
+ } else if (state_arg == "active" || state_arg == "activated") { |
+ // Technology is enabled, a service is connected and Activated. |
+ state = kNetworkActivated; |
+ } else { |
+ // Default: Technolgy is enabled and a service is connected. |
pneubeck (no reviews)
2014/03/05 18:47:09
Technolgy -> Technology
stevenjb
2014/03/05 20:38:17
Done.
|
+ state = shill::kStateOnline; |
+ } |
+ |
+ type_arg = StringToLowerASCII(type_arg); |
+ // Special cases |
+ if (type_arg == "wireless") { |
+ shill_initial_state_map_[shill::kTypeWifi] = state; |
+ shill_initial_state_map_[shill::kTypeCellular] = state; |
+ return true; |
+ } |
+ // Convenience synonyms. |
+ if (type_arg == "eth") |
+ type_arg = shill::kTypeEthernet; |
+ |
+ if (type_arg != shill::kTypeEthernet && |
+ type_arg != shill::kTypeWifi && |
+ type_arg != shill::kTypeCellular && |
+ type_arg != shill::kTypeWimax && |
+ type_arg != shill::kTypeVPN) { |
+ LOG(WARNING) << "Unrecognized Shill network type: " << type_arg; |
+ return false; |
+ } |
+ |
+ // Unconnected or disabled etherned is the same as unavailable. |
pneubeck (no reviews)
2014/03/05 18:47:09
nit: etherned -> ethernet
stevenjb
2014/03/05 20:38:17
Done.
|
+ if (type_arg == shill::kTypeEthernet && |
+ (state == shill::kStateIdle || state == kNetworkDisabled)) { |
+ state = kTechnologyUnavailable; |
+ } |
+ |
+ shill_initial_state_map_[type_arg] = state; |
+ return true; |
+} |
+ |
+std::string FakeShillManagerClient::GetInitialStateForType( |
+ const std::string& type, |
+ bool* enabled) { |
+ std::map<std::string, std::string>::const_iterator iter = |
+ shill_initial_state_map_.find(type); |
+ if (iter == shill_initial_state_map_.end()) { |
+ *enabled = false; |
+ return kTechnologyUnavailable; |
+ } |
+ std::string state = iter->second; |
+ if (state == kNetworkDisabled) { |
+ *enabled = false; |
+ return shill::kStateIdle; |
+ } |
+ *enabled = true; |
+ if ((state == shill::kStatePortal && type != shill::kTypeWifi) || |
+ (state == kNetworkActivated && type != shill::kTypeCellular)) { |
+ LOG(WARNING) << "Invalid state: " << state << " for " << type; |
+ return shill::kStateIdle; |
+ } |
+ return state; |
+} |
+ |
} // namespace chromeos |