[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / sync / internal_api / sync_rollback_manager_base.h
blob9aaf02b406bd76d85d2ae383686e26a6e41f83ca
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/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"
18 namespace syncer {
20 class WriteTransaction;
22 // Base class of sync managers used for backup and rollback. Two major
23 // functions are:
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 :
30 public SyncManager,
31 public syncable::DirectoryChangeDelegate,
32 public syncable::TransactionObserver {
33 public:
34 SyncRollbackManagerBase();
35 virtual ~SyncRollbackManagerBase();
37 // SyncManager implementation.
38 virtual void Init(
39 const base::FilePath& database_location,
40 const WeakHandle<JsEventHandler>& event_handler,
41 const std::string& sync_server_and_path,
42 int sync_server_port,
43 bool use_ssl,
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,
53 Encryptor* encryptor,
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)
64 OVERRIDE;
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()
91 OVERRIDE;
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;
115 protected:
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 {
127 return initialized_;
130 private:
131 void NotifyInitializationSuccess();
132 void NotifyInitializationFailure();
134 bool InitBackupDB(
135 const base::FilePath& sync_folder,
136 InternalComponentsFactory* internal_components_factory);
138 bool InitTypeRootNode(ModelType type);
139 void InitBookmarkFolder(const std::string& folder);
141 UserShare share_;
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_;
151 bool initialized_;
153 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase);
156 } // namespace syncer
158 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_