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/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 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 bool GaiaOAuthFetcher::HasPendingFetch() { | 50 bool GaiaOAuthFetcher::HasPendingFetch() { |
51 return fetch_pending_; | 51 return fetch_pending_; |
52 } | 52 } |
53 | 53 |
54 void GaiaOAuthFetcher::CancelRequest() { | 54 void GaiaOAuthFetcher::CancelRequest() { |
55 fetcher_.reset(); | 55 fetcher_.reset(); |
56 fetch_pending_ = false; | 56 fetch_pending_ = false; |
57 } | 57 } |
58 | 58 |
59 // static | 59 // static |
60 URLFetcher* GaiaOAuthFetcher::CreateGaiaFetcher( | 60 content::URLFetcher* GaiaOAuthFetcher::CreateGaiaFetcher( |
61 net::URLRequestContextGetter* getter, | 61 net::URLRequestContextGetter* getter, |
62 const GURL& gaia_gurl, | 62 const GURL& gaia_gurl, |
63 const std::string& body, | 63 const std::string& body, |
64 const std::string& headers, | 64 const std::string& headers, |
65 bool send_cookies, | 65 bool send_cookies, |
66 content::URLFetcherDelegate* delegate) { | 66 content::URLFetcherDelegate* delegate) { |
67 bool empty_body = body.empty(); | 67 bool empty_body = body.empty(); |
68 URLFetcher* result = | 68 URLFetcher* result = |
69 URLFetcher::Create(0, | 69 URLFetcher::Create(0, |
70 gaia_gurl, | 70 gaia_gurl, |
71 empty_body ? URLFetcher::GET : URLFetcher::POST, | 71 empty_body ? URLFetcher::GET : URLFetcher::POST, |
72 delegate); | 72 delegate); |
73 result->set_request_context(getter); | 73 result->SetRequestContext(getter); |
74 | 74 |
75 // The Gaia/OAuth token exchange requests do not require any cookie-based | 75 // The Gaia/OAuth token exchange requests do not require any cookie-based |
76 // identification as part of requests. We suppress sending any cookies to | 76 // identification as part of requests. We suppress sending any cookies to |
77 // maintain a separation between the user's browsing and Chrome's internal | 77 // maintain a separation between the user's browsing and Chrome's internal |
78 // services. Where such mixing is desired (prelogin, autologin | 78 // services. Where such mixing is desired (prelogin, autologin |
79 // or chromeos login), it will be done explicitly. | 79 // or chromeos login), it will be done explicitly. |
80 if (!send_cookies) | 80 if (!send_cookies) |
81 result->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); | 81 result->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES); |
82 | 82 |
83 if (!empty_body) | 83 if (!empty_body) |
84 result->set_upload_data("application/x-www-form-urlencoded", body); | 84 result->SetUploadData("application/x-www-form-urlencoded", body); |
85 if (!headers.empty()) | 85 if (!headers.empty()) |
86 result->set_extra_request_headers(headers); | 86 result->SetExtraRequestHeaders(headers); |
87 | 87 |
88 return result; | 88 return result; |
89 } | 89 } |
90 | 90 |
91 // static | 91 // static |
92 GURL GaiaOAuthFetcher::MakeGetOAuthTokenUrl( | 92 GURL GaiaOAuthFetcher::MakeGetOAuthTokenUrl( |
93 const std::string& oauth1_login_scope, | 93 const std::string& oauth1_login_scope, |
94 const std::string& product_name) { | 94 const std::string& product_name) { |
95 return GURL(GaiaUrls::GetInstance()->get_oauth_token_url() + | 95 return GURL(GaiaUrls::GetInstance()->get_oauth_token_url() + |
96 "?scope=" + oauth1_login_scope + | 96 "?scope=" + oauth1_login_scope + |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 if (status.is_success() && response_code == RC_REQUEST_OK) { | 648 if (status.is_success() && response_code == RC_REQUEST_OK) { |
649 std::string email; | 649 std::string email; |
650 ParseUserInfoResponse(data, &email); | 650 ParseUserInfoResponse(data, &email); |
651 VLOG(1) << "GAIA user info fetched for " << email << "."; | 651 VLOG(1) << "GAIA user info fetched for " << email << "."; |
652 consumer_->OnUserInfoSuccess(email); | 652 consumer_->OnUserInfoSuccess(email); |
653 } else { | 653 } else { |
654 consumer_->OnUserInfoFailure(GenerateAuthError(data, status)); | 654 consumer_->OnUserInfoFailure(GenerateAuthError(data, status)); |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 void GaiaOAuthFetcher::OnURLFetchComplete(const URLFetcher* source) { | 658 void GaiaOAuthFetcher::OnURLFetchComplete(const content::URLFetcher* source) { |
659 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below). | 659 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below). |
660 scoped_ptr<URLFetcher> current_fetcher(fetcher_.release()); | 660 scoped_ptr<content::URLFetcher> current_fetcher(fetcher_.release()); |
661 fetch_pending_ = false; | 661 fetch_pending_ = false; |
662 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 662 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
663 GURL url = source->url(); | 663 GURL url = source->GetUrl(); |
664 std::string data; | 664 std::string data; |
665 source->GetResponseAsString(&data); | 665 source->GetResponseAsString(&data); |
666 net::URLRequestStatus status = source->status(); | 666 net::URLRequestStatus status = source->GetStatus(); |
667 int response_code = source->response_code(); | 667 int response_code = source->GetResponseCode(); |
668 if (StartsWithASCII(url.spec(), gaia_urls->get_oauth_token_url(), true)) { | 668 if (StartsWithASCII(url.spec(), gaia_urls->get_oauth_token_url(), true)) { |
669 OnGetOAuthTokenUrlFetched(source->cookies(), status, response_code); | 669 OnGetOAuthTokenUrlFetched(source->GetCookies(), status, response_code); |
670 } else if (url.spec() == gaia_urls->oauth1_login_url()) { | 670 } else if (url.spec() == gaia_urls->oauth1_login_url()) { |
671 OnOAuthLoginFetched(data, status, response_code); | 671 OnOAuthLoginFetched(data, status, response_code); |
672 } else if (url.spec() == gaia_urls->oauth_get_access_token_url()) { | 672 } else if (url.spec() == gaia_urls->oauth_get_access_token_url()) { |
673 OnOAuthGetAccessTokenFetched(data, status, response_code); | 673 OnOAuthGetAccessTokenFetched(data, status, response_code); |
674 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { | 674 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { |
675 OnOAuthWrapBridgeFetched(data, status, response_code); | 675 OnOAuthWrapBridgeFetched(data, status, response_code); |
676 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { | 676 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { |
677 OnUserInfoFetched(data, status, response_code); | 677 OnUserInfoFetched(data, status, response_code); |
678 } else if (StartsWithASCII(url.spec(), | 678 } else if (StartsWithASCII(url.spec(), |
679 gaia_urls->oauth_revoke_token_url(), | 679 gaia_urls->oauth_revoke_token_url(), |
680 true)) { | 680 true)) { |
681 OnOAuthRevokeTokenFetched(data, status, response_code); | 681 OnOAuthRevokeTokenFetched(data, status, response_code); |
682 } else { | 682 } else { |
683 NOTREACHED(); | 683 NOTREACHED(); |
684 } | 684 } |
685 } | 685 } |
686 | 686 |
687 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { | 687 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { |
688 return fetch_step <= auto_fetch_limit_; | 688 return fetch_step <= auto_fetch_limit_; |
689 } | 689 } |
OLD | NEW |