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

Side by Side Diff: sync/sessions/nudge_tracker.cc

Issue 146113003: sync: GU retry with less explicit TimeTicks logic (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update NudgeTracker before normal mode transition cycle Created 6 years, 10 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
« no previous file with comments | « sync/sessions/nudge_tracker.h ('k') | sync/sessions/nudge_tracker_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "sync/sessions/nudge_tracker.h" 5 #include "sync/sessions/nudge_tracker.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "sync/internal_api/public/base/invalidation.h" 8 #include "sync/internal_api/public/base/invalidation.h"
9 #include "sync/notifier/invalidation_util.h" 9 #include "sync/notifier/invalidation_util.h"
10 #include "sync/notifier/object_id_invalidation_map.h" 10 #include "sync/notifier/object_id_invalidation_map.h"
(...skipping 26 matching lines...) Expand all
37 bool NudgeTracker::IsSyncRequired() const { 37 bool NudgeTracker::IsSyncRequired() const {
38 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 38 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
39 it != type_trackers_.end(); ++it) { 39 it != type_trackers_.end(); ++it) {
40 if (it->second.IsSyncRequired()) { 40 if (it->second.IsSyncRequired()) {
41 return true; 41 return true;
42 } 42 }
43 } 43 }
44 return false; 44 return false;
45 } 45 }
46 46
47 bool NudgeTracker::IsGetUpdatesRequired(base::TimeTicks now) const { 47 bool NudgeTracker::IsGetUpdatesRequired() const {
48 if (invalidations_out_of_sync_) 48 if (invalidations_out_of_sync_)
49 return true; 49 return true;
50 50
51 if (IsRetryRequired(now)) 51 if (IsRetryRequired())
52 return true; 52 return true;
53 53
54 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 54 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
55 it != type_trackers_.end(); ++it) { 55 it != type_trackers_.end(); ++it) {
56 if (it->second.IsGetUpdatesRequired()) { 56 if (it->second.IsGetUpdatesRequired()) {
57 return true; 57 return true;
58 } 58 }
59 } 59 }
60 return false; 60 return false;
61 } 61 }
62 62
63 bool NudgeTracker::IsRetryRequired(base::TimeTicks now) const { 63 bool NudgeTracker::IsRetryRequired() const {
64 return !next_retry_time_.is_null() && next_retry_time_ < now; 64 if (sync_cycle_start_time_.is_null())
65 return false;
66
67 if (current_retry_time_.is_null())
68 return false;
69
70 return current_retry_time_ < sync_cycle_start_time_;
65 } 71 }
66 72
67 void NudgeTracker::RecordSuccessfulSyncCycle(base::TimeTicks now) { 73 void NudgeTracker::RecordSuccessfulSyncCycle() {
68 updates_source_ = sync_pb::GetUpdatesCallerInfo::UNKNOWN; 74 updates_source_ = sync_pb::GetUpdatesCallerInfo::UNKNOWN;
69 last_successful_sync_time_ = now;
70 75
71 if (next_retry_time_ < now) 76 // If a retry was required, we've just serviced it. Unset the flag.
72 next_retry_time_ = base::TimeTicks(); 77 if (IsRetryRequired())
78 current_retry_time_ = base::TimeTicks();
73 79
74 // A successful cycle while invalidations are enabled puts us back into sync. 80 // A successful cycle while invalidations are enabled puts us back into sync.
75 invalidations_out_of_sync_ = !invalidations_enabled_; 81 invalidations_out_of_sync_ = !invalidations_enabled_;
76 82
77 for (TypeTrackerMap::iterator it = type_trackers_.begin(); 83 for (TypeTrackerMap::iterator it = type_trackers_.begin();
78 it != type_trackers_.end(); ++it) { 84 it != type_trackers_.end(); ++it) {
79 it->second.RecordSuccessfulSyncCycle(); 85 it->second.RecordSuccessfulSyncCycle();
80 } 86 }
81 } 87 }
82 88
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 sync_pb::GetUpdateTriggers* msg) const { 238 sync_pb::GetUpdateTriggers* msg) const {
233 DCHECK(type_trackers_.find(type) != type_trackers_.end()); 239 DCHECK(type_trackers_.find(type) != type_trackers_.end());
234 240
235 // Fill what we can from the global data. 241 // Fill what we can from the global data.
236 msg->set_invalidations_out_of_sync(invalidations_out_of_sync_); 242 msg->set_invalidations_out_of_sync(invalidations_out_of_sync_);
237 243
238 // Delegate the type-specific work to the DataTypeTracker class. 244 // Delegate the type-specific work to the DataTypeTracker class.
239 type_trackers_.find(type)->second.FillGetUpdatesTriggersMessage(msg); 245 type_trackers_.find(type)->second.FillGetUpdatesTriggersMessage(msg);
240 } 246 }
241 247
248 void NudgeTracker::SetSyncCycleStartTime(base::TimeTicks now) {
249 sync_cycle_start_time_ = now;
250
251 // If current_retry_time_ is still set, that means we have an old retry time
252 // left over from a previous cycle. For example, maybe we tried to perform
253 // this retry, hit a network connection error, and now we're in exponential
254 // backoff. In that case, we want this sync cycle to include the GU retry
255 // flag so we leave this variable set regardless of whether or not there is an
256 // overwrite pending.
257 if (!current_retry_time_.is_null()) {
258 return;
259 }
260
261 // If do not have a current_retry_time_, but we do have a next_retry_time_ and
262 // it is ready to go, then we set it as the current_retry_time_. It will stay
263 // there until a GU retry has succeeded.
264 if (!next_retry_time_.is_null() &&
265 next_retry_time_ < sync_cycle_start_time_) {
266 current_retry_time_ = next_retry_time_;
267 next_retry_time_ = base::TimeTicks();
268 }
269 }
270
242 void NudgeTracker::SetHintBufferSize(size_t size) { 271 void NudgeTracker::SetHintBufferSize(size_t size) {
243 for (TypeTrackerMap::iterator it = type_trackers_.begin(); 272 for (TypeTrackerMap::iterator it = type_trackers_.begin();
244 it != type_trackers_.end(); ++it) { 273 it != type_trackers_.end(); ++it) {
245 it->second.UpdatePayloadBufferSize(size); 274 it->second.UpdatePayloadBufferSize(size);
246 } 275 }
247 } 276 }
248 277
278 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) {
279 next_retry_time_ = retry_time;
280 }
281
249 } // namespace sessions 282 } // namespace sessions
250 } // namespace syncer 283 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/nudge_tracker.h ('k') | sync/sessions/nudge_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698