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

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

Issue 7574009: Added OAuth support to TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaked mock for OnOAuthWrapBridgeFailure. Created 9 years, 4 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
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 "https://www.google.com/accounts/OAuthLogin"; 47 "https://www.google.com/accounts/OAuthLogin";
48 48
49 static const char kUserInfoUrl[] = 49 static const char kUserInfoUrl[] =
50 "https://www.googleapis.com/oauth2/v1/userinfo"; 50 "https://www.googleapis.com/oauth2/v1/userinfo";
51 51
52 static const char kOAuthTokenCookie[] = "oauth_token"; 52 static const char kOAuthTokenCookie[] = "oauth_token";
53 53
54 GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer, 54 GaiaOAuthFetcher::GaiaOAuthFetcher(GaiaOAuthConsumer* consumer,
55 net::URLRequestContextGetter* getter, 55 net::URLRequestContextGetter* getter,
56 Profile* profile, 56 Profile* profile,
57 const std::string& service_name,
58 const std::string& service_scope) 57 const std::string& service_scope)
59 : consumer_(consumer), 58 : consumer_(consumer),
60 getter_(getter), 59 getter_(getter),
61 profile_(profile), 60 profile_(profile),
62 popup_(NULL), 61 popup_(NULL),
63 service_name_(service_name),
64 service_scope_(service_scope), 62 service_scope_(service_scope),
65 fetch_pending_(false), 63 fetch_pending_(false),
66 auto_fetch_limit_(ALL_OAUTH_STEPS) {} 64 auto_fetch_limit_(ALL_OAUTH_STEPS) {}
67 65
68 GaiaOAuthFetcher::~GaiaOAuthFetcher() {} 66 GaiaOAuthFetcher::~GaiaOAuthFetcher() {}
69 67
70 bool GaiaOAuthFetcher::HasPendingFetch() { 68 bool GaiaOAuthFetcher::HasPendingFetch() {
71 return fetch_pending_; 69 return fetch_pending_;
72 } 70 }
73 71
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 false, 399 false,
402 this)); 400 this));
403 fetch_pending_ = true; 401 fetch_pending_ = true;
404 fetcher_->Start(); 402 fetcher_->Start();
405 } 403 }
406 404
407 void GaiaOAuthFetcher::StartOAuthWrapBridge( 405 void GaiaOAuthFetcher::StartOAuthWrapBridge(
408 const std::string& oauth1_access_token, 406 const std::string& oauth1_access_token,
409 const std::string& oauth1_access_token_secret, 407 const std::string& oauth1_access_token_secret,
410 const std::string& wrap_token_duration, 408 const std::string& wrap_token_duration,
411 const std::string& service_name,
412 const std::string& service_scope) { 409 const std::string& service_scope) {
413 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!"; 410 DCHECK(!fetch_pending_) << "Tried to fetch two things at once!";
414 411
415 VLOG(1) << "Starting OAuthWrapBridge for: " << service_name; 412 VLOG(1) << "Starting OAuthWrapBridge for: " << service_scope;
416 std::string combined_scope = service_scope + " " + 413 std::string combined_scope = service_scope + " " +
417 kOAuthWrapBridgeUserInfoScope; 414 kOAuthWrapBridgeUserInfoScope;
418 service_name_ = service_name; 415 service_scope_ = service_scope;
419 416
420 // Must outlive fetcher_. 417 // Must outlive fetcher_.
421 request_body_ = MakeOAuthWrapBridgeBody( 418 request_body_ = MakeOAuthWrapBridgeBody(
422 oauth1_access_token, 419 oauth1_access_token,
423 oauth1_access_token_secret, 420 oauth1_access_token_secret,
424 wrap_token_duration, 421 wrap_token_duration,
425 combined_scope); 422 combined_scope);
426 423
427 request_headers_ = ""; 424 request_headers_ = "";
428 fetcher_.reset(CreateGaiaFetcher(getter_, 425 fetcher_.reset(CreateGaiaFetcher(getter_,
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 const net::URLRequestStatus& status, 585 const net::URLRequestStatus& status,
589 int response_code) { 586 int response_code) {
590 if (status.is_success() && response_code == RC_REQUEST_OK) { 587 if (status.is_success() && response_code == RC_REQUEST_OK) {
591 VLOG(1) << "OAuth1 access token fetched."; 588 VLOG(1) << "OAuth1 access token fetched.";
592 std::string secret; 589 std::string secret;
593 std::string token; 590 std::string token;
594 ParseOAuthGetAccessTokenResponse(data, &token, &secret); 591 ParseOAuthGetAccessTokenResponse(data, &token, &secret);
595 consumer_->OnOAuthGetAccessTokenSuccess(token, secret); 592 consumer_->OnOAuthGetAccessTokenSuccess(token, secret);
596 if (ShouldAutoFetch(OAUTH2_SERVICE_ACCESS_TOKEN)) 593 if (ShouldAutoFetch(OAUTH2_SERVICE_ACCESS_TOKEN))
597 StartOAuthWrapBridge( 594 StartOAuthWrapBridge(
598 token, secret, "3600", service_name_, service_scope_); 595 token, secret, GaiaConstants::kGaiaOAuthDuration, service_scope_);
599 } else { 596 } else {
600 consumer_->OnOAuthGetAccessTokenFailure(GenerateAuthError(data, status)); 597 consumer_->OnOAuthGetAccessTokenFailure(GenerateAuthError(data, status));
601 } 598 }
602 } 599 }
603 600
604 void GaiaOAuthFetcher::OnOAuthWrapBridgeFetched( 601 void GaiaOAuthFetcher::OnOAuthWrapBridgeFetched(
605 const std::string& data, 602 const std::string& data,
606 const net::URLRequestStatus& status, 603 const net::URLRequestStatus& status,
607 int response_code) { 604 int response_code) {
608 if (status.is_success() && response_code == RC_REQUEST_OK) { 605 if (status.is_success() && response_code == RC_REQUEST_OK) {
609 VLOG(1) << "OAuth2 access token fetched."; 606 VLOG(1) << "OAuth2 access token fetched.";
610 std::string token; 607 std::string token;
611 std::string expires_in; 608 std::string expires_in;
612 ParseOAuthWrapBridgeResponse(data, &token, &expires_in); 609 ParseOAuthWrapBridgeResponse(data, &token, &expires_in);
613 consumer_->OnOAuthWrapBridgeSuccess(service_name_, token, expires_in); 610 consumer_->OnOAuthWrapBridgeSuccess(service_scope_, token, expires_in);
614 if (ShouldAutoFetch(USER_INFO)) 611 if (ShouldAutoFetch(USER_INFO))
615 StartUserInfo(token); 612 StartUserInfo(token);
616 } else { 613 } else {
617 consumer_->OnOAuthWrapBridgeFailure(GenerateAuthError(data, status)); 614 consumer_->OnOAuthWrapBridgeFailure(service_scope_,
615 GenerateAuthError(data, status));
618 } 616 }
619 } 617 }
620 618
621 void GaiaOAuthFetcher::OnUserInfoFetched( 619 void GaiaOAuthFetcher::OnUserInfoFetched(
622 const std::string& data, 620 const std::string& data,
623 const net::URLRequestStatus& status, 621 const net::URLRequestStatus& status,
624 int response_code) { 622 int response_code) {
625 if (status.is_success() && response_code == RC_REQUEST_OK) { 623 if (status.is_success() && response_code == RC_REQUEST_OK) {
626 std::string email; 624 std::string email;
627 ParseUserInfoResponse(data, &email); 625 ParseUserInfoResponse(data, &email);
(...skipping 24 matching lines...) Expand all
652 } else if (url.spec() == kUserInfoUrl) { 650 } else if (url.spec() == kUserInfoUrl) {
653 OnUserInfoFetched(data, status, response_code); 651 OnUserInfoFetched(data, status, response_code);
654 } else { 652 } else {
655 NOTREACHED(); 653 NOTREACHED();
656 } 654 }
657 } 655 }
658 656
659 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) { 657 bool GaiaOAuthFetcher::ShouldAutoFetch(AutoFetchLimit fetch_step) {
660 return fetch_step <= auto_fetch_limit_; 658 return fetch_step <= auto_fetch_limit_;
661 } 659 }
OLDNEW
« no previous file with comments | « chrome/browser/net/gaia/gaia_oauth_fetcher.h ('k') | chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698