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

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

Issue 161253002: sync: Add interfaces for per-type sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor fix Created 6 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 | Annotate | Revision Log
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/engine/sync_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"
11 #include "sync/syncable/directory.h" 11 #include "sync/syncable/directory.h"
12 #include "sync/syncable/syncable_model_neutral_write_transaction.h" 12 #include "sync/syncable/syncable_model_neutral_write_transaction.h"
13 #include "sync/syncable/syncable_write_transaction.h" 13 #include "sync/syncable/syncable_write_transaction.h"
14 14
15 namespace syncer { 15 namespace syncer {
16 16
17 using syncable::SYNCER; 17 using syncable::SYNCER;
18 18
19 SyncDirectoryUpdateHandler::SyncDirectoryUpdateHandler( 19 DirectoryUpdateHandler::DirectoryUpdateHandler(
20 syncable::Directory* dir, 20 syncable::Directory* dir,
21 ModelType type, 21 ModelType type,
22 scoped_refptr<ModelSafeWorker> worker) 22 scoped_refptr<ModelSafeWorker> worker)
23 : dir_(dir), 23 : dir_(dir),
24 type_(type), 24 type_(type),
25 worker_(worker) {} 25 worker_(worker) {}
26 26
27 SyncDirectoryUpdateHandler::~SyncDirectoryUpdateHandler() {} 27 DirectoryUpdateHandler::~DirectoryUpdateHandler() {}
28 28
29 void SyncDirectoryUpdateHandler::GetDownloadProgress( 29 void DirectoryUpdateHandler::GetDownloadProgress(
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 SyncDirectoryUpdateHandler::ProcessGetUpdatesResponse( 34 void DirectoryUpdateHandler::ProcessGetUpdatesResponse(
35 const sync_pb::DataTypeProgressMarker& progress_marker, 35 const sync_pb::DataTypeProgressMarker& progress_marker,
36 const SyncEntityList& applicable_updates, 36 const SyncEntityList& applicable_updates,
37 sessions::StatusController* status) { 37 sessions::StatusController* status) {
38 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_); 38 syncable::ModelNeutralWriteTransaction trans(FROM_HERE, SYNCER, dir_);
39 UpdateSyncEntities(&trans, applicable_updates, status); 39 UpdateSyncEntities(&trans, applicable_updates, status);
40 UpdateProgressMarker(progress_marker); 40 UpdateProgressMarker(progress_marker);
41 } 41 }
42 42
43 void SyncDirectoryUpdateHandler::ApplyUpdates( 43 void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) {
44 sessions::StatusController* status) {
45 if (!IsApplyUpdatesRequired()) { 44 if (!IsApplyUpdatesRequired()) {
46 return; 45 return;
47 } 46 }
48 47
49 // This will invoke handlers that belong to the model and its thread, so we 48 // This will invoke handlers that belong to the model and its thread, so we
50 // switch to the appropriate thread before we start this work. 49 // switch to the appropriate thread before we start this work.
51 WorkCallback c = base::Bind( 50 WorkCallback c = base::Bind(
52 &SyncDirectoryUpdateHandler::ApplyUpdatesImpl, 51 &DirectoryUpdateHandler::ApplyUpdatesImpl,
53 // We wait until the callback is executed. We can safely use Unretained. 52 // We wait until the callback is executed. We can safely use Unretained.
54 base::Unretained(this), 53 base::Unretained(this),
55 base::Unretained(status)); 54 base::Unretained(status));
56 worker_->DoWorkAndWaitUntilDone(c); 55 worker_->DoWorkAndWaitUntilDone(c);
57 } 56 }
58 57
59 void SyncDirectoryUpdateHandler::PassiveApplyUpdates( 58 void DirectoryUpdateHandler::PassiveApplyUpdates(
60 sessions::StatusController* status) { 59 sessions::StatusController* status) {
61 if (!IsApplyUpdatesRequired()) { 60 if (!IsApplyUpdatesRequired()) {
62 return; 61 return;
63 } 62 }
64 63
65 // Just do the work here instead of deferring to another thread. 64 // Just do the work here instead of deferring to another thread.
66 ApplyUpdatesImpl(status); 65 ApplyUpdatesImpl(status);
67 } 66 }
68 67
69 SyncerError SyncDirectoryUpdateHandler::ApplyUpdatesImpl( 68 SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl(
70 sessions::StatusController* status) { 69 sessions::StatusController* status) {
71 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_); 70 syncable::WriteTransaction trans(FROM_HERE, syncable::SYNCER, dir_);
72 71
73 std::vector<int64> handles; 72 std::vector<int64> handles;
74 dir_->GetUnappliedUpdateMetaHandles( 73 dir_->GetUnappliedUpdateMetaHandles(
75 &trans, 74 &trans,
76 FullModelTypeSet(type_), 75 FullModelTypeSet(type_),
77 &handles); 76 &handles);
78 77
79 // First set of update application passes. 78 // First set of update application passes.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // There should be no simple conflicts remaining. We know this because the 125 // There should be no simple conflicts remaining. We know this because the
127 // resolver should have resolved all the conflicts we detected last time 126 // resolver should have resolved all the conflicts we detected last time
128 // and, by the two previous assertions, that no conflicts have been 127 // and, by the two previous assertions, that no conflicts have been
129 // downgraded from encryption or hierarchy down to simple. 128 // downgraded from encryption or hierarchy down to simple.
130 DCHECK(conflict_applicator.simple_conflict_ids().empty()); 129 DCHECK(conflict_applicator.simple_conflict_ids().empty());
131 } 130 }
132 131
133 return SYNCER_OK; 132 return SYNCER_OK;
134 } 133 }
135 134
136 bool SyncDirectoryUpdateHandler::IsApplyUpdatesRequired() { 135 bool DirectoryUpdateHandler::IsApplyUpdatesRequired() {
137 if (IsControlType(type_)) { 136 if (IsControlType(type_)) {
138 return false; // We don't process control types here. 137 return false; // We don't process control types here.
139 } 138 }
140 139
141 return dir_->TypeHasUnappliedUpdates(type_); 140 return dir_->TypeHasUnappliedUpdates(type_);
142 } 141 }
143 142
144 void SyncDirectoryUpdateHandler::UpdateSyncEntities( 143 void DirectoryUpdateHandler::UpdateSyncEntities(
145 syncable::ModelNeutralWriteTransaction* trans, 144 syncable::ModelNeutralWriteTransaction* trans,
146 const SyncEntityList& applicable_updates, 145 const SyncEntityList& applicable_updates,
147 sessions::StatusController* status) { 146 sessions::StatusController* status) {
148 ProcessDownloadedUpdates(dir_, trans, type_, applicable_updates, status); 147 ProcessDownloadedUpdates(dir_, trans, type_, applicable_updates, status);
149 } 148 }
150 149
151 void SyncDirectoryUpdateHandler::UpdateProgressMarker( 150 void DirectoryUpdateHandler::UpdateProgressMarker(
152 const sync_pb::DataTypeProgressMarker& progress_marker) { 151 const sync_pb::DataTypeProgressMarker& progress_marker) {
153 int field_number = progress_marker.data_type_id(); 152 int field_number = progress_marker.data_type_id();
154 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number); 153 ModelType model_type = GetModelTypeFromSpecificsFieldNumber(field_number);
155 if (!IsRealDataType(model_type) || type_ != model_type) { 154 if (!IsRealDataType(model_type) || type_ != model_type) {
156 NOTREACHED() 155 NOTREACHED()
157 << "Update handler of type " << ModelTypeToString(type_) 156 << "Update handler of type " << ModelTypeToString(type_)
158 << " asked to process progress marker with invalid type " 157 << " asked to process progress marker with invalid type "
159 << field_number; 158 << field_number;
160 } 159 }
161 dir_->SetDownloadProgress(type_, progress_marker); 160 dir_->SetDownloadProgress(type_, progress_marker);
162 } 161 }
163 162
164 } // namespace syncer 163 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698