Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: components/sync/driver/data_type_manager_impl.h

Issue 2388673002: Revert of [Sync] Move //components/sync to the syncer namespace. (patchset #5 id:40001 of https://co (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_DATA_TYPE_MANAGER_IMPL_H__ 5 #ifndef COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_IMPL_H__
6 #define COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_IMPL_H__ 6 #define COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_IMPL_H__
7 7
8 #include "components/sync/driver/data_type_manager.h" 8 #include "components/sync/driver/data_type_manager.h"
9 9
10 #include <map> 10 #include <map>
11 #include <queue> 11 #include <queue>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/callback_forward.h" 14 #include "base/callback_forward.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/time/time.h" 18 #include "base/time/time.h"
19 #include "components/sync/base/weak_handle.h"
20 #include "components/sync/driver/backend_data_type_configurer.h" 19 #include "components/sync/driver/backend_data_type_configurer.h"
21 #include "components/sync/driver/model_association_manager.h" 20 #include "components/sync/driver/model_association_manager.h"
22 21
23 namespace syncer { 22 namespace syncer {
23 struct DataTypeConfigurationStats;
24 class DataTypeDebugInfoListener;
25 template <typename T>
26 class WeakHandle;
27 }
28
29 namespace sync_driver {
24 30
25 class DataTypeController; 31 class DataTypeController;
26 class DataTypeDebugInfoListener;
27 class DataTypeEncryptionHandler; 32 class DataTypeEncryptionHandler;
28 class DataTypeManagerObserver; 33 class DataTypeManagerObserver;
29 struct DataTypeConfigurationStats;
30 34
31 // List of data types grouped by priority and ordered from high priority to 35 // List of data types grouped by priority and ordered from high priority to
32 // low priority. 36 // low priority.
33 typedef std::queue<ModelTypeSet> TypeSetPriorityList; 37 typedef std::queue<syncer::ModelTypeSet> TypeSetPriorityList;
34 38
35 class DataTypeManagerImpl : public DataTypeManager, 39 class DataTypeManagerImpl : public DataTypeManager,
36 public ModelAssociationManagerDelegate { 40 public ModelAssociationManagerDelegate {
37 public: 41 public:
38 DataTypeManagerImpl( 42 DataTypeManagerImpl(
39 const WeakHandle<DataTypeDebugInfoListener>& debug_info_listener, 43 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
44 debug_info_listener,
40 const DataTypeController::TypeMap* controllers, 45 const DataTypeController::TypeMap* controllers,
41 const DataTypeEncryptionHandler* encryption_handler, 46 const DataTypeEncryptionHandler* encryption_handler,
42 BackendDataTypeConfigurer* configurer, 47 BackendDataTypeConfigurer* configurer,
43 DataTypeManagerObserver* observer); 48 DataTypeManagerObserver* observer);
44 ~DataTypeManagerImpl() override; 49 ~DataTypeManagerImpl() override;
45 50
46 // DataTypeManager interface. 51 // DataTypeManager interface.
47 void Configure(ModelTypeSet desired_types, ConfigureReason reason) override; 52 void Configure(syncer::ModelTypeSet desired_types,
48 void ReenableType(ModelType type) override; 53 syncer::ConfigureReason reason) override;
54 void ReenableType(syncer::ModelType type) override;
49 void ResetDataTypeErrors() override; 55 void ResetDataTypeErrors() override;
50 56
51 // Needed only for backend migration. 57 // Needed only for backend migration.
52 void PurgeForMigration(ModelTypeSet undesired_types, 58 void PurgeForMigration(syncer::ModelTypeSet undesired_types,
53 ConfigureReason reason) override; 59 syncer::ConfigureReason reason) override;
54 60
55 void Stop() override; 61 void Stop() override;
56 State state() const override; 62 State state() const override;
57 63
58 // |ModelAssociationManagerDelegate| implementation. 64 // |ModelAssociationManagerDelegate| implementation.
59 void OnAllDataTypesReadyForConfigure() override; 65 void OnAllDataTypesReadyForConfigure() override;
60 void OnSingleDataTypeAssociationDone( 66 void OnSingleDataTypeAssociationDone(
61 ModelType type, 67 syncer::ModelType type,
62 const DataTypeAssociationStats& association_stats) override; 68 const syncer::DataTypeAssociationStats& association_stats) override;
63 void OnModelAssociationDone( 69 void OnModelAssociationDone(
64 const DataTypeManager::ConfigureResult& result) override; 70 const DataTypeManager::ConfigureResult& result) override;
65 void OnSingleDataTypeWillStop(ModelType type, 71 void OnSingleDataTypeWillStop(syncer::ModelType type,
66 const SyncError& error) override; 72 const syncer::SyncError& error) override;
67 73
68 // Used by unit tests. TODO(sync) : This would go away if we made 74 // Used by unit tests. TODO(sync) : This would go away if we made
69 // this class be able to do Dependency injection. crbug.com/129212. 75 // this class be able to do Dependency injection. crbug.com/129212.
70 ModelAssociationManager* GetModelAssociationManagerForTesting() { 76 ModelAssociationManager* GetModelAssociationManagerForTesting() {
71 return &model_association_manager_; 77 return &model_association_manager_;
72 } 78 }
73 79
74 private: 80 private:
75 // Helper enum for identifying which types within a priority group to 81 // Helper enum for identifying which types within a priority group to
76 // associate. 82 // associate.
77 enum AssociationGroup { 83 enum AssociationGroup {
78 // Those types that were already downloaded and didn't have an error at 84 // Those types that were already downloaded and didn't have an error at
79 // configuration time. Corresponds with AssociationTypesInfo's 85 // configuration time. Corresponds with AssociationTypesInfo's
80 // |ready_types|. These types can start associating as soon as the 86 // |ready_types|. These types can start associating as soon as the
81 // ModelAssociationManager is not busy. 87 // ModelAssociationManager is not busy.
82 READY_AT_CONFIG, 88 READY_AT_CONFIG,
83 // All other types, including first time sync types and those that have 89 // All other types, including first time sync types and those that have
84 // encountered an error. These types must wait until the syncer has done 90 // encountered an error. These types must wait until the syncer has done
85 // any db changes and/or downloads before associating. 91 // any db changes and/or downloads before associating.
86 UNREADY_AT_CONFIG, 92 UNREADY_AT_CONFIG,
87 }; 93 };
88 94
89 friend class TestDataTypeManager; 95 friend class TestDataTypeManager;
90 96
91 // Abort configuration and stop all data types due to configuration errors. 97 // Abort configuration and stop all data types due to configuration errors.
92 void Abort(ConfigureStatus status); 98 void Abort(ConfigureStatus status);
93 99
94 // Returns the priority types (control + priority user types). 100 // Returns the priority types (control + priority user types).
95 // Virtual for overriding during tests. 101 // Virtual for overriding during tests.
96 virtual ModelTypeSet GetPriorityTypes() const; 102 virtual syncer::ModelTypeSet GetPriorityTypes() const;
97 103
98 // Divide |types| into sets by their priorities and return the sets from 104 // Divide |types| into sets by their priorities and return the sets from
99 // high priority to low priority. 105 // high priority to low priority.
100 TypeSetPriorityList PrioritizeTypes(const ModelTypeSet& types); 106 TypeSetPriorityList PrioritizeTypes(const syncer::ModelTypeSet& types);
101 107
102 // Post a task to reconfigure when no downloading or association are running. 108 // Post a task to reconfigure when no downloading or association are running.
103 void ProcessReconfigure(); 109 void ProcessReconfigure();
104 110
105 void Restart(ConfigureReason reason); 111 void Restart(syncer::ConfigureReason reason);
106 void DownloadReady(ModelTypeSet types_to_download, 112 void DownloadReady(syncer::ModelTypeSet types_to_download,
107 ModelTypeSet first_sync_types, 113 syncer::ModelTypeSet first_sync_types,
108 ModelTypeSet failed_configuration_types); 114 syncer::ModelTypeSet failed_configuration_types);
109 115
110 // Notification from the SBH that download failed due to a transient 116 // Notification from the SBH that download failed due to a transient
111 // error and it will be retried. 117 // error and it will be retried.
112 void OnDownloadRetry(); 118 void OnDownloadRetry();
113 void NotifyStart(); 119 void NotifyStart();
114 void NotifyDone(const ConfigureResult& result); 120 void NotifyDone(const ConfigureResult& result);
115 121
116 // Add to |configure_time_delta_| the time since we last called 122 // Add to |configure_time_delta_| the time since we last called
117 // Restart(). 123 // Restart().
118 void AddToConfigureTime(); 124 void AddToConfigureTime();
119 125
120 void ConfigureImpl(ModelTypeSet desired_types, ConfigureReason reason); 126 void ConfigureImpl(syncer::ModelTypeSet desired_types,
127 syncer::ConfigureReason reason);
121 128
122 // Calls data type controllers of requested types to register with backend. 129 // Calls data type controllers of requested types to register with backend.
123 void RegisterTypesWithBackend(); 130 void RegisterTypesWithBackend();
124 131
125 BackendDataTypeConfigurer::DataTypeConfigStateMap BuildDataTypeConfigStateMap( 132 BackendDataTypeConfigurer::DataTypeConfigStateMap BuildDataTypeConfigStateMap(
126 const ModelTypeSet& types_being_configured) const; 133 const syncer::ModelTypeSet& types_being_configured) const;
127 134
128 // Start download of next set of types in |download_types_queue_| (if 135 // Start download of next set of types in |download_types_queue_| (if
129 // any exist, does nothing otherwise). 136 // any exist, does nothing otherwise).
130 // Will kick off association of any new ready types. 137 // Will kick off association of any new ready types.
131 void StartNextDownload(ModelTypeSet high_priority_types_before); 138 void StartNextDownload(syncer::ModelTypeSet high_priority_types_before);
132 139
133 // Start association of next batch of data types after association of 140 // Start association of next batch of data types after association of
134 // previous batch finishes. |group| controls which set of types within 141 // previous batch finishes. |group| controls which set of types within
135 // an AssociationTypesInfo to associate. Does nothing if model associator 142 // an AssociationTypesInfo to associate. Does nothing if model associator
136 // is busy performing association. 143 // is busy performing association.
137 void StartNextAssociation(AssociationGroup group); 144 void StartNextAssociation(AssociationGroup group);
138 145
139 void StopImpl(); 146 void StopImpl();
140 147
141 // Returns the currently enabled types. 148 // Returns the currently enabled types.
142 ModelTypeSet GetEnabledTypes() const; 149 syncer::ModelTypeSet GetEnabledTypes() const;
143 150
144 BackendDataTypeConfigurer* configurer_; 151 BackendDataTypeConfigurer* configurer_;
145 // Map of all data type controllers that are available for sync. 152 // Map of all data type controllers that are available for sync.
146 // This list is determined at startup by various command line flags. 153 // This list is determined at startup by various command line flags.
147 const DataTypeController::TypeMap* controllers_; 154 const DataTypeController::TypeMap* controllers_;
148 State state_; 155 State state_;
149 ModelTypeSet last_requested_types_; 156 syncer::ModelTypeSet last_requested_types_;
150 157
151 // A set of types that were enabled at the time initialization with the 158 // A set of types that were enabled at the time initialization with the
152 // |model_association_manager_| was last attempted. 159 // |model_association_manager_| was last attempted.
153 ModelTypeSet last_enabled_types_; 160 syncer::ModelTypeSet last_enabled_types_;
154 161
155 // Whether an attempt to reconfigure was made while we were busy configuring. 162 // Whether an attempt to reconfigure was made while we were busy configuring.
156 // The |last_requested_types_| will reflect the newest set of requested types. 163 // The |last_requested_types_| will reflect the newest set of requested types.
157 bool needs_reconfigure_; 164 bool needs_reconfigure_;
158 165
159 // The reason for the last reconfigure attempt. Note: this will be set to a 166 // The reason for the last reconfigure attempt. Note: this will be set to a
160 // valid value only when |needs_reconfigure_| is set. 167 // valid value only when |needs_reconfigure_| is set.
161 ConfigureReason last_configure_reason_; 168 syncer::ConfigureReason last_configure_reason_;
162 169
163 // The last time Restart() was called. 170 // The last time Restart() was called.
164 base::Time last_restart_time_; 171 base::Time last_restart_time_;
165 172
166 // The accumulated time spent between calls to Restart() and going 173 // The accumulated time spent between calls to Restart() and going
167 // to the DONE state. 174 // to the DONE state.
168 base::TimeDelta configure_time_delta_; 175 base::TimeDelta configure_time_delta_;
169 176
170 // Sync's datatype debug info listener, which we pass model association 177 // Sync's datatype debug info listener, which we pass model association
171 // statistics to. 178 // statistics to.
172 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener_; 179 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>
180 debug_info_listener_;
173 181
174 // The manager that handles the model association of the individual types. 182 // The manager that handles the model association of the individual types.
175 ModelAssociationManager model_association_manager_; 183 ModelAssociationManager model_association_manager_;
176 184
177 // DataTypeManager must have only one observer -- the ProfileSyncService that 185 // DataTypeManager must have only one observer -- the ProfileSyncService that
178 // created it and manages its lifetime. 186 // created it and manages its lifetime.
179 DataTypeManagerObserver* const observer_; 187 DataTypeManagerObserver* const observer_;
180 188
181 // For querying failed data types (having unrecoverable error) when 189 // For querying failed data types (having unrecoverable error) when
182 // configuring backend. 190 // configuring backend.
183 DataTypeStatusTable data_type_status_table_; 191 DataTypeStatusTable data_type_status_table_;
184 192
185 // Types waiting to be downloaded. 193 // Types waiting to be downloaded.
186 TypeSetPriorityList download_types_queue_; 194 TypeSetPriorityList download_types_queue_;
187 195
188 // Types waiting for association and related time tracking info. 196 // Types waiting for association and related time tracking info.
189 struct AssociationTypesInfo { 197 struct AssociationTypesInfo {
190 AssociationTypesInfo(); 198 AssociationTypesInfo();
191 AssociationTypesInfo(const AssociationTypesInfo& other); 199 AssociationTypesInfo(const AssociationTypesInfo& other);
192 ~AssociationTypesInfo(); 200 ~AssociationTypesInfo();
193 201
194 // Types to associate. 202 // Types to associate.
195 ModelTypeSet types; 203 syncer::ModelTypeSet types;
196 // Types that have just been downloaded and are being associated for the 204 // Types that have just been downloaded and are being associated for the
197 // first time. This includes types that had previously encountered an error 205 // first time. This includes types that had previously encountered an error
198 // and had to be purged/unapplied from the sync db. 206 // and had to be purged/unapplied from the sync db.
199 // This is a subset of |types|. 207 // This is a subset of |types|.
200 ModelTypeSet first_sync_types; 208 syncer::ModelTypeSet first_sync_types;
201 // Types that were already ready for association at configuration time. 209 // Types that were already ready for association at configuration time.
202 ModelTypeSet ready_types; 210 syncer::ModelTypeSet ready_types;
203 // Time at which |types| began downloading. 211 // Time at which |types| began downloading.
204 base::Time download_start_time; 212 base::Time download_start_time;
205 // Time at which |types| finished downloading. 213 // Time at which |types| finished downloading.
206 base::Time download_ready_time; 214 base::Time download_ready_time;
207 // Time at which the association for |read_types| began. 215 // Time at which the association for |read_types| began.
208 base::Time ready_association_request_time; 216 base::Time ready_association_request_time;
209 // Time at which the association for |types| began (not relevant to 217 // Time at which the association for |types| began (not relevant to
210 // |ready_types|. 218 // |ready_types|.
211 base::Time full_association_request_time; 219 base::Time full_association_request_time;
212 // The set of types that are higher priority (and were therefore blocking) 220 // The set of types that are higher priority (and were therefore blocking)
213 // the association of |types|. 221 // the association of |types|.
214 ModelTypeSet high_priority_types_before; 222 syncer::ModelTypeSet high_priority_types_before;
215 // The subset of |types| that were successfully configured. 223 // The subset of |types| that were successfully configured.
216 ModelTypeSet configured_types; 224 syncer::ModelTypeSet configured_types;
217 }; 225 };
218 std::queue<AssociationTypesInfo> association_types_queue_; 226 std::queue<AssociationTypesInfo> association_types_queue_;
219 227
220 // The encryption handler lets the DataTypeManager know the state of sync 228 // The encryption handler lets the DataTypeManager know the state of sync
221 // datatype encryption. 229 // datatype encryption.
222 const DataTypeEncryptionHandler* encryption_handler_; 230 const DataTypeEncryptionHandler* encryption_handler_;
223 231
224 // Association and time stats of data type configuration. 232 // Association and time stats of data type configuration.
225 std::vector<DataTypeConfigurationStats> configuration_stats_; 233 std::vector<syncer::DataTypeConfigurationStats> configuration_stats_;
226 234
227 // True iff we are in the process of catching up datatypes. 235 // True iff we are in the process of catching up datatypes.
228 bool catch_up_in_progress_; 236 bool catch_up_in_progress_;
229 237
230 // Configuration process is started when ModelAssociationManager notifies 238 // Configuration process is started when ModelAssociationManager notifies
231 // DataTypeManager that all types are ready for configure. 239 // DataTypeManager that all types are ready for configure.
232 // This flag ensures that this process is started only once. 240 // This flag ensures that this process is started only once.
233 bool download_started_; 241 bool download_started_;
234 242
235 base::WeakPtrFactory<DataTypeManagerImpl> weak_ptr_factory_; 243 base::WeakPtrFactory<DataTypeManagerImpl> weak_ptr_factory_;
236 244
237 DISALLOW_COPY_AND_ASSIGN(DataTypeManagerImpl); 245 DISALLOW_COPY_AND_ASSIGN(DataTypeManagerImpl);
238 }; 246 };
239 247
240 } // namespace syncer 248 } // namespace sync_driver
241 249
242 #endif // COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_IMPL_H__ 250 #endif // COMPONENTS_SYNC_DRIVER_DATA_TYPE_MANAGER_IMPL_H__
OLDNEW
« no previous file with comments | « components/sync/driver/data_type_manager.cc ('k') | components/sync/driver/data_type_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698