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

Unified Diff: chrome/browser/policy/policy_loader_win.cc

Issue 22645011: policy: use JSON schema to deserialize entries from Windows registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix 3rd party policy unit tests Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/policy_loader_win.h ('k') | chrome/browser/policy/policy_loader_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/policy/policy_loader_win.cc
diff --git a/chrome/browser/policy/policy_loader_win.cc b/chrome/browser/policy/policy_loader_win.cc
index 451ac0865bea100bded89ff47cc2555f179d2001..9c397090c87b0cc4eda19fa69bd06f7498b8eaea 100644
--- a/chrome/browser/policy/policy_loader_win.cc
+++ b/chrome/browser/policy/policy_loader_win.cc
@@ -22,14 +22,18 @@
#include "base/json/json_reader.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
#include "base/scoped_native_library.h"
#include "base/sequenced_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
+#include "chrome/browser/policy/browser_policy_connector.h"
#include "chrome/browser/policy/policy_bundle.h"
+#include "chrome/browser/policy/policy_domain_descriptor.h"
#include "chrome/browser/policy/policy_load_status.h"
#include "chrome/browser/policy/policy_map.h"
+#include "chrome/browser/policy/policy_service.h"
#include "chrome/browser/policy/preg_parser_win.h"
#include "chrome/browser/policy/registry_dict_win.h"
#include "components/json_schema/json_schema_constants.h"
@@ -188,7 +192,7 @@ std::string GetSchemaTypeForValueType(base::Value::Type value_type) {
void ParsePolicy(const RegistryDict* gpo_dict,
PolicyLevel level,
PolicyScope scope,
- const base::DictionaryValue* schema,
+ const PolicySchema* schema,
PolicyMap* policy) {
if (!gpo_dict)
return;
@@ -257,9 +261,6 @@ scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() {
if (is_initialized_)
SetupWatches();
- if (chrome_policy_schema_.empty())
- BuildChromePolicySchema();
-
// Policy scope and corresponding hive.
static const struct {
PolicyScope scope;
@@ -320,31 +321,6 @@ scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() {
return bundle.Pass();
}
-void PolicyLoaderWin::BuildChromePolicySchema() {
- scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue());
- for (const PolicyDefinitionList::Entry* e = policy_list_->begin;
- e != policy_list_->end; ++e) {
- const std::string schema_type = GetSchemaTypeForValueType(e->value_type);
- scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue());
- entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType,
- schema_type);
-
- if (e->value_type == base::Value::TYPE_LIST) {
- scoped_ptr<base::DictionaryValue> items_schema(
- new base::DictionaryValue());
- items_schema->SetStringWithoutPathExpansion(
- json_schema_constants::kType, json_schema_constants::kString);
- entry_schema->SetWithoutPathExpansion(json_schema_constants::kItems,
- items_schema.release());
- }
- properties->SetWithoutPathExpansion(e->name, entry_schema.release());
- }
- chrome_policy_schema_.SetStringWithoutPathExpansion(
- json_schema_constants::kType, json_schema_constants::kObject);
- chrome_policy_schema_.SetWithoutPathExpansion(
- json_schema_constants::kProperties, properties.release());
-}
-
bool PolicyLoaderWin::ReadPRegFile(const base::FilePath& preg_file,
RegistryDict* policy,
PolicyLoadStatusSample* status) {
@@ -445,10 +421,53 @@ void PolicyLoaderWin::LoadChromePolicy(const RegistryDict* gpo_dict,
PolicyScope scope,
PolicyMap* chrome_policy_map) {
PolicyMap policy;
- ParsePolicy(gpo_dict, level, scope, &chrome_policy_schema_, &policy);
+ const PolicySchema* schema = NULL;
+ scoped_refptr<const PolicyDomainDescriptor> descriptor =
+ get_descriptor(POLICY_DOMAIN_CHROME);
+ if (descriptor)
+ schema = descriptor->get_schema("");
+ ParsePolicy(gpo_dict, level, scope, schema, &policy);
chrome_policy_map->MergeFrom(policy);
}
+const PolicySchema* PolicyLoaderWin::Load3rdPartyPolicySchema(
+ PolicyDomain domain,
+ const std::string& component_key,
+ RegistryDict* component_dict) {
+
+ // Try to find the schema in the domain descriptor, if it exists.
+ scoped_refptr<const PolicyDomainDescriptor> descriptor =
+ get_descriptor(domain);
+ if (descriptor) {
+ const PolicySchema* schema =
+ descriptor->get_schema(domain + "//" + component_key);
+ if (schema)
+ return schema;
+ }
+
+ // Next, look in the registry entry.
+ // TODO(joaodasilva): Remove this for M31. http://crbug.com/240704
+ std::string schema_json;
+ const base::Value* schema_value = component_dict->GetValue(kKeySchema);
+ if (schema_value && schema_value->GetAsString(&schema_json)) {
+ std::string err;
+ PolicySchema* parsed_schema =
+ PolicySchema::Parse(schema_json, &err).release();
+ if (!parsed_schema) {
+ LOG(ERROR) << "Failed to parse 3rd-party policy schema for "
+ << domain << "/" << component_key << ": "
+ << err;
+ return NULL;
+ }
+ // We don't want to own the schema, but we need it around for the
+ // rest of this task to parse the policy value.
+ base::MessageLoop::current()->DeleteSoon(FROM_HERE, parsed_schema);
+ return parsed_schema;
+ }
+
+ return NULL;
+}
+
void PolicyLoaderWin::Load3rdPartyPolicy(const RegistryDict* gpo_dict,
PolicyScope scope,
PolicyBundle* bundle) {
@@ -481,17 +500,8 @@ void PolicyLoaderWin::Load3rdPartyPolicy(const RegistryDict* gpo_dict,
component != domain_dict->keys().end();
++component) {
// Load the schema.
- const base::DictionaryValue* schema_dict = NULL;
- scoped_ptr<base::Value> schema;
- std::string schema_json;
- const base::Value* schema_value = component->second->GetValue(kKeySchema);
- if (schema_value && schema_value->GetAsString(&schema_json)) {
- schema.reset(base::JSONReader::Read(schema_json));
- if (!schema || !schema->GetAsDictionary(&schema_dict)) {
- LOG(WARNING) << "Failed to parse 3rd-part policy schema for "
- << domain << "/" << component->first;
- }
- }
+ const PolicySchema* schema =
+ Load3rdPartyPolicySchema(domain, component->first, component->second);
// Parse policy.
for (size_t j = 0; j < arraysize(kLevels); j++) {
@@ -501,7 +511,7 @@ void PolicyLoaderWin::Load3rdPartyPolicy(const RegistryDict* gpo_dict,
continue;
PolicyMap policy;
- ParsePolicy(policy_dict, kLevels[j].level, scope, schema_dict, &policy);
+ ParsePolicy(policy_dict, kLevels[j].level, scope, schema, &policy);
PolicyNamespace policy_namespace(domain, component->first);
bundle->Get(policy_namespace).MergeFrom(policy);
}
« no previous file with comments | « chrome/browser/policy/policy_loader_win.h ('k') | chrome/browser/policy/policy_loader_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698