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, | 39 virtual void OnSingleDataTypeWillStop(syncer::ModelType type) = 0; |
40 const syncer::SyncError& error) = 0; | |
41 | 40 |
42 // Called when the ModelAssociationManager has tried to perform model | 41 // Called when the ModelAssociationManager has tried to perform model |
43 // association for all desired types and has nothing left to do. | 42 // association for all desired types and has nothing left to do. |
44 virtual void OnModelAssociationDone( | 43 virtual void OnModelAssociationDone( |
45 const DataTypeManager::ConfigureResult& result) = 0; | 44 const DataTypeManager::ConfigureResult& result) = 0; |
46 virtual ~ModelAssociationManagerDelegate() {} | 45 virtual ~ModelAssociationManagerDelegate() {} |
47 }; | 46 }; |
48 | 47 |
49 // The class that is responsible for model association. | 48 // The class that is responsible for model association. |
50 class ModelAssociationManager { | 49 class ModelAssociationManager { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Called by Initialize() to stop types that are not in |desired_types_|. | 91 // Called by Initialize() to stop types that are not in |desired_types_|. |
93 void StopDisabledTypes(); | 92 void StopDisabledTypes(); |
94 | 93 |
95 // Start loading non-running types that are in |desired_types_|. | 94 // Start loading non-running types that are in |desired_types_|. |
96 void LoadEnabledTypes(); | 95 void LoadEnabledTypes(); |
97 | 96 |
98 // Callback passed to each data type controller on starting association. This | 97 // Callback passed to each data type controller on starting association. This |
99 // callback will be invoked when the model association is done. | 98 // callback will be invoked when the model association is done. |
100 void TypeStartCallback(syncer::ModelType type, | 99 void TypeStartCallback(syncer::ModelType type, |
101 base::TimeTicks type_start_time, | 100 base::TimeTicks type_start_time, |
102 DataTypeController::ConfigureResult start_result, | 101 DataTypeController::StartResult start_result, |
103 const syncer::SyncMergeResult& local_merge_result, | 102 const syncer::SyncMergeResult& local_merge_result, |
104 const syncer::SyncMergeResult& syncer_merge_result); | 103 const syncer::SyncMergeResult& syncer_merge_result); |
105 | 104 |
106 // Callback that will be invoked when the models finish loading. This callback | 105 // Callback that will be invoked when the models finish loading. This callback |
107 // will be passed to |LoadModels| function. | 106 // will be passed to |LoadModels| function. |
108 void ModelLoadCallback(syncer::ModelType type, syncer::SyncError error); | 107 void ModelLoadCallback(syncer::ModelType type, syncer::SyncError error); |
109 | 108 |
| 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 |
110 // Called when all requested types are associated or association times out. | 113 // Called when all requested types are associated or association times out. |
111 // Notify |delegate_| of configuration results. | 114 // Notify |delegate_| of configuration results. |
112 void ModelAssociationDone(); | 115 void ModelAssociationDone(); |
113 | 116 |
114 // A helper to stop an individual datatype. | 117 // A helper to stop an individual datatype. |
115 void StopDatatype(const syncer::SyncError& error, DataTypeController* dtc); | 118 void StopDatatype(DataTypeController* dtc); |
116 | 119 |
117 State state_; | 120 State state_; |
118 | 121 |
119 // Data types that are enabled. | 122 // Data types that are enabled. |
120 syncer::ModelTypeSet desired_types_; | 123 syncer::ModelTypeSet desired_types_; |
121 | 124 |
122 // Data types that are requested to associate. | 125 // Data types that are requested to associate. |
123 syncer::ModelTypeSet requested_types_; | 126 syncer::ModelTypeSet requested_types_; |
124 | 127 |
125 // Data types currently being associated, including types waiting for model | 128 // Data types currently being associated, including types waiting for model |
126 // load. | 129 // load. |
127 syncer::ModelTypeSet associating_types_; | 130 syncer::ModelTypeSet associating_types_; |
128 | 131 |
129 // Data types that are loaded, i.e. ready to associate. | 132 // Data types that are loaded, i.e. ready to associate. |
130 syncer::ModelTypeSet loaded_types_; | 133 syncer::ModelTypeSet loaded_types_; |
131 | 134 |
132 // Data types that are associated, i.e. no more action needed during | 135 // Data types that are associated, i.e. no more action needed during |
133 // reconfiguration if not disabled. | 136 // reconfiguration if not disabled. |
134 syncer::ModelTypeSet associated_types_; | 137 syncer::ModelTypeSet associated_types_; |
135 | 138 |
| 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 |
136 // Time when StartAssociationAsync() is called to associate for a set of data | 151 // Time when StartAssociationAsync() is called to associate for a set of data |
137 // types. | 152 // types. |
138 base::TimeTicks association_start_time_; | 153 base::TimeTicks association_start_time_; |
139 | 154 |
140 // Set of all registered controllers. | 155 // Set of all registered controllers. |
141 const DataTypeController::TypeMap* controllers_; | 156 const DataTypeController::TypeMap* controllers_; |
142 | 157 |
143 // The processor in charge of handling model association results. | 158 // The processor in charge of handling model association results. |
144 ModelAssociationManagerDelegate* delegate_; | 159 ModelAssociationManagerDelegate* delegate_; |
145 | 160 |
146 // Timer to track and limit how long a datatype takes to model associate. | 161 // Timer to track and limit how long a datatype takes to model associate. |
147 base::OneShotTimer<ModelAssociationManager> timer_; | 162 base::OneShotTimer<ModelAssociationManager> timer_; |
148 | 163 |
149 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; | 164 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; |
150 | 165 |
151 DataTypeManager::ConfigureStatus configure_status_; | 166 DataTypeManager::ConfigureStatus configure_status_; |
152 | 167 |
153 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); | 168 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); |
154 }; | 169 }; |
155 | 170 |
156 } // namespace sync_driver | 171 } // namespace sync_driver |
157 | 172 |
158 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ | 173 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ |
OLD | NEW |