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 "base/logging.h" |
| 8 #include "sync/internal_api/public/base/invalidation.h" |
| 9 #include "sync/notifier/single_object_invalidation_set.h" |
8 #include "sync/sessions/nudge_tracker.h" | 10 #include "sync/sessions/nudge_tracker.h" |
9 | 11 |
10 namespace syncer { | 12 namespace syncer { |
11 namespace sessions { | 13 namespace sessions { |
12 | 14 |
13 DataTypeTracker::DataTypeTracker() | 15 DataTypeTracker::DataTypeTracker() |
14 : local_nudge_count_(0), | 16 : local_nudge_count_(0), |
15 local_refresh_request_count_(0), | 17 local_refresh_request_count_(0), |
16 local_payload_overflow_(false), | 18 local_payload_overflow_(false), |
17 server_payload_overflow_(false), | 19 server_payload_overflow_(false), |
18 payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType) { } | 20 payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType) { } |
19 | 21 |
20 DataTypeTracker::~DataTypeTracker() { } | 22 DataTypeTracker::~DataTypeTracker() { } |
21 | 23 |
22 void DataTypeTracker::RecordLocalChange() { | 24 void DataTypeTracker::RecordLocalChange() { |
23 local_nudge_count_++; | 25 local_nudge_count_++; |
24 } | 26 } |
25 | 27 |
26 void DataTypeTracker::RecordLocalRefreshRequest() { | 28 void DataTypeTracker::RecordLocalRefreshRequest() { |
27 local_refresh_request_count_++; | 29 local_refresh_request_count_++; |
28 } | 30 } |
29 | 31 |
30 void DataTypeTracker::RecordRemoteInvalidation( | 32 void DataTypeTracker::RecordRemoteInvalidations( |
31 const std::string& payload) { | 33 const SingleObjectInvalidationSet& invalidations) { |
32 pending_payloads_.push_back(payload); | 34 for (SingleObjectInvalidationSet::const_iterator it = |
33 if (pending_payloads_.size() > payload_buffer_size_) { | 35 invalidations.begin(); it != invalidations.end(); ++it) { |
34 // Drop the oldest payload if we've overflowed. | 36 if (it->is_unknown_version()) { |
35 pending_payloads_.pop_front(); | 37 server_payload_overflow_ = true; |
36 local_payload_overflow_ = true; | 38 } else { |
| 39 pending_payloads_.push_back(it->payload()); |
| 40 if (pending_payloads_.size() > payload_buffer_size_) { |
| 41 // Drop the oldest payload if we've overflowed. |
| 42 pending_payloads_.pop_front(); |
| 43 local_payload_overflow_ = true; |
| 44 } |
| 45 } |
37 } | 46 } |
38 } | 47 } |
39 | 48 |
40 void DataTypeTracker::RecordSuccessfulSyncCycle() { | 49 void DataTypeTracker::RecordSuccessfulSyncCycle() { |
41 // If we were throttled, then we would have been excluded from this cycle's | 50 // If we were throttled, then we would have been excluded from this cycle's |
42 // GetUpdates and Commit actions. Our state remains unchanged. | 51 // GetUpdates and Commit actions. Our state remains unchanged. |
43 if (IsThrottled()) | 52 if (IsThrottled()) |
44 return; | 53 return; |
45 | 54 |
46 local_nudge_count_ = 0; | 55 local_nudge_count_ = 0; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 148 } |
140 | 149 |
141 void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) { | 150 void DataTypeTracker::UpdateThrottleState(base::TimeTicks now) { |
142 if (now >= unthrottle_time_) { | 151 if (now >= unthrottle_time_) { |
143 unthrottle_time_ = base::TimeTicks(); | 152 unthrottle_time_ = base::TimeTicks(); |
144 } | 153 } |
145 } | 154 } |
146 | 155 |
147 } // namespace sessions | 156 } // namespace sessions |
148 } // namespace syncer | 157 } // namespace syncer |
OLD | NEW |