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

Side by Side Diff: components/policy/core/common/config_dir_policy_loader.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 (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 "components/policy/core/common/config_dir_policy_loader.h" 5 #include "components/policy/core/common/config_dir_policy_loader.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 70
71 void ConfigDirPolicyLoader::InitOnBackgroundThread() { 71 void ConfigDirPolicyLoader::InitOnBackgroundThread() {
72 base::FilePathWatcher::Callback callback = 72 base::FilePathWatcher::Callback callback =
73 base::Bind(&ConfigDirPolicyLoader::OnFileUpdated, base::Unretained(this)); 73 base::Bind(&ConfigDirPolicyLoader::OnFileUpdated, base::Unretained(this));
74 mandatory_watcher_.Watch(config_dir_.Append(kMandatoryConfigDir), false, 74 mandatory_watcher_.Watch(config_dir_.Append(kMandatoryConfigDir), false,
75 callback); 75 callback);
76 recommended_watcher_.Watch(config_dir_.Append(kRecommendedConfigDir), false, 76 recommended_watcher_.Watch(config_dir_.Append(kRecommendedConfigDir), false,
77 callback); 77 callback);
78 } 78 }
79 79
80 scoped_ptr<PolicyBundle> ConfigDirPolicyLoader::Load() { 80 std::unique_ptr<PolicyBundle> ConfigDirPolicyLoader::Load() {
81 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 81 std::unique_ptr<PolicyBundle> bundle(new PolicyBundle());
82 LoadFromPath(config_dir_.Append(kMandatoryConfigDir), 82 LoadFromPath(config_dir_.Append(kMandatoryConfigDir),
83 POLICY_LEVEL_MANDATORY, 83 POLICY_LEVEL_MANDATORY,
84 bundle.get()); 84 bundle.get());
85 LoadFromPath(config_dir_.Append(kRecommendedConfigDir), 85 LoadFromPath(config_dir_.Append(kRecommendedConfigDir),
86 POLICY_LEVEL_RECOMMENDED, 86 POLICY_LEVEL_RECOMMENDED,
87 bundle.get()); 87 bundle.get());
88 return bundle; 88 return bundle;
89 } 89 }
90 90
91 base::Time ConfigDirPolicyLoader::LastModificationTime() { 91 base::Time ConfigDirPolicyLoader::LastModificationTime() {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // The files are processed in reverse order because |MergeFrom| gives priority 139 // The files are processed in reverse order because |MergeFrom| gives priority
140 // to existing keys, but the ConfigDirPolicyProvider gives priority to the 140 // to existing keys, but the ConfigDirPolicyProvider gives priority to the
141 // last file in lexicographic order. 141 // last file in lexicographic order.
142 for (std::set<base::FilePath>::reverse_iterator config_file_iter = 142 for (std::set<base::FilePath>::reverse_iterator config_file_iter =
143 files.rbegin(); config_file_iter != files.rend(); 143 files.rbegin(); config_file_iter != files.rend();
144 ++config_file_iter) { 144 ++config_file_iter) {
145 JSONFileValueDeserializer deserializer(*config_file_iter); 145 JSONFileValueDeserializer deserializer(*config_file_iter);
146 deserializer.set_allow_trailing_comma(true); 146 deserializer.set_allow_trailing_comma(true);
147 int error_code = 0; 147 int error_code = 0;
148 std::string error_msg; 148 std::string error_msg;
149 scoped_ptr<base::Value> value = 149 std::unique_ptr<base::Value> value =
150 deserializer.Deserialize(&error_code, &error_msg); 150 deserializer.Deserialize(&error_code, &error_msg);
151 if (!value.get()) { 151 if (!value.get()) {
152 LOG(WARNING) << "Failed to read configuration file " 152 LOG(WARNING) << "Failed to read configuration file "
153 << config_file_iter->value() << ": " << error_msg; 153 << config_file_iter->value() << ": " << error_msg;
154 status.Add(JsonErrorToPolicyLoadStatus(error_code)); 154 status.Add(JsonErrorToPolicyLoadStatus(error_code));
155 continue; 155 continue;
156 } 156 }
157 base::DictionaryValue* dictionary_value = NULL; 157 base::DictionaryValue* dictionary_value = NULL;
158 if (!value->GetAsDictionary(&dictionary_value)) { 158 if (!value->GetAsDictionary(&dictionary_value)) {
159 LOG(WARNING) << "Expected JSON dictionary in configuration file " 159 LOG(WARNING) << "Expected JSON dictionary in configuration file "
160 << config_file_iter->value(); 160 << config_file_iter->value();
161 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR); 161 status.Add(POLICY_LOAD_STATUS_PARSE_ERROR);
162 continue; 162 continue;
163 } 163 }
164 164
165 // Detach the "3rdparty" node. 165 // Detach the "3rdparty" node.
166 scoped_ptr<base::Value> third_party; 166 std::unique_ptr<base::Value> third_party;
167 if (dictionary_value->Remove("3rdparty", &third_party)) 167 if (dictionary_value->Remove("3rdparty", &third_party))
168 Merge3rdPartyPolicy(third_party.get(), level, bundle); 168 Merge3rdPartyPolicy(third_party.get(), level, bundle);
169 169
170 // Add chrome policy. 170 // Add chrome policy.
171 PolicyMap policy_map; 171 PolicyMap policy_map;
172 policy_map.LoadFrom(dictionary_value, level, scope_, 172 policy_map.LoadFrom(dictionary_value, level, scope_,
173 POLICY_SOURCE_PLATFORM); 173 POLICY_SOURCE_PLATFORM);
174 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 174 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
175 .MergeFrom(policy_map); 175 .MergeFrom(policy_map);
176 } 176 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 } 228 }
229 229
230 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, 230 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path,
231 bool error) { 231 bool error) {
232 if (!error) 232 if (!error)
233 Reload(false); 233 Reload(false);
234 } 234 }
235 235
236 } // namespace policy 236 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698