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

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

Issue 11043012: [Sync] Notify invalidation handlers when sync is disabled/enabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 2 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 signin_(signin_manager), 138 signin_(signin_manager),
139 unrecoverable_error_reason_(ERROR_REASON_UNSET), 139 unrecoverable_error_reason_(ERROR_REASON_UNSET),
140 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 140 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
141 expect_sync_configuration_aborted_(false), 141 expect_sync_configuration_aborted_(false),
142 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 142 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
143 encrypt_everything_(false), 143 encrypt_everything_(false),
144 encryption_pending_(false), 144 encryption_pending_(false),
145 auto_start_enabled_(start_behavior == AUTO_START), 145 auto_start_enabled_(start_behavior == AUTO_START),
146 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 146 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
147 configure_status_(DataTypeManager::UNKNOWN), 147 configure_status_(DataTypeManager::UNKNOWN),
148 setup_in_progress_(false) { 148 setup_in_progress_(false),
149 invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR) {
149 #if defined(OS_ANDROID) 150 #if defined(OS_ANDROID)
150 chrome::VersionInfo version_info; 151 chrome::VersionInfo version_info;
151 if (version_info.IsOfficialBuild()) { 152 if (version_info.IsOfficialBuild()) {
152 sync_service_url_ = GURL(kSyncServerUrl); 153 sync_service_url_ = GURL(kSyncServerUrl);
153 } 154 }
154 #else 155 #else
155 // By default, dev, canary, and unbranded Chromium users will go to the 156 // By default, dev, canary, and unbranded Chromium users will go to the
156 // development servers. Development servers have more features than standard 157 // development servers. Development servers have more features than standard
157 // sync servers. Users with officially-branded Chrome stable and beta builds 158 // sync servers. Users with officially-branded Chrome stable and beta builds
158 // will go to the standard sync servers. 159 // will go to the standard sync servers.
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 548 }
548 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 549 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
549 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 550 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
550 551
551 weak_factory_.InvalidateWeakPtrs(); 552 weak_factory_.InvalidateWeakPtrs();
552 553
553 // Clear various flags. 554 // Clear various flags.
554 expect_sync_configuration_aborted_ = false; 555 expect_sync_configuration_aborted_ = false;
555 is_auth_in_progress_ = false; 556 is_auth_in_progress_ = false;
556 backend_initialized_ = false; 557 backend_initialized_ = false;
558 // NULL if we're called from Shutdown().
559 if (invalidator_registrar_.get())
560 UpdateInvalidatorRegistrarState();
557 cached_passphrase_.clear(); 561 cached_passphrase_.clear();
558 encryption_pending_ = false; 562 encryption_pending_ = false;
559 encrypt_everything_ = false; 563 encrypt_everything_ = false;
560 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); 564 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes();
561 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; 565 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED;
562 last_auth_error_ = AuthError::None(); 566 last_auth_error_ = AuthError::None();
563 567
564 if (sync_global_error_.get()) { 568 if (sync_global_error_.get()) {
565 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( 569 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
566 sync_global_error_.get()); 570 sync_global_error_.get());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 failed_datatypes_handler_.UpdateFailedDatatypes(errors, 694 failed_datatypes_handler_.UpdateFailedDatatypes(errors,
691 FailedDatatypesHandler::RUNTIME); 695 FailedDatatypesHandler::RUNTIME);
692 696
693 MessageLoop::current()->PostTask(FROM_HERE, 697 MessageLoop::current()->PostTask(FROM_HERE,
694 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 698 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
695 weak_factory_.GetWeakPtr())); 699 weak_factory_.GetWeakPtr()));
696 } 700 }
697 701
698 void ProfileSyncService::OnInvalidatorStateChange( 702 void ProfileSyncService::OnInvalidatorStateChange(
699 syncer::InvalidatorState state) { 703 syncer::InvalidatorState state) {
700 invalidator_registrar_->UpdateInvalidatorState(state); 704 invalidator_state_ = state;
705 UpdateInvalidatorRegistrarState();
701 } 706 }
702 707
703 void ProfileSyncService::OnIncomingInvalidation( 708 void ProfileSyncService::OnIncomingInvalidation(
704 const syncer::ObjectIdInvalidationMap& invalidation_map, 709 const syncer::ObjectIdInvalidationMap& invalidation_map,
705 syncer::IncomingInvalidationSource source) { 710 syncer::IncomingInvalidationSource source) {
706 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map, 711 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map,
707 source); 712 source);
708 } 713 }
709 714
710 void ProfileSyncService::OnBackendInitialized( 715 void ProfileSyncService::OnBackendInitialized(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 // we get here, we will have already tried and failed to delete the 747 // we get here, we will have already tried and failed to delete the
743 // directory. It would be no big deal if we tried to delete it again. 748 // directory. It would be no big deal if we tried to delete it again.
744 OnInternalUnrecoverableError(FROM_HERE, 749 OnInternalUnrecoverableError(FROM_HERE,
745 "BackendInitialize failure", 750 "BackendInitialize failure",
746 false, 751 false,
747 ERROR_REASON_BACKEND_INIT_FAILURE); 752 ERROR_REASON_BACKEND_INIT_FAILURE);
748 return; 753 return;
749 } 754 }
750 755
751 backend_initialized_ = true; 756 backend_initialized_ = true;
757 UpdateInvalidatorRegistrarState();
752 758
753 sync_js_controller_.AttachJsBackend(js_backend); 759 sync_js_controller_.AttachJsBackend(js_backend);
754 760
755 // If we have a cached passphrase use it to decrypt/encrypt data now that the 761 // If we have a cached passphrase use it to decrypt/encrypt data now that the
756 // backend is initialized. We want to call this before notifying observers in 762 // backend is initialized. We want to call this before notifying observers in
757 // case this operation affects the "passphrase required" status. 763 // case this operation affects the "passphrase required" status.
758 ConsumeCachedPassphraseIfPossible(); 764 ConsumeCachedPassphraseIfPossible();
759 765
760 // The very first time the backend initializes is effectively the first time 766 // The very first time the backend initializes is effectively the first time
761 // we can say we successfully "synced". last_synced_time_ will only be null 767 // we can say we successfully "synced". last_synced_time_ will only be null
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 void ProfileSyncService::OnInternalUnrecoverableError( 1827 void ProfileSyncService::OnInternalUnrecoverableError(
1822 const tracked_objects::Location& from_here, 1828 const tracked_objects::Location& from_here,
1823 const std::string& message, 1829 const std::string& message,
1824 bool delete_sync_database, 1830 bool delete_sync_database,
1825 UnrecoverableErrorReason reason) { 1831 UnrecoverableErrorReason reason) {
1826 DCHECK(!HasUnrecoverableError()); 1832 DCHECK(!HasUnrecoverableError());
1827 unrecoverable_error_reason_ = reason; 1833 unrecoverable_error_reason_ = reason;
1828 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); 1834 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database);
1829 } 1835 }
1830 1836
1837 void ProfileSyncService::UpdateInvalidatorRegistrarState() {
1838 const syncer::InvalidatorState effective_state =
1839 backend_initialized_ ?
1840 invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR;
1841 invalidator_registrar_->UpdateInvalidatorState(effective_state);
1842 }
1843
1831 void ProfileSyncService::ResetForTest() { 1844 void ProfileSyncService::ResetForTest() {
1832 Profile* profile = profile_; 1845 Profile* profile = profile_;
1833 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); 1846 SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
1834 ProfileSyncService::StartBehavior behavior = 1847 ProfileSyncService::StartBehavior behavior =
1835 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START 1848 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START
1836 : ProfileSyncService::MANUAL_START; 1849 : ProfileSyncService::MANUAL_START;
1837 1850
1838 // We call the destructor and placement new here because we want to explicitly 1851 // We call the destructor and placement new here because we want to explicitly
1839 // recreate a new ProfileSyncService instance at the same memory location as 1852 // recreate a new ProfileSyncService instance at the same memory location as
1840 // the old one. Doing so is fine because this code is run only from within 1853 // the old one. Doing so is fine because this code is run only from within
1841 // integration tests, and the message loop is not running at this point. 1854 // integration tests, and the message loop is not running at this point.
1842 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1855 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1843 ProfileSyncService* old_this = this; 1856 ProfileSyncService* old_this = this;
1844 this->~ProfileSyncService(); 1857 this->~ProfileSyncService();
1845 new(old_this) ProfileSyncService( 1858 new(old_this) ProfileSyncService(
1846 new ProfileSyncComponentsFactoryImpl(profile, 1859 new ProfileSyncComponentsFactoryImpl(profile,
1847 CommandLine::ForCurrentProcess()), 1860 CommandLine::ForCurrentProcess()),
1848 profile, 1861 profile,
1849 signin, 1862 signin,
1850 behavior); 1863 behavior);
1851 } 1864 }
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