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 16 matching lines...) Expand all Loading... | |
| 27 if (!RealModelTypeToObjectId(it.Get(), &id)) { | 27 if (!RealModelTypeToObjectId(it.Get(), &id)) { |
| 28 NOTREACHED(); | 28 NOTREACHED(); |
| 29 } else { | 29 } else { |
| 30 type_trackers_.insert(std::make_pair(it.Get(), DataTypeTracker(id))); | 30 type_trackers_.insert(std::make_pair(it.Get(), DataTypeTracker(id))); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 | 34 |
| 35 NudgeTracker::~NudgeTracker() { } | 35 NudgeTracker::~NudgeTracker() { } |
| 36 | 36 |
| 37 bool NudgeTracker::IsSyncRequired() const { | 37 bool NudgeTracker::IsSyncRequired() const { |
|
rlarocque
2014/01/08 20:30:08
I'm pretty sure this should return true if IsRetry
haitaol1
2014/01/09 00:30:44
I didn't call IsRetryRequired() here because that
rlarocque
2014/01/09 00:37:21
At the moment, I'm not sure either. :)
It's been
| |
| 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() const { | 47 bool NudgeTracker::IsGetUpdatesRequired(base::TimeTicks now) 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 | |
| 50 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 54 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 51 it != type_trackers_.end(); ++it) { | 55 it != type_trackers_.end(); ++it) { |
| 52 if (it->second.IsGetUpdatesRequired()) { | 56 if (it->second.IsGetUpdatesRequired()) { |
| 53 return true; | 57 return true; |
| 54 } | 58 } |
| 55 } | 59 } |
| 56 return false; | 60 return false; |
| 57 } | 61 } |
| 58 | 62 |
| 59 void NudgeTracker::RecordSuccessfulSyncCycle() { | 63 bool NudgeTracker::IsRetryRequired(base::TimeTicks now) const { |
| 64 return !next_retry_time_.is_null() && next_retry_time_ < now; | |
| 65 } | |
| 66 | |
| 67 void NudgeTracker::RecordSuccessfulSyncCycle(base::TimeTicks now) { | |
| 60 updates_source_ = sync_pb::GetUpdatesCallerInfo::UNKNOWN; | 68 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(); | |
| 61 | 73 |
| 62 // A successful cycle while invalidations are enabled puts us back into sync. | 74 // A successful cycle while invalidations are enabled puts us back into sync. |
| 63 invalidations_out_of_sync_ = !invalidations_enabled_; | 75 invalidations_out_of_sync_ = !invalidations_enabled_; |
| 64 | 76 |
| 65 for (TypeTrackerMap::iterator it = type_trackers_.begin(); | 77 for (TypeTrackerMap::iterator it = type_trackers_.begin(); |
| 66 it != type_trackers_.end(); ++it) { | 78 it != type_trackers_.end(); ++it) { |
| 67 it->second.RecordSuccessfulSyncCycle(); | 79 it->second.RecordSuccessfulSyncCycle(); |
| 68 } | 80 } |
| 69 } | 81 } |
| 70 | 82 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 | 241 |
| 230 void NudgeTracker::SetHintBufferSize(size_t size) { | 242 void NudgeTracker::SetHintBufferSize(size_t size) { |
| 231 for (TypeTrackerMap::iterator it = type_trackers_.begin(); | 243 for (TypeTrackerMap::iterator it = type_trackers_.begin(); |
| 232 it != type_trackers_.end(); ++it) { | 244 it != type_trackers_.end(); ++it) { |
| 233 it->second.UpdatePayloadBufferSize(size); | 245 it->second.UpdatePayloadBufferSize(size); |
| 234 } | 246 } |
| 235 } | 247 } |
| 236 | 248 |
| 237 } // namespace sessions | 249 } // namespace sessions |
| 238 } // namespace syncer | 250 } // namespace syncer |
| OLD | NEW |