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

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

Issue 13619014: Change PolicyLoaderWin to load PReg files if possible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments, add unit tests. Created 7 years, 8 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
Index: chrome/browser/policy/policy_loader_win.h
diff --git a/chrome/browser/policy/policy_loader_win.h b/chrome/browser/policy/policy_loader_win.h
index 4156ffea2950c7a9fd948af3e03bce54c9673400..096e4200025ee13484bbbfd8b3470773b323f79f 100644
--- a/chrome/browser/policy/policy_loader_win.h
+++ b/chrome/browser/policy/policy_loader_win.h
@@ -5,30 +5,90 @@
#ifndef CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_
#define CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_
+#include <userenv.h>
+#include <windows.h>
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
#include "base/synchronization/waitable_event.h"
+#include "base/values.h"
#include "base/win/object_watcher.h"
#include "chrome/browser/policy/async_policy_loader.h"
+#include "chrome/browser/policy/policy_types.h"
+
+namespace base {
+class FilePath;
+}
namespace policy {
-struct PolicyDefinitionList;
+class AppliedGPOListProvider;
class PolicyMap;
+struct PolicyDefinitionList;
+
+// Interface for mocking out GPO enumeration in tests.
+class AppliedGPOListProvider {
+ public:
+ virtual ~AppliedGPOListProvider() {}
+ virtual DWORD GetAppliedGPOList(DWORD flags,
+ LPCTSTR machine_name,
+ PSID sid_user,
+ GUID* extension_guid,
+ PGROUP_POLICY_OBJECT* gpo_list) = 0;
+ virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) = 0;
+};
// Loads policies from the Windows registry, and watches for Group Policy
// notifications to trigger reloads.
class PolicyLoaderWin : public AsyncPolicyLoader,
public base::win::ObjectWatcher::Delegate {
public:
- explicit PolicyLoaderWin(const PolicyDefinitionList* policy_list);
+ explicit PolicyLoaderWin(const PolicyDefinitionList* policy_list,
+ const string16& chrome_policy_key,
+ AppliedGPOListProvider* gpo_provider);
virtual ~PolicyLoaderWin();
+ // Creates a policy loader that uses the Win API to access GPO.
+ static scoped_ptr<PolicyLoaderWin> Create(
+ const PolicyDefinitionList* policy_list);
+
// AsyncPolicyLoader implementation.
virtual void InitOnFile() OVERRIDE;
virtual scoped_ptr<PolicyBundle> Load() OVERRIDE;
private:
- void LoadChromePolicy(PolicyMap* chrome_policies);
- void Load3rdPartyPolicies(PolicyBundle* bundle);
+ // Builds the Chrome policy schema in |chrome_policy_schema_|.
+ void BuildChromePolicySchema();
+
+ // Reads Chrome Policy from a PReg file at the given path and stores the
+ // result in |policy|.
+ bool ReadPRegFile(const base::FilePath& preg_file,
+ base::DictionaryValue* policy);
+
+ // Loads and parses GPO policy in |policy_object_list| for scope |scope|. If
+ // successful, stores the result in |policy| and returns true. Returns false
+ // on failure reading the policy, indicating that policy loading should fall
+ // back to reading the registry.
+ bool LoadGPOPolicy(PolicyScope scope,
+ PGROUP_POLICY_OBJECT policy_object_list,
+ base::DictionaryValue* policy);
+
+ // Queries Windows for applied group policy and writes the result to |policy|.
+ // This is the preferred way to obtain GPO data, there are reports of abuse
+ // of the registry GPO keys by 3rd-party software.
+ bool ReadPolicyFromGPO(PolicyScope scope, base::DictionaryValue* policy);
Joao da Silva 2013/04/10 12:32:12 Seems a bit arbitrary that methods are used to rea
Mattias Nissler (ping if slow) 2013/04/10 13:20:25 It is not entirely arbitrary, the GPO functions ne
+
+ // Parses Chrome policy from |gpo_dict| for the given |scope| and |level| and
+ // merges it into |chrome_policy_map|.
+ void LoadChromePolicy(const base::DictionaryValue* gpo_dict,
+ PolicyLevel level,
+ PolicyScope scope,
+ PolicyMap* chrome_policy_map);
+
+ // Loads 3rd-party policy from |gpo_dict| and merges it into |bundle|.
+ void Load3rdPartyPolicy(const base::DictionaryValue* gpo_dict,
+ PolicyScope scope,
+ PolicyBundle* bundle);
// Installs the watchers for the Group Policy update events.
void SetupWatches();
@@ -38,6 +98,9 @@ class PolicyLoaderWin : public AsyncPolicyLoader,
bool is_initialized_;
const PolicyDefinitionList* policy_list_;
+ const string16 chrome_policy_key_;
+ class AppliedGPOListProvider* gpo_provider_;
+ base::DictionaryValue chrome_policy_schema_;
base::WaitableEvent user_policy_changed_event_;
base::WaitableEvent machine_policy_changed_event_;
@@ -49,23 +112,6 @@ class PolicyLoaderWin : public AsyncPolicyLoader,
DISALLOW_COPY_AND_ASSIGN(PolicyLoaderWin);
};
-// Constants shared with tests.
-namespace registry_constants {
- // Path separator for registry keys.
- extern const wchar_t kPathSep[];
- // Registry key within Chrome's key that contains 3rd party policy.
- extern const wchar_t kThirdParty[];
- // Registry key within an extension's namespace that contains mandatory
- // policy.
- extern const wchar_t kMandatory[];
- // Registry key within an extension's namespace that contains recommended
- // policy.
- extern const wchar_t kRecommended[];
- // Registry key within an extension's namespace that contains the policy
- // schema.
- extern const wchar_t kSchema[];
-} // namespace registry_constants
-
} // namespace policy
#endif // CHROME_BROWSER_POLICY_POLICY_LOADER_WIN_H_

Powered by Google App Engine
This is Rietveld 408576698