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

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

Issue 232003005: [Sync] Add support for retrying a getupdates due to a context change (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 years, 8 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/directory_update_handler.h" 5 #include "sync/engine/directory_update_handler.h"
6 6
7 #include "sync/engine/conflict_resolver.h" 7 #include "sync/engine/conflict_resolver.h"
8 #include "sync/engine/process_updates_util.h" 8 #include "sync/engine/process_updates_util.h"
9 #include "sync/engine/update_applicator.h" 9 #include "sync/engine/update_applicator.h"
10 #include "sync/sessions/status_controller.h" 10 #include "sync/sessions/status_controller.h"
(...skipping 19 matching lines...) Expand all
30 sync_pb::DataTypeProgressMarker* progress_marker) const { 30 sync_pb::DataTypeProgressMarker* progress_marker) const {
31 dir_->GetDownloadProgress(type_, progress_marker); 31 dir_->GetDownloadProgress(type_, progress_marker);
32 } 32 }
33 33
34 void DirectoryUpdateHandler::GetDataTypeContext( 34 void DirectoryUpdateHandler::GetDataTypeContext(
35 sync_pb::DataTypeContext* context) const { 35 sync_pb::DataTypeContext* context) const {
36 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); 36 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_);
37 dir_->GetDataTypeContext(&trans, type_, context); 37 dir_->GetDataTypeContext(&trans, type_, context);
38 } 38 }
39 39
40 void DirectoryUpdateHandler::ProcessGetUpdatesResponse( 40 SyncerError DirectoryUpdateHandler::ProcessGetUpdatesResponse(
41 const sync_pb::DataTypeProgressMarker& progress_marker, 41 const sync_pb::DataTypeProgressMarker& progress_marker,
42 const sync_pb::DataTypeContext& mutated_context, 42 const sync_pb::DataTypeContext& mutated_context,
43 const SyncEntityList& applicable_updates, 43 const SyncEntityList& applicable_updates,
44 sessions::StatusController* status) { 44 sessions::StatusController* status) {
45 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); 45 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_);
46 UpdateSyncEntities(&trans, applicable_updates, status);
47
48 if (IsValidProgressMarker(progress_marker)) {
49 ExpireEntriesIfNeeded(&trans, progress_marker);
50 UpdateProgressMarker(progress_marker);
51 }
52
53 if (mutated_context.has_context()) { 46 if (mutated_context.has_context()) {
54 sync_pb::DataTypeContext local_context; 47 sync_pb::DataTypeContext local_context;
55 dir_->GetDataTypeContext(&trans, type_, &local_context); 48 dir_->GetDataTypeContext(&trans, type_, &local_context);
56 49
57 // Only update the local context if it is still relevant. If the local 50 // Only update the local context if it is still relevant. If the local
58 // version is higher, it means a local change happened while the mutation 51 // version is higher, it means a local change happened while the mutation
59 // was in flight, and the local context takes priority. 52 // was in flight, and the local context takes priority.
60 if (mutated_context.version() >= local_context.version() && 53 if (mutated_context.version() >= local_context.version() &&
61 local_context.context() != mutated_context.context()) { 54 local_context.context() != mutated_context.context()) {
62 dir_->SetDataTypeContext(&trans, type_, mutated_context); 55 dir_->SetDataTypeContext(&trans, type_, mutated_context);
63 // TODO(zea): trigger the datatype's UpdateDataTypeContext method. 56 // TODO(zea): trigger the datatype's UpdateDataTypeContext method.
57 } else if (mutated_context.version() < local_context.version()) {
58 // A GetUpdates using the old context was in progress when the context was
59 // set. Fail this get updates cycle, to force a retry.
60 DVLOG(1) << "GU Context conflict detected, forcing GU retry.";
61 return DATATYPE_TRIGGERED_RETRY;
64 } 62 }
65 } 63 }
64
65 UpdateSyncEntities(&trans, applicable_updates, status);
66
67 if (IsValidProgressMarker(progress_marker)) {
68 ExpireEntriesIfNeeded(&trans, progress_marker);
69 UpdateProgressMarker(progress_marker);
70 }
71 return SYNCER_OK;
66 } 72 }
67 73
68 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) { 74 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) {
69 if (!IsApplyUpdatesRequired()) { 75 if (!IsApplyUpdatesRequired()) {
70 return; 76 return;
71 } 77 }
72 78
73 // This will invoke handlers that belong to the model and its thread, so we 79 // This will invoke handlers that belong to the model and its thread, so we
74 // switch to the appropriate thread before we start this work. 80 // switch to the appropriate thread before we start this work.
75 WorkCallback c = base::Bind( 81 WorkCallback c = base::Bind(
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 new_gc_directive.version_watermark())) { 227 new_gc_directive.version_watermark())) {
222 ExpireEntriesByVersion(dir_, trans, type_, 228 ExpireEntriesByVersion(dir_, trans, type_,
223 new_gc_directive.version_watermark()); 229 new_gc_directive.version_watermark());
224 } 230 }
225 231
226 cached_gc_directive_.reset( 232 cached_gc_directive_.reset(
227 new sync_pb::GarbageCollectionDirective(new_gc_directive)); 233 new sync_pb::GarbageCollectionDirective(new_gc_directive));
228 } 234 }
229 235
230 } // namespace syncer 236 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698