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

Side by Side Diff: components/sync/driver/model_association_manager.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_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/macros.h" 10 #include "base/macros.h"
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h" 12 #include "base/timer/timer.h"
13 13
14 #include "components/sync/base/weak_handle.h" 14 #include "components/sync/base/weak_handle.h"
15 #include "components/sync/core/data_type_association_stats.h" 15 #include "components/sync/core/data_type_association_stats.h"
16 #include "components/sync/driver/data_type_manager.h" 16 #include "components/sync/driver/data_type_manager.h"
17 17
18 namespace syncer { 18 namespace sync_driver {
19 19
20 class DataTypeController; 20 class DataTypeController;
21 21
22 // |ModelAssociationManager| does the heavy lifting for doing the actual model 22 // |ModelAssociationManager| does the heavy lifting for doing the actual model
23 // association. It instructs DataTypeControllers to load models, start 23 // association. It instructs DataTypeControllers to load models, start
24 // associating and stopping. Since the operations are async it uses an 24 // associating and stopping. Since the operations are async it uses an
25 // interface to inform DataTypeManager the results of the operations. 25 // interface to inform DataTypeManager the results of the operations.
26 // This class is owned by DataTypeManager. 26 // This class is owned by DataTypeManager.
27 // |ModelAssociationManager| association functions are async. The results of 27 // |ModelAssociationManager| association functions are async. The results of
28 // those operations are passed back via this interface. 28 // those operations are passed back via this interface.
29 class ModelAssociationManagerDelegate { 29 class ModelAssociationManagerDelegate {
30 public: 30 public:
31 // Called when all desired types are ready to be configured with 31 // Called when all desired types are ready to be configured with
32 // BackendDataTypeConfigurer. Data type is ready when its progress marker is 32 // BackendDataTypeConfigurer. Data type is ready when its progress marker is
33 // available to configurer. Directory data types are always ready, their 33 // available to configurer. Directory data types are always ready, their
34 // progress markers are read from directory. USS data type controllers need to 34 // progress markers are read from directory. USS data type controllers need to
35 // load model and read data type context first. 35 // load model and read data type context first.
36 // This function is called at most once after each call to 36 // This function is called at most once after each call to
37 // ModelAssociationManager::Initialize(). 37 // ModelAssociationManager::Initialize().
38 virtual void OnAllDataTypesReadyForConfigure() = 0; 38 virtual void OnAllDataTypesReadyForConfigure() = 0;
39 39
40 // Called when model association (MergeDataAndStartSyncing) has completed 40 // Called when model association (MergeDataAndStartSyncing) has completed
41 // for |type|, regardless of success or failure. 41 // for |type|, regardless of success or failure.
42 virtual void OnSingleDataTypeAssociationDone( 42 virtual void OnSingleDataTypeAssociationDone(
43 ModelType type, 43 syncer::ModelType type,
44 const DataTypeAssociationStats& association_stats) = 0; 44 const syncer::DataTypeAssociationStats& association_stats) = 0;
45 45
46 // Called when the ModelAssociationManager has decided it must stop |type|, 46 // Called when the ModelAssociationManager has decided it must stop |type|,
47 // likely because it is no longer a desired data type or sync is shutting 47 // likely because it is no longer a desired data type or sync is shutting
48 // down. 48 // down.
49 virtual void OnSingleDataTypeWillStop(ModelType type, 49 virtual void OnSingleDataTypeWillStop(syncer::ModelType type,
50 const SyncError& error) = 0; 50 const syncer::SyncError& error) = 0;
51 51
52 // Called when the ModelAssociationManager has tried to perform model 52 // Called when the ModelAssociationManager has tried to perform model
53 // association for all desired types and has nothing left to do. 53 // association for all desired types and has nothing left to do.
54 virtual void OnModelAssociationDone( 54 virtual void OnModelAssociationDone(
55 const DataTypeManager::ConfigureResult& result) = 0; 55 const DataTypeManager::ConfigureResult& result) = 0;
56 virtual ~ModelAssociationManagerDelegate() {} 56 virtual ~ModelAssociationManagerDelegate() {}
57 }; 57 };
58 58
59 // The class that is responsible for model association. 59 // The class that is responsible for model association.
60 class ModelAssociationManager { 60 class ModelAssociationManager {
(...skipping 12 matching lines...) Expand all
73 ModelAssociationManager(const DataTypeController::TypeMap* controllers, 73 ModelAssociationManager(const DataTypeController::TypeMap* controllers,
74 ModelAssociationManagerDelegate* delegate); 74 ModelAssociationManagerDelegate* delegate);
75 virtual ~ModelAssociationManager(); 75 virtual ~ModelAssociationManager();
76 76
77 // Initializes the state to do the model association in future. This 77 // Initializes the state to do the model association in future. This
78 // should be called before communicating with sync server. A subsequent call 78 // should be called before communicating with sync server. A subsequent call
79 // of Initialize is only allowed if the ModelAssociationManager has invoked 79 // of Initialize is only allowed if the ModelAssociationManager has invoked
80 // |OnModelAssociationDone| on the |ModelAssociationManagerDelegate|. After 80 // |OnModelAssociationDone| on the |ModelAssociationManagerDelegate|. After
81 // this call, there should be several calls to StartAssociationAsync() 81 // this call, there should be several calls to StartAssociationAsync()
82 // to associate subset of |desired_types|. 82 // to associate subset of |desired_types|.
83 void Initialize(ModelTypeSet desired_types); 83 void Initialize(syncer::ModelTypeSet desired_types);
84 84
85 // Can be called at any time. Synchronously stops all datatypes. 85 // Can be called at any time. Synchronously stops all datatypes.
86 void Stop(); 86 void Stop();
87 87
88 // Should only be called after Initialize to start the actual association. 88 // Should only be called after Initialize to start the actual association.
89 // |types_to_associate| should be subset of |desired_types| in Initialize(). 89 // |types_to_associate| should be subset of |desired_types| in Initialize().
90 // When this is completed, |OnModelAssociationDone| will be invoked. 90 // When this is completed, |OnModelAssociationDone| will be invoked.
91 void StartAssociationAsync(const ModelTypeSet& types_to_associate); 91 void StartAssociationAsync(const syncer::ModelTypeSet& types_to_associate);
92 92
93 // This is used for TESTING PURPOSE ONLY. The test case can inspect 93 // This is used for TESTING PURPOSE ONLY. The test case can inspect
94 // and modify the timer. 94 // and modify the timer.
95 // TODO(sync) : This would go away if we made this class be able to do 95 // TODO(sync) : This would go away if we made this class be able to do
96 // Dependency injection. crbug.com/129212. 96 // Dependency injection. crbug.com/129212.
97 base::OneShotTimer* GetTimerForTesting(); 97 base::OneShotTimer* GetTimerForTesting();
98 98
99 State state() const { return state_; } 99 State state() const { return state_; }
100 100
101 private: 101 private:
102 // Called at the end of association to reset state to prepare for next 102 // Called at the end of association to reset state to prepare for next
103 // round of association. 103 // round of association.
104 void ResetForNextAssociation(); 104 void ResetForNextAssociation();
105 105
106 // Called by Initialize() to stop types that are not in |desired_types_|. 106 // Called by Initialize() to stop types that are not in |desired_types_|.
107 void StopDisabledTypes(); 107 void StopDisabledTypes();
108 108
109 // Start loading non-running types that are in |desired_types_|. 109 // Start loading non-running types that are in |desired_types_|.
110 void LoadEnabledTypes(); 110 void LoadEnabledTypes();
111 111
112 // Callback passed to each data type controller on starting association. This 112 // Callback passed to each data type controller on starting association. This
113 // callback will be invoked when the model association is done. 113 // callback will be invoked when the model association is done.
114 void TypeStartCallback(ModelType type, 114 void TypeStartCallback(syncer::ModelType type,
115 base::TimeTicks type_start_time, 115 base::TimeTicks type_start_time,
116 DataTypeController::ConfigureResult start_result, 116 DataTypeController::ConfigureResult start_result,
117 const SyncMergeResult& local_merge_result, 117 const syncer::SyncMergeResult& local_merge_result,
118 const SyncMergeResult& syncer_merge_result); 118 const syncer::SyncMergeResult& syncer_merge_result);
119 119
120 // Callback that will be invoked when the models finish loading. This callback 120 // Callback that will be invoked when the models finish loading. This callback
121 // will be passed to |LoadModels| function. 121 // will be passed to |LoadModels| function.
122 void ModelLoadCallback(ModelType type, const SyncError& error); 122 void ModelLoadCallback(syncer::ModelType type,
123 const syncer::SyncError& error);
123 124
124 // Called when all requested types are associated or association times out. 125 // Called when all requested types are associated or association times out.
125 // Will clean up any unfinished types, and update |state_| to be |new_state| 126 // Will clean up any unfinished types, and update |state_| to be |new_state|
126 // Finally, it will notify |delegate_| of the configuration result. 127 // Finally, it will notify |delegate_| of the configuration result.
127 void ModelAssociationDone(State new_state); 128 void ModelAssociationDone(State new_state);
128 129
129 // A helper to stop an individual datatype. 130 // A helper to stop an individual datatype.
130 void StopDatatype(const SyncError& error, DataTypeController* dtc); 131 void StopDatatype(const syncer::SyncError& error, DataTypeController* dtc);
131 132
132 // Calls delegate's OnAllDataTypesReadyForConfigure when all datatypes from 133 // Calls delegate's OnAllDataTypesReadyForConfigure when all datatypes from
133 // desired_types_ are ready for configure. Ensures that for every call to 134 // desired_types_ are ready for configure. Ensures that for every call to
134 // Initialize callback is called at most once. 135 // Initialize callback is called at most once.
135 // Datatype is ready if either it doesn't require LoadModels before configure 136 // Datatype is ready if either it doesn't require LoadModels before configure
136 // or LoadModels successfully finished. 137 // or LoadModels successfully finished.
137 void NotifyDelegateIfReadyForConfigure(); 138 void NotifyDelegateIfReadyForConfigure();
138 139
139 State state_; 140 State state_;
140 141
141 // Data types that are enabled. 142 // Data types that are enabled.
142 ModelTypeSet desired_types_; 143 syncer::ModelTypeSet desired_types_;
143 144
144 // Data types that are requested to associate. 145 // Data types that are requested to associate.
145 ModelTypeSet requested_types_; 146 syncer::ModelTypeSet requested_types_;
146 147
147 // Data types currently being associated, including types waiting for model 148 // Data types currently being associated, including types waiting for model
148 // load. 149 // load.
149 ModelTypeSet associating_types_; 150 syncer::ModelTypeSet associating_types_;
150 151
151 // Data types that are loaded, i.e. ready to associate. 152 // Data types that are loaded, i.e. ready to associate.
152 ModelTypeSet loaded_types_; 153 syncer::ModelTypeSet loaded_types_;
153 154
154 // Data types that are associated, i.e. no more action needed during 155 // Data types that are associated, i.e. no more action needed during
155 // reconfiguration if not disabled. 156 // reconfiguration if not disabled.
156 ModelTypeSet associated_types_; 157 syncer::ModelTypeSet associated_types_;
157 158
158 // Time when StartAssociationAsync() is called to associate for a set of data 159 // Time when StartAssociationAsync() is called to associate for a set of data
159 // types. 160 // types.
160 base::TimeTicks association_start_time_; 161 base::TimeTicks association_start_time_;
161 162
162 // Set of all registered controllers. 163 // Set of all registered controllers.
163 const DataTypeController::TypeMap* controllers_; 164 const DataTypeController::TypeMap* controllers_;
164 165
165 // The processor in charge of handling model association results. 166 // The processor in charge of handling model association results.
166 ModelAssociationManagerDelegate* delegate_; 167 ModelAssociationManagerDelegate* delegate_;
167 168
168 // Timer to track and limit how long a datatype takes to model associate. 169 // Timer to track and limit how long a datatype takes to model associate.
169 base::OneShotTimer timer_; 170 base::OneShotTimer timer_;
170 171
171 DataTypeManager::ConfigureStatus configure_status_; 172 DataTypeManager::ConfigureStatus configure_status_;
172 173
173 bool notified_about_ready_for_configure_; 174 bool notified_about_ready_for_configure_;
174 175
175 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; 176 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_;
176 177
177 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); 178 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager);
178 }; 179 };
179 180
180 } // namespace syncer 181 } // namespace sync_driver
181 182
182 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ 183 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__
OLDNEW
« no previous file with comments | « components/sync/driver/invalidation_adapter.cc ('k') | components/sync/driver/model_association_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698