| 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 "components/policy/core/common/config_dir_policy_loader.h" | 5 #include "components/policy/core/common/config_dir_policy_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/files/file_enumerator.h" | 13 #include "base/files/file_enumerator.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/json/json_file_value_serializer.h" | 15 #include "base/json/json_file_value_serializer.h" |
| 16 #include "base/json/json_reader.h" | 16 #include "base/json/json_reader.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "components/policy/core/common/policy_bundle.h" | 19 #include "components/policy/core/common/policy_bundle.h" |
| 20 #include "components/policy/core/common/policy_load_status.h" | 20 #include "components/policy/core/common/policy_load_status.h" |
| 21 #include "components/policy/core/common/policy_types.h" |
| 21 | 22 |
| 22 namespace policy { | 23 namespace policy { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // Subdirectories that contain the mandatory and recommended policies. | 27 // Subdirectories that contain the mandatory and recommended policies. |
| 27 const base::FilePath::CharType kMandatoryConfigDir[] = | 28 const base::FilePath::CharType kMandatoryConfigDir[] = |
| 28 FILE_PATH_LITERAL("managed"); | 29 FILE_PATH_LITERAL("managed"); |
| 29 const base::FilePath::CharType kRecommendedConfigDir[] = | 30 const base::FilePath::CharType kRecommendedConfigDir[] = |
| 30 FILE_PATH_LITERAL("recommended"); | 31 FILE_PATH_LITERAL("recommended"); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 continue; | 159 continue; |
| 159 } | 160 } |
| 160 | 161 |
| 161 // Detach the "3rdparty" node. | 162 // Detach the "3rdparty" node. |
| 162 scoped_ptr<base::Value> third_party; | 163 scoped_ptr<base::Value> third_party; |
| 163 if (dictionary_value->Remove("3rdparty", &third_party)) | 164 if (dictionary_value->Remove("3rdparty", &third_party)) |
| 164 Merge3rdPartyPolicy(third_party.get(), level, bundle); | 165 Merge3rdPartyPolicy(third_party.get(), level, bundle); |
| 165 | 166 |
| 166 // Add chrome policy. | 167 // Add chrome policy. |
| 167 PolicyMap policy_map; | 168 PolicyMap policy_map; |
| 168 policy_map.LoadFrom(dictionary_value, level, scope_); | 169 policy_map.LoadFrom(dictionary_value, level, scope_, |
| 170 POLICY_SOURCE_PLATFORM); |
| 169 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 171 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 170 .MergeFrom(policy_map); | 172 .MergeFrom(policy_map); |
| 171 } | 173 } |
| 172 } | 174 } |
| 173 | 175 |
| 174 void ConfigDirPolicyLoader::Merge3rdPartyPolicy( | 176 void ConfigDirPolicyLoader::Merge3rdPartyPolicy( |
| 175 const base::Value* policies, | 177 const base::Value* policies, |
| 176 PolicyLevel level, | 178 PolicyLevel level, |
| 177 PolicyBundle* bundle) { | 179 PolicyBundle* bundle) { |
| 178 // The first-level entries in |policies| are PolicyDomains. The second-level | 180 // The first-level entries in |policies| are PolicyDomains. The second-level |
| (...skipping 29 matching lines...) Expand all Loading... |
| 208 for (base::DictionaryValue::Iterator components_it(*components_dictionary); | 210 for (base::DictionaryValue::Iterator components_it(*components_dictionary); |
| 209 !components_it.IsAtEnd(); components_it.Advance()) { | 211 !components_it.IsAtEnd(); components_it.Advance()) { |
| 210 const base::DictionaryValue* policy_dictionary; | 212 const base::DictionaryValue* policy_dictionary; |
| 211 if (!components_it.value().GetAsDictionary(&policy_dictionary)) { | 213 if (!components_it.value().GetAsDictionary(&policy_dictionary)) { |
| 212 LOG(WARNING) << "3rdparty/" << domains_it.key() << "/" | 214 LOG(WARNING) << "3rdparty/" << domains_it.key() << "/" |
| 213 << components_it.key() << " value is not a dictionary!"; | 215 << components_it.key() << " value is not a dictionary!"; |
| 214 continue; | 216 continue; |
| 215 } | 217 } |
| 216 | 218 |
| 217 PolicyMap policy; | 219 PolicyMap policy; |
| 218 policy.LoadFrom(policy_dictionary, level, scope_); | 220 policy.LoadFrom(policy_dictionary, level, scope_, POLICY_SOURCE_PLATFORM); |
| 219 bundle->Get(PolicyNamespace(domain, components_it.key())) | 221 bundle->Get(PolicyNamespace(domain, components_it.key())) |
| 220 .MergeFrom(policy); | 222 .MergeFrom(policy); |
| 221 } | 223 } |
| 222 } | 224 } |
| 223 } | 225 } |
| 224 | 226 |
| 225 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, | 227 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, |
| 226 bool error) { | 228 bool error) { |
| 227 if (!error) | 229 if (!error) |
| 228 Reload(false); | 230 Reload(false); |
| 229 } | 231 } |
| 230 | 232 |
| 231 } // namespace policy | 233 } // namespace policy |
| OLD | NEW |