OLD | NEW |
---|---|
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 next_retry_time_ = base::TimeTicks(); | 72 is_retry_required_ = false; |
73 | |
74 // We don't unset the next_retry_time_ flag here, since it may have been | |
75 // updated during the sync cycle that just completed. | |
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 Loading... | |
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) { | |
246 // Assume we have nothing to do. | |
247 is_retry_required_ = false; | |
248 | |
249 // Nothing to do if no retries are scheduled. | |
250 if (next_retry_time_.is_null()) | |
251 return; | |
252 | |
253 if (next_retry_time_ < now) { | |
haitaol1
2014/01/28 20:09:20
where is next_retry_time nulled? Seems nudge track
rlarocque
2014/01/28 22:24:38
Thanks!
I had a nagging feeling that this code wa
| |
254 // The time has come. We should perform a GU retry as soon as possible. | |
255 is_retry_required_ = true; | |
256 } | |
257 } | |
258 | |
242 void NudgeTracker::SetHintBufferSize(size_t size) { | 259 void NudgeTracker::SetHintBufferSize(size_t size) { |
243 for (TypeTrackerMap::iterator it = type_trackers_.begin(); | 260 for (TypeTrackerMap::iterator it = type_trackers_.begin(); |
244 it != type_trackers_.end(); ++it) { | 261 it != type_trackers_.end(); ++it) { |
245 it->second.UpdatePayloadBufferSize(size); | 262 it->second.UpdatePayloadBufferSize(size); |
246 } | 263 } |
247 } | 264 } |
248 | 265 |
266 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) { | |
267 next_retry_time_ = retry_time; | |
268 } | |
269 | |
249 } // namespace sessions | 270 } // namespace sessions |
250 } // namespace syncer | 271 } // namespace syncer |
OLD | NEW |