1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_IMPL_H__ 6 #define CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_IMPL_H__ 7 #pragma once 8 9 #include "chrome/browser/sync/glue/data_type_manager.h" 10 11 #include <map> 12 #include <vector> 13 14 #include "base/basictypes.h" 15 #include "base/task.h" 16 17 namespace browser_sync { 18 19 class DataTypeController; 20 class SyncBackendHost; 21 22 class DataTypeManagerImpl : public DataTypeManager { 23 public: 24 DataTypeManagerImpl(SyncBackendHost* backend, 25 const DataTypeController::TypeMap& controllers); 26 virtual ~DataTypeManagerImpl(); 27 28 // DataTypeManager interface. 29 virtual void Configure(const TypeSet& desired_types); 30 virtual void Stop(); 31 virtual const DataTypeController::TypeMap& controllers(); 32 virtual State state(); 33 34 private: 35 // Starts the next data type in the kStartOrder list, indicated by 36 // the current_type_ member. If there are no more data types to 37 // start, the stashed start_callback_ is invoked. 38 void StartNextType(); 39 40 // Callback passed to each data type controller on startup. 41 void TypeStartCallback(DataTypeController::StartResult result, 42 const tracked_objects::Location& from_here); 43 44 // Stops all data types. 45 void FinishStop(); 46 void FinishStopAndNotify(ConfigureResult result, 47 const tracked_objects::Location& location); 48 49 // Returns true if any last_requested_types_ currently needs to start model 50 // association. If non-null, fills |needs_start| with all such controllers. 51 bool GetControllersNeedingStart( 52 std::vector<DataTypeController*>* needs_start); 53 54 void Restart(); 55 void DownloadReady(); 56 void NotifyStart(); 57 void NotifyDone(ConfigureResult result, 58 const tracked_objects::Location& location); 59 void SetBlockedAndNotify(); 60 61 SyncBackendHost* backend_; 62 // Map of all data type controllers that are available for sync. 63 // This list is determined at startup by various command line flags. 64 const DataTypeController::TypeMap controllers_; 65 State state_; 66 std::map<syncable::ModelType, int> start_order_; 67 TypeSet last_requested_types_; 68 std::vector<DataTypeController*> needs_start_; 69 std::vector<DataTypeController*> needs_stop_; 70 71 // Whether an attempt to reconfigure was made while we were busy configuring. 72 // The |last_requested_types_| will reflect the newest set of requested types. 73 bool needs_reconfigure_; 74 75 ScopedRunnableMethodFactory<DataTypeManagerImpl> method_factory_; 76 77 DISALLOW_COPY_AND_ASSIGN(DataTypeManagerImpl); 78 }; 79 80 } // namespace browser_sync 81 82 #endif // CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_IMPL_H__ 83