Chromium Code Reviews| 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" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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 // We store updates to our GU retry timer in next_retry_time_. The one | |
| 252 // currently in effect is stored in current_retry_time_. Here is where we | |
| 253 // apply the pending update from next_retry_time_ to current_retry_time_. The | |
| 254 // current_retry_time_ will be overwritten in the process. | |
| 255 if (!next_retry_time_.is_null()) { | |
|
haitaol1
2014/01/28 23:07:23
Probably don't set current_retry_time if it's not
rlarocque
2014/01/28 23:17:09
Correct. That was my intention. At least, that's
| |
| 256 current_retry_time_ = next_retry_time_; | |
| 257 next_retry_time_ = base::TimeTicks(); | |
| 258 } | |
| 259 } | |
| 260 | |
| 242 void NudgeTracker::SetHintBufferSize(size_t size) { | 261 void NudgeTracker::SetHintBufferSize(size_t size) { |
| 243 for (TypeTrackerMap::iterator it = type_trackers_.begin(); | 262 for (TypeTrackerMap::iterator it = type_trackers_.begin(); |
| 244 it != type_trackers_.end(); ++it) { | 263 it != type_trackers_.end(); ++it) { |
| 245 it->second.UpdatePayloadBufferSize(size); | 264 it->second.UpdatePayloadBufferSize(size); |
| 246 } | 265 } |
| 247 } | 266 } |
| 248 | 267 |
| 268 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) { | |
| 269 next_retry_time_ = retry_time; | |
| 270 } | |
| 271 | |
| 249 } // namespace sessions | 272 } // namespace sessions |
| 250 } // namespace syncer | 273 } // namespace syncer |
| OLD | NEW |