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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 UpdateInvalidatorState(); |
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 Loading... |
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 UpdateInvalidatorState(); |
701 } | 706 } |
702 | 707 |
703 void ProfileSyncService::OnIncomingInvalidation( | 708 void ProfileSyncService::OnIncomingInvalidation( |
704 const syncer::ObjectIdStateMap& id_state_map, | 709 const syncer::ObjectIdStateMap& id_state_map, |
705 syncer::IncomingInvalidationSource source) { | 710 syncer::IncomingInvalidationSource source) { |
706 invalidator_registrar_->DispatchInvalidationsToHandlers(id_state_map, source); | 711 invalidator_registrar_->DispatchInvalidationsToHandlers(id_state_map, source); |
707 } | 712 } |
708 | 713 |
709 void ProfileSyncService::OnBackendInitialized( | 714 void ProfileSyncService::OnBackendInitialized( |
710 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { | 715 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { |
(...skipping 30 matching lines...) Expand all Loading... |
741 // we get here, we will have already tried and failed to delete the | 746 // we get here, we will have already tried and failed to delete the |
742 // directory. It would be no big deal if we tried to delete it again. | 747 // directory. It would be no big deal if we tried to delete it again. |
743 OnInternalUnrecoverableError(FROM_HERE, | 748 OnInternalUnrecoverableError(FROM_HERE, |
744 "BackendInitialize failure", | 749 "BackendInitialize failure", |
745 false, | 750 false, |
746 ERROR_REASON_BACKEND_INIT_FAILURE); | 751 ERROR_REASON_BACKEND_INIT_FAILURE); |
747 return; | 752 return; |
748 } | 753 } |
749 | 754 |
750 backend_initialized_ = true; | 755 backend_initialized_ = true; |
| 756 UpdateInvalidatorState(); |
751 | 757 |
752 sync_js_controller_.AttachJsBackend(js_backend); | 758 sync_js_controller_.AttachJsBackend(js_backend); |
753 | 759 |
754 // If we have a cached passphrase use it to decrypt/encrypt data now that the | 760 // If we have a cached passphrase use it to decrypt/encrypt data now that the |
755 // backend is initialized. We want to call this before notifying observers in | 761 // backend is initialized. We want to call this before notifying observers in |
756 // case this operation affects the "passphrase required" status. | 762 // case this operation affects the "passphrase required" status. |
757 ConsumeCachedPassphraseIfPossible(); | 763 ConsumeCachedPassphraseIfPossible(); |
758 | 764 |
759 // The very first time the backend initializes is effectively the first time | 765 // The very first time the backend initializes is effectively the first time |
760 // we can say we successfully "synced". last_synced_time_ will only be null | 766 // 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 Loading... |
1820 void ProfileSyncService::OnInternalUnrecoverableError( | 1826 void ProfileSyncService::OnInternalUnrecoverableError( |
1821 const tracked_objects::Location& from_here, | 1827 const tracked_objects::Location& from_here, |
1822 const std::string& message, | 1828 const std::string& message, |
1823 bool delete_sync_database, | 1829 bool delete_sync_database, |
1824 UnrecoverableErrorReason reason) { | 1830 UnrecoverableErrorReason reason) { |
1825 DCHECK(!HasUnrecoverableError()); | 1831 DCHECK(!HasUnrecoverableError()); |
1826 unrecoverable_error_reason_ = reason; | 1832 unrecoverable_error_reason_ = reason; |
1827 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); | 1833 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); |
1828 } | 1834 } |
1829 | 1835 |
| 1836 void ProfileSyncService::UpdateInvalidatorState() { |
| 1837 const syncer::InvalidatorState effective_state = |
| 1838 backend_initialized_ ? |
| 1839 invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR; |
| 1840 invalidator_registrar_->UpdateInvalidatorState(effective_state); |
| 1841 } |
| 1842 |
1830 void ProfileSyncService::ResetForTest() { | 1843 void ProfileSyncService::ResetForTest() { |
1831 Profile* profile = profile_; | 1844 Profile* profile = profile_; |
1832 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); | 1845 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); |
1833 ProfileSyncService::StartBehavior behavior = | 1846 ProfileSyncService::StartBehavior behavior = |
1834 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START | 1847 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START |
1835 : ProfileSyncService::MANUAL_START; | 1848 : ProfileSyncService::MANUAL_START; |
1836 | 1849 |
1837 // We call the destructor and placement new here because we want to explicitly | 1850 // We call the destructor and placement new here because we want to explicitly |
1838 // recreate a new ProfileSyncService instance at the same memory location as | 1851 // recreate a new ProfileSyncService instance at the same memory location as |
1839 // the old one. Doing so is fine because this code is run only from within | 1852 // the old one. Doing so is fine because this code is run only from within |
1840 // integration tests, and the message loop is not running at this point. | 1853 // integration tests, and the message loop is not running at this point. |
1841 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. | 1854 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine
d-behaviour-after-directly-calling-the-destru. |
1842 ProfileSyncService* old_this = this; | 1855 ProfileSyncService* old_this = this; |
1843 this->~ProfileSyncService(); | 1856 this->~ProfileSyncService(); |
1844 new(old_this) ProfileSyncService( | 1857 new(old_this) ProfileSyncService( |
1845 new ProfileSyncComponentsFactoryImpl(profile, | 1858 new ProfileSyncComponentsFactoryImpl(profile, |
1846 CommandLine::ForCurrentProcess()), | 1859 CommandLine::ForCurrentProcess()), |
1847 profile, | 1860 profile, |
1848 signin, | 1861 signin, |
1849 behavior); | 1862 behavior); |
1850 } | 1863 } |
OLD | NEW |