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

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

Issue 6091002: Refactor the windows policy provider to use AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows tests Created 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "chrome/browser/browser_thread.h"
10
11 namespace policy {
12
13 ConfigurationPolicyLoaderWin::ConfigurationPolicyLoaderWin(
14 AsynchronousPolicyProvider::Delegate* delegate,
15 int reload_interval_minutes)
16 : AsynchronousPolicyLoader(delegate, reload_interval_minutes),
17 user_policy_changed_event_(false, false),
18 machine_policy_changed_event_(false, false),
19 user_policy_watcher_failed_(false),
20 machine_policy_watcher_failed_(false) {
21 if (!RegisterGPNotification(user_policy_changed_event_.handle(), false)) {
22 PLOG(WARNING) << "Failed to register user group policy notification";
23 user_policy_watcher_failed_ = true;
24 }
25 if (!RegisterGPNotification(machine_policy_changed_event_.handle(), true)) {
26 PLOG(WARNING) << "Failed to register machine group policy notification.";
27 machine_policy_watcher_failed_ = true;
28 }
29 }
30
31 void ConfigurationPolicyLoaderWin::InitOnFileThread() {
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
33 AsynchronousPolicyLoader::InitOnFileThread();
34 MessageLoop::current()->AddDestructionObserver(this);
35 SetupWatches();
36 }
37
38 void ConfigurationPolicyLoaderWin::StopOnFileThread() {
39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
40 MessageLoop::current()->RemoveDestructionObserver(this);
41 user_policy_watcher_.StopWatching();
42 machine_policy_watcher_.StopWatching();
43 AsynchronousPolicyLoader::StopOnFileThread();
44 }
45
46 void ConfigurationPolicyLoaderWin::SetupWatches() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
48 CancelReloadTask();
49
50 if (!user_policy_watcher_failed_ &&
51 !user_policy_watcher_.GetWatchedObject() &&
52 !user_policy_watcher_.StartWatching(
53 user_policy_changed_event_.handle(), this)) {
54 LOG(WARNING) << "Failed to start watch for user policy change event";
55 user_policy_watcher_failed_ = true;
56 }
57 if (!machine_policy_watcher_failed_ &&
58 !machine_policy_watcher_.GetWatchedObject() &&
59 !machine_policy_watcher_.StartWatching(
60 machine_policy_changed_event_.handle(), this)) {
61 LOG(WARNING) << "Failed to start watch for machine policy change event";
62 machine_policy_watcher_failed_ = true;
63 }
64
65 if (user_policy_watcher_failed_ || machine_policy_watcher_failed_)
66 ScheduleFallbackReloadTask();
67 }
68
69 void ConfigurationPolicyLoaderWin::Reload() {
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
71 AsynchronousPolicyLoader::Reload();
72 SetupWatches();
73 }
74
75 void ConfigurationPolicyLoaderWin::OnObjectSignaled(HANDLE object) {
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
77 DCHECK(object == user_policy_changed_event_.handle() ||
78 object == machine_policy_changed_event_.handle())
79 << "unexpected object signaled policy reload, obj = "
80 << std::showbase << std::hex << object;
81 Reload();
82 }
83
84 void ConfigurationPolicyLoaderWin::
85 WillDestroyCurrentMessageLoop() {
86 CancelReloadTask();
87 MessageLoop::current()->RemoveDestructionObserver(this);
88 }
89
90 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698