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

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

Issue 11348220: sync: centralize sync startup decisions in TryStart. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: zea's review Created 8 years 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 263 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
264 if (!token_service) 264 if (!token_service)
265 return; 265 return;
266 // Don't start the backend if the token service hasn't finished loading tokens 266 // Don't start the backend if the token service hasn't finished loading tokens
267 // yet (if the backend is started before the sync token has been loaded, 267 // yet (if the backend is started before the sync token has been loaded,
268 // GetCredentials() will return bogus credentials). On auto_start platforms 268 // GetCredentials() will return bogus credentials). On auto_start platforms
269 // (like ChromeOS) we don't start sync until tokens are loaded, because the 269 // (like ChromeOS) we don't start sync until tokens are loaded, because the
270 // user can be "signed in" on those platforms long before the tokens get 270 // user can be "signed in" on those platforms long before the tokens get
271 // loaded, and we don't want to generate spurious auth errors. 271 // loaded, and we don't want to generate spurious auth errors.
272 if (IsSyncTokenAvailable() || 272 if (IsSyncTokenAvailable() ||
273 (!auto_start_enabled_ && token_service->TokensLoadedFromDB())) { 273 (!auto_start_enabled_ && token_service->TokensLoadedFromDB())) {
kochi 2012/11/30 07:42:02 How about reversing these conditions just for retu
tim (not reviewing) 2012/11/30 18:51:13 I had played around with this but all the negative
274 if (HasSyncSetupCompleted() || auto_start_enabled_) { 274 // Make sure it's safe to start -- the user has either declared intent (
Andrew T Wilson (Slow) 2012/11/30 14:52:15 A dangling parenthesis? YOU MONSTER
tim (not reviewing) 2012/11/30 18:51:13 Hah. Shame on me. Fixed.
275 // setup has either completed, or the user is in that process now and we
276 // should start the backend to download account control state / encryption
277 // information), or this is a platform where the intent to sync is implicit.
278 if (HasSyncSetupCompleted() || setup_in_progress_ || auto_start_enabled_) {
275 // If sync setup has completed we always start the backend. 279 // If sync setup has completed we always start the backend.
276 // If autostart is enabled, but we haven't completed sync setup, we try to 280 // If autostart is enabled, but we haven't completed sync setup, we try to
277 // start sync anyway, since it's possible we crashed/shutdown after 281 // start sync anyway, since it's possible we crashed/shutdown after
278 // logging in but before the backend finished initializing the last time. 282 // logging in but before the backend finished initializing the last time.
279 // Note that if we haven't finished setting up sync, backend bring up will 283 // Note that if we haven't finished setting up sync, backend bring up will
280 // be done by the wizard. 284 // be done by the wizard.
281 StartUp(); 285 StartUp();
282 } 286 }
283 } 287 }
284 } 288 }
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); 1713 DCHECK(encrypted_types_.Has(syncer::PASSWORDS));
1710 // We may be called during the setup process before we're 1714 // We may be called during the setup process before we're
1711 // initialized. In this case, we default to the sensitive types. 1715 // initialized. In this case, we default to the sensitive types.
1712 return encrypted_types_; 1716 return encrypted_types_;
1713 } 1717 }
1714 1718
1715 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 1719 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
1716 NotifyObservers(); 1720 NotifyObservers();
1717 if (is_sync_managed) { 1721 if (is_sync_managed) {
1718 DisableForUser(); 1722 DisableForUser();
1719 } else if (HasSyncSetupCompleted() && 1723 } else {
1720 IsSyncEnabledAndLoggedIn() &&
1721 IsSyncTokenAvailable()) {
1722 // Previously-configured sync has been re-enabled, so start sync now. 1724 // Previously-configured sync has been re-enabled, so start sync now.
Andrew T Wilson (Slow) 2012/11/30 14:52:15 Comment is now obsolete since we don't know that s
tim (not reviewing) 2012/11/30 18:51:13 Done.
1723 StartUp(); 1725 TryStart();
1724 } 1726 }
1725 } 1727 }
1726 1728
1727 void ProfileSyncService::Observe(int type, 1729 void ProfileSyncService::Observe(int type,
1728 const content::NotificationSource& source, 1730 const content::NotificationSource& source,
1729 const content::NotificationDetails& details) { 1731 const content::NotificationDetails& details) {
1730 switch (type) { 1732 switch (type) {
1731 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: { 1733 case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL: {
1732 const GoogleServiceSigninSuccessDetails* successful = 1734 const GoogleServiceSigninSuccessDetails* successful =
1733 content::Details<const GoogleServiceSigninSuccessDetails>( 1735 content::Details<const GoogleServiceSigninSuccessDetails>(
(...skipping 30 matching lines...) Expand all
1764 // from the sync backend. 1766 // from the sync backend.
1765 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS); 1767 AuthError error(AuthError::INVALID_GAIA_CREDENTIALS);
1766 UpdateAuthErrorState(error); 1768 UpdateAuthErrorState(error);
1767 } 1769 }
1768 break; 1770 break;
1769 } 1771 }
1770 case chrome::NOTIFICATION_TOKEN_AVAILABLE: { 1772 case chrome::NOTIFICATION_TOKEN_AVAILABLE: {
1771 const TokenService::TokenAvailableDetails& token_details = 1773 const TokenService::TokenAvailableDetails& token_details =
1772 *(content::Details<const TokenService::TokenAvailableDetails>( 1774 *(content::Details<const TokenService::TokenAvailableDetails>(
1773 details).ptr()); 1775 details).ptr());
1774 if (IsTokenServiceRelevant(token_details.service()) && 1776 if (!IsTokenServiceRelevant(token_details.service()))
1775 IsSyncEnabledAndLoggedIn() && 1777 break;
1776 IsSyncTokenAvailable()) { 1778 } // Fall through.
Andrew T Wilson (Slow) 2012/11/30 14:52:15 Falling through is fine, although the code is simp
tim (not reviewing) 2012/11/30 18:51:13 Done.
1777 if (backend_initialized_)
1778 backend_->UpdateCredentials(GetCredentials());
1779 else
1780 StartUp();
1781 }
1782 break;
1783 }
1784 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { 1779 case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: {
1785 // This notification gets fired when TokenService loads the tokens 1780 // This notification gets fired when TokenService loads the tokens
1786 // from storage. 1781 // from storage.
1787 if (IsSyncEnabledAndLoggedIn()) { 1782 // Initialize the backend if sync is enabled. If the sync token was
1788 // Don't start up sync and generate an auth error on auto_start 1783 // not loaded, GetCredentials() will generate invalid credentials to
1789 // platforms as they have their own way to resolve TokenService errors. 1784 // cause the backend to generate an auth error (crbug.com/121755).
1790 // (crbug.com/128592). 1785 if (backend_initialized_)
1791 if (auto_start_enabled_ && !IsSyncTokenAvailable()) 1786 backend_->UpdateCredentials(GetCredentials());
1792 break; 1787 else
1793 1788 TryStart();
1794 // Initialize the backend if sync is enabled. If the sync token was
1795 // not loaded, GetCredentials() will generate invalid credentials to
1796 // cause the backend to generate an auth error (crbug.com/121755).
1797 if (backend_initialized_)
1798 backend_->UpdateCredentials(GetCredentials());
1799 else
1800 StartUp();
1801 }
1802 break; 1789 break;
1803 } 1790 }
1804 default: { 1791 default: {
1805 NOTREACHED(); 1792 NOTREACHED();
1806 } 1793 }
1807 } 1794 }
1808 } 1795 }
1809 1796
1810 void ProfileSyncService::AddObserver(Observer* observer) { 1797 void ProfileSyncService::AddObserver(Observer* observer) {
1811 observers_.AddObserver(observer); 1798 observers_.AddObserver(observer);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1925 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1912 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1926 ProfileSyncService* old_this = this; 1913 ProfileSyncService* old_this = this;
1927 this->~ProfileSyncService(); 1914 this->~ProfileSyncService();
1928 new(old_this) ProfileSyncService( 1915 new(old_this) ProfileSyncService(
1929 new ProfileSyncComponentsFactoryImpl(profile, 1916 new ProfileSyncComponentsFactoryImpl(profile,
1930 CommandLine::ForCurrentProcess()), 1917 CommandLine::ForCurrentProcess()),
1931 profile, 1918 profile,
1932 signin, 1919 signin,
1933 behavior); 1920 behavior);
1934 } 1921 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698