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

Side by Side Diff: chrome/browser/chromeos/login/login_utils.cc

Issue 7639004: [ChromeOS] Always fetch oauth cooken when signing in via extension. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chromeos trybot Created 9 years, 4 months 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/chromeos/login/login_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 241
242 class LoginUtilsImpl : public LoginUtils, 242 class LoginUtilsImpl : public LoginUtils,
243 public ProfileManagerObserver, 243 public ProfileManagerObserver,
244 public GaiaOAuthConsumer { 244 public GaiaOAuthConsumer {
245 public: 245 public:
246 LoginUtilsImpl() 246 LoginUtilsImpl()
247 : background_view_(NULL), 247 : background_view_(NULL),
248 pending_requests_(false), 248 pending_requests_(false),
249 using_oauth_(false), 249 using_oauth_(false),
250 has_cookies_(false),
250 delegate_(NULL) { 251 delegate_(NULL) {
251 } 252 }
252 253
253 virtual void PrepareProfile( 254 virtual void PrepareProfile(
254 const std::string& username, 255 const std::string& username,
255 const std::string& password, 256 const std::string& password,
256 const GaiaAuthConsumer::ClientLoginResult& credentials, 257 const GaiaAuthConsumer::ClientLoginResult& credentials,
257 bool pending_requests, 258 bool pending_requests,
258 bool using_oauth, 259 bool using_oauth,
260 bool has_cookies,
259 LoginUtils::Delegate* delegate) OVERRIDE; 261 LoginUtils::Delegate* delegate) OVERRIDE;
260 262
261 // Invoked after the tmpfs is successfully mounted. 263 // Invoked after the tmpfs is successfully mounted.
262 // Launches a browser in the incognito mode. 264 // Launches a browser in the incognito mode.
263 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; 265 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE;
264 266
265 // Invoked when the user is logging in for the first time, or is logging in as 267 // Invoked when the user is logging in for the first time, or is logging in as
266 // a guest user. 268 // a guest user.
267 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; 269 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE;
268 270
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 void RespectLocalePreference(Profile* pref); 358 void RespectLocalePreference(Profile* pref);
357 359
358 // The current background view. 360 // The current background view.
359 chromeos::BackgroundView* background_view_; 361 chromeos::BackgroundView* background_view_;
360 362
361 std::string username_; 363 std::string username_;
362 std::string password_; 364 std::string password_;
363 GaiaAuthConsumer::ClientLoginResult credentials_; 365 GaiaAuthConsumer::ClientLoginResult credentials_;
364 bool pending_requests_; 366 bool pending_requests_;
365 bool using_oauth_; 367 bool using_oauth_;
368 bool has_cookies_;
366 // Has to be scoped_refptr, see comment for CreateAuthenticator(...). 369 // Has to be scoped_refptr, see comment for CreateAuthenticator(...).
367 scoped_refptr<Authenticator> authenticator_; 370 scoped_refptr<Authenticator> authenticator_;
368 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_; 371 scoped_ptr<GaiaOAuthFetcher> oauth_fetcher_;
369 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_; 372 scoped_ptr<PolicyOAuthFetcher> policy_oauth_fetcher_;
370 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_; 373 scoped_ptr<OAuthLoginVerifier> oauth_login_verifier_;
371 374
372 // Delegate to be fired when the profile will be prepared. 375 // Delegate to be fired when the profile will be prepared.
373 LoginUtils::Delegate* delegate_; 376 LoginUtils::Delegate* delegate_;
374 377
375 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); 378 DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl);
(...skipping 26 matching lines...) Expand all
402 405
403 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); 406 DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper);
404 }; 407 };
405 408
406 void LoginUtilsImpl::PrepareProfile( 409 void LoginUtilsImpl::PrepareProfile(
407 const std::string& username, 410 const std::string& username,
408 const std::string& password, 411 const std::string& password,
409 const GaiaAuthConsumer::ClientLoginResult& credentials, 412 const GaiaAuthConsumer::ClientLoginResult& credentials,
410 bool pending_requests, 413 bool pending_requests,
411 bool using_oauth, 414 bool using_oauth,
415 bool has_cookies,
412 LoginUtils::Delegate* delegate) { 416 LoginUtils::Delegate* delegate) {
413 BootTimesLoader* btl = BootTimesLoader::Get(); 417 BootTimesLoader* btl = BootTimesLoader::Get();
414 418
415 VLOG(1) << "Completing login for " << username; 419 VLOG(1) << "Completing login for " << username;
416 420
417 if (CrosLibrary::Get()->EnsureLoaded()) { 421 if (CrosLibrary::Get()->EnsureLoaded()) {
418 btl->AddLoginTimeMarker("StartSession-Start", false); 422 btl->AddLoginTimeMarker("StartSession-Start", false);
419 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, ""); 423 CrosLibrary::Get()->GetLoginLibrary()->StartSession(username, "");
420 btl->AddLoginTimeMarker("StartSession-End", false); 424 btl->AddLoginTimeMarker("StartSession-End", false);
421 } 425 }
422 426
423 btl->AddLoginTimeMarker("UserLoggedIn-Start", false); 427 btl->AddLoginTimeMarker("UserLoggedIn-Start", false);
424 UserManager::Get()->UserLoggedIn(username); 428 UserManager::Get()->UserLoggedIn(username);
425 btl->AddLoginTimeMarker("UserLoggedIn-End", false); 429 btl->AddLoginTimeMarker("UserLoggedIn-End", false);
426 430
427 // Switch log file as soon as possible. 431 // Switch log file as soon as possible.
428 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess())); 432 logging::RedirectChromeLogging(*(CommandLine::ForCurrentProcess()));
429 433
430 username_ = username; 434 username_ = username;
431 password_ = password; 435 password_ = password;
432 436
433 credentials_ = credentials; 437 credentials_ = credentials;
434 pending_requests_ = pending_requests; 438 pending_requests_ = pending_requests;
435 using_oauth_ = using_oauth; 439 using_oauth_ = using_oauth;
440 has_cookies_ = has_cookies;
436 delegate_ = delegate; 441 delegate_ = delegate;
437 442
438 // The default profile will have been changed because the ProfileManager 443 // The default profile will have been changed because the ProfileManager
439 // will process the notification that the UserManager sends out. 444 // will process the notification that the UserManager sends out.
440 ProfileManager::CreateDefaultProfileAsync(this); 445 ProfileManager::CreateDefaultProfileAsync(this);
441 } 446 }
442 447
443 void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) { 448 void LoginUtilsImpl::OnProfileCreated(Profile* user_profile, Status status) {
444 CHECK(user_profile); 449 CHECK(user_profile);
445 switch (status) { 450 switch (status) {
(...skipping 18 matching lines...) Expand all
464 if (!using_oauth_) 469 if (!using_oauth_)
465 token_service_for_policy = user_profile->GetTokenService(); 470 token_service_for_policy = user_profile->GetTokenService();
466 browser_policy_connector->InitializeUserPolicy(username_, 471 browser_policy_connector->InitializeUserPolicy(username_,
467 user_profile->GetPath(), 472 user_profile->GetPath(),
468 token_service_for_policy); 473 token_service_for_policy);
469 474
470 BootTimesLoader* btl = BootTimesLoader::Get(); 475 BootTimesLoader* btl = BootTimesLoader::Get();
471 btl->AddLoginTimeMarker("UserProfileGotten", false); 476 btl->AddLoginTimeMarker("UserProfileGotten", false);
472 477
473 if (using_oauth_) { 478 if (using_oauth_) {
474 // Transfer cookies for the new user login. 479 // Transfer cookies when user signs in using extension.
475 if (!pending_requests_) { 480 if (has_cookies_) {
476 // Transfer cookies from the profile that was used for authentication. 481 // Transfer cookies from the profile that was used for authentication.
477 // This profile contains cookies that auth extension should have already 482 // This profile contains cookies that auth extension should have already
478 // put in place that will ensure that the newly created session is 483 // put in place that will ensure that the newly created session is
479 // authenticated for the websites that work with the used authentication 484 // authenticated for the websites that work with the used authentication
480 // schema. 485 // schema.
481 if (!TransferDefaultCookies(authenticator_->authentication_profile(), 486 if (!TransferDefaultCookies(authenticator_->authentication_profile(),
482 user_profile)) { 487 user_profile)) {
483 LOG(WARNING) << "Cookie transfer from the default profile failed!"; 488 LOG(WARNING) << "Cookie transfer from the default profile failed!";
484 } 489 }
485 } 490 }
486 std::string oauth1_token; 491 std::string oauth1_token;
487 std::string oauth1_secret; 492 std::string oauth1_secret;
488 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret) || 493 if (!has_cookies_ &&
489 pending_requests_) { 494 ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) {
490 // Verify OAuth access token when we find it in the profile and always if 495 // Verify OAuth access token when we find it in the profile and no cookies
491 // we are performing parallel authentication. 496 // available because user is not signing in using extension.
492 authenticator_->VerifyOAuth1AccessToken(oauth1_token, oauth1_secret); 497 authenticator_->VerifyOAuth1AccessToken(oauth1_token, oauth1_secret);
493 } else { 498 } else {
494 // If we don't have it, fetch OAuth1 access token. 499 // If we don't have it, fetch OAuth1 access token.
495 // Use off-the-record profile that was used for this step. It should 500 // Use off-the-record profile that was used for this step. It should
496 // already contain all needed cookies that will let us skip GAIA's user 501 // already contain all needed cookies that will let us skip GAIA's user
497 // authentication UI. 502 // authentication UI.
498 // 503 //
499 // TODO(rickcam) We should use an isolated App here. 504 // TODO(rickcam) We should use an isolated App here.
500 FetchOAuth1AccessToken(authenticator_->authentication_profile()); 505 FetchOAuth1AccessToken(authenticator_->authentication_profile());
501 } 506 }
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 // Mark login host for deletion after browser starts. This 990 // Mark login host for deletion after browser starts. This
986 // guarantees that the message loop will be referenced by the 991 // guarantees that the message loop will be referenced by the
987 // browser before it is dereferenced by the login host. 992 // browser before it is dereferenced by the login host.
988 if (login_host) { 993 if (login_host) {
989 login_host->OnSessionStart(); 994 login_host->OnSessionStart();
990 login_host = NULL; 995 login_host = NULL;
991 } 996 }
992 } 997 }
993 998
994 } // namespace chromeos 999 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.h ('k') | chrome/browser/chromeos/login/mock_authenticator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698