Home | History | Annotate | Download | only in sync
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_H__
      6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_H__
      7 
      8 #include <string>
      9 
     10 #include "base/memory/weak_ptr.h"
     11 #include "chrome/browser/sync/glue/data_type_controller.h"
     12 #include "chrome/browser/sync/glue/data_type_error_handler.h"
     13 #include "sync/api/sync_merge_result.h"
     14 #include "sync/internal_api/public/util/unrecoverable_error_handler.h"
     15 #include "sync/internal_api/public/util/weak_handle.h"
     16 
     17 class PasswordStore;
     18 class ProfileSyncService;
     19 class WebDataService;
     20 
     21 namespace browser_sync {
     22 class AssociatorInterface;
     23 class ChangeProcessor;
     24 class DataTypeEncryptionHandler;
     25 class DataTypeManager;
     26 class DataTypeManagerObserver;
     27 class FailedDataTypesHandler;
     28 class GenericChangeProcessor;
     29 class SharedChangeProcessor;
     30 class SyncBackendHost;
     31 class DataTypeErrorHandler;
     32 }
     33 
     34 namespace syncer {
     35 class DataTypeDebugInfoListener;
     36 class SyncableService;
     37 }
     38 
     39 namespace history {
     40 class HistoryBackend;
     41 }
     42 
     43 // Factory class for all profile sync related classes.
     44 class ProfileSyncComponentsFactory {
     45  public:
     46   // The various factory methods for the data type model associators
     47   // and change processors all return this struct.  This is needed
     48   // because the change processors typically require a type-specific
     49   // model associator at construction time.
     50   //
     51   // Note: This interface is deprecated in favor of the SyncableService API.
     52   // New datatypes that do not live on the UI thread should directly return a
     53   // weak pointer to a syncer::SyncableService. All others continue to return
     54   // SyncComponents. It is safe to assume that the factory methods below are
     55   // called on the same thread in which the datatype resides.
     56   //
     57   // TODO(zea): Have all datatypes using the new API switch to returning
     58   // SyncableService weak pointers instead of SyncComponents (crbug.com/100114).
     59   struct SyncComponents {
     60     browser_sync::AssociatorInterface* model_associator;
     61     browser_sync::ChangeProcessor* change_processor;
     62     SyncComponents(browser_sync::AssociatorInterface* ma,
     63                    browser_sync::ChangeProcessor* cp)
     64         : model_associator(ma), change_processor(cp) {}
     65   };
     66 
     67   virtual ~ProfileSyncComponentsFactory() {}
     68 
     69   // Creates and registers enabled datatypes with the provided
     70   // ProfileSyncService.
     71   virtual void RegisterDataTypes(ProfileSyncService* pss) = 0;
     72 
     73   // Instantiates a new DataTypeManager with a SyncBackendHost, a list of data
     74   // type controllers and a DataTypeManagerObserver.  The return pointer is
     75   // owned by the caller.
     76   virtual browser_sync::DataTypeManager* CreateDataTypeManager(
     77       const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
     78           debug_info_listener,
     79       const browser_sync::DataTypeController::TypeMap* controllers,
     80       const browser_sync::DataTypeEncryptionHandler* encryption_handler,
     81       browser_sync::SyncBackendHost* backend,
     82       browser_sync::DataTypeManagerObserver* observer,
     83       browser_sync::FailedDataTypesHandler* failed_data_types_handler) = 0;
     84 
     85   // Creating this in the factory helps us mock it out in testing.
     86   virtual browser_sync::GenericChangeProcessor* CreateGenericChangeProcessor(
     87       ProfileSyncService* profile_sync_service,
     88       browser_sync::DataTypeErrorHandler* error_handler,
     89       const base::WeakPtr<syncer::SyncableService>& local_service,
     90       const base::WeakPtr<syncer::SyncMergeResult>& merge_result) = 0;
     91 
     92   virtual browser_sync::SharedChangeProcessor*
     93       CreateSharedChangeProcessor() = 0;
     94 
     95   // Returns a weak pointer to the syncable service specified by |type|.
     96   // Weak pointer may be unset if service is already destroyed.
     97   // Note: Should only be called on the same thread on which a datatype resides.
     98   virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType(
     99       syncer::ModelType type) = 0;
    100 
    101   // Legacy datatypes that need to be converted to the SyncableService API.
    102   virtual SyncComponents CreateBookmarkSyncComponents(
    103       ProfileSyncService* profile_sync_service,
    104       browser_sync::DataTypeErrorHandler* error_handler) = 0;
    105   virtual SyncComponents CreatePasswordSyncComponents(
    106       ProfileSyncService* profile_sync_service,
    107       PasswordStore* password_store,
    108       browser_sync::DataTypeErrorHandler* error_handler) = 0;
    109   virtual SyncComponents CreateTypedUrlSyncComponents(
    110       ProfileSyncService* profile_sync_service,
    111       history::HistoryBackend* history_backend,
    112       browser_sync::DataTypeErrorHandler* error_handler) = 0;
    113   virtual SyncComponents CreateSessionSyncComponents(
    114       ProfileSyncService* profile_sync_service,
    115       browser_sync::DataTypeErrorHandler* error_handler) = 0;
    116 };
    117 
    118 #endif  // CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_H__
    119