| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | |
| 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/threading/thread.h" | |
| 15 #include "components/sync_driver/backend_data_type_configurer.h" | |
| 16 #include "sync/internal_api/public/base/model_type.h" | |
| 17 #include "sync/internal_api/public/configure_reason.h" | |
| 18 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | |
| 19 #include "sync/internal_api/public/shutdown_reason.h" | |
| 20 #include "sync/internal_api/public/sync_manager.h" | |
| 21 #include "sync/internal_api/public/sync_manager_factory.h" | |
| 22 #include "sync/internal_api/public/util/weak_handle.h" | |
| 23 | |
| 24 class GURL; | |
| 25 | |
| 26 namespace base { | |
| 27 class MessageLoop; | |
| 28 } | |
| 29 | |
| 30 namespace syncer { | |
| 31 class CancelationSignal; | |
| 32 class HttpPostProviderFactory; | |
| 33 class SyncManagerFactory; | |
| 34 class UnrecoverableErrorHandler; | |
| 35 } | |
| 36 | |
| 37 namespace sync_driver { | |
| 38 class ChangeProcessor; | |
| 39 class SyncFrontend; | |
| 40 } | |
| 41 | |
| 42 namespace browser_sync { | |
| 43 | |
| 44 // An API to "host" the top level SyncAPI element. | |
| 45 // | |
| 46 // This class handles dispatch of potentially blocking calls to appropriate | |
| 47 // threads and ensures that the SyncFrontend is only accessed on the UI loop. | |
| 48 class SyncBackendHost : public sync_driver::BackendDataTypeConfigurer { | |
| 49 public: | |
| 50 typedef syncer::SyncStatus Status; | |
| 51 typedef base::Callback<scoped_ptr<syncer::HttpPostProviderFactory>( | |
| 52 syncer::CancelationSignal*)> HttpPostProviderFactoryGetter; | |
| 53 | |
| 54 // Stubs used by implementing classes. | |
| 55 SyncBackendHost(); | |
| 56 ~SyncBackendHost() override; | |
| 57 | |
| 58 // Called on the frontend's thread to kick off asynchronous initialization. | |
| 59 // Optionally deletes the "Sync Data" folder during init in order to make | |
| 60 // sure we're starting fresh. | |
| 61 // | |
| 62 // |saved_nigori_state| is optional nigori state to restore from a previous | |
| 63 // backend instance. May be null. | |
| 64 virtual void Initialize( | |
| 65 sync_driver::SyncFrontend* frontend, | |
| 66 scoped_ptr<base::Thread> sync_thread, | |
| 67 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, | |
| 68 const scoped_refptr<base::SingleThreadTaskRunner>& file_thread, | |
| 69 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | |
| 70 const GURL& service_url, | |
| 71 const std::string& sync_user_agent, | |
| 72 const syncer::SyncCredentials& credentials, | |
| 73 bool delete_sync_data_folder, | |
| 74 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | |
| 75 const syncer::WeakHandle<syncer::UnrecoverableErrorHandler>& | |
| 76 unrecoverable_error_handler, | |
| 77 const base::Closure& report_unrecoverable_error_function, | |
| 78 const HttpPostProviderFactoryGetter& http_post_provider_factory_getter, | |
| 79 scoped_ptr<syncer::SyncEncryptionHandler::NigoriState> | |
| 80 saved_nigori_state) = 0; | |
| 81 | |
| 82 // Called on the frontend's thread to trigger a refresh. | |
| 83 virtual void TriggerRefresh(const syncer::ModelTypeSet& types) = 0; | |
| 84 | |
| 85 // Called on the frontend's thread to update SyncCredentials. | |
| 86 virtual void UpdateCredentials( | |
| 87 const syncer::SyncCredentials& credentials) = 0; | |
| 88 | |
| 89 // This starts the SyncerThread running a Syncer object to communicate with | |
| 90 // sync servers. Until this is called, no changes will leave or enter this | |
| 91 // browser from the cloud / sync servers. | |
| 92 // Called on |frontend_loop_|. | |
| 93 virtual void StartSyncingWithServer() = 0; | |
| 94 | |
| 95 // Called on |frontend_loop_| to asynchronously set a new passphrase for | |
| 96 // encryption. Note that it is an error to call SetEncryptionPassphrase under | |
| 97 // the following circumstances: | |
| 98 // - An explicit passphrase has already been set | |
| 99 // - |is_explicit| is true and we have pending keys. | |
| 100 // When |is_explicit| is false, a couple of things could happen: | |
| 101 // - If there are pending keys, we try to decrypt them. If decryption works, | |
| 102 // this acts like a call to SetDecryptionPassphrase. If not, the GAIA | |
| 103 // passphrase passed in is cached so we can re-encrypt with it in future. | |
| 104 // - If there are no pending keys, data is encrypted with |passphrase| (this | |
| 105 // is a no-op if data was already encrypted with |passphrase|.) | |
| 106 virtual void SetEncryptionPassphrase( | |
| 107 const std::string& passphrase, | |
| 108 bool is_explicit) = 0; | |
| 109 | |
| 110 // Called on |frontend_loop_| to use the provided passphrase to asynchronously | |
| 111 // attempt decryption. Returns false immediately if the passphrase could not | |
| 112 // be used to decrypt a locally cached copy of encrypted keys; returns true | |
| 113 // otherwise. If new encrypted keys arrive during the asynchronous call, | |
| 114 // OnPassphraseRequired may be triggered at a later time. It is an error to | |
| 115 // call this when there are no pending keys. | |
| 116 virtual bool SetDecryptionPassphrase(const std::string& passphrase) | |
| 117 WARN_UNUSED_RESULT = 0; | |
| 118 | |
| 119 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut | |
| 120 // short any long-lived or blocking sync thread tasks so that the shutdown on | |
| 121 // sync thread task that we're about to post won't have to wait very long. | |
| 122 virtual void StopSyncingForShutdown() = 0; | |
| 123 | |
| 124 // Called on |frontend_loop_| to kick off shutdown. | |
| 125 // See the implementation and Core::DoShutdown for details. | |
| 126 // Must be called *after* StopSyncingForShutdown. | |
| 127 // For any reason other than BROWSER_SHUTDOWN, caller should claim sync | |
| 128 // thread because: | |
| 129 // * during browser shutdown sync thread is not claimed to avoid blocking | |
| 130 // browser shutdown on sync shutdown. | |
| 131 // * otherwise sync thread is claimed so that if sync backend is recreated | |
| 132 // later, initialization of new backend is serialized on previous sync | |
| 133 // thread after cleanup of previous backend to avoid old/new backends | |
| 134 // interfere with each other. | |
| 135 virtual scoped_ptr<base::Thread> Shutdown(syncer::ShutdownReason reason) = 0; | |
| 136 | |
| 137 // Removes all current registrations from the backend on the | |
| 138 // InvalidationService. | |
| 139 virtual void UnregisterInvalidationIds() = 0; | |
| 140 | |
| 141 // Changes the set of data types that are currently being synced. | |
| 142 // The ready_task will be run when configuration is done with the | |
| 143 // set of all types that failed configuration (i.e., if its argument | |
| 144 // is non-empty, then an error was encountered). | |
| 145 // Returns the set of types that are ready to start without needing any | |
| 146 // further sync activity. | |
| 147 // BackendDataTypeConfigurer implementation. | |
| 148 syncer::ModelTypeSet ConfigureDataTypes( | |
| 149 syncer::ConfigureReason reason, | |
| 150 const DataTypeConfigStateMap& config_state_map, | |
| 151 const base::Callback<void(syncer::ModelTypeSet, syncer::ModelTypeSet)>& | |
| 152 ready_task, | |
| 153 const base::Callback<void()>& retry_callback) override = 0; | |
| 154 | |
| 155 // Turns on encryption of all present and future sync data. | |
| 156 virtual void EnableEncryptEverything() = 0; | |
| 157 | |
| 158 // Called on |frontend_loop_| to obtain a handle to the UserShare needed for | |
| 159 // creating transactions. Should not be called before we signal | |
| 160 // initialization is complete with OnBackendInitialized(). | |
| 161 virtual syncer::UserShare* GetUserShare() const = 0; | |
| 162 | |
| 163 // Called from any thread to obtain current status information in detailed or | |
| 164 // summarized form. | |
| 165 virtual Status GetDetailedStatus() = 0; | |
| 166 virtual syncer::sessions::SyncSessionSnapshot | |
| 167 GetLastSessionSnapshot() const = 0; | |
| 168 | |
| 169 // Determines if the underlying sync engine has made any local changes to | |
| 170 // items that have not yet been synced with the server. | |
| 171 // ONLY CALL THIS IF OnInitializationComplete was called! | |
| 172 virtual bool HasUnsyncedItems() const = 0; | |
| 173 | |
| 174 // Whether or not we are syncing encryption keys. | |
| 175 virtual bool IsNigoriEnabled() const = 0; | |
| 176 | |
| 177 // Returns the type of passphrase being used to encrypt data. See | |
| 178 // sync_encryption_handler.h. | |
| 179 virtual syncer::PassphraseType GetPassphraseType() const = 0; | |
| 180 | |
| 181 // If an explicit passphrase is in use, returns the time at which that | |
| 182 // passphrase was set (if available). | |
| 183 virtual base::Time GetExplicitPassphraseTime() const = 0; | |
| 184 | |
| 185 // True if the cryptographer has any keys available to attempt decryption. | |
| 186 // Could mean we've downloaded and loaded Nigori objects, or we bootstrapped | |
| 187 // using a token previously received. | |
| 188 virtual bool IsCryptographerReady( | |
| 189 const syncer::BaseTransaction* trans) const = 0; | |
| 190 | |
| 191 virtual void GetModelSafeRoutingInfo( | |
| 192 syncer::ModelSafeRoutingInfo* out) const = 0; | |
| 193 | |
| 194 // Send a message to the sync thread to persist the Directory to disk. | |
| 195 virtual void FlushDirectory() const = 0; | |
| 196 | |
| 197 // Requests that the backend forward to the fronent any protocol events in | |
| 198 // its buffer and begin forwarding automatically from now on. Repeated calls | |
| 199 // to this function may result in the same events being emitted several | |
| 200 // times. | |
| 201 virtual void RequestBufferedProtocolEventsAndEnableForwarding() = 0; | |
| 202 | |
| 203 // Disables protocol event forwarding. | |
| 204 virtual void DisableProtocolEventForwarding() = 0; | |
| 205 | |
| 206 // Returns a ListValue representing all nodes for the specified types through | |
| 207 // |callback| on this thread. | |
| 208 virtual void GetAllNodesForTypes( | |
| 209 syncer::ModelTypeSet types, | |
| 210 base::Callback<void(const std::vector<syncer::ModelType>&, | |
| 211 ScopedVector<base::ListValue>)> type) = 0; | |
| 212 | |
| 213 // Enables the sending of directory type debug counters. Also, for every | |
| 214 // time it is called, it makes an explicit request that updates to an update | |
| 215 // for all counters be emitted. | |
| 216 virtual void EnableDirectoryTypeDebugInfoForwarding() = 0; | |
| 217 | |
| 218 // Disables the sending of directory type debug counters. | |
| 219 virtual void DisableDirectoryTypeDebugInfoForwarding() = 0; | |
| 220 | |
| 221 virtual base::MessageLoop* GetSyncLoopForTesting() = 0; | |
| 222 | |
| 223 // Triggers sync cycle to update |types|. | |
| 224 virtual void RefreshTypesForTest(syncer::ModelTypeSet types) = 0; | |
| 225 | |
| 226 // See SyncManager::ClearServerData. | |
| 227 virtual void ClearServerData( | |
| 228 const syncer::SyncManager::ClearServerDataCallback& callback) = 0; | |
| 229 | |
| 230 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | |
| 231 }; | |
| 232 | |
| 233 } // namespace browser_sync | |
| 234 | |
| 235 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | |
| OLD | NEW |