| 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 #ifndef COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ |
| 6 #define COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ | 6 #define COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/sequenced_task_runner.h" | 15 #include "base/sequenced_task_runner.h" |
| 16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "components/sync/driver/data_type_controller.h" | 18 #include "components/sync/driver/data_type_controller.h" |
| 19 #include "components/sync/driver/sync_client.h" |
| 19 #include "components/sync/engine/model_safe_worker.h" | 20 #include "components/sync/engine/model_safe_worker.h" |
| 20 #include "components/sync/model/data_type_error_handler.h" | 21 #include "components/sync/model/data_type_error_handler.h" |
| 21 #include "components/sync/model/sync_change_processor.h" | 22 #include "components/sync/model/sync_change_processor.h" |
| 22 #include "components/sync/model/sync_data.h" | 23 #include "components/sync/model/sync_data.h" |
| 23 #include "components/sync/model/sync_error.h" | 24 #include "components/sync/model/sync_error.h" |
| 24 #include "components/sync/model/sync_error_factory.h" | 25 #include "components/sync/model/sync_error_factory.h" |
| 25 #include "components/sync/model/sync_merge_result.h" | 26 #include "components/sync/model/sync_merge_result.h" |
| 26 | 27 |
| 27 namespace syncer { | 28 namespace syncer { |
| 28 | 29 |
| 29 class ChangeProcessor; | 30 class ChangeProcessor; |
| 30 class GenericChangeProcessor; | 31 class GenericChangeProcessor; |
| 31 class GenericChangeProcessorFactory; | 32 class GenericChangeProcessorFactory; |
| 32 class SyncClient; | 33 class SyncApiComponentFactory; |
| 33 class SyncableService; | 34 class SyncableService; |
| 34 struct UserShare; | 35 struct UserShare; |
| 35 | 36 |
| 36 // A ref-counted wrapper around a GenericChangeProcessor for use with datatypes | 37 // A ref-counted wrapper around a GenericChangeProcessor for use with datatypes |
| 37 // that don't live on the UI thread. | 38 // that don't live on the UI thread. |
| 38 // | 39 // |
| 39 // We need to make it refcounted as the ownership transfer from the | 40 // We need to make it refcounted as the ownership transfer from the |
| 40 // DataTypeController is dependent on threading, and hence racy. The | 41 // DataTypeController is dependent on threading, and hence racy. The |
| 41 // SharedChangeProcessor should be created on the UI thread, but should only be | 42 // SharedChangeProcessor should be created on the UI thread, but should only be |
| 42 // connected and used on the same thread as the datatype it interacts with. | 43 // connected and used on the same thread as the datatype it interacts with. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 : public base::RefCountedThreadSafe<SharedChangeProcessor> { | 55 : public base::RefCountedThreadSafe<SharedChangeProcessor> { |
| 55 public: | 56 public: |
| 56 using StartDoneCallback = | 57 using StartDoneCallback = |
| 57 base::Callback<void(DataTypeController::ConfigureResult start_result, | 58 base::Callback<void(DataTypeController::ConfigureResult start_result, |
| 58 const SyncMergeResult& local_merge_result, | 59 const SyncMergeResult& local_merge_result, |
| 59 const SyncMergeResult& syncer_merge_result)>; | 60 const SyncMergeResult& syncer_merge_result)>; |
| 60 | 61 |
| 61 // Create an uninitialized SharedChangeProcessor. | 62 // Create an uninitialized SharedChangeProcessor. |
| 62 explicit SharedChangeProcessor(ModelType type); | 63 explicit SharedChangeProcessor(ModelType type); |
| 63 | 64 |
| 64 void StartAssociation(StartDoneCallback start_done, | 65 void StartAssociation(const StartDoneCallback& start_done, |
| 65 SyncClient* const sync_client, | 66 const SyncClient::ServiceProvider& service_provider, |
| 67 SyncApiComponentFactory* driver_factory, |
| 66 GenericChangeProcessorFactory* processor_factory, | 68 GenericChangeProcessorFactory* processor_factory, |
| 67 UserShare* user_share, | 69 UserShare* user_share, |
| 68 std::unique_ptr<DataTypeErrorHandler> error_handler); | 70 std::unique_ptr<DataTypeErrorHandler> error_handler); |
| 69 | 71 |
| 70 // Connect to the Syncer and prepare to handle changes for |type|. Will | 72 // Connect to the Syncer and prepare to handle changes for |type|. Will |
| 71 // create and store a new GenericChangeProcessor and return a weak pointer to | 73 // create and store a new GenericChangeProcessor and return a weak pointer to |
| 72 // the SyncableService associated with |type|. | 74 // the SyncableService associated with |type|. |
| 73 // Note: If this SharedChangeProcessor has been disconnected, or the | 75 // Note: If this SharedChangeProcessor has been disconnected, or the |
| 74 // SyncableService was not alive, will return a null weak pointer. | 76 // SyncableService is not alive, will return a null weak pointer. |
| 75 virtual base::WeakPtr<SyncableService> Connect( | 77 virtual base::WeakPtr<SyncableService> Connect( |
| 76 SyncClient* sync_client, | 78 const SyncClient::ServiceProvider& service_provider, |
| 79 SyncApiComponentFactory* driver_factory, |
| 77 GenericChangeProcessorFactory* processor_factory, | 80 GenericChangeProcessorFactory* processor_factory, |
| 78 UserShare* user_share, | 81 UserShare* user_share, |
| 79 std::unique_ptr<DataTypeErrorHandler> error_handler, | 82 std::unique_ptr<DataTypeErrorHandler> error_handler, |
| 80 const base::WeakPtr<SyncMergeResult>& merge_result); | 83 const base::WeakPtr<SyncMergeResult>& merge_result); |
| 81 | 84 |
| 82 // Disconnects from the generic change processor. This method is thread-safe. | 85 // Disconnects from the generic change processor. This method is thread-safe. |
| 83 // After this, all attempts to interact with the change processor by | 86 // After this, all attempts to interact with the change processor by |
| 84 // |local_service_| are dropped and return errors. The syncer will be safe to | 87 // |local_service_| are dropped and return errors. The syncer will be safe to |
| 85 // shut down from the point of view of this datatype. | 88 // shut down from the point of view of this datatype. |
| 86 // Note: Once disconnected, you cannot reconnect without creating a new | 89 // Note: Once disconnected, you cannot reconnect without creating a new |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // The local service for this type. Only set if the DTC for the type uses | 159 // The local service for this type. Only set if the DTC for the type uses |
| 157 // SharedChangeProcessor::StartAssociation(). | 160 // SharedChangeProcessor::StartAssociation(). |
| 158 base::WeakPtr<SyncableService> local_service_; | 161 base::WeakPtr<SyncableService> local_service_; |
| 159 | 162 |
| 160 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); | 163 DISALLOW_COPY_AND_ASSIGN(SharedChangeProcessor); |
| 161 }; | 164 }; |
| 162 | 165 |
| 163 } // namespace syncer | 166 } // namespace syncer |
| 164 | 167 |
| 165 #endif // COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ | 168 #endif // COMPONENTS_SYNC_DRIVER_SHARED_CHANGE_PROCESSOR_H_ |
| OLD | NEW |