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

Side by Side Diff: chrome/browser/sync/glue/model_association_manager.h

Issue 10387144: [Sync] - Implement isolated model association. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 8 years, 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__ 5 #ifndef CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__
6 #define CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__ 6 #define CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__
7 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 10
11 #include "base/memory/weak_ptr.h" 11 #include "base/memory/weak_ptr.h"
12 #include "base/timer.h"
12 13
13 #include "chrome/browser/sync/glue/data_type_manager.h" 14 #include "chrome/browser/sync/glue/data_type_manager.h"
14 15
15 namespace browser_sync { 16 namespace browser_sync {
16 17
17 class DataTypeController; 18 class DataTypeController;
18 19
19 // |ModelAssociationManager| association functions are async. The results of 20 // |ModelAssociationManager| association functions are async. The results of
20 // those operations are passed back via this interface. 21 // those operations are passed back via this interface.
21 class ModelAssociationResultProcessor { 22 class ModelAssociationResultProcessor {
22 public: 23 public:
23 virtual void OnModelAssociationDone( 24 virtual void OnModelAssociationDone(
24 const DataTypeManager::ConfigureResult& result) = 0; 25 const DataTypeManager::ConfigureResult& result) = 0;
26
27 // when types (that did not complete loading, during the previous
28 // run of the configure) get loaded this callback is called to let the
29 // DTM know and request a reconfigure.
30 virtual void OnTypesLoaded() = 0;
25 }; 31 };
26 32
27 // The class that is responsible for model association. 33 // The class that is responsible for model association.
28 class ModelAssociationManager { 34 class ModelAssociationManager {
29 public: 35 public:
30 ModelAssociationManager(const DataTypeController::TypeMap* controllers, 36 ModelAssociationManager(const DataTypeController::TypeMap* controllers,
31 ModelAssociationResultProcessor* processor); 37 ModelAssociationResultProcessor* processor);
32 virtual ~ModelAssociationManager(); 38 virtual ~ModelAssociationManager();
33 // Initializes the state to do the model association in future. This 39 // Initializes the state to do the model association in future. This
34 // should be called before downloading the data. A subsequent call of 40 // should be called before downloading the data. A subsequent call of
35 // Initialize is only allowed when |OnModelAssociationDone| 41 // Initialize is only allowed when |OnModelAssociationDone|
36 // has been called back from this class to the caller. 42 // has been called back from this class to the caller.
tim (not reviewing) 2012/05/21 23:18:57 I still don't really grok this comment. "OnModelA
lipalani1 2012/05/22 01:23:58 Done.
37 void Initialize(syncable::ModelTypeSet desired_types); 43 void Initialize(syncable::ModelTypeSet desired_types);
38 44
39 // Can be called at any time. Synchronously stops all datatypes. 45 // Can be called at any time. Synchronously stops all datatypes.
40 void Stop(); 46 void Stop();
41 47
42 // Should only be called after Initialize. 48 // Should only be called after Initialize.
43 // Starts the actual association. When this is completed 49 // Starts the actual association. When this is completed
44 // |OnModelAssociationDone| would be called on callback. 50 // |OnModelAssociationDone| would be called on callback.
45 void StartAssociationAsync(); 51 void StartAssociationAsync();
46 52
47 // It is valid to call this only when we are initialized to configure 53 // It is valid to call this only when we are initialized to configure
48 // but we have not started the configuration.(i.e., |Initialize| has 54 // but we have not started the configuration.(i.e., |Initialize| has
49 // been called but |StartAssociationAsync| has not yet been called.) 55 // been called but |StartAssociationAsync| has not yet been called.)
50 // If we have started configuration then the DTM will wait until 56 // If we have started configuration then the DTM will wait until
51 // the current configuration is done before processing the reconfigure 57 // the current configuration is done before processing the reconfigure
52 // request. 58 // request.
53 void AbortConfigurationForReconfiguration(); 59 void AbortConfigurationForReconfiguration();
54 60
55 // Should only be called after Initialize. 61 // Should only be called after Initialize.
56 // Stops any disabled types. 62 // Stops any disabled types.
57 void StopDisabledTypes(); 63 void StopDisabledTypes();
58 64
65 // This is used for TESTING PURPOSE ONLY. When invoked will
66 // simulate as though the timeout has been reached for datatype loading.
67 // Achieves that by stopping the timer and calling the timeout callback.
68 void TestSimulateDataTypeLoadTimeout();
69
59 private: 70 private:
60 enum State { 71 enum State {
61 // This is the state after |Initialize| is called. 72 // This is the state after |Initialize| is called.
62 INITIAILIZED_TO_CONFIGURE, 73 INITIAILIZED_TO_CONFIGURE,
63 // Starting a new configuration. 74 // Starting a new configuration.
64 CONFIGURING, 75 CONFIGURING,
65 // A stop command was issued. 76 // A stop command was issued.
66 ABORT, 77 ABORT,
67 // No configuration is in progress. 78 // No configuration is in progress.
68 IDLE 79 IDLE
(...skipping 13 matching lines...) Expand all
82 // will be passed to |LoadModels| function. 93 // will be passed to |LoadModels| function.
83 void ModelLoadCallback(syncable::ModelType type, SyncError error); 94 void ModelLoadCallback(syncable::ModelType type, SyncError error);
84 95
85 // Calls the |LoadModels| method on the next controller waiting to start. 96 // Calls the |LoadModels| method on the next controller waiting to start.
86 void LoadModelForNextType(); 97 void LoadModelForNextType();
87 98
88 // Calls |StartAssociating| on the next available controller whose models are 99 // Calls |StartAssociating| on the next available controller whose models are
89 // loaded. 100 // loaded.
90 void StartAssociatingNextType(); 101 void StartAssociatingNextType();
91 102
103 // We have waited long enough and the model has not loaded yet.
104 void ModelLoadTimedOut();
105
106 void HandleFailedTypes(DataTypeController::StartResult result,
107 const SyncError& error);
108
109 syncable::ModelTypeSet GetTypesWaitingToLoad();
110
111
92 State state_; 112 State state_;
93 syncable::ModelTypeSet desired_types_; 113 syncable::ModelTypeSet desired_types_;
94 std::list<SyncError> failed_datatypes_info_; 114 std::list<SyncError> failed_datatypes_info_;
95 std::map<syncable::ModelType, int> start_order_; 115 std::map<syncable::ModelType, int> start_order_;
96 116
97 // Controllers that need to be started during a config cycle. 117 // Controllers that need to be started during a config cycle.
98 std::vector<DataTypeController*> needs_start_; 118 std::vector<DataTypeController*> needs_start_;
99 119
100 // Controllers that need to be stopped during a config cycle. 120 // Controllers that need to be stopped during a config cycle.
101 std::vector<DataTypeController*> needs_stop_; 121 std::vector<DataTypeController*> needs_stop_;
102 122
103 // Controllers whose |LoadModels| function has been invoked and that are 123 // Controllers whose |LoadModels| function has been invoked and that are
104 // waiting for their models to be loaded. Cotrollers will be moved from 124 // waiting for their models to be loaded. Cotrollers will be moved from
105 // |needs_start_| to this list as their |LoadModels| method is invoked. 125 // |needs_start_| to this list as their |LoadModels| method is invoked.
106 std::vector<DataTypeController*> pending_model_load_; 126 std::vector<DataTypeController*> pending_model_load_;
107 127
108 // Controllers whose models are loaded and are ready to do model 128 // Controllers whose models are loaded and are ready to do model
109 // association. Controllers will be moved from |pending_model_load_| 129 // association. Controllers will be moved from |pending_model_load_|
110 // list to this list as they finish loading their model. 130 // list to this list as they finish loading their model.
111 std::vector<DataTypeController*> waiting_to_associate_; 131 std::vector<DataTypeController*> waiting_to_associate_;
112 132
113 // Controller currently doing model association. 133 // Controller currently doing model association.
114 DataTypeController* currently_associating_; 134 DataTypeController* currently_associating_;
115 135
116 // Set of all registered controllers. 136 // Set of all registered controllers.
117 const DataTypeController::TypeMap* controllers_; 137 const DataTypeController::TypeMap* controllers_;
118 ModelAssociationResultProcessor* result_processor_; 138 ModelAssociationResultProcessor* result_processor_;
119 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; 139 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_;
140 base::OneShotTimer<ModelAssociationManager> timer_;
120 }; 141 };
121 } // namespace browser_sync 142 } // namespace browser_sync
122 #endif // CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__ 143 #endif // CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698