| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // Given the authenticated credentials from the cookie jar, try to exchange | 277 // Given the authenticated credentials from the cookie jar, try to exchange |
| 278 // fetch OAuth request, v1 and v2 tokens. | 278 // fetch OAuth request, v1 and v2 tokens. |
| 279 void FetchOAuth1AccessToken(Profile* auth_profile); | 279 void FetchOAuth1AccessToken(Profile* auth_profile); |
| 280 | 280 |
| 281 // Given the credentials try to exchange them for | 281 // Given the credentials try to exchange them for |
| 282 // full-fledged Google authentication cookies. | 282 // full-fledged Google authentication cookies. |
| 283 virtual void FetchCookies( | 283 virtual void FetchCookies( |
| 284 Profile* profile, | 284 Profile* profile, |
| 285 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 285 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
| 286 | 286 |
| 287 // Starts process of fetching OAuth2 tokens (based on OAuth1 tokens found |
| 288 // in |user_profile|) and kicks off internal services that depend on them. |
| 289 virtual void StartTokenServices(Profile* user_profile) OVERRIDE; |
| 290 |
| 287 // Supply credentials for sync and others to use. | 291 // Supply credentials for sync and others to use. |
| 288 virtual void StartSync( | 292 virtual void StartSync( |
| 289 Profile* profile, | 293 Profile* profile, |
| 290 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; | 294 const GaiaAuthConsumer::ClientLoginResult& credentials) OVERRIDE; |
| 291 | 295 |
| 292 // Sets the current background view. | 296 // Sets the current background view. |
| 293 virtual void SetBackgroundView( | 297 virtual void SetBackgroundView( |
| 294 chromeos::BackgroundView* background_view) OVERRIDE; | 298 chromeos::BackgroundView* background_view) OVERRIDE; |
| 295 | 299 |
| 296 // Gets the current background view. | 300 // Gets the current background view. |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 585 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
| 582 // Take the credentials passed in and try to exchange them for | 586 // Take the credentials passed in and try to exchange them for |
| 583 // full-fledged Google authentication cookies. This is | 587 // full-fledged Google authentication cookies. This is |
| 584 // best-effort; it's possible that we'll fail due to network | 588 // best-effort; it's possible that we'll fail due to network |
| 585 // troubles or some such. | 589 // troubles or some such. |
| 586 // CookieFetcher will delete itself once done. | 590 // CookieFetcher will delete itself once done. |
| 587 CookieFetcher* cf = new CookieFetcher(profile); | 591 CookieFetcher* cf = new CookieFetcher(profile); |
| 588 cf->AttemptFetch(credentials.data); | 592 cf->AttemptFetch(credentials.data); |
| 589 } | 593 } |
| 590 | 594 |
| 595 void LoginUtilsImpl::StartTokenServices(Profile* user_profile) { |
| 596 std::string oauth1_token; |
| 597 std::string oauth1_secret; |
| 598 if (!ReadOAuth1AccessToken(user_profile, &oauth1_token, &oauth1_secret)) |
| 599 return; |
| 600 |
| 601 FetchSecondaryTokens(user_profile->GetOffTheRecordProfile(), oauth1_token, |
| 602 oauth1_secret); |
| 603 } |
| 604 |
| 591 void LoginUtilsImpl::StartSync( | 605 void LoginUtilsImpl::StartSync( |
| 592 Profile* user_profile, | 606 Profile* user_profile, |
| 593 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 607 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
| 594 TokenService* token_service = user_profile->GetTokenService(); | 608 TokenService* token_service = user_profile->GetTokenService(); |
| 595 static bool initialized = false; | 609 static bool initialized = false; |
| 596 if (!initialized) { | 610 if (!initialized) { |
| 597 initialized = true; | 611 initialized = true; |
| 598 | 612 |
| 599 // Set the CrOS user by getting this constructor run with the | 613 // Set the CrOS user by getting this constructor run with the |
| 600 // user's email on first retrieval. | 614 // user's email on first retrieval. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 | 877 |
| 864 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, | 878 void LoginUtilsImpl::FetchSecondaryTokens(Profile* offrecord_profile, |
| 865 const std::string& token, | 879 const std::string& token, |
| 866 const std::string& secret) { | 880 const std::string& secret) { |
| 867 FetchPolicyToken(offrecord_profile, token, secret); | 881 FetchPolicyToken(offrecord_profile, token, secret); |
| 868 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes | 882 // TODO(rickcam, zelidrag): Wire TokenService there when it becomes |
| 869 // capable of handling OAuth1 tokens directly. | 883 // capable of handling OAuth1 tokens directly. |
| 870 } | 884 } |
| 871 | 885 |
| 872 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, | 886 bool LoginUtilsImpl::ReadOAuth1AccessToken(Profile* user_profile, |
| 873 std::string* token, | 887 std::string* token, |
| 874 std::string* secret) { | 888 std::string* secret) { |
| 875 PrefService* pref_service = user_profile->GetPrefs(); | 889 PrefService* pref_service = user_profile->GetPrefs(); |
| 876 *token = pref_service->GetString(prefs::kOAuth1Token); | 890 std::string encoded_token = pref_service->GetString(prefs::kOAuth1Token); |
| 877 *secret = pref_service->GetString(prefs::kOAuth1Secret); | 891 std::string encoded_secret = pref_service->GetString(prefs::kOAuth1Secret); |
| 878 if (!token->length() || !secret->length()) | 892 if (!encoded_token.length() || !encoded_secret.length()) |
| 879 return false; | 893 return false; |
| 880 | 894 |
| 895 std::string decoded_token = authenticator_->DecryptToken(encoded_token); |
| 896 std::string decoded_secret = authenticator_->DecryptToken(encoded_secret); |
| 897 if (!decoded_token.length() || !decoded_secret.length()) |
| 898 return false; |
| 899 |
| 900 *token = decoded_token; |
| 901 *secret = decoded_secret; |
| 881 return true; | 902 return true; |
| 882 } | 903 } |
| 883 | 904 |
| 884 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, | 905 void LoginUtilsImpl::StoreOAuth1AccessToken(Profile* user_profile, |
| 885 const std::string& token, | 906 const std::string& token, |
| 886 const std::string& secret) { | 907 const std::string& secret) { |
| 887 // First store OAuth1 token + service for the current user profile... | 908 // First store OAuth1 token + service for the current user profile... |
| 888 PrefService* pref_service = user_profile->GetPrefs(); | 909 PrefService* pref_service = user_profile->GetPrefs(); |
| 889 pref_service->SetString(prefs::kOAuth1Token, token); | 910 pref_service->SetString(prefs::kOAuth1Token, |
| 890 pref_service->SetString(prefs::kOAuth1Secret, secret); | 911 authenticator_->EncryptToken(token)); |
| 912 pref_service->SetString(prefs::kOAuth1Secret, |
| 913 authenticator_->EncryptToken(secret)); |
| 891 | 914 |
| 892 // ...then record the presence of valid OAuth token for this account in local | 915 // ...then record the presence of valid OAuth token for this account in local |
| 893 // state as well. | 916 // state as well. |
| 894 UserManager::Get()->SaveUserOAuthStatus(username_, | 917 UserManager::Get()->SaveUserOAuthStatus(username_, |
| 895 UserManager::OAUTH_TOKEN_STATUS_VALID); | 918 UserManager::OAUTH_TOKEN_STATUS_VALID); |
| 896 } | 919 } |
| 897 | 920 |
| 898 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, | 921 void LoginUtilsImpl::FetchCredentials(Profile* user_profile, |
| 899 const std::string& token, | 922 const std::string& token, |
| 900 const std::string& secret) { | 923 const std::string& secret) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 // Mark login host for deletion after browser starts. This | 978 // Mark login host for deletion after browser starts. This |
| 956 // guarantees that the message loop will be referenced by the | 979 // guarantees that the message loop will be referenced by the |
| 957 // browser before it is dereferenced by the login host. | 980 // browser before it is dereferenced by the login host. |
| 958 if (login_host) { | 981 if (login_host) { |
| 959 login_host->OnSessionStart(); | 982 login_host->OnSessionStart(); |
| 960 login_host = NULL; | 983 login_host = NULL; |
| 961 } | 984 } |
| 962 } | 985 } |
| 963 | 986 |
| 964 } // namespace chromeos | 987 } // namespace chromeos |
| OLD | NEW |