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