Index: chromeos/dbus/shill_service_client_stub.cc |
diff --git a/chromeos/dbus/shill_service_client_stub.cc b/chromeos/dbus/shill_service_client_stub.cc |
index 930f935b3b952f233c53bc28d7df8540efa6073d..25ab4de12ea86e8aa304fccc8f77d875069777c6 100644 |
--- a/chromeos/dbus/shill_service_client_stub.cc |
+++ b/chromeos/dbus/shill_service_client_stub.cc |
@@ -5,6 +5,7 @@ |
#include "chromeos/dbus/shill_service_client_stub.h" |
#include "base/bind.h" |
+#include "base/bind_helpers.h" |
#include "base/command_line.h" |
#include "base/message_loop/message_loop.h" |
#include "base/stl_util.h" |
@@ -13,20 +14,16 @@ |
#include "chromeos/chromeos_switches.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
#include "chromeos/dbus/shill_manager_client.h" |
-#include "chromeos/dbus/shill_profile_client_stub.h" |
#include "chromeos/dbus/shill_property_changed_observer.h" |
#include "dbus/bus.h" |
#include "dbus/message.h" |
-#include "dbus/object_proxy.h" |
+#include "dbus/object_path.h" |
#include "third_party/cros_system_api/dbus/service_constants.h" |
namespace chromeos { |
namespace { |
-const char kStubPortalledWifiPath[] = "portalled_wifi"; |
-const char kStubPortalledWifiName[] = "Portalled Wifi"; |
- |
void ErrorFunction(const std::string& error_name, |
const std::string& error_message) { |
LOG(ERROR) << "Shill Error: " << error_name << " : " << error_message; |
@@ -54,15 +51,6 @@ ShillServiceClientStub::~ShillServiceClientStub() { |
observer_list_.begin(), observer_list_.end()); |
} |
-// static |
-bool ShillServiceClientStub::IsStubPortalledWifiEnabled( |
- const std::string& path) { |
- if (!CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kEnableStubPortalledWifi)) { |
- return false; |
- } |
- return path == kStubPortalledWifiPath; |
-} |
// ShillServiceClient overrides. |
@@ -182,7 +170,7 @@ void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, |
const base::Closure& callback, |
const ErrorCallback& error_callback) { |
VLOG(1) << "ShillServiceClientStub::Connect: " << service_path.value(); |
- base::DictionaryValue* service_properties; |
+ base::DictionaryValue* service_properties = NULL; |
if (!stub_services_.GetDictionary( |
service_path.value(), &service_properties)) { |
LOG(ERROR) << "Service not found: " << service_path.value(); |
@@ -201,45 +189,21 @@ void ShillServiceClientStub::Connect(const dbus::ObjectPath& service_path, |
flimflam::kStateProperty, |
associating_value); |
- // Set Online after a delay. |
+ // Stay Associating until the state is changed again after a delay. |
base::TimeDelta delay; |
if (CommandLine::ForCurrentProcess()->HasSwitch( |
chromeos::switches::kEnableStubInteractive)) { |
const int kConnectDelaySeconds = 5; |
delay = base::TimeDelta::FromSeconds(kConnectDelaySeconds); |
} |
- base::StringValue online_value(flimflam::kStateOnline); |
- if (service_path.value() == kStubPortalledWifiPath) |
- online_value = base::StringValue(flimflam::kStatePortal); |
- std::string passphrase; |
- service_properties->GetStringWithoutPathExpansion( |
- flimflam::kPassphraseProperty, &passphrase); |
- if (passphrase == "failure") |
- online_value = base::StringValue(flimflam::kStateFailure); |
base::MessageLoop::current()->PostDelayedTask( |
FROM_HERE, |
- base::Bind(&ShillServiceClientStub::SetProperty, |
+ base::Bind(&ShillServiceClientStub::ContinueConnect, |
weak_ptr_factory_.GetWeakPtr(), |
- service_path, |
- flimflam::kStateProperty, |
- online_value, |
- base::Bind(&base::DoNothing), |
- error_callback), |
+ service_path.value()), |
delay); |
+ |
callback.Run(); |
- // On failure, also set the Error property. |
- if (passphrase == "failure") { |
- base::MessageLoop::current()->PostDelayedTask( |
- FROM_HERE, |
- base::Bind(&ShillServiceClientStub::SetProperty, |
- weak_ptr_factory_.GetWeakPtr(), |
- service_path, |
- flimflam::kErrorProperty, |
- base::StringValue(flimflam::kErrorBadPassphrase), |
- base::Bind(&base::DoNothing), |
- error_callback), |
- delay); |
- } |
} |
void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, |
@@ -283,7 +247,7 @@ void ShillServiceClientStub::ActivateCellularModem( |
const base::Closure& callback, |
const ErrorCallback& error_callback) { |
base::DictionaryValue* service_properties = |
- GetModifiableServiceProperties(service_path.value()); |
+ GetModifiableServiceProperties(service_path.value(), false); |
if (!service_properties) { |
LOG(ERROR) << "Service not found: " << service_path.value(); |
error_callback.Run("Error.InvalidService", "Invalid Service"); |
@@ -324,7 +288,7 @@ void ShillServiceClientStub::GetLoadableProfileEntries( |
scoped_ptr<base::DictionaryValue> result_properties( |
new base::DictionaryValue); |
base::DictionaryValue* service_properties = |
- GetModifiableServiceProperties(service_path.value()); |
+ GetModifiableServiceProperties(service_path.value(), false); |
if (service_properties) { |
std::string profile_path; |
if (service_properties->GetStringWithoutPathExpansion( |
@@ -378,7 +342,8 @@ void ShillServiceClientStub::AddServiceWithIPConfig( |
AddManagerService(service_path, add_to_visible_list, add_to_watch_list); |
base::DictionaryValue* properties = |
- GetModifiableServiceProperties(service_path); |
+ GetModifiableServiceProperties(service_path, true); |
+ connect_behavior_.erase(service_path); |
properties->SetWithoutPathExpansion( |
flimflam::kSSIDProperty, |
base::Value::CreateStringValue(service_path)); |
@@ -402,6 +367,7 @@ void ShillServiceClientStub::RemoveService(const std::string& service_path) { |
RemoveManagerService(service_path); |
stub_services_.RemoveWithoutPathExpansion(service_path, NULL); |
+ connect_behavior_.erase(service_path); |
} |
bool ShillServiceClientStub::SetServiceProperty(const std::string& service_path, |
@@ -460,112 +426,12 @@ void ShillServiceClientStub::ClearServices() { |
ClearManagerServices(); |
stub_services_.Clear(); |
+ connect_behavior_.clear(); |
} |
-void ShillServiceClientStub::AddDefaultServices() { |
- const bool add_to_visible = true; |
- const bool add_to_watchlist = true; |
- |
- if (!CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kDisableStubEthernet)) { |
- AddService("eth1", "eth1", |
- flimflam::kTypeEthernet, |
- flimflam::kStateOnline, |
- add_to_visible, add_to_watchlist); |
- } |
- |
- // Wifi |
- |
- AddService("wifi1", "wifi1", |
- flimflam::kTypeWifi, |
- flimflam::kStateOnline, |
- add_to_visible, add_to_watchlist); |
- SetServiceProperty("wifi1", |
- flimflam::kSecurityProperty, |
- base::StringValue(flimflam::kSecurityWep)); |
- |
- AddService("wifi2", "wifi2_PSK", |
- flimflam::kTypeWifi, |
- flimflam::kStateIdle, |
- add_to_visible, add_to_watchlist); |
- SetServiceProperty("wifi2", |
- flimflam::kSecurityProperty, |
- base::StringValue(flimflam::kSecurityPsk)); |
- base::FundamentalValue strength_value(80); |
- SetServiceProperty("wifi2", |
- flimflam::kSignalStrengthProperty, |
- strength_value); |
- |
- if (CommandLine::ForCurrentProcess()->HasSwitch( |
- chromeos::switches::kEnableStubPortalledWifi)) { |
- AddService(kStubPortalledWifiPath, kStubPortalledWifiName, |
- flimflam::kTypeWifi, |
- flimflam::kStatePortal, |
- add_to_visible, add_to_watchlist); |
- SetServiceProperty(kStubPortalledWifiPath, |
- flimflam::kSecurityProperty, |
- base::StringValue(flimflam::kSecurityNone)); |
- } |
- |
- // Wimax |
- |
- AddService("wimax1", "wimax1", |
- flimflam::kTypeWimax, |
- flimflam::kStateIdle, |
- add_to_visible, add_to_watchlist); |
- SetServiceProperty("wimax1", |
- flimflam::kConnectableProperty, |
- base::FundamentalValue(true)); |
- |
- // Cellular |
- |
- AddService("cellular1", "cellular1", |
- flimflam::kTypeCellular, |
- flimflam::kStateIdle, |
- add_to_visible, add_to_watchlist); |
- base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); |
- SetServiceProperty("cellular1", |
- flimflam::kNetworkTechnologyProperty, |
- technology_value); |
- SetServiceProperty("cellular1", |
- flimflam::kActivationStateProperty, |
- base::StringValue(flimflam::kActivationStateNotActivated)); |
- SetServiceProperty("cellular1", |
- flimflam::kRoamingStateProperty, |
- base::StringValue(flimflam::kRoamingStateHome)); |
- |
- // VPN |
- |
- // 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(flimflam::kTypeProperty, |
- flimflam::kProviderOpenVpn); |
- provider_properties.SetString(flimflam::kHostProperty, "vpn_host"); |
- |
- AddService("vpn1", "vpn1", |
- flimflam::kTypeVPN, |
- flimflam::kStateOnline, |
- add_to_visible, add_to_watchlist); |
- SetServiceProperty("vpn1", |
- flimflam::kProviderProperty, |
- provider_properties); |
- |
- AddService("vpn2", "vpn2", |
- flimflam::kTypeVPN, |
- flimflam::kStateOffline, |
- add_to_visible, add_to_watchlist); |
- SetServiceProperty("vpn2", |
- flimflam::kProviderProperty, |
- provider_properties); |
- |
- DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface()-> |
- AddService(ShillProfileClientStub::kSharedProfilePath, "wifi2"); |
- |
- DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
- SortManagerServices(); |
+void ShillServiceClientStub::SetConnectBehavior(const std::string& service_path, |
+ const base::Closure& behavior) { |
+ connect_behavior_[service_path] = behavior; |
} |
void ShillServiceClientStub::NotifyObserversPropertyChanged( |
@@ -589,10 +455,11 @@ void ShillServiceClientStub::NotifyObserversPropertyChanged( |
} |
base::DictionaryValue* ShillServiceClientStub::GetModifiableServiceProperties( |
- const std::string& service_path) { |
+ const std::string& service_path, bool create_if_missing) { |
base::DictionaryValue* properties = NULL; |
- if (!stub_services_.GetDictionaryWithoutPathExpansion( |
- service_path, &properties)) { |
+ if (!stub_services_.GetDictionaryWithoutPathExpansion(service_path, |
+ &properties) && |
+ create_if_missing) { |
properties = new base::DictionaryValue; |
stub_services_.Set(service_path, properties); |
} |
@@ -655,4 +522,45 @@ void ShillServiceClientStub::SetCellularActivated( |
error_callback); |
} |
+void ShillServiceClientStub::ContinueConnect( |
+ const std::string& service_path) { |
+ VLOG(1) << "ShillServiceClientStub::ContinueConnect: " << service_path; |
+ base::DictionaryValue* service_properties = NULL; |
+ if (!stub_services_.GetDictionary(service_path, &service_properties)) { |
+ LOG(ERROR) << "Service not found: " << service_path; |
+ return; |
+ } |
+ |
+ if (ContainsKey(connect_behavior_, service_path)) { |
+ const base::Closure& custom_connect_behavior = |
+ connect_behavior_[service_path]; |
+ custom_connect_behavior.Run(); |
+ return; |
+ } |
+ |
+ // No custom connect behavior set, continue with the default connect behavior. |
+ std::string passphrase; |
+ service_properties->GetStringWithoutPathExpansion( |
+ flimflam::kPassphraseProperty, &passphrase); |
+ if (passphrase == "failure") { |
+ // Simulate a password failure. |
+ SetServiceProperty(service_path, |
+ flimflam::kStateProperty, |
+ base::StringValue(flimflam::kStateFailure)); |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, |
+ base::Bind( |
+ base::IgnoreResult(&ShillServiceClientStub::SetServiceProperty), |
+ weak_ptr_factory_.GetWeakPtr(), |
+ service_path, |
+ flimflam::kErrorProperty, |
+ base::StringValue(flimflam::kErrorBadPassphrase))); |
+ } else { |
+ // Set Online. |
+ SetServiceProperty(service_path, |
+ flimflam::kStateProperty, |
+ base::StringValue(flimflam::kStateOnline)); |
+ } |
+} |
+ |
} // namespace chromeos |