OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_INVALIDATOR_H_ | 5 #ifndef CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ |
6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ | 6 #define CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ |
7 | 7 |
| 8 #include <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
17 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
18 #include "components/invalidation/public/invalidation.h" | 20 #include "components/invalidation/public/invalidation.h" |
19 #include "components/invalidation/public/invalidation_handler.h" | 21 #include "components/invalidation/public/invalidation_handler.h" |
20 #include "components/policy/core/common/cloud/cloud_policy_core.h" | 22 #include "components/policy/core/common/cloud/cloud_policy_core.h" |
21 #include "components/policy/core/common/cloud/cloud_policy_store.h" | 23 #include "components/policy/core/common/cloud/cloud_policy_store.h" |
22 #include "google/cacheinvalidation/include/types.h" | 24 #include "google/cacheinvalidation/include/types.h" |
23 #include "policy/proto/device_management_backend.pb.h" | 25 #include "policy/proto/device_management_backend.pb.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // |task_runner| is used for scheduling delayed tasks. It must post tasks to | 67 // |task_runner| is used for scheduling delayed tasks. It must post tasks to |
66 // the main policy thread. | 68 // the main policy thread. |
67 // |clock| is used to get the current time. | 69 // |clock| is used to get the current time. |
68 // |highest_handled_invalidation_version| is the highest invalidation version | 70 // |highest_handled_invalidation_version| is the highest invalidation version |
69 // that was handled already before this invalidator was created. | 71 // that was handled already before this invalidator was created. |
70 CloudPolicyInvalidator( | 72 CloudPolicyInvalidator( |
71 enterprise_management::DeviceRegisterRequest::Type type, | 73 enterprise_management::DeviceRegisterRequest::Type type, |
72 CloudPolicyCore* core, | 74 CloudPolicyCore* core, |
73 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 75 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
74 scoped_ptr<base::Clock> clock, | 76 scoped_ptr<base::Clock> clock, |
75 int64 highest_handled_invalidation_version); | 77 int64_t highest_handled_invalidation_version); |
76 ~CloudPolicyInvalidator() override; | 78 ~CloudPolicyInvalidator() override; |
77 | 79 |
78 // Initializes the invalidator. No invalidations will be generated before this | 80 // Initializes the invalidator. No invalidations will be generated before this |
79 // method is called. This method must only be called once. | 81 // method is called. This method must only be called once. |
80 // |invalidation_service| is the invalidation service to use and must remain | 82 // |invalidation_service| is the invalidation service to use and must remain |
81 // valid until Shutdown is called. | 83 // valid until Shutdown is called. |
82 void Initialize(invalidation::InvalidationService* invalidation_service); | 84 void Initialize(invalidation::InvalidationService* invalidation_service); |
83 | 85 |
84 // Shuts down and disables invalidations. It must be called before the object | 86 // Shuts down and disables invalidations. It must be called before the object |
85 // is destroyed. | 87 // is destroyed. |
86 void Shutdown(); | 88 void Shutdown(); |
87 | 89 |
88 // Whether the invalidator currently has the ability to receive invalidations. | 90 // Whether the invalidator currently has the ability to receive invalidations. |
89 bool invalidations_enabled() { | 91 bool invalidations_enabled() { |
90 return invalidations_enabled_; | 92 return invalidations_enabled_; |
91 } | 93 } |
92 | 94 |
93 // The highest invalidation version that was handled already. | 95 // The highest invalidation version that was handled already. |
94 int64 highest_handled_invalidation_version() const { | 96 int64_t highest_handled_invalidation_version() const { |
95 return highest_handled_invalidation_version_; | 97 return highest_handled_invalidation_version_; |
96 } | 98 } |
97 | 99 |
98 invalidation::InvalidationService* invalidation_service_for_test() const { | 100 invalidation::InvalidationService* invalidation_service_for_test() const { |
99 return invalidation_service_; | 101 return invalidation_service_; |
100 } | 102 } |
101 | 103 |
102 // syncer::InvalidationHandler: | 104 // syncer::InvalidationHandler: |
103 void OnInvalidatorStateChange(syncer::InvalidatorState state) override; | 105 void OnInvalidatorStateChange(syncer::InvalidatorState state) override; |
104 void OnIncomingInvalidation( | 106 void OnIncomingInvalidation( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 145 |
144 // Acknowledge the latest invalidation. | 146 // Acknowledge the latest invalidation. |
145 void AcknowledgeInvalidation(); | 147 void AcknowledgeInvalidation(); |
146 | 148 |
147 // Determines if the given policy is different from the policy passed in the | 149 // Determines if the given policy is different from the policy passed in the |
148 // previous call. | 150 // previous call. |
149 bool IsPolicyChanged(const enterprise_management::PolicyData* policy); | 151 bool IsPolicyChanged(const enterprise_management::PolicyData* policy); |
150 | 152 |
151 // Determine if an invalidation has expired. | 153 // Determine if an invalidation has expired. |
152 // |version| is the version of the invalidation, or zero for unknown. | 154 // |version| is the version of the invalidation, or zero for unknown. |
153 bool IsInvalidationExpired(int64 version); | 155 bool IsInvalidationExpired(int64_t version); |
154 | 156 |
155 // Get the kMetricPolicyRefresh histogram metric which should be incremented | 157 // Get the kMetricPolicyRefresh histogram metric which should be incremented |
156 // when a policy is stored. | 158 // when a policy is stored. |
157 int GetPolicyRefreshMetric(bool policy_changed); | 159 int GetPolicyRefreshMetric(bool policy_changed); |
158 | 160 |
159 // Get the kMetricPolicyInvalidations histogram metric which should be | 161 // Get the kMetricPolicyInvalidations histogram metric which should be |
160 // incremented when an invalidation is received. | 162 // incremented when an invalidation is received. |
161 int GetInvalidationMetric(bool is_missing_payload, bool is_expired); | 163 int GetInvalidationMetric(bool is_missing_payload, bool is_expired); |
162 | 164 |
163 // Determine if invalidations have been enabled longer than the grace period. | 165 // Determine if invalidations have been enabled longer than the grace period. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 invalidation::ObjectId object_id_; | 207 invalidation::ObjectId object_id_; |
206 | 208 |
207 // Whether the policy is current invalid. This is set to true when an | 209 // Whether the policy is current invalid. This is set to true when an |
208 // invalidation is received and reset when the policy fetched due to the | 210 // invalidation is received and reset when the policy fetched due to the |
209 // invalidation is stored. | 211 // invalidation is stored. |
210 bool invalid_; | 212 bool invalid_; |
211 | 213 |
212 // The version of the latest invalidation received. This is compared to | 214 // The version of the latest invalidation received. This is compared to |
213 // the invalidation version of policy stored to determine when the | 215 // the invalidation version of policy stored to determine when the |
214 // invalidated policy is up-to-date. | 216 // invalidated policy is up-to-date. |
215 int64 invalidation_version_; | 217 int64_t invalidation_version_; |
216 | 218 |
217 // The number of invalidations with unknown version received. Since such | 219 // The number of invalidations with unknown version received. Since such |
218 // invalidations do not provide a version number, this count is used to set | 220 // invalidations do not provide a version number, this count is used to set |
219 // invalidation_version_ when such invalidations occur. | 221 // invalidation_version_ when such invalidations occur. |
220 int unknown_version_invalidation_count_; | 222 int unknown_version_invalidation_count_; |
221 | 223 |
222 // The highest invalidation version that was handled already. | 224 // The highest invalidation version that was handled already. |
223 int64 highest_handled_invalidation_version_; | 225 int64_t highest_handled_invalidation_version_; |
224 | 226 |
225 // The most up to date invalidation. | 227 // The most up to date invalidation. |
226 scoped_ptr<syncer::Invalidation> invalidation_; | 228 scoped_ptr<syncer::Invalidation> invalidation_; |
227 | 229 |
228 // The maximum random delay, in ms, between receiving an invalidation and | 230 // The maximum random delay, in ms, between receiving an invalidation and |
229 // fetching the new policy. | 231 // fetching the new policy. |
230 int max_fetch_delay_; | 232 int max_fetch_delay_; |
231 | 233 |
232 // The hash value of the current policy. This is used to determine if a new | 234 // The hash value of the current policy. This is used to determine if a new |
233 // policy is different from the current one. | 235 // policy is different from the current one. |
234 uint32 policy_hash_value_; | 236 uint32_t policy_hash_value_; |
235 | 237 |
236 // A thread checker to make sure that callbacks are invoked on the correct | 238 // A thread checker to make sure that callbacks are invoked on the correct |
237 // thread. | 239 // thread. |
238 base::ThreadChecker thread_checker_; | 240 base::ThreadChecker thread_checker_; |
239 | 241 |
240 // WeakPtrFactory used to create callbacks to this object. | 242 // WeakPtrFactory used to create callbacks to this object. |
241 base::WeakPtrFactory<CloudPolicyInvalidator> weak_factory_; | 243 base::WeakPtrFactory<CloudPolicyInvalidator> weak_factory_; |
242 | 244 |
243 DISALLOW_COPY_AND_ASSIGN(CloudPolicyInvalidator); | 245 DISALLOW_COPY_AND_ASSIGN(CloudPolicyInvalidator); |
244 }; | 246 }; |
245 | 247 |
246 } // namespace policy | 248 } // namespace policy |
247 | 249 |
248 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ | 250 #endif // CHROME_BROWSER_POLICY_CLOUD_CLOUD_POLICY_INVALIDATOR_H_ |
OLD | NEW |