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_MODEL_ASSOCIATION_MANAGER_H__ | 5 #ifndef COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ |
6 #define COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ | 6 #define COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 // Called when model association (MergeDataAndStartSyncing) has completed | 30 // Called when model association (MergeDataAndStartSyncing) has completed |
31 // for |type|, regardless of success or failure. | 31 // for |type|, regardless of success or failure. |
32 virtual void OnSingleDataTypeAssociationDone( | 32 virtual void OnSingleDataTypeAssociationDone( |
33 syncer::ModelType type, | 33 syncer::ModelType type, |
34 const syncer::DataTypeAssociationStats& association_stats) = 0; | 34 const syncer::DataTypeAssociationStats& association_stats) = 0; |
35 | 35 |
36 // Called when the ModelAssociationManager has decided it must stop |type|, | 36 // Called when the ModelAssociationManager has decided it must stop |type|, |
37 // likely because it is no longer a desired data type or sync is shutting | 37 // likely because it is no longer a desired data type or sync is shutting |
38 // down. | 38 // down. |
39 virtual void OnSingleDataTypeWillStop(syncer::ModelType type) = 0; | 39 virtual void OnSingleDataTypeWillStop(syncer::ModelType type, |
| 40 const syncer::SyncError& error) = 0; |
40 | 41 |
41 // Called when the ModelAssociationManager has tried to perform model | 42 // Called when the ModelAssociationManager has tried to perform model |
42 // association for all desired types and has nothing left to do. | 43 // association for all desired types and has nothing left to do. |
43 virtual void OnModelAssociationDone( | 44 virtual void OnModelAssociationDone( |
44 const DataTypeManager::ConfigureResult& result) = 0; | 45 const DataTypeManager::ConfigureResult& result) = 0; |
45 virtual ~ModelAssociationManagerDelegate() {} | 46 virtual ~ModelAssociationManagerDelegate() {} |
46 }; | 47 }; |
47 | 48 |
48 // The class that is responsible for model association. | 49 // The class that is responsible for model association. |
49 class ModelAssociationManager { | 50 class ModelAssociationManager { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // Called by Initialize() to stop types that are not in |desired_types_|. | 92 // Called by Initialize() to stop types that are not in |desired_types_|. |
92 void StopDisabledTypes(); | 93 void StopDisabledTypes(); |
93 | 94 |
94 // Start loading non-running types that are in |desired_types_|. | 95 // Start loading non-running types that are in |desired_types_|. |
95 void LoadEnabledTypes(); | 96 void LoadEnabledTypes(); |
96 | 97 |
97 // Callback passed to each data type controller on starting association. This | 98 // Callback passed to each data type controller on starting association. This |
98 // callback will be invoked when the model association is done. | 99 // callback will be invoked when the model association is done. |
99 void TypeStartCallback(syncer::ModelType type, | 100 void TypeStartCallback(syncer::ModelType type, |
100 base::TimeTicks type_start_time, | 101 base::TimeTicks type_start_time, |
101 DataTypeController::StartResult start_result, | 102 DataTypeController::ConfigureResult start_result, |
102 const syncer::SyncMergeResult& local_merge_result, | 103 const syncer::SyncMergeResult& local_merge_result, |
103 const syncer::SyncMergeResult& syncer_merge_result); | 104 const syncer::SyncMergeResult& syncer_merge_result); |
104 | 105 |
105 // Callback that will be invoked when the models finish loading. This callback | 106 // Callback that will be invoked when the models finish loading. This callback |
106 // will be passed to |LoadModels| function. | 107 // will be passed to |LoadModels| function. |
107 void ModelLoadCallback(syncer::ModelType type, syncer::SyncError error); | 108 void ModelLoadCallback(syncer::ModelType type, syncer::SyncError error); |
108 | 109 |
109 // When a type fails to load or fails associating this method is invoked to | |
110 // do the book keeping and do the UMA reporting. | |
111 void AppendToFailedDatatypesAndLogError(const syncer::SyncError& error); | |
112 | |
113 // Called when all requested types are associated or association times out. | 110 // Called when all requested types are associated or association times out. |
114 // Notify |delegate_| of configuration results. | 111 // Notify |delegate_| of configuration results. |
115 void ModelAssociationDone(); | 112 void ModelAssociationDone(); |
116 | 113 |
117 // A helper to stop an individual datatype. | 114 // A helper to stop an individual datatype. |
118 void StopDatatype(DataTypeController* dtc); | 115 void StopDatatype(const syncer::SyncError& error, DataTypeController* dtc); |
119 | 116 |
120 State state_; | 117 State state_; |
121 | 118 |
122 // Data types that are enabled. | 119 // Data types that are enabled. |
123 syncer::ModelTypeSet desired_types_; | 120 syncer::ModelTypeSet desired_types_; |
124 | 121 |
125 // Data types that are requested to associate. | 122 // Data types that are requested to associate. |
126 syncer::ModelTypeSet requested_types_; | 123 syncer::ModelTypeSet requested_types_; |
127 | 124 |
128 // Data types currently being associated, including types waiting for model | 125 // Data types currently being associated, including types waiting for model |
129 // load. | 126 // load. |
130 syncer::ModelTypeSet associating_types_; | 127 syncer::ModelTypeSet associating_types_; |
131 | 128 |
132 // Data types that are loaded, i.e. ready to associate. | 129 // Data types that are loaded, i.e. ready to associate. |
133 syncer::ModelTypeSet loaded_types_; | 130 syncer::ModelTypeSet loaded_types_; |
134 | 131 |
135 // Data types that are associated, i.e. no more action needed during | 132 // Data types that are associated, i.e. no more action needed during |
136 // reconfiguration if not disabled. | 133 // reconfiguration if not disabled. |
137 syncer::ModelTypeSet associated_types_; | 134 syncer::ModelTypeSet associated_types_; |
138 | 135 |
139 // Data types that are still loading/associating when configuration times | |
140 // out. | |
141 syncer::ModelTypeSet slow_types_; | |
142 | |
143 // Collects the list of errors resulting from failing to start a type. This | |
144 // would eventually be sent to the listeners after all the types have | |
145 // been given a chance to start. | |
146 std::map<syncer::ModelType, syncer::SyncError> failed_data_types_info_; | |
147 | |
148 // The set of types that can't configure due to cryptographer errors. | |
149 syncer::ModelTypeSet needs_crypto_types_; | |
150 | |
151 // Time when StartAssociationAsync() is called to associate for a set of data | 136 // Time when StartAssociationAsync() is called to associate for a set of data |
152 // types. | 137 // types. |
153 base::TimeTicks association_start_time_; | 138 base::TimeTicks association_start_time_; |
154 | 139 |
155 // Set of all registered controllers. | 140 // Set of all registered controllers. |
156 const DataTypeController::TypeMap* controllers_; | 141 const DataTypeController::TypeMap* controllers_; |
157 | 142 |
158 // The processor in charge of handling model association results. | 143 // The processor in charge of handling model association results. |
159 ModelAssociationManagerDelegate* delegate_; | 144 ModelAssociationManagerDelegate* delegate_; |
160 | 145 |
161 // Timer to track and limit how long a datatype takes to model associate. | 146 // Timer to track and limit how long a datatype takes to model associate. |
162 base::OneShotTimer<ModelAssociationManager> timer_; | 147 base::OneShotTimer<ModelAssociationManager> timer_; |
163 | 148 |
164 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; | 149 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; |
165 | 150 |
166 DataTypeManager::ConfigureStatus configure_status_; | 151 DataTypeManager::ConfigureStatus configure_status_; |
167 | 152 |
168 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); | 153 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); |
169 }; | 154 }; |
170 | 155 |
171 } // namespace sync_driver | 156 } // namespace sync_driver |
172 | 157 |
173 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ | 158 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ |
OLD | NEW |