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