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

Side by Side Diff: components/policy/core/common/policy_map.cc

Issue 1902633006: Convert //components/policy from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and use namespace alias Created 4 years, 8 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 "components/policy/core/common/policy_map.h" 5 #include "components/policy/core/common/policy_map.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/ptr_util.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 12
12 namespace policy { 13 namespace policy {
13 14
14 PolicyMap::Entry::Entry() 15 PolicyMap::Entry::Entry()
15 : level(POLICY_LEVEL_RECOMMENDED), 16 : level(POLICY_LEVEL_RECOMMENDED),
16 scope(POLICY_SCOPE_USER), 17 scope(POLICY_SCOPE_USER),
17 value(NULL), 18 value(NULL),
18 external_data_fetcher(NULL) {} 19 external_data_fetcher(NULL) {}
19 20
20 void PolicyMap::Entry::DeleteOwnedMembers() { 21 void PolicyMap::Entry::DeleteOwnedMembers() {
21 delete value; 22 delete value;
22 value = NULL; 23 value = NULL;
23 delete external_data_fetcher; 24 delete external_data_fetcher;
24 external_data_fetcher = NULL; 25 external_data_fetcher = NULL;
25 } 26 }
26 27
27 scoped_ptr<PolicyMap::Entry> PolicyMap::Entry::DeepCopy() const { 28 std::unique_ptr<PolicyMap::Entry> PolicyMap::Entry::DeepCopy() const {
28 scoped_ptr<Entry> copy(new Entry); 29 std::unique_ptr<Entry> copy(new Entry);
29 copy->level = level; 30 copy->level = level;
30 copy->scope = scope; 31 copy->scope = scope;
31 copy->source = source; 32 copy->source = source;
32 if (value) 33 if (value)
33 copy->value = value->DeepCopy(); 34 copy->value = value->DeepCopy();
34 if (external_data_fetcher) { 35 if (external_data_fetcher) {
35 copy->external_data_fetcher = 36 copy->external_data_fetcher =
36 new ExternalDataFetcher(*external_data_fetcher); 37 new ExternalDataFetcher(*external_data_fetcher);
37 } 38 }
38 return copy; 39 return copy;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 for (const_iterator it = other.begin(); it != other.end(); ++it) { 106 for (const_iterator it = other.begin(); it != other.end(); ++it) {
106 const Entry& entry = it->second; 107 const Entry& entry = it->second;
107 Set(it->first, entry.level, entry.scope, entry.source, 108 Set(it->first, entry.level, entry.scope, entry.source,
108 entry.value->DeepCopy(), 109 entry.value->DeepCopy(),
109 entry.external_data_fetcher 110 entry.external_data_fetcher
110 ? new ExternalDataFetcher(*entry.external_data_fetcher) 111 ? new ExternalDataFetcher(*entry.external_data_fetcher)
111 : nullptr); 112 : nullptr);
112 } 113 }
113 } 114 }
114 115
115 scoped_ptr<PolicyMap> PolicyMap::DeepCopy() const { 116 std::unique_ptr<PolicyMap> PolicyMap::DeepCopy() const {
116 PolicyMap* copy = new PolicyMap(); 117 PolicyMap* copy = new PolicyMap();
117 copy->CopyFrom(*this); 118 copy->CopyFrom(*this);
118 return make_scoped_ptr(copy); 119 return base::WrapUnique(copy);
119 } 120 }
120 121
121 void PolicyMap::MergeFrom(const PolicyMap& other) { 122 void PolicyMap::MergeFrom(const PolicyMap& other) {
122 for (const_iterator it = other.begin(); it != other.end(); ++it) { 123 for (const_iterator it = other.begin(); it != other.end(); ++it) {
123 const Entry* entry = Get(it->first); 124 const Entry* entry = Get(it->first);
124 if (!entry || it->second.has_higher_priority_than(*entry)) { 125 if (!entry || it->second.has_higher_priority_than(*entry)) {
125 Set(it->first, it->second.level, it->second.scope, it->second.source, 126 Set(it->first, it->second.level, it->second.scope, it->second.source,
126 it->second.value->DeepCopy(), 127 it->second.value->DeepCopy(),
127 it->second.external_data_fetcher 128 it->second.external_data_fetcher
128 ? new ExternalDataFetcher( 129 ? new ExternalDataFetcher(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 map_.clear(); 211 map_.clear();
211 } 212 }
212 213
213 // static 214 // static
214 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a, 215 bool PolicyMap::MapEntryEquals(const PolicyMap::PolicyMapType::value_type& a,
215 const PolicyMap::PolicyMapType::value_type& b) { 216 const PolicyMap::PolicyMapType::value_type& b) {
216 return a.first == b.first && a.second.Equals(b.second); 217 return a.first == b.first && a.second.Equals(b.second);
217 } 218 }
218 219
219 } // namespace policy 220 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_map.h ('k') | components/policy/core/common/policy_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698