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/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
16 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
19 #include "chromeos/dbus/shill_manager_client.h" | 20 #include "chromeos/dbus/shill_manager_client.h" |
20 #include "chromeos/dbus/shill_profile_client.h" | 21 #include "chromeos/dbus/shill_profile_client.h" |
21 #include "chromeos/dbus/shill_service_client.h" | 22 #include "chromeos/dbus/shill_service_client.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 std::string name = NetworkState::GetNameFromProperties(properties); | 60 std::string name = NetworkState::GetNameFromProperties(properties); |
60 if (!name.empty()) { | 61 if (!name.empty()) { |
61 properties_copy->SetStringWithoutPathExpansion( | 62 properties_copy->SetStringWithoutPathExpansion( |
62 flimflam::kNameProperty, name); | 63 flimflam::kNameProperty, name); |
63 } | 64 } |
64 network_handler::GetPropertiesCallback( | 65 network_handler::GetPropertiesCallback( |
65 callback, error_callback, service_path, call_status, | 66 callback, error_callback, service_path, call_status, |
66 *properties_copy.get()); | 67 *properties_copy.get()); |
67 } | 68 } |
68 | 69 |
70 void SetNetworkProfileErrorCallback( | |
71 const std::string& service_path, | |
72 const std::string& profile_path, | |
73 const network_handler::ErrorCallback& error_callback, | |
74 const std::string& dbus_error_name, | |
75 const std::string& dbus_error_message) { | |
76 network_handler::ShillErrorCallbackFunction( | |
77 "Config.SetNetworkProfile Failed: " + profile_path, | |
78 service_path, error_callback, | |
79 dbus_error_name, dbus_error_message); | |
80 } | |
81 | |
82 bool IsPassphrase(const std::string& key) { | |
83 return key == flimflam::kEapPrivateKeyPasswordProperty || | |
84 key == flimflam::kEapPasswordProperty || | |
85 key == flimflam::kL2tpIpsecPasswordProperty || | |
86 key == flimflam::kOpenVPNPasswordProperty || | |
87 key == flimflam::kPassphraseProperty || | |
88 key == flimflam::kOpenVPNOTPProperty || | |
89 key == flimflam::kEapPrivateKeyProperty || | |
90 key == flimflam::kEapPrivateKeyPasswordProperty || | |
91 key == flimflam::kEapPinProperty || | |
92 key == flimflam::kApnPasswordProperty; | |
93 } | |
94 | |
69 } // namespace | 95 } // namespace |
70 | 96 |
71 // Helper class to request from Shill the profile entries associated with a | 97 // Helper class to request from Shill the profile entries associated with a |
72 // Service and delete the service from each profile. Triggers either | 98 // Service and delete the service from each profile. Triggers either |
73 // |callback| on success or |error_callback| on failure, and calls | 99 // |callback| on success or |error_callback| on failure, and calls |
74 // |handler|->ProfileEntryDeleterCompleted() on completion to delete itself. | 100 // |handler|->ProfileEntryDeleterCompleted() on completion to delete itself. |
75 class NetworkConfigurationHandler::ProfileEntryDeleter | 101 class NetworkConfigurationHandler::ProfileEntryDeleter |
76 : public base::SupportsWeakPtr<ProfileEntryDeleter> { | 102 : public base::SupportsWeakPtr<ProfileEntryDeleter> { |
77 public: | 103 public: |
78 ProfileEntryDeleter(NetworkConfigurationHandler* handler, | 104 ProfileEntryDeleter(NetworkConfigurationHandler* handler, |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 dbus::ObjectPath(service_path), | 207 dbus::ObjectPath(service_path), |
182 base::Bind(&GetPropertiesCallback, | 208 base::Bind(&GetPropertiesCallback, |
183 callback, error_callback, service_path)); | 209 callback, error_callback, service_path)); |
184 } | 210 } |
185 | 211 |
186 void NetworkConfigurationHandler::SetProperties( | 212 void NetworkConfigurationHandler::SetProperties( |
187 const std::string& service_path, | 213 const std::string& service_path, |
188 const base::DictionaryValue& properties, | 214 const base::DictionaryValue& properties, |
189 const base::Closure& callback, | 215 const base::Closure& callback, |
190 const network_handler::ErrorCallback& error_callback) { | 216 const network_handler::ErrorCallback& error_callback) { |
217 if (properties.empty()) { | |
218 if (!callback.is_null()) | |
219 callback.Run(); | |
220 return; | |
221 } | |
191 NET_LOG_USER("SetProperties", service_path); | 222 NET_LOG_USER("SetProperties", service_path); |
223 for (base::DictionaryValue::Iterator iter(properties); | |
pneubeck (no reviews)
2013/08/08 11:10:00
uff.. isn't this a bit too much logging?
Shill ca
stevenjb
2013/08/08 19:00:56
Nobody runs Debug builds in practice.
For M30 the
| |
224 !iter.IsAtEnd(); iter.Advance()) { | |
225 std::string v = "******"; | |
226 if (!IsPassphrase(iter.key())) | |
pneubeck (no reviews)
2013/08/08 11:10:00
I don't like this blacklisting at all.
Yet another
stevenjb
2013/08/08 19:00:56
I'm not sure I agree. As you mentioned, we already
| |
227 base::JSONWriter::Write(&iter.value(), &v); | |
228 NET_LOG_DEBUG("SetProperty", service_path + "." + iter.key() + "=" + v); | |
pneubeck (no reviews)
2013/08/08 11:10:00
you might even consider making NET_LOG_DEBUG (not
stevenjb
2013/08/08 19:00:56
Again, I don't think that is useful. The point of
| |
229 } | |
192 DBusThreadManager::Get()->GetShillServiceClient()->SetProperties( | 230 DBusThreadManager::Get()->GetShillServiceClient()->SetProperties( |
193 dbus::ObjectPath(service_path), | 231 dbus::ObjectPath(service_path), |
194 properties, | 232 properties, |
195 base::Bind(&NetworkConfigurationHandler::SetPropertiesSuccessCallback, | 233 base::Bind(&NetworkConfigurationHandler::SetPropertiesSuccessCallback, |
196 AsWeakPtr(), service_path, callback), | 234 AsWeakPtr(), service_path, callback), |
197 base::Bind(&NetworkConfigurationHandler::SetPropertiesErrorCallback, | 235 base::Bind(&NetworkConfigurationHandler::SetPropertiesErrorCallback, |
198 AsWeakPtr(), service_path, error_callback)); | 236 AsWeakPtr(), service_path, error_callback)); |
199 } | 237 } |
200 | 238 |
201 void NetworkConfigurationHandler::ClearProperties( | 239 void NetworkConfigurationHandler::ClearProperties( |
202 const std::string& service_path, | 240 const std::string& service_path, |
203 const std::vector<std::string>& names, | 241 const std::vector<std::string>& names, |
204 const base::Closure& callback, | 242 const base::Closure& callback, |
205 const network_handler::ErrorCallback& error_callback) { | 243 const network_handler::ErrorCallback& error_callback) { |
244 if (names.empty()) { | |
245 if (!callback.is_null()) | |
246 callback.Run(); | |
247 return; | |
248 } | |
206 NET_LOG_USER("ClearProperties", service_path); | 249 NET_LOG_USER("ClearProperties", service_path); |
250 for (std::vector<std::string>::const_iterator iter = names.begin(); | |
251 iter != names.end(); ++iter) { | |
252 NET_LOG_DEBUG("ClearProperty", service_path + "." + *iter); | |
253 } | |
207 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( | 254 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( |
208 dbus::ObjectPath(service_path), | 255 dbus::ObjectPath(service_path), |
209 names, | 256 names, |
210 base::Bind(&NetworkConfigurationHandler::ClearPropertiesSuccessCallback, | 257 base::Bind(&NetworkConfigurationHandler::ClearPropertiesSuccessCallback, |
211 AsWeakPtr(), service_path, names, callback, error_callback), | 258 AsWeakPtr(), service_path, names, callback, error_callback), |
212 base::Bind(&NetworkConfigurationHandler::ClearPropertiesErrorCallback, | 259 base::Bind(&NetworkConfigurationHandler::ClearPropertiesErrorCallback, |
213 AsWeakPtr(), service_path, error_callback)); | 260 AsWeakPtr(), service_path, error_callback)); |
214 } | 261 } |
215 | 262 |
216 void NetworkConfigurationHandler::CreateConfiguration( | 263 void NetworkConfigurationHandler::CreateConfiguration( |
217 const base::DictionaryValue& properties, | 264 const base::DictionaryValue& properties, |
218 const network_handler::StringResultCallback& callback, | 265 const network_handler::StringResultCallback& callback, |
219 const network_handler::ErrorCallback& error_callback) { | 266 const network_handler::ErrorCallback& error_callback) { |
220 ShillManagerClient* manager = | 267 ShillManagerClient* manager = |
221 DBusThreadManager::Get()->GetShillManagerClient(); | 268 DBusThreadManager::Get()->GetShillManagerClient(); |
222 | |
223 std::string type; | 269 std::string type; |
224 properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, &type); | 270 properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, &type); |
271 | |
272 NET_LOG_USER("CreateConfiguration", type); | |
273 for (base::DictionaryValue::Iterator iter(properties); | |
pneubeck (no reviews)
2013/08/08 11:10:00
if _really_ necessary (as said above, I think it's
stevenjb
2013/08/08 19:00:56
Done.
| |
274 !iter.IsAtEnd(); iter.Advance()) { | |
275 std::string v = "******"; | |
276 if (!IsPassphrase(iter.key())) | |
277 base::JSONWriter::Write(&iter.value(), &v); | |
278 NET_LOG_DEBUG("Configure", type + "." + iter.key() + "=" + v); | |
279 } | |
280 | |
225 // Shill supports ConfigureServiceForProfile only for network type WiFi. In | 281 // Shill supports ConfigureServiceForProfile only for network type WiFi. In |
226 // all other cases, we have to rely on GetService for now. This is | 282 // all other cases, we have to rely on GetService for now. This is |
227 // unproblematic for VPN (user profile only), but will lead to inconsistencies | 283 // unproblematic for VPN (user profile only), but will lead to inconsistencies |
228 // with WiMax, for example. | 284 // with WiMax, for example. |
229 if (type == flimflam::kTypeWifi) { | 285 if (type == flimflam::kTypeWifi) { |
230 std::string profile; | 286 std::string profile; |
231 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, | 287 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, |
232 &profile); | 288 &profile); |
233 manager->ConfigureServiceForProfile( | 289 manager->ConfigureServiceForProfile( |
234 dbus::ObjectPath(profile), | 290 dbus::ObjectPath(profile), |
(...skipping 23 matching lines...) Expand all Loading... | |
258 "RemoveConfiguration In-Progress", service_path, error_callback); | 314 "RemoveConfiguration In-Progress", service_path, error_callback); |
259 return; | 315 return; |
260 } | 316 } |
261 NET_LOG_USER("Remove Configuration", service_path); | 317 NET_LOG_USER("Remove Configuration", service_path); |
262 ProfileEntryDeleter* deleter = | 318 ProfileEntryDeleter* deleter = |
263 new ProfileEntryDeleter(this, service_path, callback, error_callback); | 319 new ProfileEntryDeleter(this, service_path, callback, error_callback); |
264 profile_entry_deleters_[service_path] = deleter; | 320 profile_entry_deleters_[service_path] = deleter; |
265 deleter->Run(); | 321 deleter->Run(); |
266 } | 322 } |
267 | 323 |
324 void NetworkConfigurationHandler::SetNetworkProfile( | |
325 const std::string& service_path, | |
326 const std::string& profile_path, | |
327 const base::Closure& callback, | |
328 const network_handler::ErrorCallback& error_callback) { | |
329 NET_LOG_USER("SetNetworkProfile", service_path + ": " + profile_path); | |
330 base::StringValue profile_path_value(profile_path); | |
331 DBusThreadManager::Get()->GetShillServiceClient()->SetProperty( | |
332 dbus::ObjectPath(service_path), | |
333 flimflam::kProfileProperty, | |
334 profile_path_value, | |
335 callback, | |
336 base::Bind(&SetNetworkProfileErrorCallback, | |
337 service_path, profile_path, error_callback)); | |
338 } | |
339 | |
268 // NetworkConfigurationHandler Private methods | 340 // NetworkConfigurationHandler Private methods |
269 | 341 |
270 NetworkConfigurationHandler::NetworkConfigurationHandler() | 342 NetworkConfigurationHandler::NetworkConfigurationHandler() |
271 : network_state_handler_(NULL) { | 343 : network_state_handler_(NULL) { |
272 } | 344 } |
273 | 345 |
274 NetworkConfigurationHandler::~NetworkConfigurationHandler() { | 346 NetworkConfigurationHandler::~NetworkConfigurationHandler() { |
275 STLDeleteContainerPairSecondPointers( | 347 STLDeleteContainerPairSecondPointers( |
276 profile_entry_deleters_.begin(), profile_entry_deleters_.end()); | 348 profile_entry_deleters_.begin(), profile_entry_deleters_.end()); |
277 } | 349 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 | 448 |
377 // static | 449 // static |
378 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( | 450 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( |
379 NetworkStateHandler* network_state_handler) { | 451 NetworkStateHandler* network_state_handler) { |
380 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); | 452 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); |
381 handler->Init(network_state_handler); | 453 handler->Init(network_state_handler); |
382 return handler; | 454 return handler; |
383 } | 455 } |
384 | 456 |
385 } // namespace chromeos | 457 } // namespace chromeos |
OLD | NEW |