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

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

Issue 10805002: [Sync] Enable adding notifier observers from ProfileSyncService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
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).
427 //
428 // TODO(akalin): Fix this horribly non-intuitive behavior (see
429 // http://crbug.com/140354).
430 if (backend_.get()) {
431 backend_->UpdateRegisteredInvalidationIds(all_registered_ids_);
432 }
433
425 if (!sync_global_error_.get()) { 434 if (!sync_global_error_.get()) {
426 #if !defined(OS_ANDROID) 435 #if !defined(OS_ANDROID)
427 sync_global_error_.reset(new SyncGlobalError(this, signin())); 436 sync_global_error_.reset(new SyncGlobalError(this, signin()));
428 #endif 437 #endif
429 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( 438 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
430 sync_global_error_.get()); 439 sync_global_error_.get());
431 AddObserver(sync_global_error_.get()); 440 AddObserver(sync_global_error_.get());
432 } 441 }
433 } 442 }
434 443
444 void ProfileSyncService::UpdateRegisteredInvalidationIds(
445 syncer::SyncNotifierObserver* handler,
446 const syncer::ObjectIdSet& ids) {
447 all_registered_ids_ = notifier_helper_.UpdateRegisteredIds(handler, ids);
448 // If |backend_| is NULL, its registered IDs will be updated when
449 // it's created and initialized.
450 if (backend_.get()) {
451 backend_->UpdateRegisteredInvalidationIds(all_registered_ids_);
452 }
453 }
454
435 void ProfileSyncService::Shutdown() { 455 void ProfileSyncService::Shutdown() {
436 ShutdownImpl(false); 456 ShutdownImpl(false);
437 } 457 }
438 458
439 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { 459 void ProfileSyncService::ShutdownImpl(bool sync_disabled) {
440 // 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
441 // 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
442 // 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
443 // ChangeProcessors, leading to back-from-the-dead bugs. 463 // ChangeProcessors, leading to back-from-the-dead bugs.
444 base::Time shutdown_start_time = base::Time::Now(); 464 base::Time shutdown_start_time = base::Time::Now();
445 if (backend_.get()) 465 if (backend_.get()) {
446 backend_->StopSyncingForShutdown(); 466 backend_->StopSyncingForShutdown();
467 backend_->UpdateRegisteredInvalidationIds(syncer::ObjectIdSet());
468 }
447 469
448 // Stop all data type controllers, if needed. Note that until Stop 470 // Stop all data type controllers, if needed. Note that until Stop
449 // 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
450 // 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
451 // 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)
452 // 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.
453 if (data_type_manager_.get()) { 475 if (data_type_manager_.get()) {
454 if (data_type_manager_->state() != DataTypeManager::STOPPED) { 476 if (data_type_manager_->state() != DataTypeManager::STOPPED) {
455 // 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
456 // configure result, else we'll dcheck when we try to read the sync error. 478 // 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
629 // Update this before posting a task. So if a configure happens before 651 // 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. 652 // the task that we are going to post, this type would still be disabled.
631 failed_datatypes_handler_.UpdateFailedDatatypes(errors, 653 failed_datatypes_handler_.UpdateFailedDatatypes(errors,
632 FailedDatatypesHandler::RUNTIME); 654 FailedDatatypesHandler::RUNTIME);
633 655
634 MessageLoop::current()->PostTask(FROM_HERE, 656 MessageLoop::current()->PostTask(FROM_HERE,
635 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 657 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
636 weak_factory_.GetWeakPtr())); 658 weak_factory_.GetWeakPtr()));
637 } 659 }
638 660
661 void ProfileSyncService::OnNotificationsEnabled() {
662 notifier_helper_.EmitOnNotificationsEnabled();
663 }
664
665 void ProfileSyncService::OnNotificationsDisabled(
666 syncer::NotificationsDisabledReason reason) {
667 notifier_helper_.EmitOnNotificationsDisabled(reason);
668 }
669
670 void ProfileSyncService::OnIncomingNotification(
671 const syncer::ObjectIdPayloadMap& id_payloads,
672 syncer::IncomingNotificationSource source) {
673 notifier_helper_.DispatchInvalidationsToHandlers(id_payloads, source);
674 }
675
639 void ProfileSyncService::OnBackendInitialized( 676 void ProfileSyncService::OnBackendInitialized(
640 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { 677 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) {
641 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 678 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
642 679
643 if (is_first_time_sync_configure_) { 680 if (is_first_time_sync_configure_) {
644 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 681 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
645 } else { 682 } else {
646 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 683 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
647 } 684 }
648 685
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1792 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1756 ProfileSyncService* old_this = this; 1793 ProfileSyncService* old_this = this;
1757 this->~ProfileSyncService(); 1794 this->~ProfileSyncService();
1758 new(old_this) ProfileSyncService( 1795 new(old_this) ProfileSyncService(
1759 new ProfileSyncComponentsFactoryImpl(profile, 1796 new ProfileSyncComponentsFactoryImpl(profile,
1760 CommandLine::ForCurrentProcess()), 1797 CommandLine::ForCurrentProcess()),
1761 profile, 1798 profile,
1762 signin, 1799 signin,
1763 behavior); 1800 behavior);
1764 } 1801 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698