Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / sync / internal_api / sync_rollback_manager_base.h
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.
4
5 #ifndef SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_
6 #define SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_
7
8 #include <string>
9 #include <vector>
10
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"
17
18 namespace syncer {
19
20 class WriteTransaction;
21
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.
27 //
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();
36
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 void ThrowUnrecoverableError() OVERRIDE;
59   virtual ModelTypeSet InitialSyncEndedTypes() OVERRIDE;
60   virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken(
61       ModelTypeSet types) OVERRIDE;
62   virtual bool PurgePartiallySyncedTypes() OVERRIDE;
63   virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE;
64   virtual void StartSyncingNormally(const ModelSafeRoutingInfo& routing_info)
65       OVERRIDE;
66   virtual void ConfigureSyncer(
67       ConfigureReason reason,
68       ModelTypeSet to_download,
69       ModelTypeSet to_purge,
70       ModelTypeSet to_journal,
71       ModelTypeSet to_unapply,
72       const ModelSafeRoutingInfo& new_routing_info,
73       const base::Closure& ready_task,
74       const base::Closure& retry_task) OVERRIDE;
75   virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE;
76   virtual void OnIncomingInvalidation(
77       const ObjectIdInvalidationMap& invalidation_map) 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 std::string GetOwnerName() const OVERRIDE;
90   virtual SyncCoreProxy* GetSyncCoreProxy() OVERRIDE;
91   virtual ScopedVector<ProtocolEvent> GetBufferedProtocolEvents()
92       OVERRIDE;
93   virtual scoped_ptr<base::ListValue> GetAllNodesForType(
94       syncer::ModelType type) OVERRIDE;
95
96   // DirectoryChangeDelegate implementation.
97   virtual void HandleTransactionCompleteChangeEvent(
98       ModelTypeSet models_with_changes) OVERRIDE;
99   virtual ModelTypeSet HandleTransactionEndingChangeEvent(
100       const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
101       syncable::BaseTransaction* trans) OVERRIDE;
102   virtual void HandleCalculateChangesChangeEventFromSyncApi(
103       const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
104       syncable::BaseTransaction* trans,
105       std::vector<int64>* entries_changed) OVERRIDE;
106   virtual void HandleCalculateChangesChangeEventFromSyncer(
107       const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
108       syncable::BaseTransaction* trans,
109       std::vector<int64>* entries_changed) OVERRIDE;
110
111   // syncable::TransactionObserver implementation.
112   virtual void OnTransactionWrite(
113       const syncable::ImmutableWriteTransactionInfo& write_transaction_info,
114       ModelTypeSet models_with_changes) OVERRIDE;
115
116   virtual void RegisterDirectoryTypeDebugInfoObserver(
117       syncer::TypeDebugInfoObserver* observer) OVERRIDE;
118   virtual void UnregisterDirectoryTypeDebugInfoObserver(
119       syncer::TypeDebugInfoObserver* observer) OVERRIDE;
120   virtual bool HasDirectoryTypeDebugInfoObserver(
121       syncer::TypeDebugInfoObserver* observer) OVERRIDE;
122   virtual void RequestEmitDebugInfo() OVERRIDE;
123
124  private:
125   void NotifyInitializationSuccess();
126   void NotifyInitializationFailure();
127
128   bool InitBackupDB(
129       const base::FilePath& sync_folder,
130       InternalComponentsFactory* internal_components_factory);
131
132   bool InitTypeRootNode(ModelType type);
133   void InitBookmarkFolder(const std::string& folder);
134
135   UserShare share_;
136   ObserverList<SyncManager::Observer> observers_;
137
138   scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler_;
139   ReportUnrecoverableErrorFunction report_unrecoverable_error_function_;
140
141   base::WeakPtrFactory<SyncRollbackManagerBase> weak_ptr_factory_;
142
143   scoped_ptr<SyncEncryptionHandler> dummy_handler_;
144
145   DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase);
146 };
147
148 }  // namespace syncer
149
150 #endif  // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_