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

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

Issue 2799653006: Revert of [Sync] Stop accessing BrowserContextKeyedServiceFactory on non-UI thread. (Closed)
Patch Set: Created 3 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
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/sequenced_task_runner_handle.h" 9 #include "base/threading/sequenced_task_runner_handle.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
11 #include "components/sync/base/data_type_histogram.h" 11 #include "components/sync/base/data_type_histogram.h"
12 #include "components/sync/driver/generic_change_processor.h" 12 #include "components/sync/driver/generic_change_processor.h"
13 #include "components/sync/driver/generic_change_processor_factory.h" 13 #include "components/sync/driver/generic_change_processor_factory.h"
14 #include "components/sync/driver/shared_change_processor_ref.h" 14 #include "components/sync/driver/shared_change_processor_ref.h"
15 #include "components/sync/driver/sync_client.h"
15 #include "components/sync/model/sync_change.h" 16 #include "components/sync/model/sync_change.h"
16 #include "components/sync/model/syncable_service.h" 17 #include "components/sync/model/syncable_service.h"
17 18
18 using base::AutoLock; 19 using base::AutoLock;
19 20
20 namespace syncer { 21 namespace syncer {
21 22
22 class AttachmentService; 23 class AttachmentService;
23 24
24 SharedChangeProcessor::SharedChangeProcessor(ModelType type) 25 SharedChangeProcessor::SharedChangeProcessor(ModelType type)
(...skipping 18 matching lines...) Expand all
43 generic_change_processor_)) { 44 generic_change_processor_)) {
44 NOTREACHED(); 45 NOTREACHED();
45 } 46 }
46 } 47 }
47 } else { 48 } else {
48 DCHECK(!generic_change_processor_); 49 DCHECK(!generic_change_processor_);
49 } 50 }
50 } 51 }
51 52
52 void SharedChangeProcessor::StartAssociation( 53 void SharedChangeProcessor::StartAssociation(
53 const StartDoneCallback& start_done, 54 StartDoneCallback start_done,
54 const SyncClient::ServiceProvider& service_provider, 55 SyncClient* const sync_client,
55 SyncApiComponentFactory* driver_factory,
56 GenericChangeProcessorFactory* processor_factory, 56 GenericChangeProcessorFactory* processor_factory,
57 UserShare* user_share, 57 UserShare* user_share,
58 std::unique_ptr<DataTypeErrorHandler> error_handler) { 58 std::unique_ptr<DataTypeErrorHandler> error_handler) {
59 DCHECK(user_share); 59 DCHECK(user_share);
60 SyncMergeResult local_merge_result(type_); 60 SyncMergeResult local_merge_result(type_);
61 SyncMergeResult syncer_merge_result(type_); 61 SyncMergeResult syncer_merge_result(type_);
62 base::WeakPtrFactory<SyncMergeResult> weak_ptr_factory(&syncer_merge_result); 62 base::WeakPtrFactory<SyncMergeResult> weak_ptr_factory(&syncer_merge_result);
63 63
64 // Connect |shared_change_processor| to the syncer and get the 64 // Connect |shared_change_processor| to the syncer and get the
65 // SyncableService associated with type_. 65 // SyncableService associated with type_.
66 // Note that it's possible the shared_change_processor has already been 66 // Note that it's possible the shared_change_processor has already been
67 // disconnected at this point, so all our accesses to the syncer from this 67 // disconnected at this point, so all our accesses to the syncer from this
68 // point on are through it. 68 // point on are through it.
69 local_service_ = 69 local_service_ =
70 Connect(service_provider, driver_factory, processor_factory, user_share, 70 Connect(sync_client, processor_factory, user_share,
71 std::move(error_handler), weak_ptr_factory.GetWeakPtr()); 71 std::move(error_handler), weak_ptr_factory.GetWeakPtr());
72 if (!local_service_.get()) { 72 if (!local_service_.get()) {
73 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, 73 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR,
74 "Failed to connect to syncer.", type_); 74 "Failed to connect to syncer.", type_);
75 local_merge_result.set_error(error); 75 local_merge_result.set_error(error);
76 start_done.Run(DataTypeController::ASSOCIATION_FAILED, local_merge_result, 76 start_done.Run(DataTypeController::ASSOCIATION_FAILED, local_merge_result,
77 syncer_merge_result); 77 syncer_merge_result);
78 return; 78 return;
79 } 79 }
80 80
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 syncer_merge_result.set_num_items_after_association(GetSyncCount()); 134 syncer_merge_result.set_num_items_after_association(GetSyncCount());
135 135
136 start_done.Run(!sync_has_nodes ? DataTypeController::OK_FIRST_RUN 136 start_done.Run(!sync_has_nodes ? DataTypeController::OK_FIRST_RUN
137 : DataTypeController::OK, 137 : DataTypeController::OK,
138 local_merge_result, syncer_merge_result); 138 local_merge_result, syncer_merge_result);
139 } 139 }
140 140
141 base::WeakPtr<SyncableService> SharedChangeProcessor::Connect( 141 base::WeakPtr<SyncableService> SharedChangeProcessor::Connect(
142 const SyncClient::ServiceProvider& service_provider, 142 SyncClient* sync_client,
143 SyncApiComponentFactory* driver_factory,
144 GenericChangeProcessorFactory* processor_factory, 143 GenericChangeProcessorFactory* processor_factory,
145 UserShare* user_share, 144 UserShare* user_share,
146 std::unique_ptr<DataTypeErrorHandler> error_handler, 145 std::unique_ptr<DataTypeErrorHandler> error_handler,
147 const base::WeakPtr<SyncMergeResult>& merge_result) { 146 const base::WeakPtr<SyncMergeResult>& merge_result) {
147 DCHECK(sync_client);
148 DCHECK(error_handler); 148 DCHECK(error_handler);
149 backend_task_runner_ = base::SequencedTaskRunnerHandle::Get(); 149 backend_task_runner_ = base::SequencedTaskRunnerHandle::Get();
150 AutoLock lock(monitor_lock_); 150 AutoLock lock(monitor_lock_);
151 if (disconnected_) 151 if (disconnected_)
152 return base::WeakPtr<SyncableService>(); 152 return base::WeakPtr<SyncableService>();
153 error_handler_ = std::move(error_handler); 153 error_handler_ = std::move(error_handler);
154 base::WeakPtr<SyncableService> local_service = service_provider.Run(); 154 base::WeakPtr<SyncableService> local_service =
155 sync_client->GetSyncableServiceForType(type_);
155 if (!local_service.get()) { 156 if (!local_service.get()) {
156 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; 157 LOG(WARNING) << "SyncableService destroyed before DTC was stopped.";
157 disconnected_ = true; 158 disconnected_ = true;
158 return base::WeakPtr<SyncableService>(); 159 return base::WeakPtr<SyncableService>();
159 } 160 }
160 161
161 generic_change_processor_ = 162 generic_change_processor_ = processor_factory
162 processor_factory 163 ->CreateGenericChangeProcessor(
163 ->CreateGenericChangeProcessor(type_, user_share, 164 type_, user_share, error_handler_->Copy(),
164 error_handler_->Copy(), local_service, 165 local_service, merge_result, sync_client)
165 merge_result, driver_factory) 166 .release();
166 .release();
167 // If available, propagate attachment service to the syncable service. 167 // If available, propagate attachment service to the syncable service.
168 std::unique_ptr<AttachmentService> attachment_service = 168 std::unique_ptr<AttachmentService> attachment_service =
169 generic_change_processor_->GetAttachmentService(); 169 generic_change_processor_->GetAttachmentService();
170 if (attachment_service) { 170 if (attachment_service) {
171 local_service->SetAttachmentService(std::move(attachment_service)); 171 local_service->SetAttachmentService(std::move(attachment_service));
172 } 172 }
173 return local_service; 173 return local_service;
174 } 174 }
175 175
176 bool SharedChangeProcessor::Disconnect() { 176 bool SharedChangeProcessor::Disconnect() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 #undef PER_DATA_TYPE_MACRO 318 #undef PER_DATA_TYPE_MACRO
319 } 319 }
320 320
321 void SharedChangeProcessor::StopLocalService() { 321 void SharedChangeProcessor::StopLocalService() {
322 if (local_service_.get()) 322 if (local_service_.get())
323 local_service_->StopSyncing(type_); 323 local_service_->StopSyncing(type_);
324 local_service_.reset(); 324 local_service_.reset();
325 } 325 }
326 326
327 } // namespace syncer 327 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/driver/shared_change_processor.h ('k') | components/sync/driver/shared_change_processor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698