OLD | NEW |
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 Loading... |
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; | |
443 virtual void FetchCookies( | 441 virtual void FetchCookies( |
444 Profile* profile, | 442 Profile* profile, |
445 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 443 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
446 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; | 444 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; |
447 virtual void StartSync( | 445 virtual void StartSync( |
448 Profile* profile, | 446 Profile* profile, |
449 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 447 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
450 virtual void SetBackgroundView( | 448 virtual void SetBackgroundView( |
451 chromeos::BackgroundView* background_view) OVERRIDE; | 449 chromeos::BackgroundView* background_view) OVERRIDE; |
452 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; | 450 virtual chromeos::BackgroundView* GetBackgroundView() OVERRIDE; |
(...skipping 21 matching lines...) Expand all Loading... |
474 // fetch OAuth request, v1 and v2 tokens. | 472 // fetch OAuth request, v1 and v2 tokens. |
475 void FetchOAuth1AccessToken(Profile* auth_profile); | 473 void FetchOAuth1AccessToken(Profile* auth_profile); |
476 | 474 |
477 protected: | 475 protected: |
478 virtual std::string GetOffTheRecordCommandLine( | 476 virtual std::string GetOffTheRecordCommandLine( |
479 const GURL& start_url, | 477 const GURL& start_url, |
480 const CommandLine& base_command_line, | 478 const CommandLine& base_command_line, |
481 CommandLine *command_line); | 479 CommandLine *command_line); |
482 | 480 |
483 private: | 481 private: |
484 // Restarts OAuth session authentication check. | |
485 void KickStartAuthentication(Profile* profile); | |
486 | |
487 // Reads OAuth1 token from user profile's prefs. | 482 // Reads OAuth1 token from user profile's prefs. |
488 bool ReadOAuth1AccessToken(Profile* user_profile, | 483 bool ReadOAuth1AccessToken(Profile* user_profile, |
489 std::string* token, | 484 std::string* token, |
490 std::string* secret); | 485 std::string* secret); |
491 | 486 |
492 // Stores OAuth1 token + secret in profile's prefs. | 487 // Stores OAuth1 token + secret in profile's prefs. |
493 void StoreOAuth1AccessToken(Profile* user_profile, | 488 void StoreOAuth1AccessToken(Profile* user_profile, |
494 const std::string& token, | 489 const std::string& token, |
495 const std::string& secret); | 490 const std::string& secret); |
496 | 491 |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 chrome_browser_net::PreconnectOnUIThread( | 1012 chrome_browser_net::PreconnectOnUIThread( |
1018 GURL(GaiaUrls::GetInstance()->client_login_url()), | 1013 GURL(GaiaUrls::GetInstance()->client_login_url()), |
1019 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, | 1014 chrome_browser_net::UrlInfo::EARLY_LOAD_MOTIVATED, |
1020 kConnectionsNeeded); | 1015 kConnectionsNeeded); |
1021 } else { | 1016 } else { |
1022 new WarmingObserver(); | 1017 new WarmingObserver(); |
1023 } | 1018 } |
1024 } | 1019 } |
1025 } | 1020 } |
1026 | 1021 |
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 | |
1044 void LoginUtilsImpl::SetBackgroundView(BackgroundView* background_view) { | 1022 void LoginUtilsImpl::SetBackgroundView(BackgroundView* background_view) { |
1045 background_view_ = background_view; | 1023 background_view_ = background_view; |
1046 } | 1024 } |
1047 | 1025 |
1048 BackgroundView* LoginUtilsImpl::GetBackgroundView() { | 1026 BackgroundView* LoginUtilsImpl::GetBackgroundView() { |
1049 return background_view_; | 1027 return background_view_; |
1050 } | 1028 } |
1051 | 1029 |
1052 void LoginUtilsImpl::TransferDefaultCookies(Profile* default_profile, | 1030 void LoginUtilsImpl::TransferDefaultCookies(Profile* default_profile, |
1053 Profile* profile) { | 1031 Profile* profile) { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 const GoogleServiceAuthError& error) { | 1158 const GoogleServiceAuthError& error) { |
1181 // TODO(zelidrag): Pop up sync setup UI here? | 1159 // TODO(zelidrag): Pop up sync setup UI here? |
1182 LOG(WARNING) << "Failed fetching OAuth v1 token, error: " << error.state(); | 1160 LOG(WARNING) << "Failed fetching OAuth v1 token, error: " << error.state(); |
1183 } | 1161 } |
1184 | 1162 |
1185 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { | 1163 void LoginUtilsImpl::OnOnlineStateChanged(bool online) { |
1186 // If we come online for the first time after successful offline login, | 1164 // If we come online for the first time after successful offline login, |
1187 // we need to kick of OAuth token verification process again. | 1165 // we need to kick of OAuth token verification process again. |
1188 if (UserManager::Get()->user_is_logged_in() && | 1166 if (UserManager::Get()->user_is_logged_in() && |
1189 UserManager::Get()->offline_login() && online) { | 1167 UserManager::Get()->offline_login() && online) { |
1190 KickStartAuthentication(ProfileManager::GetDefaultProfile()); | 1168 if (!authenticator_.get()) |
| 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; |
1191 } | 1176 } |
1192 } | 1177 } |
1193 | 1178 |
1194 LoginUtils* LoginUtils::Get() { | 1179 LoginUtils* LoginUtils::Get() { |
1195 return LoginUtilsWrapper::GetInstance()->get(); | 1180 return LoginUtilsWrapper::GetInstance()->get(); |
1196 } | 1181 } |
1197 | 1182 |
1198 void LoginUtils::Set(LoginUtils* mock) { | 1183 void LoginUtils::Set(LoginUtils* mock) { |
1199 LoginUtilsWrapper::GetInstance()->reset(mock); | 1184 LoginUtilsWrapper::GetInstance()->reset(mock); |
1200 } | 1185 } |
(...skipping 20 matching lines...) Expand all Loading... |
1221 // Mark login host for deletion after browser starts. This | 1206 // Mark login host for deletion after browser starts. This |
1222 // guarantees that the message loop will be referenced by the | 1207 // guarantees that the message loop will be referenced by the |
1223 // browser before it is dereferenced by the login host. | 1208 // browser before it is dereferenced by the login host. |
1224 if (login_host) { | 1209 if (login_host) { |
1225 login_host->OnSessionStart(); | 1210 login_host->OnSessionStart(); |
1226 login_host = NULL; | 1211 login_host = NULL; |
1227 } | 1212 } |
1228 } | 1213 } |
1229 | 1214 |
1230 } // namespace chromeos | 1215 } // namespace chromeos |
OLD | NEW |