| 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_profile_client.h" | 5 #include "chromeos/dbus/fake_shill_profile_client.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 9 #include "base/location.h" | 11 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "base/values.h" | 15 #include "base/values.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
| 15 #include "chromeos/dbus/shill_property_changed_observer.h" | 17 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 16 #include "chromeos/dbus/shill_service_client.h" | 18 #include "chromeos/dbus/shill_service_client.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 57 } |
| 56 | 58 |
| 57 void FakeShillProfileClient::GetProperties( | 59 void FakeShillProfileClient::GetProperties( |
| 58 const dbus::ObjectPath& profile_path, | 60 const dbus::ObjectPath& profile_path, |
| 59 const DictionaryValueCallbackWithoutStatus& callback, | 61 const DictionaryValueCallbackWithoutStatus& callback, |
| 60 const ErrorCallback& error_callback) { | 62 const ErrorCallback& error_callback) { |
| 61 ProfileProperties* profile = GetProfile(profile_path, error_callback); | 63 ProfileProperties* profile = GetProfile(profile_path, error_callback); |
| 62 if (!profile) | 64 if (!profile) |
| 63 return; | 65 return; |
| 64 | 66 |
| 65 std::unique_ptr<base::DictionaryValue> properties( | 67 auto entry_paths = base::MakeUnique<base::ListValue>(); |
| 66 profile->properties.DeepCopy()); | |
| 67 base::ListValue* entry_paths = new base::ListValue; | |
| 68 properties->SetWithoutPathExpansion(shill::kEntriesProperty, entry_paths); | |
| 69 for (base::DictionaryValue::Iterator it(profile->entries); !it.IsAtEnd(); | 68 for (base::DictionaryValue::Iterator it(profile->entries); !it.IsAtEnd(); |
| 70 it.Advance()) { | 69 it.Advance()) { |
| 71 entry_paths->AppendString(it.key()); | 70 entry_paths->AppendString(it.key()); |
| 72 } | 71 } |
| 73 | 72 |
| 73 auto properties = |
| 74 base::MakeUnique<base::DictionaryValue>(profile->properties); |
| 75 properties->SetWithoutPathExpansion(shill::kEntriesProperty, |
| 76 std::move(entry_paths)); |
| 77 |
| 74 base::ThreadTaskRunnerHandle::Get()->PostTask( | 78 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 75 FROM_HERE, | 79 FROM_HERE, |
| 76 base::Bind(&PassDictionary, callback, base::Owned(properties.release()))); | 80 base::Bind(&PassDictionary, callback, base::Owned(properties.release()))); |
| 77 } | 81 } |
| 78 | 82 |
| 79 void FakeShillProfileClient::GetEntry( | 83 void FakeShillProfileClient::GetEntry( |
| 80 const dbus::ObjectPath& profile_path, | 84 const dbus::ObjectPath& profile_path, |
| 81 const std::string& entry_path, | 85 const std::string& entry_path, |
| 82 const DictionaryValueCallbackWithoutStatus& callback, | 86 const DictionaryValueCallbackWithoutStatus& callback, |
| 83 const ErrorCallback& error_callback) { | 87 const ErrorCallback& error_callback) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 146 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 143 AddProfile(profile_path); | 147 AddProfile(profile_path); |
| 144 } | 148 } |
| 145 | 149 |
| 146 void FakeShillProfileClient::AddEntry(const std::string& profile_path, | 150 void FakeShillProfileClient::AddEntry(const std::string& profile_path, |
| 147 const std::string& entry_path, | 151 const std::string& entry_path, |
| 148 const base::DictionaryValue& properties) { | 152 const base::DictionaryValue& properties) { |
| 149 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), | 153 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), |
| 150 ErrorCallback()); | 154 ErrorCallback()); |
| 151 DCHECK(profile); | 155 DCHECK(profile); |
| 152 profile->entries.SetWithoutPathExpansion(entry_path, properties.DeepCopy()); | 156 profile->entries.SetWithoutPathExpansion( |
| 157 entry_path, base::MakeUnique<base::Value>(properties)); |
| 153 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 158 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 154 AddManagerService(entry_path, true); | 159 AddManagerService(entry_path, true); |
| 155 } | 160 } |
| 156 | 161 |
| 157 bool FakeShillProfileClient::AddService(const std::string& profile_path, | 162 bool FakeShillProfileClient::AddService(const std::string& profile_path, |
| 158 const std::string& service_path) { | 163 const std::string& service_path) { |
| 159 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), | 164 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), |
| 160 ErrorCallback()); | 165 ErrorCallback()); |
| 161 if (!profile) { | 166 if (!profile) { |
| 162 LOG(ERROR) << "AddService: No matching profile: " << profile_path | 167 LOG(ERROR) << "AddService: No matching profile: " << profile_path |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 base::Value profile_path_value(profile_path); | 209 base::Value profile_path_value(profile_path); |
| 205 service_test->SetServiceProperty(service_path, | 210 service_test->SetServiceProperty(service_path, |
| 206 shill::kProfileProperty, | 211 shill::kProfileProperty, |
| 207 profile_path_value); | 212 profile_path_value); |
| 208 } else if (service_profile_path != profile_path) { | 213 } else if (service_profile_path != profile_path) { |
| 209 LOG(ERROR) << "Service has non matching profile path: " | 214 LOG(ERROR) << "Service has non matching profile path: " |
| 210 << service_profile_path; | 215 << service_profile_path; |
| 211 return false; | 216 return false; |
| 212 } | 217 } |
| 213 | 218 |
| 214 profile->entries.SetWithoutPathExpansion(service_path, | 219 profile->entries.SetWithoutPathExpansion( |
| 215 service_properties->DeepCopy()); | 220 service_path, base::MakeUnique<base::Value>(*service_properties)); |
| 216 return true; | 221 return true; |
| 217 } | 222 } |
| 218 | 223 |
| 219 void FakeShillProfileClient::GetProfilePaths( | 224 void FakeShillProfileClient::GetProfilePaths( |
| 220 std::vector<std::string>* profiles) { | 225 std::vector<std::string>* profiles) { |
| 221 for (const auto& profile : profiles_) | 226 for (const auto& profile : profiles_) |
| 222 profiles->push_back(profile->path); | 227 profiles->push_back(profile->path); |
| 223 } | 228 } |
| 224 | 229 |
| 225 void FakeShillProfileClient::GetProfilePathsContainingService( | 230 void FakeShillProfileClient::GetProfilePathsContainingService( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 return false; | 277 return false; |
| 273 } | 278 } |
| 274 | 279 |
| 275 if (properties) | 280 if (properties) |
| 276 properties->MergeDictionary(entry); | 281 properties->MergeDictionary(entry); |
| 277 | 282 |
| 278 return true; | 283 return true; |
| 279 } | 284 } |
| 280 | 285 |
| 281 } // namespace chromeos | 286 } // namespace chromeos |
| OLD | NEW |