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.
5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_
6 #define COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "components/sync_driver/data_type_controller.h"
11 #include "sync/api/syncable_service.h"
12 #include "sync/internal_api/public/attachments/attachment_service.h"
13 #include "sync/internal_api/public/base/model_type.h"
19 namespace browser_sync
{
20 class SyncBackendHost
;
21 } // namespace browser_sync
27 namespace invalidation
{
28 class InvalidationService
;
29 } // namespace invalidation
32 class DataTypeDebugInfoListener
;
33 class SyncableService
;
38 namespace sync_driver
{
40 class AssociatorInterface
;
41 class ChangeProcessor
;
42 class DataTypeEncryptionHandler
;
43 class DataTypeErrorHandler
;
44 class DataTypeManager
;
45 class DataTypeManagerObserver
;
46 class DataTypeStatusTable
;
47 class GenericChangeProcessor
;
48 class LocalDeviceInfoProvider
;
52 // This factory provides sync driver code with the model type specific sync/api
53 // service (like SyncableService) implementations.
54 class SyncApiComponentFactory
{
56 virtual ~SyncApiComponentFactory() {}
58 // The various factory methods for the data type model associators
59 // and change processors all return this struct. This is needed
60 // because the change processors typically require a type-specific
61 // model associator at construction time.
63 // Note: This interface is deprecated in favor of the SyncableService API.
64 // New datatypes that do not live on the UI thread should directly return a
65 // weak pointer to a syncer::SyncableService. All others continue to return
66 // SyncComponents. It is safe to assume that the factory methods below are
67 // called on the same thread in which the datatype resides.
69 // TODO(zea): Have all datatypes using the new API switch to returning
70 // SyncableService weak pointers instead of SyncComponents (crbug.com/100114).
71 struct SyncComponents
{
72 sync_driver::AssociatorInterface
* model_associator
;
73 sync_driver::ChangeProcessor
* change_processor
;
74 SyncComponents(sync_driver::AssociatorInterface
* ma
,
75 sync_driver::ChangeProcessor
* cp
)
76 : model_associator(ma
), change_processor(cp
) {}
79 virtual void Initialize(sync_driver::SyncService
* sync_service
) = 0;
81 // Creates and registers enabled datatypes with internal SyncService.
82 virtual void RegisterDataTypes() = 0;
84 // Instantiates a new DataTypeManager with a SyncBackendHost, a list of data
85 // type controllers and a DataTypeManagerObserver. The return pointer is
86 // owned by the caller.
87 virtual sync_driver::DataTypeManager
* CreateDataTypeManager(
88 const syncer::WeakHandle
<syncer::DataTypeDebugInfoListener
>&
90 const sync_driver::DataTypeController::TypeMap
* controllers
,
91 const sync_driver::DataTypeEncryptionHandler
* encryption_handler
,
92 browser_sync::SyncBackendHost
* backend
,
93 sync_driver::DataTypeManagerObserver
* observer
) = 0;
95 // Creating this in the factory helps us mock it out in testing.
96 virtual browser_sync::SyncBackendHost
* CreateSyncBackendHost(
97 const std::string
& name
,
98 invalidation::InvalidationService
* invalidator
,
99 const base::WeakPtr
<sync_driver::SyncPrefs
>& sync_prefs
,
100 const base::FilePath
& sync_folder
) = 0;
102 // Creating this in the factory helps us mock it out in testing.
103 virtual scoped_ptr
<sync_driver::LocalDeviceInfoProvider
>
104 CreateLocalDeviceInfoProvider() = 0;
106 // Legacy datatypes that need to be converted to the SyncableService API.
107 virtual SyncComponents
CreateBookmarkSyncComponents(
108 sync_driver::SyncService
* sync_service
,
109 sync_driver::DataTypeErrorHandler
* error_handler
) = 0;
110 virtual SyncComponents
CreateTypedUrlSyncComponents(
111 sync_driver::SyncService
* sync_service
,
112 history::HistoryBackend
* history_backend
,
113 sync_driver::DataTypeErrorHandler
* error_handler
) = 0;
115 // Creates attachment service.
116 // Note: Should only be called from the model type thread.
118 // |store_birthday| is the store birthday. Must not be empty.
120 // |model_type| is the model type this AttachmentService will be used with.
122 // |delegate| is optional delegate for AttachmentService to notify about
123 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not
124 // provided. AttachmentService doesn't take ownership of delegate, the pointer
125 // must be valid throughout AttachmentService lifetime.
126 virtual scoped_ptr
<syncer::AttachmentService
> CreateAttachmentService(
127 scoped_ptr
<syncer::AttachmentStoreForSync
> attachment_store
,
128 const syncer::UserShare
& user_share
,
129 const std::string
& store_birthday
,
130 syncer::ModelType model_type
,
131 syncer::AttachmentService::Delegate
* delegate
) = 0;
134 } // namespace sync_driver
136 #endif // COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_