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

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

Issue 905853002: 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) {
19 } 20 }
20 21
21 DataTypeTracker::~DataTypeTracker() { } 22 DataTypeTracker::~DataTypeTracker() { }
22 23
23 base::TimeDelta DataTypeTracker::RecordLocalChange() { 24 base::TimeDelta DataTypeTracker::RecordLocalChange() {
24 local_nudge_count_++; 25 local_nudge_count_++;
25 return nudge_delay_; 26 return nudge_delay_;
26 } 27 }
27 28
28 void DataTypeTracker::RecordLocalRefreshRequest() { 29 void DataTypeTracker::RecordLocalRefreshRequest() {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 last_dropped_invalidation_.reset(pending_invalidations_.front()); 86 last_dropped_invalidation_.reset(pending_invalidations_.front());
86 last_dropped_invalidation_->Drop(); 87 last_dropped_invalidation_->Drop();
87 pending_invalidations_.weak_erase(pending_invalidations_.begin()); 88 pending_invalidations_.weak_erase(pending_invalidations_.begin());
88 } 89 }
89 } 90 }
90 91
91 void DataTypeTracker::RecordInitialSyncRequired() { 92 void DataTypeTracker::RecordInitialSyncRequired() {
92 initial_sync_required_ = true; 93 initial_sync_required_ = true;
93 } 94 }
94 95
96 void DataTypeTracker::RecordCommitConflict() {
97 sync_required_to_resolve_conflict_ = true;
98 }
99
95 void DataTypeTracker::RecordSuccessfulSyncCycle() { 100 void DataTypeTracker::RecordSuccessfulSyncCycle() {
96 // If we were throttled, then we would have been excluded from this cycle's 101 // If we were throttled, then we would have been excluded from this cycle's
97 // GetUpdates and Commit actions. Our state remains unchanged. 102 // GetUpdates and Commit actions. Our state remains unchanged.
98 if (IsThrottled()) 103 if (IsThrottled())
99 return; 104 return;
100 105
101 local_nudge_count_ = 0; 106 local_nudge_count_ = 0;
102 local_refresh_request_count_ = 0; 107 local_refresh_request_count_ = 0;
103 108
104 // TODO(rlarocque): If we want this to be correct even if we should happen to 109 // TODO(rlarocque): If we want this to be correct even if we should happen to
105 // crash before writing all our state, we should wait until the results of 110 // crash before writing all our state, we should wait until the results of
106 // this sync cycle have been written to disk before updating the invalidations 111 // this sync cycle have been written to disk before updating the invalidations
107 // state. See crbug.com/324996. 112 // state. See crbug.com/324996.
108 for (ScopedVector<InvalidationInterface>::const_iterator it = 113 for (ScopedVector<InvalidationInterface>::const_iterator it =
109 pending_invalidations_.begin(); 114 pending_invalidations_.begin();
110 it != pending_invalidations_.end(); 115 it != pending_invalidations_.end();
111 ++it) { 116 ++it) {
112 (*it)->Acknowledge(); 117 (*it)->Acknowledge();
113 } 118 }
114 pending_invalidations_.clear(); 119 pending_invalidations_.clear();
115 120
116 if (last_dropped_invalidation_) { 121 if (last_dropped_invalidation_) {
117 last_dropped_invalidation_->Acknowledge(); 122 last_dropped_invalidation_->Acknowledge();
118 last_dropped_invalidation_.reset(); 123 last_dropped_invalidation_.reset();
119 } 124 }
120 125
121 initial_sync_required_ = false; 126 initial_sync_required_ = false;
127 sync_required_to_resolve_conflict_ = false;
122 } 128 }
123 129
124 // This limit will take effect on all future invalidations received. 130 // This limit will take effect on all future invalidations received.
125 void DataTypeTracker::UpdatePayloadBufferSize(size_t new_size) { 131 void DataTypeTracker::UpdatePayloadBufferSize(size_t new_size) {
126 payload_buffer_size_ = new_size; 132 payload_buffer_size_ = new_size;
127 } 133 }
128 134
129 bool DataTypeTracker::IsSyncRequired() const { 135 bool DataTypeTracker::IsSyncRequired() const {
130 return !IsThrottled() && (HasLocalChangePending() || IsGetUpdatesRequired()); 136 return !IsThrottled() && (HasLocalChangePending() || IsGetUpdatesRequired());
131 } 137 }
132 138
133 bool DataTypeTracker::IsGetUpdatesRequired() const { 139 bool DataTypeTracker::IsGetUpdatesRequired() const {
134 return !IsThrottled() && 140 return !IsThrottled() &&
135 (HasRefreshRequestPending() || HasPendingInvalidation() || 141 (HasRefreshRequestPending() || HasPendingInvalidation() ||
136 IsInitialSyncRequired()); 142 IsInitialSyncRequired() || IsSyncRequiredToResolveConflict());
137 } 143 }
138 144
139 bool DataTypeTracker::HasLocalChangePending() const { 145 bool DataTypeTracker::HasLocalChangePending() const {
140 return local_nudge_count_ > 0; 146 return local_nudge_count_ > 0;
141 } 147 }
142 148
143 bool DataTypeTracker::HasRefreshRequestPending() const { 149 bool DataTypeTracker::HasRefreshRequestPending() const {
144 return local_refresh_request_count_ > 0; 150 return local_refresh_request_count_ > 0;
145 } 151 }
146 152
147 bool DataTypeTracker::HasPendingInvalidation() const { 153 bool DataTypeTracker::HasPendingInvalidation() const {
148 return !pending_invalidations_.empty() || last_dropped_invalidation_; 154 return !pending_invalidations_.empty() || last_dropped_invalidation_;
149 } 155 }
150 156
151 bool DataTypeTracker::IsInitialSyncRequired() const { 157 bool DataTypeTracker::IsInitialSyncRequired() const {
152 return initial_sync_required_; 158 return initial_sync_required_;
153 } 159 }
154 160
161 bool DataTypeTracker::IsSyncRequiredToResolveConflict() const {
162 return sync_required_to_resolve_conflict_;
163 }
164
155 void DataTypeTracker::SetLegacyNotificationHint( 165 void DataTypeTracker::SetLegacyNotificationHint(
156 sync_pb::DataTypeProgressMarker* progress) const { 166 sync_pb::DataTypeProgressMarker* progress) const {
157 DCHECK(!IsThrottled()) 167 DCHECK(!IsThrottled())
158 << "We should not make requests if the type is throttled."; 168 << "We should not make requests if the type is throttled.";
159 169
160 if (!pending_invalidations_.empty() && 170 if (!pending_invalidations_.empty() &&
161 !pending_invalidations_.back()->IsUnknownVersion()) { 171 !pending_invalidations_.back()->IsUnknownVersion()) {
162 // The old-style source info can contain only one hint per type. We grab 172 // The old-style source info can contain only one hint per type. We grab
163 // the most recent, to mimic the old coalescing behaviour. 173 // the most recent, to mimic the old coalescing behaviour.
164 progress->set_notification_hint( 174 progress->set_notification_hint(
(...skipping 20 matching lines...) Expand all
185 } 195 }
186 } 196 }
187 197
188 msg->set_server_dropped_hints( 198 msg->set_server_dropped_hints(
189 !pending_invalidations_.empty() && 199 !pending_invalidations_.empty() &&
190 (*pending_invalidations_.begin())->IsUnknownVersion()); 200 (*pending_invalidations_.begin())->IsUnknownVersion());
191 msg->set_client_dropped_hints(last_dropped_invalidation_); 201 msg->set_client_dropped_hints(last_dropped_invalidation_);
192 msg->set_local_modification_nudges(local_nudge_count_); 202 msg->set_local_modification_nudges(local_nudge_count_);
193 msg->set_datatype_refresh_nudges(local_refresh_request_count_); 203 msg->set_datatype_refresh_nudges(local_refresh_request_count_);
194 msg->set_initial_sync_in_progress(initial_sync_required_); 204 msg->set_initial_sync_in_progress(initial_sync_required_);
205 msg->set_sync_for_resolve_conflict_in_progress(
206 sync_required_to_resolve_conflict_);
195 } 207 }
196 208
197 bool DataTypeTracker::IsThrottled() const { 209 bool DataTypeTracker::IsThrottled() const {
198 return !unthrottle_time_.is_null(); 210 return !unthrottle_time_.is_null();
199 } 211 }
200 212
201 base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle( 213 base::TimeDelta DataTypeTracker::GetTimeUntilUnthrottle(
202 base::TimeTicks now) const { 214 base::TimeTicks now) const {
203 if (!IsThrottled()) { 215 if (!IsThrottled()) {
204 NOTREACHED(); 216 NOTREACHED();
(...skipping 13 matching lines...) Expand all
218 unthrottle_time_ = base::TimeTicks(); 230 unthrottle_time_ = base::TimeTicks();
219 } 231 }
220 } 232 }
221 233
222 void DataTypeTracker::UpdateLocalNudgeDelay(base::TimeDelta delay) { 234 void DataTypeTracker::UpdateLocalNudgeDelay(base::TimeDelta delay) {
223 nudge_delay_ = delay; 235 nudge_delay_ = delay;
224 } 236 }
225 237
226 } // namespace sessions 238 } // namespace sessions
227 } // namespace syncer 239 } // 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