| OLD | NEW |
| 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/onc/onc_merger.h" | 5 #include "chromeos/network/onc/onc_merger.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 // Recurse into nested dictionaries. | 70 // Recurse into nested dictionaries. |
| 71 for (base::DictionaryValue::Iterator it(policy); !it.IsAtEnd(); | 71 for (base::DictionaryValue::Iterator it(policy); !it.IsAtEnd(); |
| 72 it.Advance()) { | 72 it.Advance()) { |
| 73 const base::DictionaryValue* child_policy = NULL; | 73 const base::DictionaryValue* child_policy = NULL; |
| 74 if (it.key() == ::onc::kRecommended || | 74 if (it.key() == ::onc::kRecommended || |
| 75 !it.value().GetAsDictionary(&child_policy)) { | 75 !it.value().GetAsDictionary(&child_policy)) { |
| 76 continue; | 76 continue; |
| 77 } | 77 } |
| 78 | 78 |
| 79 result_editable->SetWithoutPathExpansion( | 79 result_editable->SetWithoutPathExpansion(it.key(), |
| 80 it.key(), GetEditableFlags(*child_policy).release()); | 80 GetEditableFlags(*child_policy)); |
| 81 } | 81 } |
| 82 return result_editable; | 82 return result_editable; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // This is the base class for merging a list of DictionaryValues in | 85 // This is the base class for merging a list of DictionaryValues in |
| 86 // parallel. See MergeDictionaries function. | 86 // parallel. See MergeDictionaries function. |
| 87 class MergeListOfDictionaries { | 87 class MergeListOfDictionaries { |
| 88 public: | 88 public: |
| 89 typedef std::vector<const base::DictionaryValue*> DictPtrs; | 89 typedef std::vector<const base::DictionaryValue*> DictPtrs; |
| 90 | 90 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 it_inner != dicts.end(); ++it_inner) { | 132 it_inner != dicts.end(); ++it_inner) { |
| 133 const base::Value* value = NULL; | 133 const base::Value* value = NULL; |
| 134 if (*it_inner) | 134 if (*it_inner) |
| 135 (*it_inner)->GetWithoutPathExpansion(key, &value); | 135 (*it_inner)->GetWithoutPathExpansion(key, &value); |
| 136 values.push_back(value); | 136 values.push_back(value); |
| 137 } | 137 } |
| 138 merged_value = MergeListOfValues(key, values); | 138 merged_value = MergeListOfValues(key, values); |
| 139 } | 139 } |
| 140 | 140 |
| 141 if (merged_value) | 141 if (merged_value) |
| 142 result->SetWithoutPathExpansion(key, merged_value.release()); | 142 result->SetWithoutPathExpansion(key, std::move(merged_value)); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 return result; | 145 return result; |
| 146 } | 146 } |
| 147 | 147 |
| 148 protected: | 148 protected: |
| 149 // This function is called by MergeDictionaries for each list of values that | 149 // This function is called by MergeDictionaries for each list of values that |
| 150 // are located at the same path in each of the dictionaries. The order of the | 150 // are located at the same path in each of the dictionaries. The order of the |
| 151 // values is the same as of the given dictionaries |dicts|. If a dictionary | 151 // values is the same as of the given dictionaries |dicts|. If a dictionary |
| 152 // doesn't contain a path then it's value is NULL. | 152 // doesn't contain a path then it's value is NULL. |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 408 } |
| 409 LOG(ERROR) << "Field has no effective value: " << key; | 409 LOG(ERROR) << "Field has no effective value: " << key; |
| 410 return nullptr; | 410 return nullptr; |
| 411 } | 411 } |
| 412 | 412 |
| 413 std::unique_ptr<base::DictionaryValue> augmented_value( | 413 std::unique_ptr<base::DictionaryValue> augmented_value( |
| 414 new base::DictionaryValue); | 414 new base::DictionaryValue); |
| 415 | 415 |
| 416 if (values.active_setting) { | 416 if (values.active_setting) { |
| 417 augmented_value->SetWithoutPathExpansion( | 417 augmented_value->SetWithoutPathExpansion( |
| 418 ::onc::kAugmentationActiveSetting, values.active_setting->DeepCopy()); | 418 ::onc::kAugmentationActiveSetting, |
| 419 values.active_setting->CreateDeepCopy()); |
| 419 } | 420 } |
| 420 | 421 |
| 421 if (!which_effective.empty()) { | 422 if (!which_effective.empty()) { |
| 422 augmented_value->SetStringWithoutPathExpansion( | 423 augmented_value->SetStringWithoutPathExpansion( |
| 423 ::onc::kAugmentationEffectiveSetting, which_effective); | 424 ::onc::kAugmentationEffectiveSetting, which_effective); |
| 424 } | 425 } |
| 425 | 426 |
| 426 // Prevent credentials from being forwarded in cleartext to | 427 // Prevent credentials from being forwarded in cleartext to |
| 427 // UI. User/shared credentials are not stored separately, so they cannot | 428 // UI. User/shared credentials are not stored separately, so they cannot |
| 428 // leak here. | 429 // leak here. |
| 429 bool is_credential = onc::FieldIsCredential(*signature_, key); | 430 bool is_credential = onc::FieldIsCredential(*signature_, key); |
| 430 if (!is_credential) { | 431 if (!is_credential) { |
| 431 if (values.user_policy) { | 432 if (values.user_policy) { |
| 432 augmented_value->SetWithoutPathExpansion( | 433 augmented_value->SetWithoutPathExpansion( |
| 433 ::onc::kAugmentationUserPolicy, values.user_policy->DeepCopy()); | 434 ::onc::kAugmentationUserPolicy, |
| 435 values.user_policy->CreateDeepCopy()); |
| 434 } | 436 } |
| 435 if (values.device_policy) { | 437 if (values.device_policy) { |
| 436 augmented_value->SetWithoutPathExpansion( | 438 augmented_value->SetWithoutPathExpansion( |
| 437 ::onc::kAugmentationDevicePolicy, | 439 ::onc::kAugmentationDevicePolicy, |
| 438 values.device_policy->DeepCopy()); | 440 values.device_policy->CreateDeepCopy()); |
| 439 } | 441 } |
| 440 } | 442 } |
| 441 if (values.user_setting) { | 443 if (values.user_setting) { |
| 442 augmented_value->SetWithoutPathExpansion( | 444 augmented_value->SetWithoutPathExpansion( |
| 443 ::onc::kAugmentationUserSetting, values.user_setting->DeepCopy()); | 445 ::onc::kAugmentationUserSetting, |
| 446 values.user_setting->CreateDeepCopy()); |
| 444 } | 447 } |
| 445 if (values.shared_setting) { | 448 if (values.shared_setting) { |
| 446 augmented_value->SetWithoutPathExpansion( | 449 augmented_value->SetWithoutPathExpansion( |
| 447 ::onc::kAugmentationSharedSetting, | 450 ::onc::kAugmentationSharedSetting, |
| 448 values.shared_setting->DeepCopy()); | 451 values.shared_setting->CreateDeepCopy()); |
| 449 } | 452 } |
| 450 if (HasUserPolicy() && values.user_editable) { | 453 if (HasUserPolicy() && values.user_editable) { |
| 451 augmented_value->SetBooleanWithoutPathExpansion( | 454 augmented_value->SetBooleanWithoutPathExpansion( |
| 452 ::onc::kAugmentationUserEditable, true); | 455 ::onc::kAugmentationUserEditable, true); |
| 453 } | 456 } |
| 454 if (HasDevicePolicy() && values.device_editable) { | 457 if (HasDevicePolicy() && values.device_editable) { |
| 455 augmented_value->SetBooleanWithoutPathExpansion( | 458 augmented_value->SetBooleanWithoutPathExpansion( |
| 456 ::onc::kAugmentationDeviceEditable, true); | 459 ::onc::kAugmentationDeviceEditable, true); |
| 457 } | 460 } |
| 458 if (augmented_value->empty()) | 461 if (augmented_value->empty()) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 const base::DictionaryValue* shared_settings, | 509 const base::DictionaryValue* shared_settings, |
| 507 const base::DictionaryValue* active_settings) { | 510 const base::DictionaryValue* active_settings) { |
| 508 MergeToAugmented merger; | 511 MergeToAugmented merger; |
| 509 return merger.MergeDictionaries( | 512 return merger.MergeDictionaries( |
| 510 signature, user_policy, device_policy, user_settings, shared_settings, | 513 signature, user_policy, device_policy, user_settings, shared_settings, |
| 511 active_settings); | 514 active_settings); |
| 512 } | 515 } |
| 513 | 516 |
| 514 } // namespace onc | 517 } // namespace onc |
| 515 } // namespace chromeos | 518 } // namespace chromeos |
| OLD | NEW |