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

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

Issue 1393633003: Sync: fix for the code that checks whether the initial download has completed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR feedback Created 5 years, 2 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
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/directory_type_debug_info_emitter.h" 10 #include "sync/sessions/directory_type_debug_info_emitter.h"
11 #include "sync/syncable/directory.h" 11 #include "sync/syncable/directory.h"
12 #include "sync/syncable/model_neutral_mutable_entry.h" 12 #include "sync/syncable/model_neutral_mutable_entry.h"
13 #include "sync/syncable/syncable_changes_version.h"
13 #include "sync/syncable/syncable_model_neutral_write_transaction.h" 14 #include "sync/syncable/syncable_model_neutral_write_transaction.h"
14 #include "sync/syncable/syncable_write_transaction.h" 15 #include "sync/syncable/syncable_write_transaction.h"
15 #include "sync/util/data_type_histogram.h" 16 #include "sync/util/data_type_histogram.h"
16 17
17 namespace syncer { 18 namespace syncer {
18 19
19 using syncable::SYNCER; 20 using syncable::SYNCER;
20 21
21 DirectoryUpdateHandler::DirectoryUpdateHandler( 22 DirectoryUpdateHandler::DirectoryUpdateHandler(
22 syncable::Directory* dir, 23 syncable::Directory* dir,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 DVLOG(1) << "Type root folder " << ModelTypeToRootTag(type_) 103 DVLOG(1) << "Type root folder " << ModelTypeToRootTag(type_)
103 << " already exists."; 104 << " already exists.";
104 return; 105 return;
105 } 106 }
106 107
107 entry.PutServerIsDir(true); 108 entry.PutServerIsDir(true);
108 entry.PutUniqueServerTag(ModelTypeToRootTag(type_)); 109 entry.PutUniqueServerTag(ModelTypeToRootTag(type_));
109 } 110 }
110 111
111 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) { 112 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) {
112 if (!IsApplyUpdatesRequired()) { 113 if (IsApplyUpdatesRequired()) {
113 return; 114 // This will invoke handlers that belong to the model and its thread, so we
115 // switch to the appropriate thread before we start this work.
116 WorkCallback c =
117 base::Bind(&DirectoryUpdateHandler::ApplyUpdatesImpl,
118 // We wait until the callback is executed. We can safely use
119 // Unretained.
120 base::Unretained(this), base::Unretained(status));
121 worker_->DoWorkAndWaitUntilDone(c);
122
123 debug_info_emitter_->EmitUpdateCountersUpdate();
124 debug_info_emitter_->EmitStatusCountersUpdate();
114 } 125 }
115 126
116 // This will invoke handlers that belong to the model and its thread, so we 127 PostApplyUpdates();
117 // switch to the appropriate thread before we start this work.
118 WorkCallback c = base::Bind(
119 &DirectoryUpdateHandler::ApplyUpdatesImpl,
120 // We wait until the callback is executed. We can safely use Unretained.
121 base::Unretained(this),
122 base::Unretained(status));
123 worker_->DoWorkAndWaitUntilDone(c);
124
125 debug_info_emitter_->EmitUpdateCountersUpdate();
126 debug_info_emitter_->EmitStatusCountersUpdate();
127 } 128 }
128 129
129 void DirectoryUpdateHandler::PassiveApplyUpdates( 130 void DirectoryUpdateHandler::PassiveApplyUpdates(
130 sessions::StatusController* status) { 131 sessions::StatusController* status) {
131 if (!IsApplyUpdatesRequired()) { 132 if (IsApplyUpdatesRequired()) {
132 return; 133 // Just do the work here instead of deferring to another thread.
134 ApplyUpdatesImpl(status);
135
136 debug_info_emitter_->EmitUpdateCountersUpdate();
137 debug_info_emitter_->EmitStatusCountersUpdate();
133 } 138 }
134 139
135 // Just do the work here instead of deferring to another thread. 140 PostApplyUpdates();
136 ApplyUpdatesImpl(status);
137
138 debug_info_emitter_->EmitUpdateCountersUpdate();
139 debug_info_emitter_->EmitStatusCountersUpdate();
140 } 141 }
141 142
142 SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl( 143 SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl(
143 sessions::StatusController* status) { 144 sessions::StatusController* status) {
144 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_); 145 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_);
145 146
146 std::vector<int64> handles; 147 std::vector<int64> handles;
147 dir_->GetUnappliedUpdateMetaHandles( 148 dir_->GetUnappliedUpdateMetaHandles(
148 &trans, 149 &trans,
149 FullModelTypeSet(type_), 150 FullModelTypeSet(type_),
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // There should be no simple conflicts remaining. We know this because the 212 // There should be no simple conflicts remaining. We know this because the
212 // resolver should have resolved all the conflicts we detected last time 213 // resolver should have resolved all the conflicts we detected last time
213 // and, by the two previous assertions, that no conflicts have been 214 // and, by the two previous assertions, that no conflicts have been
214 // downgraded from encryption or hierarchy down to simple. 215 // downgraded from encryption or hierarchy down to simple.
215 DCHECK(conflict_applicator.simple_conflict_ids().empty()); 216 DCHECK(conflict_applicator.simple_conflict_ids().empty());
216 } 217 }
217 218
218 return SYNCER_OK; 219 return SYNCER_OK;
219 } 220 }
220 221
222 void DirectoryUpdateHandler::PostApplyUpdates() {
223 // If this is a type with client generated root, the root node has been
224 // created locally and didn't go through ApplyUpdatesImpl.
225 // Mark it as having the initial download completed so that the type
226 // reports as properly initialized (which is done by changing the root's
227 // base version to a value other than CHANGES_VERSION).
228 // This does nothing if the root's base version is already other than
229 // CHANGES_VERSION.
230 if (IsTypeWithClientGeneratedRoot(type_)) {
231 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_);
232 dir_->MarkInitialSyncEndedForType(&trans, type_);
233 }
234 }
235
221 bool DirectoryUpdateHandler::IsApplyUpdatesRequired() { 236 bool DirectoryUpdateHandler::IsApplyUpdatesRequired() {
222 if (IsControlType(type_)) { 237 if (IsControlType(type_)) {
223 return false; // We don't process control types here. 238 return false; // We don't process control types here.
224 } 239 }
225 240
226 return dir_->TypeHasUnappliedUpdates(type_); 241 return dir_->TypeHasUnappliedUpdates(type_);
227 } 242 }
228 243
229 void DirectoryUpdateHandler::UpdateSyncEntities( 244 void DirectoryUpdateHandler::UpdateSyncEntities(
230 syncable::ModelNeutralWriteTransaction* trans, 245 syncable::ModelNeutralWriteTransaction* trans,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 new_gc_directive.version_watermark())) { 303 new_gc_directive.version_watermark())) {
289 ExpireEntriesByVersion(dir_, trans, type_, 304 ExpireEntriesByVersion(dir_, trans, type_,
290 new_gc_directive.version_watermark()); 305 new_gc_directive.version_watermark());
291 } 306 }
292 307
293 cached_gc_directive_.reset( 308 cached_gc_directive_.reset(
294 new sync_pb::GarbageCollectionDirective(new_gc_directive)); 309 new sync_pb::GarbageCollectionDirective(new_gc_directive));
295 } 310 }
296 311
297 } // namespace syncer 312 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/directory_update_handler.h ('k') | sync/engine/directory_update_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698