| Index: chrome/browser/policy/config_dir_policy_loader.cc
|
| diff --git a/chrome/browser/policy/config_dir_policy_loader.cc b/chrome/browser/policy/config_dir_policy_loader.cc
|
| index 5e6505833105530c1fc74b8835abebf31c341b6d..572a82d4085d6367829daefda32795e57c69570f 100644
|
| --- a/chrome/browser/policy/config_dir_policy_loader.cc
|
| +++ b/chrome/browser/policy/config_dir_policy_loader.cc
|
| @@ -12,10 +12,12 @@
|
| #include "base/bind_helpers.h"
|
| #include "base/file_util.h"
|
| #include "base/json/json_file_value_serializer.h"
|
| +#include "base/json/json_reader.h"
|
| #include "base/logging.h"
|
| #include "base/platform_file.h"
|
| #include "base/stl_util.h"
|
| #include "chrome/browser/policy/policy_bundle.h"
|
| +#include "chrome/browser/policy/policy_load_status.h"
|
|
|
| namespace policy {
|
|
|
| @@ -27,6 +29,31 @@ const base::FilePath::CharType kMandatoryConfigDir[] =
|
| const base::FilePath::CharType kRecommendedConfigDir[] =
|
| FILE_PATH_LITERAL("recommended");
|
|
|
| +PolicyLoadStatus JsonErrorToPolicyLoadStatus(int status) {
|
| + switch (status) {
|
| + case JSONFileValueSerializer::JSON_ACCESS_DENIED:
|
| + case JSONFileValueSerializer::JSON_CANNOT_READ_FILE:
|
| + case JSONFileValueSerializer::JSON_FILE_LOCKED:
|
| + return POLICY_LOAD_STATUS_READ_ERROR;
|
| + case JSONFileValueSerializer::JSON_NO_SUCH_FILE:
|
| + return POLICY_LOAD_STATUS_MISSING;
|
| + case base::JSONReader::JSON_INVALID_ESCAPE:
|
| + case base::JSONReader::JSON_SYNTAX_ERROR:
|
| + case base::JSONReader::JSON_UNEXPECTED_TOKEN:
|
| + case base::JSONReader::JSON_TRAILING_COMMA:
|
| + case base::JSONReader::JSON_TOO_MUCH_NESTING:
|
| + case base::JSONReader::JSON_UNEXPECTED_DATA_AFTER_ROOT:
|
| + case base::JSONReader::JSON_UNSUPPORTED_ENCODING:
|
| + case base::JSONReader::JSON_UNQUOTED_DICTIONARY_KEY:
|
| + return POLICY_LOAD_STATUS_PARSE_ERROR;
|
| + case base::JSONReader::JSON_NO_ERROR:
|
| + NOTREACHED();
|
| + return POLICY_LOAD_STATUS_STARTED;
|
| + }
|
| + NOTREACHED() << "Invalid status " << status;
|
| + return POLICY_LOAD_STATUS_PARSE_ERROR;
|
| +}
|
| +
|
| } // namespace
|
|
|
| ConfigDirPolicyLoader::ConfigDirPolicyLoader(const base::FilePath& config_dir,
|
| @@ -97,6 +124,12 @@ void ConfigDirPolicyLoader::LoadFromPath(const base::FilePath& path,
|
| !config_file_path.empty(); config_file_path = file_enumerator.Next())
|
| files.insert(config_file_path);
|
|
|
| + PolicyLoadStatusSample status;
|
| + if (files.empty()) {
|
| + status.Add(POLICY_LOAD_STATUS_NO_POLICY);
|
| + return;
|
| + }
|
| +
|
| // Start with an empty dictionary and merge the files' contents.
|
| // The files are processed in reverse order because |MergeFrom| gives priority
|
| // to existing keys, but the ConfigDirPolicyProvider gives priority to the
|
| @@ -113,12 +146,14 @@ void ConfigDirPolicyLoader::LoadFromPath(const base::FilePath& path,
|
| if (!value.get()) {
|
| LOG(WARNING) << "Failed to read configuration file "
|
| << config_file_iter->value() << ": " << error_msg;
|
| + status.Add(JsonErrorToPolicyLoadStatus(error_code));
|
| continue;
|
| }
|
| base::DictionaryValue* dictionary_value = NULL;
|
| if (!value->GetAsDictionary(&dictionary_value)) {
|
| LOG(WARNING) << "Expected JSON dictionary in configuration file "
|
| << config_file_iter->value();
|
| + status.Add(POLICY_LOAD_STATUS_PARSE_ERROR);
|
| continue;
|
| }
|
|
|
|
|