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 ModelTypeSet InitialSyncEndedTypes() OVERRIDE; 39 virtual ModelTypeSet GetTypesWithEmptyProgressMarkerToken( 40 ModelTypeSet types) OVERRIDE; 41 virtual bool PurgePartiallySyncedTypes() OVERRIDE; 42 virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; 43 virtual void StartSyncingNormally(const ModelSafeRoutingInfo& routing_info) 44 OVERRIDE; 45 virtual void ConfigureSyncer( 46 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 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; 55 virtual void OnIncomingInvalidation( 56 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; 57 virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE; 58 virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE; 59 virtual SyncStatus GetDetailedStatus() const OVERRIDE; 60 virtual void SaveChanges() OVERRIDE; 61 virtual void ShutdownOnSyncThread() OVERRIDE; 62 virtual UserShare* GetUserShare() OVERRIDE; 63 virtual const std::string cache_guid() OVERRIDE; 64 virtual bool ReceivedExperiment(Experiments* experiments) OVERRIDE; 65 virtual bool HasUnsyncedItems() OVERRIDE; 66 virtual SyncEncryptionHandler* GetEncryptionHandler() OVERRIDE; 67 virtual void RefreshTypes(ModelTypeSet types) OVERRIDE; 68 virtual std::string GetOwnerName() const OVERRIDE; 69 virtual SyncCoreProxy* GetSyncCoreProxy() OVERRIDE; 70 virtual ScopedVector<ProtocolEvent> GetBufferedProtocolEvents() 71 OVERRIDE; 72 virtual scoped_ptr<base::ListValue> GetAllNodesForType( 73 syncer::ModelType type) OVERRIDE; 74 75 // DirectoryChangeDelegate implementation. 76 virtual void HandleTransactionCompleteChangeEvent( 77 ModelTypeSet models_with_changes) OVERRIDE; 78 virtual ModelTypeSet HandleTransactionEndingChangeEvent( 79 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, 80 syncable::BaseTransaction* trans) OVERRIDE; 81 virtual void HandleCalculateChangesChangeEventFromSyncApi( 82 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, 83 syncable::BaseTransaction* trans, 84 std::vector<int64>* entries_changed) OVERRIDE; 85 virtual void HandleCalculateChangesChangeEventFromSyncer( 86 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, 87 syncable::BaseTransaction* trans, 88 std::vector<int64>* entries_changed) OVERRIDE; 89 90 // syncable::TransactionObserver implementation. 91 virtual void OnTransactionWrite( 92 const syncable::ImmutableWriteTransactionInfo& write_transaction_info, 93 ModelTypeSet models_with_changes) OVERRIDE; 94 95 protected: 96 ObserverList<SyncManager::Observer>* GetObservers(); 97 98 // Initialize sync backup DB. 99 bool InitInternal( 100 const base::FilePath& database_location, 101 InternalComponentsFactory* internal_components_factory, 102 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler, 103 ReportUnrecoverableErrorFunction report_unrecoverable_error_function); 104 105 virtual void RegisterDirectoryTypeDebugInfoObserver( 106 syncer::TypeDebugInfoObserver* observer) OVERRIDE; 107 virtual void UnregisterDirectoryTypeDebugInfoObserver( 108 syncer::TypeDebugInfoObserver* observer) OVERRIDE; 109 virtual bool HasDirectoryTypeDebugInfoObserver( 110 syncer::TypeDebugInfoObserver* observer) OVERRIDE; 111 virtual void RequestEmitDebugInfo() OVERRIDE; 112 113 bool initialized() const { 114 return initialized_; 115 } 116 117 private: 118 void NotifyInitializationSuccess(); 119 void NotifyInitializationFailure(); 120 121 bool InitBackupDB( 122 const base::FilePath& sync_folder, 123 InternalComponentsFactory* internal_components_factory); 124 125 bool InitTypeRootNode(ModelType type); 126 void InitBookmarkFolder(const std::string& folder); 127 128 UserShare share_; 129 ObserverList<SyncManager::Observer> observers_; 130 131 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler_; 132 ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; 133 134 base::WeakPtrFactory<SyncRollbackManagerBase> weak_ptr_factory_; 135 136 scoped_ptr<SyncEncryptionHandler> dummy_handler_; 137 138 bool initialized_; 139 140 DISALLOW_COPY_AND_ASSIGN(SyncRollbackManagerBase); 141 }; 142 143 } // namespace syncer 144 145 #endif // SYNC_INTERNAL_API_SYNC_ROLLBACK_MANAGER_BASE_H_ 146