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

Side by Side Diff: chromeos/network/onc/onc_merger.cc

Issue 1556773002: Convert Pass()→std::move() in //chromeos (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « chromeos/network/onc/onc_mapper.cc ('k') | chromeos/network/onc/onc_normalizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 10 #include <vector>
10 11
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chromeos/network/onc/onc_signature.h" 15 #include "chromeos/network/onc/onc_signature.h"
15 #include "components/onc/onc_constants.h" 16 #include "components/onc/onc_constants.h"
16 17
17 namespace chromeos { 18 namespace chromeos {
18 namespace onc { 19 namespace onc {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 it.Advance()) { 71 it.Advance()) {
71 const base::DictionaryValue* child_policy = NULL; 72 const base::DictionaryValue* child_policy = NULL;
72 if (it.key() == ::onc::kRecommended || 73 if (it.key() == ::onc::kRecommended ||
73 !it.value().GetAsDictionary(&child_policy)) { 74 !it.value().GetAsDictionary(&child_policy)) {
74 continue; 75 continue;
75 } 76 }
76 77
77 result_editable->SetWithoutPathExpansion( 78 result_editable->SetWithoutPathExpansion(
78 it.key(), GetEditableFlags(*child_policy).release()); 79 it.key(), GetEditableFlags(*child_policy).release());
79 } 80 }
80 return result_editable.Pass(); 81 return result_editable;
81 } 82 }
82 83
83 // This is the base class for merging a list of DictionaryValues in 84 // This is the base class for merging a list of DictionaryValues in
84 // parallel. See MergeDictionaries function. 85 // parallel. See MergeDictionaries function.
85 class MergeListOfDictionaries { 86 class MergeListOfDictionaries {
86 public: 87 public:
87 typedef std::vector<const base::DictionaryValue*> DictPtrs; 88 typedef std::vector<const base::DictionaryValue*> DictPtrs;
88 89
89 MergeListOfDictionaries() { 90 MergeListOfDictionaries() {
90 } 91 }
(...skipping 25 matching lines...) Expand all
116 DictPtrs nested_dicts; 117 DictPtrs nested_dicts;
117 for (DictPtrs::const_iterator it_inner = dicts.begin(); 118 for (DictPtrs::const_iterator it_inner = dicts.begin();
118 it_inner != dicts.end(); ++it_inner) { 119 it_inner != dicts.end(); ++it_inner) {
119 const base::DictionaryValue* nested_dict = NULL; 120 const base::DictionaryValue* nested_dict = NULL;
120 if (*it_inner) 121 if (*it_inner)
121 (*it_inner)->GetDictionaryWithoutPathExpansion(key, &nested_dict); 122 (*it_inner)->GetDictionaryWithoutPathExpansion(key, &nested_dict);
122 nested_dicts.push_back(nested_dict); 123 nested_dicts.push_back(nested_dict);
123 } 124 }
124 DictionaryPtr merged_dict(MergeNestedDictionaries(key, nested_dicts)); 125 DictionaryPtr merged_dict(MergeNestedDictionaries(key, nested_dicts));
125 if (!merged_dict->empty()) 126 if (!merged_dict->empty())
126 merged_value = merged_dict.Pass(); 127 merged_value = std::move(merged_dict);
127 } else { 128 } else {
128 std::vector<const base::Value*> values; 129 std::vector<const base::Value*> values;
129 for (DictPtrs::const_iterator it_inner = dicts.begin(); 130 for (DictPtrs::const_iterator it_inner = dicts.begin();
130 it_inner != dicts.end(); ++it_inner) { 131 it_inner != dicts.end(); ++it_inner) {
131 const base::Value* value = NULL; 132 const base::Value* value = NULL;
132 if (*it_inner) 133 if (*it_inner)
133 (*it_inner)->GetWithoutPathExpansion(key, &value); 134 (*it_inner)->GetWithoutPathExpansion(key, &value);
134 values.push_back(value); 135 values.push_back(value);
135 } 136 }
136 merged_value = MergeListOfValues(key, values); 137 merged_value = MergeListOfValues(key, values);
137 } 138 }
138 139
139 if (merged_value) 140 if (merged_value)
140 result->SetWithoutPathExpansion(key, merged_value.release()); 141 result->SetWithoutPathExpansion(key, merged_value.release());
141 } 142 }
142 } 143 }
143 return result.Pass(); 144 return result;
144 } 145 }
145 146
146 protected: 147 protected:
147 // This function is called by MergeDictionaries for each list of values that 148 // This function is called by MergeDictionaries for each list of values that
148 // are located at the same path in each of the dictionaries. The order of the 149 // are located at the same path in each of the dictionaries. The order of the
149 // values is the same as of the given dictionaries |dicts|. If a dictionary 150 // values is the same as of the given dictionaries |dicts|. If a dictionary
150 // doesn't contain a path then it's value is NULL. 151 // doesn't contain a path then it's value is NULL.
151 virtual scoped_ptr<base::Value> MergeListOfValues( 152 virtual scoped_ptr<base::Value> MergeListOfValues(
152 const std::string& key, 153 const std::string& key,
153 const std::vector<const base::Value*>& values) = 0; 154 const std::vector<const base::Value*>& values) = 0;
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 MergeToEffective::MergeValues(key, values, &which_effective); 391 MergeToEffective::MergeValues(key, values, &which_effective);
391 392
392 if (IsReadOnlyField(*signature_, key)) { 393 if (IsReadOnlyField(*signature_, key)) {
393 // Don't augment read-only fields (GUID and Type). 394 // Don't augment read-only fields (GUID and Type).
394 if (effective_value) { 395 if (effective_value) {
395 // DCHECK that all provided fields are identical. 396 // DCHECK that all provided fields are identical.
396 DCHECK(AllPresentValuesEqual(values, *effective_value)) 397 DCHECK(AllPresentValuesEqual(values, *effective_value))
397 << "Values do not match: " << key 398 << "Values do not match: " << key
398 << " Effective: " << *effective_value; 399 << " Effective: " << *effective_value;
399 // Return the un-augmented field. 400 // Return the un-augmented field.
400 return effective_value.Pass(); 401 return effective_value;
401 } 402 }
402 if (values.active_setting) { 403 if (values.active_setting) {
403 // Unmanaged networks have assigned (active) values. 404 // Unmanaged networks have assigned (active) values.
404 return make_scoped_ptr(values.active_setting->DeepCopy()); 405 return make_scoped_ptr(values.active_setting->DeepCopy());
405 } 406 }
406 LOG(ERROR) << "Field has no effective value: " << key; 407 LOG(ERROR) << "Field has no effective value: " << key;
407 return nullptr; 408 return nullptr;
408 } 409 }
409 410
410 scoped_ptr<base::DictionaryValue> augmented_value( 411 scoped_ptr<base::DictionaryValue> augmented_value(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 if (HasUserPolicy() && values.user_editable) { 448 if (HasUserPolicy() && values.user_editable) {
448 augmented_value->SetBooleanWithoutPathExpansion( 449 augmented_value->SetBooleanWithoutPathExpansion(
449 ::onc::kAugmentationUserEditable, true); 450 ::onc::kAugmentationUserEditable, true);
450 } 451 }
451 if (HasDevicePolicy() && values.device_editable) { 452 if (HasDevicePolicy() && values.device_editable) {
452 augmented_value->SetBooleanWithoutPathExpansion( 453 augmented_value->SetBooleanWithoutPathExpansion(
453 ::onc::kAugmentationDeviceEditable, true); 454 ::onc::kAugmentationDeviceEditable, true);
454 } 455 }
455 if (augmented_value->empty()) 456 if (augmented_value->empty())
456 augmented_value.reset(); 457 augmented_value.reset();
457 return augmented_value.Pass(); 458 return std::move(augmented_value);
458 } 459 }
459 460
460 // MergeListOfDictionaries override. 461 // MergeListOfDictionaries override.
461 DictionaryPtr MergeNestedDictionaries(const std::string& key, 462 DictionaryPtr MergeNestedDictionaries(const std::string& key,
462 const DictPtrs& dicts) override { 463 const DictPtrs& dicts) override {
463 DictionaryPtr result; 464 DictionaryPtr result;
464 if (signature_) { 465 if (signature_) {
465 const OncValueSignature* enclosing_signature = signature_; 466 const OncValueSignature* enclosing_signature = signature_;
466 signature_ = NULL; 467 signature_ = NULL;
467 468
468 const OncFieldSignature* field = 469 const OncFieldSignature* field =
469 GetFieldSignature(*enclosing_signature, key); 470 GetFieldSignature(*enclosing_signature, key);
470 if (field) 471 if (field)
471 signature_ = field->value_signature; 472 signature_ = field->value_signature;
472 result = MergeToEffective::MergeNestedDictionaries(key, dicts); 473 result = MergeToEffective::MergeNestedDictionaries(key, dicts);
473 474
474 signature_ = enclosing_signature; 475 signature_ = enclosing_signature;
475 } else { 476 } else {
476 result = MergeToEffective::MergeNestedDictionaries(key, dicts); 477 result = MergeToEffective::MergeNestedDictionaries(key, dicts);
477 } 478 }
478 return result.Pass(); 479 return result;
479 } 480 }
480 481
481 private: 482 private:
482 const OncValueSignature* signature_; 483 const OncValueSignature* signature_;
483 DISALLOW_COPY_AND_ASSIGN(MergeToAugmented); 484 DISALLOW_COPY_AND_ASSIGN(MergeToAugmented);
484 }; 485 };
485 486
486 } // namespace 487 } // namespace
487 488
488 DictionaryPtr MergeSettingsAndPoliciesToEffective( 489 DictionaryPtr MergeSettingsAndPoliciesToEffective(
(...skipping 14 matching lines...) Expand all
503 const base::DictionaryValue* shared_settings, 504 const base::DictionaryValue* shared_settings,
504 const base::DictionaryValue* active_settings) { 505 const base::DictionaryValue* active_settings) {
505 MergeToAugmented merger; 506 MergeToAugmented merger;
506 return merger.MergeDictionaries( 507 return merger.MergeDictionaries(
507 signature, user_policy, device_policy, user_settings, shared_settings, 508 signature, user_policy, device_policy, user_settings, shared_settings,
508 active_settings); 509 active_settings);
509 } 510 }
510 511
511 } // namespace onc 512 } // namespace onc
512 } // namespace chromeos 513 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_mapper.cc ('k') | chromeos/network/onc/onc_normalizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698