| 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Subdirectories that contain the mandatory and recommended policies. | 26 // Subdirectories that contain the mandatory and recommended policies. |
| 27 const base::FilePath::CharType kMandatoryConfigDir[] = | 27 const base::FilePath::CharType kMandatoryConfigDir[] = |
| 28 FILE_PATH_LITERAL("managed"); | 28 FILE_PATH_LITERAL("managed"); |
| 29 const base::FilePath::CharType kRecommendedConfigDir[] = | 29 const base::FilePath::CharType kRecommendedConfigDir[] = |
| 30 FILE_PATH_LITERAL("recommended"); | 30 FILE_PATH_LITERAL("recommended"); |
| 31 | 31 |
| 32 PolicyLoadStatus JsonErrorToPolicyLoadStatus(int status) { | 32 PolicyLoadStatus JsonErrorToPolicyLoadStatus(int status) { |
| 33 switch (status) { | 33 switch (status) { |
| 34 case JSONFileValueSerializer::JSON_ACCESS_DENIED: | 34 case JSONFileValueDeserializer::JSON_ACCESS_DENIED: |
| 35 case JSONFileValueSerializer::JSON_CANNOT_READ_FILE: | 35 case JSONFileValueDeserializer::JSON_CANNOT_READ_FILE: |
| 36 case JSONFileValueSerializer::JSON_FILE_LOCKED: | 36 case JSONFileValueDeserializer::JSON_FILE_LOCKED: |
| 37 return POLICY_LOAD_STATUS_READ_ERROR; | 37 return POLICY_LOAD_STATUS_READ_ERROR; |
| 38 case JSONFileValueSerializer::JSON_NO_SUCH_FILE: | 38 case JSONFileValueDeserializer::JSON_NO_SUCH_FILE: |
| 39 return POLICY_LOAD_STATUS_MISSING; | 39 return POLICY_LOAD_STATUS_MISSING; |
| 40 case base::JSONReader::JSON_INVALID_ESCAPE: | 40 case base::JSONReader::JSON_INVALID_ESCAPE: |
| 41 case base::JSONReader::JSON_SYNTAX_ERROR: | 41 case base::JSONReader::JSON_SYNTAX_ERROR: |
| 42 case base::JSONReader::JSON_UNEXPECTED_TOKEN: | 42 case base::JSONReader::JSON_UNEXPECTED_TOKEN: |
| 43 case base::JSONReader::JSON_TRAILING_COMMA: | 43 case base::JSONReader::JSON_TRAILING_COMMA: |
| 44 case base::JSONReader::JSON_TOO_MUCH_NESTING: | 44 case base::JSONReader::JSON_TOO_MUCH_NESTING: |
| 45 case base::JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT: | 45 case base::JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT: |
| 46 case base::JSONReader::JSON_UNSUPPORTED_ENCODING: | 46 case base::JSONReader::JSON_UNSUPPORTED_ENCODING: |
| 47 case base::JSONReader::JSON_UNQUOTED_DICTIONARY_KEY: | 47 case base::JSONReader::JSON_UNQUOTED_DICTIONARY_KEY: |
| 48 return POLICY_LOAD_STATUS_PARSE_ERROR; | 48 return POLICY_LOAD_STATUS_PARSE_ERROR; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Start with an empty dictionary and merge the files' contents. | 134 // Start with an empty dictionary and merge the files' contents. |
| 135 // The files are processed in reverse order because |MergeFrom| gives priority | 135 // The files are processed in reverse order because |MergeFrom| gives priority |
| 136 // to existing keys, but the ConfigDirPolicyProvider gives priority to the | 136 // to existing keys, but the ConfigDirPolicyProvider gives priority to the |
| 137 // last file in lexicographic order. | 137 // last file in lexicographic order. |
| 138 for (std::set<base::FilePath>::reverse_iterator config_file_iter = | 138 for (std::set<base::FilePath>::reverse_iterator config_file_iter = |
| 139 files.rbegin(); config_file_iter != files.rend(); | 139 files.rbegin(); config_file_iter != files.rend(); |
| 140 ++config_file_iter) { | 140 ++config_file_iter) { |
| 141 JSONFileValueSerializer deserializer(*config_file_iter); | 141 JSONFileValueDeserializer deserializer(*config_file_iter); |
| 142 deserializer.set_allow_trailing_comma(true); | 142 deserializer.set_allow_trailing_comma(true); |
| 143 int error_code = 0; | 143 int error_code = 0; |
| 144 std::string error_msg; | 144 std::string error_msg; |
| 145 scoped_ptr<base::Value> value( | 145 scoped_ptr<base::Value> value( |
| 146 deserializer.Deserialize(&error_code, &error_msg)); | 146 deserializer.Deserialize(&error_code, &error_msg)); |
| 147 if (!value.get()) { | 147 if (!value.get()) { |
| 148 LOG(WARNING) << "Failed to read configuration file " | 148 LOG(WARNING) << "Failed to read configuration file " |
| 149 << config_file_iter->value() << ": " << error_msg; | 149 << config_file_iter->value() << ": " << error_msg; |
| 150 status.Add(JsonErrorToPolicyLoadStatus(error_code)); | 150 status.Add(JsonErrorToPolicyLoadStatus(error_code)); |
| 151 continue; | 151 continue; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, | 225 void ConfigDirPolicyLoader::OnFileUpdated(const base::FilePath& path, |
| 226 bool error) { | 226 bool error) { |
| 227 if (!error) | 227 if (!error) |
| 228 Reload(false); | 228 Reload(false); |
| 229 } | 229 } |
| 230 | 230 |
| 231 } // namespace policy | 231 } // namespace policy |
| OLD | NEW |