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 COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ 6 #define COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ 7 8 #include <memory> 9 #include <string> 10 11 #include "base/compiler_specific.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/sequenced_task_runner.h" 14 #include "components/sync/base/model_type.h" 15 #include "components/sync/driver/sync_api_component_factory.h" 16 #include "components/version_info/version_info.h" 17 18 namespace syncer { 19 class ModelTypeController; 20 class ModelTypeControllerDelegate; 21 class SyncInvalidationsService; 22 class SyncService; 23 } 24 25 namespace autofill { 26 class AutofillWebDataService; 27 } 28 29 namespace password_manager { 30 class PasswordStore; 31 } 32 33 namespace sync_bookmarks { 34 class BookmarkSyncService; 35 } 36 37 namespace browser_sync { 38 39 class BrowserSyncClient; 40 41 class ProfileSyncComponentsFactoryImpl 42 : public syncer::SyncApiComponentFactory { 43 public: 44 ProfileSyncComponentsFactoryImpl( 45 BrowserSyncClient* sync_client, 46 version_info::Channel channel, 47 const char* history_disabled_pref, 48 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, 49 const scoped_refptr<base::SequencedTaskRunner>& db_thread, 50 const scoped_refptr<autofill::AutofillWebDataService>& 51 web_data_service_on_disk, 52 const scoped_refptr<autofill::AutofillWebDataService>& 53 web_data_service_in_memory, 54 const scoped_refptr<password_manager::PasswordStore>& 55 profile_password_store, 56 const scoped_refptr<password_manager::PasswordStore>& 57 account_password_store, 58 sync_bookmarks::BookmarkSyncService* bookmark_sync_service); 59 ProfileSyncComponentsFactoryImpl(const ProfileSyncComponentsFactoryImpl&) = 60 delete; 61 ProfileSyncComponentsFactoryImpl& operator=( 62 const ProfileSyncComponentsFactoryImpl&) = delete; 63 ~ProfileSyncComponentsFactoryImpl() override; 64 65 // Creates and returns enabled datatypes and their controllers. 66 // |disabled_types| allows callers to prevent certain types from being 67 // created (e.g. to honor command-line flags). 68 syncer::DataTypeController::TypeVector CreateCommonDataTypeControllers( 69 syncer::ModelTypeSet disabled_types, 70 syncer::SyncService* sync_service); 71 72 // SyncApiComponentFactory implementation: 73 std::unique_ptr<syncer::DataTypeManager> CreateDataTypeManager( 74 syncer::ModelTypeSet initial_types, 75 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 76 debug_info_listener, 77 const syncer::DataTypeController::TypeMap* controllers, 78 const syncer::DataTypeEncryptionHandler* encryption_handler, 79 syncer::ModelTypeConfigurer* configurer, 80 syncer::DataTypeManagerObserver* observer) override; 81 std::unique_ptr<syncer::SyncEngine> CreateSyncEngine( 82 const std::string& name, 83 invalidation::InvalidationService* invalidator, 84 syncer::SyncInvalidationsService* sync_invalidation_service, 85 const base::WeakPtr<syncer::SyncPrefs>& sync_prefs) override; 86 void DeleteLegacyDirectoryFilesAndNigoriStorage() override; 87 88 private: 89 // Factory function for ModelTypeController instances for models living on 90 // |ui_thread_|. 91 std::unique_ptr<syncer::ModelTypeController> 92 CreateModelTypeControllerForModelRunningOnUIThread(syncer::ModelType type); 93 94 // Factory function for ModelTypeControllerDelegate instances for models 95 // living in |ui_thread_| that have their delegate accessible via SyncClient. 96 std::unique_ptr<syncer::ModelTypeControllerDelegate> 97 CreateForwardingControllerDelegate(syncer::ModelType type); 98 99 // Factory function for ModelTypeController instances for wallet-related 100 // datatypes, which live in |db_thread_| and have a delegate accessible via 101 // AutofillWebDataService. 102 std::unique_ptr<syncer::ModelTypeController> CreateWalletModelTypeController( 103 syncer::ModelType type, 104 const base::RepeatingCallback< 105 base::WeakPtr<syncer::ModelTypeControllerDelegate>( 106 autofill::AutofillWebDataService*)>& delegate_from_web_data, 107 syncer::SyncService* sync_service); 108 // Same as above, but supporting STORAGE_IN_MEMORY implemented as an 109 // independent AutofillWebDataService, namely |web_data_service_in_memory_|. 110 std::unique_ptr<syncer::ModelTypeController> 111 CreateWalletModelTypeControllerWithInMemorySupport( 112 syncer::ModelType type, 113 const base::RepeatingCallback< 114 base::WeakPtr<syncer::ModelTypeControllerDelegate>( 115 autofill::AutofillWebDataService*)>& delegate_from_web_data, 116 syncer::SyncService* sync_service); 117 118 // Client/platform specific members. 119 BrowserSyncClient* const sync_client_; 120 const version_info::Channel channel_; 121 const char* history_disabled_pref_; 122 const scoped_refptr<base::SequencedTaskRunner> ui_thread_; 123 const scoped_refptr<base::SequencedTaskRunner> db_thread_; 124 const scoped_refptr<base::SequencedTaskRunner> 125 engines_and_directory_deletion_thread_; 126 const scoped_refptr<autofill::AutofillWebDataService> 127 web_data_service_on_disk_; 128 const scoped_refptr<autofill::AutofillWebDataService> 129 web_data_service_in_memory_; 130 const scoped_refptr<password_manager::PasswordStore> profile_password_store_; 131 const scoped_refptr<password_manager::PasswordStore> account_password_store_; 132 sync_bookmarks::BookmarkSyncService* const bookmark_sync_service_; 133 }; 134 135 } // namespace browser_sync 136 137 #endif // COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ 138