summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 18:01:06 +0000
committernkostylev@chromium.org <nkostylev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 18:01:06 +0000
commitd4aaa95e6481e57663544b63109f73906c0e7d61 (patch)
tree5db47d0b96c2c7fc3786e4ce73ee3fc5f7ce2343
parent44392c6cce164e4b54df6a17fdf41a08ab55b7f1 (diff)
downloadchromium_src-d4aaa95e6481e57663544b63109f73906c0e7d61.zip
chromium_src-d4aaa95e6481e57663544b63109f73906c0e7d61.tar.gz
chromium_src-d4aaa95e6481e57663544b63109f73906c0e7d61.tar.bz2
[cros] Fetch cookies after online authentication is successful.
BUG=chromium-os:9814 TEST=Manual. Checked that web properties load w/o auth request for new user/existing user/existing with cookies cleared/existing with changed password. Review URL: http://codereview.chromium.org/5641001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69016 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc5
-rw-r--r--chrome/browser/chromeos/login/existing_user_controller.cc10
-rw-r--r--chrome/browser/chromeos/login/login_performer.cc12
-rw-r--r--chrome/browser/chromeos/login/login_screen.cc5
-rw-r--r--chrome/browser/chromeos/login/login_utils.cc64
-rw-r--r--chrome/browser/chromeos/login/login_utils.h15
-rw-r--r--chrome/browser/chromeos/login/mock_authenticator.h15
7 files changed, 98 insertions, 28 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index d5b6d7f..23d7ad6 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -932,7 +932,10 @@ class StubLogin : public chromeos::LoginStatusConsumer {
const std::string& password,
const GaiaAuthConsumer::ClientLoginResult& credentials,
bool pending_requests) {
- chromeos::LoginUtils::Get()->CompleteLogin(username, password, credentials);
+ chromeos::LoginUtils::Get()->CompleteLogin(username,
+ password,
+ credentials,
+ pending_requests);
delete this;
}
diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc
index 2e43129..2e2bb5a 100644
--- a/chrome/browser/chromeos/login/existing_user_controller.cc
+++ b/chrome/browser/chromeos/login/existing_user_controller.cc
@@ -525,7 +525,10 @@ void ExistingUserController::OnLoginSuccess(
}
// For new user login don't launch browser until we pass image screen.
LoginUtils::Get()->EnableBrowserLaunch(false);
- LoginUtils::Get()->CompleteLogin(username, password, credentials);
+ LoginUtils::Get()->CompleteLogin(username,
+ password,
+ credentials,
+ pending_requests);
ActivateWizard(WizardController::IsDeviceRegistered() ?
WizardController::kUserImageScreenName :
WizardController::kRegistrationScreenName);
@@ -534,7 +537,10 @@ void ExistingUserController::OnLoginSuccess(
WmIpc::Message message(WM_IPC_MESSAGE_WM_HIDE_LOGIN);
WmIpc::instance()->SendMessage(message);
- LoginUtils::Get()->CompleteLogin(username, password, credentials);
+ LoginUtils::Get()->CompleteLogin(username,
+ password,
+ credentials,
+ pending_requests);
// Delay deletion as we're on the stack.
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
diff --git a/chrome/browser/chromeos/login/login_performer.cc b/chrome/browser/chromeos/login/login_performer.cc
index 5701e86..d1b2281 100644
--- a/chrome/browser/chromeos/login/login_performer.cc
+++ b/chrome/browser/chromeos/login/login_performer.cc
@@ -20,10 +20,10 @@
#include "chrome/browser/chromeos/login/screen_locker.h"
#include "chrome/browser/chromeos/user_cros_settings_provider.h"
#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/common/notification_service.h"
-#include "chrome/common/notification_type.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/notification_type.h"
#include "grit/generated_resources.h"
namespace chromeos {
@@ -127,9 +127,11 @@ void LoginPerformer::OnLoginSuccess(
DCHECK(!pending_requests)
<< "Pending request w/o delegate_ should not happen!";
// Online login has succeeded.
- // TODO(nkostylev): Execute CookieFetcher->AttemptFetch() here once
- // async login is implemented.
- // http://crosbug.com/9814
+ Profile* profile =
+ g_browser_process->profile_manager()->GetDefaultProfile();
+ LoginUtils::Get()->FetchCookies(profile, credentials);
+ LoginUtils::Get()->FetchTokens(profile, credentials);
+
if (ScreenLocker::default_screen_locker()) {
DVLOG(1) << "Online login OK - unlocking screen.";
RequestScreenUnlock();
diff --git a/chrome/browser/chromeos/login/login_screen.cc b/chrome/browser/chromeos/login/login_screen.cc
index b2c8dd9..f14b5f35 100644
--- a/chrome/browser/chromeos/login/login_screen.cc
+++ b/chrome/browser/chromeos/login/login_screen.cc
@@ -102,7 +102,10 @@ void LoginScreen::OnLoginSuccess(
delegate()->GetObserver(this)->OnExit(ScreenObserver::LOGIN_SIGN_IN_SELECTED);
AppendStartUrlToCmdline();
- LoginUtils::Get()->CompleteLogin(username, password, credentials);
+ LoginUtils::Get()->CompleteLogin(username,
+ password,
+ credentials,
+ pending_requests);
}
void LoginScreen::OnOffTheRecordLoginSuccess() {
diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc
index 11df756..8c7b81c 100644
--- a/chrome/browser/chromeos/login/login_utils.cc
+++ b/chrome/browser/chromeos/login/login_utils.cc
@@ -107,7 +107,8 @@ class LoginUtilsImpl : public LoginUtils {
virtual void CompleteLogin(
const std::string& username,
const std::string& password,
- const GaiaAuthConsumer::ClientLoginResult& credentials);
+ const GaiaAuthConsumer::ClientLoginResult& credentials,
+ bool pending_requests);
// Invoked after the tmpfs is successfully mounted.
// Launches a browser in the off the record (incognito) mode.
@@ -131,6 +132,17 @@ class LoginUtilsImpl : public LoginUtils {
// Warms the url used by authentication.
virtual void PrewarmAuthentication();
+ // Given the credentials try to exchange them for
+ // full-fledged Google authentication cookies.
+ virtual void FetchCookies(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials);
+
+ // Supply credentials for sync and others to use.
+ virtual void FetchTokens(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials);
+
private:
// Check user's profile for kApplicationLocale setting.
void RespectLocalePreference(PrefService* pref);
@@ -172,7 +184,8 @@ class LoginUtilsWrapper {
void LoginUtilsImpl::CompleteLogin(
const std::string& username,
const std::string& password,
- const GaiaAuthConsumer::ClientLoginResult& credentials) {
+ const GaiaAuthConsumer::ClientLoginResult& credentials,
+ bool pending_requests) {
BootTimesLoader* btl = BootTimesLoader::Get();
VLOG(1) << "Completing login for " << username;
@@ -223,15 +236,13 @@ void LoginUtilsImpl::CompleteLogin(
new ResetDefaultProxyConfigServiceTask(
proxy_config_service));
- // Take the credentials passed in and try to exchange them for
- // full-fledged Google authentication cookies. This is
- // best-effort; it's possible that we'll fail due to network
- // troubles or some such. Either way, |cf| will call
- // DoBrowserLaunch on the UI thread when it's done, and then
- // delete itself.
- CookieFetcher* cf = new CookieFetcher(profile);
- cf->AttemptFetch(credentials.data);
- btl->AddLoginTimeMarker("CookieFetchStarted", false);
+ // Since we're doing parallel authentication, only new user sign in
+ // would perform online auth before calling CompleteLogin.
+ // For existing users there's usually a pending online auth request.
+ // Cookies will be fetched after it's is succeeded.
+ if (!pending_requests) {
+ FetchCookies(profile, credentials);
+ }
// Init extension event routers; this normally happens in browser_main
// but on Chrome OS it has to be deferred until the user finishes
@@ -247,9 +258,11 @@ void LoginUtilsImpl::CompleteLogin(
token_service->Initialize(GaiaConstants::kChromeOSSource,
profile);
token_service->LoadTokensFromDB();
- token_service->UpdateCredentials(credentials);
- if (token_service->AreCredentialsValid()) {
- token_service->StartFetchingTokens();
+
+ // For existing users there's usually a pending online auth request.
+ // Tokens will be fetched after it's is succeeded.
+ if (!pending_requests) {
+ FetchTokens(profile, credentials);
}
btl->AddLoginTimeMarker("TokensGotten", false);
@@ -293,6 +306,29 @@ void LoginUtilsImpl::CompleteLogin(
DoBrowserLaunch(profile);
}
+void LoginUtilsImpl::FetchCookies(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials) {
+ // Take the credentials passed in and try to exchange them for
+ // full-fledged Google authentication cookies. This is
+ // best-effort; it's possible that we'll fail due to network
+ // troubles or some such.
+ // CookieFetcher will delete itself once done.
+ CookieFetcher* cf = new CookieFetcher(profile);
+ cf->AttemptFetch(credentials.data);
+ BootTimesLoader::Get()->AddLoginTimeMarker("CookieFetchStarted", false);
+}
+
+void LoginUtilsImpl::FetchTokens(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials) {
+ TokenService* token_service = profile->GetTokenService();
+ token_service->UpdateCredentials(credentials);
+ if (token_service->AreCredentialsValid()) {
+ token_service->StartFetchingTokens();
+ }
+}
+
void LoginUtilsImpl::RespectLocalePreference(PrefService* pref) {
std::string pref_locale = pref->GetString(prefs::kApplicationLocale);
if (pref_locale.empty()) {
diff --git a/chrome/browser/chromeos/login/login_utils.h b/chrome/browser/chromeos/login/login_utils.h
index 6357e2b..165852b 100644
--- a/chrome/browser/chromeos/login/login_utils.h
+++ b/chrome/browser/chromeos/login/login_utils.h
@@ -36,10 +36,12 @@ class LoginUtils {
// Invoked after the user has successfully logged in. This launches a browser
// and does other bookkeeping after logging in.
+ // If |pending_requests| is true, there's a pending online auth request.
virtual void CompleteLogin(
const std::string& username,
const std::string& password,
- const GaiaAuthConsumer::ClientLoginResult& credentials) = 0;
+ const GaiaAuthConsumer::ClientLoginResult& credentials,
+ bool pending_requests) = 0;
// Invoked after the tmpfs is successfully mounted.
// Asks session manager to restart Chrome in Browse Without Sign In mode.
@@ -64,6 +66,17 @@ class LoginUtils {
// Prewarms the authentication network connection.
virtual void PrewarmAuthentication() = 0;
+ // Given the credentials try to exchange them for
+ // full-fledged Google authentication cookies.
+ virtual void FetchCookies(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials) = 0;
+
+ // Supply credentials for sync and others to use.
+ virtual void FetchTokens(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials) = 0;
+
};
} // namespace chromeos
diff --git a/chrome/browser/chromeos/login/mock_authenticator.h b/chrome/browser/chromeos/login/mock_authenticator.h
index 92db635..5e0f708 100644
--- a/chrome/browser/chromeos/login/mock_authenticator.h
+++ b/chrome/browser/chromeos/login/mock_authenticator.h
@@ -112,7 +112,8 @@ class MockLoginUtils : public LoginUtils {
virtual void CompleteLogin(const std::string& username,
const std::string& password,
- const GaiaAuthConsumer::ClientLoginResult& res) {
+ const GaiaAuthConsumer::ClientLoginResult& res,
+ bool pending_requests) {
EXPECT_EQ(expected_username_, username);
EXPECT_EQ(expected_password_, password);
}
@@ -135,11 +136,17 @@ class MockLoginUtils : public LoginUtils {
return true;
}
- virtual const std::string& GetAuthToken() const {
- return auth_token_;
+ virtual void PrewarmAuthentication() {
}
- virtual void PrewarmAuthentication() {
+ virtual void FetchCookies(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials) {
+ }
+
+ virtual void FetchTokens(
+ Profile* profile,
+ const GaiaAuthConsumer::ClientLoginResult& credentials) {
}
private: