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/macros.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/sequenced_task_runner.h"
15 #include "components/sync/base/model_type.h"
16 #include "components/sync/driver/sync_api_component_factory.h"
17 #include "components/version_info/version_info.h"
18 
19 namespace syncer {
20 class ModelTypeController;
21 class ModelTypeControllerDelegate;
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() override;
60 
61   // Creates and returns enabled datatypes and their controllers.
62   // |disabled_types| allows callers to prevent certain types from being
63   // created (e.g. to honor command-line flags).
64   syncer::DataTypeController::TypeVector CreateCommonDataTypeControllers(
65       syncer::ModelTypeSet disabled_types,
66       syncer::SyncService* sync_service);
67 
68   // SyncApiComponentFactory implementation:
69   std::unique_ptr<syncer::DataTypeManager> CreateDataTypeManager(
70       syncer::ModelTypeSet initial_types,
71       const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
72           debug_info_listener,
73       const syncer::DataTypeController::TypeMap* controllers,
74       const syncer::DataTypeEncryptionHandler* encryption_handler,
75       syncer::ModelTypeConfigurer* configurer,
76       syncer::DataTypeManagerObserver* observer) override;
77   std::unique_ptr<syncer::SyncEngine> CreateSyncEngine(
78       const std::string& name,
79       invalidation::InvalidationService* invalidator,
80       const base::WeakPtr<syncer::SyncPrefs>& sync_prefs) override;
81 
82  private:
83   // Factory function for ModelTypeController instances for models living on
84   // |ui_thread_|.
85   std::unique_ptr<syncer::ModelTypeController>
86   CreateModelTypeControllerForModelRunningOnUIThread(syncer::ModelType type);
87 
88   // Factory function for ModelTypeControllerDelegate instances for models
89   // living in |ui_thread_| that have their delegate accessible via SyncClient.
90   std::unique_ptr<syncer::ModelTypeControllerDelegate>
91   CreateForwardingControllerDelegate(syncer::ModelType type);
92 
93   // Factory function for ModelTypeController instances for wallet-related
94   // datatypes, which live in |db_thread_| and have a delegate accessible via
95   // AutofillWebDataService.
96   std::unique_ptr<syncer::ModelTypeController> CreateWalletModelTypeController(
97       syncer::ModelType type,
98       const base::RepeatingCallback<
99           base::WeakPtr<syncer::ModelTypeControllerDelegate>(
100               autofill::AutofillWebDataService*)>& delegate_from_web_data,
101       syncer::SyncService* sync_service);
102   // Same as above, but supporting STORAGE_IN_MEMORY implemented as an
103   // independent AutofillWebDataService, namely |web_data_service_in_memory_|.
104   std::unique_ptr<syncer::ModelTypeController>
105   CreateWalletModelTypeControllerWithInMemorySupport(
106       syncer::ModelType type,
107       const base::RepeatingCallback<
108           base::WeakPtr<syncer::ModelTypeControllerDelegate>(
109               autofill::AutofillWebDataService*)>& delegate_from_web_data,
110       syncer::SyncService* sync_service);
111 
112   // Client/platform specific members.
113   BrowserSyncClient* const sync_client_;
114   const version_info::Channel channel_;
115   const char* history_disabled_pref_;
116   const scoped_refptr<base::SequencedTaskRunner> ui_thread_;
117   const scoped_refptr<base::SequencedTaskRunner> db_thread_;
118   const scoped_refptr<autofill::AutofillWebDataService>
119       web_data_service_on_disk_;
120   const scoped_refptr<autofill::AutofillWebDataService>
121       web_data_service_in_memory_;
122   const scoped_refptr<password_manager::PasswordStore> profile_password_store_;
123   const scoped_refptr<password_manager::PasswordStore> account_password_store_;
124   sync_bookmarks::BookmarkSyncService* const bookmark_sync_service_;
125 
126   DISALLOW_COPY_AND_ASSIGN(ProfileSyncComponentsFactoryImpl);
127 };
128 
129 }  // namespace browser_sync
130 
131 #endif  // COMPONENTS_BROWSER_SYNC_PROFILE_SYNC_COMPONENTS_FACTORY_IMPL_H__
132