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/internal_components_factory.h"
14 #include "sync/internal_api/public/sync_manager.h"
15 #include "sync/internal_api/public/user_share.h"
16 #include "sync/syncable/directory_change_delegate.h"
17 #include "sync/syncable/transaction_observer.h"
21 class WriteTransaction
;
23 // Base class of sync managers used for backup and rollback. Two major
25 // * Init(): load backup DB into sync directory.
26 // * ConfigureSyncer(): initialize permanent sync nodes (root, bookmark
27 // permanent folders) for configured type as needed.
29 // Most of other functions are no ops.
30 class SYNC_EXPORT_PRIVATE SyncRollbackManagerBase
:
32 public syncable::DirectoryChangeDelegate
,
33 public syncable::TransactionObserver
{
35 SyncRollbackManagerBase();
36 virtual ~SyncRollbackManagerBase();
38 // SyncManager implementation.
39 virtual ModelTypeSet
InitialSyncEndedTypes() OVERRIDE
;
40 virtual ModelTypeSet
GetTypesWithEmptyProgressMarkerToken(
41 ModelTypeSet types
) OVERRIDE
;
42 virtual bool PurgePartiallySyncedTypes() OVERRIDE
;
43 virtual void UpdateCredentials(const SyncCredentials
& credentials
) OVERRIDE
;
44 virtual void StartSyncingNormally(const ModelSafeRoutingInfo
& routing_info
)
46 virtual void ConfigureSyncer(
47 ConfigureReason reason
,
48 ModelTypeSet to_download
,
49 ModelTypeSet to_purge
,
50 ModelTypeSet to_journal
,
51 ModelTypeSet to_unapply
,
52 const ModelSafeRoutingInfo
& new_routing_info
,
53 const base::Closure
& ready_task
,
54 const base::Closure
& retry_task
) OVERRIDE
;
55 virtual void SetInvalidatorEnabled(bool invalidator_enabled
) OVERRIDE
;
56 virtual void OnIncomingInvalidation(
57 syncer::ModelType type
,
58 scoped_ptr
<InvalidationInterface
> invalidation
) OVERRIDE
;
59 virtual void AddObserver(SyncManager::Observer
* observer
) OVERRIDE
;
60 virtual void RemoveObserver(SyncManager::Observer
* observer
) OVERRIDE
;
61 virtual SyncStatus
GetDetailedStatus() const OVERRIDE
;
62 virtual void SaveChanges() OVERRIDE
;
63 virtual void ShutdownOnSyncThread(ShutdownReason reason
) OVERRIDE
;
64 virtual UserShare
* GetUserShare() OVERRIDE
;
65 virtual const std::string
cache_guid() OVERRIDE
;
66 virtual bool ReceivedExperiment(Experiments
* experiments
) OVERRIDE
;
67 virtual bool HasUnsyncedItems() OVERRIDE
;
68 virtual SyncEncryptionHandler
* GetEncryptionHandler() OVERRIDE
;
69 virtual void RefreshTypes(ModelTypeSet types
) OVERRIDE
;
70 virtual SyncContextProxy
* GetSyncContextProxy() OVERRIDE
;
71 virtual ScopedVector
<ProtocolEvent
> GetBufferedProtocolEvents()
73 virtual scoped_ptr
<base::ListValue
> GetAllNodesForType(
74 syncer::ModelType type
) OVERRIDE
;
76 // DirectoryChangeDelegate implementation.
77 virtual void HandleTransactionCompleteChangeEvent(
78 ModelTypeSet models_with_changes
) OVERRIDE
;
79 virtual ModelTypeSet
HandleTransactionEndingChangeEvent(
80 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
81 syncable::BaseTransaction
* trans
) OVERRIDE
;
82 virtual void HandleCalculateChangesChangeEventFromSyncApi(
83 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
84 syncable::BaseTransaction
* trans
,
85 std::vector
<int64
>* entries_changed
) OVERRIDE
;
86 virtual void HandleCalculateChangesChangeEventFromSyncer(
87 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
88 syncable::BaseTransaction
* trans
,
89 std::vector
<int64
>* entries_changed
) OVERRIDE
;
91 // syncable::TransactionObserver implementation.
92 virtual void OnTransactionWrite(
93 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
94 ModelTypeSet models_with_changes
) OVERRIDE
;
97 ObserverList
<SyncManager::Observer
>* GetObservers();
99 // Initialize sync backup DB.
101 const base::FilePath
& database_location
,
102 InternalComponentsFactory
* internal_components_factory
,
103 InternalComponentsFactory::StorageOption storage
,
104 scoped_ptr
<UnrecoverableErrorHandler
> unrecoverable_error_handler
,
105 ReportUnrecoverableErrorFunction report_unrecoverable_error_function
);
107 virtual void RegisterDirectoryTypeDebugInfoObserver(
108 syncer::TypeDebugInfoObserver
* observer
) OVERRIDE
;
109 virtual void UnregisterDirectoryTypeDebugInfoObserver(
110 syncer::TypeDebugInfoObserver
* observer
) OVERRIDE
;
111 virtual bool HasDirectoryTypeDebugInfoObserver(
112 syncer::TypeDebugInfoObserver
* observer
) OVERRIDE
;
113 virtual void RequestEmitDebugInfo() OVERRIDE
;
115 bool initialized() const {
120 void NotifyInitializationSuccess();
121 void NotifyInitializationFailure();
123 bool InitBackupDB(const base::FilePath
& sync_folder
,
124 InternalComponentsFactory
* internal_components_factory
,
125 InternalComponentsFactory::StorageOption storage
);
127 bool InitTypeRootNode(ModelType type
);
128 void InitBookmarkFolder(const std::string
& folder
);
131 ObserverList
<SyncManager::Observer
> observers_
;
133 scoped_ptr
<UnrecoverableErrorHandler
> unrecoverable_error_handler_
;
134 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_
;
136 scoped_ptr
<SyncEncryptionHandler
> dummy_handler_
;
140 base::WeakPtrFactory
<SyncRollbackManagerBase
> weak_ptr_factory_
;
142 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase
);
145 } // namespace syncer
147 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_