Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 if (!user_policy_watcher_.GetWatchedObject() && | |
| 52 !user_policy_watcher_.StartWatching( | |
| 53 user_policy_changed_event_.handle(), this)) { | |
|
Mattias Nissler (ping if slow)
2010/12/22 08:45:53
Maybe collapse the ifs into a single one? (also be
danno
2010/12/22 11:02:17
Done.
| |
| 54 LOG(WARNING) << "Failed to start watch for user policy change event"; | |
| 55 user_policy_watcher_failed_ = true; | |
| 56 } | |
| 57 } | |
| 58 if (!machine_policy_watcher_failed_) { | |
| 59 if (!machine_policy_watcher_.GetWatchedObject() && | |
| 60 !machine_policy_watcher_.StartWatching( | |
| 61 machine_policy_changed_event_.handle(), this)) { | |
| 62 LOG(WARNING) << "Failed to start watch for machine policy change event"; | |
| 63 machine_policy_watcher_failed_ = true; | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 if (user_policy_watcher_failed_ || machine_policy_watcher_failed_) { | |
| 68 ScheduleFallbackReloadTask(); | |
| 69 } | |
|
Mattias Nissler (ping if slow)
2010/12/22 08:45:53
Can drop the curlies here.
danno
2010/12/22 11:02:17
Done.
| |
| 70 } | |
| 71 | |
| 72 void ConfigurationPolicyLoaderWin::Reload() { | |
| 73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
| 74 AsynchronousPolicyLoader::Reload(); | |
| 75 SetupWatches(); | |
| 76 } | |
| 77 | |
| 78 void ConfigurationPolicyLoaderWin::OnObjectSignaled(HANDLE object) { | |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
| 80 DCHECK(object == user_policy_changed_event_.handle() || | |
| 81 object == machine_policy_changed_event_.handle()) | |
| 82 << "unexpected object signaled policy reload, obj = " | |
| 83 << std::showbase << std::hex << object; | |
| 84 Reload(); | |
| 85 } | |
| 86 | |
| 87 void ConfigurationPolicyLoaderWin:: | |
| 88 WillDestroyCurrentMessageLoop() { | |
| 89 CancelReloadTask(); | |
| 90 MessageLoop::current()->RemoveDestructionObserver(this); | |
| 91 } | |
| 92 | |
| 93 } // namespace policy | |
| OLD | NEW |