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