Chromium Code Reviews| 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 |
| 22 using ServiceProvider = SyncClient::ServiceProvider; | |
| 23 | |
| 23 class AttachmentService; | 24 class AttachmentService; |
| 24 | 25 |
| 25 SharedChangeProcessor::SharedChangeProcessor(ModelType type) | 26 SharedChangeProcessor::SharedChangeProcessor(ModelType type) |
| 26 : disconnected_(false), | 27 : disconnected_(false), |
| 27 type_(type), | 28 type_(type), |
| 28 frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 29 frontend_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 29 generic_change_processor_(nullptr) { | 30 generic_change_processor_(nullptr) { |
| 30 DCHECK_NE(type_, UNSPECIFIED); | 31 DCHECK_NE(type_, UNSPECIFIED); |
| 31 } | 32 } |
| 32 | 33 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 44 generic_change_processor_)) { | 45 generic_change_processor_)) { |
| 45 NOTREACHED(); | 46 NOTREACHED(); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 } else { | 49 } else { |
| 49 DCHECK(!generic_change_processor_); | 50 DCHECK(!generic_change_processor_); |
| 50 } | 51 } |
| 51 } | 52 } |
| 52 | 53 |
| 53 void SharedChangeProcessor::StartAssociation( | 54 void SharedChangeProcessor::StartAssociation( |
| 54 StartDoneCallback start_done, | 55 const StartDoneCallback& start_done, |
| 55 SyncClient* const sync_client, | 56 const ServiceProvider& service_provider, |
|
pavely
2017/03/27 19:38:25
ServiceProvider looks weird outside of context of
skym
2017/03/27 21:45:26
Removed using instead, hopefully that's okay.
| |
| 57 SyncApiComponentFactory* driver_factory, | |
| 56 GenericChangeProcessorFactory* processor_factory, | 58 GenericChangeProcessorFactory* processor_factory, |
| 57 UserShare* user_share, | 59 UserShare* user_share, |
| 58 std::unique_ptr<DataTypeErrorHandler> error_handler) { | 60 std::unique_ptr<DataTypeErrorHandler> error_handler) { |
| 59 DCHECK(user_share); | 61 DCHECK(user_share); |
| 60 SyncMergeResult local_merge_result(type_); | 62 SyncMergeResult local_merge_result(type_); |
| 61 SyncMergeResult syncer_merge_result(type_); | 63 SyncMergeResult syncer_merge_result(type_); |
| 62 base::WeakPtrFactory<SyncMergeResult> weak_ptr_factory(&syncer_merge_result); | 64 base::WeakPtrFactory<SyncMergeResult> weak_ptr_factory(&syncer_merge_result); |
| 63 | 65 |
| 64 // Connect |shared_change_processor| to the syncer and get the | 66 // Connect |shared_change_processor| to the syncer and get the |
| 65 // SyncableService associated with type_. | 67 // SyncableService associated with type_. |
| 66 // Note that it's possible the shared_change_processor has already been | 68 // 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 | 69 // disconnected at this point, so all our accesses to the syncer from this |
| 68 // point on are through it. | 70 // point on are through it. |
| 69 local_service_ = | 71 local_service_ = |
| 70 Connect(sync_client, processor_factory, user_share, | 72 Connect(service_provider, driver_factory, processor_factory, user_share, |
| 71 std::move(error_handler), weak_ptr_factory.GetWeakPtr()); | 73 std::move(error_handler), weak_ptr_factory.GetWeakPtr()); |
| 72 if (!local_service_.get()) { | 74 if (!local_service_.get()) { |
| 73 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, | 75 SyncError error(FROM_HERE, SyncError::DATATYPE_ERROR, |
| 74 "Failed to connect to syncer.", type_); | 76 "Failed to connect to syncer.", type_); |
| 75 local_merge_result.set_error(error); | 77 local_merge_result.set_error(error); |
| 76 start_done.Run(DataTypeController::ASSOCIATION_FAILED, local_merge_result, | 78 start_done.Run(DataTypeController::ASSOCIATION_FAILED, local_merge_result, |
| 77 syncer_merge_result); | 79 syncer_merge_result); |
| 78 return; | 80 return; |
| 79 } | 81 } |
| 80 | 82 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 } | 134 } |
| 133 | 135 |
| 134 syncer_merge_result.set_num_items_after_association(GetSyncCount()); | 136 syncer_merge_result.set_num_items_after_association(GetSyncCount()); |
| 135 | 137 |
| 136 start_done.Run(!sync_has_nodes ? DataTypeController::OK_FIRST_RUN | 138 start_done.Run(!sync_has_nodes ? DataTypeController::OK_FIRST_RUN |
| 137 : DataTypeController::OK, | 139 : DataTypeController::OK, |
| 138 local_merge_result, syncer_merge_result); | 140 local_merge_result, syncer_merge_result); |
| 139 } | 141 } |
| 140 | 142 |
| 141 base::WeakPtr<SyncableService> SharedChangeProcessor::Connect( | 143 base::WeakPtr<SyncableService> SharedChangeProcessor::Connect( |
| 142 SyncClient* sync_client, | 144 const ServiceProvider& service_provider, |
| 145 SyncApiComponentFactory* driver_factory, | |
| 143 GenericChangeProcessorFactory* processor_factory, | 146 GenericChangeProcessorFactory* processor_factory, |
| 144 UserShare* user_share, | 147 UserShare* user_share, |
| 145 std::unique_ptr<DataTypeErrorHandler> error_handler, | 148 std::unique_ptr<DataTypeErrorHandler> error_handler, |
| 146 const base::WeakPtr<SyncMergeResult>& merge_result) { | 149 const base::WeakPtr<SyncMergeResult>& merge_result) { |
| 147 DCHECK(sync_client); | |
| 148 DCHECK(error_handler); | 150 DCHECK(error_handler); |
| 149 backend_task_runner_ = base::SequencedTaskRunnerHandle::Get(); | 151 backend_task_runner_ = base::SequencedTaskRunnerHandle::Get(); |
| 150 AutoLock lock(monitor_lock_); | 152 AutoLock lock(monitor_lock_); |
| 151 if (disconnected_) | 153 if (disconnected_) |
| 152 return base::WeakPtr<SyncableService>(); | 154 return base::WeakPtr<SyncableService>(); |
| 153 error_handler_ = std::move(error_handler); | 155 error_handler_ = std::move(error_handler); |
| 154 base::WeakPtr<SyncableService> local_service = | 156 base::WeakPtr<SyncableService> local_service = service_provider.Run(); |
| 155 sync_client->GetSyncableServiceForType(type_); | |
| 156 if (!local_service.get()) { | 157 if (!local_service.get()) { |
| 157 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; | 158 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; |
| 158 disconnected_ = true; | 159 disconnected_ = true; |
| 159 return base::WeakPtr<SyncableService>(); | 160 return base::WeakPtr<SyncableService>(); |
| 160 } | 161 } |
| 161 | 162 |
| 162 generic_change_processor_ = processor_factory | 163 generic_change_processor_ = |
| 163 ->CreateGenericChangeProcessor( | 164 processor_factory |
| 164 type_, user_share, error_handler_->Copy(), | 165 ->CreateGenericChangeProcessor(type_, user_share, |
| 165 local_service, merge_result, sync_client) | 166 error_handler_->Copy(), local_service, |
| 166 .release(); | 167 merge_result, driver_factory) |
| 168 .release(); | |
| 167 // If available, propagate attachment service to the syncable service. | 169 // If available, propagate attachment service to the syncable service. |
| 168 std::unique_ptr<AttachmentService> attachment_service = | 170 std::unique_ptr<AttachmentService> attachment_service = |
| 169 generic_change_processor_->GetAttachmentService(); | 171 generic_change_processor_->GetAttachmentService(); |
| 170 if (attachment_service) { | 172 if (attachment_service) { |
| 171 local_service->SetAttachmentService(std::move(attachment_service)); | 173 local_service->SetAttachmentService(std::move(attachment_service)); |
| 172 } | 174 } |
| 173 return local_service; | 175 return local_service; |
| 174 } | 176 } |
| 175 | 177 |
| 176 bool SharedChangeProcessor::Disconnect() { | 178 bool SharedChangeProcessor::Disconnect() { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 #undef PER_DATA_TYPE_MACRO | 320 #undef PER_DATA_TYPE_MACRO |
| 319 } | 321 } |
| 320 | 322 |
| 321 void SharedChangeProcessor::StopLocalService() { | 323 void SharedChangeProcessor::StopLocalService() { |
| 322 if (local_service_.get()) | 324 if (local_service_.get()) |
| 323 local_service_->StopSyncing(type_); | 325 local_service_->StopSyncing(type_); |
| 324 local_service_.reset(); | 326 local_service_.reset(); |
| 325 } | 327 } |
| 326 | 328 |
| 327 } // namespace syncer | 329 } // namespace syncer |
| OLD | NEW |