Index: chrome/browser/policy/policy_change_watcher.h |
diff --git a/chrome/browser/policy/policy_change_watcher.h b/chrome/browser/policy/policy_change_watcher.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..024023848d920a5dba37363221543f61b758052e |
--- /dev/null |
+++ b/chrome/browser/policy/policy_change_watcher.h |
@@ -0,0 +1,106 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_POLICY_POLICY_CHANGE_WATCHER_H_ |
+#define CHROME_BROWSER_POLICY_POLICY_CHANGE_WATCHER_H_ |
+ |
+#include <string> |
+#include <vector> |
+ |
+#include "base/basictypes.h" |
+#include "base/compiler_specific.h" |
+#include "base/observer_list.h" |
+#include "chrome/browser/policy/policy_bundle.h" |
+#include "chrome/browser/policy/policy_service.h" |
+ |
+class PrefRegistrySimple; |
+class PrefRegistrySyncable; |
+class Profile; |
+ |
+namespace policy { |
+ |
+class PolicyServiceChangeWatcher : public PolicyService::Observer { |
+ public: |
+ PolicyServiceChangeWatcher(PolicyService* policy_service, |
+ const std::string& current_hash); |
+ virtual ~PolicyServiceChangeWatcher(); |
+ |
+ // PolicyService::Observer: |
+ virtual void OnPolicyUpdated(const PolicyNamespace& ns, |
+ const PolicyMap& previous, |
+ const PolicyMap& current) OVERRIDE; |
+ virtual void OnPolicyServiceInitialized(PolicyDomain domain) OVERRIDE; |
+ |
+ protected: |
+ bool is_initialization_complete() const { |
+ return !domains_pending_initialization_; |
+ } |
+ |
+ const std::string& current_hash() const { return current_hash_; }; |
+ |
+ virtual void Init(); |
+ |
+ virtual void OnPolicyChanged() = 0; |
+ |
+ private: |
+ void CheckIfPolicyChanged(const PolicyBundle& bundle); |
+ |
+ int domains_pending_initialization_; |
+ std::string current_hash_; |
+ |
+ PolicyService* policy_service_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PolicyServiceChangeWatcher); |
+}; |
+ |
+class DevicePolicyChangeWatcher : public PolicyServiceChangeWatcher { |
+ public: |
+ class Observer { |
+ public: |
+ virtual void OnDevicePolicyStatusChanged( |
+ const std::vector<std::string>& users_with_changed_device_policy) = 0; |
+ |
+ protected: |
+ virtual ~Observer(); |
+ }; |
+ |
+ DevicePolicyChangeWatcher(); |
+ virtual ~DevicePolicyChangeWatcher(); |
+ |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
+ static void RegisterPrefs(PrefRegistrySimple* registry); |
+ |
+ void AcknowledgePolicyChange(const std::string& username); |
+ |
+ private: |
+ std::vector<std::string> ListUsersWithChangedDevicePolicy() const; |
+ void NotifyDevicePolicyStatusChanged(); |
+ |
+ // PolicyServiceChangeWatcher: |
+ virtual void OnPolicyChanged() OVERRIDE; |
+ |
+ ObserverList<Observer, true> observers_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DevicePolicyChangeWatcher); |
+}; |
+ |
+class UserPolicyChangeWatcher : public PolicyServiceChangeWatcher { |
+ public: |
+ UserPolicyChangeWatcher(Profile* profile); |
+ virtual ~UserPolicyChangeWatcher(); |
+ |
+ static void RegisterUserPrefs(PrefRegistrySyncable* registry); |
+ |
+ private: |
+ // PolicyServiceChangeWatcher: |
+ virtual void OnPolicyChanged() OVERRIDE; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(UserPolicyChangeWatcher); |
+}; |
+ |
+} // namespace policy |
+ |
+#endif // CHROME_BROWSER_POLICY_POLICY_CHANGE_WATCHER_H_ |