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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 10824252: Revert 150990 - [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
OLDNEW
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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 425 // |backend_| may end up being NULL here in tests (in synchronous
426 // initialization mode). 426 // initialization mode).
427 // 427 //
428 // TODO(akalin): Fix this horribly non-intuitive behavior (see 428 // TODO(akalin): Fix this horribly non-intuitive behavior (see
429 // http://crbug.com/140354). 429 // http://crbug.com/140354).
430 if (backend_.get()) { 430 if (backend_.get()) {
431 backend_->UpdateRegisteredInvalidationIds( 431 backend_->UpdateRegisteredInvalidationIds(all_registered_ids_);
432 notifier_registrar_.GetAllRegisteredIds());
433 } 432 }
434 433
435 if (!sync_global_error_.get()) { 434 if (!sync_global_error_.get()) {
436 #if !defined(OS_ANDROID) 435 #if !defined(OS_ANDROID)
437 sync_global_error_.reset(new SyncGlobalError(this, signin())); 436 sync_global_error_.reset(new SyncGlobalError(this, signin()));
438 #endif 437 #endif
439 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( 438 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
440 sync_global_error_.get()); 439 sync_global_error_.get());
441 AddObserver(sync_global_error_.get()); 440 AddObserver(sync_global_error_.get());
442 } 441 }
443 } 442 }
444 443
445 void ProfileSyncService::RegisterInvalidationHandler(
446 syncer::SyncNotifierObserver* handler) {
447 notifier_registrar_.RegisterHandler(handler);
448 }
449
450 void ProfileSyncService::UpdateRegisteredInvalidationIds( 444 void ProfileSyncService::UpdateRegisteredInvalidationIds(
451 syncer::SyncNotifierObserver* handler, 445 syncer::SyncNotifierObserver* handler,
452 const syncer::ObjectIdSet& ids) { 446 const syncer::ObjectIdSet& ids) {
453 notifier_registrar_.UpdateRegisteredIds(handler, ids); 447 all_registered_ids_ = notifier_helper_.UpdateRegisteredIds(handler, ids);
454
455 // If |backend_| is NULL, its registered IDs will be updated when 448 // If |backend_| is NULL, its registered IDs will be updated when
456 // it's created and initialized. 449 // it's created and initialized.
457 if (backend_.get()) { 450 if (backend_.get()) {
458 backend_->UpdateRegisteredInvalidationIds( 451 backend_->UpdateRegisteredInvalidationIds(all_registered_ids_);
459 notifier_registrar_.GetAllRegisteredIds());
460 } 452 }
461 } 453 }
462 454
463 void ProfileSyncService::UnregisterInvalidationHandler(
464 syncer::SyncNotifierObserver* handler) {
465 notifier_registrar_.UnregisterHandler(handler);
466 }
467
468 void ProfileSyncService::Shutdown() { 455 void ProfileSyncService::Shutdown() {
469 ShutdownImpl(false); 456 ShutdownImpl(false);
470 } 457 }
471 458
472 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { 459 void ProfileSyncService::ShutdownImpl(bool sync_disabled) {
473 // First, we spin down the backend and wait for it to stop syncing completely 460 // First, we spin down the backend and wait for it to stop syncing completely
474 // before we Stop the data type manager. This is to avoid a late sync cycle 461 // before we Stop the data type manager. This is to avoid a late sync cycle
475 // applying changes to the sync db that wouldn't get applied via 462 // applying changes to the sync db that wouldn't get applied via
476 // ChangeProcessors, leading to back-from-the-dead bugs. 463 // ChangeProcessors, leading to back-from-the-dead bugs.
477 base::Time shutdown_start_time = base::Time::Now(); 464 base::Time shutdown_start_time = base::Time::Now();
478 if (backend_.get()) { 465 if (backend_.get()) {
479 backend_->StopSyncingForShutdown(); 466 backend_->StopSyncingForShutdown();
467 backend_->UpdateRegisteredInvalidationIds(syncer::ObjectIdSet());
480 } 468 }
481 469
482 // Stop all data type controllers, if needed. Note that until Stop 470 // Stop all data type controllers, if needed. Note that until Stop
483 // completes, it is possible in theory to have a ChangeProcessor apply a 471 // completes, it is possible in theory to have a ChangeProcessor apply a
484 // change from a native model. In that case, it will get applied to the sync 472 // change from a native model. In that case, it will get applied to the sync
485 // database (which doesn't get destroyed until we destroy the backend below) 473 // database (which doesn't get destroyed until we destroy the backend below)
486 // as an unsynced change. That will be persisted, and committed on restart. 474 // as an unsynced change. That will be persisted, and committed on restart.
487 if (data_type_manager_.get()) { 475 if (data_type_manager_.get()) {
488 if (data_type_manager_->state() != DataTypeManager::STOPPED) { 476 if (data_type_manager_->state() != DataTypeManager::STOPPED) {
489 // When aborting as part of shutdown, we should expect an aborted sync 477 // When aborting as part of shutdown, we should expect an aborted sync
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // the task that we are going to post, this type would still be disabled. 652 // the task that we are going to post, this type would still be disabled.
665 failed_datatypes_handler_.UpdateFailedDatatypes(errors, 653 failed_datatypes_handler_.UpdateFailedDatatypes(errors,
666 FailedDatatypesHandler::RUNTIME); 654 FailedDatatypesHandler::RUNTIME);
667 655
668 MessageLoop::current()->PostTask(FROM_HERE, 656 MessageLoop::current()->PostTask(FROM_HERE,
669 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 657 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
670 weak_factory_.GetWeakPtr())); 658 weak_factory_.GetWeakPtr()));
671 } 659 }
672 660
673 void ProfileSyncService::OnNotificationsEnabled() { 661 void ProfileSyncService::OnNotificationsEnabled() {
674 notifier_registrar_.EmitOnNotificationsEnabled(); 662 notifier_helper_.EmitOnNotificationsEnabled();
675 } 663 }
676 664
677 void ProfileSyncService::OnNotificationsDisabled( 665 void ProfileSyncService::OnNotificationsDisabled(
678 syncer::NotificationsDisabledReason reason) { 666 syncer::NotificationsDisabledReason reason) {
679 notifier_registrar_.EmitOnNotificationsDisabled(reason); 667 notifier_helper_.EmitOnNotificationsDisabled(reason);
680 } 668 }
681 669
682 void ProfileSyncService::OnIncomingNotification( 670 void ProfileSyncService::OnIncomingNotification(
683 const syncer::ObjectIdPayloadMap& id_payloads, 671 const syncer::ObjectIdPayloadMap& id_payloads,
684 syncer::IncomingNotificationSource source) { 672 syncer::IncomingNotificationSource source) {
685 notifier_registrar_.DispatchInvalidationsToHandlers(id_payloads, source); 673 notifier_helper_.DispatchInvalidationsToHandlers(id_payloads, source);
686 } 674 }
687 675
688 void ProfileSyncService::OnBackendInitialized( 676 void ProfileSyncService::OnBackendInitialized(
689 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { 677 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) {
690 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 678 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
691 679
692 if (is_first_time_sync_configure_) { 680 if (is_first_time_sync_configure_) {
693 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 681 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
694 } else { 682 } else {
695 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 683 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1811 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1799 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1812 ProfileSyncService* old_this = this; 1800 ProfileSyncService* old_this = this;
1813 this->~ProfileSyncService(); 1801 this->~ProfileSyncService();
1814 new(old_this) ProfileSyncService( 1802 new(old_this) ProfileSyncService(
1815 new ProfileSyncComponentsFactoryImpl(profile, 1803 new ProfileSyncComponentsFactoryImpl(profile,
1816 CommandLine::ForCurrentProcess()), 1804 CommandLine::ForCurrentProcess()),
1817 profile, 1805 profile,
1818 signin, 1806 signin,
1819 behavior); 1807 behavior);
1820 } 1808 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698