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

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

Issue 423193002: sync: Add non-blocking type encryption support (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
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_) {
Nicolas Zea 2014/07/30 00:34:15 It seems like it might be better to do: if (versio
rlarocque 2014/07/30 21:56:00 Done.
197 std::max(highest_gu_response_version_, version); 197 highest_gu_response_version_ = version;
198
199 // Got an applicable update newer than any inapplicable updates. It must
200 // be safe to discard the old inapplicable update, if there was one.
201 ClearInapplicableUpdate();
202 }
198 203
199 if (IsInConflict()) { 204 if (IsInConflict()) {
200 // Incoming update clobbers the pending commit on the sync thread. 205 // Incoming update clobbers the pending commit on the sync thread.
201 // The model thread can re-request this commit later if it wants to. 206 // The model thread can re-request this commit later if it wants to.
202 ClearPendingCommit(); 207 ClearPendingCommit();
203 } 208 }
204 } 209 }
205 210
211 bool EntityTracker::ReceiveInapplicableUpdate(const UpdateResponseData& data) {
212 if (data.response_version >= highest_gu_response_version_) {
Nicolas Zea 2014/07/30 00:34:15 nit: I find it cleaner to just return early here t
rlarocque 2014/07/30 21:56:00 Done.
213 highest_gu_response_version_ = data.response_version;
214 inapplicable_update_.reset(new UpdateResponseData(data));
215 ClearPendingCommit();
216 return true;
217 }
218 return false;
219 }
220
221 bool EntityTracker::HasInapplicableUpdate() const {
222 return !!inapplicable_update_;
223 }
224
225 UpdateResponseData EntityTracker::GetInapplicableUpdate() const {
226 return *inapplicable_update_;
227 }
228
229 void EntityTracker::ClearInapplicableUpdate() {
230 inapplicable_update_.reset();
231 }
232
206 bool EntityTracker::IsInConflict() const { 233 bool EntityTracker::IsInConflict() const {
207 if (!is_commit_pending_) 234 if (!is_commit_pending_)
208 return false; 235 return false;
209 236
237 if (HasInapplicableUpdate())
238 return true;
239
210 if (highest_gu_response_version_ <= highest_commit_response_version_) { 240 if (highest_gu_response_version_ <= highest_commit_response_version_) {
211 // The most recent server state was created in a commit made by this 241 // 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. 242 // client. We're fully up to date, and therefore not in conflict.
213 return false; 243 return false;
214 } else { 244 } else {
215 // The most recent server state was written by someone else. 245 // 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 246 // Did the model thread have the most up to date version when it issued the
217 // commit request? 247 // commit request?
218 if (base_version_ >= highest_gu_response_version_) { 248 if (base_version_ >= highest_gu_response_version_) {
219 return false; // Yes. 249 return false; // Yes.
220 } else { 250 } else {
221 return true; // No. 251 return true; // No.
222 } 252 }
223 } 253 }
224 } 254 }
225 255
226 bool EntityTracker::IsServerKnown() const { 256 bool EntityTracker::IsServerKnown() const {
227 return base_version_ != kUncommittedVersion; 257 return base_version_ != kUncommittedVersion;
228 } 258 }
229 259
230 void EntityTracker::ClearPendingCommit() { 260 void EntityTracker::ClearPendingCommit() {
231 is_commit_pending_ = false; 261 is_commit_pending_ = false;
232 262
233 // Clearing the specifics might free up some memory. It can't hurt to try. 263 // Clearing the specifics might free up some memory. It can't hurt to try.
234 specifics_.Clear(); 264 specifics_.Clear();
235 } 265 }
236 266
237 } // namespace syncer 267 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698