| 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 // Verifies OAuth1 access token by performing OAuthLogin. | 150 // Verifies OAuth1 access token by performing OAuthLogin. |
| 151 class OAuthLoginVerifier : public GaiaOAuthConsumer { | 151 class OAuthLoginVerifier : public GaiaOAuthConsumer { |
| 152 public: | 152 public: |
| 153 OAuthLoginVerifier(Profile* user_profile, | 153 OAuthLoginVerifier(Profile* user_profile, |
| 154 const std::string& oauth1_token, | 154 const std::string& oauth1_token, |
| 155 const std::string& oauth1_secret) | 155 const std::string& oauth1_secret) |
| 156 : oauth_fetcher_(this, | 156 : oauth_fetcher_(this, |
| 157 user_profile->GetOffTheRecordProfile()->GetRequestContext(), | 157 user_profile->GetOffTheRecordProfile()->GetRequestContext(), |
| 158 user_profile->GetOffTheRecordProfile(), | 158 user_profile->GetOffTheRecordProfile(), |
| 159 GaiaConstants::kSyncService, |
| 159 kServiceScopeChromeOS), | 160 kServiceScopeChromeOS), |
| 160 oauth1_token_(oauth1_token), | 161 oauth1_token_(oauth1_token), |
| 161 oauth1_secret_(oauth1_secret) { | 162 oauth1_secret_(oauth1_secret) { |
| 162 } | 163 } |
| 163 virtual ~OAuthLoginVerifier() {} | 164 virtual ~OAuthLoginVerifier() {} |
| 164 | 165 |
| 165 void Start() { | 166 void Start() { |
| 166 oauth_fetcher_.StartOAuthLogin(GaiaConstants::kChromeOSSource, | 167 oauth_fetcher_.StartOAuthLogin(GaiaConstants::kChromeOSSource, |
| 167 GaiaConstants::kContactsService, | 168 GaiaConstants::kContactsService, |
| 168 oauth1_token_, | 169 oauth1_token_, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 193 | 194 |
| 194 // Fetches an OAuth token and initializes user policy with it. | 195 // Fetches an OAuth token and initializes user policy with it. |
| 195 class PolicyOAuthFetcher : public GaiaOAuthConsumer { | 196 class PolicyOAuthFetcher : public GaiaOAuthConsumer { |
| 196 public: | 197 public: |
| 197 PolicyOAuthFetcher(Profile* profile, | 198 PolicyOAuthFetcher(Profile* profile, |
| 198 const std::string& oauth1_token, | 199 const std::string& oauth1_token, |
| 199 const std::string& oauth1_secret) | 200 const std::string& oauth1_secret) |
| 200 : oauth_fetcher_(this, | 201 : oauth_fetcher_(this, |
| 201 profile->GetRequestContext(), | 202 profile->GetRequestContext(), |
| 202 profile, | 203 profile, |
| 204 GaiaConstants::kDeviceManagementService, |
| 203 kServiceScopeChromeOSDeviceManagement), | 205 kServiceScopeChromeOSDeviceManagement), |
| 204 oauth1_token_(oauth1_token), | 206 oauth1_token_(oauth1_token), |
| 205 oauth1_secret_(oauth1_secret) { | 207 oauth1_secret_(oauth1_secret) { |
| 206 oauth_fetcher_.SetAutoFetchLimit( | 208 oauth_fetcher_.SetAutoFetchLimit( |
| 207 GaiaOAuthFetcher::OAUTH2_SERVICE_ACCESS_TOKEN); | 209 GaiaOAuthFetcher::OAUTH2_SERVICE_ACCESS_TOKEN); |
| 208 } | 210 } |
| 209 virtual ~PolicyOAuthFetcher() {} | 211 virtual ~PolicyOAuthFetcher() {} |
| 210 | 212 |
| 211 void Start() { | 213 void Start() { |
| 212 oauth_fetcher_.StartOAuthWrapBridge(oauth1_token_, oauth1_secret_, "3600", | 214 oauth_fetcher_.StartOAuthWrapBridge(oauth1_token_, oauth1_secret_, "3600", |
| 215 std::string(GaiaConstants::kDeviceManagementService), |
| 213 std::string(kServiceScopeChromeOSDeviceManagement)); | 216 std::string(kServiceScopeChromeOSDeviceManagement)); |
| 214 } | 217 } |
| 215 | 218 |
| 216 // GaiaOAuthConsumer implementation: | 219 // GaiaOAuthConsumer implementation: |
| 217 virtual void OnOAuthWrapBridgeSuccess( | 220 virtual void OnOAuthWrapBridgeSuccess( |
| 221 const std::string& service_name, |
| 218 const std::string& token, | 222 const std::string& token, |
| 219 const std::string& expires_in) OVERRIDE { | 223 const std::string& expires_in) OVERRIDE { |
| 220 policy::BrowserPolicyConnector* browser_policy_connector = | 224 policy::BrowserPolicyConnector* browser_policy_connector = |
| 221 g_browser_process->browser_policy_connector(); | 225 g_browser_process->browser_policy_connector(); |
| 222 browser_policy_connector->RegisterForUserPolicy(token); | 226 browser_policy_connector->RegisterForUserPolicy(token); |
| 223 } | 227 } |
| 224 | 228 |
| 225 virtual void OnOAuthWrapBridgeFailure( | 229 virtual void OnOAuthWrapBridgeFailure( |
| 226 const GoogleServiceAuthError& error) OVERRIDE { | 230 const GoogleServiceAuthError& error) OVERRIDE { |
| 227 LOG(WARNING) << "Failed to get OAuth access token."; | 231 LOG(WARNING) << "Failed to get OAuth access token."; |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 delegate_->OnProfilePrepared(user_profile); | 562 delegate_->OnProfilePrepared(user_profile); |
| 559 | 563 |
| 560 // TODO(altimofeev): Need to sanitize memory used to store password. | 564 // TODO(altimofeev): Need to sanitize memory used to store password. |
| 561 credentials_ = GaiaAuthConsumer::ClientLoginResult(); | 565 credentials_ = GaiaAuthConsumer::ClientLoginResult(); |
| 562 } | 566 } |
| 563 | 567 |
| 564 void LoginUtilsImpl::FetchOAuth1AccessToken(Profile* auth_profile) { | 568 void LoginUtilsImpl::FetchOAuth1AccessToken(Profile* auth_profile) { |
| 565 oauth_fetcher_.reset(new GaiaOAuthFetcher(this, | 569 oauth_fetcher_.reset(new GaiaOAuthFetcher(this, |
| 566 auth_profile->GetRequestContext(), | 570 auth_profile->GetRequestContext(), |
| 567 auth_profile, | 571 auth_profile, |
| 572 GaiaConstants::kSyncService, |
| 568 kServiceScopeChromeOS)); | 573 kServiceScopeChromeOS)); |
| 569 // Let's first get the Oauth request token and OAuth1 token+secret. | 574 // Let's first get the Oauth request token and OAuth1 token+secret. |
| 570 // One we get that, we will kick off individial requests for OAuth2 tokens for | 575 // One we get that, we will kick off individial requests for OAuth2 tokens for |
| 571 // all our services. | 576 // all our services. |
| 572 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); | 577 oauth_fetcher_->SetAutoFetchLimit(GaiaOAuthFetcher::OAUTH1_ALL_ACCESS_TOKEN); |
| 573 oauth_fetcher_->StartGetOAuthTokenRequest(); | 578 oauth_fetcher_->StartGetOAuthTokenRequest(); |
| 574 } | 579 } |
| 575 | 580 |
| 576 void LoginUtilsImpl::FetchCookies( | 581 void LoginUtilsImpl::FetchCookies( |
| 577 Profile* profile, | 582 Profile* profile, |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 // Mark login host for deletion after browser starts. This | 957 // Mark login host for deletion after browser starts. This |
| 953 // guarantees that the message loop will be referenced by the | 958 // guarantees that the message loop will be referenced by the |
| 954 // browser before it is dereferenced by the login host. | 959 // browser before it is dereferenced by the login host. |
| 955 if (login_host) { | 960 if (login_host) { |
| 956 login_host->OnSessionStart(); | 961 login_host->OnSessionStart(); |
| 957 login_host = NULL; | 962 login_host = NULL; |
| 958 } | 963 } |
| 959 } | 964 } |
| 960 | 965 |
| 961 } // namespace chromeos | 966 } // namespace chromeos |
| OLD | NEW |