| 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/internal_api/public/sessions/sync_source_info.h" | |
| 10 #include "sync/protocol/sync.pb.h" | 9 #include "sync/protocol/sync.pb.h" |
| 11 | 10 |
| 12 namespace syncer { | 11 namespace syncer { |
| 13 namespace sessions { | 12 namespace sessions { |
| 14 | 13 |
| 15 size_t NudgeTracker::kDefaultMaxPayloadsPerType = 10; | 14 size_t NudgeTracker::kDefaultMaxPayloadsPerType = 10; |
| 16 | 15 |
| 17 NudgeTracker::NudgeTracker() | 16 NudgeTracker::NudgeTracker() |
| 18 : updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), | 17 : updates_source_(sync_pb::GetUpdatesCallerInfo::UNKNOWN), |
| 19 invalidations_enabled_(false), | 18 invalidations_enabled_(false), |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ModelTypeSet result; | 168 ModelTypeSet result; |
| 170 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | 169 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); |
| 171 it != type_trackers_.end(); ++it) { | 170 it != type_trackers_.end(); ++it) { |
| 172 if (it->second.IsThrottled()) { | 171 if (it->second.IsThrottled()) { |
| 173 result.Put(it->first); | 172 result.Put(it->first); |
| 174 } | 173 } |
| 175 } | 174 } |
| 176 return result; | 175 return result; |
| 177 } | 176 } |
| 178 | 177 |
| 179 // This function is intended to mimic the behavior of older clients. Newer | |
| 180 // clients and servers will not rely on SyncSourceInfo. See FillProtoMessage | |
| 181 // for the more modern equivalent. | |
| 182 SyncSourceInfo NudgeTracker::GetSourceInfo() const { | |
| 183 ModelTypeInvalidationMap invalidation_map; | |
| 184 for (TypeTrackerMap::const_iterator it = type_trackers_.begin(); | |
| 185 it != type_trackers_.end(); ++it) { | |
| 186 if (it->second.IsThrottled()) { | |
| 187 // We pretend throttled types are not enabled by skipping them. | |
| 188 continue; | |
| 189 } else if (it->second.HasPendingInvalidation()) { | |
| 190 // The old-style source info can contain only one hint per type. We grab | |
| 191 // the most recent, to mimic the old coalescing behaviour. | |
| 192 Invalidation invalidation; | |
| 193 invalidation.payload = it->second.GetMostRecentInvalidationPayload(); | |
| 194 invalidation_map.insert(std::make_pair(it->first, invalidation)); | |
| 195 } else if (it->second.HasLocalChangePending()) { | |
| 196 // The old-style source info sent up an empty string (as opposed to | |
| 197 // nothing at all) when the type was locally nudged, but had not received | |
| 198 // any invalidations. | |
| 199 Invalidation invalidation; | |
| 200 invalidation.payload = ""; | |
| 201 invalidation_map.insert(std::make_pair(it->first, invalidation)); | |
| 202 } | |
| 203 } | |
| 204 | |
| 205 return SyncSourceInfo(updates_source_, invalidation_map); | |
| 206 } | |
| 207 | |
| 208 void NudgeTracker::SetLegacyNotificationHint( | 178 void NudgeTracker::SetLegacyNotificationHint( |
| 209 ModelType type, | 179 ModelType type, |
| 210 sync_pb::DataTypeProgressMarker* progress) const { | 180 sync_pb::DataTypeProgressMarker* progress) const { |
| 211 DCHECK(type_trackers_.find(type) != type_trackers_.end()); | 181 DCHECK(type_trackers_.find(type) != type_trackers_.end()); |
| 212 type_trackers_.find(type)->second.SetLegacyNotificationHint(progress); | 182 type_trackers_.find(type)->second.SetLegacyNotificationHint(progress); |
| 213 } | 183 } |
| 214 | 184 |
| 215 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource NudgeTracker::updates_source() | 185 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource NudgeTracker::updates_source() |
| 216 const { | 186 const { |
| 217 return updates_source_; | 187 return updates_source_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 231 | 201 |
| 232 void NudgeTracker::SetHintBufferSize(size_t size) { | 202 void NudgeTracker::SetHintBufferSize(size_t size) { |
| 233 for (TypeTrackerMap::iterator it = type_trackers_.begin(); | 203 for (TypeTrackerMap::iterator it = type_trackers_.begin(); |
| 234 it != type_trackers_.end(); ++it) { | 204 it != type_trackers_.end(); ++it) { |
| 235 it->second.UpdatePayloadBufferSize(size); | 205 it->second.UpdatePayloadBufferSize(size); |
| 236 } | 206 } |
| 237 } | 207 } |
| 238 | 208 |
| 239 } // namespace sessions | 209 } // namespace sessions |
| 240 } // namespace syncer | 210 } // namespace syncer |
| OLD | NEW |