OLD | NEW |
| (Empty) |
1 // Copyright 2014 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_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ | |
6 #define COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ | |
7 | |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "components/sync/api/syncable_service.h" | |
13 #include "components/sync/base/model_type.h" | |
14 #include "components/sync/core/attachments/attachment_service.h" | |
15 #include "components/sync_driver/data_type_controller.h" | |
16 | |
17 namespace base { | |
18 class FilePath; | |
19 } // namespace base | |
20 | |
21 namespace browser_sync { | |
22 class SyncBackendHost; | |
23 } // namespace browser_sync | |
24 | |
25 namespace history { | |
26 class HistoryBackend; | |
27 } | |
28 | |
29 namespace invalidation { | |
30 class InvalidationService; | |
31 } // namespace invalidation | |
32 | |
33 namespace syncer { | |
34 class DataTypeDebugInfoListener; | |
35 class DataTypeErrorHandler; | |
36 class SyncableService; | |
37 | |
38 struct UserShare; | |
39 } // namespace syncer | |
40 | |
41 namespace sync_driver { | |
42 | |
43 class AssociatorInterface; | |
44 class ChangeProcessor; | |
45 class DataTypeEncryptionHandler; | |
46 class DataTypeManager; | |
47 class DataTypeManagerObserver; | |
48 class DataTypeStatusTable; | |
49 class GenericChangeProcessor; | |
50 class LocalDeviceInfoProvider; | |
51 class SyncPrefs; | |
52 class SyncClient; | |
53 class SyncService; | |
54 | |
55 // This factory provides sync driver code with the model type specific sync/api | |
56 // service (like SyncableService) implementations. | |
57 class SyncApiComponentFactory { | |
58 public: | |
59 virtual ~SyncApiComponentFactory() {} | |
60 // Callback to allow platform-specific datatypes to register themselves as | |
61 // data type controllers. | |
62 // |disabled_types| and |enabled_types| control the disable/enable state of | |
63 // types that are on or off by default (respectively). | |
64 typedef base::Callback<void(sync_driver::SyncService* sync_service, | |
65 syncer::ModelTypeSet disabled_types, | |
66 syncer::ModelTypeSet enabled_types)> | |
67 RegisterDataTypesMethod; | |
68 | |
69 // The various factory methods for the data type model associators | |
70 // and change processors all return this struct. This is needed | |
71 // because the change processors typically require a type-specific | |
72 // model associator at construction time. | |
73 // | |
74 // Note: This interface is deprecated in favor of the SyncableService API. | |
75 // New datatypes that do not live on the UI thread should directly return a | |
76 // weak pointer to a syncer::SyncableService. All others continue to return | |
77 // SyncComponents. It is safe to assume that the factory methods below are | |
78 // called on the same thread in which the datatype resides. | |
79 // | |
80 // TODO(zea): Have all datatypes using the new API switch to returning | |
81 // SyncableService weak pointers instead of SyncComponents (crbug.com/100114). | |
82 struct SyncComponents { | |
83 sync_driver::AssociatorInterface* model_associator; | |
84 sync_driver::ChangeProcessor* change_processor; | |
85 SyncComponents(sync_driver::AssociatorInterface* ma, | |
86 sync_driver::ChangeProcessor* cp) | |
87 : model_associator(ma), change_processor(cp) {} | |
88 }; | |
89 | |
90 // Creates and registers enabled datatypes with the provided SyncClient. | |
91 virtual void RegisterDataTypes( | |
92 sync_driver::SyncService* sync_service, | |
93 const RegisterDataTypesMethod& register_platform_types_method) = 0; | |
94 | |
95 // Instantiates a new DataTypeManager with a SyncBackendHost, a list of data | |
96 // type controllers and a DataTypeManagerObserver. The return pointer is | |
97 // owned by the caller. | |
98 virtual sync_driver::DataTypeManager* CreateDataTypeManager( | |
99 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& | |
100 debug_info_listener, | |
101 const sync_driver::DataTypeController::TypeMap* controllers, | |
102 const sync_driver::DataTypeEncryptionHandler* encryption_handler, | |
103 browser_sync::SyncBackendHost* backend, | |
104 sync_driver::DataTypeManagerObserver* observer) = 0; | |
105 | |
106 // Creating this in the factory helps us mock it out in testing. | |
107 virtual browser_sync::SyncBackendHost* CreateSyncBackendHost( | |
108 const std::string& name, | |
109 invalidation::InvalidationService* invalidator, | |
110 const base::WeakPtr<sync_driver::SyncPrefs>& sync_prefs, | |
111 const base::FilePath& sync_folder) = 0; | |
112 | |
113 // Creating this in the factory helps us mock it out in testing. | |
114 virtual std::unique_ptr<sync_driver::LocalDeviceInfoProvider> | |
115 CreateLocalDeviceInfoProvider() = 0; | |
116 | |
117 // Legacy datatypes that need to be converted to the SyncableService API. | |
118 virtual SyncComponents CreateBookmarkSyncComponents( | |
119 sync_driver::SyncService* sync_service, | |
120 syncer::DataTypeErrorHandler* error_handler) = 0; | |
121 | |
122 // Creates attachment service. | |
123 // Note: Should only be called from the model type thread. | |
124 // | |
125 // |store_birthday| is the store birthday. Must not be empty. | |
126 // | |
127 // |model_type| is the model type this AttachmentService will be used with. | |
128 // | |
129 // |delegate| is optional delegate for AttachmentService to notify about | |
130 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not | |
131 // provided. AttachmentService doesn't take ownership of delegate, the pointer | |
132 // must be valid throughout AttachmentService lifetime. | |
133 virtual std::unique_ptr<syncer::AttachmentService> CreateAttachmentService( | |
134 std::unique_ptr<syncer::AttachmentStoreForSync> attachment_store, | |
135 const syncer::UserShare& user_share, | |
136 const std::string& store_birthday, | |
137 syncer::ModelType model_type, | |
138 syncer::AttachmentService::Delegate* delegate) = 0; | |
139 }; | |
140 | |
141 } // namespace sync_driver | |
142 | |
143 #endif // COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ | |
OLD | NEW |