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_IMPL_H__ 6 #define CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "base/memory/weak_ptr.h" 13 #include "chrome/browser/sync/profile_sync_components_factory.h" 14 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 15 #include "google_apis/gaia/oauth2_token_service.h" 16 17 class Profile; 18 19 namespace base { 20 class CommandLine; 21 } 22 23 namespace extensions { 24 class ExtensionSystem; 25 } 26 27 class ProfileSyncComponentsFactoryImpl : public ProfileSyncComponentsFactory { 28 public: 29 // Constructs a ProfileSyncComponentsFactoryImpl. 30 // 31 // |sync_service_url| is the base URL of the sync server. 32 // 33 // |account_id| is the sync user's account id. 34 // 35 // |scope_set| is the set of scopes to use for sync. 36 // 37 // |token_service| must outlive the ProfileSyncComponentsFactoryImpl. 38 // 39 // |url_request_context_getter| must outlive the 40 // ProfileSyncComponentsFactoryImpl. 41 ProfileSyncComponentsFactoryImpl( 42 Profile* profile, 43 base::CommandLine* command_line, 44 const GURL& sync_service_url, 45 const std::string& account_id, 46 const OAuth2TokenService::ScopeSet& scope_set, 47 OAuth2TokenService* token_service, 48 net::URLRequestContextGetter* url_request_context_getter); 49 virtual ~ProfileSyncComponentsFactoryImpl(); 50 51 virtual void RegisterDataTypes(ProfileSyncService* pss) OVERRIDE; 52 53 virtual browser_sync::DataTypeManager* CreateDataTypeManager( 54 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 55 debug_info_listener, 56 const browser_sync::DataTypeController::TypeMap* controllers, 57 const browser_sync::DataTypeEncryptionHandler* encryption_handler, 58 browser_sync::SyncBackendHost* backend, 59 browser_sync::DataTypeManagerObserver* observer, 60 browser_sync::FailedDataTypesHandler* failed_data_types_handler) 61 OVERRIDE; 62 63 virtual browser_sync::SyncBackendHost* CreateSyncBackendHost( 64 const std::string& name, 65 Profile* profile, 66 invalidation::InvalidationService* invalidator, 67 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, 68 const base::FilePath& sync_folder) OVERRIDE; 69 70 virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( 71 syncer::ModelType type) OVERRIDE; 72 virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService( 73 syncer::AttachmentService::Delegate* delegate) OVERRIDE; 74 75 // Legacy datatypes that need to be converted to the SyncableService API. 76 virtual SyncComponents CreateBookmarkSyncComponents( 77 ProfileSyncService* profile_sync_service, 78 browser_sync::DataTypeErrorHandler* error_handler) OVERRIDE; 79 virtual SyncComponents CreateTypedUrlSyncComponents( 80 ProfileSyncService* profile_sync_service, 81 history::HistoryBackend* history_backend, 82 browser_sync::DataTypeErrorHandler* error_handler) OVERRIDE; 83 84 private: 85 // Register data types which are enabled on desktop platforms only. 86 // |disabled_types| and |enabled_types| correspond only to those types 87 // being explicitly enabled/disabled by the command line. 88 void RegisterDesktopDataTypes(syncer::ModelTypeSet disabled_types, 89 syncer::ModelTypeSet enabled_types, 90 ProfileSyncService* pss); 91 // Register data types which are enabled on both desktop and mobile. 92 // |disabled_types| and |enabled_types| correspond only to those types 93 // being explicitly enabled/disabled by the command line. 94 void RegisterCommonDataTypes(syncer::ModelTypeSet disabled_types, 95 syncer::ModelTypeSet enabled_types, 96 ProfileSyncService* pss); 97 // Used to bind a callback to give to DataTypeControllers to disable 98 // data types. 99 browser_sync::DataTypeController::DisableTypeCallback 100 MakeDisableCallbackFor(syncer::ModelType type); 101 void DisableBrokenType(syncer::ModelType type, 102 const tracked_objects::Location& from_here, 103 const std::string& message); 104 105 Profile* profile_; 106 base::CommandLine* command_line_; 107 // Set on the UI thread (since extensions::ExtensionSystemFactory is 108 // non-threadsafe); accessed on both the UI and FILE threads in 109 // GetSyncableServiceForType. 110 extensions::ExtensionSystem* extension_system_; 111 scoped_refptr<autofill::AutofillWebDataService> web_data_service_; 112 113 const GURL sync_service_url_; 114 const std::string account_id_; 115 const OAuth2TokenService::ScopeSet scope_set_; 116 OAuth2TokenService* const token_service_; 117 net::URLRequestContextGetter* const url_request_context_getter_; 118 119 base::WeakPtrFactory<ProfileSyncComponentsFactoryImpl> weak_factory_; 120 121 DISALLOW_COPY_AND_ASSIGN(ProfileSyncComponentsFactoryImpl); 122 }; 123 124 #endif // CHROME_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__ 125