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 ModelTypeSet
InitialSyncEndedTypes() OVERRIDE
;
59 virtual ModelTypeSet
GetTypesWithEmptyProgressMarkerToken(
60 ModelTypeSet types
) OVERRIDE
;
61 virtual bool PurgePartiallySyncedTypes() OVERRIDE
;
62 virtual void UpdateCredentials(const SyncCredentials
& credentials
) OVERRIDE
;
63 virtual void StartSyncingNormally(const ModelSafeRoutingInfo
& routing_info
)
65 virtual void ConfigureSyncer(
66 ConfigureReason reason
,
67 ModelTypeSet to_download
,
68 ModelTypeSet to_purge
,
69 ModelTypeSet to_journal
,
70 ModelTypeSet to_unapply
,
71 const ModelSafeRoutingInfo
& new_routing_info
,
72 const base::Closure
& ready_task
,
73 const base::Closure
& retry_task
) OVERRIDE
;
74 virtual void SetInvalidatorEnabled(bool invalidator_enabled
) OVERRIDE
;
75 virtual void OnIncomingInvalidation(
76 syncer::ModelType type
,
77 scoped_ptr
<InvalidationInterface
> invalidation
) 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 SyncContextProxy
* GetSyncContextProxy() OVERRIDE
;
90 virtual ScopedVector
<ProtocolEvent
> GetBufferedProtocolEvents()
92 virtual scoped_ptr
<base::ListValue
> GetAllNodesForType(
93 syncer::ModelType type
) OVERRIDE
;
95 // DirectoryChangeDelegate implementation.
96 virtual void HandleTransactionCompleteChangeEvent(
97 ModelTypeSet models_with_changes
) OVERRIDE
;
98 virtual ModelTypeSet
HandleTransactionEndingChangeEvent(
99 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
100 syncable::BaseTransaction
* trans
) OVERRIDE
;
101 virtual void HandleCalculateChangesChangeEventFromSyncApi(
102 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
103 syncable::BaseTransaction
* trans
,
104 std::vector
<int64
>* entries_changed
) OVERRIDE
;
105 virtual void HandleCalculateChangesChangeEventFromSyncer(
106 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
107 syncable::BaseTransaction
* trans
,
108 std::vector
<int64
>* entries_changed
) OVERRIDE
;
110 // syncable::TransactionObserver implementation.
111 virtual void OnTransactionWrite(
112 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
113 ModelTypeSet models_with_changes
) OVERRIDE
;
116 ObserverList
<SyncManager::Observer
>* GetObservers();
118 virtual void RegisterDirectoryTypeDebugInfoObserver(
119 syncer::TypeDebugInfoObserver
* observer
) OVERRIDE
;
120 virtual void UnregisterDirectoryTypeDebugInfoObserver(
121 syncer::TypeDebugInfoObserver
* observer
) OVERRIDE
;
122 virtual bool HasDirectoryTypeDebugInfoObserver(
123 syncer::TypeDebugInfoObserver
* observer
) OVERRIDE
;
124 virtual void RequestEmitDebugInfo() OVERRIDE
;
126 bool initialized() const {
131 void NotifyInitializationSuccess();
132 void NotifyInitializationFailure();
135 const base::FilePath
& sync_folder
,
136 InternalComponentsFactory
* internal_components_factory
);
138 bool InitTypeRootNode(ModelType type
);
139 void InitBookmarkFolder(const std::string
& folder
);
142 ObserverList
<SyncManager::Observer
> observers_
;
144 scoped_ptr
<UnrecoverableErrorHandler
> unrecoverable_error_handler_
;
145 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_
;
147 base::WeakPtrFactory
<SyncRollbackManagerBase
> weak_ptr_factory_
;
149 scoped_ptr
<SyncEncryptionHandler
> dummy_handler_
;
153 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase
);
156 } // namespace syncer
158 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_