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

Side by Side Diff: components/sync_driver/model_association_manager.h

Issue 317453002: sync: cut a few profile deps from DataTypeControllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move OnUserShareReady Created 6 years, 6 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 | Annotate | Revision Log
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/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/timer/timer.h" 11 #include "base/timer/timer.h"
12 12
13 #include "components/sync_driver/data_type_manager.h" 13 #include "components/sync_driver/data_type_manager.h"
14 #include "sync/internal_api/public/data_type_association_stats.h" 14 #include "sync/internal_api/public/data_type_association_stats.h"
15 #include "sync/internal_api/public/util/weak_handle.h" 15 #include "sync/internal_api/public/util/weak_handle.h"
16 16
17 // |ModelAssociationManager| does the heavy lifting for doing the actual model 17 // |ModelAssociationManager| does the heavy lifting for doing the actual model
18 // association. It instructs DataTypeControllers to load models, start 18 // association. It instructs DataTypeControllers to load models, start
19 // associating and stopping. Since the operations are async it uses an 19 // associating and stopping. Since the operations are async it uses an
20 // interface to inform DataTypeManager the results of the operations. 20 // interface to inform DataTypeManager the results of the operations.
21 // This class is owned by DataTypeManager. 21 // This class is owned by DataTypeManager.
22 namespace browser_sync { 22 namespace browser_sync {
23 23
24 class DataTypeController; 24 class DataTypeController;
25 25
26 // |ModelAssociationManager| association functions are async. The results of 26 // |ModelAssociationManager| association functions are async. The results of
27 // those operations are passed back via this interface. 27 // those operations are passed back via this interface.
28 class ModelAssociationResultProcessor { 28 class ModelAssociationManagerDelegate {
29 public: 29 public:
30 // Called when model association (MergeDataAndStartSyncing) has completed
31 // for |type|, regardless of success or failure.
30 virtual void OnSingleDataTypeAssociationDone( 32 virtual void OnSingleDataTypeAssociationDone(
31 syncer::ModelType type, 33 syncer::ModelType type,
32 const syncer::DataTypeAssociationStats& association_stats) = 0; 34 const syncer::DataTypeAssociationStats& association_stats) = 0;
35
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
38 // down.
39 virtual void OnSingleDataTypeWillStop(syncer::ModelType type) = 0;
40
41 // Called when the ModelAssociationManager has tried to perform model
42 // association for all desired types and has nothing left to do.
33 virtual void OnModelAssociationDone( 43 virtual void OnModelAssociationDone(
34 const DataTypeManager::ConfigureResult& result) = 0; 44 const DataTypeManager::ConfigureResult& result) = 0;
35 virtual ~ModelAssociationResultProcessor() {} 45 virtual ~ModelAssociationManagerDelegate() {}
36 }; 46 };
37 47
38 // The class that is responsible for model association. 48 // The class that is responsible for model association.
39 class ModelAssociationManager { 49 class ModelAssociationManager {
40 public: 50 public:
41 ModelAssociationManager(const DataTypeController::TypeMap* controllers, 51 ModelAssociationManager(const DataTypeController::TypeMap* controllers,
42 ModelAssociationResultProcessor* processor); 52 ModelAssociationManagerDelegate* delegate);
43 virtual ~ModelAssociationManager(); 53 virtual ~ModelAssociationManager();
44 54
45 // Initializes the state to do the model association in future. This 55 // Initializes the state to do the model association in future. This
46 // should be called before communicating with sync server. A subsequent call 56 // should be called before communicating with sync server. A subsequent call
47 // of Initialize is only allowed if the ModelAssociationManager has invoked 57 // of Initialize is only allowed if the ModelAssociationManager has invoked
48 // |OnModelAssociationDone| on the |ModelAssociationResultProcessor|. After 58 // |OnModelAssociationDone| on the |ModelAssociationManagerDelegate|. After
49 // this call, there should be several calls to StartAssociationAsync() 59 // this call, there should be several calls to StartAssociationAsync()
50 // to associate subset of |desired_types|. 60 // to associate subset of |desired_types|.
51 void Initialize(syncer::ModelTypeSet desired_types); 61 void Initialize(syncer::ModelTypeSet desired_types);
52 62
53 // Can be called at any time. Synchronously stops all datatypes. 63 // Can be called at any time. Synchronously stops all datatypes.
54 void Stop(); 64 void Stop();
55 65
56 // Should only be called after Initialize to start the actual association. 66 // Should only be called after Initialize to start the actual association.
57 // |types_to_associate| should be subset of |desired_types| in Initialize(). 67 // |types_to_associate| should be subset of |desired_types| in Initialize().
58 // When this is completed, |OnModelAssociationDone| will be invoked. 68 // When this is completed, |OnModelAssociationDone| will be invoked.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 104
95 // 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
96 // will be passed to |LoadModels| function. 106 // will be passed to |LoadModels| function.
97 void ModelLoadCallback(syncer::ModelType type, syncer::SyncError error); 107 void ModelLoadCallback(syncer::ModelType type, syncer::SyncError error);
98 108
99 // When a type fails to load or fails associating this method is invoked to 109 // When a type fails to load or fails associating this method is invoked to
100 // do the book keeping and do the UMA reporting. 110 // do the book keeping and do the UMA reporting.
101 void AppendToFailedDatatypesAndLogError(const syncer::SyncError& error); 111 void AppendToFailedDatatypesAndLogError(const syncer::SyncError& error);
102 112
103 // Called when all requested types are associated or association times out. 113 // Called when all requested types are associated or association times out.
104 // Notify |result_processor_| of configuration results. 114 // Notify |delegate_| of configuration results.
105 void ModelAssociationDone(); 115 void ModelAssociationDone();
106 116
117 // A helper to stop an individual datatype.
118 void StopDatatype(DataTypeController* dtc);
119
107 State state_; 120 State state_;
108 121
109 // Data types that are enabled. 122 // Data types that are enabled.
110 syncer::ModelTypeSet desired_types_; 123 syncer::ModelTypeSet desired_types_;
111 124
112 // Data types that are requested to associate. 125 // Data types that are requested to associate.
113 syncer::ModelTypeSet requested_types_; 126 syncer::ModelTypeSet requested_types_;
114 127
115 // Data types currently being associated, including types waiting for model 128 // Data types currently being associated, including types waiting for model
116 // load. 129 // load.
(...skipping 19 matching lines...) Expand all
136 syncer::ModelTypeSet needs_crypto_types_; 149 syncer::ModelTypeSet needs_crypto_types_;
137 150
138 // 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
139 // types. 152 // types.
140 base::TimeTicks association_start_time_; 153 base::TimeTicks association_start_time_;
141 154
142 // Set of all registered controllers. 155 // Set of all registered controllers.
143 const DataTypeController::TypeMap* controllers_; 156 const DataTypeController::TypeMap* controllers_;
144 157
145 // The processor in charge of handling model association results. 158 // The processor in charge of handling model association results.
146 ModelAssociationResultProcessor* result_processor_; 159 ModelAssociationManagerDelegate* delegate_;
147 160
148 // 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.
149 base::OneShotTimer<ModelAssociationManager> timer_; 162 base::OneShotTimer<ModelAssociationManager> timer_;
150 163
151 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; 164 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_;
152 165
153 DataTypeManager::ConfigureStatus configure_status_; 166 DataTypeManager::ConfigureStatus configure_status_;
154 167
155 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); 168 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager);
156 }; 169 };
157 } // namespace browser_sync 170 } // namespace browser_sync
158 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__ 171 #endif // COMPONENTS_SYNC_DRIVER_MODEL_ASSOCIATION_MANAGER_H__
OLDNEW
« no previous file with comments | « components/sync_driver/data_type_manager_impl_unittest.cc ('k') | components/sync_driver/model_association_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698