Roll src/third_party/WebKit 96fb88b:6bbd108 (svn 201045:201047)
[chromium-blink-merge.git] / sync / internal_api / sync_rollback_manager_base.h
blob638b2f063d053bae07c521441f812fa9fb3a1d82
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_
8 #include <string>
9 #include <vector>
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"
19 namespace syncer {
21 class WriteTransaction;
23 // Base class of sync managers used for backup and rollback. Two major
24 // functions are:
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 :
31 public SyncManager,
32 public syncable::DirectoryChangeDelegate,
33 public syncable::TransactionObserver {
34 public:
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,
45 base::Time last_poll_time) override;
46 void ConfigureSyncer(ConfigureReason reason,
47 ModelTypeSet to_download,
48 ModelTypeSet to_purge,
49 ModelTypeSet to_journal,
50 ModelTypeSet to_unapply,
51 const ModelSafeRoutingInfo& new_routing_info,
52 const base::Closure& ready_task,
53 const base::Closure& retry_task) override;
54 void SetInvalidatorEnabled(bool invalidator_enabled) override;
55 void OnIncomingInvalidation(
56 syncer::ModelType type,
57 scoped_ptr<InvalidationInterface> invalidation) override;
58 void AddObserver(SyncManager::Observer* observer) override;
59 void RemoveObserver(SyncManager::Observer* observer) override;
60 SyncStatus GetDetailedStatus() const override;
61 void SaveChanges() override;
62 void ShutdownOnSyncThread(ShutdownReason reason) override;
63 UserShare* GetUserShare() override;
64 const std::string cache_guid() override;
65 bool ReceivedExperiment(Experiments* experiments) override;
66 bool HasUnsyncedItems() override;
67 SyncEncryptionHandler* GetEncryptionHandler() override;
68 void RefreshTypes(ModelTypeSet types) override;
69 syncer_v2::SyncContextProxy* GetSyncContextProxy() override;
70 ScopedVector<ProtocolEvent> GetBufferedProtocolEvents() override;
71 scoped_ptr<base::ListValue> GetAllNodesForType(
72 syncer::ModelType type) override;
73 void ClearServerData(const ClearServerDataCallback& callback) override;
75 // DirectoryChangeDelegate implementation.
76 void HandleTransactionCompleteChangeEvent(
77 ModelTypeSet models_with_changes) override;
78 ModelTypeSet HandleTransactionEndingChangeEvent(
79 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
80 syncable::BaseTransaction* trans) override;
81 void HandleCalculateChangesChangeEventFromSyncApi(
82 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
83 syncable::BaseTransaction* trans,
84 std::vector<int64>* entries_changed) override;
85 void HandleCalculateChangesChangeEventFromSyncer(
86 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
87 syncable::BaseTransaction* trans,
88 std::vector<int64>* entries_changed) override;
90 // syncable::TransactionObserver implementation.
91 void OnTransactionWrite(
92 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
93 ModelTypeSet models_with_changes) override;
95 protected:
96 base::ObserverList<SyncManager::Observer>* GetObservers();
98 // Initialize sync backup DB.
99 bool InitInternal(
100 const base::FilePath& database_location,
101 InternalComponentsFactory* internal_components_factory,
102 InternalComponentsFactory::StorageOption storage,
103 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler,
104 const base::Closure& report_unrecoverable_error_function);
106 void RegisterDirectoryTypeDebugInfoObserver(
107 syncer::TypeDebugInfoObserver* observer) override;
108 void UnregisterDirectoryTypeDebugInfoObserver(
109 syncer::TypeDebugInfoObserver* observer) override;
110 bool HasDirectoryTypeDebugInfoObserver(
111 syncer::TypeDebugInfoObserver* observer) override;
112 void RequestEmitDebugInfo() override;
114 bool initialized() const {
115 return initialized_;
118 private:
119 void NotifyInitializationSuccess();
120 void NotifyInitializationFailure();
122 bool InitBackupDB(const base::FilePath& sync_folder,
123 InternalComponentsFactory* internal_components_factory,
124 InternalComponentsFactory::StorageOption storage);
126 bool InitTypeRootNode(ModelType type);
127 void InitBookmarkFolder(const std::string& folder);
129 UserShare share_;
130 base::ObserverList<SyncManager::Observer> observers_;
132 WeakHandle<UnrecoverableErrorHandler> unrecoverable_error_handler_;
133 base::Closure report_unrecoverable_error_function_;
135 scoped_ptr<SyncEncryptionHandler> dummy_handler_;
137 bool initialized_;
139 base::WeakPtrFactory<SyncRollbackManagerBase> weak_ptr_factory_;
141 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase);
144 } // namespace syncer
146 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_