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 "components/sync/sessions_impl/data_type_tracker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "sync/internal_api/public/base/invalidation_interface.h" | 12 #include "components/sync/base/invalidation_interface.h" |
13 #include "sync/sessions/nudge_tracker.h" | 13 #include "components/sync/sessions_impl/nudge_tracker.h" |
14 | 14 |
15 namespace syncer { | 15 namespace syncer { |
16 namespace sessions { | 16 namespace sessions { |
17 | 17 |
18 DataTypeTracker::DataTypeTracker() | 18 DataTypeTracker::DataTypeTracker() |
19 : local_nudge_count_(0), | 19 : local_nudge_count_(0), |
20 local_refresh_request_count_(0), | 20 local_refresh_request_count_(0), |
21 payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType), | 21 payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType), |
22 initial_sync_required_(false), | 22 initial_sync_required_(false), |
23 sync_required_to_resolve_conflict_(false) { | 23 sync_required_to_resolve_conflict_(false) {} |
24 } | |
25 | 24 |
26 DataTypeTracker::~DataTypeTracker() { } | 25 DataTypeTracker::~DataTypeTracker() {} |
27 | 26 |
28 base::TimeDelta DataTypeTracker::RecordLocalChange() { | 27 base::TimeDelta DataTypeTracker::RecordLocalChange() { |
29 local_nudge_count_++; | 28 local_nudge_count_++; |
30 return nudge_delay_; | 29 return nudge_delay_; |
31 } | 30 } |
32 | 31 |
33 void DataTypeTracker::RecordLocalRefreshRequest() { | 32 void DataTypeTracker::RecordLocalRefreshRequest() { |
34 local_refresh_request_count_++; | 33 local_refresh_request_count_++; |
35 } | 34 } |
36 | 35 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 108 |
110 local_nudge_count_ = 0; | 109 local_nudge_count_ = 0; |
111 local_refresh_request_count_ = 0; | 110 local_refresh_request_count_ = 0; |
112 | 111 |
113 // TODO(rlarocque): If we want this to be correct even if we should happen to | 112 // TODO(rlarocque): If we want this to be correct even if we should happen to |
114 // crash before writing all our state, we should wait until the results of | 113 // crash before writing all our state, we should wait until the results of |
115 // this sync cycle have been written to disk before updating the invalidations | 114 // this sync cycle have been written to disk before updating the invalidations |
116 // state. See crbug.com/324996. | 115 // state. See crbug.com/324996. |
117 for (ScopedVector<InvalidationInterface>::const_iterator it = | 116 for (ScopedVector<InvalidationInterface>::const_iterator it = |
118 pending_invalidations_.begin(); | 117 pending_invalidations_.begin(); |
119 it != pending_invalidations_.end(); | 118 it != pending_invalidations_.end(); ++it) { |
120 ++it) { | |
121 (*it)->Acknowledge(); | 119 (*it)->Acknowledge(); |
122 } | 120 } |
123 pending_invalidations_.clear(); | 121 pending_invalidations_.clear(); |
124 | 122 |
125 if (last_dropped_invalidation_) { | 123 if (last_dropped_invalidation_) { |
126 last_dropped_invalidation_->Acknowledge(); | 124 last_dropped_invalidation_->Acknowledge(); |
127 last_dropped_invalidation_.reset(); | 125 last_dropped_invalidation_.reset(); |
128 } | 126 } |
129 | 127 |
130 initial_sync_required_ = false; | 128 initial_sync_required_ = false; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 183 } |
186 } | 184 } |
187 | 185 |
188 void DataTypeTracker::FillGetUpdatesTriggersMessage( | 186 void DataTypeTracker::FillGetUpdatesTriggersMessage( |
189 sync_pb::GetUpdateTriggers* msg) const { | 187 sync_pb::GetUpdateTriggers* msg) const { |
190 // Fill the list of payloads, if applicable. The payloads must be ordered | 188 // Fill the list of payloads, if applicable. The payloads must be ordered |
191 // oldest to newest, so we insert them in the same order as we've been storing | 189 // oldest to newest, so we insert them in the same order as we've been storing |
192 // them internally. | 190 // them internally. |
193 for (ScopedVector<InvalidationInterface>::const_iterator it = | 191 for (ScopedVector<InvalidationInterface>::const_iterator it = |
194 pending_invalidations_.begin(); | 192 pending_invalidations_.begin(); |
195 it != pending_invalidations_.end(); | 193 it != pending_invalidations_.end(); ++it) { |
196 ++it) { | |
197 if (!(*it)->IsUnknownVersion()) { | 194 if (!(*it)->IsUnknownVersion()) { |
198 msg->add_notification_hint((*it)->GetPayload()); | 195 msg->add_notification_hint((*it)->GetPayload()); |
199 } | 196 } |
200 } | 197 } |
201 | 198 |
202 msg->set_server_dropped_hints( | 199 msg->set_server_dropped_hints( |
203 !pending_invalidations_.empty() && | 200 !pending_invalidations_.empty() && |
204 (*pending_invalidations_.begin())->IsUnknownVersion()); | 201 (*pending_invalidations_.begin())->IsUnknownVersion()); |
205 msg->set_client_dropped_hints(!!last_dropped_invalidation_); | 202 msg->set_client_dropped_hints(!!last_dropped_invalidation_); |
206 msg->set_local_modification_nudges(local_nudge_count_); | 203 msg->set_local_modification_nudges(local_nudge_count_); |
207 msg->set_datatype_refresh_nudges(local_refresh_request_count_); | 204 msg->set_datatype_refresh_nudges(local_refresh_request_count_); |
208 msg->set_initial_sync_in_progress(initial_sync_required_); | 205 msg->set_initial_sync_in_progress(initial_sync_required_); |
209 msg->set_sync_for_resolve_conflict_in_progress( | 206 msg->set_sync_for_resolve_conflict_in_progress( |
210 sync_required_to_resolve_conflict_); | 207 sync_required_to_resolve_conflict_); |
211 } | 208 } |
212 | 209 |
213 bool DataTypeTracker::IsThrottled() const { | 210 bool DataTypeTracker::IsThrottled() const { |
214 return !unthrottle_time_.is_null(); | 211 return !unthrottle_time_.is_null(); |
215 } | 212 } |
216 | 213 |
217 base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle( | 214 base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle( |
218 base::TimeTicks now) const { | 215 base::TimeTicks now) const { |
219 if (!IsThrottled()) { | 216 if (!IsThrottled()) { |
220 NOTREACHED(); | 217 NOTREACHED(); |
221 return base::TimeDelta::FromSeconds(0); | 218 return base::TimeDelta::FromSeconds(0); |
222 } | 219 } |
223 return std::max(base::TimeDelta::FromSeconds(0), | 220 return std::max(base::TimeDelta::FromSeconds(0), unthrottle_time_ - now); |
224 unthrottle_time_ - now); | |
225 } | 221 } |
226 | 222 |
227 void DataTypeTracker::ThrottleType(base::TimeDelta duration, | 223 void DataTypeTracker::ThrottleType(base::TimeDelta duration, |
228 base::TimeTicks now) { | 224 base::TimeTicks now) { |
229 unthrottle_time_ = std::max(unthrottle_time_, now + duration); | 225 unthrottle_time_ = std::max(unthrottle_time_, now + duration); |
230 } | 226 } |
231 | 227 |
232 void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) { | 228 void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) { |
233 if (now >= unthrottle_time_) { | 229 if (now >= unthrottle_time_) { |
234 unthrottle_time_ = base::TimeTicks(); | 230 unthrottle_time_ = base::TimeTicks(); |
235 } | 231 } |
236 } | 232 } |
237 | 233 |
238 void DataTypeTracker::UpdateLocalNudgeDelay(base::TimeDelta delay) { | 234 void DataTypeTracker::UpdateLocalNudgeDelay(base::TimeDelta delay) { |
239 nudge_delay_ = delay; | 235 nudge_delay_ = delay; |
240 } | 236 } |
241 | 237 |
242 } // namespace sessions | 238 } // namespace sessions |
243 } // namespace syncer | 239 } // namespace syncer |
OLD | NEW |