Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / policy / core / common / policy_loader_win.h
blob93be1f5fb2c7c3ccaa95b0708413ec55d55c1558
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_WIN_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_WIN_H_
8 #include <windows.h>
9 #include <userenv.h>
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "base/synchronization/waitable_event.h"
17 #include "base/win/object_watcher.h"
18 #include "components/policy/core/common/async_policy_loader.h"
19 #include "components/policy/core/common/policy_types.h"
20 #include "components/policy/policy_export.h"
22 namespace base {
23 class SequencedTaskRunner;
26 namespace policy {
28 class AppliedGPOListProvider;
29 class PolicyLoadStatusSample;
30 class PolicyMap;
31 class RegistryDict;
33 // Interface for mocking out GPO enumeration in tests.
34 class POLICY_EXPORT AppliedGPOListProvider {
35 public:
36 virtual ~AppliedGPOListProvider() {}
37 virtual DWORD GetAppliedGPOList(DWORD flags,
38 LPCTSTR machine_name,
39 PSID sid_user,
40 GUID* extension_guid,
41 PGROUP_POLICY_OBJECT* gpo_list) = 0;
42 virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) = 0;
45 // Loads policies from the Windows registry, and watches for Group Policy
46 // notifications to trigger reloads.
47 class POLICY_EXPORT PolicyLoaderWin
48 : public AsyncPolicyLoader,
49 public base::win::ObjectWatcher::Delegate {
50 public:
51 // The PReg file name used by GPO.
52 static const base::FilePath::CharType kPRegFileName[];
54 // Passing |gpo_provider| equal nullptr forces all reads to go through the
55 // registry. This is undesirable for Chrome (see crbug.com/259236), but
56 // needed for some other use cases (i.e. Chromoting - see crbug.com/460734).
57 PolicyLoaderWin(scoped_refptr<base::SequencedTaskRunner> task_runner,
58 const base::string16& chrome_policy_key,
59 AppliedGPOListProvider* gpo_provider);
60 ~PolicyLoaderWin() override;
62 // Creates a policy loader that uses the Win API to access GPO.
63 static scoped_ptr<PolicyLoaderWin> Create(
64 scoped_refptr<base::SequencedTaskRunner> task_runner,
65 const base::string16& chrome_policy_key);
67 // AsyncPolicyLoader implementation.
68 void InitOnBackgroundThread() override;
69 scoped_ptr<PolicyBundle> Load() override;
71 private:
72 // Reads Chrome Policy from a PReg file at the given path and stores the
73 // result in |policy|.
74 bool ReadPRegFile(const base::FilePath& preg_file,
75 RegistryDict* policy,
76 PolicyLoadStatusSample* status);
78 // Loads and parses GPO policy in |policy_object_list| for scope |scope|. If
79 // successful, stores the result in |policy| and returns true. Returns false
80 // on failure reading the policy, indicating that policy loading should fall
81 // back to reading the registry.
82 bool LoadGPOPolicy(PolicyScope scope,
83 PGROUP_POLICY_OBJECT policy_object_list,
84 RegistryDict* policy,
85 PolicyLoadStatusSample* status);
87 // Queries Windows for applied group policy and writes the result to |policy|.
88 // This is the preferred way to obtain GPO data, there are reports of abuse
89 // of the registry GPO keys by 3rd-party software.
90 bool ReadPolicyFromGPO(PolicyScope scope,
91 RegistryDict* policy,
92 PolicyLoadStatusSample* status);
94 // Parses Chrome policy from |gpo_dict| for the given |scope| and |level| and
95 // merges it into |chrome_policy_map|.
96 void LoadChromePolicy(const RegistryDict* gpo_dict,
97 PolicyLevel level,
98 PolicyScope scope,
99 PolicyMap* chrome_policy_map);
101 // Loads 3rd-party policy from |gpo_dict| and merges it into |bundle|.
102 void Load3rdPartyPolicy(const RegistryDict* gpo_dict,
103 PolicyScope scope,
104 PolicyBundle* bundle);
106 // Installs the watchers for the Group Policy update events.
107 void SetupWatches();
109 // ObjectWatcher::Delegate overrides:
110 void OnObjectSignaled(HANDLE object) override;
112 bool is_initialized_;
113 const base::string16 chrome_policy_key_;
114 class AppliedGPOListProvider* gpo_provider_;
116 base::WaitableEvent user_policy_changed_event_;
117 base::WaitableEvent machine_policy_changed_event_;
118 base::win::ObjectWatcher user_policy_watcher_;
119 base::win::ObjectWatcher machine_policy_watcher_;
120 bool user_policy_watcher_failed_;
121 bool machine_policy_watcher_failed_;
123 DISALLOW_COPY_AND_ASSIGN(PolicyLoaderWin);
126 } // namespace policy
128 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_LOADER_WIN_H_