OLD | NEW |
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" | |
16 #include "components/sync/model/sync_change.h" | 15 #include "components/sync/model/sync_change.h" |
17 #include "components/sync/model/syncable_service.h" | 16 #include "components/sync/model/syncable_service.h" |
18 | 17 |
19 using base::AutoLock; | 18 using base::AutoLock; |
20 | 19 |
21 namespace syncer { | 20 namespace syncer { |
22 | 21 |
23 class AttachmentService; | 22 class AttachmentService; |
24 | 23 |
25 SharedChangeProcessor::SharedChangeProcessor(ModelType type) | 24 SharedChangeProcessor::SharedChangeProcessor(ModelType type) |
(...skipping 18 matching lines...) Expand all Loading... |
44 generic_change_processor_)) { | 43 generic_change_processor_)) { |
45 NOTREACHED(); | 44 NOTREACHED(); |
46 } | 45 } |
47 } | 46 } |
48 } else { | 47 } else { |
49 DCHECK(!generic_change_processor_); | 48 DCHECK(!generic_change_processor_); |
50 } | 49 } |
51 } | 50 } |
52 | 51 |
53 void SharedChangeProcessor::StartAssociation( | 52 void SharedChangeProcessor::StartAssociation( |
54 StartDoneCallback start_done, | 53 const StartDoneCallback& start_done, |
55 SyncClient* const sync_client, | 54 const SyncClient::ServiceProvider& service_provider, |
| 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(sync_client, processor_factory, user_share, | 70 Connect(service_provider, driver_factory, 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 Loading... |
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 SyncClient* sync_client, | 142 const SyncClient::ServiceProvider& service_provider, |
| 143 SyncApiComponentFactory* driver_factory, |
143 GenericChangeProcessorFactory* processor_factory, | 144 GenericChangeProcessorFactory* processor_factory, |
144 UserShare* user_share, | 145 UserShare* user_share, |
145 std::unique_ptr<DataTypeErrorHandler> error_handler, | 146 std::unique_ptr<DataTypeErrorHandler> error_handler, |
146 const base::WeakPtr<SyncMergeResult>& merge_result) { | 147 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 = | 154 base::WeakPtr<SyncableService> local_service = service_provider.Run(); |
155 sync_client->GetSyncableServiceForType(type_); | |
156 if (!local_service.get()) { | 155 if (!local_service.get()) { |
157 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; | 156 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; |
158 disconnected_ = true; | 157 disconnected_ = true; |
159 return base::WeakPtr<SyncableService>(); | 158 return base::WeakPtr<SyncableService>(); |
160 } | 159 } |
161 | 160 |
162 generic_change_processor_ = processor_factory | 161 generic_change_processor_ = |
163 ->CreateGenericChangeProcessor( | 162 processor_factory |
164 type_, user_share, error_handler_->Copy(), | 163 ->CreateGenericChangeProcessor(type_, user_share, |
165 local_service, merge_result, sync_client) | 164 error_handler_->Copy(), local_service, |
166 .release(); | 165 merge_result, driver_factory) |
| 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 Loading... |
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 |
OLD | NEW |