Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: components/sync_driver/glue/sync_backend_host.h

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

Powered by Google App Engine
This is Rietveld 408576698