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/protocol/sync.pb.h" | 8 #include "sync/protocol/sync.pb.h" |
9 | 9 |
10 namespace syncer { | 10 namespace syncer { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 99 |
100 void NudgeTracker::RecordRemoteInvalidation( | 100 void NudgeTracker::RecordRemoteInvalidation( |
101 syncer::ModelType type, | 101 syncer::ModelType type, |
102 scoped_ptr<InvalidationInterface> invalidation) { | 102 scoped_ptr<InvalidationInterface> invalidation) { |
103 // Forward the invalidations to the proper recipient. | 103 // Forward the invalidations to the proper recipient. |
104 TypeTrackerMap::iterator tracker_it = type_trackers_.find(type); | 104 TypeTrackerMap::iterator tracker_it = type_trackers_.find(type); |
105 DCHECK(tracker_it != type_trackers_.end()); | 105 DCHECK(tracker_it != type_trackers_.end()); |
106 tracker_it->second->RecordRemoteInvalidation(invalidation.Pass()); | 106 tracker_it->second->RecordRemoteInvalidation(invalidation.Pass()); |
107 } | 107 } |
108 | 108 |
| 109 void NudgeTracker::RecordInitialSyncRequired(syncer::ModelType type) { |
| 110 TypeTrackerMap::iterator tracker_it = type_trackers_.find(type); |
| 111 DCHECK(tracker_it != type_trackers_.end()); |
| 112 tracker_it->second->RecordInitialSyncRequired(); |
| 113 } |
| 114 |
109 void NudgeTracker::OnInvalidationsEnabled() { | 115 void NudgeTracker::OnInvalidationsEnabled() { |
110 invalidations_enabled_ = true; | 116 invalidations_enabled_ = true; |
111 } | 117 } |
112 | 118 |
113 void NudgeTracker::OnInvalidationsDisabled() { | 119 void NudgeTracker::OnInvalidationsDisabled() { |
114 invalidations_enabled_ = false; | 120 invalidations_enabled_ = false; |
115 invalidations_out_of_sync_ = true; | 121 invalidations_out_of_sync_ = true; |
116 } | 122 } |
117 | 123 |
118 void NudgeTracker::SetTypesThrottledUntil( | 124 void NudgeTracker::SetTypesThrottledUntil( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // There's an order to these sources: NOTIFICATION, DATATYPE_REFRESH, LOCAL, | 227 // There's an order to these sources: NOTIFICATION, DATATYPE_REFRESH, LOCAL, |
222 // RETRY. The server makes optimization decisions based on this field, so | 228 // RETRY. The server makes optimization decisions based on this field, so |
223 // it's important to get this right. Setting it wrong could lead to missed | 229 // it's important to get this right. Setting it wrong could lead to missed |
224 // updates. | 230 // updates. |
225 // | 231 // |
226 // This complexity is part of the reason why we're deprecating 'source' in | 232 // This complexity is part of the reason why we're deprecating 'source' in |
227 // favor of 'origin'. | 233 // favor of 'origin'. |
228 bool has_invalidation_pending = false; | 234 bool has_invalidation_pending = false; |
229 bool has_refresh_request_pending = false; | 235 bool has_refresh_request_pending = false; |
230 bool has_commit_pending = false; | 236 bool has_commit_pending = false; |
| 237 bool is_initial_sync_required = false; |
231 bool has_retry = IsRetryRequired(); | 238 bool has_retry = IsRetryRequired(); |
232 | 239 |
233 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 240 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
234 it != type_trackers_.end(); ++it) { | 241 it != type_trackers_.end(); ++it) { |
235 const DataTypeTracker& tracker = *it->second; | 242 const DataTypeTracker& tracker = *it->second; |
236 if (!tracker.IsThrottled() && tracker.HasPendingInvalidation()) { | 243 if (!tracker.IsThrottled() && tracker.HasPendingInvalidation()) { |
237 has_invalidation_pending = true; | 244 has_invalidation_pending = true; |
238 } | 245 } |
239 if (!tracker.IsThrottled() && tracker.HasRefreshRequestPending()) { | 246 if (!tracker.IsThrottled() && tracker.HasRefreshRequestPending()) { |
240 has_refresh_request_pending = true; | 247 has_refresh_request_pending = true; |
241 } | 248 } |
242 if (!tracker.IsThrottled() && tracker.HasLocalChangePending()) { | 249 if (!tracker.IsThrottled() && tracker.HasLocalChangePending()) { |
243 has_commit_pending = true; | 250 has_commit_pending = true; |
244 } | 251 } |
| 252 if (!tracker.IsThrottled() && tracker.IsInitialSyncRequired()) { |
| 253 is_initial_sync_required = true; |
| 254 } |
245 } | 255 } |
246 | 256 |
247 if (has_invalidation_pending) { | 257 if (has_invalidation_pending) { |
248 return sync_pb::GetUpdatesCallerInfo::NOTIFICATION; | 258 return sync_pb::GetUpdatesCallerInfo::NOTIFICATION; |
249 } else if (has_refresh_request_pending) { | 259 } else if (has_refresh_request_pending) { |
250 return sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH; | 260 return sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH; |
| 261 } else if (is_initial_sync_required) { |
| 262 // Not quite accurate, but good enough for our purposes. This setting of |
| 263 // SOURCE is just a backward-compatibility hack anyway. |
| 264 return sync_pb::GetUpdatesCallerInfo::DATATYPE_REFRESH; |
251 } else if (has_commit_pending) { | 265 } else if (has_commit_pending) { |
252 return sync_pb::GetUpdatesCallerInfo::LOCAL; | 266 return sync_pb::GetUpdatesCallerInfo::LOCAL; |
253 } else if (has_retry) { | 267 } else if (has_retry) { |
254 return sync_pb::GetUpdatesCallerInfo::RETRY; | 268 return sync_pb::GetUpdatesCallerInfo::RETRY; |
255 } else { | 269 } else { |
256 return sync_pb::GetUpdatesCallerInfo::UNKNOWN; | 270 return sync_pb::GetUpdatesCallerInfo::UNKNOWN; |
257 } | 271 } |
258 } | 272 } |
259 | 273 |
260 void NudgeTracker::FillProtoMessage( | 274 void NudgeTracker::FillProtoMessage( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 it->second->UpdatePayloadBufferSize(size); | 312 it->second->UpdatePayloadBufferSize(size); |
299 } | 313 } |
300 } | 314 } |
301 | 315 |
302 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) { | 316 void NudgeTracker::SetNextRetryTime(base::TimeTicks retry_time) { |
303 next_retry_time_ = retry_time; | 317 next_retry_time_ = retry_time; |
304 } | 318 } |
305 | 319 |
306 } // namespace sessions | 320 } // namespace sessions |
307 } // namespace syncer | 321 } // namespace syncer |
OLD | NEW |