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 SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_
6 #define SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_
11 #include "sync/base/sync_export.h"
12 #include "sync/internal_api/public/http_post_provider_factory.h"
13 #include "sync/internal_api/public/sync_manager.h"
14 #include "sync/internal_api/public/user_share.h"
15 #include "sync/syncable/directory_change_delegate.h"
16 #include "sync/syncable/transaction_observer.h"
20 class WriteTransaction;
22 // Base class of sync managers used for backup and rollback. Two major
24 // * Init(): load backup DB into sync directory.
25 // * ConfigureSyncer(): initialize permanent sync nodes (root, bookmark
26 // permanent folders) for configured type as needed.
28 // Most of other functions are no ops.
29 class SYNC_EXPORT_PRIVATE SyncRollbackManagerBase :
31 public syncable::DirectoryChangeDelegate,
32 public syncable::TransactionObserver {
34 SyncRollbackManagerBase();
35 virtual ~SyncRollbackManagerBase();
37 // SyncManager implementation.
39 const base::FilePath& database_location,
40 const WeakHandle<JsEventHandler>& event_handler,
41 const std::string& sync_server_and_path,
44 scoped_ptr<HttpPostProviderFactory> post_factory,
45 const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
46 ExtensionsActivity* extensions_activity,
47 SyncManager::ChangeDelegate* change_delegate,
48 const SyncCredentials& credentials,
49 const std::string& invalidator_client_id,
50 const std::string& restored_key_for_bootstrapping,
51 const std::string& restored_keystore_key_for_bootstrapping,
52 InternalComponentsFactory* internal_components_factory,
54 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
55 ReportUnrecoverableErrorFunction
56 report_unrecoverable_error_function,
57 CancelationSignal* cancelation_signal) OVERRIDE;
58 virtual void ThrowUnrecoverableError() OVERRIDE;
59 virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
60 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
61 ModelTypeSet types) OVERRIDE;
62 virtual bool PurgePartiallySyncedTypes() OVERRIDE;
63 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE;
64 virtual void StartSyncingNormally(const ModelSafeRoutingInfo& routing_info)
66 virtual void ConfigureSyncer(
67 ConfigureReason reason,
68 ModelTypeSet to_download,
69 ModelTypeSet to_purge,
70 ModelTypeSet to_journal,
71 ModelTypeSet to_unapply,
72 const ModelSafeRoutingInfo& new_routing_info,
73 const base::Closure& ready_task,
74 const base::Closure& retry_task) OVERRIDE;
75 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE;
76 virtual void OnIncomingInvalidation(
77 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE;
78 virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE;
79 virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE;
80 virtual SyncStatus GetDetailedStatus() const OVERRIDE;
81 virtual void SaveChanges() OVERRIDE;
82 virtual void ShutdownOnSyncThread() OVERRIDE;
83 virtual UserShare* GetUserShare() OVERRIDE;
84 virtual const std::string cache_guid() OVERRIDE;
85 virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE;
86 virtual bool HasUnsyncedItems() OVERRIDE;
87 virtual SyncEncryptionHandler* GetEncryptionHandler() OVERRIDE;
88 virtual void RefreshTypes(ModelTypeSet types) OVERRIDE;
89 virtual std::string GetOwnerName() const OVERRIDE;
90 virtual SyncCoreProxy* GetSyncCoreProxy() OVERRIDE;
91 virtual ScopedVector<ProtocolEvent> GetBufferedProtocolEvents()
93 virtual scoped_ptr<base::ListValue> GetAllNodesForType(
94 syncer::ModelType type) OVERRIDE;
96 // DirectoryChangeDelegate implementation.
97 virtual void HandleTransactionCompleteChangeEvent(
98 ModelTypeSet models_with_changes) OVERRIDE;
99 virtual ModelTypeSet HandleTransactionEndingChangeEvent(
100 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
101 syncable::BaseTransaction* trans) OVERRIDE;
102 virtual void HandleCalculateChangesChangeEventFromSyncApi(
103 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
104 syncable::BaseTransaction* trans,
105 std::vector<int64>* entries_changed) OVERRIDE;
106 virtual void HandleCalculateChangesChangeEventFromSyncer(
107 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
108 syncable::BaseTransaction* trans,
109 std::vector<int64>* entries_changed) OVERRIDE;
111 // syncable::TransactionObserver implementation.
112 virtual void OnTransactionWrite(
113 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
114 ModelTypeSet models_with_changes) OVERRIDE;
116 virtual void RegisterDirectoryTypeDebugInfoObserver(
117 syncer::TypeDebugInfoObserver* observer) OVERRIDE;
118 virtual void UnregisterDirectoryTypeDebugInfoObserver(
119 syncer::TypeDebugInfoObserver* observer) OVERRIDE;
120 virtual bool HasDirectoryTypeDebugInfoObserver(
121 syncer::TypeDebugInfoObserver* observer) OVERRIDE;
122 virtual void RequestEmitDebugInfo() OVERRIDE;
125 void NotifyInitializationSuccess();
126 void NotifyInitializationFailure();
129 const base::FilePath& sync_folder,
130 InternalComponentsFactory* internal_components_factory);
132 bool InitTypeRootNode(ModelType type);
133 void InitBookmarkFolder(const std::string& folder);
136 ObserverList<SyncManager::Observer> observers_;
138 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler_;
139 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_;
141 base::WeakPtrFactory<SyncRollbackManagerBase> weak_ptr_factory_;
143 scoped_ptr<SyncEncryptionHandler> dummy_handler_;
145 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase);
148 } // namespace syncer
150 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_