Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(471)

Side by Side Diff: chrome/browser/policy/cloud/cloud_policy_invalidator.cc

Issue 460573005: Pass highest handled invalidation version between invalidators (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed nits. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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());
58 // |highest_handled_invalidation_version_| indicates the highest actual
59 // invalidation version handled. Since actual invalidations can have only
60 // positive versions, this member may be zero (no versioned invalidation
61 // handled yet) or positive. Negative values are not allowed:
62 //
63 // Negative version numbers are used internally by CloudPolicyInvalidator to
64 // keep track of unversioned invalidations. When such an invalidation is
65 // handled, |highest_handled_invalidation_version_| remains unchanged and does
66 // not become negative.
67 DCHECK_LE(0, highest_handled_invalidation_version_);
55 } 68 }
56 69
57 CloudPolicyInvalidator::~CloudPolicyInvalidator() { 70 CloudPolicyInvalidator::~CloudPolicyInvalidator() {
58 DCHECK(state_ == SHUT_DOWN); 71 DCHECK(state_ == SHUT_DOWN);
59 } 72 }
60 73
61 void CloudPolicyInvalidator::Initialize( 74 void CloudPolicyInvalidator::Initialize(
62 invalidation::InvalidationService* invalidation_service) { 75 invalidation::InvalidationService* invalidation_service) {
63 DCHECK(state_ == UNINITIALIZED); 76 DCHECK(state_ == UNINITIALIZED);
64 DCHECK(thread_checker_.CalledOnValidThread()); 77 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) { 160 if (type_ == enterprise_management::DeviceRegisterRequest::DEVICE) {
148 UMA_HISTOGRAM_ENUMERATION(kMetricDevicePolicyRefresh, 161 UMA_HISTOGRAM_ENUMERATION(kMetricDevicePolicyRefresh,
149 GetPolicyRefreshMetric(policy_changed), 162 GetPolicyRefreshMetric(policy_changed),
150 METRIC_POLICY_REFRESH_SIZE); 163 METRIC_POLICY_REFRESH_SIZE);
151 } else { 164 } else {
152 UMA_HISTOGRAM_ENUMERATION(kMetricUserPolicyRefresh, 165 UMA_HISTOGRAM_ENUMERATION(kMetricUserPolicyRefresh,
153 GetPolicyRefreshMetric(policy_changed), 166 GetPolicyRefreshMetric(policy_changed),
154 METRIC_POLICY_REFRESH_SIZE); 167 METRIC_POLICY_REFRESH_SIZE);
155 } 168 }
156 169
170 const int64 store_invalidation_version = store->invalidation_version();
171
157 // If the policy was invalid and the version stored matches the latest 172 // If the policy was invalid and the version stored matches the latest
158 // invalidation version, acknowledge the latest invalidation. 173 // invalidation version, acknowledge the latest invalidation.
159 if (invalid_ && store->invalidation_version() == invalidation_version_) 174 if (invalid_ && store_invalidation_version == invalidation_version_)
160 AcknowledgeInvalidation(); 175 AcknowledgeInvalidation();
176
177 // Update the highest invalidation version that was handled already.
178 if (store_invalidation_version > highest_handled_invalidation_version_)
179 highest_handled_invalidation_version_ = store_invalidation_version;
161 } 180 }
162 181
163 UpdateRegistration(store->policy()); 182 UpdateRegistration(store->policy());
164 UpdateMaxFetchDelay(store->policy_map()); 183 UpdateMaxFetchDelay(store->policy_map());
165 } 184 }
166 185
167 void CloudPolicyInvalidator::OnStoreError(CloudPolicyStore* store) {} 186 void CloudPolicyInvalidator::OnStoreError(CloudPolicyStore* store) {}
168 187
169 void CloudPolicyInvalidator::HandleInvalidation( 188 void CloudPolicyInvalidator::HandleInvalidation(
170 const syncer::Invalidation& invalidation) { 189 const syncer::Invalidation& invalidation) {
171 // Ignore old invalidations. 190 // Ignore old invalidations.
172 if (invalid_ && 191 if (invalid_ &&
173 !invalidation.is_unknown_version() && 192 !invalidation.is_unknown_version() &&
174 invalidation.version() <= invalidation_version_) { 193 invalidation.version() <= invalidation_version_) {
175 return; 194 return;
176 } 195 }
177 196
197 if (!invalidation.is_unknown_version() &&
198 invalidation.version() <= highest_handled_invalidation_version_) {
199 // If this invalidation version was handled already, acknowledge the
200 // invalidation but ignore it otherwise.
201 invalidation.Acknowledge();
202 return;
203 }
204
178 // If there is still a pending invalidation, acknowledge it, since we only 205 // If there is still a pending invalidation, acknowledge it, since we only
179 // care about the latest invalidation. 206 // care about the latest invalidation.
180 if (invalid_) 207 if (invalid_)
181 AcknowledgeInvalidation(); 208 AcknowledgeInvalidation();
182 209
183 // Get the version and payload from the invalidation. 210 // Get the version and payload from the invalidation.
184 // When an invalidation with unknown version is received, use negative 211 // When an invalidation with unknown version is received, use negative
185 // numbers based on the number of such invalidations received. This 212 // numbers based on the number of such invalidations received. This
186 // ensures that the version numbers do not collide with "real" versions 213 // ensures that the version numbers do not collide with "real" versions
187 // (which are positive) or previous invalidations with unknown version. 214 // (which are positive) or previous invalidations with unknown version.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 bool CloudPolicyInvalidator::GetInvalidationsEnabled() { 438 bool CloudPolicyInvalidator::GetInvalidationsEnabled() {
412 if (!invalidations_enabled_) 439 if (!invalidations_enabled_)
413 return false; 440 return false;
414 // If invalidations have been enabled for less than the grace period, then 441 // If invalidations have been enabled for less than the grace period, then
415 // consider invalidations to be disabled for metrics reporting. 442 // consider invalidations to be disabled for metrics reporting.
416 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_; 443 base::TimeDelta elapsed = clock_->Now() - invalidations_enabled_time_;
417 return elapsed.InSeconds() >= kInvalidationGracePeriod; 444 return elapsed.InSeconds() >= kInvalidationGracePeriod;
418 } 445 }
419 446
420 } // namespace policy 447 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698