OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/data_type_tracker.h" | 5 #include "sync/sessions/data_type_tracker.h" |
6 | 6 |
| 7 #include "base/logging.h" |
7 #include "sync/sessions/nudge_tracker.h" | 8 #include "sync/sessions/nudge_tracker.h" |
8 | 9 |
9 namespace syncer { | 10 namespace syncer { |
10 namespace sessions { | 11 namespace sessions { |
11 | 12 |
12 DataTypeTracker::DataTypeTracker() | 13 DataTypeTracker::DataTypeTracker() |
13 : local_nudge_count_(0), | 14 : local_nudge_count_(0), |
14 local_refresh_request_count_(0), | 15 local_refresh_request_count_(0), |
15 local_payload_overflow_(false), | 16 local_payload_overflow_(false), |
16 server_payload_overflow_(false), | 17 server_payload_overflow_(false), |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 67 } |
67 | 68 |
68 bool DataTypeTracker::HasPendingInvalidation() const { | 69 bool DataTypeTracker::HasPendingInvalidation() const { |
69 return !pending_payloads_.empty(); | 70 return !pending_payloads_.empty(); |
70 } | 71 } |
71 | 72 |
72 std::string DataTypeTracker::GetMostRecentInvalidationPayload() const { | 73 std::string DataTypeTracker::GetMostRecentInvalidationPayload() const { |
73 return pending_payloads_.back(); | 74 return pending_payloads_.back(); |
74 } | 75 } |
75 | 76 |
| 77 void DataTypeTracker::SetLegacyNotificationHint( |
| 78 sync_pb::DataTypeProgressMarker* progress) const { |
| 79 DCHECK(!IsThrottled()) |
| 80 << "We should not make requests if the type is throttled."; |
| 81 |
| 82 if (HasPendingInvalidation()) { |
| 83 // The old-style source info can contain only one hint per type. We grab |
| 84 // the most recent, to mimic the old coalescing behaviour. |
| 85 progress->set_notification_hint(GetMostRecentInvalidationPayload()); |
| 86 } else if (HasLocalChangePending()) { |
| 87 // The old-style source info sent up an empty string (as opposed to |
| 88 // nothing at all) when the type was locally nudged, but had not received |
| 89 // any invalidations. |
| 90 progress->set_notification_hint(""); |
| 91 } |
| 92 } |
| 93 |
76 void DataTypeTracker::FillGetUpdatesTriggersMessage( | 94 void DataTypeTracker::FillGetUpdatesTriggersMessage( |
77 sync_pb::GetUpdateTriggers* msg) const { | 95 sync_pb::GetUpdateTriggers* msg) const { |
78 // Fill the list of payloads, if applicable. The payloads must be ordered | 96 // Fill the list of payloads, if applicable. The payloads must be ordered |
79 // oldest to newest, so we insert them in the same order as we've been storing | 97 // oldest to newest, so we insert them in the same order as we've been storing |
80 // them internally. | 98 // them internally. |
81 for (PayloadList::const_iterator payload_it = pending_payloads_.begin(); | 99 for (PayloadList::const_iterator payload_it = pending_payloads_.begin(); |
82 payload_it != pending_payloads_.end(); ++payload_it) { | 100 payload_it != pending_payloads_.end(); ++payload_it) { |
83 msg->add_notification_hint(*payload_it); | 101 msg->add_notification_hint(*payload_it); |
84 } | 102 } |
85 | 103 |
(...skipping 25 matching lines...) Expand all Loading... |
111 } | 129 } |
112 | 130 |
113 void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) { | 131 void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) { |
114 if (now >= unthrottle_time_) { | 132 if (now >= unthrottle_time_) { |
115 unthrottle_time_ = base::TimeTicks(); | 133 unthrottle_time_ = base::TimeTicks(); |
116 } | 134 } |
117 } | 135 } |
118 | 136 |
119 } // namespace sessions | 137 } // namespace sessions |
120 } // namespace syncer | 138 } // namespace syncer |
OLD | NEW |