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

Unified Diff: chrome/browser/policy/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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/policy/policy_loader_win.h ('k') | chrome/browser/policy/policy_loader_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 77%
rename from chrome/browser/policy/configuration_policy_provider_delegate_win.cc
rename to chrome/browser/policy/policy_loader_win.cc
index d0ccb0d6e52c2fd54dd2073abfb5cd5cf5c85fc3..c1f1351d1dd9e4f70e46baf4548bccfe5905fb28 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,44 @@ base::Value* ReadDictionaryValue(const string16& name,
} // namespace
-ConfigurationPolicyProviderDelegateWin::ConfigurationPolicyProviderDelegateWin(
- const PolicyDefinitionList* policy_definition_list)
- : policy_definition_list_(policy_definition_list) {}
+PolicyLoaderWin::PolicyLoaderWin(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),
+ 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;
+ }
+}
+
+PolicyLoaderWin::~PolicyLoaderWin() {
+ user_policy_watcher_.StopWatching();
+ machine_policy_watcher_.StopWatching();
+}
+
+void PolicyLoaderWin::InitOnFile() {
+ is_initialized_ = true;
+ SetupWatches();
+}
+
+scoped_ptr<PolicyBundle> PolicyLoaderWin::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 +284,30 @@ scoped_ptr<PolicyBundle> ConfigurationPolicyProviderDelegateWin::Load() {
return bundle.Pass();
}
+void PolicyLoaderWin::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 PolicyLoaderWin::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
« no previous file with comments | « chrome/browser/policy/policy_loader_win.h ('k') | chrome/browser/policy/policy_loader_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698