OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/prefs/pref_member.h" | 12 #include "base/prefs/pref_member.h" |
13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 13 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
14 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 14 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
| 15 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" |
15 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 16 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
16 #include "chrome/browser/policy/configuration_policy_provider.h" | 17 #include "chrome/browser/policy/configuration_policy_provider.h" |
17 | 18 |
| 19 namespace invalidation { |
| 20 class InvalidationService; |
| 21 } |
| 22 |
18 namespace policy { | 23 namespace policy { |
19 | 24 |
20 class PolicyBundle; | 25 class PolicyBundle; |
21 | 26 |
22 // CloudPolicyManager is the main switching central between cloud policy and the | 27 // CloudPolicyManager is the main switching central between cloud policy and the |
23 // upper layers of the policy stack. It wires up a CloudPolicyCore to the | 28 // upper layers of the policy stack. It wires up a CloudPolicyCore to the |
24 // ConfigurationPolicyProvider interface. | 29 // ConfigurationPolicyProvider interface. |
25 // | 30 // |
26 // This class contains the base functionality, there are subclasses that add | 31 // This class contains the base functionality, there are subclasses that add |
27 // functionality specific to user-level and device-level cloud policy, such as | 32 // functionality specific to user-level and device-level cloud policy, such as |
28 // blocking on initial user policy fetch or device enrollment. | 33 // blocking on initial user policy fetch or device enrollment. |
29 class CloudPolicyManager : public ConfigurationPolicyProvider, | 34 class CloudPolicyManager : public ConfigurationPolicyProvider, |
30 public CloudPolicyStore::Observer { | 35 public CloudPolicyStore::Observer, |
| 36 public CloudPolicyInvalidationHandler { |
31 public: | 37 public: |
32 CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, | 38 CloudPolicyManager(const PolicyNamespaceKey& policy_ns_key, |
33 CloudPolicyStore* cloud_policy_store); | 39 CloudPolicyStore* cloud_policy_store); |
34 virtual ~CloudPolicyManager(); | 40 virtual ~CloudPolicyManager(); |
35 | 41 |
36 CloudPolicyCore* core() { return &core_; } | 42 CloudPolicyCore* core() { return &core_; } |
37 const CloudPolicyCore* core() const { return &core_; } | 43 const CloudPolicyCore* core() const { return &core_; } |
38 | 44 |
39 // ConfigurationPolicyProvider: | 45 // ConfigurationPolicyProvider: |
40 virtual void Shutdown() OVERRIDE; | 46 virtual void Shutdown() OVERRIDE; |
41 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; | 47 virtual bool IsInitializationComplete(PolicyDomain domain) const OVERRIDE; |
42 virtual void RefreshPolicies() OVERRIDE; | 48 virtual void RefreshPolicies() OVERRIDE; |
43 | 49 |
44 // CloudPolicyStore::Observer: | 50 // CloudPolicyStore::Observer: |
45 virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE; | 51 virtual void OnStoreLoaded(CloudPolicyStore* cloud_policy_store) OVERRIDE; |
46 virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE; | 52 virtual void OnStoreError(CloudPolicyStore* cloud_policy_store) OVERRIDE; |
47 | 53 |
| 54 // CloudPolicyInvalidationHandler: |
| 55 virtual void InvalidatePolicy() OVERRIDE; |
| 56 virtual void OnInvalidatorStateChanged(bool invalidations_enabled) OVERRIDE; |
| 57 |
48 protected: | 58 protected: |
49 // Check whether fully initialized and if so, publish policy by calling | 59 // Check whether fully initialized and if so, publish policy by calling |
50 // ConfigurationPolicyStore::UpdatePolicy(). | 60 // ConfigurationPolicyStore::UpdatePolicy(). |
51 void CheckAndPublishPolicy(); | 61 void CheckAndPublishPolicy(); |
52 | 62 |
| 63 // Enable policy invalidations to be received by creating the invalidator |
| 64 // object. The refresh scheduler must be started before calling this method. |
| 65 // |service| is the invalidation service to use and must remain valid until |
| 66 // Shutdown or UnregisterInvalidator is called. |
| 67 // |ignore_switch| is intended to allow invalidator creation in unit tests |
| 68 // (ignoring the command line flag normally required to enable invalidation). |
| 69 void CreateInvalidator(invalidation::InvalidationService* service) { |
| 70 CreateInvalidator(service, false /* ignore_switch */); |
| 71 } |
| 72 void CreateInvalidator( |
| 73 invalidation::InvalidationService* service, |
| 74 bool ignore_switch); |
| 75 |
| 76 // Causes the invalidator to unregister with the invalidation service and then |
| 77 // destroys the invalidator. This method should only be called when policy is |
| 78 // no longer applied; it should not be called for normal browser shutdown. |
| 79 // This method has no effect if CreateInvalidator has not been called. |
| 80 void UnregisterInvalidator(); |
| 81 |
53 // Called by CheckAndPublishPolicy() to create a bundle with the current | 82 // Called by CheckAndPublishPolicy() to create a bundle with the current |
54 // policies. | 83 // policies. |
55 virtual scoped_ptr<PolicyBundle> CreatePolicyBundle(); | 84 virtual scoped_ptr<PolicyBundle> CreatePolicyBundle(); |
56 | 85 |
57 // Convenience accessors to core() components. | 86 // Convenience accessors to core() components. |
58 CloudPolicyClient* client() { return core_.client(); } | 87 CloudPolicyClient* client() { return core_.client(); } |
59 const CloudPolicyClient* client() const { return core_.client(); } | 88 const CloudPolicyClient* client() const { return core_.client(); } |
60 CloudPolicyStore* store() { return core_.store(); } | 89 CloudPolicyStore* store() { return core_.store(); } |
61 const CloudPolicyStore* store() const { return core_.store(); } | 90 const CloudPolicyStore* store() const { return core_.store(); } |
62 CloudPolicyService* service() { return core_.service(); } | 91 CloudPolicyService* service() { return core_.service(); } |
63 const CloudPolicyService* service() const { return core_.service(); } | 92 const CloudPolicyService* service() const { return core_.service(); } |
64 | 93 |
65 private: | 94 private: |
66 // Completion handler for policy refresh operations. | 95 // Completion handler for policy refresh operations. |
67 void OnRefreshComplete(bool success); | 96 void OnRefreshComplete(bool success); |
68 | 97 |
69 CloudPolicyCore core_; | 98 CloudPolicyCore core_; |
70 | 99 |
71 // Whether there's a policy refresh operation pending, in which case all | 100 // Whether there's a policy refresh operation pending, in which case all |
72 // policy update notifications are deferred until after it completes. | 101 // policy update notifications are deferred until after it completes. |
73 bool waiting_for_policy_refresh_; | 102 bool waiting_for_policy_refresh_; |
74 | 103 |
| 104 // The policy invalidator, which handles invalidations to the policy. |
| 105 scoped_ptr<CloudPolicyInvalidator> invalidator_; |
| 106 |
75 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager); | 107 DISALLOW_COPY_AND_ASSIGN(CloudPolicyManager); |
76 }; | 108 }; |
77 | 109 |
78 } // namespace policy | 110 } // namespace policy |
79 | 111 |
80 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ | 112 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_MANAGER_H_ |
OLD | NEW |