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 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" | 5 #include "chrome/browser/policy/cloud/cloud_policy_invalidator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/hash.h" | 8 #include "base/hash.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 const int CloudPolicyInvalidator::kMaxFetchDelayMin = 1000; | 27 const int CloudPolicyInvalidator::kMaxFetchDelayMin = 1000; |
28 const int CloudPolicyInvalidator::kMaxFetchDelayMax = 300000; | 28 const int CloudPolicyInvalidator::kMaxFetchDelayMax = 300000; |
29 const int CloudPolicyInvalidator::kInvalidationGracePeriod = 10; | 29 const int CloudPolicyInvalidator::kInvalidationGracePeriod = 10; |
30 const int CloudPolicyInvalidator::kUnknownVersionIgnorePeriod = 30; | 30 const int CloudPolicyInvalidator::kUnknownVersionIgnorePeriod = 30; |
31 const int CloudPolicyInvalidator::kMaxInvalidationTimeDelta = 300; | 31 const int CloudPolicyInvalidator::kMaxInvalidationTimeDelta = 300; |
32 | 32 |
33 CloudPolicyInvalidator::CloudPolicyInvalidator( | 33 CloudPolicyInvalidator::CloudPolicyInvalidator( |
34 enterprise_management::DeviceRegisterRequest::Type type, | 34 enterprise_management::DeviceRegisterRequest::Type type, |
35 CloudPolicyCore* core, | 35 CloudPolicyCore* core, |
36 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 36 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
37 scoped_ptr<base::Clock> clock) | 37 scoped_ptr<base::Clock> clock, |
| 38 int64 highest_handled_invalidation_version) |
38 : state_(UNINITIALIZED), | 39 : state_(UNINITIALIZED), |
39 type_(type), | 40 type_(type), |
40 core_(core), | 41 core_(core), |
41 task_runner_(task_runner), | 42 task_runner_(task_runner), |
42 clock_(clock.Pass()), | 43 clock_(clock.Pass()), |
43 invalidation_service_(NULL), | 44 invalidation_service_(NULL), |
44 invalidations_enabled_(false), | 45 invalidations_enabled_(false), |
45 invalidation_service_enabled_(false), | 46 invalidation_service_enabled_(false), |
46 is_registered_(false), | 47 is_registered_(false), |
47 invalid_(false), | 48 invalid_(false), |
48 invalidation_version_(0), | 49 invalidation_version_(0), |
49 unknown_version_invalidation_count_(0), | 50 unknown_version_invalidation_count_(0), |
| 51 highest_handled_invalidation_version_( |
| 52 highest_handled_invalidation_version), |
50 weak_factory_(this), | 53 weak_factory_(this), |
51 max_fetch_delay_(kMaxFetchDelayDefault), | 54 max_fetch_delay_(kMaxFetchDelayDefault), |
52 policy_hash_value_(0) { | 55 policy_hash_value_(0) { |
53 DCHECK(core); | 56 DCHECK(core); |
54 DCHECK(task_runner.get()); | 57 DCHECK(task_runner.get()); |
55 } | 58 } |
56 | 59 |
57 CloudPolicyInvalidator::~CloudPolicyInvalidator() { | 60 CloudPolicyInvalidator::~CloudPolicyInvalidator() { |
58 DCHECK(state_ == SHUT_DOWN); | 61 DCHECK(state_ == SHUT_DOWN); |
59 } | 62 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) { | 150 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) { |
148 UMA_HISTOGRAM_ENUMERATION(kMetricDevicePolicyRefresh, | 151 UMA_HISTOGRAM_ENUMERATION(kMetricDevicePolicyRefresh, |
149 GetPolicyRefreshMetric(policy_changed), | 152 GetPolicyRefreshMetric(policy_changed), |
150 METRIC_POLICY_REFRESH_SIZE); | 153 METRIC_POLICY_REFRESH_SIZE); |
151 } else { | 154 } else { |
152 UMA_HISTOGRAM_ENUMERATION(kMetricUserPolicyRefresh, | 155 UMA_HISTOGRAM_ENUMERATION(kMetricUserPolicyRefresh, |
153 GetPolicyRefreshMetric(policy_changed), | 156 GetPolicyRefreshMetric(policy_changed), |
154 METRIC_POLICY_REFRESH_SIZE); | 157 METRIC_POLICY_REFRESH_SIZE); |
155 } | 158 } |
156 | 159 |
| 160 const int64 store_invalidation_version = store->invalidation_version(); |
| 161 |
157 // If the policy was invalid and the version stored matches the latest | 162 // If the policy was invalid and the version stored matches the latest |
158 // invalidation version, acknowledge the latest invalidation. | 163 // invalidation version, acknowledge the latest invalidation. |
159 if (invalid_ && store->invalidation_version() == invalidation_version_) | 164 if (invalid_ && store_invalidation_version == invalidation_version_) |
160 AcknowledgeInvalidation(); | 165 AcknowledgeInvalidation(); |
| 166 |
| 167 // Update the highest invalidation version that was handled already. |
| 168 if (store_invalidation_version > highest_handled_invalidation_version_) |
| 169 highest_handled_invalidation_version_ = store_invalidation_version; |
161 } | 170 } |
162 | 171 |
163 UpdateRegistration(store->policy()); | 172 UpdateRegistration(store->policy()); |
164 UpdateMaxFetchDelay(store->policy_map()); | 173 UpdateMaxFetchDelay(store->policy_map()); |
165 } | 174 } |
166 | 175 |
167 void CloudPolicyInvalidator::OnStoreError(CloudPolicyStore* store) {} | 176 void CloudPolicyInvalidator::OnStoreError(CloudPolicyStore* store) {} |
168 | 177 |
169 void CloudPolicyInvalidator::HandleInvalidation( | 178 void CloudPolicyInvalidator::HandleInvalidation( |
170 const syncer::Invalidation& invalidation) { | 179 const syncer::Invalidation& invalidation) { |
171 // Ignore old invalidations. | 180 // Ignore old invalidations. |
172 if (invalid_ && | 181 if (invalid_ && |
173 !invalidation.is_unknown_version() && | 182 !invalidation.is_unknown_version() && |
174 invalidation.version() <= invalidation_version_) { | 183 invalidation.version() <= invalidation_version_) { |
175 return; | 184 return; |
176 } | 185 } |
177 | 186 |
| 187 if (!invalidation.is_unknown_version() && |
| 188 invalidation.version() <= highest_handled_invalidation_version_) { |
| 189 // If this invalidation version was handled already, acknowledge the |
| 190 // invalidation but ignore it otherwise. |
| 191 invalidation.Acknowledge(); |
| 192 return; |
| 193 } |
| 194 |
178 // If there is still a pending invalidation, acknowledge it, since we only | 195 // If there is still a pending invalidation, acknowledge it, since we only |
179 // care about the latest invalidation. | 196 // care about the latest invalidation. |
180 if (invalid_) | 197 if (invalid_) |
181 AcknowledgeInvalidation(); | 198 AcknowledgeInvalidation(); |
182 | 199 |
183 // Get the version and payload from the invalidation. | 200 // Get the version and payload from the invalidation. |
184 // When an invalidation with unknown version is received, use negative | 201 // When an invalidation with unknown version is received, use negative |
185 // numbers based on the number of such invalidations received. This | 202 // numbers based on the number of such invalidations received. This |
186 // ensures that the version numbers do not collide with "real" versions | 203 // ensures that the version numbers do not collide with "real" versions |
187 // (which are positive) or previous invalidations with unknown version. | 204 // (which are positive) or previous invalidations with unknown version. |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { | 428 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { |
412 if (!invalidations_enabled_) | 429 if (!invalidations_enabled_) |
413 return false; | 430 return false; |
414 // If invalidations have been enabled for less than the grace period, then | 431 // If invalidations have been enabled for less than the grace period, then |
415 // consider invalidations to be disabled for metrics reporting. | 432 // consider invalidations to be disabled for metrics reporting. |
416 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; | 433 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; |
417 return elapsed.InSeconds() >= kInvalidationGracePeriod; | 434 return elapsed.InSeconds() >= kInvalidationGracePeriod; |
418 } | 435 } |
419 | 436 |
420 } // namespace policy | 437 } // namespace policy |
OLD | NEW |