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 ~SyncRollbackManagerBase() override
;
38 // SyncManager implementation.
39 ModelTypeSet
InitialSyncEndedTypes() override
;
40 ModelTypeSet
GetTypesWithEmptyProgressMarkerToken(
41 ModelTypeSet types
) override
;
42 bool PurgePartiallySyncedTypes() override
;
43 void UpdateCredentials(const SyncCredentials
& credentials
) override
;
44 void StartSyncingNormally(const ModelSafeRoutingInfo
& routing_info
) override
;
45 void ConfigureSyncer(ConfigureReason reason
,
46 ModelTypeSet to_download
,
47 ModelTypeSet to_purge
,
48 ModelTypeSet to_journal
,
49 ModelTypeSet to_unapply
,
50 const ModelSafeRoutingInfo
& new_routing_info
,
51 const base::Closure
& ready_task
,
52 const base::Closure
& retry_task
) override
;
53 void SetInvalidatorEnabled(bool invalidator_enabled
) override
;
54 void OnIncomingInvalidation(
55 syncer::ModelType type
,
56 scoped_ptr
<InvalidationInterface
> invalidation
) override
;
57 void AddObserver(SyncManager::Observer
* observer
) override
;
58 void RemoveObserver(SyncManager::Observer
* observer
) override
;
59 SyncStatus
GetDetailedStatus() const override
;
60 void SaveChanges() override
;
61 void ShutdownOnSyncThread(ShutdownReason reason
) override
;
62 UserShare
* GetUserShare() override
;
63 const std::string
cache_guid() override
;
64 bool ReceivedExperiment(Experiments
* experiments
) override
;
65 bool HasUnsyncedItems() override
;
66 SyncEncryptionHandler
* GetEncryptionHandler() override
;
67 void RefreshTypes(ModelTypeSet types
) override
;
68 SyncContextProxy
* GetSyncContextProxy() override
;
69 ScopedVector
<ProtocolEvent
> GetBufferedProtocolEvents() override
;
70 scoped_ptr
<base::ListValue
> GetAllNodesForType(
71 syncer::ModelType type
) override
;
73 // DirectoryChangeDelegate implementation.
74 void HandleTransactionCompleteChangeEvent(
75 ModelTypeSet models_with_changes
) override
;
76 ModelTypeSet
HandleTransactionEndingChangeEvent(
77 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
78 syncable::BaseTransaction
* trans
) override
;
79 void HandleCalculateChangesChangeEventFromSyncApi(
80 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
81 syncable::BaseTransaction
* trans
,
82 std::vector
<int64
>* entries_changed
) override
;
83 void HandleCalculateChangesChangeEventFromSyncer(
84 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
85 syncable::BaseTransaction
* trans
,
86 std::vector
<int64
>* entries_changed
) override
;
88 // syncable::TransactionObserver implementation.
89 void OnTransactionWrite(
90 const syncable::ImmutableWriteTransactionInfo
& write_transaction_info
,
91 ModelTypeSet models_with_changes
) override
;
94 ObserverList
<SyncManager::Observer
>* GetObservers();
96 // Initialize sync backup DB.
98 const base::FilePath
& database_location
,
99 InternalComponentsFactory
* internal_components_factory
,
100 InternalComponentsFactory::StorageOption storage
,
101 scoped_ptr
<UnrecoverableErrorHandler
> unrecoverable_error_handler
,
102 ReportUnrecoverableErrorFunction report_unrecoverable_error_function
);
104 void RegisterDirectoryTypeDebugInfoObserver(
105 syncer::TypeDebugInfoObserver
* observer
) override
;
106 void UnregisterDirectoryTypeDebugInfoObserver(
107 syncer::TypeDebugInfoObserver
* observer
) override
;
108 bool HasDirectoryTypeDebugInfoObserver(
109 syncer::TypeDebugInfoObserver
* observer
) override
;
110 void RequestEmitDebugInfo() override
;
112 bool initialized() const {
117 void NotifyInitializationSuccess();
118 void NotifyInitializationFailure();
120 bool InitBackupDB(const base::FilePath
& sync_folder
,
121 InternalComponentsFactory
* internal_components_factory
,
122 InternalComponentsFactory::StorageOption storage
);
124 bool InitTypeRootNode(ModelType type
);
125 void InitBookmarkFolder(const std::string
& folder
);
128 ObserverList
<SyncManager::Observer
> observers_
;
130 scoped_ptr
<UnrecoverableErrorHandler
> unrecoverable_error_handler_
;
131 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_
;
133 scoped_ptr
<SyncEncryptionHandler
> dummy_handler_
;
137 base::WeakPtrFactory
<SyncRollbackManagerBase
> weak_ptr_factory_
;
139 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase
);
142 } // namespace syncer
144 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_