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

Side by Side Diff: chrome/browser/policy/policy_loader_win.cc

Issue 10696034: Share JSON schema constants. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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 unified diff | Download patch
OLDNEW
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 "chrome/browser/policy/policy_loader_win.h" 5 #include "chrome/browser/policy/policy_loader_win.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include <string.h> 9 #include <string.h>
10 10
11 #include <userenv.h> 11 #include <userenv.h>
12 12
13 // userenv.dll is required for RegisterGPNotification(). 13 // userenv.dll is required for RegisterGPNotification().
14 #pragma comment(lib, "userenv.lib") 14 #pragma comment(lib, "userenv.lib")
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/string16.h" 20 #include "base/string16.h"
21 #include "base/string_number_conversions.h" 21 #include "base/string_number_conversions.h"
22 #include "base/utf_string_conversions.h" 22 #include "base/utf_string_conversions.h"
23 #include "base/values.h" 23 #include "base/values.h"
24 #include "base/win/registry.h" 24 #include "base/win/registry.h"
25 #include "chrome/browser/policy/policy_bundle.h" 25 #include "chrome/browser/policy/policy_bundle.h"
26 #include "chrome/browser/policy/policy_map.h" 26 #include "chrome/browser/policy/policy_map.h"
27 #include "chrome/common/json_schema_constants.h"
27 #include "policy/policy_constants.h" 28 #include "policy/policy_constants.h"
28 29
29 using base::win::RegKey; 30 using base::win::RegKey;
30 using base::win::RegistryKeyIterator; 31 using base::win::RegistryKeyIterator;
31 using base::win::RegistryValueIterator; 32 using base::win::RegistryValueIterator;
33 using namespace json_schema_constants;
Aaron Boodman 2012/08/10 19:30:23 If you end up sticking with the approach you have:
Joao da Silva 2012/09/05 14:03:29 Just went for this one. It's a bit extra typing bu
32 using namespace policy::registry_constants; 34 using namespace policy::registry_constants;
33 35
34 namespace policy { 36 namespace policy {
35 37
36 namespace registry_constants { 38 namespace registry_constants {
37 const wchar_t kPathSep[] = L"\\"; 39 const wchar_t kPathSep[] = L"\\";
38 const wchar_t kThirdParty[] = L"3rdparty"; 40 const wchar_t kThirdParty[] = L"3rdparty";
39 const wchar_t kMandatory[] = L"policy"; 41 const wchar_t kMandatory[] = L"policy";
40 const wchar_t kRecommended[] = L"recommended"; 42 const wchar_t kRecommended[] = L"recommended";
41 const wchar_t kSchema[] = L"schema"; 43 const wchar_t kSchema[] = L"schema";
42 const char kType[] = "type";
43 const char kProperties[] = "properties";
44 const char kAdditionalProperties[] = "additionalProperties";
45 const char kItems[] = "items";
46 } // namespace registry_constants 44 } // namespace registry_constants
47 45
48 namespace { 46 namespace {
49 47
50 // Map of registry hives to their corresponding policy scope, in decreasing 48 // Map of registry hives to their corresponding policy scope, in decreasing
51 // order of priority. 49 // order of priority.
52 const struct { 50 const struct {
53 HKEY hive; 51 HKEY hive;
54 PolicyScope scope; 52 PolicyScope scope;
55 } kHives[] = { 53 } kHives[] = {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 RegKey key; 215 RegKey key;
218 if (!LoadHighestPriorityKey(string16(), name, &key, level, scope)) 216 if (!LoadHighestPriorityKey(string16(), name, &key, level, scope))
219 return NULL; 217 return NULL;
220 string16 value; 218 string16 value;
221 if (!ReadRegistryString(&key, name, &value)) 219 if (!ReadRegistryString(&key, name, &value))
222 return NULL; 220 return NULL;
223 return base::JSONReader::Read(UTF16ToUTF8(value)); 221 return base::JSONReader::Read(UTF16ToUTF8(value));
224 } 222 }
225 223
226 // Returns the Value type described in |schema|, or |default_type| if not found. 224 // Returns the Value type described in |schema|, or |default_type| if not found.
227 base::Value::Type GetType(const base::DictionaryValue* schema, 225 base::Value::Type GetType(const base::DictionaryValue* schema,
Aaron Boodman 2012/08/10 19:30:23 We already have JSONSchemaValidator::GetJSONSchema
Joao da Silva 2012/09/05 14:03:29 JSONSchemaValidator::GetJSONSchemaType does Value-
Aaron Boodman 2012/09/11 22:32:39 Just add it to JSONSchemaValidator then. I feel li
Joao da Silva 2012/09/12 16:09:39 Done.
228 base::Value::Type default_type) { 226 base::Value::Type default_type) {
229 // JSON-schema types to base::Value::Type mapping. 227 // JSON-schema types to base::Value::Type mapping.
230 static const struct { 228 static const struct {
231 // JSON schema type. 229 // JSON schema type.
232 const char* schema_type; 230 const char* schema_type;
233 // Correspondent value type. 231 // Correspondent value type.
234 base::Value::Type value_type; 232 base::Value::Type value_type;
235 } kSchemaToValueTypeMap[] = { 233 } kSchemaToValueTypeMap[] = {
236 { "array", base::Value::TYPE_LIST }, 234 { "array", base::Value::TYPE_LIST },
237 { "boolean", base::Value::TYPE_BOOLEAN }, 235 { "boolean", base::Value::TYPE_BOOLEAN },
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 678
681 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { 679 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) {
682 DCHECK(object == user_policy_changed_event_.handle() || 680 DCHECK(object == user_policy_changed_event_.handle() ||
683 object == machine_policy_changed_event_.handle()) 681 object == machine_policy_changed_event_.handle())
684 << "unexpected object signaled policy reload, obj = " 682 << "unexpected object signaled policy reload, obj = "
685 << std::showbase << std::hex << object; 683 << std::showbase << std::hex << object;
686 Reload(false); 684 Reload(false);
687 } 685 }
688 686
689 } // namespace policy 687 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698