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

Side by Side Diff: sync/engine/entity_tracker.cc

Issue 442053002: sync: Add non-blocking type encryption (retry) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « sync/engine/entity_tracker.h ('k') | sync/engine/model_type_entity.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/engine/entity_tracker.h" 5 #include "sync/engine/entity_tracker.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "sync/internal_api/public/base/model_type.h" 8 #include "sync/internal_api/public/base/model_type.h"
9 #include "sync/internal_api/public/non_blocking_sync_common.h" 9 #include "sync/internal_api/public/non_blocking_sync_common.h"
10 #include "sync/syncable/syncable_util.h" 10 #include "sync/syncable/syncable_util.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 highest_commit_response_version_ = response_version; 186 highest_commit_response_version_ = response_version;
187 187
188 // Because an in-progress commit blocks the sync thread, we can assume that 188 // Because an in-progress commit blocks the sync thread, we can assume that
189 // the item we just committed successfully is exactly the one we have now. 189 // the item we just committed successfully is exactly the one we have now.
190 // Nothing changed it while the commit was happening. Since we're now in 190 // Nothing changed it while the commit was happening. Since we're now in
191 // sync with the server, we can clear the pending commit. 191 // sync with the server, we can clear the pending commit.
192 ClearPendingCommit(); 192 ClearPendingCommit();
193 } 193 }
194 194
195 void EntityTracker::ReceiveUpdate(int64 version) { 195 void EntityTracker::ReceiveUpdate(int64 version) {
196 highest_gu_response_version_ = 196 if (version <= highest_gu_response_version_)
197 std::max(highest_gu_response_version_, version); 197 return;
198
199 highest_gu_response_version_ = version;
200
201 // Got an applicable update newer than any pending updates. It must be safe
202 // to discard the old pending update, if there was one.
203 ClearPendingUpdate();
198 204
199 if (IsInConflict()) { 205 if (IsInConflict()) {
200 // Incoming update clobbers the pending commit on the sync thread. 206 // Incoming update clobbers the pending commit on the sync thread.
201 // The model thread can re-request this commit later if it wants to. 207 // The model thread can re-request this commit later if it wants to.
202 ClearPendingCommit(); 208 ClearPendingCommit();
203 } 209 }
204 } 210 }
205 211
212 bool EntityTracker::ReceivePendingUpdate(const UpdateResponseData& data) {
213 if (data.response_version < highest_gu_response_version_)
214 return false;
215
216 highest_gu_response_version_ = data.response_version;
217 pending_update_.reset(new UpdateResponseData(data));
218 ClearPendingCommit();
219 return true;
220 }
221
222 bool EntityTracker::HasPendingUpdate() const {
223 return !!pending_update_;
224 }
225
226 UpdateResponseData EntityTracker::GetPendingUpdate() const {
227 return *pending_update_;
228 }
229
230 void EntityTracker::ClearPendingUpdate() {
231 pending_update_.reset();
232 }
233
206 bool EntityTracker::IsInConflict() const { 234 bool EntityTracker::IsInConflict() const {
207 if (!is_commit_pending_) 235 if (!is_commit_pending_)
208 return false; 236 return false;
209 237
238 if (HasPendingUpdate())
239 return true;
240
210 if (highest_gu_response_version_ <= highest_commit_response_version_) { 241 if (highest_gu_response_version_ <= highest_commit_response_version_) {
211 // The most recent server state was created in a commit made by this 242 // The most recent server state was created in a commit made by this
212 // client. We're fully up to date, and therefore not in conflict. 243 // client. We're fully up to date, and therefore not in conflict.
213 return false; 244 return false;
214 } else { 245 } else {
215 // The most recent server state was written by someone else. 246 // The most recent server state was written by someone else.
216 // Did the model thread have the most up to date version when it issued the 247 // Did the model thread have the most up to date version when it issued the
217 // commit request? 248 // commit request?
218 if (base_version_ >= highest_gu_response_version_) { 249 if (base_version_ >= highest_gu_response_version_) {
219 return false; // Yes. 250 return false; // Yes.
220 } else { 251 } else {
221 return true; // No. 252 return true; // No.
222 } 253 }
223 } 254 }
224 } 255 }
225 256
226 bool EntityTracker::IsServerKnown() const { 257 bool EntityTracker::IsServerKnown() const {
227 return base_version_ != kUncommittedVersion; 258 return base_version_ != kUncommittedVersion;
228 } 259 }
229 260
230 void EntityTracker::ClearPendingCommit() { 261 void EntityTracker::ClearPendingCommit() {
231 is_commit_pending_ = false; 262 is_commit_pending_ = false;
232 263
233 // Clearing the specifics might free up some memory. It can't hurt to try. 264 // Clearing the specifics might free up some memory. It can't hurt to try.
234 specifics_.Clear(); 265 specifics_.Clear();
235 } 266 }
236 267
237 } // namespace syncer 268 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/entity_tracker.h ('k') | sync/engine/model_type_entity.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698