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 { | |
Mattias Nissler (ping if slow)
2013/08/28 14:20:40
AFAICS, the only user of this is CloudPolicyInvali
Steve Condie
2013/09/07 01:11:20
Opened bug 286613 to track refactoring the policy
| |
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 } | |
113 | |
96 protected: | 114 protected: |
97 // Invokes the corresponding callback on all registered observers. | 115 // Invokes the corresponding callback on all registered observers. |
98 void NotifyStoreLoaded(); | 116 void NotifyStoreLoaded(); |
99 void NotifyStoreError(); | 117 void NotifyStoreError(); |
100 | 118 |
101 // Decoded version of the currently effective policy. | 119 // Decoded version of the currently effective policy. |
102 PolicyMap policy_map_; | 120 PolicyMap policy_map_; |
103 | 121 |
104 // Currently effective policy. | 122 // Currently effective policy. |
105 scoped_ptr<enterprise_management::PolicyData> policy_; | 123 scoped_ptr<enterprise_management::PolicyData> policy_; |
106 | 124 |
107 // Latest status code. | 125 // Latest status code. |
108 Status status_; | 126 Status status_; |
109 | 127 |
110 // Latest validation status. | 128 // Latest validation status. |
111 CloudPolicyValidatorBase::Status validation_status_; | 129 CloudPolicyValidatorBase::Status validation_status_; |
112 | 130 |
131 // The invalidation version of the last policy stored. | |
132 int64 invalidation_version_; | |
133 | |
113 private: | 134 private: |
114 // Whether the store has completed asynchronous initialization, which is | 135 // Whether the store has completed asynchronous initialization, which is |
115 // triggered by calling Load(). | 136 // triggered by calling Load(). |
116 bool is_initialized_; | 137 bool is_initialized_; |
117 | 138 |
139 // Whether latest policy loaded was different from the previous policy. | |
140 bool policy_changed_; | |
141 | |
142 // The hash value of the current policy. This is used to determine when the | |
143 // policy changes. | |
144 uint32 hash_value_; | |
145 | |
118 ObserverList<Observer, true> observers_; | 146 ObserverList<Observer, true> observers_; |
119 | 147 |
120 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); | 148 DISALLOW_COPY_AND_ASSIGN(CloudPolicyStore); |
121 }; | 149 }; |
122 | 150 |
123 } // namespace policy | 151 } // namespace policy |
124 | 152 |
125 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ | 153 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_STORE_H_ |
OLD | NEW |