OLD | NEW |
---|---|
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" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "chromeos/network/onc/onc_validator.h" | 32 #include "chromeos/network/onc/onc_validator.h" |
33 #include "chromeos/network/policy_util.h" | 33 #include "chromeos/network/policy_util.h" |
34 #include "chromeos/network/shill_property_util.h" | 34 #include "chromeos/network/shill_property_util.h" |
35 #include "components/onc/onc_constants.h" | 35 #include "components/onc/onc_constants.h" |
36 #include "third_party/cros_system_api/dbus/service_constants.h" | 36 #include "third_party/cros_system_api/dbus/service_constants.h" |
37 | 37 |
38 namespace chromeos { | 38 namespace chromeos { |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 typedef std::map<std::string, const base::DictionaryValue*> GuidToPolicyMap; | |
43 | |
42 // These are error strings used for error callbacks. None of these error | 44 // These are error strings used for error callbacks. None of these error |
43 // messages are user-facing: they should only appear in logs. | 45 // messages are user-facing: they should only appear in logs. |
44 const char kInvalidUserSettingsMessage[] = "User settings are invalid."; | 46 const char kInvalidUserSettingsMessage[] = "User settings are invalid."; |
45 const char kInvalidUserSettings[] = "Error.InvalidUserSettings"; | 47 const char kInvalidUserSettings[] = "Error.InvalidUserSettings"; |
46 const char kNetworkAlreadyConfiguredMessage[] = | 48 const char kNetworkAlreadyConfiguredMessage[] = |
47 "Network is already configured."; | 49 "Network is already configured."; |
48 const char kNetworkAlreadyConfigured[] = "Error.NetworkAlreadyConfigured"; | 50 const char kNetworkAlreadyConfigured[] = "Error.NetworkAlreadyConfigured"; |
49 const char kPoliciesNotInitializedMessage[] = "Policies not initialized."; | 51 const char kPoliciesNotInitializedMessage[] = "Policies not initialized."; |
50 const char kPoliciesNotInitialized[] = "Error.PoliciesNotInitialized"; | 52 const char kPoliciesNotInitialized[] = "Error.PoliciesNotInitialized"; |
51 const char kProfileNotInitializedMessage[] = "Profile not initialized."; | 53 const char kProfileNotInitializedMessage[] = "Profile not initialized."; |
(...skipping 24 matching lines...) Expand all Loading... | |
76 error_name, | 78 error_name, |
77 error_message))); | 79 error_message))); |
78 } | 80 } |
79 | 81 |
80 void LogErrorWithDict(const tracked_objects::Location& from_where, | 82 void LogErrorWithDict(const tracked_objects::Location& from_where, |
81 const std::string& error_name, | 83 const std::string& error_name, |
82 scoped_ptr<base::DictionaryValue> error_data) { | 84 scoped_ptr<base::DictionaryValue> error_data) { |
83 LOG(ERROR) << from_where.ToString() << ": " << error_name; | 85 LOG(ERROR) << from_where.ToString() << ": " << error_name; |
84 } | 86 } |
85 | 87 |
86 const base::DictionaryValue* GetByGUID( | 88 const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies, |
87 const ManagedNetworkConfigurationHandlerImpl::GuidToPolicyMap& policies, | 89 const std::string& guid) { |
88 const std::string& guid) { | 90 GuidToPolicyMap::const_iterator it = policies.find(guid); |
89 ManagedNetworkConfigurationHandlerImpl::GuidToPolicyMap::const_iterator it = | |
90 policies.find(guid); | |
91 if (it == policies.end()) | 91 if (it == policies.end()) |
92 return NULL; | 92 return NULL; |
93 return it->second; | 93 return it->second; |
94 } | 94 } |
95 | 95 |
96 void TranslatePropertiesToOncAndRunCallback( | 96 void TranslatePropertiesToOncAndRunCallback( |
97 const network_handler::DictionaryResultCallback& callback, | 97 const network_handler::DictionaryResultCallback& callback, |
98 const std::string& service_path, | 98 const std::string& service_path, |
99 const base::DictionaryValue& shill_properties) { | 99 const base::DictionaryValue& shill_properties) { |
100 scoped_ptr<base::DictionaryValue> onc_network( | 100 scoped_ptr<base::DictionaryValue> onc_network( |
101 onc::TranslateShillServiceToONCPart( | 101 onc::TranslateShillServiceToONCPart( |
102 shill_properties, | 102 shill_properties, |
103 &onc::kNetworkWithStateSignature)); | 103 &onc::kNetworkWithStateSignature)); |
104 callback.Run(service_path, *onc_network); | 104 callback.Run(service_path, *onc_network); |
105 } | 105 } |
106 | 106 |
107 } // namespace | 107 } // namespace |
108 | 108 |
109 struct ManagedNetworkConfigurationHandlerImpl::Policies { | |
110 ~Policies() { STLDeleteValues(&per_network_config); } | |
bartfab (slow)
2013/10/16 12:40:31
The style guide says:
"Simple accessors should ge
pneubeck (no reviews)
2013/10/17 10:22:26
Hm. Whether this applies to .cc local classes as w
bartfab (slow)
2013/10/17 11:57:58
Yes. There was a discussion about this on chromium
| |
111 | |
112 GuidToPolicyMap per_network_config; | |
113 base::DictionaryValue global_network_config; | |
114 }; | |
115 | |
109 void ManagedNetworkConfigurationHandlerImpl::AddObserver( | 116 void ManagedNetworkConfigurationHandlerImpl::AddObserver( |
110 NetworkPolicyObserver* observer) { | 117 NetworkPolicyObserver* observer) { |
111 observers_.AddObserver(observer); | 118 observers_.AddObserver(observer); |
112 } | 119 } |
113 | 120 |
114 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( | 121 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( |
115 NetworkPolicyObserver* observer) { | 122 NetworkPolicyObserver* observer) { |
116 observers_.RemoveObserver(observer); | 123 observers_.RemoveObserver(observer); |
117 } | 124 } |
118 | 125 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 shill_properties, | 186 shill_properties, |
180 &onc::kNetworkWithStateSignature)); | 187 &onc::kNetworkWithStateSignature)); |
181 | 188 |
182 std::string guid; | 189 std::string guid; |
183 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID, | 190 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID, |
184 &guid); | 191 &guid); |
185 | 192 |
186 const base::DictionaryValue* user_policy = NULL; | 193 const base::DictionaryValue* user_policy = NULL; |
187 const base::DictionaryValue* device_policy = NULL; | 194 const base::DictionaryValue* device_policy = NULL; |
188 if (!guid.empty() && profile) { | 195 if (!guid.empty() && profile) { |
189 const GuidToPolicyMap* policies = GetPoliciesForProfile(*profile); | 196 const Policies* policies = GetPoliciesForProfile(*profile); |
190 if (!policies) { | 197 if (!policies) { |
191 RunErrorCallback(service_path, | 198 RunErrorCallback(service_path, |
192 kPoliciesNotInitialized, | 199 kPoliciesNotInitialized, |
193 kPoliciesNotInitializedMessage, | 200 kPoliciesNotInitializedMessage, |
194 error_callback); | 201 error_callback); |
195 return; | 202 return; |
196 } | 203 } |
197 const base::DictionaryValue* policy = GetByGUID(*policies, guid); | 204 const base::DictionaryValue* policy = |
205 GetByGUID(policies->per_network_config, guid); | |
198 if (profile->type() == NetworkProfile::TYPE_SHARED) | 206 if (profile->type() == NetworkProfile::TYPE_SHARED) |
199 device_policy = policy; | 207 device_policy = policy; |
200 else if (profile->type() == NetworkProfile::TYPE_USER) | 208 else if (profile->type() == NetworkProfile::TYPE_USER) |
201 user_policy = policy; | 209 user_policy = policy; |
202 else | 210 else |
203 NOTREACHED(); | 211 NOTREACHED(); |
204 } | 212 } |
205 | 213 |
206 // This call also removes credentials from policies. | 214 // This call also removes credentials from policies. |
207 scoped_ptr<base::DictionaryValue> augmented_properties = | 215 scoped_ptr<base::DictionaryValue> augmented_properties = |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 RunErrorCallback(service_path, | 268 RunErrorCallback(service_path, |
261 kUnknownProfilePath, | 269 kUnknownProfilePath, |
262 kUnknownProfilePathMessage, | 270 kUnknownProfilePathMessage, |
263 error_callback); | 271 error_callback); |
264 return; | 272 return; |
265 } | 273 } |
266 | 274 |
267 VLOG(2) << "SetProperties: Found GUID " << guid << " and profile " | 275 VLOG(2) << "SetProperties: Found GUID " << guid << " and profile " |
268 << profile->ToDebugString(); | 276 << profile->ToDebugString(); |
269 | 277 |
270 const GuidToPolicyMap* policies = GetPoliciesForProfile(*profile); | 278 const Policies* policies = GetPoliciesForProfile(*profile); |
271 if (!policies) { | 279 if (!policies) { |
272 RunErrorCallback(service_path, | 280 RunErrorCallback(service_path, |
273 kPoliciesNotInitialized, | 281 kPoliciesNotInitialized, |
274 kPoliciesNotInitializedMessage, | 282 kPoliciesNotInitializedMessage, |
275 error_callback); | 283 error_callback); |
276 return; | 284 return; |
277 } | 285 } |
278 | 286 |
279 // Validate the ONC dictionary. We are liberal and ignore unknown field | 287 // Validate the ONC dictionary. We are liberal and ignore unknown field |
280 // names. User settings are only partial ONC, thus we ignore missing fields. | 288 // names. User settings are only partial ONC, thus we ignore missing fields. |
(...skipping 12 matching lines...) Expand all Loading... | |
293 if (validation_result == onc::Validator::INVALID) { | 301 if (validation_result == onc::Validator::INVALID) { |
294 RunErrorCallback(service_path, | 302 RunErrorCallback(service_path, |
295 kInvalidUserSettings, | 303 kInvalidUserSettings, |
296 kInvalidUserSettingsMessage, | 304 kInvalidUserSettingsMessage, |
297 error_callback); | 305 error_callback); |
298 return; | 306 return; |
299 } | 307 } |
300 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) | 308 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) |
301 LOG(WARNING) << "Validation of ONC user settings produced warnings."; | 309 LOG(WARNING) << "Validation of ONC user settings produced warnings."; |
302 | 310 |
303 const base::DictionaryValue* policy = GetByGUID(*policies, guid); | 311 const base::DictionaryValue* policy = |
312 GetByGUID(policies->per_network_config, guid); | |
304 VLOG(2) << "This configuration is " << (policy ? "" : "not ") << "managed."; | 313 VLOG(2) << "This configuration is " << (policy ? "" : "not ") << "managed."; |
305 | 314 |
306 scoped_ptr<base::DictionaryValue> shill_dictionary( | 315 scoped_ptr<base::DictionaryValue> shill_dictionary( |
307 policy_util::CreateShillConfiguration( | 316 policy_util::CreateShillConfiguration( |
308 *profile, guid, policy, validated_user_settings.get())); | 317 *profile, guid, policy, validated_user_settings.get())); |
309 | 318 |
310 network_configuration_handler_->SetProperties( | 319 network_configuration_handler_->SetProperties( |
311 service_path, *shill_dictionary, callback, error_callback); | 320 service_path, *shill_dictionary, callback, error_callback); |
312 } | 321 } |
313 | 322 |
314 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration( | 323 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration( |
315 const std::string& userhash, | 324 const std::string& userhash, |
316 const base::DictionaryValue& properties, | 325 const base::DictionaryValue& properties, |
317 const network_handler::StringResultCallback& callback, | 326 const network_handler::StringResultCallback& callback, |
318 const network_handler::ErrorCallback& error_callback) const { | 327 const network_handler::ErrorCallback& error_callback) const { |
319 const GuidToPolicyMap* policies = GetPoliciesForUser(userhash); | 328 const Policies* policies = GetPoliciesForUser(userhash); |
320 if (!policies) { | 329 if (!policies) { |
321 RunErrorCallback("", | 330 RunErrorCallback("", |
322 kPoliciesNotInitialized, | 331 kPoliciesNotInitialized, |
323 kPoliciesNotInitializedMessage, | 332 kPoliciesNotInitializedMessage, |
324 error_callback); | 333 error_callback); |
325 return; | 334 return; |
326 } | 335 } |
327 | 336 |
328 if (policy_util::FindMatchingPolicy(*policies, properties)) { | 337 if (policy_util::FindMatchingPolicy(policies->per_network_config, |
338 properties)) { | |
329 RunErrorCallback("", | 339 RunErrorCallback("", |
330 kNetworkAlreadyConfigured, | 340 kNetworkAlreadyConfigured, |
331 kNetworkAlreadyConfiguredMessage, | 341 kNetworkAlreadyConfiguredMessage, |
332 error_callback); | 342 error_callback); |
333 } | 343 } |
334 | 344 |
335 const NetworkProfile* profile = | 345 const NetworkProfile* profile = |
336 network_profile_handler_->GetProfileForUserhash(userhash); | 346 network_profile_handler_->GetProfileForUserhash(userhash); |
337 if (!profile) { | 347 if (!profile) { |
338 RunErrorCallback("", | 348 RunErrorCallback("", |
(...skipping 21 matching lines...) Expand all Loading... | |
360 const std::string& service_path, | 370 const std::string& service_path, |
361 const base::Closure& callback, | 371 const base::Closure& callback, |
362 const network_handler::ErrorCallback& error_callback) const { | 372 const network_handler::ErrorCallback& error_callback) const { |
363 network_configuration_handler_->RemoveConfiguration( | 373 network_configuration_handler_->RemoveConfiguration( |
364 service_path, callback, error_callback); | 374 service_path, callback, error_callback); |
365 } | 375 } |
366 | 376 |
367 void ManagedNetworkConfigurationHandlerImpl::SetPolicy( | 377 void ManagedNetworkConfigurationHandlerImpl::SetPolicy( |
368 ::onc::ONCSource onc_source, | 378 ::onc::ONCSource onc_source, |
369 const std::string& userhash, | 379 const std::string& userhash, |
370 const base::ListValue& network_configs_onc) { | 380 const base::ListValue& network_configs_onc, |
381 const base::DictionaryValue& global_network_config) { | |
371 VLOG(1) << "Setting policies from " << ToDebugString(onc_source, userhash) | 382 VLOG(1) << "Setting policies from " << ToDebugString(onc_source, userhash) |
372 << "."; | 383 << "."; |
373 | 384 |
374 // |userhash| must be empty for device policies. | 385 // |userhash| must be empty for device policies. |
375 DCHECK(onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY || | 386 DCHECK(onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY || |
376 userhash.empty()); | 387 userhash.empty()); |
377 GuidToPolicyMap& policies = policies_by_user_[userhash]; | 388 Policies* policies = NULL; |
389 if (ContainsKey(policies_by_user_, userhash)) { | |
390 policies = policies_by_user_[userhash].get(); | |
391 } else { | |
392 policies = new Policies; | |
393 policies_by_user_[userhash] = make_linked_ptr(policies); | |
394 } | |
378 | 395 |
379 GuidToPolicyMap old_policies; | 396 policies->global_network_config.MergeDictionary(&global_network_config); |
380 policies.swap(old_policies); | 397 |
398 GuidToPolicyMap old_per_network_config; | |
399 policies->per_network_config.swap(old_per_network_config); | |
381 | 400 |
382 // This stores all GUIDs of policies that have changed or are new. | 401 // This stores all GUIDs of policies that have changed or are new. |
383 std::set<std::string> modified_policies; | 402 std::set<std::string> modified_policies; |
384 | 403 |
385 for (base::ListValue::const_iterator it = network_configs_onc.begin(); | 404 for (base::ListValue::const_iterator it = network_configs_onc.begin(); |
386 it != network_configs_onc.end(); ++it) { | 405 it != network_configs_onc.end(); ++it) { |
387 const base::DictionaryValue* network = NULL; | 406 const base::DictionaryValue* network = NULL; |
388 (*it)->GetAsDictionary(&network); | 407 (*it)->GetAsDictionary(&network); |
389 DCHECK(network); | 408 DCHECK(network); |
390 | 409 |
391 std::string guid; | 410 std::string guid; |
392 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid); | 411 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid); |
393 DCHECK(!guid.empty()); | 412 DCHECK(!guid.empty()); |
394 | 413 |
395 if (policies.count(guid) > 0) { | 414 if (policies->per_network_config.count(guid) > 0) { |
396 LOG(ERROR) << "ONC from " << ToDebugString(onc_source, userhash) | 415 LOG(ERROR) << "ONC from " << ToDebugString(onc_source, userhash) |
397 << " contains several entries for the same GUID " | 416 << " contains several entries for the same GUID " |
398 << guid << "."; | 417 << guid << "."; |
399 delete policies[guid]; | 418 delete policies->per_network_config[guid]; |
400 } | 419 } |
401 const base::DictionaryValue* new_entry = network->DeepCopy(); | 420 const base::DictionaryValue* new_entry = network->DeepCopy(); |
402 policies[guid] = new_entry; | 421 policies->per_network_config[guid] = new_entry; |
403 | 422 |
404 const base::DictionaryValue* old_entry = old_policies[guid]; | 423 const base::DictionaryValue* old_entry = old_per_network_config[guid]; |
405 if (!old_entry || !old_entry->Equals(new_entry)) | 424 if (!old_entry || !old_entry->Equals(new_entry)) |
406 modified_policies.insert(guid); | 425 modified_policies.insert(guid); |
407 } | 426 } |
408 | 427 |
409 STLDeleteValues(&old_policies); | 428 STLDeleteValues(&old_per_network_config); |
410 | 429 |
411 const NetworkProfile* profile = | 430 const NetworkProfile* profile = |
412 network_profile_handler_->GetProfileForUserhash(userhash); | 431 network_profile_handler_->GetProfileForUserhash(userhash); |
413 if (!profile) { | 432 if (!profile) { |
414 VLOG(1) << "The relevant Shill profile isn't initialized yet, postponing " | 433 VLOG(1) << "The relevant Shill profile isn't initialized yet, postponing " |
415 << "policy application."; | 434 << "policy application."; |
416 return; | 435 return; |
417 } | 436 } |
418 | 437 |
419 scoped_refptr<PolicyApplicator> applicator = new PolicyApplicator( | 438 scoped_refptr<PolicyApplicator> applicator = |
420 weak_ptr_factory_.GetWeakPtr(), *profile, policies, &modified_policies); | 439 new PolicyApplicator(weak_ptr_factory_.GetWeakPtr(), |
440 *profile, | |
441 policies->per_network_config, | |
bartfab (slow)
2013/10/16 12:40:31
Since you have a struct that groups per-network co
pneubeck (no reviews)
2013/10/17 10:22:26
I think it's not worth it for two arguments only,
| |
442 policies->global_network_config, | |
443 &modified_policies); | |
421 applicator->Run(); | 444 applicator->Run(); |
422 } | 445 } |
423 | 446 |
424 void ManagedNetworkConfigurationHandlerImpl::OnProfileAdded( | 447 void ManagedNetworkConfigurationHandlerImpl::OnProfileAdded( |
425 const NetworkProfile& profile) { | 448 const NetworkProfile& profile) { |
426 VLOG(1) << "Adding profile " << profile.ToDebugString() << "'."; | 449 VLOG(1) << "Adding profile " << profile.ToDebugString() << "'."; |
427 | 450 |
428 const GuidToPolicyMap* policies = GetPoliciesForProfile(profile); | 451 const Policies* policies = GetPoliciesForProfile(profile); |
429 if (!policies) { | 452 if (!policies) { |
430 VLOG(1) << "The relevant policy is not initialized, " | 453 VLOG(1) << "The relevant policy is not initialized, " |
431 << "postponing policy application."; | 454 << "postponing policy application."; |
432 return; | 455 return; |
433 } | 456 } |
434 | 457 |
435 std::set<std::string> policy_guids; | 458 std::set<std::string> policy_guids; |
436 for (GuidToPolicyMap::const_iterator it = policies->begin(); | 459 for (GuidToPolicyMap::const_iterator it = |
437 it != policies->end(); ++it) { | 460 policies->per_network_config.begin(); |
461 it != policies->per_network_config.end(); ++it) { | |
438 policy_guids.insert(it->first); | 462 policy_guids.insert(it->first); |
439 } | 463 } |
440 | 464 |
441 scoped_refptr<PolicyApplicator> applicator = new PolicyApplicator( | 465 scoped_refptr<PolicyApplicator> applicator = |
442 weak_ptr_factory_.GetWeakPtr(), profile, *policies, &policy_guids); | 466 new PolicyApplicator(weak_ptr_factory_.GetWeakPtr(), |
467 profile, | |
468 policies->per_network_config, | |
469 policies->global_network_config, | |
470 &policy_guids); | |
443 applicator->Run(); | 471 applicator->Run(); |
444 } | 472 } |
445 | 473 |
446 void ManagedNetworkConfigurationHandlerImpl::OnProfileRemoved( | 474 void ManagedNetworkConfigurationHandlerImpl::OnProfileRemoved( |
447 const NetworkProfile& profile) { | 475 const NetworkProfile& profile) { |
448 // Nothing to do in this case. | 476 // Nothing to do in this case. |
449 } | 477 } |
450 | 478 |
451 void ManagedNetworkConfigurationHandlerImpl::CreateConfigurationFromPolicy( | 479 void ManagedNetworkConfigurationHandlerImpl::CreateConfigurationFromPolicy( |
452 const base::DictionaryValue& shill_properties) { | 480 const base::DictionaryValue& shill_properties) { |
453 network_configuration_handler_->CreateConfiguration( | 481 network_configuration_handler_->CreateConfiguration( |
454 shill_properties, | 482 shill_properties, |
455 base::Bind(&ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied, | 483 base::Bind(&ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied, |
456 weak_ptr_factory_.GetWeakPtr()), | 484 weak_ptr_factory_.GetWeakPtr()), |
457 base::Bind(&LogErrorWithDict, FROM_HERE)); | 485 base::Bind(&LogErrorWithDict, FROM_HERE)); |
458 } | 486 } |
459 | 487 |
488 void ManagedNetworkConfigurationHandlerImpl:: | |
489 UpdateExistingConfigurationWithPropertiesFromPolicy( | |
490 const base::DictionaryValue& existing_properties, | |
491 const base::DictionaryValue& new_properties) { | |
492 base::DictionaryValue shill_properties; | |
493 | |
494 std::string profile; | |
495 existing_properties.GetStringWithoutPathExpansion(shill::kProfileProperty, | |
496 &profile); | |
497 if (profile.empty()) { | |
498 LOG(ERROR) << "Missing profile property."; | |
499 return; | |
500 } | |
501 shill_properties.SetStringWithoutPathExpansion(shill::kProfileProperty, | |
502 profile); | |
503 | |
504 if (!shill_property_util::CopyIdentifyingProperties(existing_properties, | |
505 &shill_properties)) { | |
506 LOG(ERROR) << "Missing identifying properties."; | |
507 } | |
508 | |
509 shill_properties.MergeDictionary(&new_properties); | |
510 | |
511 network_configuration_handler_->CreateConfiguration( | |
512 shill_properties, | |
513 base::Bind(&ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied, | |
514 weak_ptr_factory_.GetWeakPtr()), | |
515 base::Bind(&LogErrorWithDict, FROM_HERE)); | |
516 } | |
517 | |
460 const base::DictionaryValue* | 518 const base::DictionaryValue* |
461 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGUID( | 519 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGUID( |
462 const std::string userhash, | 520 const std::string userhash, |
463 const std::string& guid, | 521 const std::string& guid, |
464 ::onc::ONCSource* onc_source) const { | 522 ::onc::ONCSource* onc_source) const { |
465 *onc_source = ::onc::ONC_SOURCE_NONE; | 523 *onc_source = ::onc::ONC_SOURCE_NONE; |
466 | 524 |
467 if (!userhash.empty()) { | 525 if (!userhash.empty()) { |
468 const GuidToPolicyMap* user_policies = GetPoliciesForUser(userhash); | 526 const Policies* user_policies = GetPoliciesForUser(userhash); |
469 if (user_policies) { | 527 if (user_policies) { |
470 GuidToPolicyMap::const_iterator found = user_policies->find(guid); | 528 const base::DictionaryValue* policy = |
471 if (found != user_policies->end()) { | 529 GetByGUID(user_policies->per_network_config, guid); |
530 if (policy) { | |
472 *onc_source = ::onc::ONC_SOURCE_USER_POLICY; | 531 *onc_source = ::onc::ONC_SOURCE_USER_POLICY; |
473 return found->second; | 532 return policy; |
474 } | 533 } |
475 } | 534 } |
476 } | 535 } |
477 | 536 |
478 const GuidToPolicyMap* device_policies = GetPoliciesForUser(std::string()); | 537 const Policies* device_policies = GetPoliciesForUser(std::string()); |
479 if (device_policies) { | 538 if (device_policies) { |
480 GuidToPolicyMap::const_iterator found = device_policies->find(guid); | 539 const base::DictionaryValue* policy = |
481 if (found != device_policies->end()) { | 540 GetByGUID(device_policies->per_network_config, guid); |
541 if (policy) { | |
482 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY; | 542 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY; |
483 return found->second; | 543 return policy; |
484 } | 544 } |
485 } | 545 } |
486 | 546 |
487 return NULL; | 547 return NULL; |
488 } | 548 } |
489 | 549 |
490 const base::DictionaryValue* | 550 const base::DictionaryValue* |
491 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGuidAndProfile( | 551 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGuidAndProfile( |
492 const std::string& guid, | 552 const std::string& guid, |
493 const std::string& profile_path) const { | 553 const std::string& profile_path) const { |
494 const NetworkProfile* profile = | 554 const NetworkProfile* profile = |
495 network_profile_handler_->GetProfileForPath(profile_path); | 555 network_profile_handler_->GetProfileForPath(profile_path); |
496 if (!profile) { | 556 if (!profile) { |
497 LOG(ERROR) << "Profile path unknown: " << profile_path; | 557 LOG(ERROR) << "Profile path unknown: " << profile_path; |
498 return NULL; | 558 return NULL; |
499 } | 559 } |
500 | 560 |
501 const GuidToPolicyMap* policies = GetPoliciesForProfile(*profile); | 561 const Policies* policies = GetPoliciesForProfile(*profile); |
502 if (!policies) | 562 if (!policies) |
503 return NULL; | 563 return NULL; |
504 | 564 |
505 GuidToPolicyMap::const_iterator it = policies->find(guid); | 565 return GetByGUID(policies->per_network_config, guid); |
506 if (it == policies->end()) | |
507 return NULL; | |
508 return it->second; | |
509 } | 566 } |
510 | 567 |
511 const ManagedNetworkConfigurationHandlerImpl::GuidToPolicyMap* | 568 const ManagedNetworkConfigurationHandlerImpl::Policies* |
512 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForUser( | 569 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForUser( |
513 const std::string& userhash) const { | 570 const std::string& userhash) const { |
514 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash); | 571 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash); |
515 if (it == policies_by_user_.end()) | 572 if (it == policies_by_user_.end()) |
516 return NULL; | 573 return NULL; |
517 return &it->second; | 574 return it->second.get(); |
518 } | 575 } |
519 | 576 |
520 const ManagedNetworkConfigurationHandlerImpl::GuidToPolicyMap* | 577 const ManagedNetworkConfigurationHandlerImpl::Policies* |
521 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForProfile( | 578 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForProfile( |
522 const NetworkProfile& profile) const { | 579 const NetworkProfile& profile) const { |
523 DCHECK(profile.type() != NetworkProfile::TYPE_SHARED || | 580 DCHECK(profile.type() != NetworkProfile::TYPE_SHARED || |
524 profile.userhash.empty()); | 581 profile.userhash.empty()); |
525 return GetPoliciesForUser(profile.userhash); | 582 return GetPoliciesForUser(profile.userhash); |
526 } | 583 } |
527 | 584 |
528 ManagedNetworkConfigurationHandlerImpl::ManagedNetworkConfigurationHandlerImpl() | 585 ManagedNetworkConfigurationHandlerImpl::ManagedNetworkConfigurationHandlerImpl() |
529 : network_state_handler_(NULL), | 586 : network_state_handler_(NULL), |
530 network_profile_handler_(NULL), | 587 network_profile_handler_(NULL), |
531 network_configuration_handler_(NULL), | 588 network_configuration_handler_(NULL), |
532 weak_ptr_factory_(this) {} | 589 weak_ptr_factory_(this) {} |
533 | 590 |
534 ManagedNetworkConfigurationHandlerImpl:: | 591 ManagedNetworkConfigurationHandlerImpl:: |
535 ~ManagedNetworkConfigurationHandlerImpl() { | 592 ~ManagedNetworkConfigurationHandlerImpl() { |
536 network_profile_handler_->RemoveObserver(this); | 593 network_profile_handler_->RemoveObserver(this); |
537 for (UserToPoliciesMap::iterator it = policies_by_user_.begin(); | |
538 it != policies_by_user_.end(); ++it) { | |
539 STLDeleteValues(&it->second); | |
540 } | |
541 } | 594 } |
542 | 595 |
543 void ManagedNetworkConfigurationHandlerImpl::Init( | 596 void ManagedNetworkConfigurationHandlerImpl::Init( |
544 NetworkStateHandler* network_state_handler, | 597 NetworkStateHandler* network_state_handler, |
545 NetworkProfileHandler* network_profile_handler, | 598 NetworkProfileHandler* network_profile_handler, |
546 NetworkConfigurationHandler* network_configuration_handler) { | 599 NetworkConfigurationHandler* network_configuration_handler) { |
547 network_state_handler_ = network_state_handler; | 600 network_state_handler_ = network_state_handler; |
548 network_profile_handler_ = network_profile_handler; | 601 network_profile_handler_ = network_profile_handler; |
549 network_configuration_handler_ = network_configuration_handler; | 602 network_configuration_handler_ = network_configuration_handler; |
550 network_profile_handler_->AddObserver(this); | 603 network_profile_handler_->AddObserver(this); |
551 } | 604 } |
552 | 605 |
553 void ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied( | 606 void ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied( |
554 const std::string& service_path) { | 607 const std::string& service_path) { |
555 if (service_path.empty()) | 608 if (service_path.empty()) |
556 return; | 609 return; |
557 FOR_EACH_OBSERVER( | 610 FOR_EACH_OBSERVER( |
558 NetworkPolicyObserver, observers_, PolicyApplied(service_path)); | 611 NetworkPolicyObserver, observers_, PolicyApplied(service_path)); |
559 } | 612 } |
560 | 613 |
561 } // namespace chromeos | 614 } // namespace chromeos |
OLD | NEW |