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

Side by Side Diff: chrome/browser/group_policy.h

Issue 450037: Adds basic group policy support. Resubmitting r33093 with a new unit test.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/group_policy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // A central repository for definitions relating to Group Policy.
6
7 #ifndef CHROME_BROWSER_GROUP_POLICY_H_
8 #define CHROME_BROWSER_GROUP_POLICY_H_
9
10 #include <windows.h>
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 #include "base/values.h"
14 #include "build/build_config.h"
15
16 // Each policy:
17 // - has a name; this is used to refer to the policy for testing in code.
18 // - has a type; the type of a policy decides what sort of value a policy
19 // lookup returns as well as how the policy handles it when it is
20 // defined both in user and machine policy.
21 // Policy types include:
22 // # Flag; a boolean flag, if either machine or user instance
23 // of the flag is nonzero, then the flag is set. Otherwise,
24 // whether both or either are nonexistent or zero, the flag
25 // is unset.
26 // # Number; a DWORD number.
27 // # String; a character string.
28 // # String List; an unordered list of strings.
29 // - belongs to class; Each policy is either a machine or a user policy
30 // or both.
31 // Policies that belong to the user class are stored under HKCU, while
32 // those of machine class are stored under HKLM. Policies of class both
33 // belong in both places. For such policies, the meaning of
34 // conflicting settings is determined by the type of the policy.
35 // - has a registry key; This is a path from the toplevel key or keys that
36 // the policy class implies.
37 // - has a value name; Depending on the type of the policy, this is the name
38 // of the value or the subkey that contains the policy flag or value.
39 // - has a display name; this is the name displayed to the administrator in
40 // the group policy editor.
41 // - has a help string; this is the help string displayed to the administrator
42 // in the group policy editor.
43
44 namespace group_policy {
45
46 // Get the root registry location of group policy settings.
47 bool GetPolicySettingsRootKey(std::wstring* policy_key);
48
49 // Check if the machine has any group policy settings.
50 bool HasGroupPolicySettings();
51
52 // True if the machine has group policy settings in HKCU.
53 bool HasHkcuSettings();
54
55 // True if the machine has group policy settings in HKLM.
56 bool HasHklmSettings();
57
58 // This specifies how to combine the user and machine keys for the
59 // policy setting; some are only applicable to certain data types
60 // and/or certain storage types. Add more as needed.
61 enum PolicyCombine {
62 POLICYCOMBINE_PREFERMACHINE, // HKLM policy takes priority.
63 POLICYCOMBINE_PREFERUSER, // HKCU policy takes priority.
64 POLICYCOMBINE_CONCATENATE, // Concatenate both policies.
65 POLICYCOMBINE_LOGICALOR, // Logical OR of both keys.
66 };
67
68 // This specifies how the policy setting is stored in the registry.
69 // Add more as needed.
70 enum PolicyStorage {
71 POLICYSTORAGE_SINGLEVALUE, // Policy is a single registry value.
72 POLICYSTORAGE_CONCATSUBKEYS, // Policy is set of subkeys of specified key.
73 };
74
75 // Class that represents a group policy setting. Encapsulates the lookup
76 // from both policy sections of the registry, as well as the method for
77 // combining values in the two policy sections.
78 class SettingBase {
79 public:
80 SettingBase(const wchar_t* regkey,
81 const wchar_t* regvalue,
82 PolicyStorage storage,
83 PolicyCombine combine) : regkey_(regkey),
84 regvalue_(regvalue), storage_(storage),
85 combine_(combine) {
86 // Both parameters are required. Either can be empty (but not both.)
87 DCHECK(regkey != NULL);
88 DCHECK(regvalue != NULL);
89 DCHECK(regkey[0] != L'\0' || regvalue[0] != L'\0');
90
91 // If storage is POLICYSTORAGE_CONCATSUBKEYS, regvalue should be empty.
92 DCHECK((storage != POLICYSTORAGE_CONCATSUBKEYS) ||
93 regvalue[0] == L'\0');
94 }
95
96 // Returns whether this setting is controlled by group policy;
97 // indicates whether this value is set somewhere in the registry.
98 bool IsPolicyControlled() const;
99
100 protected:
101 // These accessors are protected and then individually exposed in a
102 // templated base class. That lets the compiler enforce that the code
103 // using a policy is using the appropriate data type.
104 HRESULT GetSetting(std::wstring* value, bool* found) const;
105 HRESULT GetSetting(ListValue* list, bool* found) const;
106 HRESULT GetSetting(DWORD* value, bool* found) const;
107 HRESULT GetSetting(bool* value, bool* found) const;
108 const wchar_t* regkey_;
109 const wchar_t* regvalue_;
110
111 private:
112 // Private helper accessors for pulling individual registry keys
113 HRESULT GetSettingFromTree(HKEY tree, std::wstring* value, bool* found) const;
114 HRESULT GetSettingFromTree(HKEY tree, ListValue* value, bool* found) const;
115 HRESULT GetSettingFromTree(HKEY tree, DWORD* value, bool* found) const;
116 HRESULT GetSettingFromTree(HKEY tree, bool* value, bool* found) const;
117
118 PolicyStorage storage_;
119 PolicyCombine combine_;
120 };
121
122 // Templated class to provide type-safe access to policy setting.
123 template <typename T>
124 class Setting : public SettingBase {
125 public:
126 Setting(const wchar_t* regkey,
127 const wchar_t* regvalue,
128 PolicyStorage storage,
129 PolicyCombine combine) :
130 SettingBase(regkey, regvalue, storage, combine) {
131 }
132
133 HRESULT GetSetting(T* value, bool* found) const {
134 DCHECK(found);
135 DCHECK(value);
136 DCHECK(regvalue_ != NULL && regkey_ != NULL) <<
137 "Setting not initialized - don't call at static init time!";
138
139 *found = false;
140
141 if (!HasGroupPolicySettings())
142 return S_OK;
143
144 return SettingBase::GetSetting(value, found);
145 }
146 };
147
148 // Is option set, default is 'no'.
149 bool IsBoolOptionSet(const Setting<bool>& setting);
150
151 // Helper function for appending all of one ListValue to another.
152 void AppendAll(ListValue* target, ListValue* source);
153
154 } // namespace
155
156 #endif // CHROME_BROWSER_GROUP_POLICY_H_
157
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/group_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698