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 |
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/browser_url_util.h" |
14 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 15 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/tabs/tab_strip_model.h" | 17 #include "chrome/browser/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
18 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
19 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 20 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
20 #include "chrome/common/net/gaia/gaia_constants.h" | 21 #include "chrome/common/net/gaia/gaia_constants.h" |
21 #include "chrome/common/net/gaia/gaia_urls.h" | 22 #include "chrome/common/net/gaia/gaia_urls.h" |
22 #include "chrome/common/net/gaia/google_service_auth_error.h" | 23 #include "chrome/common/net/gaia/google_service_auth_error.h" |
23 #include "chrome/common/net/gaia/oauth_request_signer.h" | 24 #include "chrome/common/net/gaia/oauth_request_signer.h" |
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 void GaiaOAuthFetcher::OnURLFetchComplete(const content::URLFetcher* source) { | 665 void GaiaOAuthFetcher::OnURLFetchComplete(const content::URLFetcher* source) { |
665 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below). | 666 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below). |
666 scoped_ptr<content::URLFetcher> current_fetcher(fetcher_.release()); | 667 scoped_ptr<content::URLFetcher> current_fetcher(fetcher_.release()); |
667 fetch_pending_ = false; | 668 fetch_pending_ = false; |
668 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 669 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
669 GURL url = source->GetURL(); | 670 GURL url = source->GetURL(); |
670 std::string data; | 671 std::string data; |
671 source->GetResponseAsString(&data); | 672 source->GetResponseAsString(&data); |
672 net::URLRequestStatus status = source->GetStatus(); | 673 net::URLRequestStatus status = source->GetStatus(); |
673 int response_code = source->GetResponseCode(); | 674 int response_code = source->GetResponseCode(); |
| 675 VLOG(1) << "GaiaOAuthFetcher::OnURLFetchComplete" |
| 676 << ", url=" << url.spec() |
| 677 << ", status=" << response_code; |
674 if (StartsWithASCII(url.spec(), gaia_urls->get_oauth_token_url(), true)) { | 678 if (StartsWithASCII(url.spec(), gaia_urls->get_oauth_token_url(), true)) { |
675 OnGetOAuthTokenUrlFetched(source->GetCookies(), status, response_code); | 679 OnGetOAuthTokenUrlFetched(source->GetCookies(), status, response_code); |
676 } else if (url.spec() == gaia_urls->oauth1_login_url()) { | 680 } else if (url.spec() == gaia_urls->oauth1_login_url()) { |
677 OnOAuthLoginFetched(data, status, response_code); | 681 OnOAuthLoginFetched(data, status, response_code); |
678 } else if (url.spec() == gaia_urls->oauth_get_access_token_url()) { | 682 } else if (url.spec() == gaia_urls->oauth_get_access_token_url()) { |
679 OnOAuthGetAccessTokenFetched(data, status, response_code); | 683 OnOAuthGetAccessTokenFetched(data, status, response_code); |
680 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { | 684 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { |
681 OnOAuthWrapBridgeFetched(data, status, response_code); | 685 OnOAuthWrapBridgeFetched(data, status, response_code); |
682 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { | 686 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { |
683 OnUserInfoFetched(data, status, response_code); | 687 OnUserInfoFetched(data, status, response_code); |
684 } else if (StartsWithASCII(url.spec(), | 688 } else if (StartsWithASCII(url.spec(), |
685 gaia_urls->oauth_revoke_token_url(), | 689 gaia_urls->oauth_revoke_token_url(), |
686 true)) { | 690 true)) { |
687 OnOAuthRevokeTokenFetched(data, status, response_code); | 691 OnOAuthRevokeTokenFetched(data, status, response_code); |
688 } else { | 692 } else { |
689 NOTREACHED(); | 693 // Invalid cookies cause Gaia to redirect to ServiceLogin. Check if |
| 694 // this is the case and report failure properly. |
| 695 std::string url_no_query = url.GetOrigin().spec() + url.path().substr(1); |
| 696 std::string continue_url; |
| 697 if (url_no_query == gaia_urls->service_login_url() && |
| 698 chrome_browser_net::GetValueForKeyInQuery(url, "continue", |
| 699 &continue_url)) { |
| 700 LOG(ERROR) << "GaiaOAuthFetcher redirected to service login" |
| 701 << " , url=" << url.spec(); |
| 702 |
| 703 if (StartsWithASCII(continue_url, |
| 704 gaia_urls->get_oauth_token_url(), |
| 705 true)) { |
| 706 consumer_->OnGetOAuthTokenFailure(GoogleServiceAuthError( |
| 707 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 708 } else if (continue_url == gaia_urls->oauth1_login_url()) { |
| 709 consumer_->OnOAuthLoginFailure(GoogleServiceAuthError( |
| 710 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 711 } else if (continue_url == gaia_urls->oauth_get_access_token_url()) { |
| 712 consumer_->OnOAuthGetAccessTokenFailure(GoogleServiceAuthError( |
| 713 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 714 } else if (continue_url == gaia_urls->oauth_wrap_bridge_url()) { |
| 715 consumer_->OnOAuthWrapBridgeFailure(service_scope_, |
| 716 GoogleServiceAuthError( |
| 717 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 718 } else if (continue_url == gaia_urls->oauth_user_info_url()) { |
| 719 consumer_->OnUserInfoFailure(GoogleServiceAuthError( |
| 720 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 721 } else if (StartsWithASCII(continue_url, |
| 722 gaia_urls->oauth_revoke_token_url(), |
| 723 true)) { |
| 724 consumer_->OnOAuthRevokeTokenFailure(GoogleServiceAuthError( |
| 725 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); |
| 726 } else { |
| 727 NOTREACHED(); |
| 728 } |
| 729 } else { |
| 730 NOTREACHED() << "GaiaOAuthFetcher unknown url=" << url.spec(); |
| 731 } |
690 } | 732 } |
691 } | 733 } |
692 | 734 |
693 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { | 735 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { |
694 return fetch_step <= auto_fetch_limit_; | 736 return fetch_step <= auto_fetch_limit_; |
695 } | 737 } |
OLD | NEW |