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

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

Issue 102493002: Use schemas bundled in extensions to convert policies loaded on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added bug url Created 7 years 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
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 8d89206a399c381c504453f271307e2ae673ff27..bc4deda079d52db6899ba0a6ea0561f5384c4272 100644
--- a/chrome/browser/policy/policy_loader_win.cc
+++ b/chrome/browser/policy/policy_loader_win.cc
@@ -19,7 +19,6 @@
#include "base/basictypes.h"
#include "base/file_util.h"
-#include "base/json/json_reader.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/scoped_native_library.h"
@@ -27,17 +26,15 @@
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
+#include "base/values.h"
#include "chrome/browser/policy/policy_load_status.h"
#include "chrome/browser/policy/preg_parser_win.h"
-#include "components/json_schema/json_schema_constants.h"
#include "components/policy/core/common/policy_bundle.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_namespace.h"
#include "components/policy/core/common/registry_dict_win.h"
#include "components/policy/core/common/schema.h"
-namespace schema = json_schema_constants;
-
namespace policy {
namespace {
@@ -164,32 +161,12 @@ class WinGPOListProvider : public AppliedGPOListProvider {
static base::LazyInstance<WinGPOListProvider> g_win_gpo_list_provider =
LAZY_INSTANCE_INITIALIZER;
-std::string GetSchemaTypeForValueType(base::Value::Type value_type) {
- switch (value_type) {
- case base::Value::TYPE_DICTIONARY:
- return json_schema_constants::kObject;
- case base::Value::TYPE_INTEGER:
- return json_schema_constants::kInteger;
- case base::Value::TYPE_LIST:
- return json_schema_constants::kArray;
- case base::Value::TYPE_BOOLEAN:
- return json_schema_constants::kBoolean;
- case base::Value::TYPE_STRING:
- return json_schema_constants::kString;
- default:
- break;
- }
-
- NOTREACHED() << "Unsupported policy value type " << value_type;
- return json_schema_constants::kNull;
-}
-
// Parses |gpo_dict| according to |schema| and writes the resulting policy
// settings to |policy| for the given |scope| and |level|.
void ParsePolicy(const RegistryDict* gpo_dict,
PolicyLevel level,
PolicyScope scope,
- const base::DictionaryValue* schema,
+ const Schema& schema,
PolicyMap* policy) {
if (!gpo_dict)
return;
@@ -263,9 +240,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;
@@ -326,36 +300,6 @@ scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() {
return bundle.Pass();
}
-void PolicyLoaderWin::BuildChromePolicySchema() {
- // TODO(joaodasilva): use the Schema directly instead of building this
- // DictionaryValue.
- scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue());
- const Schema* chrome_schema =
- schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, ""));
- for (Schema::Iterator it = chrome_schema->GetPropertiesIterator();
- !it.IsAtEnd(); it.Advance()) {
- const std::string schema_type =
- GetSchemaTypeForValueType(it.schema().type());
- scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue());
- entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType,
- schema_type);
-
- if (it.schema().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(it.key(), 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) {
@@ -456,7 +400,9 @@ 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 Schema* chrome_schema =
+ schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, ""));
+ ParsePolicy(gpo_dict, level, scope, *chrome_schema, &policy);
chrome_policy_map->MergeFrom(policy);
}
@@ -491,16 +437,27 @@ void PolicyLoaderWin::Load3rdPartyPolicy(const RegistryDict* gpo_dict,
domain_dict->keys().begin());
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 PolicyNamespace policy_namespace(domain, component->first);
+
+ Schema schema;
+ const Schema* schema_from_map = schema_map()->GetSchema(policy_namespace);
+ if (schema_from_map)
+ schema = *schema_from_map;
+ if (!schema.valid()) {
+ // TODO(joaodasilva): the schema should come from the schema_map(), but
+ // the Legacy Browser Support extension was launched when this loader
+ // used a schema embedded in the registry. Remove this for M35.
+ // http://crbug.com/325349
+ std::string schema_json;
+ const base::Value* value = component->second->GetValue(kKeySchema);
+ if (value && value->GetAsString(&schema_json)) {
+ std::string error;
+ schema = Schema::ParseWithBackwardsCompatibility(
+ schema_json, &error, true);
+ if (!schema.valid()) {
+ LOG(WARNING) << "Invalid schema in the registry for "
+ << name << "/" << component->first << ": " << error;
+ }
}
}
@@ -512,8 +469,7 @@ void PolicyLoaderWin::Load3rdPartyPolicy(const RegistryDict* gpo_dict,
continue;
PolicyMap policy;
- ParsePolicy(policy_dict, kLevels[j].level, scope, schema_dict, &policy);
- PolicyNamespace policy_namespace(domain, component->first);
+ ParsePolicy(policy_dict, kLevels[j].level, scope, schema, &policy);
bundle->Get(policy_namespace).MergeFrom(policy);
}
}

Powered by Google App Engine
This is Rietveld 408576698