Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Side by Side Diff: chrome/browser/net/gaia/gaia_oauth_fetcher.cc

Issue 8373021: Convert URLFetcher::Delegates to use an interface in content/public/common. Also remove the old U... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync and remove unncessary forward declares Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 "chrome/browser/net/gaia/gaia_oauth_consumer.h" 14 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/tabs/tab_strip_model.h" 16 #include "chrome/browser/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/browser_list.h" 17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
19 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" 19 #include "chrome/common/net/gaia/gaia_auth_fetcher.h"
20 #include "chrome/common/net/gaia/gaia_constants.h" 20 #include "chrome/common/net/gaia/gaia_constants.h"
21 #include "chrome/common/net/gaia/gaia_urls.h" 21 #include "chrome/common/net/gaia/gaia_urls.h"
22 #include "chrome/common/net/gaia/google_service_auth_error.h" 22 #include "chrome/common/net/gaia/google_service_auth_error.h"
23 #include "chrome/common/net/gaia/oauth_request_signer.h" 23 #include "chrome/common/net/gaia/oauth_request_signer.h"
24 #include "chrome/common/net/http_return.h" 24 #include "chrome/common/net/http_return.h"
25 #include "content/public/browser/notification_details.h" 25 #include "content/public/browser/notification_details.h"
26 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
27 #include "content/common/net/url_fetcher.h"
27 #include "grit/chromium_strings.h" 28 #include "grit/chromium_strings.h"
28 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
29 #include "net/url_request/url_request_context_getter.h" 30 #include "net/url_request/url_request_context_getter.h"
30 #include "net/url_request/url_request_status.h" 31 #include "net/url_request/url_request_status.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 33
33 static const char kOAuthTokenCookie[] = "oauth_token"; 34 static const char kOAuthTokenCookie[] = "oauth_token";
34 35
35 GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, 36 GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer,
36 net::URLRequestContextGetter* getter, 37 net::URLRequestContextGetter* getter,
(...skipping 18 matching lines...) Expand all
55 fetch_pending_ = false; 56 fetch_pending_ = false;
56 } 57 }
57 58
58 // static 59 // static
59 URLFetcher* GaiaOAuthFetcher::CreateGaiaFetcher( 60 URLFetcher* GaiaOAuthFetcher::CreateGaiaFetcher(
60 net::URLRequestContextGetter* getter, 61 net::URLRequestContextGetter* getter,
61 const GURL& gaia_gurl, 62 const GURL& gaia_gurl,
62 const std::string& body, 63 const std::string& body,
63 const std::string& headers, 64 const std::string& headers,
64 bool send_cookies, 65 bool send_cookies,
65 URLFetcher::Delegate* delegate) { 66 content::URLFetcherDelegate* delegate) {
66 bool empty_body = body.empty(); 67 bool empty_body = body.empty();
67 URLFetcher* result = 68 URLFetcher* result =
68 URLFetcher::Create(0, 69 URLFetcher::Create(0,
69 gaia_gurl, 70 gaia_gurl,
70 empty_body ? URLFetcher::GET : URLFetcher::POST, 71 empty_body ? URLFetcher::GET : URLFetcher::POST,
71 delegate); 72 delegate);
72 result->set_request_context(getter); 73 result->set_request_context(getter);
73 74
74 // 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
75 // identification as part of requests. We suppress sending any cookies to 76 // identification as part of requests. We suppress sending any cookies to
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 if (status.is_success() && response_code == RC_REQUEST_OK) { 648 if (status.is_success() && response_code == RC_REQUEST_OK) {
648 std::string email; 649 std::string email;
649 ParseUserInfoResponse(data, &email); 650 ParseUserInfoResponse(data, &email);
650 VLOG(1) << "GAIA user info fetched for " << email << "."; 651 VLOG(1) << "GAIA user info fetched for " << email << ".";
651 consumer_->OnUserInfoSuccess(email); 652 consumer_->OnUserInfoSuccess(email);
652 } else { 653 } else {
653 consumer_->OnUserInfoFailure(GenerateAuthError(data, status)); 654 consumer_->OnUserInfoFailure(GenerateAuthError(data, status));
654 } 655 }
655 } 656 }
656 657
657 void GaiaOAuthFetcher::OnURLFetchComplete(const URLFetcher* source, 658 void GaiaOAuthFetcher::OnURLFetchComplete(const URLFetcher* source) {
658 const GURL& url,
659 const net::URLRequestStatus& status,
660 int response_code,
661 const net::ResponseCookies& cookies,
662 const std::string& data) {
663 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below). 659 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below).
664 scoped_ptr<URLFetcher> current_fetcher(fetcher_.release()); 660 scoped_ptr<URLFetcher> current_fetcher(fetcher_.release());
665 fetch_pending_ = false; 661 fetch_pending_ = false;
666 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 662 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
663 GURL url = source->url();
664 std::string data;
665 source->GetResponseAsString(&data);
666 net::URLRequestStatus status = source->status();
667 int response_code = source->response_code();
667 if (StartsWithASCII(url.spec(), gaia_urls->get_oauth_token_url(), true)) { 668 if (StartsWithASCII(url.spec(), gaia_urls->get_oauth_token_url(), true)) {
668 OnGetOAuthTokenUrlFetched(cookies, status, response_code); 669 OnGetOAuthTokenUrlFetched(source->cookies(), status, response_code);
669 } else if (url.spec() == gaia_urls->oauth1_login_url()) { 670 } else if (url.spec() == gaia_urls->oauth1_login_url()) {
670 OnOAuthLoginFetched(data, status, response_code); 671 OnOAuthLoginFetched(data, status, response_code);
671 } else if (url.spec() == gaia_urls->oauth_get_access_token_url()) { 672 } else if (url.spec() == gaia_urls->oauth_get_access_token_url()) {
672 OnOAuthGetAccessTokenFetched(data, status, response_code); 673 OnOAuthGetAccessTokenFetched(data, status, response_code);
673 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { 674 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) {
674 OnOAuthWrapBridgeFetched(data, status, response_code); 675 OnOAuthWrapBridgeFetched(data, status, response_code);
675 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { 676 } else if (url.spec() == gaia_urls->oauth_user_info_url()) {
676 OnUserInfoFetched(data, status, response_code); 677 OnUserInfoFetched(data, status, response_code);
677 } else if (StartsWithASCII(url.spec(), 678 } else if (StartsWithASCII(url.spec(),
678 gaia_urls->oauth_revoke_token_url(), 679 gaia_urls->oauth_revoke_token_url(),
679 true)) { 680 true)) {
680 OnOAuthRevokeTokenFetched(data, status, response_code); 681 OnOAuthRevokeTokenFetched(data, status, response_code);
681 } else { 682 } else {
682 NOTREACHED(); 683 NOTREACHED();
683 } 684 }
684 } 685 }
685 686
686 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { 687 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) {
687 return fetch_step <= auto_fetch_limit_; 688 return fetch_step <= auto_fetch_limit_;
688 } 689 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698