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..2e306125f1632722ff483af14213b2c06602d7be 100644 |
--- a/chromeos/dbus/fake_shill_manager_client.cc |
+++ b/chromeos/dbus/fake_shill_manager_client.cc |
@@ -73,6 +73,11 @@ void AppendServicesForType( |
} |
} |
+void LogErrorCallback(const std::string& error_name, |
+ const std::string& error_message) { |
+ LOG(ERROR) << error_name << ": " << error_message; |
+} |
+ |
} // namespace |
FakeShillManagerClient::FakeShillManagerClient() |
@@ -391,6 +396,12 @@ void FakeShillManagerClient::ClearProperties() { |
stub_properties_.Clear(); |
} |
+void FakeShillManagerClient::SetManagerProperty(const std::string& key, |
+ const base::Value& value) { |
+ SetProperty(key, value, |
+ base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); |
+} |
+ |
void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
bool add_to_visible_list, |
bool add_to_watch_list) { |
@@ -440,8 +451,14 @@ void FakeShillManagerClient::SortManagerServices() { |
shill::kTypeVPN |
}; |
base::ListValue* service_list = GetListProperty(shill::kServicesProperty); |
- if (!service_list || service_list->empty()) |
+ if (!service_list || service_list->empty()) { |
+ if (!default_service_.empty()) { |
+ default_service_.clear(); |
+ base::StringValue empty_value(""); |
+ SetManagerProperty(shill::kDefaultServiceProperty, empty_value); |
+ } |
return; |
+ } |
std::vector<std::string> active_services; |
std::vector<std::string> inactive_services; |
for (size_t i = 0; i < arraysize(ordered_types); ++i) { |
@@ -455,6 +472,32 @@ void FakeShillManagerClient::SortManagerServices() { |
service_list->AppendString(inactive_services[i]); |
CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
+ |
+ // Set the first active service as the Default service. |
+ std::string new_default_service; |
+ if (!active_services.empty()) { |
+ ShillServiceClient::TestInterface* service_client = |
+ DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
+ std::string service_path = active_services[0]; |
+ const base::DictionaryValue* properties = |
+ service_client->GetServiceProperties(service_path); |
+ if (!properties) { |
+ LOG(ERROR) << "Properties not found for service: " << service_path; |
+ } else { |
+ std::string state; |
+ properties->GetString(shill::kStateProperty, &state); |
+ if (state == shill::kStateOnline || |
+ state == shill::kStatePortal || |
+ state == shill::kStateReady) { |
+ new_default_service = service_path; |
+ } |
+ } |
+ } |
+ if (default_service_ != new_default_service) { |
+ default_service_ = new_default_service; |
+ base::StringValue default_service_value(default_service_); |
+ SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
+ } |
} |
void FakeShillManagerClient::AddGeoNetwork( |