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(); |
| 111 |
| 112 GuidToPolicyMap per_network_config; |
| 113 base::DictionaryValue global_network_config; |
| 114 }; |
| 115 |
| 116 ManagedNetworkConfigurationHandlerImpl::Policies::~Policies() { |
| 117 STLDeleteValues(&per_network_config); |
| 118 } |
| 119 |
109 void ManagedNetworkConfigurationHandlerImpl::AddObserver( | 120 void ManagedNetworkConfigurationHandlerImpl::AddObserver( |
110 NetworkPolicyObserver* observer) { | 121 NetworkPolicyObserver* observer) { |
111 observers_.AddObserver(observer); | 122 observers_.AddObserver(observer); |
112 } | 123 } |
113 | 124 |
114 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( | 125 void ManagedNetworkConfigurationHandlerImpl::RemoveObserver( |
115 NetworkPolicyObserver* observer) { | 126 NetworkPolicyObserver* observer) { |
116 observers_.RemoveObserver(observer); | 127 observers_.RemoveObserver(observer); |
117 } | 128 } |
118 | 129 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 shill_properties, | 190 shill_properties, |
180 &onc::kNetworkWithStateSignature)); | 191 &onc::kNetworkWithStateSignature)); |
181 | 192 |
182 std::string guid; | 193 std::string guid; |
183 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID, | 194 active_settings->GetStringWithoutPathExpansion(::onc::network_config::kGUID, |
184 &guid); | 195 &guid); |
185 | 196 |
186 const base::DictionaryValue* user_policy = NULL; | 197 const base::DictionaryValue* user_policy = NULL; |
187 const base::DictionaryValue* device_policy = NULL; | 198 const base::DictionaryValue* device_policy = NULL; |
188 if (!guid.empty() && profile) { | 199 if (!guid.empty() && profile) { |
189 const GuidToPolicyMap* policies = GetPoliciesForProfile(*profile); | 200 const Policies* policies = GetPoliciesForProfile(*profile); |
190 if (!policies) { | 201 if (!policies) { |
191 RunErrorCallback(service_path, | 202 RunErrorCallback(service_path, |
192 kPoliciesNotInitialized, | 203 kPoliciesNotInitialized, |
193 kPoliciesNotInitializedMessage, | 204 kPoliciesNotInitializedMessage, |
194 error_callback); | 205 error_callback); |
195 return; | 206 return; |
196 } | 207 } |
197 const base::DictionaryValue* policy = GetByGUID(*policies, guid); | 208 const base::DictionaryValue* policy = |
| 209 GetByGUID(policies->per_network_config, guid); |
198 if (profile->type() == NetworkProfile::TYPE_SHARED) | 210 if (profile->type() == NetworkProfile::TYPE_SHARED) |
199 device_policy = policy; | 211 device_policy = policy; |
200 else if (profile->type() == NetworkProfile::TYPE_USER) | 212 else if (profile->type() == NetworkProfile::TYPE_USER) |
201 user_policy = policy; | 213 user_policy = policy; |
202 else | 214 else |
203 NOTREACHED(); | 215 NOTREACHED(); |
204 } | 216 } |
205 | 217 |
206 // This call also removes credentials from policies. | 218 // This call also removes credentials from policies. |
207 scoped_ptr<base::DictionaryValue> augmented_properties = | 219 scoped_ptr<base::DictionaryValue> augmented_properties = |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 RunErrorCallback(service_path, | 272 RunErrorCallback(service_path, |
261 kUnknownProfilePath, | 273 kUnknownProfilePath, |
262 kUnknownProfilePathMessage, | 274 kUnknownProfilePathMessage, |
263 error_callback); | 275 error_callback); |
264 return; | 276 return; |
265 } | 277 } |
266 | 278 |
267 VLOG(2) << "SetProperties: Found GUID " << guid << " and profile " | 279 VLOG(2) << "SetProperties: Found GUID " << guid << " and profile " |
268 << profile->ToDebugString(); | 280 << profile->ToDebugString(); |
269 | 281 |
270 const GuidToPolicyMap* policies = GetPoliciesForProfile(*profile); | 282 const Policies* policies = GetPoliciesForProfile(*profile); |
271 if (!policies) { | 283 if (!policies) { |
272 RunErrorCallback(service_path, | 284 RunErrorCallback(service_path, |
273 kPoliciesNotInitialized, | 285 kPoliciesNotInitialized, |
274 kPoliciesNotInitializedMessage, | 286 kPoliciesNotInitializedMessage, |
275 error_callback); | 287 error_callback); |
276 return; | 288 return; |
277 } | 289 } |
278 | 290 |
279 // Validate the ONC dictionary. We are liberal and ignore unknown field | 291 // Validate the ONC dictionary. We are liberal and ignore unknown field |
280 // names. User settings are only partial ONC, thus we ignore missing fields. | 292 // 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) { | 305 if (validation_result == onc::Validator::INVALID) { |
294 RunErrorCallback(service_path, | 306 RunErrorCallback(service_path, |
295 kInvalidUserSettings, | 307 kInvalidUserSettings, |
296 kInvalidUserSettingsMessage, | 308 kInvalidUserSettingsMessage, |
297 error_callback); | 309 error_callback); |
298 return; | 310 return; |
299 } | 311 } |
300 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) | 312 if (validation_result == onc::Validator::VALID_WITH_WARNINGS) |
301 LOG(WARNING) << "Validation of ONC user settings produced warnings."; | 313 LOG(WARNING) << "Validation of ONC user settings produced warnings."; |
302 | 314 |
303 const base::DictionaryValue* policy = GetByGUID(*policies, guid); | 315 const base::DictionaryValue* policy = |
| 316 GetByGUID(policies->per_network_config, guid); |
304 VLOG(2) << "This configuration is " << (policy ? "" : "not ") << "managed."; | 317 VLOG(2) << "This configuration is " << (policy ? "" : "not ") << "managed."; |
305 | 318 |
306 scoped_ptr<base::DictionaryValue> shill_dictionary( | 319 scoped_ptr<base::DictionaryValue> shill_dictionary( |
307 policy_util::CreateShillConfiguration( | 320 policy_util::CreateShillConfiguration( |
308 *profile, guid, policy, validated_user_settings.get())); | 321 *profile, guid, policy, validated_user_settings.get())); |
309 | 322 |
310 network_configuration_handler_->SetProperties( | 323 network_configuration_handler_->SetProperties( |
311 service_path, *shill_dictionary, callback, error_callback); | 324 service_path, *shill_dictionary, callback, error_callback); |
312 } | 325 } |
313 | 326 |
314 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration( | 327 void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration( |
315 const std::string& userhash, | 328 const std::string& userhash, |
316 const base::DictionaryValue& properties, | 329 const base::DictionaryValue& properties, |
317 const network_handler::StringResultCallback& callback, | 330 const network_handler::StringResultCallback& callback, |
318 const network_handler::ErrorCallback& error_callback) const { | 331 const network_handler::ErrorCallback& error_callback) const { |
319 const GuidToPolicyMap* policies = GetPoliciesForUser(userhash); | 332 const Policies* policies = GetPoliciesForUser(userhash); |
320 if (!policies) { | 333 if (!policies) { |
321 RunErrorCallback("", | 334 RunErrorCallback("", |
322 kPoliciesNotInitialized, | 335 kPoliciesNotInitialized, |
323 kPoliciesNotInitializedMessage, | 336 kPoliciesNotInitializedMessage, |
324 error_callback); | 337 error_callback); |
325 return; | 338 return; |
326 } | 339 } |
327 | 340 |
328 if (policy_util::FindMatchingPolicy(*policies, properties)) { | 341 if (policy_util::FindMatchingPolicy(policies->per_network_config, |
| 342 properties)) { |
329 RunErrorCallback("", | 343 RunErrorCallback("", |
330 kNetworkAlreadyConfigured, | 344 kNetworkAlreadyConfigured, |
331 kNetworkAlreadyConfiguredMessage, | 345 kNetworkAlreadyConfiguredMessage, |
332 error_callback); | 346 error_callback); |
333 } | 347 } |
334 | 348 |
335 const NetworkProfile* profile = | 349 const NetworkProfile* profile = |
336 network_profile_handler_->GetProfileForUserhash(userhash); | 350 network_profile_handler_->GetProfileForUserhash(userhash); |
337 if (!profile) { | 351 if (!profile) { |
338 RunErrorCallback("", | 352 RunErrorCallback("", |
(...skipping 21 matching lines...) Expand all Loading... |
360 const std::string& service_path, | 374 const std::string& service_path, |
361 const base::Closure& callback, | 375 const base::Closure& callback, |
362 const network_handler::ErrorCallback& error_callback) const { | 376 const network_handler::ErrorCallback& error_callback) const { |
363 network_configuration_handler_->RemoveConfiguration( | 377 network_configuration_handler_->RemoveConfiguration( |
364 service_path, callback, error_callback); | 378 service_path, callback, error_callback); |
365 } | 379 } |
366 | 380 |
367 void ManagedNetworkConfigurationHandlerImpl::SetPolicy( | 381 void ManagedNetworkConfigurationHandlerImpl::SetPolicy( |
368 ::onc::ONCSource onc_source, | 382 ::onc::ONCSource onc_source, |
369 const std::string& userhash, | 383 const std::string& userhash, |
370 const base::ListValue& network_configs_onc) { | 384 const base::ListValue& network_configs_onc, |
| 385 const base::DictionaryValue& global_network_config) { |
371 VLOG(1) << "Setting policies from " << ToDebugString(onc_source, userhash) | 386 VLOG(1) << "Setting policies from " << ToDebugString(onc_source, userhash) |
372 << "."; | 387 << "."; |
373 | 388 |
374 // |userhash| must be empty for device policies. | 389 // |userhash| must be empty for device policies. |
375 DCHECK(onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY || | 390 DCHECK(onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY || |
376 userhash.empty()); | 391 userhash.empty()); |
377 GuidToPolicyMap& policies = policies_by_user_[userhash]; | 392 Policies* policies = NULL; |
| 393 if (ContainsKey(policies_by_user_, userhash)) { |
| 394 policies = policies_by_user_[userhash].get(); |
| 395 } else { |
| 396 policies = new Policies; |
| 397 policies_by_user_[userhash] = make_linked_ptr(policies); |
| 398 } |
378 | 399 |
379 GuidToPolicyMap old_policies; | 400 policies->global_network_config.MergeDictionary(&global_network_config); |
380 policies.swap(old_policies); | 401 |
| 402 GuidToPolicyMap old_per_network_config; |
| 403 policies->per_network_config.swap(old_per_network_config); |
381 | 404 |
382 // This stores all GUIDs of policies that have changed or are new. | 405 // This stores all GUIDs of policies that have changed or are new. |
383 std::set<std::string> modified_policies; | 406 std::set<std::string> modified_policies; |
384 | 407 |
385 for (base::ListValue::const_iterator it = network_configs_onc.begin(); | 408 for (base::ListValue::const_iterator it = network_configs_onc.begin(); |
386 it != network_configs_onc.end(); ++it) { | 409 it != network_configs_onc.end(); ++it) { |
387 const base::DictionaryValue* network = NULL; | 410 const base::DictionaryValue* network = NULL; |
388 (*it)->GetAsDictionary(&network); | 411 (*it)->GetAsDictionary(&network); |
389 DCHECK(network); | 412 DCHECK(network); |
390 | 413 |
391 std::string guid; | 414 std::string guid; |
392 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid); | 415 network->GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid); |
393 DCHECK(!guid.empty()); | 416 DCHECK(!guid.empty()); |
394 | 417 |
395 if (policies.count(guid) > 0) { | 418 if (policies->per_network_config.count(guid) > 0) { |
396 LOG(ERROR) << "ONC from " << ToDebugString(onc_source, userhash) | 419 LOG(ERROR) << "ONC from " << ToDebugString(onc_source, userhash) |
397 << " contains several entries for the same GUID " | 420 << " contains several entries for the same GUID " |
398 << guid << "."; | 421 << guid << "."; |
399 delete policies[guid]; | 422 delete policies->per_network_config[guid]; |
400 } | 423 } |
401 const base::DictionaryValue* new_entry = network->DeepCopy(); | 424 const base::DictionaryValue* new_entry = network->DeepCopy(); |
402 policies[guid] = new_entry; | 425 policies->per_network_config[guid] = new_entry; |
403 | 426 |
404 const base::DictionaryValue* old_entry = old_policies[guid]; | 427 const base::DictionaryValue* old_entry = old_per_network_config[guid]; |
405 if (!old_entry || !old_entry->Equals(new_entry)) | 428 if (!old_entry || !old_entry->Equals(new_entry)) |
406 modified_policies.insert(guid); | 429 modified_policies.insert(guid); |
407 } | 430 } |
408 | 431 |
409 STLDeleteValues(&old_policies); | 432 STLDeleteValues(&old_per_network_config); |
410 | 433 |
411 const NetworkProfile* profile = | 434 const NetworkProfile* profile = |
412 network_profile_handler_->GetProfileForUserhash(userhash); | 435 network_profile_handler_->GetProfileForUserhash(userhash); |
413 if (!profile) { | 436 if (!profile) { |
414 VLOG(1) << "The relevant Shill profile isn't initialized yet, postponing " | 437 VLOG(1) << "The relevant Shill profile isn't initialized yet, postponing " |
415 << "policy application."; | 438 << "policy application."; |
416 return; | 439 return; |
417 } | 440 } |
418 | 441 |
419 scoped_refptr<PolicyApplicator> applicator = new PolicyApplicator( | 442 scoped_refptr<PolicyApplicator> applicator = |
420 weak_ptr_factory_.GetWeakPtr(), *profile, policies, &modified_policies); | 443 new PolicyApplicator(weak_ptr_factory_.GetWeakPtr(), |
| 444 *profile, |
| 445 policies->per_network_config, |
| 446 policies->global_network_config, |
| 447 &modified_policies); |
421 applicator->Run(); | 448 applicator->Run(); |
422 } | 449 } |
423 | 450 |
424 void ManagedNetworkConfigurationHandlerImpl::OnProfileAdded( | 451 void ManagedNetworkConfigurationHandlerImpl::OnProfileAdded( |
425 const NetworkProfile& profile) { | 452 const NetworkProfile& profile) { |
426 VLOG(1) << "Adding profile " << profile.ToDebugString() << "'."; | 453 VLOG(1) << "Adding profile " << profile.ToDebugString() << "'."; |
427 | 454 |
428 const GuidToPolicyMap* policies = GetPoliciesForProfile(profile); | 455 const Policies* policies = GetPoliciesForProfile(profile); |
429 if (!policies) { | 456 if (!policies) { |
430 VLOG(1) << "The relevant policy is not initialized, " | 457 VLOG(1) << "The relevant policy is not initialized, " |
431 << "postponing policy application."; | 458 << "postponing policy application."; |
432 return; | 459 return; |
433 } | 460 } |
434 | 461 |
435 std::set<std::string> policy_guids; | 462 std::set<std::string> policy_guids; |
436 for (GuidToPolicyMap::const_iterator it = policies->begin(); | 463 for (GuidToPolicyMap::const_iterator it = |
437 it != policies->end(); ++it) { | 464 policies->per_network_config.begin(); |
| 465 it != policies->per_network_config.end(); ++it) { |
438 policy_guids.insert(it->first); | 466 policy_guids.insert(it->first); |
439 } | 467 } |
440 | 468 |
441 scoped_refptr<PolicyApplicator> applicator = new PolicyApplicator( | 469 scoped_refptr<PolicyApplicator> applicator = |
442 weak_ptr_factory_.GetWeakPtr(), profile, *policies, &policy_guids); | 470 new PolicyApplicator(weak_ptr_factory_.GetWeakPtr(), |
| 471 profile, |
| 472 policies->per_network_config, |
| 473 policies->global_network_config, |
| 474 &policy_guids); |
443 applicator->Run(); | 475 applicator->Run(); |
444 } | 476 } |
445 | 477 |
446 void ManagedNetworkConfigurationHandlerImpl::OnProfileRemoved( | 478 void ManagedNetworkConfigurationHandlerImpl::OnProfileRemoved( |
447 const NetworkProfile& profile) { | 479 const NetworkProfile& profile) { |
448 // Nothing to do in this case. | 480 // Nothing to do in this case. |
449 } | 481 } |
450 | 482 |
451 void ManagedNetworkConfigurationHandlerImpl::CreateConfigurationFromPolicy( | 483 void ManagedNetworkConfigurationHandlerImpl::CreateConfigurationFromPolicy( |
452 const base::DictionaryValue& shill_properties) { | 484 const base::DictionaryValue& shill_properties) { |
453 network_configuration_handler_->CreateConfiguration( | 485 network_configuration_handler_->CreateConfiguration( |
454 shill_properties, | 486 shill_properties, |
455 base::Bind(&ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied, | 487 base::Bind(&ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied, |
456 weak_ptr_factory_.GetWeakPtr()), | 488 weak_ptr_factory_.GetWeakPtr()), |
457 base::Bind(&LogErrorWithDict, FROM_HERE)); | 489 base::Bind(&LogErrorWithDict, FROM_HERE)); |
458 } | 490 } |
459 | 491 |
| 492 void ManagedNetworkConfigurationHandlerImpl:: |
| 493 UpdateExistingConfigurationWithPropertiesFromPolicy( |
| 494 const base::DictionaryValue& existing_properties, |
| 495 const base::DictionaryValue& new_properties) { |
| 496 base::DictionaryValue shill_properties; |
| 497 |
| 498 std::string profile; |
| 499 existing_properties.GetStringWithoutPathExpansion(shill::kProfileProperty, |
| 500 &profile); |
| 501 if (profile.empty()) { |
| 502 LOG(ERROR) << "Missing profile property."; |
| 503 return; |
| 504 } |
| 505 shill_properties.SetStringWithoutPathExpansion(shill::kProfileProperty, |
| 506 profile); |
| 507 |
| 508 if (!shill_property_util::CopyIdentifyingProperties(existing_properties, |
| 509 &shill_properties)) { |
| 510 LOG(ERROR) << "Missing identifying properties."; |
| 511 } |
| 512 |
| 513 shill_properties.MergeDictionary(&new_properties); |
| 514 |
| 515 network_configuration_handler_->CreateConfiguration( |
| 516 shill_properties, |
| 517 base::Bind(&ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied, |
| 518 weak_ptr_factory_.GetWeakPtr()), |
| 519 base::Bind(&LogErrorWithDict, FROM_HERE)); |
| 520 } |
| 521 |
460 const base::DictionaryValue* | 522 const base::DictionaryValue* |
461 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGUID( | 523 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGUID( |
462 const std::string userhash, | 524 const std::string userhash, |
463 const std::string& guid, | 525 const std::string& guid, |
464 ::onc::ONCSource* onc_source) const { | 526 ::onc::ONCSource* onc_source) const { |
465 *onc_source = ::onc::ONC_SOURCE_NONE; | 527 *onc_source = ::onc::ONC_SOURCE_NONE; |
466 | 528 |
467 if (!userhash.empty()) { | 529 if (!userhash.empty()) { |
468 const GuidToPolicyMap* user_policies = GetPoliciesForUser(userhash); | 530 const Policies* user_policies = GetPoliciesForUser(userhash); |
469 if (user_policies) { | 531 if (user_policies) { |
470 GuidToPolicyMap::const_iterator found = user_policies->find(guid); | 532 const base::DictionaryValue* policy = |
471 if (found != user_policies->end()) { | 533 GetByGUID(user_policies->per_network_config, guid); |
| 534 if (policy) { |
472 *onc_source = ::onc::ONC_SOURCE_USER_POLICY; | 535 *onc_source = ::onc::ONC_SOURCE_USER_POLICY; |
473 return found->second; | 536 return policy; |
474 } | 537 } |
475 } | 538 } |
476 } | 539 } |
477 | 540 |
478 const GuidToPolicyMap* device_policies = GetPoliciesForUser(std::string()); | 541 const Policies* device_policies = GetPoliciesForUser(std::string()); |
479 if (device_policies) { | 542 if (device_policies) { |
480 GuidToPolicyMap::const_iterator found = device_policies->find(guid); | 543 const base::DictionaryValue* policy = |
481 if (found != device_policies->end()) { | 544 GetByGUID(device_policies->per_network_config, guid); |
| 545 if (policy) { |
482 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY; | 546 *onc_source = ::onc::ONC_SOURCE_DEVICE_POLICY; |
483 return found->second; | 547 return policy; |
484 } | 548 } |
485 } | 549 } |
486 | 550 |
487 return NULL; | 551 return NULL; |
488 } | 552 } |
489 | 553 |
490 const base::DictionaryValue* | 554 const base::DictionaryValue* |
491 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGuidAndProfile( | 555 ManagedNetworkConfigurationHandlerImpl::FindPolicyByGuidAndProfile( |
492 const std::string& guid, | 556 const std::string& guid, |
493 const std::string& profile_path) const { | 557 const std::string& profile_path) const { |
494 const NetworkProfile* profile = | 558 const NetworkProfile* profile = |
495 network_profile_handler_->GetProfileForPath(profile_path); | 559 network_profile_handler_->GetProfileForPath(profile_path); |
496 if (!profile) { | 560 if (!profile) { |
497 LOG(ERROR) << "Profile path unknown: " << profile_path; | 561 LOG(ERROR) << "Profile path unknown: " << profile_path; |
498 return NULL; | 562 return NULL; |
499 } | 563 } |
500 | 564 |
501 const GuidToPolicyMap* policies = GetPoliciesForProfile(*profile); | 565 const Policies* policies = GetPoliciesForProfile(*profile); |
502 if (!policies) | 566 if (!policies) |
503 return NULL; | 567 return NULL; |
504 | 568 |
505 GuidToPolicyMap::const_iterator it = policies->find(guid); | 569 return GetByGUID(policies->per_network_config, guid); |
506 if (it == policies->end()) | |
507 return NULL; | |
508 return it->second; | |
509 } | 570 } |
510 | 571 |
511 const ManagedNetworkConfigurationHandlerImpl::GuidToPolicyMap* | 572 const ManagedNetworkConfigurationHandlerImpl::Policies* |
512 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForUser( | 573 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForUser( |
513 const std::string& userhash) const { | 574 const std::string& userhash) const { |
514 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash); | 575 UserToPoliciesMap::const_iterator it = policies_by_user_.find(userhash); |
515 if (it == policies_by_user_.end()) | 576 if (it == policies_by_user_.end()) |
516 return NULL; | 577 return NULL; |
517 return &it->second; | 578 return it->second.get(); |
518 } | 579 } |
519 | 580 |
520 const ManagedNetworkConfigurationHandlerImpl::GuidToPolicyMap* | 581 const ManagedNetworkConfigurationHandlerImpl::Policies* |
521 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForProfile( | 582 ManagedNetworkConfigurationHandlerImpl::GetPoliciesForProfile( |
522 const NetworkProfile& profile) const { | 583 const NetworkProfile& profile) const { |
523 DCHECK(profile.type() != NetworkProfile::TYPE_SHARED || | 584 DCHECK(profile.type() != NetworkProfile::TYPE_SHARED || |
524 profile.userhash.empty()); | 585 profile.userhash.empty()); |
525 return GetPoliciesForUser(profile.userhash); | 586 return GetPoliciesForUser(profile.userhash); |
526 } | 587 } |
527 | 588 |
528 ManagedNetworkConfigurationHandlerImpl::ManagedNetworkConfigurationHandlerImpl() | 589 ManagedNetworkConfigurationHandlerImpl::ManagedNetworkConfigurationHandlerImpl() |
529 : network_state_handler_(NULL), | 590 : network_state_handler_(NULL), |
530 network_profile_handler_(NULL), | 591 network_profile_handler_(NULL), |
531 network_configuration_handler_(NULL), | 592 network_configuration_handler_(NULL), |
532 weak_ptr_factory_(this) {} | 593 weak_ptr_factory_(this) {} |
533 | 594 |
534 ManagedNetworkConfigurationHandlerImpl:: | 595 ManagedNetworkConfigurationHandlerImpl:: |
535 ~ManagedNetworkConfigurationHandlerImpl() { | 596 ~ManagedNetworkConfigurationHandlerImpl() { |
536 network_profile_handler_->RemoveObserver(this); | 597 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 } | 598 } |
542 | 599 |
543 void ManagedNetworkConfigurationHandlerImpl::Init( | 600 void ManagedNetworkConfigurationHandlerImpl::Init( |
544 NetworkStateHandler* network_state_handler, | 601 NetworkStateHandler* network_state_handler, |
545 NetworkProfileHandler* network_profile_handler, | 602 NetworkProfileHandler* network_profile_handler, |
546 NetworkConfigurationHandler* network_configuration_handler) { | 603 NetworkConfigurationHandler* network_configuration_handler) { |
547 network_state_handler_ = network_state_handler; | 604 network_state_handler_ = network_state_handler; |
548 network_profile_handler_ = network_profile_handler; | 605 network_profile_handler_ = network_profile_handler; |
549 network_configuration_handler_ = network_configuration_handler; | 606 network_configuration_handler_ = network_configuration_handler; |
550 network_profile_handler_->AddObserver(this); | 607 network_profile_handler_->AddObserver(this); |
551 } | 608 } |
552 | 609 |
553 void ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied( | 610 void ManagedNetworkConfigurationHandlerImpl::OnPolicyApplied( |
554 const std::string& service_path) { | 611 const std::string& service_path) { |
555 if (service_path.empty()) | 612 if (service_path.empty()) |
556 return; | 613 return; |
557 FOR_EACH_OBSERVER( | 614 FOR_EACH_OBSERVER( |
558 NetworkPolicyObserver, observers_, PolicyApplied(service_path)); | 615 NetworkPolicyObserver, observers_, PolicyApplied(service_path)); |
559 } | 616 } |
560 | 617 |
561 } // namespace chromeos | 618 } // namespace chromeos |
OLD | NEW |