summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r--chrome/browser/sync/signin_manager.cc42
-rw-r--r--chrome/browser/sync/signin_manager.h14
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_