Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: sync/sessions/data_type_tracker.cc

Issue 891123003: Revert of Sync commit errors should temporarily re-enable trigger pre-commit getupdates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/sessions/data_type_tracker.h ('k') | sync/sessions/nudge_tracker.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_interface.h" 8 #include "sync/internal_api/public/base/invalidation_interface.h"
9 #include "sync/sessions/nudge_tracker.h" 9 #include "sync/sessions/nudge_tracker.h"
10 10
11 namespace syncer { 11 namespace syncer {
12 namespace sessions { 12 namespace sessions {
13 13
14 DataTypeTracker::DataTypeTracker() 14 DataTypeTracker::DataTypeTracker()
15 : local_nudge_count_(0), 15 : local_nudge_count_(0),
16 local_refresh_request_count_(0), 16 local_refresh_request_count_(0),
17 payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType), 17 payload_buffer_size_(NudgeTracker::kDefaultMaxPayloadsPerType),
18 initial_sync_required_(false), 18 initial_sync_required_(false) {
19 sync_required_to_resolve_conflict_(false) {
20 } 19 }
21 20
22 DataTypeTracker::~DataTypeTracker() { } 21 DataTypeTracker::~DataTypeTracker() { }
23 22
24 base::TimeDelta DataTypeTracker::RecordLocalChange() { 23 base::TimeDelta DataTypeTracker::RecordLocalChange() {
25 local_nudge_count_++; 24 local_nudge_count_++;
26 return nudge_delay_; 25 return nudge_delay_;
27 } 26 }
28 27
29 void DataTypeTracker::RecordLocalRefreshRequest() { 28 void DataTypeTracker::RecordLocalRefreshRequest() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 last_dropped_invalidation_.reset(pending_invalidations_.front()); 85 last_dropped_invalidation_.reset(pending_invalidations_.front());
87 last_dropped_invalidation_->Drop(); 86 last_dropped_invalidation_->Drop();
88 pending_invalidations_.weak_erase(pending_invalidations_.begin()); 87 pending_invalidations_.weak_erase(pending_invalidations_.begin());
89 } 88 }
90 } 89 }
91 90
92 void DataTypeTracker::RecordInitialSyncRequired() { 91 void DataTypeTracker::RecordInitialSyncRequired() {
93 initial_sync_required_ = true; 92 initial_sync_required_ = true;
94 } 93 }
95 94
96 void DataTypeTracker::RecordCommitConflict() {
97 sync_required_to_resolve_conflict_ = true;
98 }
99
100 void DataTypeTracker::RecordSuccessfulSyncCycle() { 95 void DataTypeTracker::RecordSuccessfulSyncCycle() {
101 // If we were throttled, then we would have been excluded from this cycle's 96 // If we were throttled, then we would have been excluded from this cycle's
102 // GetUpdates and Commit actions. Our state remains unchanged. 97 // GetUpdates and Commit actions. Our state remains unchanged.
103 if (IsThrottled()) 98 if (IsThrottled())
104 return; 99 return;
105 100
106 local_nudge_count_ = 0; 101 local_nudge_count_ = 0;
107 local_refresh_request_count_ = 0; 102 local_refresh_request_count_ = 0;
108 103
109 // TODO(rlarocque): If we want this to be correct even if we should happen to 104 // TODO(rlarocque): If we want this to be correct even if we should happen to
110 // crash before writing all our state, we should wait until the results of 105 // crash before writing all our state, we should wait until the results of
111 // this sync cycle have been written to disk before updating the invalidations 106 // this sync cycle have been written to disk before updating the invalidations
112 // state. See crbug.com/324996. 107 // state. See crbug.com/324996.
113 for (ScopedVector<InvalidationInterface>::const_iterator it = 108 for (ScopedVector<InvalidationInterface>::const_iterator it =
114 pending_invalidations_.begin(); 109 pending_invalidations_.begin();
115 it != pending_invalidations_.end(); 110 it != pending_invalidations_.end();
116 ++it) { 111 ++it) {
117 (*it)->Acknowledge(); 112 (*it)->Acknowledge();
118 } 113 }
119 pending_invalidations_.clear(); 114 pending_invalidations_.clear();
120 115
121 if (last_dropped_invalidation_) { 116 if (last_dropped_invalidation_) {
122 last_dropped_invalidation_->Acknowledge(); 117 last_dropped_invalidation_->Acknowledge();
123 last_dropped_invalidation_.reset(); 118 last_dropped_invalidation_.reset();
124 } 119 }
125 120
126 initial_sync_required_ = false; 121 initial_sync_required_ = false;
127 sync_required_to_resolve_conflict_ = false;
128 } 122 }
129 123
130 // This limit will take effect on all future invalidations received. 124 // This limit will take effect on all future invalidations received.
131 void DataTypeTracker::UpdatePayloadBufferSize(size_t new_size) { 125 void DataTypeTracker::UpdatePayloadBufferSize(size_t new_size) {
132 payload_buffer_size_ = new_size; 126 payload_buffer_size_ = new_size;
133 } 127 }
134 128
135 bool DataTypeTracker::IsSyncRequired() const { 129 bool DataTypeTracker::IsSyncRequired() const {
136 return !IsThrottled() && (HasLocalChangePending() || IsGetUpdatesRequired()); 130 return !IsThrottled() && (HasLocalChangePending() || IsGetUpdatesRequired());
137 } 131 }
138 132
139 bool DataTypeTracker::IsGetUpdatesRequired() const { 133 bool DataTypeTracker::IsGetUpdatesRequired() const {
140 return !IsThrottled() && 134 return !IsThrottled() &&
141 (HasRefreshRequestPending() || HasPendingInvalidation() || 135 (HasRefreshRequestPending() || HasPendingInvalidation() ||
142 IsInitialSyncRequired() || IsSyncRequiredToResolveConflict()); 136 IsInitialSyncRequired());
143 } 137 }
144 138
145 bool DataTypeTracker::HasLocalChangePending() const { 139 bool DataTypeTracker::HasLocalChangePending() const {
146 return local_nudge_count_ > 0; 140 return local_nudge_count_ > 0;
147 } 141 }
148 142
149 bool DataTypeTracker::HasRefreshRequestPending() const { 143 bool DataTypeTracker::HasRefreshRequestPending() const {
150 return local_refresh_request_count_ > 0; 144 return local_refresh_request_count_ > 0;
151 } 145 }
152 146
153 bool DataTypeTracker::HasPendingInvalidation() const { 147 bool DataTypeTracker::HasPendingInvalidation() const {
154 return !pending_invalidations_.empty() || last_dropped_invalidation_; 148 return !pending_invalidations_.empty() || last_dropped_invalidation_;
155 } 149 }
156 150
157 bool DataTypeTracker::IsInitialSyncRequired() const { 151 bool DataTypeTracker::IsInitialSyncRequired() const {
158 return initial_sync_required_; 152 return initial_sync_required_;
159 } 153 }
160 154
161 bool DataTypeTracker::IsSyncRequiredToResolveConflict() const {
162 return sync_required_to_resolve_conflict_;
163 }
164
165 void DataTypeTracker::SetLegacyNotificationHint( 155 void DataTypeTracker::SetLegacyNotificationHint(
166 sync_pb::DataTypeProgressMarker* progress) const { 156 sync_pb::DataTypeProgressMarker* progress) const {
167 DCHECK(!IsThrottled()) 157 DCHECK(!IsThrottled())
168 << "We should not make requests if the type is throttled."; 158 << "We should not make requests if the type is throttled.";
169 159
170 if (!pending_invalidations_.empty() && 160 if (!pending_invalidations_.empty() &&
171 !pending_invalidations_.back()->IsUnknownVersion()) { 161 !pending_invalidations_.back()->IsUnknownVersion()) {
172 // The old-style source info can contain only one hint per type. We grab 162 // The old-style source info can contain only one hint per type. We grab
173 // the most recent, to mimic the old coalescing behaviour. 163 // the most recent, to mimic the old coalescing behaviour.
174 progress->set_notification_hint( 164 progress->set_notification_hint(
(...skipping 20 matching lines...) Expand all
195 } 185 }
196 } 186 }
197 187
198 msg->set_server_dropped_hints( 188 msg->set_server_dropped_hints(
199 !pending_invalidations_.empty() && 189 !pending_invalidations_.empty() &&
200 (*pending_invalidations_.begin())->IsUnknownVersion()); 190 (*pending_invalidations_.begin())->IsUnknownVersion());
201 msg->set_client_dropped_hints(last_dropped_invalidation_); 191 msg->set_client_dropped_hints(last_dropped_invalidation_);
202 msg->set_local_modification_nudges(local_nudge_count_); 192 msg->set_local_modification_nudges(local_nudge_count_);
203 msg->set_datatype_refresh_nudges(local_refresh_request_count_); 193 msg->set_datatype_refresh_nudges(local_refresh_request_count_);
204 msg->set_initial_sync_in_progress(initial_sync_required_); 194 msg->set_initial_sync_in_progress(initial_sync_required_);
205 msg->set_sync_for_resolve_conflict_in_progress(
206 sync_required_to_resolve_conflict_);
207 } 195 }
208 196
209 bool DataTypeTracker::IsThrottled() const { 197 bool DataTypeTracker::IsThrottled() const {
210 return !unthrottle_time_.is_null(); 198 return !unthrottle_time_.is_null();
211 } 199 }
212 200
213 base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle( 201 base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle(
214 base::TimeTicks now) const { 202 base::TimeTicks now) const {
215 if (!IsThrottled()) { 203 if (!IsThrottled()) {
216 NOTREACHED(); 204 NOTREACHED();
(...skipping 13 matching lines...) Expand all
230 unthrottle_time_ = base::TimeTicks(); 218 unthrottle_time_ = base::TimeTicks();
231 } 219 }
232 } 220 }
233 221
234 void DataTypeTracker::UpdateLocalNudgeDelay(base::TimeDelta delay) { 222 void DataTypeTracker::UpdateLocalNudgeDelay(base::TimeDelta delay) {
235 nudge_delay_ = delay; 223 nudge_delay_ = delay;
236 } 224 }
237 225
238 } // namespace sessions 226 } // namespace sessions
239 } // namespace syncer 227 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sessions/data_type_tracker.h ('k') | sync/sessions/nudge_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698