diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 16:39:21 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-21 16:39:21 +0000 |
commit | 7d155e97457eae44d00863d3e47b926b4744f6e4 (patch) | |
tree | d54c53b594cc3da2ef1bebc7b6315b633d39b047 /chrome/browser/sync | |
parent | 985702c9fa95e190d46b2093d542f42e70296ddd (diff) | |
download | chromium_src-7d155e97457eae44d00863d3e47b926b4744f6e4.zip chromium_src-7d155e97457eae44d00863d3e47b926b4744f6e4.tar.gz chromium_src-7d155e97457eae44d00863d3e47b926b4744f6e4.tar.bz2 |
When a user logs into sync, the appropriate cookies are retrieved so that
she is already logged into Google web services, and does not need to enter
her username and password again.
This feature is on by default, but can be turned off by specifying
--disable-auto-login on the command line or the about:flags page.
BUG=None
TEST=Make sure the browser has no google or youtube cookies. Either clear
all the cookies or start with a brand new profile. Go to menu item
"Wrench / Options", go to the tab "Personal stuff", and click the "Enable
these features..." button to enable sync. Follow the wizard to login to your
google account and finish the sync process. Once terminated, browse to
gmail.com and you should be already logged in.
Review URL: http://codereview.chromium.org/7121014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89842 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r-- | chrome/browser/sync/signin_manager.cc | 42 | ||||
-rw-r--r-- | chrome/browser/sync/signin_manager.h | 14 |
2 files changed, 55 insertions, 1 deletions
diff --git a/chrome/browser/sync/signin_manager.cc b/chrome/browser/sync/signin_manager.cc index 1ec73e2..11f4bc1 100644 --- a/chrome/browser/sync/signin_manager.cc +++ b/chrome/browser/sync/signin_manager.cc @@ -4,12 +4,15 @@ #include "chrome/browser/sync/signin_manager.h" +#include "base/command_line.h" #include "base/string_util.h" #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service.h" #include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/pref_names.h" +#include "chrome/common/chrome_switches.h" #include "content/common/notification_service.h" const char kGetInfoEmailKey[] = "email"; @@ -69,6 +72,18 @@ void SigninManager::StartSignIn(const std::string& username, login_token, login_captcha, GaiaAuthFetcher::HostedAccountsNotAllowed); + + // Register for token availability. The signin manager will pre-login the + // user when the GAIA service token is ready for use. Only do this if we + // are not running in ChomiumOS, since it handles pre-login itself. +#if !defined(OS_CHROMEOS) + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kDisableAutoLogin)) { + registrar_.Add(this, + NotificationType::TOKEN_AVAILABLE, + NotificationService::AllSources()); + } +#endif } void SigninManager::ProvideSecondFactorAccessCode( @@ -161,3 +176,30 @@ void SigninManager::OnClientLoginFailure(const GoogleServiceAuthError& error) { SignOut(); } + +void SigninManager::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { +#if !defined(OS_CHROMEOS) + DCHECK(type == NotificationType::TOKEN_AVAILABLE); + TokenService::TokenAvailableDetails* tok_details = + Details<TokenService::TokenAvailableDetails>(details).ptr(); + + // If a GAIA service token has become available, use it to pre-login the + // user to other services that depend on GAIA credentials. + if (tok_details->service() == GaiaConstants::kGaiaService) { + if (client_login_.get() == NULL) { + client_login_.reset(new GaiaAuthFetcher(this, + GaiaConstants::kChromeSource, + profile_->GetRequestContext())); + } + + client_login_->StartTokenAuth(tok_details->token()); + + // We only want to do this once per sign-in. + registrar_.Remove(this, + NotificationType::TOKEN_AVAILABLE, + NotificationService::AllSources()); + } +#endif +} diff --git a/chrome/browser/sync/signin_manager.h b/chrome/browser/sync/signin_manager.h index 603c323..869b652 100644 --- a/chrome/browser/sync/signin_manager.h +++ b/chrome/browser/sync/signin_manager.h @@ -16,6 +16,8 @@ #include "base/memory/scoped_ptr.h" #include "chrome/common/net/gaia/gaia_auth_consumer.h" #include "chrome/common/net/gaia/google_service_auth_error.h" +#include "content/common/notification_observer.h" +#include "content/common/notification_registrar.h" class GaiaAuthFetcher; class Profile; @@ -33,7 +35,7 @@ struct GoogleServiceSigninSuccessDetails { std::string password; }; -class SigninManager : public GaiaAuthConsumer { +class SigninManager : public GaiaAuthConsumer , public NotificationObserver { public: SigninManager(); virtual ~SigninManager(); @@ -75,6 +77,11 @@ class SigninManager : public GaiaAuthConsumer { virtual void OnGetUserInfoKeyNotFound(const std::string& key); virtual void OnGetUserInfoFailure(const GoogleServiceAuthError& error); + // NotificationObserver + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) OVERRIDE; + private: Profile* profile_; std::string username_; @@ -87,6 +94,11 @@ class SigninManager : public GaiaAuthConsumer { // Actual client login handler. scoped_ptr<GaiaAuthFetcher> client_login_; + + // Register for notifications from the TokenService. + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(SigninManager); }; #endif // CHROME_BROWSER_SYNC_SIGNIN_MANAGER_H_ |