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

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

Issue 10491013: Implement the windows policy provider based on the AsyncPolicyLoader. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed comment Created 8 years, 6 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
(Empty)
1 // Copyright (c) 2011 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 #include "chrome/browser/policy/configuration_policy_loader_win.h"
6
7 #include <userenv.h>
8
9 #include "content/public/browser/browser_thread.h"
10
11 // userenv.dll is required for RegisterGPNotification().
12 #pragma comment(lib, "userenv.lib")
13
14 using content::BrowserThread;
15
16 namespace policy {
17
18 ConfigurationPolicyLoaderWin::ConfigurationPolicyLoaderWin(
19 AsynchronousPolicyProvider::Delegate* delegate,
20 int reload_interval_minutes)
21 : AsynchronousPolicyLoader(delegate, reload_interval_minutes),
22 user_policy_changed_event_(false, false),
23 machine_policy_changed_event_(false, false),
24 user_policy_watcher_failed_(false),
25 machine_policy_watcher_failed_(false) {
26 if (!RegisterGPNotification(user_policy_changed_event_.handle(), false)) {
27 PLOG(WARNING) << "Failed to register user group policy notification";
28 user_policy_watcher_failed_ = true;
29 }
30 if (!RegisterGPNotification(machine_policy_changed_event_.handle(), true)) {
31 PLOG(WARNING) << "Failed to register machine group policy notification.";
32 machine_policy_watcher_failed_ = true;
33 }
34 }
35
36 void ConfigurationPolicyLoaderWin::Reload(bool force) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
38 // Reset the watches BEFORE reading the individual policies to avoid
39 // missing a change notification.
40 SetupWatches();
41 AsynchronousPolicyLoader::Reload(force);
42 }
43
44 void ConfigurationPolicyLoaderWin::InitOnFileThread() {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
46 AsynchronousPolicyLoader::InitOnFileThread();
47 SetupWatches();
48 }
49
50 void ConfigurationPolicyLoaderWin::StopOnFileThread() {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
52 user_policy_watcher_.StopWatching();
53 machine_policy_watcher_.StopWatching();
54 AsynchronousPolicyLoader::StopOnFileThread();
55 }
56
57 void ConfigurationPolicyLoaderWin::SetupWatches() {
58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
59 CancelReloadTask();
60
61 if (!user_policy_watcher_failed_ &&
62 !user_policy_watcher_.GetWatchedObject() &&
63 !user_policy_watcher_.StartWatching(
64 user_policy_changed_event_.handle(), this)) {
65 LOG(WARNING) << "Failed to start watch for user policy change event";
66 user_policy_watcher_failed_ = true;
67 }
68 if (!machine_policy_watcher_failed_ &&
69 !machine_policy_watcher_.GetWatchedObject() &&
70 !machine_policy_watcher_.StartWatching(
71 machine_policy_changed_event_.handle(), this)) {
72 LOG(WARNING) << "Failed to start watch for machine policy change event";
73 machine_policy_watcher_failed_ = true;
74 }
75
76 if (user_policy_watcher_failed_ || machine_policy_watcher_failed_)
77 ScheduleFallbackReloadTask();
78 }
79
80 void ConfigurationPolicyLoaderWin::OnObjectSignaled(HANDLE object) {
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
82 DCHECK(object == user_policy_changed_event_.handle() ||
83 object == machine_policy_changed_event_.handle())
84 << "unexpected object signaled policy reload, obj = "
85 << std::showbase << std::hex << object;
86 Reload(false);
87 }
88
89 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698