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 #include "chrome/browser/sync/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 sync_prefs_.GetSpareBootstrapToken()); | 415 sync_prefs_.GetSpareBootstrapToken()); |
416 } | 416 } |
417 #endif | 417 #endif |
418 CreateBackend(); | 418 CreateBackend(); |
419 | 419 |
420 // Initialize the backend. Every time we start up a new SyncBackendHost, | 420 // Initialize the backend. Every time we start up a new SyncBackendHost, |
421 // we'll want to start from a fresh SyncDB, so delete any old one that might | 421 // we'll want to start from a fresh SyncDB, so delete any old one that might |
422 // be there. | 422 // be there. |
423 InitializeBackend(!HasSyncSetupCompleted()); | 423 InitializeBackend(!HasSyncSetupCompleted()); |
424 | 424 |
425 // |backend_| may end up being NULL here in tests (in synchronous | |
426 // |initialization mode). | |
tim (not reviewing)
2012/08/01 21:52:52
What would it take to get rid of synchronous initi
akalin
2012/08/02 08:05:43
Actually, it might be easy now. I think I put tha
| |
427 // | |
428 // TODO(akalin): Fix this horribly non-intuitive behavior. | |
429 if (backend_.get()) { | |
430 backend_->UpdateRegisteredIds(all_registered_ids_); | |
431 } | |
432 | |
425 if (!sync_global_error_.get()) { | 433 if (!sync_global_error_.get()) { |
426 #if !defined(OS_ANDROID) | 434 #if !defined(OS_ANDROID) |
427 sync_global_error_.reset(new SyncGlobalError(this, signin())); | 435 sync_global_error_.reset(new SyncGlobalError(this, signin())); |
428 #endif | 436 #endif |
429 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | 437 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( |
430 sync_global_error_.get()); | 438 sync_global_error_.get()); |
431 AddObserver(sync_global_error_.get()); | 439 AddObserver(sync_global_error_.get()); |
432 } | 440 } |
433 } | 441 } |
434 | 442 |
443 void ProfileSyncService::UpdateRegisteredIds( | |
444 syncer::SyncNotifierObserver* handler, | |
445 const syncer::ObjectIdSet& ids) { | |
446 all_registered_ids_ = notifier_helper_.UpdateRegisteredIds(handler, ids); | |
447 // If |backend_| is NULL, its registered IDs will be updated when | |
448 // it's created and initialized. | |
449 if (backend_.get()) { | |
450 backend_->UpdateRegisteredIds(all_registered_ids_); | |
451 } | |
452 } | |
453 | |
435 void ProfileSyncService::Shutdown() { | 454 void ProfileSyncService::Shutdown() { |
436 ShutdownImpl(false); | 455 ShutdownImpl(false); |
437 } | 456 } |
438 | 457 |
439 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { | 458 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { |
440 // First, we spin down the backend and wait for it to stop syncing completely | 459 // First, we spin down the backend and wait for it to stop syncing completely |
441 // before we Stop the data type manager. This is to avoid a late sync cycle | 460 // before we Stop the data type manager. This is to avoid a late sync cycle |
442 // applying changes to the sync db that wouldn't get applied via | 461 // applying changes to the sync db that wouldn't get applied via |
443 // ChangeProcessors, leading to back-from-the-dead bugs. | 462 // ChangeProcessors, leading to back-from-the-dead bugs. |
444 base::Time shutdown_start_time = base::Time::Now(); | 463 base::Time shutdown_start_time = base::Time::Now(); |
445 if (backend_.get()) | 464 if (backend_.get()) { |
446 backend_->StopSyncingForShutdown(); | 465 backend_->StopSyncingForShutdown(); |
466 backend_->UpdateRegisteredIds(syncer::ObjectIdSet()); | |
467 } | |
447 | 468 |
448 // Stop all data type controllers, if needed. Note that until Stop | 469 // Stop all data type controllers, if needed. Note that until Stop |
449 // completes, it is possible in theory to have a ChangeProcessor apply a | 470 // completes, it is possible in theory to have a ChangeProcessor apply a |
450 // change from a native model. In that case, it will get applied to the sync | 471 // change from a native model. In that case, it will get applied to the sync |
451 // database (which doesn't get destroyed until we destroy the backend below) | 472 // database (which doesn't get destroyed until we destroy the backend below) |
452 // as an unsynced change. That will be persisted, and committed on restart. | 473 // as an unsynced change. That will be persisted, and committed on restart. |
453 if (data_type_manager_.get()) { | 474 if (data_type_manager_.get()) { |
454 if (data_type_manager_->state() != DataTypeManager::STOPPED) { | 475 if (data_type_manager_->state() != DataTypeManager::STOPPED) { |
455 // When aborting as part of shutdown, we should expect an aborted sync | 476 // When aborting as part of shutdown, we should expect an aborted sync |
456 // configure result, else we'll dcheck when we try to read the sync error. | 477 // configure result, else we'll dcheck when we try to read the sync error. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
629 // Update this before posting a task. So if a configure happens before | 650 // Update this before posting a task. So if a configure happens before |
630 // the task that we are going to post, this type would still be disabled. | 651 // the task that we are going to post, this type would still be disabled. |
631 failed_datatypes_handler_.UpdateFailedDatatypes(errors, | 652 failed_datatypes_handler_.UpdateFailedDatatypes(errors, |
632 FailedDatatypesHandler::RUNTIME); | 653 FailedDatatypesHandler::RUNTIME); |
633 | 654 |
634 MessageLoop::current()->PostTask(FROM_HERE, | 655 MessageLoop::current()->PostTask(FROM_HERE, |
635 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, | 656 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, |
636 weak_factory_.GetWeakPtr())); | 657 weak_factory_.GetWeakPtr())); |
637 } | 658 } |
638 | 659 |
660 void ProfileSyncService::OnNotificationsEnabled() { | |
661 notifier_helper_.EmitOnNotificationsEnabled(); | |
662 } | |
663 | |
664 void ProfileSyncService::OnNotificationsDisabled( | |
665 syncer::NotificationsDisabledReason reason) { | |
666 notifier_helper_.EmitOnNotificationsDisabled(reason); | |
667 } | |
668 | |
669 void ProfileSyncService::OnIncomingNotification( | |
670 const syncer::ObjectIdPayloadMap& id_payloads, | |
671 syncer::IncomingNotificationSource source) { | |
672 notifier_helper_.DispatchInvalidationsToHandlers(id_payloads, source); | |
673 } | |
674 | |
639 void ProfileSyncService::OnBackendInitialized( | 675 void ProfileSyncService::OnBackendInitialized( |
640 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { | 676 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { |
641 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); | 677 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); |
642 | 678 |
643 if (is_first_time_sync_configure_) { | 679 if (is_first_time_sync_configure_) { |
644 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); | 680 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); |
645 } else { | 681 } else { |
646 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); | 682 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); |
647 } | 683 } |
648 | 684 |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1755 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. | 1791 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. |
1756 ProfileSyncService* old_this = this; | 1792 ProfileSyncService* old_this = this; |
1757 this->~ProfileSyncService(); | 1793 this->~ProfileSyncService(); |
1758 new(old_this) ProfileSyncService( | 1794 new(old_this) ProfileSyncService( |
1759 new ProfileSyncComponentsFactoryImpl(profile, | 1795 new ProfileSyncComponentsFactoryImpl(profile, |
1760 CommandLine::ForCurrentProcess()), | 1796 CommandLine::ForCurrentProcess()), |
1761 profile, | 1797 profile, |
1762 signin, | 1798 signin, |
1763 behavior); | 1799 behavior); |
1764 } | 1800 } |
OLD | NEW |