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

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

Issue 978923003: Improve Cellular support in networkingPrivate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_430115_internet_options_use_guid
Patch Set: Rebase Created 5 years, 9 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
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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 void LogErrorWithDict(const tracked_objects::Location& from_where, 71 void LogErrorWithDict(const tracked_objects::Location& from_where,
72 const std::string& error_name, 72 const std::string& error_name,
73 scoped_ptr<base::DictionaryValue> error_data) { 73 scoped_ptr<base::DictionaryValue> error_data) {
74 device_event_log::AddEntry(from_where.file_name(), from_where.line_number(), 74 device_event_log::AddEntry(from_where.file_name(), from_where.line_number(),
75 device_event_log::LOG_TYPE_NETWORK, 75 device_event_log::LOG_TYPE_NETWORK,
76 device_event_log::LOG_LEVEL_ERROR, error_name); 76 device_event_log::LOG_LEVEL_ERROR, error_name);
77 } 77 }
78 78
79 const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies, 79 const base::DictionaryValue* GetPolicyByGUID(const GuidToPolicyMap& policies,
80 const std::string& guid) { 80 const std::string& guid) {
81 GuidToPolicyMap::const_iterator it = policies.find(guid); 81 GuidToPolicyMap::const_iterator it = policies.find(guid);
82 if (it == policies.end()) 82 if (it == policies.end())
83 return NULL; 83 return NULL;
84 return it->second; 84 return it->second;
85 } 85 }
86 86
87 scoped_ptr<base::DictionaryValue> ExtractShillDeviceSettings(
88 base::DictionaryValue* user_settings) {
89 scoped_ptr<base::DictionaryValue> shill_device_settings(
90 new base::DictionaryValue);
91 // Only extract specific properties that can be set in Shill.
92 base::DictionaryValue* cellular;
93 if (user_settings->GetDictionaryWithoutPathExpansion(
94 ::onc::network_config::kCellular, &cellular)) {
95 scoped_ptr<base::Value> value;
96 if (cellular->RemoveWithoutPathExpansion(::onc::cellular::kCarrier,
97 &value)) {
98 shill_device_settings->SetWithoutPathExpansion(shill::kCarrierProperty,
99 value.Pass());
100 }
101 if (cellular->RemoveWithoutPathExpansion(::onc::cellular::kAllowRoaming,
102 &value)) {
103 shill_device_settings->SetWithoutPathExpansion(
104 shill::kCellularAllowRoamingProperty, value.Pass());
105 }
106 }
107 return shill_device_settings.Pass();
108 }
109
87 } // namespace 110 } // namespace
88 111
89 struct ManagedNetworkConfigurationHandlerImpl::Policies { 112 struct ManagedNetworkConfigurationHandlerImpl::Policies {
90 ~Policies(); 113 ~Policies();
91 114
92 GuidToPolicyMap per_network_config; 115 GuidToPolicyMap per_network_config;
93 base::DictionaryValue global_network_config; 116 base::DictionaryValue global_network_config;
94 }; 117 };
95 118
96 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() { 119 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 const base::DictionaryValue* network_policy = NULL; 194 const base::DictionaryValue* network_policy = NULL;
172 const base::DictionaryValue* global_policy = NULL; 195 const base::DictionaryValue* global_policy = NULL;
173 if (profile) { 196 if (profile) {
174 const Policies* policies = GetPoliciesForProfile(*profile); 197 const Policies* policies = GetPoliciesForProfile(*profile);
175 if (!policies) { 198 if (!policies) {
176 InvokeErrorCallback( 199 InvokeErrorCallback(
177 service_path, error_callback, kPoliciesNotInitialized); 200 service_path, error_callback, kPoliciesNotInitialized);
178 return; 201 return;
179 } 202 }
180 if (!guid.empty()) 203 if (!guid.empty())
181 network_policy = GetByGUID(policies->per_network_config, guid); 204 network_policy = GetPolicyByGUID(policies->per_network_config, guid);
182 global_policy = &policies->global_network_config; 205 global_policy = &policies->global_network_config;
183 } 206 }
184 207
185 scoped_ptr<base::DictionaryValue> augmented_properties( 208 scoped_ptr<base::DictionaryValue> augmented_properties(
186 policy_util::CreateManagedONC(global_policy, 209 policy_util::CreateManagedONC(global_policy,
187 network_policy, 210 network_policy,
188 user_settings, 211 user_settings,
189 active_settings.get(), 212 active_settings.get(),
190 profile)); 213 profile));
191 callback.Run(service_path, *augmented_properties); 214 callback.Run(service_path, *augmented_properties);
(...skipping 27 matching lines...) Expand all
219 &onc::kNetworkWithStateSignature)); 242 &onc::kNetworkWithStateSignature));
220 callback.Run(service_path, *onc_network); 243 callback.Run(service_path, *onc_network);
221 } 244 }
222 245
223 // SetProperties 246 // SetProperties
224 247
225 void ManagedNetworkConfigurationHandlerImpl::SetProperties( 248 void ManagedNetworkConfigurationHandlerImpl::SetProperties(
226 const std::string& service_path, 249 const std::string& service_path,
227 const base::DictionaryValue& user_settings, 250 const base::DictionaryValue& user_settings,
228 const base::Closure& callback, 251 const base::Closure& callback,
229 const network_handler::ErrorCallback& error_callback) const { 252 const network_handler::ErrorCallback& error_callback) {
230 const NetworkState* state = 253 const NetworkState* state =
231 network_state_handler_->GetNetworkStateFromServicePath( 254 network_state_handler_->GetNetworkStateFromServicePath(
232 service_path, true /* configured_only */); 255 service_path, true /* configured_only */);
233 if (!state) { 256 if (!state) {
234 InvokeErrorCallback(service_path, error_callback, kUnknownNetwork); 257 InvokeErrorCallback(service_path, error_callback, kUnknownNetwork);
235 return; 258 return;
236 } 259 }
237 260
238 std::string guid = state->guid(); 261 std::string guid = state->guid();
239 DCHECK(!guid.empty()); 262 DCHECK(!guid.empty());
(...skipping 20 matching lines...) Expand all
260 283
261 // We need to ensure that required configuration properties (e.g. Type) are 284 // We need to ensure that required configuration properties (e.g. Type) are
262 // included for ONC validation and translation to Shill properties. 285 // included for ONC validation and translation to Shill properties.
263 scoped_ptr<base::DictionaryValue> user_settings_copy( 286 scoped_ptr<base::DictionaryValue> user_settings_copy(
264 user_settings.DeepCopy()); 287 user_settings.DeepCopy());
265 user_settings_copy->SetStringWithoutPathExpansion( 288 user_settings_copy->SetStringWithoutPathExpansion(
266 ::onc::network_config::kType, 289 ::onc::network_config::kType,
267 network_util::TranslateShillTypeToONC(state->type())); 290 network_util::TranslateShillTypeToONC(state->type()));
268 user_settings_copy->MergeDictionary(&user_settings); 291 user_settings_copy->MergeDictionary(&user_settings);
269 292
293 // Extract any Device properties to apply separately, before validation.
pneubeck (no reviews) 2015/03/24 16:19:52 any reason to do this before validation? So far, a
294 scoped_ptr<base::DictionaryValue> shill_device_dictionary(
295 ExtractShillDeviceSettings(user_settings_copy.get()));
296
270 // Validate the ONC dictionary. We are liberal and ignore unknown field 297 // Validate the ONC dictionary. We are liberal and ignore unknown field
271 // names. User settings are only partial ONC, thus we ignore missing fields. 298 // names. User settings are only partial ONC, thus we ignore missing fields.
272 onc::Validator validator(false, // Ignore unknown fields. 299 onc::Validator validator(false, // Ignore unknown fields.
273 false, // Ignore invalid recommended field names. 300 false, // Ignore invalid recommended field names.
274 false, // Ignore missing fields. 301 false, // Ignore missing fields.
275 false); // This ONC does not come from policy. 302 false); // This ONC does not come from policy.
276 303
277 onc::Validator::Result validation_result; 304 onc::Validator::Result validation_result;
278 scoped_ptr<base::DictionaryValue> validated_user_settings = 305 scoped_ptr<base::DictionaryValue> validated_user_settings =
279 validator.ValidateAndRepairObject( 306 validator.ValidateAndRepairObject(
280 &onc::kNetworkConfigurationSignature, 307 &onc::kNetworkConfigurationSignature,
281 *user_settings_copy, 308 *user_settings_copy,
282 &validation_result); 309 &validation_result);
283 if (validation_result == onc::Validator::INVALID) { 310 if (validation_result == onc::Validator::INVALID) {
284 InvokeErrorCallback(service_path, error_callback, kInvalidUserSettings); 311 InvokeErrorCallback(service_path, error_callback, kInvalidUserSettings);
285 return; 312 return;
286 } 313 }
287 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) 314 if (validation_result == onc::Validator::VALID_WITH_WARNINGS)
288 LOG(WARNING) << "Validation of ONC user settings produced warnings."; 315 LOG(WARNING) << "Validation of ONC user settings produced warnings.";
289 316
290 // Fill in HexSSID field from contents of SSID field if not set already. 317 // Fill in HexSSID field from contents of SSID field if not set already.
291 if (user_settings_copy) { 318 onc::FillInHexSSIDFieldsInOncObject(onc::kNetworkConfigurationSignature,
292 onc::FillInHexSSIDFieldsInOncObject(onc::kNetworkConfigurationSignature, 319 validated_user_settings.get());
293 validated_user_settings.get());
294 }
295 320
296 const base::DictionaryValue* network_policy = 321 const base::DictionaryValue* network_policy =
297 GetByGUID(policies->per_network_config, guid); 322 GetPolicyByGUID(policies->per_network_config, guid);
298 VLOG(2) << "This configuration is " << (network_policy ? "" : "not ") 323 VLOG(2) << "This configuration is " << (network_policy ? "" : "not ")
299 << "managed."; 324 << "managed.";
300 325
301 scoped_ptr<base::DictionaryValue> shill_dictionary( 326 scoped_ptr<base::DictionaryValue> shill_dictionary(
302 policy_util::CreateShillConfiguration(*profile, 327 policy_util::CreateShillConfiguration(*profile,
303 guid, 328 guid,
304 &policies->global_network_config, 329 &policies->global_network_config,
305 network_policy, 330 network_policy,
306 validated_user_settings.get())); 331 validated_user_settings.get()));
307 332
333 if (!shill_device_dictionary->empty() && network_device_handler_) {
334 SetShillDeviceProperties(
335 state->device_path(), shill_device_dictionary.Pass(),
336 base::Bind(
337 &ManagedNetworkConfigurationHandlerImpl::SetShillServiceProperties,
338 weak_ptr_factory_.GetWeakPtr(), service_path,
339 base::Passed(&shill_dictionary), callback, error_callback),
340 error_callback);
341 } else {
342 SetShillServiceProperties(service_path, shill_dictionary.Pass(), callback,
343 error_callback);
344 }
345 }
346
347 void ManagedNetworkConfigurationHandlerImpl::SetShillDeviceProperties(
pneubeck (no reviews) 2015/03/24 16:19:52 this should really, really move to the NetworkDevi
348 const std::string& device_path,
349 scoped_ptr<base::DictionaryValue> shill_device_dictionary,
350 const base::Closure& callback,
351 const network_handler::ErrorCallback& error_callback) {
352 // Note: The 'Remove' calls here are crucial to ensure we do not start an
353 // infinte callback chain.
354 scoped_ptr<base::Value> shill_value;
355 if (shill_device_dictionary->RemoveWithoutPathExpansion(
356 shill::kCarrierProperty, &shill_value)) {
357 std::string carrier;
358 shill_value->GetAsString(&carrier);
359 NET_LOG(USER) << "SetCarrier: " << device_path << ": " << carrier;
360 network_device_handler_->SetCarrier(
361 device_path, carrier,
362 base::Bind(
363 &ManagedNetworkConfigurationHandlerImpl::SetShillDeviceProperties,
364 weak_ptr_factory_.GetWeakPtr(), device_path,
365 base::Passed(&shill_device_dictionary), callback, error_callback),
366 error_callback);
367 return;
368 }
369 if (shill_device_dictionary->empty()) {
370 callback.Run();
371 return;
372 }
373 // We have to set Device properites one at a time, but setting them is rare.
374 base::DictionaryValue::Iterator iter(*shill_device_dictionary);
375 std::string key = iter.key();
376 if (shill_device_dictionary->RemoveWithoutPathExpansion(key, &shill_value)) {
377 NET_LOG(USER) << "SetDeviceProperty: " << device_path << ": " << key << "="
378 << *shill_value;
379 network_device_handler_->SetDeviceProperty(
380 device_path, key, *shill_value,
381 base::Bind(
382 &ManagedNetworkConfigurationHandlerImpl::SetShillDeviceProperties,
383 weak_ptr_factory_.GetWeakPtr(), device_path,
384 base::Passed(&shill_device_dictionary), callback, error_callback),
385 error_callback);
386 }
387 }
388
389 void ManagedNetworkConfigurationHandlerImpl::SetShillServiceProperties(
390 const std::string& service_path,
391 scoped_ptr<base::DictionaryValue> shill_service_dictionary,
392 const base::Closure& callback,
393 const network_handler::ErrorCallback& error_callback) {
308 network_configuration_handler_->SetShillProperties( 394 network_configuration_handler_->SetShillProperties(
309 service_path, *shill_dictionary, 395 service_path, *shill_service_dictionary,
310 NetworkConfigurationObserver::SOURCE_USER_ACTION, callback, 396 NetworkConfigurationObserver::SOURCE_USER_ACTION, callback,
311 error_callback); 397 error_callback);
312 } 398 }
313 399
314 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration( 400 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration(
315 const std::string& userhash, 401 const std::string& userhash,
316 const base::DictionaryValue& properties, 402 const base::DictionaryValue& properties,
317 const network_handler::StringResultCallback& callback, 403 const network_handler::StringResultCallback& callback,
318 const network_handler::ErrorCallback& error_callback) const { 404 const network_handler::ErrorCallback& error_callback) const {
319 const Policies* policies = GetPoliciesForUser(userhash); 405 const Policies* policies = GetPoliciesForUser(userhash);
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGUID( 651 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGUID(
566 const std::string userhash, 652 const std::string userhash,
567 const std::string& guid, 653 const std::string& guid,
568 ::onc::ONCSource* onc_source) const { 654 ::onc::ONCSource* onc_source) const {
569 *onc_source = ::onc::ONC_SOURCE_NONE; 655 *onc_source = ::onc::ONC_SOURCE_NONE;
570 656
571 if (!userhash.empty()) { 657 if (!userhash.empty()) {
572 const Policies* user_policies = GetPoliciesForUser(userhash); 658 const Policies* user_policies = GetPoliciesForUser(userhash);
573 if (user_policies) { 659 if (user_policies) {
574 const base::DictionaryValue* policy = 660 const base::DictionaryValue* policy =
575 GetByGUID(user_policies->per_network_config, guid); 661 GetPolicyByGUID(user_policies->per_network_config, guid);
576 if (policy) { 662 if (policy) {
577 *onc_source = ::onc::ONC_SOURCE_USER_POLICY; 663 *onc_source = ::onc::ONC_SOURCE_USER_POLICY;
578 return policy; 664 return policy;
579 } 665 }
580 } 666 }
581 } 667 }
582 668
583 const Policies* device_policies = GetPoliciesForUser(std::string()); 669 const Policies* device_policies = GetPoliciesForUser(std::string());
584 if (device_policies) { 670 if (device_policies) {
585 const base::DictionaryValue* policy = 671 const base::DictionaryValue* policy =
586 GetByGUID(device_policies->per_network_config, guid); 672 GetPolicyByGUID(device_policies->per_network_config, guid);
587 if (policy) { 673 if (policy) {
588 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY; 674 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY;
589 return policy; 675 return policy;
590 } 676 }
591 } 677 }
592 678
593 return NULL; 679 return NULL;
594 } 680 }
595 681
596 const GuidToPolicyMap* 682 const GuidToPolicyMap*
(...skipping 24 matching lines...) Expand all
621 network_profile_handler_->GetProfileForPath(profile_path); 707 network_profile_handler_->GetProfileForPath(profile_path);
622 if (!profile) { 708 if (!profile) {
623 NET_LOG_ERROR("Profile path unknown:" + profile_path, guid); 709 NET_LOG_ERROR("Profile path unknown:" + profile_path, guid);
624 return NULL; 710 return NULL;
625 } 711 }
626 712
627 const Policies* policies = GetPoliciesForProfile(*profile); 713 const Policies* policies = GetPoliciesForProfile(*profile);
628 if (!policies) 714 if (!policies)
629 return NULL; 715 return NULL;
630 716
631 return GetByGUID(policies->per_network_config, guid); 717 return GetPolicyByGUID(policies->per_network_config, guid);
632 } 718 }
633 719
634 const ManagedNetworkConfigurationHandlerImpl::Policies* 720 const ManagedNetworkConfigurationHandlerImpl::Policies*
635 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForUser( 721 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForUser(
636 const std::string& userhash) const { 722 const std::string& userhash) const {
637 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash); 723 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash);
638 if (it == policies_by_user_.end()) 724 if (it == policies_by_user_.end())
639 return NULL; 725 return NULL;
640 return it->second.get(); 726 return it->second.get();
641 } 727 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 scoped_ptr<base::DictionaryValue> network_properties, 887 scoped_ptr<base::DictionaryValue> network_properties,
802 GetDevicePropertiesCallback send_callback, 888 GetDevicePropertiesCallback send_callback,
803 const std::string& error_name, 889 const std::string& error_name,
804 scoped_ptr<base::DictionaryValue> error_data) { 890 scoped_ptr<base::DictionaryValue> error_data) {
805 NET_LOG_ERROR("Error getting device properties", service_path); 891 NET_LOG_ERROR("Error getting device properties", service_path);
806 send_callback.Run(service_path, network_properties.Pass()); 892 send_callback.Run(service_path, network_properties.Pass());
807 } 893 }
808 894
809 895
810 } // namespace chromeos 896 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698