| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_shill_manager_client.h" | 5 #include "chromeos/dbus/fake_shill_manager_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "base/values.h" | |
| 21 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 22 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 23 #include "chromeos/dbus/fake_shill_device_client.h" | 22 #include "chromeos/dbus/fake_shill_device_client.h" |
| 24 #include "chromeos/dbus/shill_device_client.h" | 23 #include "chromeos/dbus/shill_device_client.h" |
| 25 #include "chromeos/dbus/shill_ipconfig_client.h" | 24 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 26 #include "chromeos/dbus/shill_profile_client.h" | 25 #include "chromeos/dbus/shill_profile_client.h" |
| 27 #include "chromeos/dbus/shill_property_changed_observer.h" | 26 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 28 #include "chromeos/dbus/shill_service_client.h" | 27 #include "chromeos/dbus/shill_service_client.h" |
| 29 #include "dbus/bus.h" | 28 #include "dbus/bus.h" |
| 30 #include "dbus/message.h" | 29 #include "dbus/message.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 base::ThreadTaskRunnerHandle::Get()->PostTask( | 177 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 179 FROM_HERE, base::Bind(&FakeShillManagerClient::PassStubGeoNetworks, | 178 FROM_HERE, base::Bind(&FakeShillManagerClient::PassStubGeoNetworks, |
| 180 weak_ptr_factory_.GetWeakPtr(), callback)); | 179 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void FakeShillManagerClient::SetProperty(const std::string& name, | 182 void FakeShillManagerClient::SetProperty(const std::string& name, |
| 184 const base::Value& value, | 183 const base::Value& value, |
| 185 const base::Closure& callback, | 184 const base::Closure& callback, |
| 186 const ErrorCallback& error_callback) { | 185 const ErrorCallback& error_callback) { |
| 187 VLOG(2) << "SetProperty: " << name; | 186 VLOG(2) << "SetProperty: " << name; |
| 188 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); | 187 stub_properties_.SetWithoutPathExpansion( |
| 188 name, base::MakeUnique<base::Value>(value)); |
| 189 CallNotifyObserversPropertyChanged(name); | 189 CallNotifyObserversPropertyChanged(name); |
| 190 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 190 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void FakeShillManagerClient::RequestScan(const std::string& type, | 193 void FakeShillManagerClient::RequestScan(const std::string& type, |
| 194 const base::Closure& callback, | 194 const base::Closure& callback, |
| 195 const ErrorCallback& error_callback) { | 195 const ErrorCallback& error_callback) { |
| 196 VLOG(1) << "RequestScan: " << type; | 196 VLOG(1) << "RequestScan: " << type; |
| 197 // For Stub purposes, default to a Wifi scan. | 197 // For Stub purposes, default to a Wifi scan. |
| 198 std::string device_type = shill::kTypeWifi; | 198 std::string device_type = shill::kTypeWifi; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 447 } |
| 448 } | 448 } |
| 449 } | 449 } |
| 450 | 450 |
| 451 void FakeShillManagerClient::AddGeoNetwork( | 451 void FakeShillManagerClient::AddGeoNetwork( |
| 452 const std::string& technology, | 452 const std::string& technology, |
| 453 const base::DictionaryValue& network) { | 453 const base::DictionaryValue& network) { |
| 454 base::ListValue* list_value = NULL; | 454 base::ListValue* list_value = NULL; |
| 455 if (!stub_geo_networks_.GetListWithoutPathExpansion(technology, | 455 if (!stub_geo_networks_.GetListWithoutPathExpansion(technology, |
| 456 &list_value)) { | 456 &list_value)) { |
| 457 list_value = new base::ListValue; | 457 list_value = stub_geo_networks_.SetListWithoutPathExpansion( |
| 458 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); | 458 technology, base::MakeUnique<base::ListValue>()); |
| 459 } | 459 } |
| 460 list_value->Append(network.CreateDeepCopy()); | 460 list_value->GetList().push_back(network); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { | 463 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { |
| 464 const char* key = shill::kProfilesProperty; | 464 const char* key = shill::kProfilesProperty; |
| 465 if (GetListProperty(key)->AppendIfNotPresent( | 465 if (GetListProperty(key)->AppendIfNotPresent( |
| 466 base::MakeUnique<base::Value>(profile_path))) { | 466 base::MakeUnique<base::Value>(profile_path))) { |
| 467 CallNotifyObserversPropertyChanged(key); | 467 CallNotifyObserversPropertyChanged(key); |
| 468 } | 468 } |
| 469 } | 469 } |
| 470 | 470 |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 971 } | 971 } |
| 972 for (auto& observer : observer_list_) | 972 for (auto& observer : observer_list_) |
| 973 observer.OnPropertyChanged(property, *value); | 973 observer.OnPropertyChanged(property, *value); |
| 974 } | 974 } |
| 975 | 975 |
| 976 base::ListValue* FakeShillManagerClient::GetListProperty( | 976 base::ListValue* FakeShillManagerClient::GetListProperty( |
| 977 const std::string& property) { | 977 const std::string& property) { |
| 978 base::ListValue* list_property = NULL; | 978 base::ListValue* list_property = NULL; |
| 979 if (!stub_properties_.GetListWithoutPathExpansion( | 979 if (!stub_properties_.GetListWithoutPathExpansion( |
| 980 property, &list_property)) { | 980 property, &list_property)) { |
| 981 list_property = new base::ListValue; | 981 list_property = stub_properties_.SetListWithoutPathExpansion( |
| 982 stub_properties_.SetWithoutPathExpansion(property, list_property); | 982 property, base::MakeUnique<base::ListValue>()); |
| 983 } | 983 } |
| 984 return list_property; | 984 return list_property; |
| 985 } | 985 } |
| 986 | 986 |
| 987 bool FakeShillManagerClient::TechnologyEnabled(const std::string& type) const { | 987 bool FakeShillManagerClient::TechnologyEnabled(const std::string& type) const { |
| 988 if (type == shill::kTypeVPN) | 988 if (type == shill::kTypeVPN) |
| 989 return true; // VPN is always "enabled" since there is no associated device | 989 return true; // VPN is always "enabled" since there is no associated device |
| 990 if (type == shill::kTypeEthernetEap) | 990 if (type == shill::kTypeEthernetEap) |
| 991 return true; | 991 return true; |
| 992 bool enabled = false; | 992 bool enabled = false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1010 enabled_list->AppendIfNotPresent(base::MakeUnique<base::Value>(type)); | 1010 enabled_list->AppendIfNotPresent(base::MakeUnique<base::Value>(type)); |
| 1011 else | 1011 else |
| 1012 enabled_list->Remove(base::Value(type), NULL); | 1012 enabled_list->Remove(base::Value(type), NULL); |
| 1013 CallNotifyObserversPropertyChanged( | 1013 CallNotifyObserversPropertyChanged( |
| 1014 shill::kEnabledTechnologiesProperty); | 1014 shill::kEnabledTechnologiesProperty); |
| 1015 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 1015 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
| 1016 // May affect available services. | 1016 // May affect available services. |
| 1017 SortManagerServices(true); | 1017 SortManagerServices(true); |
| 1018 } | 1018 } |
| 1019 | 1019 |
| 1020 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( | 1020 std::unique_ptr<base::ListValue> FakeShillManagerClient::GetEnabledServiceList( |
| 1021 const std::string& property) const { | 1021 const std::string& property) const { |
| 1022 base::ListValue* new_service_list = new base::ListValue; | 1022 auto new_service_list = base::MakeUnique<base::ListValue>(); |
| 1023 const base::ListValue* service_list; | 1023 const base::ListValue* service_list; |
| 1024 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { | 1024 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { |
| 1025 ShillServiceClient::TestInterface* service_client = | 1025 ShillServiceClient::TestInterface* service_client = |
| 1026 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 1026 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 1027 for (base::ListValue::const_iterator iter = service_list->begin(); | 1027 for (base::ListValue::const_iterator iter = service_list->begin(); |
| 1028 iter != service_list->end(); ++iter) { | 1028 iter != service_list->end(); ++iter) { |
| 1029 std::string service_path; | 1029 std::string service_path; |
| 1030 if (!iter->GetAsString(&service_path)) | 1030 if (!iter->GetAsString(&service_path)) |
| 1031 continue; | 1031 continue; |
| 1032 const base::DictionaryValue* properties = | 1032 const base::DictionaryValue* properties = |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 1228 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
| 1229 result = shill::kStateIdle; | 1229 result = shill::kStateIdle; |
| 1230 } | 1230 } |
| 1231 } | 1231 } |
| 1232 VLOG(1) << "Initial state for: " << type << " = " << result | 1232 VLOG(1) << "Initial state for: " << type << " = " << result |
| 1233 << " Enabled: " << *enabled; | 1233 << " Enabled: " << *enabled; |
| 1234 return result; | 1234 return result; |
| 1235 } | 1235 } |
| 1236 | 1236 |
| 1237 } // namespace chromeos | 1237 } // namespace chromeos |
| OLD | NEW |