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