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

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: Created 6 years, 11 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 (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"
11 #include "sync/protocol/sync.pb.h" 11 #include "sync/protocol/sync.pb.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 namespace sessions { 14 namespace sessions {
15 15
16 size_t NudgeTracker::kDefaultMaxPayloadsPerType = 10; 16 size_t NudgeTracker::kDefaultMaxPayloadsPerType = 10;
17 17
18 NudgeTracker::NudgeTracker() 18 NudgeTracker::NudgeTracker()
19 : updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), 19 : updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN),
20 invalidations_enabled_(false), 20 invalidations_enabled_(false),
21 invalidations_out_of_sync_(true) { 21 invalidations_out_of_sync_(true),
22 is_retry_required_(false) {
22 ModelTypeSet protocol_types = ProtocolTypes(); 23 ModelTypeSet protocol_types = ProtocolTypes();
23 // Default initialize all the type trackers. 24 // Default initialize all the type trackers.
24 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good(); 25 for (ModelTypeSet::Iterator it = protocol_types.First(); it.Good();
25 it.Inc()) { 26 it.Inc()) {
26 invalidation::ObjectId id; 27 invalidation::ObjectId id;
27 if (!RealModelTypeToObjectId(it.Get(), &id)) { 28 if (!RealModelTypeToObjectId(it.Get(), &id)) {
28 NOTREACHED(); 29 NOTREACHED();
29 } else { 30 } else {
30 type_trackers_.insert(std::make_pair(it.Get(), DataTypeTracker(id))); 31 type_trackers_.insert(std::make_pair(it.Get(), DataTypeTracker(id)));
31 } 32 }
32 } 33 }
33 } 34 }
34 35
35 NudgeTracker::~NudgeTracker() { } 36 NudgeTracker::~NudgeTracker() { }
36 37
37 bool NudgeTracker::IsSyncRequired() const { 38 bool NudgeTracker::IsSyncRequired() const {
38 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 39 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
39 it != type_trackers_.end(); ++it) { 40 it != type_trackers_.end(); ++it) {
40 if (it->second.IsSyncRequired()) { 41 if (it->second.IsSyncRequired()) {
41 return true; 42 return true;
42 } 43 }
43 } 44 }
44 return false; 45 return false;
45 } 46 }
46 47
47 bool NudgeTracker::IsGetUpdatesRequired(base::TimeTicks now) const { 48 bool NudgeTracker::IsGetUpdatesRequired() const {
48 if (invalidations_out_of_sync_) 49 if (invalidations_out_of_sync_)
49 return true; 50 return true;
50 51
51 if (IsRetryRequired(now)) 52 if (IsRetryRequired())
52 return true; 53 return true;
53 54
54 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); 55 for (TypeTrackerMap::const_iterator it = type_trackers_.begin();
55 it != type_trackers_.end(); ++it) { 56 it != type_trackers_.end(); ++it) {
56 if (it->second.IsGetUpdatesRequired()) { 57 if (it->second.IsGetUpdatesRequired()) {
57 return true; 58 return true;
58 } 59 }
59 } 60 }
60 return false; 61 return false;
61 } 62 }
62 63
63 bool NudgeTracker::IsRetryRequired(base::TimeTicks now) const { 64 bool NudgeTracker::IsRetryRequired() const {
64 return !next_retry_time_.is_null() && next_retry_time_ < now; 65 return is_retry_required_;
65 } 66 }
66 67
67 void NudgeTracker::RecordSuccessfulSyncCycle(base::TimeTicks now) { 68 void NudgeTracker::RecordSuccessfulSyncCycle() {
68 updates_source_ = sync_pb::GetUpdatesCallerInfo::UNKNOWN; 69 updates_source_ = sync_pb::GetUpdatesCallerInfo::UNKNOWN;
69 last_successful_sync_time_ = now;
70 70
71 if (next_retry_time_ < now) 71 // If a retry was required, we've just serviced it. Unset the flag.
72 if (is_retry_required_) {
73 is_retry_required_ = false;
72 next_retry_time_ = base::TimeTicks(); 74 next_retry_time_ = base::TimeTicks();
75 }
73 76
74 // A successful cycle while invalidations are enabled puts us back into sync. 77 // A successful cycle while invalidations are enabled puts us back into sync.
75 invalidations_out_of_sync_ = !invalidations_enabled_; 78 invalidations_out_of_sync_ = !invalidations_enabled_;
76 79
77 for (TypeTrackerMap::iterator it = type_trackers_.begin(); 80 for (TypeTrackerMap::iterator it = type_trackers_.begin();
78 it != type_trackers_.end(); ++it) { 81 it != type_trackers_.end(); ++it) {
79 it->second.RecordSuccessfulSyncCycle(); 82 it->second.RecordSuccessfulSyncCycle();
80 } 83 }
81 } 84 }
82 85
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 sync_pb::GetUpdateTriggers* msg) const { 235 sync_pb::GetUpdateTriggers* msg) const {
233 DCHECK(type_trackers_.find(type) != type_trackers_.end()); 236 DCHECK(type_trackers_.find(type) != type_trackers_.end());
234 237
235 // Fill what we can from the global data. 238 // Fill what we can from the global data.
236 msg->set_invalidations_out_of_sync(invalidations_out_of_sync_); 239 msg->set_invalidations_out_of_sync(invalidations_out_of_sync_);
237 240
238 // Delegate the type-specific work to the DataTypeTracker class. 241 // Delegate the type-specific work to the DataTypeTracker class.
239 type_trackers_.find(type)->second.FillGetUpdatesTriggersMessage(msg); 242 type_trackers_.find(type)->second.FillGetUpdatesTriggersMessage(msg);
240 } 243 }
241 244
245 void NudgeTracker::ToggleRetryFlagIfRequired(base::TimeTicks now) {
haitaol1 2014/01/27 23:17:07 Seems redundant to keep both is_retry_required and
rlarocque 2014/01/28 01:06:34 I wanted to avoid saving the value of 'now' inside
246 // Nothing to do if no retries are scheduled for the future.
247 if (next_retry_time_.is_null())
248 return;
249
250 if (next_retry_time_ < now) {
251 // The time has come. We should perform a GU retry as soon as possible.
252 is_retry_required_ = true;
253 next_retry_time_ = base::TimeTicks();
254 }
255 }
256
242 void NudgeTracker::SetHintBufferSize(size_t size) { 257 void NudgeTracker::SetHintBufferSize(size_t size) {
243 for (TypeTrackerMap::iterator it = type_trackers_.begin(); 258 for (TypeTrackerMap::iterator it = type_trackers_.begin();
244 it != type_trackers_.end(); ++it) { 259 it != type_trackers_.end(); ++it) {
245 it->second.UpdatePayloadBufferSize(size); 260 it->second.UpdatePayloadBufferSize(size);
246 } 261 }
247 } 262 }
248 263
264 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) {
265 next_retry_time_ = retry_time;
266 }
267
249 } // namespace sessions 268 } // namespace sessions
250 } // namespace syncer 269 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698