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

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

Issue 267433005: Provide IPConfigs in networkingPrivate.GetProperties (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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/network/managed_network_configuration_handler_impl.h" 5 #include "chromeos/network/managed_network_configuration_handler_impl.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/location.h" 12 #include "base/location.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/values.h" 17 #include "base/values.h"
18 #include "chromeos/dbus/shill_manager_client.h" 18 #include "chromeos/dbus/shill_manager_client.h"
19 #include "chromeos/dbus/shill_profile_client.h" 19 #include "chromeos/dbus/shill_profile_client.h"
20 #include "chromeos/dbus/shill_service_client.h" 20 #include "chromeos/dbus/shill_service_client.h"
21 #include "chromeos/network/device_state.h"
21 #include "chromeos/network/network_configuration_handler.h" 22 #include "chromeos/network/network_configuration_handler.h"
22 #include "chromeos/network/network_event_log.h" 23 #include "chromeos/network/network_event_log.h"
23 #include "chromeos/network/network_policy_observer.h" 24 #include "chromeos/network/network_policy_observer.h"
24 #include "chromeos/network/network_profile.h" 25 #include "chromeos/network/network_profile.h"
25 #include "chromeos/network/network_profile_handler.h" 26 #include "chromeos/network/network_profile_handler.h"
26 #include "chromeos/network/network_state.h" 27 #include "chromeos/network/network_state.h"
27 #include "chromeos/network/network_state_handler.h" 28 #include "chromeos/network/network_state_handler.h"
28 #include "chromeos/network/network_ui_data.h" 29 #include "chromeos/network/network_ui_data.h"
29 #include "chromeos/network/onc/onc_merger.h" 30 #include "chromeos/network/onc/onc_merger.h"
30 #include "chromeos/network/onc/onc_signature.h" 31 #include "chromeos/network/onc/onc_signature.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 77 }
77 78
78 const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies, 79 const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies,
79 const std::string& guid) { 80 const std::string& guid) {
80 GuidToPolicyMap::const_iterator it = policies.find(guid); 81 GuidToPolicyMap::const_iterator it = policies.find(guid);
81 if (it == policies.end()) 82 if (it == policies.end())
82 return NULL; 83 return NULL;
83 return it->second; 84 return it->second;
84 } 85 }
85 86
86 void TranslatePropertiesToOncAndRunCallback(
87 const network_handler::DictionaryResultCallback& callback,
88 const std::string& service_path,
89 const base::DictionaryValue& shill_properties) {
90 scoped_ptr<base::DictionaryValue> onc_network(
91 onc::TranslateShillServiceToONCPart(
92 shill_properties,
93 &onc::kNetworkWithStateSignature));
94 callback.Run(service_path, *onc_network);
95 }
96
97 } // namespace 87 } // namespace
98 88
99 struct ManagedNetworkConfigurationHandlerImpl::Policies { 89 struct ManagedNetworkConfigurationHandlerImpl::Policies {
100 ~Policies(); 90 ~Policies();
101 91
102 GuidToPolicyMap per_network_config; 92 GuidToPolicyMap per_network_config;
103 base::DictionaryValue global_network_config; 93 base::DictionaryValue global_network_config;
104 }; 94 };
105 95
106 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() { 96 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 user_settings = ui_data->user_settings(); 152 user_settings = ui_data->user_settings();
163 else 153 else
164 NOTREACHED(); 154 NOTREACHED();
165 } else if (profile) { 155 } else if (profile) {
166 NET_LOG_ERROR("Service contains empty or invalid UIData", service_path); 156 NET_LOG_ERROR("Service contains empty or invalid UIData", service_path);
167 // TODO(pneubeck): add a conversion of user configured entries of old 157 // TODO(pneubeck): add a conversion of user configured entries of old
168 // ChromeOS versions. We will have to use a heuristic to determine which 158 // ChromeOS versions. We will have to use a heuristic to determine which
169 // properties _might_ be user configured. 159 // properties _might_ be user configured.
170 } 160 }
171 161
162 scoped_ptr<base::DictionaryValue> properties_copy(
163 shill_properties.DeepCopy());
164 // Add the IPConfigs to the dictionary before the ONC translation.
165 GetIPConfigs(service_path, properties_copy.get());
166
172 scoped_ptr<base::DictionaryValue> active_settings( 167 scoped_ptr<base::DictionaryValue> active_settings(
173 onc::TranslateShillServiceToONCPart( 168 onc::TranslateShillServiceToONCPart(
174 shill_properties, 169 *properties_copy,
175 &onc::kNetworkWithStateSignature)); 170 &onc::kNetworkWithStateSignature));
176 171
177 std::string guid; 172 std::string guid;
178 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID, 173 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID,
179 &guid); 174 &guid);
180 175
181 const base::DictionaryValue* user_policy = NULL; 176 const base::DictionaryValue* user_policy = NULL;
182 const base::DictionaryValue* device_policy = NULL; 177 const base::DictionaryValue* device_policy = NULL;
183 if (!guid.empty() && profile) { 178 if (!guid.empty() && profile) {
184 const Policies* policies = GetPoliciesForProfile(*profile); 179 const Policies* policies = GetPoliciesForProfile(*profile);
(...skipping 20 matching lines...) Expand all
205 device_policy, 200 device_policy,
206 user_settings, 201 user_settings,
207 shared_settings, 202 shared_settings,
208 active_settings.get()); 203 active_settings.get());
209 callback.Run(service_path, *augmented_properties); 204 callback.Run(service_path, *augmented_properties);
210 } 205 }
211 206
212 void ManagedNetworkConfigurationHandlerImpl::GetProperties( 207 void ManagedNetworkConfigurationHandlerImpl::GetProperties(
213 const std::string& service_path, 208 const std::string& service_path,
214 const network_handler::DictionaryResultCallback& callback, 209 const network_handler::DictionaryResultCallback& callback,
215 const network_handler::ErrorCallback& error_callback) const { 210 const network_handler::ErrorCallback& error_callback) {
216 network_configuration_handler_->GetProperties( 211 network_configuration_handler_->GetProperties(
217 service_path, 212 service_path,
218 base::Bind(&TranslatePropertiesToOncAndRunCallback, callback), 213 base::Bind(&ManagedNetworkConfigurationHandlerImpl::GetPropertiesCallback,
214 weak_ptr_factory_.GetWeakPtr(),
215 callback),
219 error_callback); 216 error_callback);
220 } 217 }
221 218
219 void ManagedNetworkConfigurationHandlerImpl::GetPropertiesCallback(
220 const network_handler::DictionaryResultCallback& callback,
221 const std::string& service_path,
222 const base::DictionaryValue& shill_properties) {
223 scoped_ptr<base::DictionaryValue> properties_copy(
224 shill_properties.DeepCopy());
225 // Add the IPConfigs to the dictionary before the ONC translation.
226 GetIPConfigs(service_path, properties_copy.get());
227
228 scoped_ptr<base::DictionaryValue> onc_network(
229 onc::TranslateShillServiceToONCPart(
230 *properties_copy,
231 &onc::kNetworkWithStateSignature));
232 callback.Run(service_path, *onc_network);
233 }
234
222 void ManagedNetworkConfigurationHandlerImpl::SetProperties( 235 void ManagedNetworkConfigurationHandlerImpl::SetProperties(
223 const std::string& service_path, 236 const std::string& service_path,
224 const base::DictionaryValue& user_settings, 237 const base::DictionaryValue& user_settings,
225 const base::Closure& callback, 238 const base::Closure& callback,
226 const network_handler::ErrorCallback& error_callback) const { 239 const network_handler::ErrorCallback& error_callback) const {
227 const NetworkState* state = 240 const NetworkState* state =
228 network_state_handler_->GetNetworkState(service_path); 241 network_state_handler_->GetNetworkState(service_path);
229 242
230 if (!state) { 243 if (!state) {
231 InvokeErrorCallback(service_path, error_callback, kUnknownServicePath); 244 InvokeErrorCallback(service_path, error_callback, kUnknownServicePath);
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 } 602 }
590 603
591 void ManagedNetworkConfigurationHandlerImpl::OnPolicyAppliedToNetwork( 604 void ManagedNetworkConfigurationHandlerImpl::OnPolicyAppliedToNetwork(
592 const std::string& service_path) { 605 const std::string& service_path) {
593 if (service_path.empty()) 606 if (service_path.empty())
594 return; 607 return;
595 FOR_EACH_OBSERVER( 608 FOR_EACH_OBSERVER(
596 NetworkPolicyObserver, observers_, PolicyApplied(service_path)); 609 NetworkPolicyObserver, observers_, PolicyApplied(service_path));
597 } 610 }
598 611
612 void ManagedNetworkConfigurationHandlerImpl::GetIPConfigs(
613 const std::string& service_path,
614 base::DictionaryValue* properties) {
615 std::string connection_state;
616 properties->GetStringWithoutPathExpansion(
617 shill::kStateProperty, &connection_state);
618 if (!NetworkState::StateIsConnected(connection_state))
619 return;
620
621 // Get the IPConfig properties from the device and store them in "IPConfigs"
622 // (plural) in the properties dictionary. (Note: Shill only provides a single
623 // "IPConfig" property for a network service, but a consumer of this API may
624 // want information about all ipv4 and ipv6 IPConfig properties.
625 std::string device;
626 properties->GetStringWithoutPathExpansion(shill::kDeviceProperty, &device);
627 const DeviceState* device_state =
628 network_state_handler_->GetDeviceState(device);
629 if (!device_state) {
630 NET_LOG_ERROR("GetIPConfigs: no device: " + device, service_path);
631 return;
632 }
633 // Convert IPConfig dictionary to a ListValue.
634 base::ListValue* ip_configs = new base::ListValue;
635 for (base::DictionaryValue::Iterator iter(device_state->ip_configs());
636 !iter.IsAtEnd(); iter.Advance()) {
637 ip_configs->Append(iter.value().DeepCopy());
638 }
639 properties->SetWithoutPathExpansion(shill::kIPConfigsProperty, ip_configs);
640 }
641
599 } // namespace chromeos 642 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698