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

Side by Side Diff: components/sync/driver/shared_change_processor.cc

Issue 2203673002: [Sync] Move //components/sync_driver to //components/sync/driver. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sd-a
Patch Set: Full change rebased on static lib. Created 4 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
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 "components/sync_driver/shared_change_processor.h" 5 #include "components/sync/driver/shared_change_processor.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/sync/api/sync_change.h" 10 #include "components/sync/api/sync_change.h"
11 #include "components/sync/api/syncable_service.h" 11 #include "components/sync/api/syncable_service.h"
12 #include "components/sync/core/data_type_error_handler.h" 12 #include "components/sync/core/data_type_error_handler.h"
13 #include "components/sync_driver/generic_change_processor.h" 13 #include "components/sync/driver/generic_change_processor.h"
14 #include "components/sync_driver/generic_change_processor_factory.h" 14 #include "components/sync/driver/generic_change_processor_factory.h"
15 #include "components/sync_driver/sync_client.h" 15 #include "components/sync/driver/sync_client.h"
16 16
17 using base::AutoLock; 17 using base::AutoLock;
18 18
19 namespace syncer { 19 namespace syncer {
20 class AttachmentService; 20 class AttachmentService;
21 } 21 }
22 22
23 namespace sync_driver { 23 namespace sync_driver {
24 24
25 SharedChangeProcessor::SharedChangeProcessor() 25 SharedChangeProcessor::SharedChangeProcessor()
26 : disconnected_(false), 26 : disconnected_(false),
27 type_(syncer::UNSPECIFIED), 27 type_(syncer::UNSPECIFIED),
28 frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()), 28 frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()),
29 generic_change_processor_(NULL), 29 generic_change_processor_(NULL),
30 error_handler_(NULL) { 30 error_handler_(NULL) {}
31 }
32 31
33 SharedChangeProcessor::~SharedChangeProcessor() { 32 SharedChangeProcessor::~SharedChangeProcessor() {
34 // We can either be deleted when the DTC is destroyed (on UI 33 // We can either be deleted when the DTC is destroyed (on UI
35 // thread), or when the syncer::SyncableService stops syncing (datatype 34 // thread), or when the syncer::SyncableService stops syncing (datatype
36 // thread). |generic_change_processor_|, if non-NULL, must be 35 // thread). |generic_change_processor_|, if non-NULL, must be
37 // deleted on |backend_loop_|. 36 // deleted on |backend_loop_|.
38 if (backend_task_runner_.get()) { 37 if (backend_task_runner_.get()) {
39 if (backend_task_runner_->BelongsToCurrentThread()) { 38 if (backend_task_runner_->BelongsToCurrentThread()) {
40 delete generic_change_processor_; 39 delete generic_change_processor_;
41 } else { 40 } else {
(...skipping 25 matching lines...) Expand all
67 type_ = type; 66 type_ = type;
68 error_handler_ = error_handler; 67 error_handler_ = error_handler;
69 base::WeakPtr<syncer::SyncableService> local_service = 68 base::WeakPtr<syncer::SyncableService> local_service =
70 sync_client->GetSyncableServiceForType(type); 69 sync_client->GetSyncableServiceForType(type);
71 if (!local_service.get()) { 70 if (!local_service.get()) {
72 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; 71 LOG(WARNING) << "SyncableService destroyed before DTC was stopped.";
73 disconnected_ = true; 72 disconnected_ = true;
74 return base::WeakPtr<syncer::SyncableService>(); 73 return base::WeakPtr<syncer::SyncableService>();
75 } 74 }
76 75
77 generic_change_processor_ = 76 generic_change_processor_ = processor_factory
78 processor_factory->CreateGenericChangeProcessor(type, 77 ->CreateGenericChangeProcessor(
79 user_share, 78 type, user_share, error_handler,
80 error_handler, 79 local_service, merge_result, sync_client)
81 local_service, 80 .release();
82 merge_result,
83 sync_client).release();
84 // If available, propagate attachment service to the syncable service. 81 // If available, propagate attachment service to the syncable service.
85 std::unique_ptr<syncer::AttachmentService> attachment_service = 82 std::unique_ptr<syncer::AttachmentService> attachment_service =
86 generic_change_processor_->GetAttachmentService(); 83 generic_change_processor_->GetAttachmentService();
87 if (attachment_service) { 84 if (attachment_service) {
88 local_service->SetAttachmentService(std::move(attachment_service)); 85 local_service->SetAttachmentService(std::move(attachment_service));
89 } 86 }
90 return local_service; 87 return local_service;
91 } 88 }
92 89
93 bool SharedChangeProcessor::Disconnect() { 90 bool SharedChangeProcessor::Disconnect() {
(...skipping 23 matching lines...) Expand all
117 114
118 syncer::SyncError SharedChangeProcessor::ProcessSyncChanges( 115 syncer::SyncError SharedChangeProcessor::ProcessSyncChanges(
119 const tracked_objects::Location& from_here, 116 const tracked_objects::Location& from_here,
120 const syncer::SyncChangeList& list_of_changes) { 117 const syncer::SyncChangeList& list_of_changes) {
121 DCHECK(backend_task_runner_.get()); 118 DCHECK(backend_task_runner_.get());
122 DCHECK(backend_task_runner_->BelongsToCurrentThread()); 119 DCHECK(backend_task_runner_->BelongsToCurrentThread());
123 AutoLock lock(monitor_lock_); 120 AutoLock lock(monitor_lock_);
124 if (disconnected_) { 121 if (disconnected_) {
125 // The DTC that disconnects us must ensure it posts a StopSyncing task. 122 // The DTC that disconnects us must ensure it posts a StopSyncing task.
126 // If we reach this, it means it just hasn't executed yet. 123 // If we reach this, it means it just hasn't executed yet.
127 syncer::SyncError error(FROM_HERE, 124 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
128 syncer::SyncError::DATATYPE_ERROR, 125 "Change processor disconnected.", type_);
129 "Change processor disconnected.",
130 type_);
131 return error; 126 return error;
132 } 127 }
133 return generic_change_processor_->ProcessSyncChanges( 128 return generic_change_processor_->ProcessSyncChanges(from_here,
134 from_here, list_of_changes); 129 list_of_changes);
135 } 130 }
136 131
137 syncer::SyncDataList SharedChangeProcessor::GetAllSyncData( 132 syncer::SyncDataList SharedChangeProcessor::GetAllSyncData(
138 syncer::ModelType type) const { 133 syncer::ModelType type) const {
139 syncer::SyncDataList data; 134 syncer::SyncDataList data;
140 GetAllSyncDataReturnError(type, &data); // Handles the disconnect case. 135 GetAllSyncDataReturnError(type, &data); // Handles the disconnect case.
141 return data; 136 return data;
142 } 137 }
143 138
144 syncer::SyncError SharedChangeProcessor::GetAllSyncDataReturnError( 139 syncer::SyncError SharedChangeProcessor::GetAllSyncDataReturnError(
145 syncer::ModelType type, 140 syncer::ModelType type,
146 syncer::SyncDataList* data) const { 141 syncer::SyncDataList* data) const {
147 DCHECK(backend_task_runner_.get()); 142 DCHECK(backend_task_runner_.get());
148 DCHECK(backend_task_runner_->BelongsToCurrentThread()); 143 DCHECK(backend_task_runner_->BelongsToCurrentThread());
149 AutoLock lock(monitor_lock_); 144 AutoLock lock(monitor_lock_);
150 if (disconnected_) { 145 if (disconnected_) {
151 syncer::SyncError error(FROM_HERE, 146 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
152 syncer::SyncError::DATATYPE_ERROR, 147 "Change processor disconnected.", type_);
153 "Change processor disconnected.",
154 type_);
155 return error; 148 return error;
156 } 149 }
157 return generic_change_processor_->GetAllSyncDataReturnError(data); 150 return generic_change_processor_->GetAllSyncDataReturnError(data);
158 } 151 }
159 152
160 syncer::SyncError SharedChangeProcessor::UpdateDataTypeContext( 153 syncer::SyncError SharedChangeProcessor::UpdateDataTypeContext(
161 syncer::ModelType type, 154 syncer::ModelType type,
162 syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status, 155 syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status,
163 const std::string& context) { 156 const std::string& context) {
164 DCHECK(backend_task_runner_.get()); 157 DCHECK(backend_task_runner_.get());
165 DCHECK(backend_task_runner_->BelongsToCurrentThread()); 158 DCHECK(backend_task_runner_->BelongsToCurrentThread());
166 AutoLock lock(monitor_lock_); 159 AutoLock lock(monitor_lock_);
167 if (disconnected_) { 160 if (disconnected_) {
168 syncer::SyncError error(FROM_HERE, 161 syncer::SyncError error(FROM_HERE, syncer::SyncError::DATATYPE_ERROR,
169 syncer::SyncError::DATATYPE_ERROR, 162 "Change processor disconnected.", type_);
170 "Change processor disconnected.",
171 type_);
172 return error; 163 return error;
173 } 164 }
174 return generic_change_processor_->UpdateDataTypeContext( 165 return generic_change_processor_->UpdateDataTypeContext(type, refresh_status,
175 type, refresh_status, context); 166 context);
176 } 167 }
177 168
178 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) { 169 bool SharedChangeProcessor::SyncModelHasUserCreatedNodes(bool* has_nodes) {
179 DCHECK(backend_task_runner_.get()); 170 DCHECK(backend_task_runner_.get());
180 DCHECK(backend_task_runner_->BelongsToCurrentThread()); 171 DCHECK(backend_task_runner_->BelongsToCurrentThread());
181 AutoLock lock(monitor_lock_); 172 AutoLock lock(monitor_lock_);
182 if (disconnected_) { 173 if (disconnected_) {
183 LOG(ERROR) << "Change processor disconnected."; 174 LOG(ERROR) << "Change processor disconnected.";
184 return false; 175 return false;
185 } 176 }
(...skipping 22 matching lines...) Expand all
208 return generic_change_processor_->GetDataTypeContext(context); 199 return generic_change_processor_->GetDataTypeContext(context);
209 } 200 }
210 201
211 syncer::SyncError SharedChangeProcessor::CreateAndUploadError( 202 syncer::SyncError SharedChangeProcessor::CreateAndUploadError(
212 const tracked_objects::Location& location, 203 const tracked_objects::Location& location,
213 const std::string& message) { 204 const std::string& message) {
214 AutoLock lock(monitor_lock_); 205 AutoLock lock(monitor_lock_);
215 if (!disconnected_) { 206 if (!disconnected_) {
216 return error_handler_->CreateAndUploadError(location, message, type_); 207 return error_handler_->CreateAndUploadError(location, message, type_);
217 } else { 208 } else {
218 return syncer::SyncError(location, 209 return syncer::SyncError(location, syncer::SyncError::DATATYPE_ERROR,
219 syncer::SyncError::DATATYPE_ERROR, 210 message, type_);
220 message,
221 type_);
222 } 211 }
223 } 212 }
224 213
225 } // namespace sync_driver 214 } // namespace sync_driver
OLDNEW
« no previous file with comments | « components/sync/driver/shared_change_processor.h ('k') | components/sync/driver/shared_change_processor_ref.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698