Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/net/gaia/gaia_oauth_fetcher.h" | 5 #include "chrome/browser/net/gaia/gaia_oauth_fetcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | |
| 14 #include "base/values.h" | 15 #include "base/values.h" |
| 15 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 16 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
| 16 #include "chrome/common/net/url_util.h" | 17 #include "chrome/common/net/url_util.h" |
| 17 #include "google_apis/gaia/gaia_auth_fetcher.h" | 18 #include "google_apis/gaia/gaia_auth_fetcher.h" |
| 18 #include "google_apis/gaia/gaia_constants.h" | 19 #include "google_apis/gaia/gaia_constants.h" |
| 19 #include "google_apis/gaia/gaia_urls.h" | 20 #include "google_apis/gaia/gaia_urls.h" |
| 20 #include "google_apis/gaia/oauth_request_signer.h" | 21 #include "google_apis/gaia/oauth_request_signer.h" |
| 21 #include "grit/chromium_strings.h" | 22 #include "grit/chromium_strings.h" |
| 23 #include "net/base/escape.h" | |
| 22 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 23 #include "net/cookies/parsed_cookie.h" | 25 #include "net/cookies/parsed_cookie.h" |
| 24 #include "net/http/http_status_code.h" | 26 #include "net/http/http_status_code.h" |
| 25 #include "net/url_request/url_fetcher.h" | 27 #include "net/url_request/url_fetcher.h" |
| 26 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 27 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 29 | 31 |
| 30 static const char kOAuthTokenCookie[] = "oauth_token"; | 32 namespace { |
| 33 | |
| 34 const char kOAuthTokenCookie[] = "oauth_token"; | |
| 35 const char kOAuth2LoginBodyFormat[] = | |
| 36 "source=%s&" | |
| 37 "service=%s"; | |
|
xiyuan
2013/01/07 23:07:55
kOAuth2LoginBodyFormat is not used anywhere. And I
zel
2013/01/08 02:05:41
changes to gaia_oauth_fetcher.cc/h are reverted no
| |
| 38 | |
| 39 } // namespace | |
| 31 | 40 |
| 32 GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, | 41 GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, |
| 33 net::URLRequestContextGetter* getter, | 42 net::URLRequestContextGetter* getter, |
| 34 const std::string& service_scope) | 43 const std::string& service_scope) |
| 35 : consumer_(consumer), | 44 : consumer_(consumer), |
| 36 getter_(getter), | 45 getter_(getter), |
| 37 service_scope_(service_scope), | 46 service_scope_(service_scope), |
| 38 fetch_pending_(false), | 47 fetch_pending_(false), |
| 39 auto_fetch_limit_(USER_INFO) {} | 48 auto_fetch_limit_(USER_INFO) {} |
| 40 | 49 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); | 256 DictionaryValue* dict = static_cast<DictionaryValue*>(value.get()); |
| 248 if (dict->Get("email", &email_value)) { | 257 if (dict->Get("email", &email_value)) { |
| 249 if (email_value->GetType() == base::Value::TYPE_STRING) { | 258 if (email_value->GetType() == base::Value::TYPE_STRING) { |
| 250 StringValue* email = static_cast<StringValue*>(email_value); | 259 StringValue* email = static_cast<StringValue*>(email_value); |
| 251 email->GetAsString(email_result); | 260 email->GetAsString(email_result); |
| 252 } | 261 } |
| 253 } | 262 } |
| 254 } | 263 } |
| 255 } | 264 } |
| 256 | 265 |
| 257 void GaiaOAuthFetcher::StartOAuthLogin( | 266 void GaiaOAuthFetcher::StartOAuth1Login( |
| 258 const char* source, | 267 const char* source, |
| 259 const char* service, | 268 const char* service, |
| 260 const std::string& oauth1_access_token, | 269 const std::string& oauth1_access_token, |
| 261 const std::string& oauth1_access_token_secret) { | 270 const std::string& oauth1_access_token_secret) { |
| 262 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; | 271 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; |
| 263 | 272 |
| 264 request_type_ = OAUTH1_LOGIN; | 273 request_type_ = OAUTH1_LOGIN; |
| 265 // Must outlive fetcher_. | 274 // Must outlive fetcher_. |
| 266 request_body_ = MakeOAuthLoginBody(source, service, oauth1_access_token, | 275 request_body_ = MakeOAuthLoginBody(source, service, oauth1_access_token, |
| 267 oauth1_access_token_secret); | 276 oauth1_access_token_secret); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 switch (request_type_) { | 551 switch (request_type_) { |
| 543 case OAUTH1_LOGIN: | 552 case OAUTH1_LOGIN: |
| 544 OnOAuthLoginFetched(data, status, response_code); | 553 OnOAuthLoginFetched(data, status, response_code); |
| 545 break; | 554 break; |
| 546 case OAUTH1_REQUEST_TOKEN: | 555 case OAUTH1_REQUEST_TOKEN: |
| 547 OnGetOAuthTokenUrlFetched(source->GetCookies(), status, response_code); | 556 OnGetOAuthTokenUrlFetched(source->GetCookies(), status, response_code); |
| 548 break; | 557 break; |
| 549 case OAUTH1_ALL_ACCESS_TOKEN: | 558 case OAUTH1_ALL_ACCESS_TOKEN: |
| 550 OnOAuthGetAccessTokenFetched(data, status, response_code); | 559 OnOAuthGetAccessTokenFetched(data, status, response_code); |
| 551 break; | 560 break; |
| 561 case OAUTH2_LOGIN: | |
| 562 OnOAuthLoginFetched(data, status, response_code); | |
| 563 break; | |
| 552 case OAUTH2_SERVICE_ACCESS_TOKEN: | 564 case OAUTH2_SERVICE_ACCESS_TOKEN: |
| 553 OnOAuthWrapBridgeFetched(data, status, response_code); | 565 OnOAuthWrapBridgeFetched(data, status, response_code); |
| 554 break; | 566 break; |
| 567 case OAUTH2_REVOKE_TOKEN: | |
| 568 OnOAuthRevokeTokenFetched(data, status, response_code); | |
| 569 break; | |
| 555 case USER_INFO: | 570 case USER_INFO: |
| 556 OnUserInfoFetched(data, status, response_code); | 571 OnUserInfoFetched(data, status, response_code); |
| 557 break; | 572 break; |
| 558 case OAUTH2_REVOKE_TOKEN: | |
| 559 OnOAuthRevokeTokenFetched(data, status, response_code); | |
| 560 break; | |
| 561 } | 573 } |
| 562 } | 574 } |
| 563 | 575 |
| 564 bool GaiaOAuthFetcher::ShouldAutoFetch(RequestType fetch_step) { | 576 bool GaiaOAuthFetcher::ShouldAutoFetch(RequestType fetch_step) { |
| 565 return fetch_step <= auto_fetch_limit_; | 577 return fetch_step <= auto_fetch_limit_; |
| 566 } | 578 } |
| OLD | NEW |