OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "chrome/browser/invalidation/invalidation_service.h" | 17 #include "chrome/browser/invalidation/invalidation_service.h" |
18 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" | 18 #include "chrome/browser/sync/glue/backend_data_type_configurer.h" |
19 #include "chrome/browser/sync/glue/extensions_activity_monitor.h" | 19 #include "chrome/browser/sync/glue/extensions_activity_monitor.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
22 #include "google_apis/gaia/google_service_auth_error.h" | 22 #include "google_apis/gaia/google_service_auth_error.h" |
23 #include "sync/internal_api/public/base/cancelation_signal.h" | |
23 #include "sync/internal_api/public/base/model_type.h" | 24 #include "sync/internal_api/public/base/model_type.h" |
24 #include "sync/internal_api/public/configure_reason.h" | 25 #include "sync/internal_api/public/configure_reason.h" |
25 #include "sync/internal_api/public/engine/model_safe_worker.h" | 26 #include "sync/internal_api/public/engine/model_safe_worker.h" |
26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 27 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
27 #include "sync/internal_api/public/sync_encryption_handler.h" | 28 #include "sync/internal_api/public/sync_encryption_handler.h" |
28 #include "sync/internal_api/public/sync_manager.h" | 29 #include "sync/internal_api/public/sync_manager.h" |
29 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" | 30 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" |
30 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 31 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
31 #include "sync/internal_api/public/util/weak_handle.h" | 32 #include "sync/internal_api/public/util/weak_handle.h" |
32 #include "sync/notifier/invalidation_handler.h" | 33 #include "sync/notifier/invalidation_handler.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 | 212 |
212 // Called on |frontend_loop_| to use the provided passphrase to asynchronously | 213 // Called on |frontend_loop_| to use the provided passphrase to asynchronously |
213 // attempt decryption. Returns false immediately if the passphrase could not | 214 // attempt decryption. Returns false immediately if the passphrase could not |
214 // be used to decrypt a locally cached copy of encrypted keys; returns true | 215 // be used to decrypt a locally cached copy of encrypted keys; returns true |
215 // otherwise. If new encrypted keys arrive during the asynchronous call, | 216 // otherwise. If new encrypted keys arrive during the asynchronous call, |
216 // OnPassphraseRequired may be triggered at a later time. It is an error to | 217 // OnPassphraseRequired may be triggered at a later time. It is an error to |
217 // call this when there are no pending keys. | 218 // call this when there are no pending keys. |
218 bool SetDecryptionPassphrase(const std::string& passphrase) | 219 bool SetDecryptionPassphrase(const std::string& passphrase) |
219 WARN_UNUSED_RESULT; | 220 WARN_UNUSED_RESULT; |
220 | 221 |
221 // Called on |frontend_loop_| to kick off shutdown procedure. After this, no | 222 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut |
222 // further sync activity will occur with the sync server and no further | 223 // short any long-lived or blocking sync thread tasks so that the shutdown on |
223 // change applications will occur from changes already downloaded. | 224 // sync thread task that we're about to post won't have to wait very long. |
224 // Furthermore, no notifications will be sent to any invalidation handler. | |
225 virtual void StopSyncingForShutdown(); | 225 virtual void StopSyncingForShutdown(); |
226 | 226 |
227 // Called on |frontend_loop_| to kick off shutdown. | 227 // Called on |frontend_loop_| to kick off shutdown. |
228 // See the implementation and Core::DoShutdown for details. | 228 // See the implementation and Core::DoShutdown for details. |
229 // Must be called *after* StopSyncingForShutdown. Caller should claim sync | 229 // Must be called *after* StopSyncingForShutdown. Caller should claim sync |
230 // thread using STOP_AND_CLAIM_THREAD or DISABLE_AND_CLAIM_THREAD if sync | 230 // thread using STOP_AND_CLAIM_THREAD or DISABLE_AND_CLAIM_THREAD if sync |
231 // backend might be recreated later because otherwise: | 231 // backend might be recreated later because otherwise: |
232 // * sync loop may be stopped on main loop and cause it to be blocked. | 232 // * sync loop may be stopped on main loop and cause it to be blocked. |
233 // * new/old backend may interfere with each other if new backend is created | 233 // * new/old backend may interfere with each other if new backend is created |
234 // before old one finishes cleanup. | 234 // before old one finishes cleanup. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 | 306 |
307 base::MessageLoop* GetSyncLoopForTesting(); | 307 base::MessageLoop* GetSyncLoopForTesting(); |
308 | 308 |
309 protected: | 309 protected: |
310 // The types and functions below are protected so that test | 310 // The types and functions below are protected so that test |
311 // subclasses can use them. | 311 // subclasses can use them. |
312 // | 312 // |
313 // TODO(akalin): Figure out a better way for tests to hook into | 313 // TODO(akalin): Figure out a better way for tests to hook into |
314 // SyncBackendHost. | 314 // SyncBackendHost. |
315 | 315 |
316 typedef base::Callback<scoped_ptr<syncer::HttpPostProviderFactory>(void)> | |
317 MakeHttpBridgeFactoryFn; | |
318 | |
319 // Utility struct for holding initialization options. | 316 // Utility struct for holding initialization options. |
320 struct DoInitializeOptions { | 317 struct DoInitializeOptions { |
321 DoInitializeOptions( | 318 DoInitializeOptions( |
322 base::MessageLoop* sync_loop, | 319 base::MessageLoop* sync_loop, |
323 SyncBackendRegistrar* registrar, | 320 SyncBackendRegistrar* registrar, |
324 const syncer::ModelSafeRoutingInfo& routing_info, | 321 const syncer::ModelSafeRoutingInfo& routing_info, |
325 const std::vector<syncer::ModelSafeWorker*>& workers, | 322 const std::vector<syncer::ModelSafeWorker*>& workers, |
326 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, | 323 const scoped_refptr<syncer::ExtensionsActivity>& extensions_activity, |
327 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, | 324 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, |
328 const GURL& service_url, | 325 const GURL& service_url, |
329 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, | 326 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory, |
330 const syncer::SyncCredentials& credentials, | 327 const syncer::SyncCredentials& credentials, |
331 const std::string& invalidator_client_id, | 328 const std::string& invalidator_client_id, |
332 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 329 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
333 bool delete_sync_data_folder, | 330 bool delete_sync_data_folder, |
334 const std::string& restored_key_for_bootstrapping, | 331 const std::string& restored_key_for_bootstrapping, |
335 const std::string& restored_keystore_key_for_bootstrapping, | 332 const std::string& restored_keystore_key_for_bootstrapping, |
336 scoped_ptr<syncer::InternalComponentsFactory> | 333 scoped_ptr<syncer::InternalComponentsFactory> |
337 internal_components_factory, | 334 internal_components_factory, |
338 scoped_ptr<syncer::UnrecoverableErrorHandler> | 335 scoped_ptr<syncer::UnrecoverableErrorHandler> |
339 unrecoverable_error_handler, | 336 unrecoverable_error_handler, |
340 syncer::ReportUnrecoverableErrorFunction | 337 syncer::ReportUnrecoverableErrorFunction |
341 report_unrecoverable_error_function, | 338 report_unrecoverable_error_function, |
342 bool use_oauth2_token); | 339 bool use_oauth2_token, |
340 syncer::CancelationSignal* scm_cancelation_signal); | |
343 ~DoInitializeOptions(); | 341 ~DoInitializeOptions(); |
344 | 342 |
345 base::MessageLoop* sync_loop; | 343 base::MessageLoop* sync_loop; |
346 SyncBackendRegistrar* registrar; | 344 SyncBackendRegistrar* registrar; |
347 syncer::ModelSafeRoutingInfo routing_info; | 345 syncer::ModelSafeRoutingInfo routing_info; |
348 std::vector<syncer::ModelSafeWorker*> workers; | 346 std::vector<syncer::ModelSafeWorker*> workers; |
349 scoped_refptr<syncer::ExtensionsActivity> extensions_activity; | 347 scoped_refptr<syncer::ExtensionsActivity> extensions_activity; |
350 syncer::WeakHandle<syncer::JsEventHandler> event_handler; | 348 syncer::WeakHandle<syncer::JsEventHandler> event_handler; |
351 GURL service_url; | 349 GURL service_url; |
352 // Overridden by tests. | 350 // Overridden by tests. |
353 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; | 351 scoped_ptr<syncer::HttpPostProviderFactory> http_bridge_factory; |
354 syncer::SyncCredentials credentials; | 352 syncer::SyncCredentials credentials; |
355 const std::string invalidator_client_id; | 353 const std::string invalidator_client_id; |
356 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory; | 354 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory; |
357 std::string lsid; | 355 std::string lsid; |
358 bool delete_sync_data_folder; | 356 bool delete_sync_data_folder; |
359 std::string restored_key_for_bootstrapping; | 357 std::string restored_key_for_bootstrapping; |
360 std::string restored_keystore_key_for_bootstrapping; | 358 std::string restored_keystore_key_for_bootstrapping; |
361 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory; | 359 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory; |
362 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler; | 360 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler; |
363 syncer::ReportUnrecoverableErrorFunction | 361 syncer::ReportUnrecoverableErrorFunction |
364 report_unrecoverable_error_function; | 362 report_unrecoverable_error_function; |
365 bool use_oauth2_token; | 363 bool use_oauth2_token; |
364 syncer::CancelationSignal* const scm_cancelation_signal; | |
366 }; | 365 }; |
367 | 366 |
368 // Allows tests to perform alternate core initialization work. | 367 // Allows tests to perform alternate core initialization work. |
369 virtual void InitCore(scoped_ptr<DoInitializeOptions> options); | 368 virtual void InitCore(scoped_ptr<DoInitializeOptions> options); |
370 | 369 |
371 // Request the syncer to reconfigure with the specfied params. | 370 // Request the syncer to reconfigure with the specfied params. |
372 // Virtual for testing. | 371 // Virtual for testing. |
373 virtual void RequestConfigureSyncer( | 372 virtual void RequestConfigureSyncer( |
374 syncer::ConfigureReason reason, | 373 syncer::ConfigureReason reason, |
375 syncer::ModelTypeSet to_download, | 374 syncer::ModelTypeSet to_download, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 int type, | 515 int type, |
517 const content::NotificationSource& source, | 516 const content::NotificationSource& source, |
518 const content::NotificationDetails& details) OVERRIDE; | 517 const content::NotificationDetails& details) OVERRIDE; |
519 | 518 |
520 // InvalidationHandler implementation. | 519 // InvalidationHandler implementation. |
521 virtual void OnInvalidatorStateChange( | 520 virtual void OnInvalidatorStateChange( |
522 syncer::InvalidatorState state) OVERRIDE; | 521 syncer::InvalidatorState state) OVERRIDE; |
523 virtual void OnIncomingInvalidation( | 522 virtual void OnIncomingInvalidation( |
524 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 523 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
525 | 524 |
526 // Handles stopping the core's SyncManager, accounting for whether | |
527 // initialization is done yet. | |
528 void StopSyncManagerForShutdown(); | |
529 | |
530 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; | 525 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; |
531 | 526 |
532 content::NotificationRegistrar notification_registrar_; | 527 content::NotificationRegistrar notification_registrar_; |
533 | 528 |
534 // A reference to the MessageLoop used to construct |this|, so we know how | 529 // A reference to the MessageLoop used to construct |this|, so we know how |
535 // to safely talk back to the SyncFrontend. | 530 // to safely talk back to the SyncFrontend. |
536 base::MessageLoop* const frontend_loop_; | 531 base::MessageLoop* const frontend_loop_; |
537 | 532 |
538 Profile* const profile_; | 533 Profile* const profile_; |
539 | 534 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
582 // Temporary holder of sync manager's initialization results. Set by | 577 // Temporary holder of sync manager's initialization results. Set by |
583 // HandleSyncManagerInitializationOnFrontendLoop, and consumed when we pass | 578 // HandleSyncManagerInitializationOnFrontendLoop, and consumed when we pass |
584 // it via OnBackendInitialized in the final state of | 579 // it via OnBackendInitialized in the final state of |
585 // HandleInitializationCompletedOnFrontendLoop. | 580 // HandleInitializationCompletedOnFrontendLoop. |
586 syncer::WeakHandle<syncer::JsBackend> js_backend_; | 581 syncer::WeakHandle<syncer::JsBackend> js_backend_; |
587 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; | 582 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; |
588 | 583 |
589 invalidation::InvalidationService* invalidator_; | 584 invalidation::InvalidationService* invalidator_; |
590 bool invalidation_handler_registered_; | 585 bool invalidation_handler_registered_; |
591 | 586 |
587 // These signals are (mostly) owned by the UI thread. They allow us to send | |
588 // requests to shut down the HttpBridgeFactory and ServerConnectionManager | |
589 // without having to wait for those classes to finish initializing first. | |
590 // | |
591 // See comments in StopSyncingForShutdown() and Shutdown() for more details. | |
592 scoped_ptr<syncer::CancelationSignal> factory_cancelation_signal_; | |
haitaol1
2013/09/13 18:43:21
Maybe move these into SyncBackendRegistrar, which
rlarocque
2013/09/13 20:27:17
That should work. However, there is a comment tha
| |
593 scoped_ptr<syncer::CancelationSignal> scm_cancelation_signal_; | |
594 | |
592 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 595 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
593 }; | 596 }; |
594 | 597 |
595 } // namespace browser_sync | 598 } // namespace browser_sync |
596 | 599 |
597 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 600 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
OLD | NEW |