OLD | NEW |
1 // Copyright (c) 2012 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" | |
15 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" | 14 #include "chrome/browser/net/gaia/gaia_oauth_consumer.h" |
16 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/tabs/tab_strip_model.h" | 16 #include "chrome/browser/tabs/tab_strip_model.h" |
18 #include "chrome/browser/ui/browser_list.h" | 17 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" | 19 #include "chrome/common/net/gaia/gaia_auth_fetcher.h" |
21 #include "chrome/common/net/gaia/gaia_constants.h" | 20 #include "chrome/common/net/gaia/gaia_constants.h" |
22 #include "chrome/common/net/gaia/gaia_urls.h" | 21 #include "chrome/common/net/gaia/gaia_urls.h" |
23 #include "chrome/common/net/gaia/google_service_auth_error.h" | 22 #include "chrome/common/net/gaia/google_service_auth_error.h" |
24 #include "chrome/common/net/gaia/oauth_request_signer.h" | 23 #include "chrome/common/net/gaia/oauth_request_signer.h" |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 OnOAuthGetAccessTokenFetched(data, status, response_code); | 679 OnOAuthGetAccessTokenFetched(data, status, response_code); |
681 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { | 680 } else if (url.spec() == gaia_urls->oauth_wrap_bridge_url()) { |
682 OnOAuthWrapBridgeFetched(data, status, response_code); | 681 OnOAuthWrapBridgeFetched(data, status, response_code); |
683 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { | 682 } else if (url.spec() == gaia_urls->oauth_user_info_url()) { |
684 OnUserInfoFetched(data, status, response_code); | 683 OnUserInfoFetched(data, status, response_code); |
685 } else if (StartsWithASCII(url.spec(), | 684 } else if (StartsWithASCII(url.spec(), |
686 gaia_urls->oauth_revoke_token_url(), | 685 gaia_urls->oauth_revoke_token_url(), |
687 true)) { | 686 true)) { |
688 OnOAuthRevokeTokenFetched(data, status, response_code); | 687 OnOAuthRevokeTokenFetched(data, status, response_code); |
689 } else { | 688 } else { |
690 // Invalid cookies cause Gaia to redirect to ServiceLogin. Check if | 689 NOTREACHED(); |
691 // this is the case and report failure properly. | |
692 std::string url_no_query = url.GetOrigin().spec() + url.path().substr(1); | |
693 std::string continue_url; | |
694 if (url_no_query == gaia_urls->service_login_url() && | |
695 chrome_browser_net::GetValueForKeyInQuery(url, "continue", | |
696 &continue_url)) { | |
697 LOG(ERROR) << "GaiaOAuthFetcher redirected to service login" | |
698 << " , url=" << url.spec(); | |
699 | |
700 if (StartsWithASCII(continue_url, | |
701 gaia_urls->get_oauth_token_url(), | |
702 true)) { | |
703 consumer_->OnGetOAuthTokenFailure(GoogleServiceAuthError( | |
704 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | |
705 } else if (continue_url == gaia_urls->oauth1_login_url()) { | |
706 consumer_->OnOAuthLoginFailure(GoogleServiceAuthError( | |
707 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | |
708 } else if (continue_url == gaia_urls->oauth_get_access_token_url()) { | |
709 consumer_->OnOAuthGetAccessTokenFailure(GoogleServiceAuthError( | |
710 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | |
711 } else if (continue_url == gaia_urls->oauth_wrap_bridge_url()) { | |
712 consumer_->OnOAuthWrapBridgeFailure(service_scope_, | |
713 GoogleServiceAuthError( | |
714 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | |
715 } else if (continue_url == gaia_urls->oauth_user_info_url()) { | |
716 consumer_->OnUserInfoFailure(GoogleServiceAuthError( | |
717 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | |
718 } else if (StartsWithASCII(continue_url, | |
719 gaia_urls->oauth_revoke_token_url(), | |
720 true)) { | |
721 consumer_->OnOAuthRevokeTokenFailure(GoogleServiceAuthError( | |
722 GoogleServiceAuthError::SERVICE_UNAVAILABLE)); | |
723 } else { | |
724 NOTREACHED(); | |
725 } | |
726 } else { | |
727 NOTREACHED() << "GaiaOAuthFetcher unknown url=" << url.spec(); | |
728 } | |
729 } | 690 } |
730 } | 691 } |
731 | 692 |
732 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { | 693 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { |
733 return fetch_step <= auto_fetch_limit_; | 694 return fetch_step <= auto_fetch_limit_; |
734 } | 695 } |
OLD | NEW |