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" | |
24 #include "sync/internal_api/public/base/model_type.h" | 23 #include "sync/internal_api/public/base/model_type.h" |
25 #include "sync/internal_api/public/configure_reason.h" | 24 #include "sync/internal_api/public/configure_reason.h" |
26 #include "sync/internal_api/public/engine/model_safe_worker.h" | 25 #include "sync/internal_api/public/engine/model_safe_worker.h" |
27 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" | 26 #include "sync/internal_api/public/sessions/sync_session_snapshot.h" |
28 #include "sync/internal_api/public/sync_encryption_handler.h" | 27 #include "sync/internal_api/public/sync_encryption_handler.h" |
29 #include "sync/internal_api/public/sync_manager.h" | 28 #include "sync/internal_api/public/sync_manager.h" |
30 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" | 29 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" |
31 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 30 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
32 #include "sync/internal_api/public/util/weak_handle.h" | 31 #include "sync/internal_api/public/util/weak_handle.h" |
33 #include "sync/notifier/invalidation_handler.h" | 32 #include "sync/notifier/invalidation_handler.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 211 |
213 // Called on |frontend_loop_| to use the provided passphrase to asynchronously | 212 // Called on |frontend_loop_| to use the provided passphrase to asynchronously |
214 // attempt decryption. Returns false immediately if the passphrase could not | 213 // attempt decryption. Returns false immediately if the passphrase could not |
215 // be used to decrypt a locally cached copy of encrypted keys; returns true | 214 // be used to decrypt a locally cached copy of encrypted keys; returns true |
216 // otherwise. If new encrypted keys arrive during the asynchronous call, | 215 // otherwise. If new encrypted keys arrive during the asynchronous call, |
217 // OnPassphraseRequired may be triggered at a later time. It is an error to | 216 // OnPassphraseRequired may be triggered at a later time. It is an error to |
218 // call this when there are no pending keys. | 217 // call this when there are no pending keys. |
219 bool SetDecryptionPassphrase(const std::string& passphrase) | 218 bool SetDecryptionPassphrase(const std::string& passphrase) |
220 WARN_UNUSED_RESULT; | 219 WARN_UNUSED_RESULT; |
221 | 220 |
222 // Called on |frontend_loop_| to kick off shutdown procedure. Attempts to cut | 221 // Called on |frontend_loop_| to kick off shutdown procedure. After this, no |
223 // short any long-lived or blocking sync thread tasks so that the shutdown on | 222 // further sync activity will occur with the sync server and no further |
224 // sync thread task that we're about to post won't have to wait very long. | 223 // change applications will occur from changes already downloaded. |
| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, | 332 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory, |
333 bool delete_sync_data_folder, | 333 bool delete_sync_data_folder, |
334 const std::string& restored_key_for_bootstrapping, | 334 const std::string& restored_key_for_bootstrapping, |
335 const std::string& restored_keystore_key_for_bootstrapping, | 335 const std::string& restored_keystore_key_for_bootstrapping, |
336 scoped_ptr<syncer::InternalComponentsFactory> | 336 scoped_ptr<syncer::InternalComponentsFactory> |
337 internal_components_factory, | 337 internal_components_factory, |
338 scoped_ptr<syncer::UnrecoverableErrorHandler> | 338 scoped_ptr<syncer::UnrecoverableErrorHandler> |
339 unrecoverable_error_handler, | 339 unrecoverable_error_handler, |
340 syncer::ReportUnrecoverableErrorFunction | 340 syncer::ReportUnrecoverableErrorFunction |
341 report_unrecoverable_error_function, | 341 report_unrecoverable_error_function, |
342 bool use_oauth2_token, | 342 bool use_oauth2_token); |
343 syncer::CancelationSignal* cancelation_signal); | |
344 ~DoInitializeOptions(); | 343 ~DoInitializeOptions(); |
345 | 344 |
346 base::MessageLoop* sync_loop; | 345 base::MessageLoop* sync_loop; |
347 SyncBackendRegistrar* registrar; | 346 SyncBackendRegistrar* registrar; |
348 syncer::ModelSafeRoutingInfo routing_info; | 347 syncer::ModelSafeRoutingInfo routing_info; |
349 std::vector<syncer::ModelSafeWorker*> workers; | 348 std::vector<syncer::ModelSafeWorker*> workers; |
350 scoped_refptr<syncer::ExtensionsActivity> extensions_activity; | 349 scoped_refptr<syncer::ExtensionsActivity> extensions_activity; |
351 syncer::WeakHandle<syncer::JsEventHandler> event_handler; | 350 syncer::WeakHandle<syncer::JsEventHandler> event_handler; |
352 GURL service_url; | 351 GURL service_url; |
353 // Overridden by tests. | 352 // Overridden by tests. |
354 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; | 353 MakeHttpBridgeFactoryFn make_http_bridge_factory_fn; |
355 syncer::SyncCredentials credentials; | 354 syncer::SyncCredentials credentials; |
356 const std::string invalidator_client_id; | 355 const std::string invalidator_client_id; |
357 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory; | 356 scoped_ptr<syncer::SyncManagerFactory> sync_manager_factory; |
358 std::string lsid; | 357 std::string lsid; |
359 bool delete_sync_data_folder; | 358 bool delete_sync_data_folder; |
360 std::string restored_key_for_bootstrapping; | 359 std::string restored_key_for_bootstrapping; |
361 std::string restored_keystore_key_for_bootstrapping; | 360 std::string restored_keystore_key_for_bootstrapping; |
362 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory; | 361 scoped_ptr<syncer::InternalComponentsFactory> internal_components_factory; |
363 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler; | 362 scoped_ptr<syncer::UnrecoverableErrorHandler> unrecoverable_error_handler; |
364 syncer::ReportUnrecoverableErrorFunction | 363 syncer::ReportUnrecoverableErrorFunction |
365 report_unrecoverable_error_function; | 364 report_unrecoverable_error_function; |
366 bool use_oauth2_token; | 365 bool use_oauth2_token; |
367 syncer::CancelationSignal* const cancelation_signal; | |
368 }; | 366 }; |
369 | 367 |
370 // Allows tests to perform alternate core initialization work. | 368 // Allows tests to perform alternate core initialization work. |
371 virtual void InitCore(scoped_ptr<DoInitializeOptions> options); | 369 virtual void InitCore(scoped_ptr<DoInitializeOptions> options); |
372 | 370 |
373 // Request the syncer to reconfigure with the specfied params. | 371 // Request the syncer to reconfigure with the specfied params. |
374 // Virtual for testing. | 372 // Virtual for testing. |
375 virtual void RequestConfigureSyncer( | 373 virtual void RequestConfigureSyncer( |
376 syncer::ConfigureReason reason, | 374 syncer::ConfigureReason reason, |
377 syncer::ModelTypeSet to_download, | 375 syncer::ModelTypeSet to_download, |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 int type, | 516 int type, |
519 const content::NotificationSource& source, | 517 const content::NotificationSource& source, |
520 const content::NotificationDetails& details) OVERRIDE; | 518 const content::NotificationDetails& details) OVERRIDE; |
521 | 519 |
522 // InvalidationHandler implementation. | 520 // InvalidationHandler implementation. |
523 virtual void OnInvalidatorStateChange( | 521 virtual void OnInvalidatorStateChange( |
524 syncer::InvalidatorState state) OVERRIDE; | 522 syncer::InvalidatorState state) OVERRIDE; |
525 virtual void OnIncomingInvalidation( | 523 virtual void OnIncomingInvalidation( |
526 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 524 const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
527 | 525 |
| 526 // Handles stopping the core's SyncManager, accounting for whether |
| 527 // initialization is done yet. |
| 528 void StopSyncManagerForShutdown(); |
| 529 |
528 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; | 530 base::WeakPtrFactory<SyncBackendHost> weak_ptr_factory_; |
529 | 531 |
530 content::NotificationRegistrar notification_registrar_; | 532 content::NotificationRegistrar notification_registrar_; |
531 | 533 |
532 // A reference to the MessageLoop used to construct |this|, so we know how | 534 // A reference to the MessageLoop used to construct |this|, so we know how |
533 // to safely talk back to the SyncFrontend. | 535 // to safely talk back to the SyncFrontend. |
534 base::MessageLoop* const frontend_loop_; | 536 base::MessageLoop* const frontend_loop_; |
535 | 537 |
536 Profile* const profile_; | 538 Profile* const profile_; |
537 | 539 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 // Temporary holder of sync manager's initialization results. Set by | 582 // Temporary holder of sync manager's initialization results. Set by |
581 // HandleSyncManagerInitializationOnFrontendLoop, and consumed when we pass | 583 // HandleSyncManagerInitializationOnFrontendLoop, and consumed when we pass |
582 // it via OnBackendInitialized in the final state of | 584 // it via OnBackendInitialized in the final state of |
583 // HandleInitializationCompletedOnFrontendLoop. | 585 // HandleInitializationCompletedOnFrontendLoop. |
584 syncer::WeakHandle<syncer::JsBackend> js_backend_; | 586 syncer::WeakHandle<syncer::JsBackend> js_backend_; |
585 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; | 587 syncer::WeakHandle<syncer::DataTypeDebugInfoListener> debug_info_listener_; |
586 | 588 |
587 invalidation::InvalidationService* invalidator_; | 589 invalidation::InvalidationService* invalidator_; |
588 bool invalidation_handler_registered_; | 590 bool invalidation_handler_registered_; |
589 | 591 |
590 syncer::CancelationSignal cancelation_signal_; | |
591 | |
592 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); | 592 DISALLOW_COPY_AND_ASSIGN(SyncBackendHost); |
593 }; | 593 }; |
594 | 594 |
595 } // namespace browser_sync | 595 } // namespace browser_sync |
596 | 596 |
597 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ | 597 #endif // CHROME_BROWSER_SYNC_GLUE_SYNC_BACKEND_HOST_H_ |
OLD | NEW |