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

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

Issue 8537002: Re-authenticate oauth tokens after crash and restart Sync. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 bool pending_requests, 431 bool pending_requests,
432 bool using_oauth, 432 bool using_oauth,
433 bool has_cookies, 433 bool has_cookies,
434 LoginUtils::Delegate* delegate) OVERRIDE; 434 LoginUtils::Delegate* delegate) OVERRIDE;
435 virtual void DelegateDeleted(Delegate* delegate) OVERRIDE; 435 virtual void DelegateDeleted(Delegate* delegate) OVERRIDE;
436 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE; 436 virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE;
437 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE; 437 virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE;
438 virtual scoped_refptr<Authenticator> CreateAuthenticator( 438 virtual scoped_refptr<Authenticator> CreateAuthenticator(
439 LoginStatusConsumer* consumer) OVERRIDE; 439 LoginStatusConsumer* consumer) OVERRIDE;
440 virtual void PrewarmAuthentication() OVERRIDE; 440 virtual void PrewarmAuthentication() OVERRIDE;
441 virtual void RestoreAuthenticationSession(const std::string& user_name,
442 Profile* profile) OVERRIDE;
441 virtual void FetchCookies( 443 virtual void FetchCookies(
442 Profile* profile, 444 Profile* profile,
443 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; 445 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE;
444 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; 446 virtual void StartTokenServices(Profile* user_profile) OVERRIDE;
445 virtual void StartSync( 447 virtual void StartSync(
446 Profile* profile, 448 Profile* profile,
447 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; 449 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE;
448 virtual void SetBackgroundView( 450 virtual void SetBackgroundView(
449 chromeos::BackgroundView* background_view) OVERRIDE; 451 chromeos::BackgroundView* background_view) OVERRIDE;
450 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; 452 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE;
(...skipping 21 matching lines...) Expand all
472 // fetch OAuth request, v1 and v2 tokens. 474 // fetch OAuth request, v1 and v2 tokens.
473 void FetchOAuth1AccessToken(Profile* auth_profile); 475 void FetchOAuth1AccessToken(Profile* auth_profile);
474 476
475 protected: 477 protected:
476 virtual std::string GetOffTheRecordCommandLine( 478 virtual std::string GetOffTheRecordCommandLine(
477 const GURL& start_url, 479 const GURL& start_url,
478 const CommandLine& base_command_line, 480 const CommandLine& base_command_line,
479 CommandLine *command_line); 481 CommandLine *command_line);
480 482
481 private: 483 private:
484 // Restarts OAuth session authentication check.
485 void KickStartAuthentication(Profile* profile);
486
482 // Reads OAuth1 token from user profile's prefs. 487 // Reads OAuth1 token from user profile's prefs.
483 bool ReadOAuth1AccessToken(Profile* user_profile, 488 bool ReadOAuth1AccessToken(Profile* user_profile,
484 std::string* token, 489 std::string* token,
485 std::string* secret); 490 std::string* secret);
486 491
487 // Stores OAuth1 token + secret in profile's prefs. 492 // Stores OAuth1 token + secret in profile's prefs.
488 void StoreOAuth1AccessToken(Profile* user_profile, 493 void StoreOAuth1AccessToken(Profile* user_profile,
489 const std::string& token, 494 const std::string& token,
490 const std::string& secret); 495 const std::string& secret);
491 496
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 chrome_browser_net::PreconnectOnUIThread( 1017 chrome_browser_net::PreconnectOnUIThread(
1013 GURL(GaiaUrls::GetInstance()->client_login_url()), 1018 GURL(GaiaUrls::GetInstance()->client_login_url()),
1014 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, 1019 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED,
1015 kConnectionsNeeded); 1020 kConnectionsNeeded);
1016 } else { 1021 } else {
1017 new WarmingObserver(); 1022 new WarmingObserver();
1018 } 1023 }
1019 } 1024 }
1020 } 1025 }
1021 1026
1027 void LoginUtilsImpl::RestoreAuthenticationSession(const std::string& username,
1028 Profile* user_profile) {
1029 username_ = username;
1030 KickStartAuthentication(user_profile);
1031 }
1032
1033 void LoginUtilsImpl::KickStartAuthentication(Profile* user_profile) {
1034 if (!authenticator_.get())
1035 CreateAuthenticator(NULL);
1036 std::string oauth1_token;
1037 std::string oauth1_secret;
1038 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
1039 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret);
1040
1041 authenticator_ = NULL;
1042 }
1043
1022 void LoginUtilsImpl::SetBackgroundView(BackgroundView* background_view) { 1044 void LoginUtilsImpl::SetBackgroundView(BackgroundView* background_view) {
1023 background_view_ = background_view; 1045 background_view_ = background_view;
1024 } 1046 }
1025 1047
1026 BackgroundView* LoginUtilsImpl::GetBackgroundView() { 1048 BackgroundView* LoginUtilsImpl::GetBackgroundView() {
1027 return background_view_; 1049 return background_view_;
1028 } 1050 }
1029 1051
1030 void LoginUtilsImpl::TransferDefaultCookies(Profile* default_profile, 1052 void LoginUtilsImpl::TransferDefaultCookies(Profile* default_profile,
1031 Profile* profile) { 1053 Profile* profile) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 const GoogleServiceAuthError& error) { 1180 const GoogleServiceAuthError& error) {
1159 // TODO(zelidrag): Pop up sync setup UI here? 1181 // TODO(zelidrag): Pop up sync setup UI here?
1160 LOG(WARNING) << "Failed fetching OAuth v1 token, error: " << error.state(); 1182 LOG(WARNING) << "Failed fetching OAuth v1 token, error: " << error.state();
1161 } 1183 }
1162 1184
1163 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { 1185 void LoginUtilsImpl::OnOnlineStateChanged(bool online) {
1164 // If we come online for the first time after successful offline login, 1186 // If we come online for the first time after successful offline login,
1165 // we need to kick of OAuth token verification process again. 1187 // we need to kick of OAuth token verification process again.
1166 if (UserManager::Get()->user_is_logged_in() && 1188 if (UserManager::Get()->user_is_logged_in() &&
1167 UserManager::Get()->offline_login() && online) { 1189 UserManager::Get()->offline_login() && online) {
1168 if (!authenticator_.get()) 1190 KickStartAuthentication(ProfileManager::GetDefaultProfile());
1169 CreateAuthenticator(NULL);
1170 std::string oauth1_token;
1171 std::string oauth1_secret;
1172 Profile* user_profile = ProfileManager::GetDefaultProfile();
1173 if (ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret))
1174 VerifyOAuth1AccessToken(user_profile, oauth1_token, oauth1_secret);
1175 authenticator_ = NULL;
1176 } 1191 }
1177 } 1192 }
1178 1193
1179 LoginUtils* LoginUtils::Get() { 1194 LoginUtils* LoginUtils::Get() {
1180 return LoginUtilsWrapper::GetInstance()->get(); 1195 return LoginUtilsWrapper::GetInstance()->get();
1181 } 1196 }
1182 1197
1183 void LoginUtils::Set(LoginUtils* mock) { 1198 void LoginUtils::Set(LoginUtils* mock) {
1184 LoginUtilsWrapper::GetInstance()->reset(mock); 1199 LoginUtilsWrapper::GetInstance()->reset(mock);
1185 } 1200 }
(...skipping 20 matching lines...) Expand all
1206 // Mark login host for deletion after browser starts. This 1221 // Mark login host for deletion after browser starts. This
1207 // guarantees that the message loop will be referenced by the 1222 // guarantees that the message loop will be referenced by the
1208 // browser before it is dereferenced by the login host. 1223 // browser before it is dereferenced by the login host.
1209 if (login_host) { 1224 if (login_host) {
1210 login_host->OnSessionStart(); 1225 login_host->OnSessionStart();
1211 login_host = NULL; 1226 login_host = NULL;
1212 } 1227 }
1213 } 1228 }
1214 1229
1215 } // namespace chromeos 1230 } // 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