OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/network/network_configuration_handler.h" | 5 #include "chromeos/network/network_configuration_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
20 #include "chromeos/dbus/shill_manager_client.h" | 20 #include "chromeos/dbus/shill_manager_client.h" |
21 #include "chromeos/dbus/shill_profile_client.h" | 21 #include "chromeos/dbus/shill_profile_client.h" |
22 #include "chromeos/dbus/shill_service_client.h" | 22 #include "chromeos/dbus/shill_service_client.h" |
23 #include "chromeos/network/network_device_handler.h" | |
23 #include "chromeos/network/network_event_log.h" | 24 #include "chromeos/network/network_event_log.h" |
24 #include "chromeos/network/network_state.h" | 25 #include "chromeos/network/network_state.h" |
25 #include "chromeos/network/network_state_handler.h" | 26 #include "chromeos/network/network_state_handler.h" |
26 #include "chromeos/network/shill_property_util.h" | 27 #include "chromeos/network/shill_property_util.h" |
27 #include "dbus/object_path.h" | 28 #include "dbus/object_path.h" |
28 #include "third_party/cros_system_api/dbus/service_constants.h" | 29 #include "third_party/cros_system_api/dbus/service_constants.h" |
29 | 30 |
30 namespace chromeos { | 31 namespace chromeos { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Strip surrounding "" from keys (if present). | 35 // Strip surrounding "" from keys (if present). |
35 std::string StripQuotations(const std::string& in_str) { | 36 std::string StripQuotations(const std::string& in_str) { |
36 size_t len = in_str.length(); | 37 size_t len = in_str.length(); |
37 if (len >= 2 && in_str[0] == '"' && in_str[len-1] == '"') | 38 if (len >= 2 && in_str[0] == '"' && in_str[len - 1] == '"') |
38 return in_str.substr(1, len-2); | 39 return in_str.substr(1, len - 2); |
39 return in_str; | 40 return in_str; |
40 } | 41 } |
41 | 42 |
42 void InvokeErrorCallback(const std::string& service_path, | 43 void InvokeErrorCallback(const std::string& service_path, |
43 const network_handler::ErrorCallback& error_callback, | 44 const network_handler::ErrorCallback& error_callback, |
44 const std::string& error_name) { | 45 const std::string& error_name) { |
45 std::string error_msg = "Config Error: " + error_name; | 46 std::string error_msg = "Config Error: " + error_name; |
46 NET_LOG_ERROR(error_msg, service_path); | 47 NET_LOG_ERROR(error_msg, service_path); |
47 network_handler::RunErrorCallback( | 48 network_handler::RunErrorCallback(error_callback, service_path, error_name, |
48 error_callback, service_path, error_name, error_msg); | 49 error_msg); |
49 } | 50 } |
50 | 51 |
51 void GetPropertiesCallback( | 52 void GetPropertiesCallback( |
52 const network_handler::DictionaryResultCallback& callback, | 53 const network_handler::DictionaryResultCallback& callback, |
53 const network_handler::ErrorCallback& error_callback, | 54 const network_handler::ErrorCallback& error_callback, |
54 const std::string& service_path, | 55 const std::string& service_path, |
55 DBusMethodCallStatus call_status, | 56 DBusMethodCallStatus call_status, |
56 const base::DictionaryValue& properties) { | 57 const base::DictionaryValue& properties) { |
57 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 58 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
58 // Because network services are added and removed frequently, we will see | 59 // Because network services are added and removed frequently, we will see |
59 // failures regularly, so don't log these. | 60 // failures regularly, so don't log these. |
60 network_handler::RunErrorCallback(error_callback, | 61 network_handler::RunErrorCallback(error_callback, service_path, |
61 service_path, | |
62 network_handler::kDBusFailedError, | 62 network_handler::kDBusFailedError, |
63 network_handler::kDBusFailedErrorMessage); | 63 network_handler::kDBusFailedErrorMessage); |
64 return; | 64 return; |
65 } | 65 } |
66 if (callback.is_null()) | 66 if (callback.is_null()) |
67 return; | 67 return; |
68 | 68 |
69 // Get the correct name from WifiHex if necessary. | 69 // Get the correct name from WifiHex if necessary. |
70 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy()); | 70 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy()); |
71 std::string name = | 71 std::string name = |
72 shill_property_util::GetNameFromProperties(service_path, properties); | 72 shill_property_util::GetNameFromProperties(service_path, properties); |
73 if (!name.empty()) | 73 if (!name.empty()) |
74 properties_copy->SetStringWithoutPathExpansion(shill::kNameProperty, name); | 74 properties_copy->SetStringWithoutPathExpansion(shill::kNameProperty, name); |
75 callback.Run(service_path, *properties_copy.get()); | 75 callback.Run(service_path, *properties_copy.get()); |
76 } | 76 } |
77 | 77 |
78 void SetNetworkProfileErrorCallback( | 78 void SetNetworkProfileErrorCallback( |
79 const std::string& service_path, | 79 const std::string& service_path, |
80 const std::string& profile_path, | 80 const std::string& profile_path, |
81 const network_handler::ErrorCallback& error_callback, | 81 const network_handler::ErrorCallback& error_callback, |
82 const std::string& dbus_error_name, | 82 const std::string& dbus_error_name, |
83 const std::string& dbus_error_message) { | 83 const std::string& dbus_error_message) { |
84 network_handler::ShillErrorCallbackFunction( | 84 network_handler::ShillErrorCallbackFunction( |
85 "Config.SetNetworkProfile Failed: " + profile_path, | 85 "Config.SetNetworkProfile Failed: " + profile_path, service_path, |
86 service_path, error_callback, | 86 error_callback, dbus_error_name, dbus_error_message); |
87 dbus_error_name, dbus_error_message); | |
88 } | 87 } |
89 | 88 |
90 void LogConfigProperties(const std::string& desc, | 89 void LogConfigProperties(const std::string& desc, |
91 const std::string& path, | 90 const std::string& path, |
92 const base::DictionaryValue& properties) { | 91 const base::DictionaryValue& properties) { |
93 for (base::DictionaryValue::Iterator iter(properties); | 92 for (base::DictionaryValue::Iterator iter(properties); !iter.IsAtEnd(); |
94 !iter.IsAtEnd(); iter.Advance()) { | 93 iter.Advance()) { |
95 std::string v = "******"; | 94 std::string v = "******"; |
96 if (!shill_property_util::IsPassphraseKey(iter.key())) | 95 if (!shill_property_util::IsPassphraseKey(iter.key())) |
97 base::JSONWriter::Write(&iter.value(), &v); | 96 base::JSONWriter::Write(&iter.value(), &v); |
98 NET_LOG_DEBUG(desc, path + "." + iter.key() + "=" + v); | 97 NET_LOG_DEBUG(desc, path + "." + iter.key() + "=" + v); |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
101 bool PropertyRequiresIPConfigRefresh(const std::string& key) { | |
102 return key == shill::kStaticIPAddressProperty || | |
103 key == shill::kStaticIPPrefixlenProperty || | |
104 key == shill::kStaticIPGatewayProperty || | |
105 key == shill::kStaticIPNameServersProperty; | |
106 } | |
107 | |
102 } // namespace | 108 } // namespace |
103 | 109 |
104 // Helper class to request from Shill the profile entries associated with a | 110 // Helper class to request from Shill the profile entries associated with a |
105 // Service and delete the service from each profile. Triggers either | 111 // Service and delete the service from each profile. Triggers either |
106 // |callback| on success or |error_callback| on failure, and calls | 112 // |callback| on success or |error_callback| on failure, and calls |
107 // |handler|->ProfileEntryDeleterCompleted() on completion to delete itself. | 113 // |handler|->ProfileEntryDeleterCompleted() on completion to delete itself. |
108 class NetworkConfigurationHandler::ProfileEntryDeleter | 114 class NetworkConfigurationHandler::ProfileEntryDeleter |
109 : public base::SupportsWeakPtr<ProfileEntryDeleter> { | 115 : public base::SupportsWeakPtr<ProfileEntryDeleter> { |
110 public: | 116 public: |
111 ProfileEntryDeleter(NetworkConfigurationHandler* handler, | 117 ProfileEntryDeleter(NetworkConfigurationHandler* handler, |
112 const std::string& service_path, | 118 const std::string& service_path, |
113 const std::string& guid, | 119 const std::string& guid, |
114 NetworkConfigurationObserver::Source source, | 120 NetworkConfigurationObserver::Source source, |
115 const base::Closure& callback, | 121 const base::Closure& callback, |
116 const network_handler::ErrorCallback& error_callback) | 122 const network_handler::ErrorCallback& error_callback) |
117 : owner_(handler), | 123 : owner_(handler), |
118 service_path_(service_path), | 124 service_path_(service_path), |
119 guid_(guid), | 125 guid_(guid), |
120 source_(source), | 126 source_(source), |
121 callback_(callback), | 127 callback_(callback), |
122 error_callback_(error_callback) { | 128 error_callback_(error_callback) {} |
123 } | |
124 | 129 |
125 void Run() { | 130 void Run() { |
126 DBusThreadManager::Get()->GetShillServiceClient()-> | 131 DBusThreadManager::Get() |
127 GetLoadableProfileEntries( | 132 ->GetShillServiceClient() |
133 ->GetLoadableProfileEntries( | |
128 dbus::ObjectPath(service_path_), | 134 dbus::ObjectPath(service_path_), |
129 base::Bind(&ProfileEntryDeleter::GetProfileEntriesToDeleteCallback, | 135 base::Bind(&ProfileEntryDeleter::GetProfileEntriesToDeleteCallback, |
130 AsWeakPtr())); | 136 AsWeakPtr())); |
131 } | 137 } |
132 | 138 |
133 private: | 139 private: |
134 void GetProfileEntriesToDeleteCallback( | 140 void GetProfileEntriesToDeleteCallback( |
135 DBusMethodCallStatus call_status, | 141 DBusMethodCallStatus call_status, |
136 const base::DictionaryValue& profile_entries) { | 142 const base::DictionaryValue& profile_entries) { |
137 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 143 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
138 InvokeErrorCallback( | 144 InvokeErrorCallback(service_path_, error_callback_, |
139 service_path_, error_callback_, "GetLoadableProfileEntriesFailed"); | 145 "GetLoadableProfileEntriesFailed"); |
140 // ProfileEntryDeleterCompleted will delete this. | 146 // ProfileEntryDeleterCompleted will delete this. |
141 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, | 147 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, |
142 false /* failed */); | 148 false /* failed */); |
143 return; | 149 return; |
144 } | 150 } |
145 | 151 |
146 for (base::DictionaryValue::Iterator iter(profile_entries); | 152 for (base::DictionaryValue::Iterator iter(profile_entries); !iter.IsAtEnd(); |
147 !iter.IsAtEnd(); iter.Advance()) { | 153 iter.Advance()) { |
148 std::string profile_path = StripQuotations(iter.key()); | 154 std::string profile_path = StripQuotations(iter.key()); |
149 std::string entry_path; | 155 std::string entry_path; |
150 iter.value().GetAsString(&entry_path); | 156 iter.value().GetAsString(&entry_path); |
151 if (profile_path.empty() || entry_path.empty()) { | 157 if (profile_path.empty() || entry_path.empty()) { |
152 NET_LOG_ERROR("Failed to parse Profile Entry", base::StringPrintf( | 158 NET_LOG_ERROR("Failed to parse Profile Entry", |
153 "%s: %s", profile_path.c_str(), entry_path.c_str())); | 159 base::StringPrintf("%s: %s", profile_path.c_str(), |
160 entry_path.c_str())); | |
154 continue; | 161 continue; |
155 } | 162 } |
156 if (profile_delete_entries_.count(profile_path) != 0) { | 163 if (profile_delete_entries_.count(profile_path) != 0) { |
157 NET_LOG_ERROR("Multiple Profile Entries", base::StringPrintf( | 164 NET_LOG_ERROR("Multiple Profile Entries", |
158 "%s: %s", profile_path.c_str(), entry_path.c_str())); | 165 base::StringPrintf("%s: %s", profile_path.c_str(), |
166 entry_path.c_str())); | |
159 continue; | 167 continue; |
160 } | 168 } |
161 NET_LOG_DEBUG("Delete Profile Entry", base::StringPrintf( | 169 NET_LOG_DEBUG("Delete Profile Entry", |
162 "%s: %s", profile_path.c_str(), entry_path.c_str())); | 170 base::StringPrintf("%s: %s", profile_path.c_str(), |
171 entry_path.c_str())); | |
163 profile_delete_entries_[profile_path] = entry_path; | 172 profile_delete_entries_[profile_path] = entry_path; |
164 DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry( | 173 DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry( |
165 dbus::ObjectPath(profile_path), | 174 dbus::ObjectPath(profile_path), entry_path, |
166 entry_path, | |
167 base::Bind(&ProfileEntryDeleter::ProfileEntryDeletedCallback, | 175 base::Bind(&ProfileEntryDeleter::ProfileEntryDeletedCallback, |
168 AsWeakPtr(), profile_path, entry_path), | 176 AsWeakPtr(), profile_path, entry_path), |
169 base::Bind(&ProfileEntryDeleter::ShillErrorCallback, | 177 base::Bind(&ProfileEntryDeleter::ShillErrorCallback, AsWeakPtr(), |
170 AsWeakPtr(), profile_path, entry_path)); | 178 profile_path, entry_path)); |
171 } | 179 } |
172 } | 180 } |
173 | 181 |
174 void ProfileEntryDeletedCallback(const std::string& profile_path, | 182 void ProfileEntryDeletedCallback(const std::string& profile_path, |
175 const std::string& entry) { | 183 const std::string& entry) { |
176 NET_LOG_DEBUG("Profile Entry Deleted", base::StringPrintf( | 184 NET_LOG_DEBUG( |
177 "%s: %s", profile_path.c_str(), entry.c_str())); | 185 "Profile Entry Deleted", |
186 base::StringPrintf("%s: %s", profile_path.c_str(), entry.c_str())); | |
178 profile_delete_entries_.erase(profile_path); | 187 profile_delete_entries_.erase(profile_path); |
179 if (!profile_delete_entries_.empty()) | 188 if (!profile_delete_entries_.empty()) |
180 return; | 189 return; |
181 // Run the callback if this is the last pending deletion. | 190 // Run the callback if this is the last pending deletion. |
182 if (!callback_.is_null()) | 191 if (!callback_.is_null()) |
183 callback_.Run(); | 192 callback_.Run(); |
184 // ProfileEntryDeleterCompleted will delete this. | 193 // ProfileEntryDeleterCompleted will delete this. |
185 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, | 194 owner_->ProfileEntryDeleterCompleted(service_path_, guid_, source_, |
186 true /* success */); | 195 true /* success */); |
187 } | 196 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 observers_.RemoveObserver(observer); | 234 observers_.RemoveObserver(observer); |
226 } | 235 } |
227 | 236 |
228 void NetworkConfigurationHandler::GetProperties( | 237 void NetworkConfigurationHandler::GetProperties( |
229 const std::string& service_path, | 238 const std::string& service_path, |
230 const network_handler::DictionaryResultCallback& callback, | 239 const network_handler::DictionaryResultCallback& callback, |
231 const network_handler::ErrorCallback& error_callback) const { | 240 const network_handler::ErrorCallback& error_callback) const { |
232 NET_LOG_USER("GetProperties", service_path); | 241 NET_LOG_USER("GetProperties", service_path); |
233 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( | 242 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( |
234 dbus::ObjectPath(service_path), | 243 dbus::ObjectPath(service_path), |
235 base::Bind(&GetPropertiesCallback, | 244 base::Bind(&GetPropertiesCallback, callback, error_callback, |
236 callback, error_callback, service_path)); | 245 service_path)); |
237 } | 246 } |
238 | 247 |
239 void NetworkConfigurationHandler::SetProperties( | 248 void NetworkConfigurationHandler::SetProperties( |
240 const std::string& service_path, | 249 const std::string& service_path, |
241 const base::DictionaryValue& properties, | 250 const base::DictionaryValue& properties, |
242 NetworkConfigurationObserver::Source source, | 251 NetworkConfigurationObserver::Source source, |
243 const base::Closure& callback, | 252 const base::Closure& callback, |
244 const network_handler::ErrorCallback& error_callback) { | 253 const network_handler::ErrorCallback& error_callback) { |
245 if (properties.empty()) { | 254 if (properties.empty()) { |
246 if (!callback.is_null()) | 255 if (!callback.is_null()) |
247 callback.Run(); | 256 callback.Run(); |
248 return; | 257 return; |
249 } | 258 } |
250 NET_LOG_USER("SetProperties", service_path); | 259 NET_LOG_USER("SetProperties", service_path); |
251 LogConfigProperties("SetProperty", service_path, properties); | |
252 | 260 |
261 // Copy |properties| to |properties_to_set| then iterate over |properties| and | |
262 // move any NULL properties to |properties_to_clear|, removing them from | |
263 // |properties_to_set|. | |
264 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); | |
265 std::vector<std::string> properties_to_clear; | |
266 for (base::DictionaryValue::Iterator iter(properties); !iter.IsAtEnd(); | |
267 iter.Advance()) { | |
268 const std::string& key = iter.key(); | |
269 const base::Value& value = iter.value(); | |
270 if (value.IsType(base::Value::TYPE_NULL)) { | |
271 properties_to_set->RemoveWithoutPathExpansion(key, nullptr); | |
272 properties_to_clear.push_back(key); | |
273 } else if (value.IsType(base::Value::TYPE_DICTIONARY)) { | |
pneubeck (no reviews)
2014/12/05 09:47:46
isn't this rather dangerous if you want to support
stevenjb
2015/01/08 00:44:39
Removed (for now at least) since we are using empt
| |
274 // Also clear empty dictionaries. | |
275 const base::DictionaryValue* dictionary; | |
276 if (!value.GetAsDictionary(&dictionary) || dictionary->empty()) { | |
pneubeck (no reviews)
2014/12/05 09:47:46
this check for !GetAsDictionary after IsType(Dicti
stevenjb
2015/01/08 00:44:39
Acknowledged.
| |
277 properties_to_set->RemoveWithoutPathExpansion(key, nullptr); | |
278 properties_to_clear.push_back(key); | |
279 } | |
280 } | |
281 } | |
282 | |
283 // Copy input properties to pass to observers on completion. | |
253 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy()); | 284 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy()); |
254 DBusThreadManager::Get()->GetShillServiceClient()->SetProperties( | 285 |
255 dbus::ObjectPath(service_path), properties, | 286 if (!properties_to_clear.empty()) { |
256 base::Bind(&NetworkConfigurationHandler::SetPropertiesSuccessCallback, | 287 // ClearProperties chains a Shill GetProperties request followed by a Shill |
257 AsWeakPtr(), service_path, base::Passed(&properties_copy), | 288 // ClearProperties request, so wait for those to complete before setting any |
258 source, callback), | 289 // properties. |
259 base::Bind(&NetworkConfigurationHandler::SetPropertiesErrorCallback, | 290 ClearProperties( |
pneubeck (no reviews)
2014/12/05 09:47:46
is this behavior covered in NCH unit tests already
stevenjb
2015/01/08 00:44:39
Removed for now.
| |
260 AsWeakPtr(), service_path, error_callback)); | 291 service_path, properties_to_clear, |
292 base::Bind(&NetworkConfigurationHandler::SendSetPropertiesToShill, | |
293 AsWeakPtr(), service_path, base::Passed(&properties_copy), | |
294 base::Passed(&properties_to_set), source, callback, | |
295 error_callback), | |
296 error_callback); | |
297 } else { | |
298 SendSetPropertiesToShill(service_path, properties_copy.Pass(), | |
299 properties_to_set.Pass(), source, callback, | |
300 error_callback); | |
301 } | |
261 } | 302 } |
262 | 303 |
263 void NetworkConfigurationHandler::ClearProperties( | 304 void NetworkConfigurationHandler::ClearProperties( |
264 const std::string& service_path, | 305 const std::string& service_path, |
265 const std::vector<std::string>& names, | 306 const std::vector<std::string>& names, |
266 const base::Closure& callback, | 307 const base::Closure& callback, |
267 const network_handler::ErrorCallback& error_callback) { | 308 const network_handler::ErrorCallback& error_callback) { |
268 if (names.empty()) { | 309 if (names.empty()) { |
269 if (!callback.is_null()) | 310 if (!callback.is_null()) |
270 callback.Run(); | 311 callback.Run(); |
271 return; | 312 return; |
272 } | 313 } |
273 NET_LOG_USER("ClearProperties", service_path); | 314 NET_LOG_USER("ClearProperties", service_path); |
274 for (std::vector<std::string>::const_iterator iter = names.begin(); | 315 // Shill triggers an error if we clear properties that are unset, so |
275 iter != names.end(); ++iter) { | 316 // first get the current properties. |
276 NET_LOG_DEBUG("ClearProperty", service_path + "." + *iter); | 317 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( |
277 } | |
278 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( | |
279 dbus::ObjectPath(service_path), | 318 dbus::ObjectPath(service_path), |
280 names, | 319 base::Bind(&NetworkConfigurationHandler::ClearPropertiesGetCallback, |
281 base::Bind(&NetworkConfigurationHandler::ClearPropertiesSuccessCallback, | 320 AsWeakPtr(), service_path, names, callback, error_callback)); |
282 AsWeakPtr(), service_path, names, callback), | |
283 base::Bind(&NetworkConfigurationHandler::ClearPropertiesErrorCallback, | |
284 AsWeakPtr(), service_path, error_callback)); | |
285 } | 321 } |
286 | 322 |
287 void NetworkConfigurationHandler::CreateConfiguration( | 323 void NetworkConfigurationHandler::CreateConfiguration( |
288 const base::DictionaryValue& properties, | 324 const base::DictionaryValue& properties, |
289 NetworkConfigurationObserver::Source source, | 325 NetworkConfigurationObserver::Source source, |
290 const network_handler::StringResultCallback& callback, | 326 const network_handler::StringResultCallback& callback, |
291 const network_handler::ErrorCallback& error_callback) { | 327 const network_handler::ErrorCallback& error_callback) { |
292 ShillManagerClient* manager = | 328 ShillManagerClient* manager = |
293 DBusThreadManager::Get()->GetShillManagerClient(); | 329 DBusThreadManager::Get()->GetShillManagerClient(); |
294 std::string type; | 330 std::string type; |
295 properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); | 331 properties.GetStringWithoutPathExpansion(shill::kTypeProperty, &type); |
296 DCHECK(!type.empty()); | 332 DCHECK(!type.empty()); |
297 if (NetworkTypePattern::Ethernet().MatchesType(type)) { | 333 if (NetworkTypePattern::Ethernet().MatchesType(type)) { |
298 InvokeErrorCallback( | 334 InvokeErrorCallback( |
299 shill_property_util::GetNetworkIdFromProperties(properties), | 335 shill_property_util::GetNetworkIdFromProperties(properties), |
300 error_callback, | 336 error_callback, "ConfigureServiceForProfile: Invalid type: " + type); |
301 "ConfigureServiceForProfile: Invalid type: " + type); | |
302 return; | 337 return; |
303 } | 338 } |
304 | 339 |
305 NET_LOG_USER("CreateConfiguration: " + type, | 340 NET_LOG_USER("CreateConfiguration: " + type, |
306 shill_property_util::GetNetworkIdFromProperties(properties)); | 341 shill_property_util::GetNetworkIdFromProperties(properties)); |
307 LogConfigProperties("Configure", type, properties); | 342 LogConfigProperties("Configure", type, properties); |
308 | 343 |
309 std::string profile_path; | 344 std::string profile_path; |
310 properties.GetStringWithoutPathExpansion(shill::kProfileProperty, | 345 properties.GetStringWithoutPathExpansion(shill::kProfileProperty, |
311 &profile_path); | 346 &profile_path); |
312 DCHECK(!profile_path.empty()); | 347 DCHECK(!profile_path.empty()); |
313 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy()); | 348 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy()); |
314 manager->ConfigureServiceForProfile( | 349 manager->ConfigureServiceForProfile( |
315 dbus::ObjectPath(profile_path), properties, | 350 dbus::ObjectPath(profile_path), properties, |
316 base::Bind(&NetworkConfigurationHandler::RunCreateNetworkCallback, | 351 base::Bind(&NetworkConfigurationHandler::RunCreateNetworkCallback, |
317 AsWeakPtr(), profile_path, source, | 352 AsWeakPtr(), profile_path, source, |
318 base::Passed(&properties_copy), callback), | 353 base::Passed(&properties_copy), callback), |
319 base::Bind(&network_handler::ShillErrorCallbackFunction, | 354 base::Bind(&network_handler::ShillErrorCallbackFunction, |
320 "Config.CreateConfiguration Failed", "", error_callback)); | 355 "Config.CreateConfiguration Failed", "", error_callback)); |
321 } | 356 } |
322 | 357 |
323 void NetworkConfigurationHandler::RemoveConfiguration( | 358 void NetworkConfigurationHandler::RemoveConfiguration( |
324 const std::string& service_path, | 359 const std::string& service_path, |
325 NetworkConfigurationObserver::Source source, | 360 NetworkConfigurationObserver::Source source, |
326 const base::Closure& callback, | 361 const base::Closure& callback, |
327 const network_handler::ErrorCallback& error_callback) { | 362 const network_handler::ErrorCallback& error_callback) { |
328 // Service.Remove is not reliable. Instead, request the profile entries | 363 // Service.Remove is not reliable. Instead, request the profile entries |
329 // for the service and remove each entry. | 364 // for the service and remove each entry. |
330 if (ContainsKey(profile_entry_deleters_, service_path)) { | 365 if (ContainsKey(profile_entry_deleters_, service_path)) { |
331 InvokeErrorCallback( | 366 InvokeErrorCallback(service_path, error_callback, |
332 service_path, error_callback, "RemoveConfigurationInProgress"); | 367 "RemoveConfigurationInProgress"); |
333 return; | 368 return; |
334 } | 369 } |
335 | 370 |
336 std::string guid; | 371 std::string guid; |
337 const NetworkState* network_state = | 372 const NetworkState* network_state = |
338 network_state_handler_->GetNetworkState(service_path); | 373 network_state_handler_->GetNetworkState(service_path); |
339 if (network_state) | 374 if (network_state) |
340 guid = network_state->guid(); | 375 guid = network_state->guid(); |
341 NET_LOG_USER("Remove Configuration", service_path); | 376 NET_LOG_USER("Remove Configuration", service_path); |
342 ProfileEntryDeleter* deleter = new ProfileEntryDeleter( | 377 ProfileEntryDeleter* deleter = new ProfileEntryDeleter( |
(...skipping 19 matching lines...) Expand all Loading... | |
362 error_callback)); | 397 error_callback)); |
363 } | 398 } |
364 | 399 |
365 // NetworkConfigurationHandler Private methods | 400 // NetworkConfigurationHandler Private methods |
366 | 401 |
367 NetworkConfigurationHandler::NetworkConfigurationHandler() | 402 NetworkConfigurationHandler::NetworkConfigurationHandler() |
368 : network_state_handler_(NULL) { | 403 : network_state_handler_(NULL) { |
369 } | 404 } |
370 | 405 |
371 NetworkConfigurationHandler::~NetworkConfigurationHandler() { | 406 NetworkConfigurationHandler::~NetworkConfigurationHandler() { |
372 STLDeleteContainerPairSecondPointers( | 407 STLDeleteContainerPairSecondPointers(profile_entry_deleters_.begin(), |
373 profile_entry_deleters_.begin(), profile_entry_deleters_.end()); | 408 profile_entry_deleters_.end()); |
374 } | 409 } |
375 | 410 |
376 void NetworkConfigurationHandler::Init( | 411 void NetworkConfigurationHandler::Init( |
377 NetworkStateHandler* network_state_handler) { | 412 NetworkStateHandler* network_state_handler, |
413 NetworkDeviceHandler* network_device_handler) { | |
378 network_state_handler_ = network_state_handler; | 414 network_state_handler_ = network_state_handler; |
415 network_device_handler_ = network_device_handler; | |
379 } | 416 } |
380 | 417 |
381 void NetworkConfigurationHandler::RunCreateNetworkCallback( | 418 void NetworkConfigurationHandler::RunCreateNetworkCallback( |
382 const std::string& profile_path, | 419 const std::string& profile_path, |
383 NetworkConfigurationObserver::Source source, | 420 NetworkConfigurationObserver::Source source, |
384 scoped_ptr<base::DictionaryValue> configure_properties, | 421 scoped_ptr<base::DictionaryValue> configure_properties, |
385 const network_handler::StringResultCallback& callback, | 422 const network_handler::StringResultCallback& callback, |
386 const dbus::ObjectPath& service_path) { | 423 const dbus::ObjectPath& service_path) { |
387 if (!callback.is_null()) | 424 if (!callback.is_null()) |
388 callback.Run(service_path.value()); | 425 callback.Run(service_path.value()); |
(...skipping 28 matching lines...) Expand all Loading... | |
417 const std::string& profile_path, | 454 const std::string& profile_path, |
418 NetworkConfigurationObserver::Source source, | 455 NetworkConfigurationObserver::Source source, |
419 const base::Closure& callback) { | 456 const base::Closure& callback) { |
420 if (!callback.is_null()) | 457 if (!callback.is_null()) |
421 callback.Run(); | 458 callback.Run(); |
422 FOR_EACH_OBSERVER( | 459 FOR_EACH_OBSERVER( |
423 NetworkConfigurationObserver, observers_, | 460 NetworkConfigurationObserver, observers_, |
424 OnConfigurationProfileChanged(service_path, profile_path, source)); | 461 OnConfigurationProfileChanged(service_path, profile_path, source)); |
425 } | 462 } |
426 | 463 |
464 void NetworkConfigurationHandler::SendSetPropertiesToShill( | |
465 const std::string& service_path, | |
466 scoped_ptr<base::DictionaryValue> changed_properties, | |
467 scoped_ptr<base::DictionaryValue> properties_to_set, | |
468 NetworkConfigurationObserver::Source source, | |
469 const base::Closure& callback, | |
470 const network_handler::ErrorCallback& error_callback) { | |
471 if (properties_to_set->empty()) { | |
472 SetPropertiesSuccessCallback(service_path, changed_properties.Pass(), | |
473 source, callback); | |
474 return; | |
475 } | |
476 | |
477 LogConfigProperties("SetProperty", service_path, *properties_to_set); | |
478 DBusThreadManager::Get()->GetShillServiceClient()->SetProperties( | |
479 dbus::ObjectPath(service_path), *properties_to_set, | |
480 base::Bind(&NetworkConfigurationHandler::SetPropertiesSuccessCallback, | |
481 AsWeakPtr(), service_path, base::Passed(&changed_properties), | |
482 source, callback), | |
483 base::Bind(&NetworkConfigurationHandler::SetPropertiesErrorCallback, | |
484 AsWeakPtr(), service_path, error_callback)); | |
485 | |
486 // If we set any properties that might affect IP config, request an IP config | |
487 // refresh after calling SetProperties. Note: it is possible (but unlikely and | |
488 // harmless) for both Set and Clear to trigger an IP Config refresh. | |
489 for (base::DictionaryValue::Iterator iter(*properties_to_set); | |
490 !iter.IsAtEnd(); iter.Advance()) { | |
491 const std::string& key = iter.key(); | |
492 if (PropertyRequiresIPConfigRefresh(key)) { | |
493 RequestRefreshIPConfigs(service_path); | |
494 break; | |
495 } | |
496 } | |
497 } | |
498 | |
427 void NetworkConfigurationHandler::SetPropertiesSuccessCallback( | 499 void NetworkConfigurationHandler::SetPropertiesSuccessCallback( |
428 const std::string& service_path, | 500 const std::string& service_path, |
429 scoped_ptr<base::DictionaryValue> set_properties, | 501 scoped_ptr<base::DictionaryValue> changed_properties, |
430 NetworkConfigurationObserver::Source source, | 502 NetworkConfigurationObserver::Source source, |
431 const base::Closure& callback) { | 503 const base::Closure& callback) { |
432 if (!callback.is_null()) | 504 if (!callback.is_null()) |
433 callback.Run(); | 505 callback.Run(); |
434 const NetworkState* network_state = | 506 const NetworkState* network_state = |
435 network_state_handler_->GetNetworkState(service_path); | 507 network_state_handler_->GetNetworkState(service_path); |
436 if (!network_state) | 508 if (!network_state) |
437 return; // Network no longer exists, do not notify or request update. | 509 return; // Network no longer exists, do not notify or request update. |
438 | 510 |
439 FOR_EACH_OBSERVER(NetworkConfigurationObserver, observers_, | 511 FOR_EACH_OBSERVER(NetworkConfigurationObserver, observers_, |
440 OnPropertiesSet(service_path, network_state->guid(), | 512 OnPropertiesSet(service_path, network_state->guid(), |
441 *set_properties, source)); | 513 *changed_properties, source)); |
442 network_state_handler_->RequestUpdateForNetwork(service_path); | 514 network_state_handler_->RequestUpdateForNetwork(service_path); |
443 } | 515 } |
444 | 516 |
445 void NetworkConfigurationHandler::SetPropertiesErrorCallback( | 517 void NetworkConfigurationHandler::SetPropertiesErrorCallback( |
446 const std::string& service_path, | 518 const std::string& service_path, |
447 const network_handler::ErrorCallback& error_callback, | 519 const network_handler::ErrorCallback& error_callback, |
448 const std::string& dbus_error_name, | 520 const std::string& dbus_error_name, |
449 const std::string& dbus_error_message) { | 521 const std::string& dbus_error_message) { |
450 network_handler::ShillErrorCallbackFunction( | 522 network_handler::ShillErrorCallbackFunction( |
451 "Config.SetProperties Failed", | 523 "Config.SetProperties Failed", service_path, error_callback, |
452 service_path, error_callback, | |
453 dbus_error_name, dbus_error_message); | 524 dbus_error_name, dbus_error_message); |
454 // Some properties may have changed so request an update regardless. | 525 // Some properties may have changed so request an update regardless. |
455 network_state_handler_->RequestUpdateForNetwork(service_path); | 526 network_state_handler_->RequestUpdateForNetwork(service_path); |
456 } | 527 } |
457 | 528 |
529 void NetworkConfigurationHandler::ClearPropertiesGetCallback( | |
530 const std::string& service_path, | |
531 const std::vector<std::string>& names, | |
532 const base::Closure& callback, | |
533 const network_handler::ErrorCallback& error_callback, | |
534 DBusMethodCallStatus call_status, | |
535 const base::DictionaryValue& properties) { | |
536 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | |
537 network_handler::RunErrorCallback(error_callback, service_path, | |
538 network_handler::kDBusFailedError, | |
539 network_handler::kDBusFailedErrorMessage); | |
540 return; | |
541 } | |
542 | |
543 // Clear only properties that are currently set. Also trigger an IP Configs | |
544 // refresh if necessary (see note in SendSetPropertiesToShill). | |
545 std::vector<std::string> properties_to_clear; | |
546 bool refresh_ip_configs = false; | |
547 for (const auto& key : names) { | |
548 if (properties.HasKey(key)) { | |
549 NET_LOG_DEBUG("ClearProperty", service_path + "." + key); | |
550 properties_to_clear.push_back(key); | |
551 if (PropertyRequiresIPConfigRefresh(key)) | |
552 refresh_ip_configs = true; | |
553 } else { | |
554 NET_LOG_DEBUG("ClearProperty:Unset (Ignoring)", service_path + "." + key); | |
555 } | |
556 } | |
557 | |
558 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( | |
559 dbus::ObjectPath(service_path), properties_to_clear, | |
560 base::Bind(&NetworkConfigurationHandler::ClearPropertiesSuccessCallback, | |
561 AsWeakPtr(), service_path, properties_to_clear, callback), | |
562 base::Bind(&NetworkConfigurationHandler::ClearPropertiesErrorCallback, | |
563 AsWeakPtr(), service_path, error_callback)); | |
564 | |
565 // If we cleared any properties that might affect IP config, request an IP | |
566 // config refresh after calling ClearProperties. | |
567 if (refresh_ip_configs) | |
568 RequestRefreshIPConfigs(service_path); | |
569 } | |
570 | |
458 void NetworkConfigurationHandler::ClearPropertiesSuccessCallback( | 571 void NetworkConfigurationHandler::ClearPropertiesSuccessCallback( |
459 const std::string& service_path, | 572 const std::string& service_path, |
460 const std::vector<std::string>& names, | 573 const std::vector<std::string>& names, |
461 const base::Closure& callback, | 574 const base::Closure& callback, |
462 const base::ListValue& result) { | 575 const base::ListValue& result) { |
463 const std::string kClearPropertiesFailedError("Error.ClearPropertiesFailed"); | 576 const std::string kClearPropertiesFailedError("Error.ClearPropertiesFailed"); |
464 DCHECK(names.size() == result.GetSize()) | 577 if (names.size() != result.GetSize()) |
465 << "Incorrect result size from ClearProperties."; | 578 NET_LOG_ERROR("ClearProperties Result size != input", service_path); |
466 | 579 |
467 for (size_t i = 0; i < result.GetSize(); ++i) { | 580 for (size_t i = 0; i < result.GetSize(); ++i) { |
468 bool success = false; | 581 bool success = false; |
469 result.GetBoolean(i, &success); | 582 result.GetBoolean(i, &success); |
470 if (!success) { | 583 if (!success) { |
471 // If a property was cleared that has never been set, the clear will fail. | 584 // If a property was cleared that has never been set, the clear will fail. |
472 // We do not track which properties have been set, so just log the error. | 585 // We do not track which properties have been set, so just log the error. |
473 NET_LOG_ERROR("ClearProperties Failed: " + names[i], service_path); | 586 NET_LOG_ERROR("ClearProperties Failed: " + names[i], service_path); |
474 } | 587 } |
475 } | 588 } |
476 | 589 |
477 if (!callback.is_null()) | 590 if (!callback.is_null()) |
478 callback.Run(); | 591 callback.Run(); |
479 network_state_handler_->RequestUpdateForNetwork(service_path); | 592 network_state_handler_->RequestUpdateForNetwork(service_path); |
480 } | 593 } |
481 | 594 |
482 void NetworkConfigurationHandler::ClearPropertiesErrorCallback( | 595 void NetworkConfigurationHandler::ClearPropertiesErrorCallback( |
483 const std::string& service_path, | 596 const std::string& service_path, |
484 const network_handler::ErrorCallback& error_callback, | 597 const network_handler::ErrorCallback& error_callback, |
485 const std::string& dbus_error_name, | 598 const std::string& dbus_error_name, |
486 const std::string& dbus_error_message) { | 599 const std::string& dbus_error_message) { |
487 network_handler::ShillErrorCallbackFunction( | 600 network_handler::ShillErrorCallbackFunction( |
488 "Config.ClearProperties Failed", | 601 "Config.ClearProperties Failed", service_path, error_callback, |
489 service_path, error_callback, | |
490 dbus_error_name, dbus_error_message); | 602 dbus_error_name, dbus_error_message); |
491 // Some properties may have changed so request an update regardless. | 603 // Some properties may have changed so request an update regardless. |
492 network_state_handler_->RequestUpdateForNetwork(service_path); | 604 network_state_handler_->RequestUpdateForNetwork(service_path); |
493 } | 605 } |
494 | 606 |
607 void NetworkConfigurationHandler::RequestRefreshIPConfigs( | |
608 const std::string& service_path) { | |
609 if (!network_device_handler_) | |
610 return; | |
611 const NetworkState* network_state = | |
612 network_state_handler_->GetNetworkState(service_path); | |
613 if (!network_state || network_state->device_path().empty()) | |
614 return; | |
615 network_device_handler_->RequestRefreshIPConfigs( | |
616 network_state->device_path(), base::Bind(&base::DoNothing), | |
617 network_handler::ErrorCallback()); | |
618 } | |
619 | |
495 // static | 620 // static |
496 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( | 621 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( |
497 NetworkStateHandler* network_state_handler) { | 622 NetworkStateHandler* network_state_handler, |
623 NetworkDeviceHandler* network_device_handler) { | |
498 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); | 624 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); |
499 handler->Init(network_state_handler); | 625 handler->Init(network_state_handler, network_device_handler); |
500 return handler; | 626 return handler; |
501 } | 627 } |
502 | 628 |
503 } // namespace chromeos | 629 } // namespace chromeos |
OLD | NEW |