| 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 "base/thread_task_runner_handle.h" | 7 #include "base/thread_task_runner_handle.h" |
| 8 #include "components/sync_driver/generic_change_processor.h" | 8 #include "components/sync_driver/generic_change_processor.h" |
| 9 #include "components/sync_driver/generic_change_processor_factory.h" | 9 #include "components/sync_driver/generic_change_processor_factory.h" |
| 10 #include "components/sync_driver/sync_api_component_factory.h" | 10 #include "components/sync_driver/sync_client.h" |
| 11 #include "sync/api/sync_change.h" | 11 #include "sync/api/sync_change.h" |
| 12 #include "sync/api/syncable_service.h" |
| 12 | 13 |
| 13 using base::AutoLock; | 14 using base::AutoLock; |
| 14 | 15 |
| 15 namespace syncer { | 16 namespace syncer { |
| 16 class AttachmentService; | 17 class AttachmentService; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace sync_driver { | 20 namespace sync_driver { |
| 20 | 21 |
| 21 SharedChangeProcessor::SharedChangeProcessor() | 22 SharedChangeProcessor::SharedChangeProcessor() |
| (...skipping 18 matching lines...) Expand all Loading... |
| 40 generic_change_processor_)) { | 41 generic_change_processor_)) { |
| 41 NOTREACHED(); | 42 NOTREACHED(); |
| 42 } | 43 } |
| 43 } | 44 } |
| 44 } else { | 45 } else { |
| 45 DCHECK(!generic_change_processor_); | 46 DCHECK(!generic_change_processor_); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 base::WeakPtr<syncer::SyncableService> SharedChangeProcessor::Connect( | 50 base::WeakPtr<syncer::SyncableService> SharedChangeProcessor::Connect( |
| 50 SyncApiComponentFactory* sync_factory, | 51 SyncClient* sync_client, |
| 51 GenericChangeProcessorFactory* processor_factory, | 52 GenericChangeProcessorFactory* processor_factory, |
| 52 syncer::UserShare* user_share, | 53 syncer::UserShare* user_share, |
| 53 DataTypeErrorHandler* error_handler, | 54 DataTypeErrorHandler* error_handler, |
| 54 syncer::ModelType type, | 55 syncer::ModelType type, |
| 55 const base::WeakPtr<syncer::SyncMergeResult>& merge_result) { | 56 const base::WeakPtr<syncer::SyncMergeResult>& merge_result) { |
| 56 DCHECK(sync_factory); | 57 DCHECK(sync_client); |
| 57 DCHECK(error_handler); | 58 DCHECK(error_handler); |
| 58 DCHECK_NE(type, syncer::UNSPECIFIED); | 59 DCHECK_NE(type, syncer::UNSPECIFIED); |
| 59 backend_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 60 backend_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 60 AutoLock lock(monitor_lock_); | 61 AutoLock lock(monitor_lock_); |
| 61 if (disconnected_) | 62 if (disconnected_) |
| 62 return base::WeakPtr<syncer::SyncableService>(); | 63 return base::WeakPtr<syncer::SyncableService>(); |
| 63 type_ = type; | 64 type_ = type; |
| 64 error_handler_ = error_handler; | 65 error_handler_ = error_handler; |
| 65 base::WeakPtr<syncer::SyncableService> local_service = | 66 base::WeakPtr<syncer::SyncableService> local_service = |
| 66 sync_factory->GetSyncableServiceForType(type); | 67 sync_client->GetSyncableServiceForType(type); |
| 67 if (!local_service.get()) { | 68 if (!local_service.get()) { |
| 68 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; | 69 LOG(WARNING) << "SyncableService destroyed before DTC was stopped."; |
| 69 disconnected_ = true; | 70 disconnected_ = true; |
| 70 return base::WeakPtr<syncer::SyncableService>(); | 71 return base::WeakPtr<syncer::SyncableService>(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 generic_change_processor_ = | 74 generic_change_processor_ = |
| 74 processor_factory->CreateGenericChangeProcessor(type, | 75 processor_factory->CreateGenericChangeProcessor(type, |
| 75 user_share, | 76 user_share, |
| 76 error_handler, | 77 error_handler, |
| 77 local_service, | 78 local_service, |
| 78 merge_result, | 79 merge_result, |
| 79 sync_factory).release(); | 80 sync_client).release(); |
| 80 // If available, propagate attachment service to the syncable service. | 81 // If available, propagate attachment service to the syncable service. |
| 81 scoped_ptr<syncer::AttachmentService> attachment_service = | 82 scoped_ptr<syncer::AttachmentService> attachment_service = |
| 82 generic_change_processor_->GetAttachmentService(); | 83 generic_change_processor_->GetAttachmentService(); |
| 83 if (attachment_service) { | 84 if (attachment_service) { |
| 84 local_service->SetAttachmentService(attachment_service.Pass()); | 85 local_service->SetAttachmentService(attachment_service.Pass()); |
| 85 } | 86 } |
| 86 return local_service; | 87 return local_service; |
| 87 } | 88 } |
| 88 | 89 |
| 89 bool SharedChangeProcessor::Disconnect() { | 90 bool SharedChangeProcessor::Disconnect() { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return error_handler_->CreateAndUploadError(location, message, type_); | 213 return error_handler_->CreateAndUploadError(location, message, type_); |
| 213 } else { | 214 } else { |
| 214 return syncer::SyncError(location, | 215 return syncer::SyncError(location, |
| 215 syncer::SyncError::DATATYPE_ERROR, | 216 syncer::SyncError::DATATYPE_ERROR, |
| 216 message, | 217 message, |
| 217 type_); | 218 type_); |
| 218 } | 219 } |
| 219 } | 220 } |
| 220 | 221 |
| 221 } // namespace sync_driver | 222 } // namespace sync_driver |
| OLD | NEW |