| OLD | NEW |
| (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 | |
| OLD | NEW |