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