sync_api_component_factory_impl.h 5.2 KB

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