Chromium Code Reviews| Index: chrome/browser/policy/policy_loader_win.cc |
| diff --git a/chrome/browser/policy/configuration_policy_provider_delegate_win.cc b/chrome/browser/policy/policy_loader_win.cc |
| similarity index 76% |
| rename from chrome/browser/policy/configuration_policy_provider_delegate_win.cc |
| rename to chrome/browser/policy/policy_loader_win.cc |
| index d0ccb0d6e52c2fd54dd2073abfb5cd5cf5c85fc3..4d923cc23b6d9caea7e6dfe59ad06db00d7cf3d8 100644 |
| --- a/chrome/browser/policy/configuration_policy_provider_delegate_win.cc |
| +++ b/chrome/browser/policy/policy_loader_win.cc |
| @@ -2,16 +2,22 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/policy/configuration_policy_provider_delegate_win.h" |
| +#include "chrome/browser/policy/policy_loader_win.h" |
| #include <string> |
| #include <string.h> |
| +#include <userenv.h> |
| + |
| +// userenv.dll is required for RegisterGPNotification(). |
| +#pragma comment(lib, "userenv.lib") |
| + |
| #include "base/basictypes.h" |
| #include "base/json/json_reader.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/string16.h" |
| #include "base/string_number_conversions.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/values.h" |
| @@ -203,18 +209,51 @@ base::Value* ReadDictionaryValue(const string16& name, |
| } // namespace |
| -ConfigurationPolicyProviderDelegateWin::ConfigurationPolicyProviderDelegateWin( |
| - const PolicyDefinitionList* policy_definition_list) |
| - : policy_definition_list_(policy_definition_list) {} |
| +WinPolicyLoader::WinPolicyLoader(const PolicyDefinitionList* policy_list) |
| + : is_initialized_(false), |
| + policy_list_(policy_list), |
| + user_policy_changed_event_(false, false), |
| + machine_policy_changed_event_(false, false), |
| + user_policy_watcher_failed_(false), |
|
Mattias Nissler (ping if slow)
2012/06/04 09:29:41
the failed_ fields are no longer used AFAICS
Joao da Silva
2012/06/06 13:05:24
They're used in SetupWatches() to stop trying to i
|
| + machine_policy_watcher_failed_(false) { |
| + if (!RegisterGPNotification(user_policy_changed_event_.handle(), false)) { |
| + DPLOG(WARNING) << "Failed to register user group policy notification"; |
| + user_policy_watcher_failed_ = true; |
| + } |
| + if (!RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { |
| + DPLOG(WARNING) << "Failed to register machine group policy notification."; |
| + machine_policy_watcher_failed_ = true; |
| + } |
| +} |
| + |
| +WinPolicyLoader::~WinPolicyLoader() { |
| + user_policy_watcher_.StopWatching(); |
| + machine_policy_watcher_.StopWatching(); |
| +} |
| + |
| +// static |
| +AsyncPolicyProvider* WinPolicyLoader::CreateProvider( |
| + const PolicyDefinitionList* policy_list) { |
| + WinPolicyLoader* loader = new WinPolicyLoader(policy_list); |
| + return new AsyncPolicyProvider(policy_list, loader); |
| +} |
| + |
| +void WinPolicyLoader::InitOnFile() { |
| + is_initialized_ = true; |
| + SetupWatches(); |
| +} |
| + |
| +scoped_ptr<PolicyBundle> WinPolicyLoader::Load() { |
| + // Reset the watches BEFORE reading the individual policies to avoid |
| + // missing a change notification. |
| + if (is_initialized_) |
| + SetupWatches(); |
| -scoped_ptr<PolicyBundle> ConfigurationPolicyProviderDelegateWin::Load() { |
| scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| PolicyMap& chrome_policy = bundle->Get(POLICY_DOMAIN_CHROME, std::string()); |
| const PolicyDefinitionList::Entry* current; |
| - for (current = policy_definition_list_->begin; |
| - current != policy_definition_list_->end; |
| - ++current) { |
| + for (current = policy_list_->begin; current != policy_list_->end; ++current) { |
| const string16 name(ASCIIToUTF16(current->name)); |
| PolicyLevel level = POLICY_LEVEL_MANDATORY; |
| PolicyScope scope = POLICY_SCOPE_MACHINE; |
| @@ -252,4 +291,30 @@ scoped_ptr<PolicyBundle> ConfigurationPolicyProviderDelegateWin::Load() { |
| return bundle.Pass(); |
| } |
| +void WinPolicyLoader::SetupWatches() { |
| + DCHECK(is_initialized_); |
| + if (!user_policy_watcher_failed_ && |
| + !user_policy_watcher_.GetWatchedObject() && |
| + !user_policy_watcher_.StartWatching( |
| + user_policy_changed_event_.handle(), this)) { |
| + DLOG(WARNING) << "Failed to start watch for user policy change event"; |
| + user_policy_watcher_failed_ = true; |
| + } |
| + if (!machine_policy_watcher_failed_ && |
| + !machine_policy_watcher_.GetWatchedObject() && |
| + !machine_policy_watcher_.StartWatching( |
| + machine_policy_changed_event_.handle(), this)) { |
| + DLOG(WARNING) << "Failed to start watch for machine policy change event"; |
| + machine_policy_watcher_failed_ = true; |
| + } |
| +} |
| + |
| +void WinPolicyLoader::OnObjectSignaled(HANDLE object) { |
| + DCHECK(object == user_policy_changed_event_.handle() || |
| + object == machine_policy_changed_event_.handle()) |
| + << "unexpected object signaled policy reload, obj = " |
| + << std::showbase << std::hex << object; |
| + Reload(false); |
| +} |
| + |
| } // namespace policy |