OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ | 5 #ifndef COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ |
6 #define COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ | 6 #define COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "components/sync_driver/data_type_controller.h" |
10 #include "sync/api/syncable_service.h" | 11 #include "sync/api/syncable_service.h" |
11 #include "sync/internal_api/public/attachments/attachment_service.h" | 12 #include "sync/internal_api/public/attachments/attachment_service.h" |
12 #include "sync/internal_api/public/base/model_type.h" | 13 #include "sync/internal_api/public/base/model_type.h" |
13 | 14 |
| 15 namespace base { |
| 16 class FilePath; |
| 17 } // namespace base |
| 18 |
| 19 namespace browser_sync { |
| 20 class SyncBackendHost; |
| 21 } // namespace browser_sync |
| 22 |
| 23 namespace history { |
| 24 class HistoryBackend; |
| 25 } |
| 26 |
| 27 namespace invalidation { |
| 28 class InvalidationService; |
| 29 } // namespace invalidation |
| 30 |
14 namespace syncer { | 31 namespace syncer { |
| 32 class DataTypeDebugInfoListener; |
| 33 class SyncableService; |
| 34 |
15 struct UserShare; | 35 struct UserShare; |
16 } // namespace syncer | 36 } // namespace syncer |
17 | 37 |
18 namespace sync_driver { | 38 namespace sync_driver { |
19 | 39 |
| 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; |
| 49 class SyncPrefs; |
| 50 class SyncService; |
| 51 |
20 // This factory provides sync driver code with the model type specific sync/api | 52 // This factory provides sync driver code with the model type specific sync/api |
21 // service (like SyncableService) implementations. | 53 // service (like SyncableService) implementations. |
22 class SyncApiComponentFactory { | 54 class SyncApiComponentFactory { |
23 public: | 55 public: |
24 virtual ~SyncApiComponentFactory() {} | 56 virtual ~SyncApiComponentFactory() {} |
25 | 57 |
26 // Returns a weak pointer to the syncable service specified by |type|. | 58 // The various factory methods for the data type model associators |
27 // Weak pointer may be unset if service is already destroyed. | 59 // and change processors all return this struct. This is needed |
28 // Note: Should only be called from the model type thread. | 60 // because the change processors typically require a type-specific |
29 virtual base::WeakPtr<syncer::SyncableService> GetSyncableServiceForType( | 61 // model associator at construction time. |
30 syncer::ModelType type) = 0; | 62 // |
| 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. |
| 68 // |
| 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) {} |
| 77 }; |
| 78 |
| 79 virtual void Initialize(sync_driver::SyncService* sync_service) = 0; |
| 80 |
| 81 // Creates and registers enabled datatypes with internal SyncService. |
| 82 virtual void RegisterDataTypes() = 0; |
| 83 |
| 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>& |
| 89 debug_info_listener, |
| 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; |
| 94 |
| 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; |
| 101 |
| 102 // Creating this in the factory helps us mock it out in testing. |
| 103 virtual scoped_ptr<sync_driver::LocalDeviceInfoProvider> |
| 104 CreateLocalDeviceInfoProvider() = 0; |
| 105 |
| 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; |
31 | 114 |
32 // Creates attachment service. | 115 // Creates attachment service. |
33 // Note: Should only be called from the model type thread. | 116 // Note: Should only be called from the model type thread. |
34 // | 117 // |
35 // |store_birthday| is the store birthday. Must not be empty. | 118 // |store_birthday| is the store birthday. Must not be empty. |
36 // | 119 // |
37 // |model_type| is the model type this AttachmentService will be used with. | 120 // |model_type| is the model type this AttachmentService will be used with. |
38 // | 121 // |
39 // |delegate| is optional delegate for AttachmentService to notify about | 122 // |delegate| is optional delegate for AttachmentService to notify about |
40 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not | 123 // asynchronous events (AttachmentUploaded). Pass NULL if delegate is not |
41 // provided. AttachmentService doesn't take ownership of delegate, the pointer | 124 // provided. AttachmentService doesn't take ownership of delegate, the pointer |
42 // must be valid throughout AttachmentService lifetime. | 125 // must be valid throughout AttachmentService lifetime. |
43 virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService( | 126 virtual scoped_ptr<syncer::AttachmentService> CreateAttachmentService( |
44 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, | 127 scoped_ptr<syncer::AttachmentStoreForSync> attachment_store, |
45 const syncer::UserShare& user_share, | 128 const syncer::UserShare& user_share, |
46 const std::string& store_birthday, | 129 const std::string& store_birthday, |
47 syncer::ModelType model_type, | 130 syncer::ModelType model_type, |
48 syncer::AttachmentService::Delegate* delegate) = 0; | 131 syncer::AttachmentService::Delegate* delegate) = 0; |
49 }; | 132 }; |
50 | 133 |
51 } // namespace sync_driver | 134 } // namespace sync_driver |
52 | 135 |
53 #endif // COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ | 136 #endif // COMPONENTS_SYNC_DRIVER_SYNC_API_COMPONENT_FACTORY_H_ |
OLD | NEW |