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_STORE_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 bool is_managed() const { | 67 bool is_managed() const { |
68 return policy_.get() && | 68 return policy_.get() && |
69 policy_->state() == enterprise_management::PolicyData::ACTIVE; | 69 policy_->state() == enterprise_management::PolicyData::ACTIVE; |
70 } | 70 } |
71 Status status() const { return status_; } | 71 Status status() const { return status_; } |
72 CloudPolicyValidatorBase::Status validation_status() const { | 72 CloudPolicyValidatorBase::Status validation_status() const { |
73 return validation_status_; | 73 return validation_status_; |
74 } | 74 } |
75 | 75 |
| 76 // Returns true if the latest policy loaded was different from the previous |
| 77 // policy. |
| 78 bool policy_changed() const { |
| 79 return policy_changed_; |
| 80 } |
| 81 |
76 // Store a new policy blob. Pending load/store operations will be canceled. | 82 // Store a new policy blob. Pending load/store operations will be canceled. |
77 // The store operation may proceed asynchronously and observers are notified | 83 // The store operation may proceed asynchronously and observers are notified |
78 // once the operation finishes. If successful, OnStoreLoaded() will be invoked | 84 // once the operation finishes. If successful, OnStoreLoaded() will be invoked |
79 // on the observers and the updated policy can be read through policy(). | 85 // on the observers and the updated policy can be read through policy(). |
80 // Errors generate OnStoreError() notifications. | 86 // Errors generate OnStoreError() notifications. |
| 87 // |invalidation_version| is the invalidation version of the policy to be |
| 88 // stored. |
| 89 void Store( |
| 90 const enterprise_management::PolicyFetchResponse& policy, |
| 91 int64 invalidation_version); |
| 92 |
81 virtual void Store( | 93 virtual void Store( |
82 const enterprise_management::PolicyFetchResponse& policy) = 0; | 94 const enterprise_management::PolicyFetchResponse& policy) = 0; |
83 | 95 |
84 // Load the current policy blob from persistent storage. Pending load/store | 96 // Load the current policy blob from persistent storage. Pending load/store |
85 // operations will be canceled. This may trigger asynchronous operations. | 97 // operations will be canceled. This may trigger asynchronous operations. |
86 // Upon success, OnStoreLoaded() will be called on the registered observers. | 98 // Upon success, OnStoreLoaded() will be called on the registered observers. |
87 // Otherwise, OnStoreError() reports the reason for failure. | 99 // Otherwise, OnStoreError() reports the reason for failure. |
88 virtual void Load() = 0; | 100 virtual void Load() = 0; |
89 | 101 |
90 // Registers an observer to be notified when policy changes. | 102 // Registers an observer to be notified when policy changes. |
91 void AddObserver(Observer* observer); | 103 void AddObserver(Observer* observer); |
92 | 104 |
93 // Removes the specified observer. | 105 // Removes the specified observer. |
94 void RemoveObserver(Observer* observer); | 106 void RemoveObserver(Observer* observer); |
95 | 107 |
| 108 // The invalidation version of the last policy stored. This value can be read |
| 109 // by observers to determine which version of the policy is now available. |
| 110 int64 invalidation_version() { |
| 111 return invalidation_version_; |
| 112 } |
96 protected: | 113 protected: |
97 // Invokes the corresponding callback on all registered observers. | 114 // Invokes the corresponding callback on all registered observers. |
98 void NotifyStoreLoaded(); | 115 void NotifyStoreLoaded(); |
99 void NotifyStoreError(); | 116 void NotifyStoreError(); |
100 | 117 |
101 // Decoded version of the currently effective policy. | 118 // Decoded version of the currently effective policy. |
102 PolicyMap policy_map_; | 119 PolicyMap policy_map_; |
103 | 120 |
104 // Currently effective policy. | 121 // Currently effective policy. |
105 scoped_ptr<enterprise_management::PolicyData> policy_; | 122 scoped_ptr<enterprise_management::PolicyData> policy_; |
106 | 123 |
107 // Latest status code. | 124 // Latest status code. |
108 Status status_; | 125 Status status_; |
109 | 126 |
110 // Latest validation status. | 127 // Latest validation status. |
111 CloudPolicyValidatorBase::Status validation_status_; | 128 CloudPolicyValidatorBase::Status validation_status_; |
112 | 129 |
| 130 // The invalidation version of the last policy stored. |
| 131 int64 invalidation_version_; |
| 132 |
113 private: | 133 private: |
114 // Whether the store has completed asynchronous initialization, which is | 134 // Whether the store has completed asynchronous initialization, which is |
115 // triggered by calling Load(). | 135 // triggered by calling Load(). |
116 bool is_initialized_; | 136 bool is_initialized_; |
117 | 137 |
| 138 // Whether latest policy loaded was different from the previous policy. |
| 139 bool policy_changed_; |
| 140 |
| 141 // The hash value of the current policy. This is used to determine when the |
| 142 // policy changes. |
| 143 uint32 hash_value_; |
| 144 |
118 ObserverList<Observer, true> observers_; | 145 ObserverList<Observer, true> observers_; |
119 | 146 |
120 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); | 147 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); |
121 }; | 148 }; |
122 | 149 |
123 } // namespace policy | 150 } // namespace policy |
124 | 151 |
125 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ | 152 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ |
OLD | NEW |