Update V8 to version 4.5.92.
[chromium-blink-merge.git] / sync / internal_api / sync_rollback_manager_base.h
blobaa415a2631148fa39243dc2358d4a8105e812917
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 SyncContextProxy* GetSyncContextProxy() override;
70 ScopedVector<ProtocolEvent> GetBufferedProtocolEvents() override;
71 scoped_ptr<base::ListValue> GetAllNodesForType(
72 syncer::ModelType type) override;
74 // DirectoryChangeDelegate implementation.
75 void HandleTransactionCompleteChangeEvent(
76 ModelTypeSet models_with_changes) override;
77 ModelTypeSet HandleTransactionEndingChangeEvent(
78 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
79 syncable::BaseTransaction* trans) override;
80 void HandleCalculateChangesChangeEventFromSyncApi(
81 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
82 syncable::BaseTransaction* trans,
83 std::vector<int64>* entries_changed) override;
84 void HandleCalculateChangesChangeEventFromSyncer(
85 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
86 syncable::BaseTransaction* trans,
87 std::vector<int64>* entries_changed) override;
89 // syncable::TransactionObserver implementation.
90 void OnTransactionWrite(
91 const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
92 ModelTypeSet models_with_changes) override;
94 protected:
95 base::ObserverList<SyncManager::Observer>* GetObservers();
97 // Initialize sync backup DB.
98 bool InitInternal(
99 const base::FilePath& database_location,
100 InternalComponentsFactory* internal_components_factory,
101 InternalComponentsFactory::StorageOption storage,
102 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
103 const base::Closure& report_unrecoverable_error_function);
105 void RegisterDirectoryTypeDebugInfoObserver(
106 syncer::TypeDebugInfoObserver* observer) override;
107 void UnregisterDirectoryTypeDebugInfoObserver(
108 syncer::TypeDebugInfoObserver* observer) override;
109 bool HasDirectoryTypeDebugInfoObserver(
110 syncer::TypeDebugInfoObserver* observer) override;
111 void RequestEmitDebugInfo() override;
113 bool initialized() const {
114 return initialized_;
117 private:
118 void NotifyInitializationSuccess();
119 void NotifyInitializationFailure();
121 bool InitBackupDB(const base::FilePath& sync_folder,
122 InternalComponentsFactory* internal_components_factory,
123 InternalComponentsFactory::StorageOption storage);
125 bool InitTypeRootNode(ModelType type);
126 void InitBookmarkFolder(const std::string& folder);
128 UserShare share_;
129 base::ObserverList<SyncManager::Observer> observers_;
131 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler_;
132 base::Closure report_unrecoverable_error_function_;
134 scoped_ptr<SyncEncryptionHandler> dummy_handler_;
136 bool initialized_;
138 base::WeakPtrFactory<SyncRollbackManagerBase> weak_ptr_factory_;
140 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase);
143 } // namespace syncer
145 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_