Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chromeos/network/network_configuration_handler.cc

Issue 917053002: Add Source property to networkingPrivate.getState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase with separated test expectations Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/network/network_configuration_handler.h ('k') | chromeos/network/network_state.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 void InvokeErrorCallback(const std::string& service_path, 43 void InvokeErrorCallback(const std::string& service_path,
44 const network_handler::ErrorCallback& error_callback, 44 const network_handler::ErrorCallback& error_callback,
45 const std::string& error_name) { 45 const std::string& error_name) {
46 std::string error_msg = "Config Error: " + error_name; 46 std::string error_msg = "Config Error: " + error_name;
47 NET_LOG_ERROR(error_msg, service_path); 47 NET_LOG_ERROR(error_msg, service_path);
48 network_handler::RunErrorCallback( 48 network_handler::RunErrorCallback(
49 error_callback, service_path, error_name, error_msg); 49 error_callback, service_path, error_name, error_msg);
50 } 50 }
51 51
52 void GetPropertiesCallback(
53 const network_handler::DictionaryResultCallback& callback,
54 const network_handler::ErrorCallback& error_callback,
55 const std::string& service_path,
56 DBusMethodCallStatus call_status,
57 const base::DictionaryValue& properties) {
58 if (call_status != DBUS_METHOD_CALL_SUCCESS) {
59 // Because network services are added and removed frequently, we will see
60 // failures regularly, so don't log these.
61 network_handler::RunErrorCallback(error_callback,
62 service_path,
63 network_handler::kDBusFailedError,
64 network_handler::kDBusFailedErrorMessage);
65 return;
66 }
67 if (callback.is_null())
68 return;
69
70 // Get the correct name from WifiHex if necessary.
71 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy());
72 std::string name =
73 shill_property_util::GetNameFromProperties(service_path, properties);
74 if (!name.empty())
75 properties_copy->SetStringWithoutPathExpansion(shill::kNameProperty, name);
76 callback.Run(service_path, *properties_copy.get());
77 }
78
79 void SetNetworkProfileErrorCallback( 52 void SetNetworkProfileErrorCallback(
80 const std::string& service_path, 53 const std::string& service_path,
81 const std::string& profile_path, 54 const std::string& profile_path,
82 const network_handler::ErrorCallback& error_callback, 55 const network_handler::ErrorCallback& error_callback,
83 const std::string& dbus_error_name, 56 const std::string& dbus_error_name,
84 const std::string& dbus_error_message) { 57 const std::string& dbus_error_message) {
85 network_handler::ShillErrorCallbackFunction( 58 network_handler::ShillErrorCallbackFunction(
86 "Config.SetNetworkProfile Failed: " + profile_path, 59 "Config.SetNetworkProfile Failed: " + profile_path,
87 service_path, error_callback, 60 service_path, error_callback,
88 dbus_error_name, dbus_error_message); 61 dbus_error_name, dbus_error_message);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 195 }
223 196
224 void NetworkConfigurationHandler::RemoveObserver( 197 void NetworkConfigurationHandler::RemoveObserver(
225 NetworkConfigurationObserver* observer) { 198 NetworkConfigurationObserver* observer) {
226 observers_.RemoveObserver(observer); 199 observers_.RemoveObserver(observer);
227 } 200 }
228 201
229 void NetworkConfigurationHandler::GetProperties( 202 void NetworkConfigurationHandler::GetProperties(
230 const std::string& service_path, 203 const std::string& service_path,
231 const network_handler::DictionaryResultCallback& callback, 204 const network_handler::DictionaryResultCallback& callback,
232 const network_handler::ErrorCallback& error_callback) const { 205 const network_handler::ErrorCallback& error_callback) {
233 NET_LOG_USER("GetProperties", service_path); 206 NET_LOG_USER("GetProperties", service_path);
234 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( 207 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
235 dbus::ObjectPath(service_path), 208 dbus::ObjectPath(service_path),
236 base::Bind(&GetPropertiesCallback, 209 base::Bind(&NetworkConfigurationHandler::GetPropertiesCallback,
237 callback, error_callback, service_path)); 210 AsWeakPtr(), callback, error_callback, service_path));
238 } 211 }
239 212
240 void NetworkConfigurationHandler::SetProperties( 213 void NetworkConfigurationHandler::SetProperties(
241 const std::string& service_path, 214 const std::string& service_path,
242 const base::DictionaryValue& properties, 215 const base::DictionaryValue& properties,
243 NetworkConfigurationObserver::Source source, 216 NetworkConfigurationObserver::Source source,
244 const base::Closure& callback, 217 const base::Closure& callback,
245 const network_handler::ErrorCallback& error_callback) { 218 const network_handler::ErrorCallback& error_callback) {
246 if (properties.empty()) { 219 if (properties.empty()) {
247 if (!callback.is_null()) 220 if (!callback.is_null())
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 const std::string& profile_path, 398 const std::string& profile_path,
426 NetworkConfigurationObserver::Source source, 399 NetworkConfigurationObserver::Source source,
427 const base::Closure& callback) { 400 const base::Closure& callback) {
428 if (!callback.is_null()) 401 if (!callback.is_null())
429 callback.Run(); 402 callback.Run();
430 FOR_EACH_OBSERVER( 403 FOR_EACH_OBSERVER(
431 NetworkConfigurationObserver, observers_, 404 NetworkConfigurationObserver, observers_,
432 OnConfigurationProfileChanged(service_path, profile_path, source)); 405 OnConfigurationProfileChanged(service_path, profile_path, source));
433 } 406 }
434 407
408 void NetworkConfigurationHandler::GetPropertiesCallback(
409 const network_handler::DictionaryResultCallback& callback,
410 const network_handler::ErrorCallback& error_callback,
411 const std::string& service_path,
412 DBusMethodCallStatus call_status,
413 const base::DictionaryValue& properties) {
414 if (call_status != DBUS_METHOD_CALL_SUCCESS) {
415 // Because network services are added and removed frequently, we will see
416 // failures regularly, so don't log these.
417 network_handler::RunErrorCallback(error_callback, service_path,
418 network_handler::kDBusFailedError,
419 network_handler::kDBusFailedErrorMessage);
420 return;
421 }
422 if (callback.is_null())
423 return;
424
425 // Get the correct name from WifiHex if necessary.
426 scoped_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy());
427 std::string name =
428 shill_property_util::GetNameFromProperties(service_path, properties);
429 if (!name.empty())
430 properties_copy->SetStringWithoutPathExpansion(shill::kNameProperty, name);
431
432 // Get the GUID property from NetworkState if it is not set in Shill.
433 std::string guid;
434 properties.GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid);
435 if (guid.empty()) {
436 const NetworkState* network_state =
437 network_state_handler_->GetNetworkState(service_path);
438 if (network_state) {
439 properties_copy->SetStringWithoutPathExpansion(
440 ::onc::network_config::kGUID, network_state->guid());
441 }
442 }
443
444 callback.Run(service_path, *properties_copy.get());
445 }
446
435 void NetworkConfigurationHandler::SetPropertiesSuccessCallback( 447 void NetworkConfigurationHandler::SetPropertiesSuccessCallback(
436 const std::string& service_path, 448 const std::string& service_path,
437 scoped_ptr<base::DictionaryValue> set_properties, 449 scoped_ptr<base::DictionaryValue> set_properties,
438 NetworkConfigurationObserver::Source source, 450 NetworkConfigurationObserver::Source source,
439 const base::Closure& callback) { 451 const base::Closure& callback) {
440 if (!callback.is_null()) 452 if (!callback.is_null())
441 callback.Run(); 453 callback.Run();
442 const NetworkState* network_state = 454 const NetworkState* network_state =
443 network_state_handler_->GetNetworkState(service_path); 455 network_state_handler_->GetNetworkState(service_path);
444 if (!network_state) 456 if (!network_state)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // static 528 // static
517 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest( 529 NetworkConfigurationHandler* NetworkConfigurationHandler::InitializeForTest(
518 NetworkStateHandler* network_state_handler, 530 NetworkStateHandler* network_state_handler,
519 NetworkDeviceHandler* network_device_handler) { 531 NetworkDeviceHandler* network_device_handler) {
520 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler(); 532 NetworkConfigurationHandler* handler = new NetworkConfigurationHandler();
521 handler->Init(network_state_handler, network_device_handler); 533 handler->Init(network_state_handler, network_device_handler);
522 return handler; 534 return handler;
523 } 535 }
524 536
525 } // namespace chromeos 537 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/network_configuration_handler.h ('k') | chromeos/network/network_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698