Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // |ModelAssociationManager| does the heavy lifting for doing the actual model | 16 // |ModelAssociationManager| does the heavy lifting for doing the actual model |
| 16 // association. It instructs DataTypeControllers to load models, start | 17 // association. It instructs DataTypeControllers to load models, start |
| 17 // associating and stopping. Since the operations are async it uses an | 18 // associating and stopping. Since the operations are async it uses an |
| 18 // interface to inform DTM the results of the operations. | 19 // interface to inform DataTypeManager the results of the operations. |
| 19 // This class is owned by DTM. | 20 // This class is owned by DataTypeManager. |
| 20 namespace browser_sync { | 21 namespace browser_sync { |
| 21 | 22 |
| 22 class DataTypeController; | 23 class DataTypeController; |
| 23 | 24 |
| 24 // |ModelAssociationManager| association functions are async. The results of | 25 // |ModelAssociationManager| association functions are async. The results of |
| 25 // those operations are passed back via this interface. | 26 // those operations are passed back via this interface. |
| 26 class ModelAssociationResultProcessor { | 27 class ModelAssociationResultProcessor { |
| 27 public: | 28 public: |
| 28 virtual void OnModelAssociationDone( | 29 virtual void OnModelAssociationDone( |
| 29 const DataTypeManager::ConfigureResult& result) = 0; | 30 const DataTypeManager::ConfigureResult& result) = 0; |
| 30 virtual ~ModelAssociationResultProcessor() {} | 31 virtual ~ModelAssociationResultProcessor() {} |
| 32 | |
| 33 // when types (that did not complete loading, during the previous | |
|
tim (not reviewing)
2012/05/22 16:50:05
nit - Comments start with capital letters.
Seeing
lipalani1
2012/05/22 20:20:46
Done.
| |
| 34 // run of the configure) get loaded this callback is called to let the | |
| 35 // DataTypeManager know and request a reconfigure. | |
| 36 virtual void OnTypesLoaded() = 0; | |
| 31 }; | 37 }; |
| 32 | 38 |
| 33 // The class that is responsible for model association. | 39 // The class that is responsible for model association. |
| 34 class ModelAssociationManager { | 40 class ModelAssociationManager { |
| 35 public: | 41 public: |
| 36 ModelAssociationManager(const DataTypeController::TypeMap* controllers, | 42 ModelAssociationManager(const DataTypeController::TypeMap* controllers, |
| 37 ModelAssociationResultProcessor* processor); | 43 ModelAssociationResultProcessor* processor); |
| 38 virtual ~ModelAssociationManager(); | 44 virtual ~ModelAssociationManager(); |
| 39 | 45 |
| 40 // Initializes the state to do the model association in future. This | 46 // Initializes the state to do the model association in future. This |
| 41 // should be called before communicating with sync server. A subsequent call | 47 // should be called before communicating with sync server. A subsequent call |
| 42 // of Initialize is only allowed if the current configure cycle is completed, | 48 // of Initialize is only allowed if the ModelAssociationManager has invoked |
| 43 // aborted or stopped. | 49 // |OnModelAssociationDone| on the |ModelAssociationResultProcessor|. |
| 44 void Initialize(syncable::ModelTypeSet desired_types); | 50 void Initialize(syncable::ModelTypeSet desired_types); |
| 45 | 51 |
| 46 // Can be called at any time. Synchronously stops all datatypes. | 52 // Can be called at any time. Synchronously stops all datatypes. |
| 47 void Stop(); | 53 void Stop(); |
| 48 | 54 |
| 49 // Should only be called after Initialize. | 55 // Should only be called after Initialize. |
| 50 // Starts the actual association. When this is completed | 56 // Starts the actual association. When this is completed |
| 51 // |OnModelAssociationDone| would be called invoked. | 57 // |OnModelAssociationDone| would be called invoked. |
| 52 void StartAssociationAsync(); | 58 void StartAssociationAsync(); |
| 53 | 59 |
| 54 // It is valid to call this only when we are initialized to configure | 60 // It is valid to call this only when we are initialized to configure |
| 55 // but we have not started the configuration.(i.e., |Initialize| has | 61 // but we have not started the configuration.(i.e., |Initialize| has |
| 56 // been called but |StartAssociationAsync| has not yet been called.) | 62 // been called but |StartAssociationAsync| has not yet been called.) |
| 57 // If we have started configuration then the DTM will wait until | 63 // If we have started configuration then the DataTypeManager will wait until |
| 58 // the current configuration is done before processing the reconfigure | 64 // the current configuration is done before processing the reconfigure |
| 59 // request. We goto IDLE state and clear all our internal state. It is | 65 // request. We goto IDLE state and clear all our internal state. It is |
| 60 // safe to do this as we have not started association on any DTCs. | 66 // safe to do this as we have not started association on any DTCs. |
| 61 void ResetForReconfiguration(); | 67 void ResetForReconfiguration(); |
| 62 | 68 |
| 63 // Should only be called after Initialize. | 69 // Should only be called after Initialize. |
| 64 // Stops any disabled types. | 70 // Stops any disabled types. |
| 65 void StopDisabledTypes(); | 71 void StopDisabledTypes(); |
| 66 | 72 |
| 73 // This is used for TESTING PURPOSE ONLY. The test case can inspect | |
| 74 // and modify the timer. | |
| 75 base::OneShotTimer<ModelAssociationManager>* GetTimerForTesting(); | |
| 76 | |
| 67 private: | 77 private: |
| 68 enum State { | 78 enum State { |
| 69 // This is the state after |Initialize| is called. | 79 // This is the state after |Initialize| is called. |
| 70 INITIAILIZED_TO_CONFIGURE, | 80 INITIAILIZED_TO_CONFIGURE, |
| 71 // Starting a new configuration. | 81 // Starting a new configuration. |
| 72 CONFIGURING, | 82 CONFIGURING, |
| 73 // A stop command was issued. | 83 // A stop command was issued. |
| 74 ABORTED, | 84 ABORTED, |
| 75 // No configuration is in progress. | 85 // No configuration is in progress. |
| 76 IDLE | 86 IDLE |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 90 // will be passed to |LoadModels| function. | 100 // will be passed to |LoadModels| function. |
| 91 void ModelLoadCallback(syncable::ModelType type, SyncError error); | 101 void ModelLoadCallback(syncable::ModelType type, SyncError error); |
| 92 | 102 |
| 93 // Calls the |LoadModels| method on the next controller waiting to start. | 103 // Calls the |LoadModels| method on the next controller waiting to start. |
| 94 void LoadModelForNextType(); | 104 void LoadModelForNextType(); |
| 95 | 105 |
| 96 // Calls |StartAssociating| on the next available controller whose models are | 106 // Calls |StartAssociating| on the next available controller whose models are |
| 97 // loaded. | 107 // loaded. |
| 98 void StartAssociatingNextType(); | 108 void StartAssociatingNextType(); |
| 99 | 109 |
| 110 // We have waited long enough and the model has not loaded yet. | |
| 111 void ModelLoadTimedOut(); | |
| 112 | |
| 113 void HandleFailedTypes(DataTypeController::StartResult result, | |
|
tim (not reviewing)
2012/05/22 16:50:05
Comment.
lipalani1
2012/05/22 20:20:46
Done.
| |
| 114 const SyncError& error); | |
| 115 | |
| 116 syncable::ModelTypeSet GetTypesWaitingToLoad(); | |
| 117 | |
| 118 | |
| 100 State state_; | 119 State state_; |
| 101 syncable::ModelTypeSet desired_types_; | 120 syncable::ModelTypeSet desired_types_; |
| 102 std::list<SyncError> failed_datatypes_info_; | 121 std::list<SyncError> failed_datatypes_info_; |
| 103 std::map<syncable::ModelType, int> start_order_; | 122 std::map<syncable::ModelType, int> start_order_; |
| 104 | 123 |
| 105 // This illustration explains the movement of one DTC through various lists. | 124 // This illustration explains the movement of one DTC through various lists. |
| 106 // Consider a dataype, say, BOOKMARKS which is NOT_RUNNING and will be | 125 // Consider a dataype, say, BOOKMARKS which is NOT_RUNNING and will be |
| 107 // configured now. | 126 // configured now. |
| 108 // Initially all lists are empty. BOOKMARKS is in the |controllers_| | 127 // Initially all lists are empty. BOOKMARKS is in the |controllers_| |
| 109 // map. Here is how the controller moves to various list | 128 // map. Here is how the controller moves to various list |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 133 // list to this list as they finish loading their model. | 152 // list to this list as they finish loading their model. |
| 134 std::vector<DataTypeController*> waiting_to_associate_; | 153 std::vector<DataTypeController*> waiting_to_associate_; |
| 135 | 154 |
| 136 // Controller currently doing model association. | 155 // Controller currently doing model association. |
| 137 DataTypeController* currently_associating_; | 156 DataTypeController* currently_associating_; |
| 138 | 157 |
| 139 // Set of all registered controllers. | 158 // Set of all registered controllers. |
| 140 const DataTypeController::TypeMap* controllers_; | 159 const DataTypeController::TypeMap* controllers_; |
| 141 ModelAssociationResultProcessor* result_processor_; | 160 ModelAssociationResultProcessor* result_processor_; |
| 142 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; | 161 base::WeakPtrFactory<ModelAssociationManager> weak_ptr_factory_; |
| 162 base::OneShotTimer<ModelAssociationManager> timer_; | |
| 143 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); | 163 DISALLOW_COPY_AND_ASSIGN(ModelAssociationManager); |
| 144 }; | 164 }; |
| 145 } // namespace browser_sync | 165 } // namespace browser_sync |
| 146 #endif // CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__ | 166 #endif // CHROME_BROWSER_SYNC_GLUE_MODEL_ASSOCIATION_MANAGER_H__ |
| OLD | NEW |