| 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 | |
| 51 if (IsRetryRequired(now)) | |
| 52 return true; | |
| 53 | |
| 54 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 50 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 55 it != type_trackers_.end(); ++it) { | 51 it != type_trackers_.end(); ++it) { |
| 56 if (it->second.IsGetUpdatesRequired()) { | 52 if (it->second.IsGetUpdatesRequired()) { |
| 57 return true; | 53 return true; |
| 58 } | 54 } |
| 59 } | 55 } |
| 60 return false; | 56 return false; |
| 61 } | 57 } |
| 62 | 58 |
| 63 bool NudgeTracker::IsRetryRequired(base::TimeTicks now) const { | 59 void NudgeTracker::RecordSuccessfulSyncCycle() { |
| 64 return !next_retry_time_.is_null() && next_retry_time_ < now; | |
| 65 } | |
| 66 | |
| 67 void NudgeTracker::RecordSuccessfulSyncCycle(base::TimeTicks now) { | |
| 68 updates_source_ = sync_pb::GetUpdatesCallerInfo::UNKNOWN; | 60 updates_source_ = sync_pb::GetUpdatesCallerInfo::UNKNOWN; |
| 69 last_successful_sync_time_ = now; | |
| 70 | |
| 71 if (next_retry_time_ < now) | |
| 72 next_retry_time_ = base::TimeTicks(); | |
| 73 | 61 |
| 74 // A successful cycle while invalidations are enabled puts us back into sync. | 62 // A successful cycle while invalidations are enabled puts us back into sync. |
| 75 invalidations_out_of_sync_ = !invalidations_enabled_; | 63 invalidations_out_of_sync_ = !invalidations_enabled_; |
| 76 | 64 |
| 77 for (TypeTrackerMap::iterator it = type_trackers_.begin(); | 65 for (TypeTrackerMap::iterator it = type_trackers_.begin(); |
| 78 it != type_trackers_.end(); ++it) { | 66 it != type_trackers_.end(); ++it) { |
| 79 it->second.RecordSuccessfulSyncCycle(); | 67 it->second.RecordSuccessfulSyncCycle(); |
| 80 } | 68 } |
| 81 } | 69 } |
| 82 | 70 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 229 |
| 242 void NudgeTracker::SetHintBufferSize(size_t size) { | 230 void NudgeTracker::SetHintBufferSize(size_t size) { |
| 243 for (TypeTrackerMap::iterator it = type_trackers_.begin(); | 231 for (TypeTrackerMap::iterator it = type_trackers_.begin(); |
| 244 it != type_trackers_.end(); ++it) { | 232 it != type_trackers_.end(); ++it) { |
| 245 it->second.UpdatePayloadBufferSize(size); | 233 it->second.UpdatePayloadBufferSize(size); |
| 246 } | 234 } |
| 247 } | 235 } |
| 248 | 236 |
| 249 } // namespace sessions | 237 } // namespace sessions |
| 250 } // namespace syncer | 238 } // namespace syncer |
| OLD | NEW |