Home | History | Annotate | Download | only in sync_driver
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_
      6 #define COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_
      7 
      8 #include <map>
      9 
     10 #include "base/memory/ref_counted.h"
     11 #include "base/memory/scoped_ptr.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "base/stl_util.h"
     14 #include "sync/internal_api/public/base/model_type.h"
     15 
     16 namespace base {
     17 class SequencedTaskRunner;
     18 }  // namespace base
     19 
     20 namespace syncer {
     21 class ModelTypeSyncProxyImpl;
     22 class SyncContextProxy;
     23 }  //namespace syncer
     24 
     25 namespace sync_driver {
     26 
     27 class NonBlockingDataTypeController;
     28 
     29 // Manages a set of NonBlockingDataTypeControllers.
     30 //
     31 // Each NonBlockingDataTypeController instance handles the logic around
     32 // enabling and disabling sync for a particular non-blocking type.  This class
     33 // manages all the controllers.
     34 class NonBlockingDataTypeManager {
     35  public:
     36   NonBlockingDataTypeManager();
     37   ~NonBlockingDataTypeManager();
     38 
     39   // Declares |type| as a non-blocking type.  Should be done early
     40   // on during sync initialization.
     41   //
     42   // The |preferred| flag indicates whether or not this type should be synced.
     43   void RegisterType(syncer::ModelType type, bool preferred);
     44 
     45   // Connects the ModelTypeSyncProxyImpl and associated model type
     46   // thread to its NonBlockingDataTypeController on the UI thread.
     47   void InitializeType(
     48       syncer::ModelType type,
     49       const scoped_refptr<base::SequencedTaskRunner>& task_runner,
     50       const base::WeakPtr<syncer::ModelTypeSyncProxyImpl>& type_sync_proxy);
     51 
     52   // Connects the sync backend, as represented by a SyncContextProxy, to the
     53   // NonBlockingDataTypeController on the UI thread.
     54   void ConnectSyncBackend(scoped_ptr<syncer::SyncContextProxy> proxy);
     55 
     56   // Disconnects the sync backend from the UI thread.  Should be called
     57   // early on during shutdown, but the whole procedure is asynchronous so
     58   // there's not much downside to calling it later.
     59   void DisconnectSyncBackend();
     60 
     61   // Updates the set of types the user wants to have synced.
     62   void SetPreferredTypes(syncer::ModelTypeSet types);
     63 
     64   // Returns the list of all known non-blocking sync types that registered with
     65   // RegisterType.
     66   syncer::ModelTypeSet GetRegisteredTypes() const;
     67 
     68  private:
     69   typedef
     70       std::map<syncer::ModelType, NonBlockingDataTypeController*>
     71       NonBlockingDataTypeControllerMap;
     72 
     73   // List of data type controllers for non-blocking types.
     74   NonBlockingDataTypeControllerMap non_blocking_data_type_controllers_;
     75 
     76   // Deleter for elements of the non-blocking data types controller map.
     77   STLValueDeleter<NonBlockingDataTypeControllerMap>
     78       non_blocking_data_type_controllers_deleter_;
     79 };
     80 
     81 }  // namespace sync_driver
     82 
     83 #endif  // COMPONENTS_SYNC_DRIVER_NON_BLOCKING_DATA_TYPE_MANAGER_H_
     84