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_NON_UI_DATA_TYPE_CONTROLLER_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_NON_UI_DATA_TYPE_CONTROLLER_H_ |
6 #define COMPONENTS_SYNC_DRIVER_NON_UI_DATA_TYPE_CONTROLLER_H_ | 6 #define COMPONENTS_SYNC_DRIVER_NON_UI_DATA_TYPE_CONTROLLER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "components/sync/driver/directory_data_type_controller.h" | 14 #include "components/sync/driver/directory_data_type_controller.h" |
15 #include "components/sync/driver/shared_change_processor.h" | 15 #include "components/sync/driver/shared_change_processor.h" |
16 | 16 |
17 namespace syncer { | 17 namespace syncer { |
| 18 |
| 19 class SyncClient; |
18 class SyncableService; | 20 class SyncableService; |
19 struct UserShare; | 21 struct UserShare; |
20 } | |
21 | |
22 namespace sync_driver { | |
23 | |
24 class SyncClient; | |
25 | 22 |
26 class NonUIDataTypeController : public DirectoryDataTypeController { | 23 class NonUIDataTypeController : public DirectoryDataTypeController { |
27 public: | 24 public: |
28 // |dump_stack| is called when an unrecoverable error occurs. | 25 // |dump_stack| is called when an unrecoverable error occurs. |
29 NonUIDataTypeController(syncer::ModelType type, | 26 NonUIDataTypeController(ModelType type, |
30 const base::Closure& dump_stack, | 27 const base::Closure& dump_stack, |
31 SyncClient* sync_client); | 28 SyncClient* sync_client); |
32 ~NonUIDataTypeController() override; | 29 ~NonUIDataTypeController() override; |
33 | 30 |
34 // DataTypeController interface. | 31 // DataTypeController interface. |
35 void LoadModels(const ModelLoadCallback& model_load_callback) override; | 32 void LoadModels(const ModelLoadCallback& model_load_callback) override; |
36 void StartAssociating(const StartCallback& start_callback) override; | 33 void StartAssociating(const StartCallback& start_callback) override; |
37 void Stop() override; | 34 void Stop() override; |
38 syncer::ModelSafeGroup model_safe_group() const override = 0; | 35 ModelSafeGroup model_safe_group() const override = 0; |
39 ChangeProcessor* GetChangeProcessor() const override; | 36 ChangeProcessor* GetChangeProcessor() const override; |
40 std::string name() const override; | 37 std::string name() const override; |
41 State state() const override; | 38 State state() const override; |
42 | 39 |
43 protected: | 40 protected: |
44 // For testing only. | 41 // For testing only. |
45 NonUIDataTypeController(); | 42 NonUIDataTypeController(); |
46 | 43 |
47 // Start any dependent services that need to be running before we can | 44 // Start any dependent services that need to be running before we can |
48 // associate models. The default implementation is a no-op. | 45 // associate models. The default implementation is a no-op. |
(...skipping 11 matching lines...) Expand all Loading... |
60 | 57 |
61 // Posts the given task to the backend thread, i.e. the thread the | 58 // Posts the given task to the backend thread, i.e. the thread the |
62 // datatype lives on. Return value: True if task posted successfully, | 59 // datatype lives on. Return value: True if task posted successfully, |
63 // false otherwise. | 60 // false otherwise. |
64 virtual bool PostTaskOnBackendThread( | 61 virtual bool PostTaskOnBackendThread( |
65 const tracked_objects::Location& from_here, | 62 const tracked_objects::Location& from_here, |
66 const base::Closure& task) = 0; | 63 const base::Closure& task) = 0; |
67 | 64 |
68 // Start up complete, update the state and invoke the callback. | 65 // Start up complete, update the state and invoke the callback. |
69 virtual void StartDone(DataTypeController::ConfigureResult start_result, | 66 virtual void StartDone(DataTypeController::ConfigureResult start_result, |
70 const syncer::SyncMergeResult& local_merge_result, | 67 const SyncMergeResult& local_merge_result, |
71 const syncer::SyncMergeResult& syncer_merge_result); | 68 const SyncMergeResult& syncer_merge_result); |
72 | 69 |
73 // Kick off the association process. | 70 // Kick off the association process. |
74 virtual bool StartAssociationAsync(); | 71 virtual bool StartAssociationAsync(); |
75 | 72 |
76 // Record causes of start failure. | 73 // Record causes of start failure. |
77 virtual void RecordStartFailure(ConfigureResult result); | 74 virtual void RecordStartFailure(ConfigureResult result); |
78 | 75 |
79 // To allow unit tests to control thread interaction during non-ui startup | 76 // To allow unit tests to control thread interaction during non-ui startup |
80 // and shutdown, use a factory method to create the SharedChangeProcessor. | 77 // and shutdown, use a factory method to create the SharedChangeProcessor. |
81 virtual SharedChangeProcessor* CreateSharedChangeProcessor(); | 78 virtual SharedChangeProcessor* CreateSharedChangeProcessor(); |
82 | 79 |
83 // If the DTC is waiting for models to load, once the models are | 80 // If the DTC is waiting for models to load, once the models are |
84 // loaded the datatype service will call this function on DTC to let | 81 // loaded the datatype service will call this function on DTC to let |
85 // us know that it is safe to start associating. | 82 // us know that it is safe to start associating. |
86 void OnModelLoaded(); | 83 void OnModelLoaded(); |
87 | 84 |
88 std::unique_ptr<syncer::DataTypeErrorHandler> CreateErrorHandler() override; | 85 std::unique_ptr<DataTypeErrorHandler> CreateErrorHandler() override; |
89 | 86 |
90 private: | 87 private: |
91 // Posted on the backend thread by StartAssociationAsync(). | 88 // Posted on the backend thread by StartAssociationAsync(). |
92 void StartAssociationWithSharedChangeProcessor( | 89 void StartAssociationWithSharedChangeProcessor( |
93 const scoped_refptr<SharedChangeProcessor>& shared_change_processor); | 90 const scoped_refptr<SharedChangeProcessor>& shared_change_processor); |
94 | 91 |
95 // Calls Disconnect() on |shared_change_processor_|, then sets it to | 92 // Calls Disconnect() on |shared_change_processor_|, then sets it to |
96 // NULL. Must be called only by StartDoneImpl() or Stop() (on the | 93 // NULL. Must be called only by StartDoneImpl() or Stop() (on the |
97 // UI thread) and only after a call to Start() (i.e., | 94 // UI thread) and only after a call to Start() (i.e., |
98 // |shared_change_processor_| must be non-NULL). | 95 // |shared_change_processor_| must be non-NULL). |
99 void DisconnectSharedChangeProcessor(); | 96 void DisconnectSharedChangeProcessor(); |
100 | 97 |
101 // Posts StopLocalService() to the processor on the model type thread. | 98 // Posts StopLocalService() to the processor on the model type thread. |
102 void StopSyncableService(); | 99 void StopSyncableService(); |
103 | 100 |
104 // Disable this type with the sync service. Should only be invoked in case of | 101 // Disable this type with the sync service. Should only be invoked in case of |
105 // an unrecoverable error. | 102 // an unrecoverable error. |
106 // Note: this is performed on the UI thread. | 103 // Note: this is performed on the UI thread. |
107 void DisableImpl(const syncer::SyncError& error); | 104 void DisableImpl(const SyncError& error); |
108 | 105 |
109 // UserShare is stored in StartAssociating while on UI thread and | 106 // UserShare is stored in StartAssociating while on UI thread and |
110 // passed to SharedChangeProcessor::Connect on the model thread. | 107 // passed to SharedChangeProcessor::Connect on the model thread. |
111 syncer::UserShare* user_share_; | 108 UserShare* user_share_; |
112 | 109 |
113 // State of this datatype controller. | 110 // State of this datatype controller. |
114 State state_; | 111 State state_; |
115 | 112 |
116 // Callbacks for use when starting the datatype. | 113 // Callbacks for use when starting the datatype. |
117 StartCallback start_callback_; | 114 StartCallback start_callback_; |
118 ModelLoadCallback model_load_callback_; | 115 ModelLoadCallback model_load_callback_; |
119 | 116 |
120 // The shared change processor is the thread-safe interface to the | 117 // The shared change processor is the thread-safe interface to the |
121 // datatype. We hold a reference to it from the UI thread so that | 118 // datatype. We hold a reference to it from the UI thread so that |
122 // we can call Disconnect() on it from Stop()/StartDoneImpl(). Most | 119 // we can call Disconnect() on it from Stop()/StartDoneImpl(). Most |
123 // of the work is done on the backend thread, and in | 120 // of the work is done on the backend thread, and in |
124 // StartAssociationWithSharedChangeProcessor() for this class in | 121 // StartAssociationWithSharedChangeProcessor() for this class in |
125 // particular. | 122 // particular. |
126 // | 123 // |
127 // Lifetime: The SharedChangeProcessor object is created on the UI | 124 // Lifetime: The SharedChangeProcessor object is created on the UI |
128 // thread and passed on to the backend thread. This reference is | 125 // thread and passed on to the backend thread. This reference is |
129 // released on the UI thread in Stop()/StartDoneImpl(), but the | 126 // released on the UI thread in Stop()/StartDoneImpl(), but the |
130 // backend thread may still have references to it (which is okay, | 127 // backend thread may still have references to it (which is okay, |
131 // since we call Disconnect() before releasing the UI thread | 128 // since we call Disconnect() before releasing the UI thread |
132 // reference). | 129 // reference). |
133 scoped_refptr<SharedChangeProcessor> shared_change_processor_; | 130 scoped_refptr<SharedChangeProcessor> shared_change_processor_; |
134 }; | 131 }; |
135 | 132 |
136 } // namespace sync_driver | 133 } // namespace syncer |
137 | 134 |
138 #endif // COMPONENTS_SYNC_DRIVER_NON_UI_DATA_TYPE_CONTROLLER_H_ | 135 #endif // COMPONENTS_SYNC_DRIVER_NON_UI_DATA_TYPE_CONTROLLER_H_ |
OLD | NEW |