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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 GURL url(GaiaUrls::GetInstance()->oauth_revoke_token_url()); | 454 GURL url(GaiaUrls::GetInstance()->oauth_revoke_token_url()); |
455 fetcher_.reset(CreateGaiaFetcher(getter_, url, request_body_, | 455 fetcher_.reset(CreateGaiaFetcher(getter_, url, request_body_, |
456 request_headers_, false, this)); | 456 request_headers_, false, this)); |
457 fetch_pending_ = true; | 457 fetch_pending_ = true; |
458 fetcher_->Start(); | 458 fetcher_->Start(); |
459 } | 459 } |
460 | 460 |
461 // static | 461 // static |
462 GoogleServiceAuthError GaiaOAuthFetcher::GenerateAuthError( | 462 GoogleServiceAuthError GaiaOAuthFetcher::GenerateAuthError( |
463 const std::string& data, | 463 const std::string& data, |
464 const net::URLRequestStatus& status) { | 464 const net::URLRequestStatus& status, |
| 465 int response_code) { |
465 if (!status.is_success()) { | 466 if (!status.is_success()) { |
466 if (status.status() == net::URLRequestStatus::CANCELED) { | 467 if (status.status() == net::URLRequestStatus::CANCELED) { |
467 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); | 468 return GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED); |
468 } else { | 469 } else { |
469 LOG(WARNING) << "Could not reach Google Accounts servers: errno " | 470 LOG(WARNING) << "Could not reach Google Accounts servers: errno " |
470 << status.error(); | 471 << status.error(); |
471 return GoogleServiceAuthError::FromConnectionError(status.error()); | 472 return GoogleServiceAuthError::FromConnectionError(status.error()); |
472 } | 473 } |
473 } else { | 474 } else { |
474 LOG(WARNING) << "Unrecognized response from Google Accounts servers."; | 475 LOG(WARNING) << "Unrecognized response from Google Accounts servers " |
| 476 << "code " << response_code << " data " << data; |
475 return GoogleServiceAuthError( | 477 return GoogleServiceAuthError( |
476 GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 478 GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
477 } | 479 } |
478 | 480 |
479 NOTREACHED(); | 481 NOTREACHED(); |
480 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); | 482 return GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE); |
481 } | 483 } |
482 | 484 |
483 void GaiaOAuthFetcher::Observe(int type, | 485 void GaiaOAuthFetcher::Observe(int type, |
484 const content::NotificationSource& source, | 486 const content::NotificationSource& source, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 if (status.is_success() && response_code == RC_REQUEST_OK) { | 601 if (status.is_success() && response_code == RC_REQUEST_OK) { |
600 VLOG(1) << "OAuth1 access token fetched."; | 602 VLOG(1) << "OAuth1 access token fetched."; |
601 std::string secret; | 603 std::string secret; |
602 std::string token; | 604 std::string token; |
603 ParseOAuthGetAccessTokenResponse(data, &token, &secret); | 605 ParseOAuthGetAccessTokenResponse(data, &token, &secret); |
604 consumer_->OnOAuthGetAccessTokenSuccess(token, secret); | 606 consumer_->OnOAuthGetAccessTokenSuccess(token, secret); |
605 if (ShouldAutoFetch(OAUTH2_SERVICE_ACCESS_TOKEN)) | 607 if (ShouldAutoFetch(OAUTH2_SERVICE_ACCESS_TOKEN)) |
606 StartOAuthWrapBridge( | 608 StartOAuthWrapBridge( |
607 token, secret, GaiaConstants::kGaiaOAuthDuration, service_scope_); | 609 token, secret, GaiaConstants::kGaiaOAuthDuration, service_scope_); |
608 } else { | 610 } else { |
609 consumer_->OnOAuthGetAccessTokenFailure(GenerateAuthError(data, status)); | 611 consumer_->OnOAuthGetAccessTokenFailure(GenerateAuthError(data, status, |
| 612 response_code)); |
610 } | 613 } |
611 } | 614 } |
612 | 615 |
613 void GaiaOAuthFetcher::OnOAuthWrapBridgeFetched( | 616 void GaiaOAuthFetcher::OnOAuthWrapBridgeFetched( |
614 const std::string& data, | 617 const std::string& data, |
615 const net::URLRequestStatus& status, | 618 const net::URLRequestStatus& status, |
616 int response_code) { | 619 int response_code) { |
617 if (status.is_success() && response_code == RC_REQUEST_OK) { | 620 if (status.is_success() && response_code == RC_REQUEST_OK) { |
618 VLOG(1) << "OAuth2 access token fetched."; | 621 VLOG(1) << "OAuth2 access token fetched."; |
619 std::string token; | 622 std::string token; |
620 std::string expires_in; | 623 std::string expires_in; |
621 ParseOAuthWrapBridgeResponse(data, &token, &expires_in); | 624 ParseOAuthWrapBridgeResponse(data, &token, &expires_in); |
622 consumer_->OnOAuthWrapBridgeSuccess(service_scope_, token, expires_in); | 625 consumer_->OnOAuthWrapBridgeSuccess(service_scope_, token, expires_in); |
623 if (ShouldAutoFetch(USER_INFO)) | 626 if (ShouldAutoFetch(USER_INFO)) |
624 StartUserInfo(token); | 627 StartUserInfo(token); |
625 } else { | 628 } else { |
626 consumer_->OnOAuthWrapBridgeFailure(service_scope_, | 629 consumer_->OnOAuthWrapBridgeFailure(service_scope_, |
627 GenerateAuthError(data, status)); | 630 GenerateAuthError(data, status, |
| 631 response_code)); |
628 } | 632 } |
629 } | 633 } |
630 | 634 |
631 void GaiaOAuthFetcher::OnOAuthRevokeTokenFetched( | 635 void GaiaOAuthFetcher::OnOAuthRevokeTokenFetched( |
632 const std::string& data, | 636 const std::string& data, |
633 const net::URLRequestStatus& status, | 637 const net::URLRequestStatus& status, |
634 int response_code) { | 638 int response_code) { |
635 if (status.is_success() && response_code == RC_REQUEST_OK) { | 639 if (status.is_success() && response_code == RC_REQUEST_OK) { |
636 consumer_->OnOAuthRevokeTokenSuccess(); | 640 consumer_->OnOAuthRevokeTokenSuccess(); |
637 } else { | 641 } else { |
638 LOG(ERROR) << "Token revocation failure " << response_code << ": " << data; | 642 LOG(ERROR) << "Token revocation failure " << response_code << ": " << data; |
639 consumer_->OnOAuthRevokeTokenFailure(GenerateAuthError(data, status)); | 643 consumer_->OnOAuthRevokeTokenFailure(GenerateAuthError(data, status, |
| 644 response_code)); |
640 } | 645 } |
641 } | 646 } |
642 | 647 |
643 void GaiaOAuthFetcher::OnUserInfoFetched( | 648 void GaiaOAuthFetcher::OnUserInfoFetched( |
644 const std::string& data, | 649 const std::string& data, |
645 const net::URLRequestStatus& status, | 650 const net::URLRequestStatus& status, |
646 int response_code) { | 651 int response_code) { |
647 if (status.is_success() && response_code == RC_REQUEST_OK) { | 652 if (status.is_success() && response_code == RC_REQUEST_OK) { |
648 std::string email; | 653 std::string email; |
649 ParseUserInfoResponse(data, &email); | 654 ParseUserInfoResponse(data, &email); |
650 VLOG(1) << "GAIA user info fetched for " << email << "."; | 655 VLOG(1) << "GAIA user info fetched for " << email << "."; |
651 consumer_->OnUserInfoSuccess(email); | 656 consumer_->OnUserInfoSuccess(email); |
652 } else { | 657 } else { |
653 consumer_->OnUserInfoFailure(GenerateAuthError(data, status)); | 658 consumer_->OnUserInfoFailure(GenerateAuthError(data, status, |
| 659 response_code)); |
654 } | 660 } |
655 } | 661 } |
656 | 662 |
657 void GaiaOAuthFetcher::OnURLFetchComplete(const content::URLFetcher* source) { | 663 void GaiaOAuthFetcher::OnURLFetchComplete(const content::URLFetcher* source) { |
658 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below). | 664 // Keep |fetcher_| around to avoid invalidating its |status| (accessed below). |
659 scoped_ptr<content::URLFetcher> current_fetcher(fetcher_.release()); | 665 scoped_ptr<content::URLFetcher> current_fetcher(fetcher_.release()); |
660 fetch_pending_ = false; | 666 fetch_pending_ = false; |
661 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); | 667 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); |
662 GURL url = source->GetURL(); | 668 GURL url = source->GetURL(); |
663 std::string data; | 669 std::string data; |
(...skipping 15 matching lines...) Expand all Loading... |
679 true)) { | 685 true)) { |
680 OnOAuthRevokeTokenFetched(data, status, response_code); | 686 OnOAuthRevokeTokenFetched(data, status, response_code); |
681 } else { | 687 } else { |
682 NOTREACHED(); | 688 NOTREACHED(); |
683 } | 689 } |
684 } | 690 } |
685 | 691 |
686 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { | 692 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { |
687 return fetch_step <= auto_fetch_limit_; | 693 return fetch_step <= auto_fetch_limit_; |
688 } | 694 } |
OLD | NEW |