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

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

Issue 1824743002: Drop non-user policy in ConfigDirPolicyLoader on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 5 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>
11 #include <string> 11 #include <string>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/files/file_enumerator.h" 15 #include "base/files/file_enumerator.h"
16 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
17 #include "base/json/json_file_value_serializer.h" 17 #include "base/json/json_file_value_serializer.h"
18 #include "base/json/json_reader.h" 18 #include "base/json/json_reader.h"
19 #include "base/logging.h" 19 #include "base/logging.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/stl_util.h" 21 #include "base/stl_util.h"
22 #include "components/policy/core/common/policy_bundle.h" 22 #include "components/policy/core/common/policy_bundle.h"
23 #include "components/policy/core/common/policy_load_status.h" 23 #include "components/policy/core/common/policy_load_status.h"
24 #include "components/policy/core/common/policy_types.h" 24 #include "components/policy/core/common/policy_types.h"
25 #include "policy/policy_constants.h"
25 26
26 namespace policy { 27 namespace policy {
27 28
28 namespace { 29 namespace {
29 30
30 // Subdirectories that contain the mandatory and recommended policies. 31 // Subdirectories that contain the mandatory and recommended policies.
31 const base::FilePath::CharType kMandatoryConfigDir[] = 32 const base::FilePath::CharType kMandatoryConfigDir[] =
32 FILE_PATH_LITERAL("managed"); 33 FILE_PATH_LITERAL("managed");
33 const base::FilePath::CharType kRecommendedConfigDir[] = 34 const base::FilePath::CharType kRecommendedConfigDir[] =
34 FILE_PATH_LITERAL("recommended"); 35 FILE_PATH_LITERAL("recommended");
(...skipping 16 matching lines...) Expand all
51 case base::JSONReader::JSON_UNQUOTED_DICTIONARY_KEY: 52 case base::JSONReader::JSON_UNQUOTED_DICTIONARY_KEY:
52 return POLICY_LOAD_STATUS_PARSE_ERROR; 53 return POLICY_LOAD_STATUS_PARSE_ERROR;
53 case base::JSONReader::JSON_NO_ERROR: 54 case base::JSONReader::JSON_NO_ERROR:
54 NOTREACHED(); 55 NOTREACHED();
55 return POLICY_LOAD_STATUS_STARTED; 56 return POLICY_LOAD_STATUS_STARTED;
56 } 57 }
57 NOTREACHED() << "Invalid status " << status; 58 NOTREACHED() << "Invalid status " << status;
58 return POLICY_LOAD_STATUS_PARSE_ERROR; 59 return POLICY_LOAD_STATUS_PARSE_ERROR;
59 } 60 }
60 61
62 bool IsUserPolicy(const PolicyMap::const_iterator iter) {
63 const PolicyDetails* policy_details = GetChromePolicyDetails(iter->first);
64 if (!policy_details) {
65 LOG(ERROR) << "Ignoring unknown platform policy: " << iter->first;
66 return false;
67 }
68 if (policy_details->is_device_policy) {
69 // Device Policy is only implemented as Cloud Policy (not Platform Policy).
70 LOG(ERROR) << "Ignoring device platform policy: " << iter->first;
71 return false;
72 }
73 return true;
74 }
75
61 } // namespace 76 } // namespace
62 77
63 ConfigDirPolicyLoader::ConfigDirPolicyLoader( 78 ConfigDirPolicyLoader::ConfigDirPolicyLoader(
64 scoped_refptr<base::SequencedTaskRunner> task_runner, 79 scoped_refptr<base::SequencedTaskRunner> task_runner,
65 const base::FilePath& config_dir, 80 const base::FilePath& config_dir,
66 PolicyScope scope) 81 PolicyScope scope)
67 : AsyncPolicyLoader(task_runner), config_dir_(config_dir), scope_(scope) {} 82 : AsyncPolicyLoader(task_runner), config_dir_(config_dir), scope_(scope) {}
68 83
69 ConfigDirPolicyLoader::~ConfigDirPolicyLoader() {} 84 ConfigDirPolicyLoader::~ConfigDirPolicyLoader() {}
70 85
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 179
165 // Detach the "3rdparty" node. 180 // Detach the "3rdparty" node.
166 std::unique_ptr<base::Value> third_party; 181 std::unique_ptr<base::Value> third_party;
167 if (dictionary_value->Remove("3rdparty", &third_party)) 182 if (dictionary_value->Remove("3rdparty", &third_party))
168 Merge3rdPartyPolicy(third_party.get(), level, bundle); 183 Merge3rdPartyPolicy(third_party.get(), level, bundle);
169 184
170 // Add chrome policy. 185 // Add chrome policy.
171 PolicyMap policy_map; 186 PolicyMap policy_map;
172 policy_map.LoadFrom(dictionary_value, level, scope_, 187 policy_map.LoadFrom(dictionary_value, level, scope_,
173 POLICY_SOURCE_PLATFORM); 188 POLICY_SOURCE_PLATFORM);
189 policy_map.EraseNonmatching(base::Bind(&IsUserPolicy));
174 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 190 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
175 .MergeFrom(policy_map); 191 .MergeFrom(policy_map);
176 } 192 }
177 } 193 }
178 194
179 void ConfigDirPolicyLoader::Merge3rdPartyPolicy( 195 void ConfigDirPolicyLoader::Merge3rdPartyPolicy(
180 const base::Value* policies, 196 const base::Value* policies,
181 PolicyLevel level, 197 PolicyLevel level,
182 PolicyBundle* bundle) { 198 PolicyBundle* bundle) {
183 // The first-level entries in |policies| are PolicyDomains. The second-level 199 // The first-level entries in |policies| are PolicyDomains. The second-level
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 243 }
228 } 244 }
229 245
230 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, 246 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path,
231 bool error) { 247 bool error) {
232 if (!error) 248 if (!error)
233 Reload(false); 249 Reload(false);
234 } 250 }
235 251
236 } // namespace policy 252 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698