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

Side by Side Diff: components/sync/driver/glue/sync_backend_host_impl.h

Issue 2533083002: [Sync] SyncEngine refactor part 1: interfaces. (Closed)
Patch Set: Rebase. Created 4 years 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ 5 #ifndef COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_
6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ 6 #define COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/compiler_specific.h" 16 #include "base/compiler_specific.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/threading/thread_checker.h"
21 #include "base/threading/thread.h"
22 #include "components/invalidation/public/invalidation_handler.h" 21 #include "components/invalidation/public/invalidation_handler.h"
23 #include "components/sync/base/extensions_activity.h" 22 #include "components/sync/base/extensions_activity.h"
24 #include "components/sync/base/model_type.h" 23 #include "components/sync/base/model_type.h"
25 #include "components/sync/base/weak_handle.h" 24 #include "components/sync/base/weak_handle.h"
26 #include "components/sync/driver/backend_data_type_configurer.h"
27 #include "components/sync/driver/glue/sync_backend_host.h"
28 #include "components/sync/engine/configure_reason.h" 25 #include "components/sync/engine/configure_reason.h"
29 #include "components/sync/engine/cycle/sync_cycle_snapshot.h" 26 #include "components/sync/engine/cycle/sync_cycle_snapshot.h"
30 #include "components/sync/engine/cycle/type_debug_info_observer.h" 27 #include "components/sync/engine/cycle/type_debug_info_observer.h"
28 #include "components/sync/engine/model_type_configurer.h"
29 #include "components/sync/engine/sync_engine.h"
31 #include "components/sync/engine/sync_manager.h" 30 #include "components/sync/engine/sync_manager.h"
32 #include "components/sync/protocol/encryption.pb.h" 31 #include "components/sync/protocol/encryption.pb.h"
33 #include "components/sync/protocol/sync_protocol_error.h" 32 #include "components/sync/protocol/sync_protocol_error.h"
34 33
35 class GURL; 34 class GURL;
36 35
37 namespace invalidation { 36 namespace invalidation {
38 class InvalidationService; 37 class InvalidationService;
39 } // namespace invalidation 38 } // namespace invalidation
40 39
41 namespace syncer { 40 namespace syncer {
42 41
43 class ChangeProcessor; 42 class ChangeProcessor;
44 class SyncBackendHostCore; 43 class SyncBackendHostCore;
45 class SyncBackendRegistrar; 44 class SyncBackendRegistrar;
46 class SyncClient; 45 class SyncClient;
47 class SyncManagerFactory; 46 class SyncManagerFactory;
48 class SyncPrefs; 47 class SyncPrefs;
49 class UnrecoverableErrorHandler; 48 class UnrecoverableErrorHandler;
50 struct DoInitializeOptions; 49 struct DoInitializeOptions;
51 50
52 // The only real implementation of the SyncBackendHost. See that interface's 51 // The only real implementation of the SyncEngine. See that interface's
skym 2016/12/02 20:54:54 You don't normally leave in double space sentence
maxbogue 2016/12/02 23:59:27 You know me too well.
53 // definition for documentation of public methods. 52 // definition for documentation of public methods.
54 class SyncBackendHostImpl : public SyncBackendHost, public InvalidationHandler { 53 class SyncBackendHostImpl : public SyncEngine, public InvalidationHandler {
55 public: 54 public:
56 typedef SyncStatus Status; 55 typedef SyncStatus Status;
57 56
58 // Create a SyncBackendHost with a reference to the |frontend| that 57 // Create a SyncEngine with a reference to the |host| that it serves and
skym 2016/12/02 20:54:54 Where's the reference to the host in this ctor? Is
maxbogue 2016/12/02 23:59:27 Removing the whole comment.
59 // it serves and communicates to via the SyncFrontend interface (on 58 // communicates to via the SyncEngineHost interface (on the same thread it
60 // the same thread it used to call the constructor). Must outlive 59 // used to
61 // |sync_prefs|. 60 // call the constructor). Must outlive |sync_prefs|.
62 SyncBackendHostImpl( 61 SyncBackendHostImpl(
63 const std::string& name, 62 const std::string& name,
64 SyncClient* sync_client, 63 SyncClient* sync_client,
65 invalidation::InvalidationService* invalidator, 64 invalidation::InvalidationService* invalidator,
66 const base::WeakPtr<SyncPrefs>& sync_prefs, 65 const base::WeakPtr<SyncPrefs>& sync_prefs,
67 const base::FilePath& sync_folder); 66 const base::FilePath& sync_folder);
68 ~SyncBackendHostImpl() override; 67 ~SyncBackendHostImpl() override;
69 68
70 // SyncBackendHost implementation. 69 // SyncEngine implementation.
71 void Initialize( 70 void Initialize(
skym 2016/12/02 20:54:54 I'm still a bit confused why exactly the second st
maxbogue 2016/12/02 23:59:27 I dunno about before but now it's important becaus
72 SyncFrontend* frontend, 71 SyncEngineHost* host,
73 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner, 72 scoped_refptr<base::SingleThreadTaskRunner> sync_task_runner,
74 const WeakHandle<JsEventHandler>& event_handler, 73 const WeakHandle<JsEventHandler>& event_handler,
75 const GURL& service_url, 74 const GURL& service_url,
76 const std::string& sync_user_agent, 75 const std::string& sync_user_agent,
77 const SyncCredentials& credentials, 76 const SyncCredentials& credentials,
78 bool delete_sync_data_folder, 77 bool delete_sync_data_folder,
79 bool enable_local_sync_backend, 78 bool enable_local_sync_backend,
80 const base::FilePath& local_sync_backend_folder, 79 const base::FilePath& local_sync_backend_folder,
81 std::unique_ptr<SyncManagerFactory> sync_manager_factory, 80 std::unique_ptr<SyncManagerFactory> sync_manager_factory,
82 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, 81 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // manager initialization to be passed back to the UI thread. 162 // manager initialization to be passed back to the UI thread.
164 // 163 //
165 // |model_type_connector| is our ModelTypeConnector, which is owned because in 164 // |model_type_connector| is our ModelTypeConnector, which is owned because in
166 // production it is a proxy object to the real ModelTypeConnector. 165 // production it is a proxy object to the real ModelTypeConnector.
167 virtual void HandleInitializationSuccessOnFrontendLoop( 166 virtual void HandleInitializationSuccessOnFrontendLoop(
168 const WeakHandle<JsBackend> js_backend, 167 const WeakHandle<JsBackend> js_backend,
169 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener, 168 const WeakHandle<DataTypeDebugInfoListener> debug_info_listener,
170 std::unique_ptr<ModelTypeConnector> model_type_connector, 169 std::unique_ptr<ModelTypeConnector> model_type_connector,
171 const std::string& cache_guid); 170 const std::string& cache_guid);
172 171
173 // Forwards a ProtocolEvent to the frontend. Will not be called unless a 172 // Forwards a ProtocolEvent to the host. Will not be called unless a call to
174 // call to SetForwardProtocolEvents() explicitly requested that we start 173 // SetForwardProtocolEvents() explicitly requested that we start forwarding
175 // forwarding these events. 174 // these events.
176 void HandleProtocolEventOnFrontendLoop(std::unique_ptr<ProtocolEvent> event); 175 void HandleProtocolEventOnFrontendLoop(std::unique_ptr<ProtocolEvent> event);
177 176
178 // Forwards a directory commit counter update to the frontend loop. Will not 177 // Forwards a directory commit counter update to the frontend loop. Will not
179 // be called unless a call to EnableDirectoryTypeDebugInfoForwarding() 178 // be called unless a call to EnableDirectoryTypeDebugInfoForwarding()
180 // explicitly requested that we start forwarding these events. 179 // explicitly requested that we start forwarding these events.
181 void HandleDirectoryCommitCountersUpdatedOnFrontendLoop( 180 void HandleDirectoryCommitCountersUpdatedOnFrontendLoop(
182 ModelType type, 181 ModelType type,
183 const CommitCounters& counters); 182 const CommitCounters& counters);
184 183
185 // Forwards a directory update counter update to the frontend loop. Will not 184 // Forwards a directory update counter update to the frontend loop. Will not
186 // be called unless a call to EnableDirectoryTypeDebugInfoForwarding() 185 // be called unless a call to EnableDirectoryTypeDebugInfoForwarding()
187 // explicitly requested that we start forwarding these events. 186 // explicitly requested that we start forwarding these events.
188 void HandleDirectoryUpdateCountersUpdatedOnFrontendLoop( 187 void HandleDirectoryUpdateCountersUpdatedOnFrontendLoop(
189 ModelType type, 188 ModelType type,
190 const UpdateCounters& counters); 189 const UpdateCounters& counters);
191 190
192 // Forwards a directory status counter update to the frontend loop. Will not 191 // Forwards a directory status counter update to the frontend loop. Will not
193 // be called unless a call to EnableDirectoryTypeDebugInfoForwarding() 192 // be called unless a call to EnableDirectoryTypeDebugInfoForwarding()
194 // explicitly requested that we start forwarding these events. 193 // explicitly requested that we start forwarding these events.
195 void HandleDirectoryStatusCountersUpdatedOnFrontendLoop( 194 void HandleDirectoryStatusCountersUpdatedOnFrontendLoop(
196 ModelType type, 195 ModelType type,
197 const StatusCounters& counters); 196 const StatusCounters& counters);
198 197
199 // Overwrites the kSyncInvalidationVersions preference with the most recent 198 // Overwrites the kSyncInvalidationVersions preference with the most recent
200 // set of invalidation versions for each type. 199 // set of invalidation versions for each type.
201 void UpdateInvalidationVersions( 200 void UpdateInvalidationVersions(
202 const std::map<ModelType, int64_t>& invalidation_versions); 201 const std::map<ModelType, int64_t>& invalidation_versions);
203 202
204 SyncFrontend* frontend() { return frontend_; } 203 SyncEngineHost* host() { return host_; }
205 204
206 private: 205 private:
207 friend class SyncBackendHostCore; 206 friend class SyncBackendHostCore;
208 207
209 // Checks if we have received a notice to turn on experimental datatypes 208 // Checks if we have received a notice to turn on experimental datatypes
210 // (via the nigori node) and informs the frontend if that is the case. 209 // (via the nigori node) and informs the frontend if that is the case.
211 // Note: it is illegal to call this before the backend is initialized. 210 // Note: it is illegal to call this before the backend is initialized.
212 void AddExperimentalTypes(); 211 void AddExperimentalTypes();
213 212
214 // Handles backend initialization failure. 213 // Handles backend initialization failure.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 296
298 // Our core, which communicates directly to the syncapi. Use refptr instead 297 // Our core, which communicates directly to the syncapi. Use refptr instead
299 // of WeakHandle because |core_| is created on UI loop but released on 298 // of WeakHandle because |core_| is created on UI loop but released on
300 // sync loop. 299 // sync loop.
301 scoped_refptr<SyncBackendHostCore> core_; 300 scoped_refptr<SyncBackendHostCore> core_;
302 301
303 // A handle referencing the main interface for non-blocking sync types. This 302 // A handle referencing the main interface for non-blocking sync types. This
304 // object is owned because in production code it is a proxy object. 303 // object is owned because in production code it is a proxy object.
305 std::unique_ptr<ModelTypeConnector> model_type_connector_; 304 std::unique_ptr<ModelTypeConnector> model_type_connector_;
306 305
307 bool initialized_; 306 bool initialized_ = false;
308 307
309 const base::WeakPtr<SyncPrefs> sync_prefs_; 308 const base::WeakPtr<SyncPrefs> sync_prefs_;
310 309
311 std::unique_ptr<SyncBackendRegistrar> registrar_; 310 std::unique_ptr<SyncBackendRegistrar> registrar_;
312 311
313 // The frontend which we serve (and are owned by). 312 // The host which we serve (and are owned by).
skym 2016/12/02 20:54:54 Might be a good place to comment about the lifecyc
maxbogue 2016/12/02 23:59:27 Done.
314 SyncFrontend* frontend_; 313 SyncEngineHost* host_ = nullptr;
315 314
316 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired 315 // We cache the cryptographer's pending keys whenever NotifyPassphraseRequired
317 // is called. This way, before the UI calls SetDecryptionPassphrase on the 316 // is called. This way, before the UI calls SetDecryptionPassphrase on the
318 // syncer, it can avoid the overhead of an asynchronous decryption call and 317 // syncer, it can avoid the overhead of an asynchronous decryption call and
319 // give the user immediate feedback about the passphrase entered by first 318 // give the user immediate feedback about the passphrase entered by first
320 // trying to decrypt the cached pending keys on the UI thread. Note that 319 // trying to decrypt the cached pending keys on the UI thread. Note that
321 // SetDecryptionPassphrase can still fail after the cached pending keys are 320 // SetDecryptionPassphrase can still fail after the cached pending keys are
322 // successfully decrypted if the pending keys have changed since the time they 321 // successfully decrypted if the pending keys have changed since the time they
323 // were cached. 322 // were cached.
324 sync_pb::EncryptedData cached_pending_keys_; 323 sync_pb::EncryptedData cached_pending_keys_;
325 324
326 // The state of the passphrase required to decrypt the bag of encryption keys 325 // The state of the passphrase required to decrypt the bag of encryption keys
327 // in the nigori node. Updated whenever a new nigori node arrives or the user 326 // in the nigori node. Updated whenever a new nigori node arrives or the user
328 // manually changes their passphrase state. Cached so we can synchronously 327 // manually changes their passphrase state. Cached so we can synchronously
329 // check it from the UI thread. 328 // check it from the UI thread.
330 PassphraseType cached_passphrase_type_; 329 PassphraseType cached_passphrase_type_ = PassphraseType::IMPLICIT_PASSPHRASE;
331 330
332 // If an explicit passphrase is in use, the time at which the passphrase was 331 // If an explicit passphrase is in use, the time at which the passphrase was
333 // first set (if available). 332 // first set (if available).
334 base::Time cached_explicit_passphrase_time_; 333 base::Time cached_explicit_passphrase_time_;
335 334
336 // UI-thread cache of the last SyncCycleSnapshot received from syncapi. 335 // UI-thread cache of the last SyncCycleSnapshot received from syncapi.
337 SyncCycleSnapshot last_snapshot_; 336 SyncCycleSnapshot last_snapshot_;
338 337
339 invalidation::InvalidationService* invalidator_; 338 invalidation::InvalidationService* invalidator_;
340 bool invalidation_handler_registered_; 339 bool invalidation_handler_registered_ = false;
341 340
342 // Checks that we're on the same thread this was constructed on (UI thread). 341 // Checks that we're on the same thread this was constructed on (UI thread).
343 base::ThreadChecker thread_checker_; 342 base::ThreadChecker thread_checker_;
344 343
345 base::WeakPtrFactory<SyncBackendHostImpl> weak_ptr_factory_; 344 base::WeakPtrFactory<SyncBackendHostImpl> weak_ptr_factory_;
346 345
347 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostImpl); 346 DISALLOW_COPY_AND_ASSIGN(SyncBackendHostImpl);
348 }; 347 };
349 348
350 } // namespace syncer 349 } // namespace syncer
351 350
352 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_ 351 #endif // COMPONENTS_SYNC_DRIVER_GLUE_SYNC_BACKEND_HOST_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698