Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | 12 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/shill_manager_client.h" | 13 #include "chromeos/dbus/shill_manager_client.h" |
| 14 #include "chromeos/dbus/shill_property_changed_observer.h" | 14 #include "chromeos/dbus/shill_property_changed_observer.h" |
| 15 #include "chromeos/dbus/shill_service_client.h" | 15 #include "chromeos/dbus/shill_service_client.h" |
| 16 #include "dbus/bus.h" | 16 #include "dbus/bus.h" |
| 17 #include "dbus/message.h" | 17 #include "dbus/message.h" |
| 18 #include "dbus/object_path.h" | 18 #include "dbus/object_path.h" |
| 19 #include "dbus/values_util.h" | 19 #include "dbus/values_util.h" |
| 20 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 struct FakeShillProfileClient::ProfileProperties { | 24 struct FakeShillProfileClient::ProfileProperties { |
| 25 base::DictionaryValue entries; | 25 base::DictionaryValue entries; // Dictionary of Service Dictionaries |
| 26 base::DictionaryValue properties; | 26 base::DictionaryValue properties; // Dictionary of Profile properties |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 void PassDictionary( | 31 void PassDictionary( |
| 32 const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback, | 32 const ShillProfileClient::DictionaryValueCallbackWithoutStatus& callback, |
| 33 const base::DictionaryValue* dictionary) { | 33 const base::DictionaryValue* dictionary) { |
| 34 callback.Run(*dictionary); | 34 callback.Run(*dictionary); |
| 35 } | 35 } |
| 36 | 36 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 136 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 137 AddProfile(profile_path); | 137 AddProfile(profile_path); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void FakeShillProfileClient::AddEntry(const std::string& profile_path, | 140 void FakeShillProfileClient::AddEntry(const std::string& profile_path, |
| 141 const std::string& entry_path, | 141 const std::string& entry_path, |
| 142 const base::DictionaryValue& properties) { | 142 const base::DictionaryValue& properties) { |
| 143 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), | 143 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), |
| 144 ErrorCallback()); | 144 ErrorCallback()); |
| 145 DCHECK(profile); | 145 DCHECK(profile); |
| 146 profile->entries.SetWithoutPathExpansion(entry_path, | 146 profile->entries.SetWithoutPathExpansion(entry_path, properties.DeepCopy()); |
| 147 properties.DeepCopy()); | |
| 148 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> | 147 DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> |
| 149 AddManagerService(entry_path, false /* visible */, false /* watch */); | 148 AddManagerService(entry_path, false /* visible */, false /* watch */); |
| 150 } | 149 } |
| 151 | 150 |
| 152 bool FakeShillProfileClient::AddService(const std::string& profile_path, | 151 bool FakeShillProfileClient::AddService(const std::string& profile_path, |
| 153 const std::string& service_path) { | 152 const std::string& service_path) { |
| 154 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), | 153 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), |
| 155 ErrorCallback()); | 154 ErrorCallback()); |
| 156 if (!profile) { | 155 if (!profile) { |
| 157 LOG(ERROR) << "No matching profile: " << profile_path; | 156 LOG(ERROR) << "AddService: No matching profile: " << profile_path; |
| 158 return false; | 157 return false; |
| 159 } | 158 } |
| 159 if (profile->entries.HasKey(service_path)) { | |
| 160 LOG(ERROR) << "AddService: Profile: " << profile_path | |
| 161 << " already contains Service: " << service_path; | |
| 162 return false; | |
| 163 } | |
| 164 return AddOrUpdateServiceImpl(profile, profile_path, service_path); | |
| 165 } | |
| 160 | 166 |
| 167 bool FakeShillProfileClient::UpdateService(const std::string& profile_path, | |
| 168 const std::string& service_path) { | |
| 169 ProfileProperties* profile = GetProfile(dbus::ObjectPath(profile_path), | |
| 170 ErrorCallback()); | |
| 171 if (!profile) { | |
| 172 LOG(ERROR) << "UpdateService: No matching profile: " << profile_path; | |
| 173 return false; | |
| 174 } | |
| 175 if (!profile->entries.HasKey(service_path)) { | |
| 176 LOG(ERROR) << "UpdateService: Profile: " << profile_path | |
| 177 << " does not contain Service: " << service_path; | |
| 178 return false; | |
| 179 } | |
| 180 return AddOrUpdateServiceImpl(profile, profile_path, service_path); | |
| 181 } | |
| 182 | |
| 183 bool FakeShillProfileClient::AddOrUpdateServiceImpl( | |
| 184 ProfileProperties* profile, | |
| 185 const std::string& profile_path, | |
| 186 const std::string& service_path) { | |
| 161 ShillServiceClient::TestInterface* service_test = | 187 ShillServiceClient::TestInterface* service_test = |
| 162 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 188 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 163 const base::DictionaryValue* service_properties = | 189 const base::DictionaryValue* service_properties = |
| 164 service_test->GetServiceProperties(service_path); | 190 service_test->GetServiceProperties(service_path); |
| 165 if (!service_properties) { | 191 if (!service_properties) { |
| 166 LOG(ERROR) << "No matching service: " << service_path; | 192 LOG(ERROR) << "No matching service: " << service_path; |
| 167 return false; | 193 return false; |
| 168 } | 194 } |
| 169 std::string service_profile_path; | 195 std::string service_profile_path; |
| 170 service_properties->GetStringWithoutPathExpansion(shill::kProfileProperty, | 196 service_properties->GetStringWithoutPathExpansion(shill::kProfileProperty, |
| 171 &service_profile_path); | 197 &service_profile_path); |
| 172 if (!service_profile_path.empty() && service_profile_path != profile_path) { | 198 if (service_profile_path.empty()) { |
| 199 base::StringValue profile_path_value(profile_path); | |
| 200 service_test->SetServiceProperty(service_path, | |
| 201 shill::kProfileProperty, | |
| 202 profile_path_value); | |
| 203 } else if (service_profile_path != profile_path) { | |
| 173 LOG(ERROR) << "Service has non matching profile path: " | 204 LOG(ERROR) << "Service has non matching profile path: " |
| 174 << service_profile_path; | 205 << service_profile_path; |
| 175 return false; | 206 return false; |
| 176 } | 207 } |
| 177 | 208 |
| 178 base::StringValue profile_path_value(profile_path); | |
| 179 service_test->SetServiceProperty(service_path, | |
| 180 shill::kProfileProperty, | |
| 181 profile_path_value); | |
| 182 profile->entries.SetWithoutPathExpansion(service_path, | 209 profile->entries.SetWithoutPathExpansion(service_path, |
| 183 service_properties->DeepCopy()); | 210 service_properties->DeepCopy()); |
| 184 return true; | 211 return true; |
| 185 } | 212 } |
| 186 | 213 |
| 187 void FakeShillProfileClient::GetProfilePaths( | 214 void FakeShillProfileClient::GetProfilePaths( |
| 188 std::vector<std::string>* profiles) { | 215 std::vector<std::string>* profiles) { |
| 189 for (ProfileMap::iterator iter = profiles_.begin(); | 216 for (ProfileMap::iterator iter = profiles_.begin(); |
| 190 iter != profiles_.end(); ++iter) { | 217 iter != profiles_.end(); ++iter) { |
| 191 profiles->push_back(iter->first); | 218 profiles->push_back(iter->first); |
| 192 } | 219 } |
| 193 } | 220 } |
| 194 | 221 |
| 222 bool FakeShillProfileClient::GetService(const std::string& service_path, | |
| 223 std::string* profile_path, | |
| 224 base::DictionaryValue* properties) { | |
| 225 properties->Clear(); | |
| 226 for (ProfileMap::const_iterator iter = profiles_.begin(); | |
| 227 iter != profiles_.end(); ++iter) { | |
| 228 const ProfileProperties* profile = iter->second; | |
| 229 const base::DictionaryValue* entry; | |
| 230 if (!profile->entries.GetDictionaryWithoutPathExpansion( | |
| 231 service_path, &entry)) { | |
| 232 continue; | |
| 233 } | |
| 234 *profile_path = iter->first; | |
| 235 properties->MergeDictionary(entry); | |
| 236 return true; | |
| 237 } | |
| 238 return false; | |
| 239 } | |
| 240 | |
| 241 void FakeShillProfileClient::ClearProfiles() { | |
| 242 STLDeleteValues(&profiles_); | |
| 243 profiles_.clear(); | |
|
pneubeck (no reviews)
2014/05/14 08:12:17
Redundant, STLDeleteValues also clears.
stevenjb
2014/05/14 17:08:10
So it does. done.
| |
| 244 } | |
| 245 | |
| 195 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile( | 246 FakeShillProfileClient::ProfileProperties* FakeShillProfileClient::GetProfile( |
| 196 const dbus::ObjectPath& profile_path, | 247 const dbus::ObjectPath& profile_path, |
| 197 const ErrorCallback& error_callback) { | 248 const ErrorCallback& error_callback) { |
| 198 ProfileMap::const_iterator found = profiles_.find(profile_path.value()); | 249 ProfileMap::const_iterator found = profiles_.find(profile_path.value()); |
| 199 if (found == profiles_.end()) { | 250 if (found == profiles_.end()) { |
| 200 if (!error_callback.is_null()) | 251 if (!error_callback.is_null()) |
| 201 error_callback.Run("Error.InvalidProfile", "Invalid profile"); | 252 error_callback.Run("Error.InvalidProfile", "Invalid profile"); |
| 202 return NULL; | 253 return NULL; |
| 203 } | 254 } |
| 204 | 255 |
| 205 return found->second; | 256 return found->second; |
| 206 } | 257 } |
| 207 | 258 |
| 208 } // namespace chromeos | 259 } // namespace chromeos |
| OLD | NEW |