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

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

Issue 56113003: Implement new invalidations ack tracking system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Modify drive TODO comment + rebase Created 7 years 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/hash.h" 9 #include "base/hash.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 24 matching lines...) Expand all
35 : state_(UNINITIALIZED), 35 : state_(UNINITIALIZED),
36 core_(core), 36 core_(core),
37 task_runner_(task_runner), 37 task_runner_(task_runner),
38 invalidation_service_(NULL), 38 invalidation_service_(NULL),
39 invalidations_enabled_(false), 39 invalidations_enabled_(false),
40 invalidation_service_enabled_(false), 40 invalidation_service_enabled_(false),
41 registered_timestamp_(0), 41 registered_timestamp_(0),
42 invalid_(false), 42 invalid_(false),
43 invalidation_version_(0), 43 invalidation_version_(0),
44 unknown_version_invalidation_count_(0), 44 unknown_version_invalidation_count_(0),
45 ack_handle_(syncer::AckHandle::InvalidAckHandle()),
46 weak_factory_(this), 45 weak_factory_(this),
47 max_fetch_delay_(kMaxFetchDelayDefault), 46 max_fetch_delay_(kMaxFetchDelayDefault),
48 policy_hash_value_(0) { 47 policy_hash_value_(0) {
49 DCHECK(core); 48 DCHECK(core);
50 DCHECK(task_runner.get()); 49 DCHECK(task_runner.get());
51 } 50 }
52 51
53 CloudPolicyInvalidator::~CloudPolicyInvalidator() { 52 CloudPolicyInvalidator::~CloudPolicyInvalidator() {
54 DCHECK(state_ == SHUT_DOWN); 53 DCHECK(state_ == SHUT_DOWN);
55 } 54 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void CloudPolicyInvalidator::OnIncomingInvalidation( 90 void CloudPolicyInvalidator::OnIncomingInvalidation(
92 const syncer::ObjectIdInvalidationMap& invalidation_map) { 91 const syncer::ObjectIdInvalidationMap& invalidation_map) {
93 DCHECK(state_ == STARTED); 92 DCHECK(state_ == STARTED);
94 DCHECK(thread_checker_.CalledOnValidThread()); 93 DCHECK(thread_checker_.CalledOnValidThread());
95 const syncer::SingleObjectInvalidationSet& list = 94 const syncer::SingleObjectInvalidationSet& list =
96 invalidation_map.ForObject(object_id_); 95 invalidation_map.ForObject(object_id_);
97 if (list.IsEmpty()) { 96 if (list.IsEmpty()) {
98 NOTREACHED(); 97 NOTREACHED();
99 return; 98 return;
100 } 99 }
100
101 // Acknowledge all except the invalidation with the highest version.
102 syncer::SingleObjectInvalidationSet::const_reverse_iterator it =
103 list.rbegin();
104 ++it;
105 for ( ; it != list.rend(); ++it) {
106 it->Acknowledge();
107 }
108
109 // Handle the highest version invalidation.
101 HandleInvalidation(list.back()); 110 HandleInvalidation(list.back());
102 } 111 }
103 112
104 void CloudPolicyInvalidator::OnCoreConnected(CloudPolicyCore* core) {} 113 void CloudPolicyInvalidator::OnCoreConnected(CloudPolicyCore* core) {}
105 114
106 void CloudPolicyInvalidator::OnRefreshSchedulerStarted(CloudPolicyCore* core) { 115 void CloudPolicyInvalidator::OnRefreshSchedulerStarted(CloudPolicyCore* core) {
107 DCHECK(state_ == STOPPED); 116 DCHECK(state_ == STOPPED);
108 DCHECK(thread_checker_.CalledOnValidThread()); 117 DCHECK(thread_checker_.CalledOnValidThread());
109 state_ = STARTED; 118 state_ = STARTED;
110 OnStoreLoaded(core_->store()); 119 OnStoreLoaded(core_->store());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 156 }
148 157
149 UpdateRegistration(store->policy()); 158 UpdateRegistration(store->policy());
150 UpdateMaxFetchDelay(store->policy_map()); 159 UpdateMaxFetchDelay(store->policy_map());
151 } 160 }
152 161
153 void CloudPolicyInvalidator::OnStoreError(CloudPolicyStore* store) {} 162 void CloudPolicyInvalidator::OnStoreError(CloudPolicyStore* store) {}
154 163
155 void CloudPolicyInvalidator::HandleInvalidation( 164 void CloudPolicyInvalidator::HandleInvalidation(
156 const syncer::Invalidation& invalidation) { 165 const syncer::Invalidation& invalidation) {
157 // The invalidation service may send an invalidation more than once if there 166 // Ignore old invalidations.
158 // is a delay in acknowledging it. Duplicate invalidations are ignored. 167 if (invalid_ &&
159 if (invalid_ && ack_handle_.Equals(invalidation.ack_handle())) 168 !invalidation.is_unknown_version() &&
169 invalidation.version() <= invalidation_version_) {
160 return; 170 return;
171 }
161 172
162 // If there is still a pending invalidation, acknowledge it, since we only 173 // If there is still a pending invalidation, acknowledge it, since we only
163 // care about the latest invalidation. 174 // care about the latest invalidation.
164 if (invalid_) 175 if (invalid_)
165 AcknowledgeInvalidation(); 176 AcknowledgeInvalidation();
166 177
167 // Update invalidation state. 178 // Update invalidation state.
168 invalid_ = true; 179 invalid_ = true;
169 ack_handle_ = invalidation.ack_handle(); 180 invalidation_.reset(new syncer::Invalidation(invalidation));
170 181
171 // When an invalidation with unknown version is received, use negative 182 // When an invalidation with unknown version is received, use negative
172 // numbers based on the number of such invalidations received. This 183 // numbers based on the number of such invalidations received. This
173 // ensures that the version numbers do not collide with "real" versions 184 // ensures that the version numbers do not collide with "real" versions
174 // (which are positive) or previous invalidations with unknown version. 185 // (which are positive) or previous invalidations with unknown version.
175 if (invalidation.is_unknown_version()) { 186 if (invalidation.is_unknown_version()) {
176 invalidation_version_ = -(++unknown_version_invalidation_count_); 187 invalidation_version_ = -(++unknown_version_invalidation_count_);
177 } else { 188 } else {
178 invalidation_version_ = invalidation.version(); 189 invalidation_version_ = invalidation.version();
179 } 190 }
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // the client yet, so set it now that the required time has elapsed. 326 // the client yet, so set it now that the required time has elapsed.
316 if (is_missing_payload) 327 if (is_missing_payload)
317 core_->client()->SetInvalidationInfo(invalidation_version_, std::string()); 328 core_->client()->SetInvalidationInfo(invalidation_version_, std::string());
318 core_->refresh_scheduler()->RefreshSoon(); 329 core_->refresh_scheduler()->RefreshSoon();
319 } 330 }
320 331
321 void CloudPolicyInvalidator::AcknowledgeInvalidation() { 332 void CloudPolicyInvalidator::AcknowledgeInvalidation() {
322 DCHECK(invalid_); 333 DCHECK(invalid_);
323 invalid_ = false; 334 invalid_ = false;
324 core_->client()->SetInvalidationInfo(0, std::string()); 335 core_->client()->SetInvalidationInfo(0, std::string());
325 invalidation_service_->AcknowledgeInvalidation(object_id_, ack_handle_); 336 invalidation_->Acknowledge();
337 invalidation_.reset();
326 // Cancel any scheduled policy refreshes. 338 // Cancel any scheduled policy refreshes.
327 weak_factory_.InvalidateWeakPtrs(); 339 weak_factory_.InvalidateWeakPtrs();
328 } 340 }
329 341
330 bool CloudPolicyInvalidator::IsPolicyChanged( 342 bool CloudPolicyInvalidator::IsPolicyChanged(
331 const enterprise_management::PolicyData* policy) { 343 const enterprise_management::PolicyData* policy) {
332 // Determine if the policy changed by comparing its hash value to the 344 // Determine if the policy changed by comparing its hash value to the
333 // previous policy's hash value. 345 // previous policy's hash value.
334 uint32 new_hash_value = 0; 346 uint32 new_hash_value = 0;
335 if (policy && policy->has_policy_value()) 347 if (policy && policy->has_policy_value())
(...skipping 10 matching lines...) Expand all
346 if (invalidations_enabled_) 358 if (invalidations_enabled_)
347 return METRIC_POLICY_REFRESH_CHANGED; 359 return METRIC_POLICY_REFRESH_CHANGED;
348 return METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS; 360 return METRIC_POLICY_REFRESH_CHANGED_NO_INVALIDATIONS;
349 } 361 }
350 if (invalid_) 362 if (invalid_)
351 return METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED; 363 return METRIC_POLICY_REFRESH_INVALIDATED_UNCHANGED;
352 return METRIC_POLICY_REFRESH_UNCHANGED; 364 return METRIC_POLICY_REFRESH_UNCHANGED;
353 } 365 }
354 366
355 } // namespace policy 367 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698