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

Unified Diff: remoting/host/gaia_oauth_client.cc

Issue 10637008: Remove UrlFetcher from remoting and use the one in net instead. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | remoting/host/host_port_allocator.h » ('j') | remoting/host/host_port_allocator.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/gaia_oauth_client.cc
diff --git a/remoting/host/gaia_oauth_client.cc b/remoting/host/gaia_oauth_client.cc
index db7d449faef1b1d741520f8e8b53a41ec961886c..eecdb5a063ee8c5b3f5812b72675a71b142645e2 100644
--- a/remoting/host/gaia_oauth_client.cc
+++ b/remoting/host/gaia_oauth_client.cc
@@ -5,6 +5,7 @@
#include "remoting/host/gaia_oauth_client.h"
#include "base/bind.h"
+#include "base/compiler_specific.h"
#include "base/json/json_reader.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -12,9 +13,10 @@
#include "googleurl/src/gurl.h"
#include "net/base/escape.h"
#include "net/http/http_status_code.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h"
-#include "remoting/host/url_fetcher.h"
namespace {
@@ -44,18 +46,21 @@ OAuthProviderInfo OAuthProviderInfo::GetDefault() {
}
class GaiaOAuthClient::Core
- : public base::RefCountedThreadSafe<GaiaOAuthClient::Core> {
+ : public base::RefCountedThreadSafe<GaiaOAuthClient::Core>,
+ public net::URLFetcherDelegate {
Wez 2012/06/22 20:14:39 Do we actually need this implementation to be spli
Jamie 2012/06/22 22:42:02 This implementation is based on one used by cloud
Wez 2012/06/22 23:58:35 SGTM
public:
Core(const OAuthProviderInfo& info,
net::URLRequestContextGetter* request_context_getter)
: provider_info_(info),
request_context_getter_(request_context_getter),
- delegate_(NULL) {
+ delegate_(NULL),
+ request_is_oauth_refresh_(false) {
}
void RefreshToken(const OAuthClientInfo& oauth_client_info,
const std::string& refresh_token,
GaiaOAuthClient::Delegate* delegate);
+ virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
Wez 2012/06/22 20:14:39 nit: Prefix this with a blank line and comment "ne
Jamie 2012/06/22 22:42:02 Done.
private:
friend class base::RefCountedThreadSafe<Core>;
@@ -73,7 +78,8 @@ class GaiaOAuthClient::Core
scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
GaiaOAuthClient::Delegate* delegate_;
- scoped_ptr<UrlFetcher> request_;
+ scoped_ptr<net::URLFetcher> request_;
+ bool request_is_oauth_refresh_;
Wez 2012/06/22 20:14:39 Looking at the rest of the class, I think it'd be
Jamie 2012/06/22 22:42:02 That's what I had at first, but we check that the
Wez 2012/06/22 23:58:35 I take your point, but you should really use a "st
Jamie 2012/06/23 00:20:23 Done.
std::string access_token_;
int expires_in_seconds_;
@@ -97,12 +103,27 @@ void GaiaOAuthClient::Core::RefreshToken(
"&client_secret=" +
net::EscapeUrlEncodedData(oauth_client_info.client_secret, true) +
"&grant_type=refresh_token";
- request_.reset(new UrlFetcher(GURL(provider_info_.access_token_url),
- UrlFetcher::POST));
+ request_.reset(net::URLFetcher::Create(
+ GURL(provider_info_.access_token_url), net::URLFetcher::POST, this));
request_->SetRequestContext(request_context_getter_);
request_->SetUploadData("application/x-www-form-urlencoded", post_body);
- request_->Start(
- base::Bind(&GaiaOAuthClient::Core::OnAuthTokenFetchComplete, this));
+ request_is_oauth_refresh_ = true;
+ request_->Start();
+}
+
+void GaiaOAuthClient::Core::OnURLFetchComplete(
+ const net::URLFetcher* source) {
+ std::string response_string;
+ source->GetResponseAsString(&response_string);
+ if (request_is_oauth_refresh_) {
+ OnAuthTokenFetchComplete(source->GetStatus(),
+ source->GetResponseCode(),
+ response_string);
+ } else {
+ OnUserInfoFetchComplete(source->GetStatus(),
+ source->GetResponseCode(),
+ response_string);
+ }
}
void GaiaOAuthClient::Core::OnAuthTokenFetchComplete(
@@ -146,18 +167,19 @@ void GaiaOAuthClient::Core::OnAuthTokenFetchComplete(
}
void GaiaOAuthClient::Core::FetchUserInfoAndInvokeCallback() {
- request_.reset(new UrlFetcher(
- GURL(provider_info_.user_info_url), UrlFetcher::GET));
+ request_.reset(net::URLFetcher::Create(
+ GURL(provider_info_.user_info_url), net::URLFetcher::GET, this));
request_->SetRequestContext(request_context_getter_);
- request_->SetHeader("Authorization", "Bearer " + access_token_);
- request_->Start(
- base::Bind(&GaiaOAuthClient::Core::OnUserInfoFetchComplete, this));
+ request_->AddExtraRequestHeader("Authorization: Bearer " + access_token_);
Wez 2012/06/22 20:14:39 Do we need to sanitize access_token_, or will AddE
Jamie 2012/06/22 22:42:02 It DCHECKs that it doesn't contain CRLF. Something
+ request_is_oauth_refresh_ = false;
+ request_->Start();
}
void GaiaOAuthClient::Core::OnUserInfoFetchComplete(
const net::URLRequestStatus& status,
int response_code,
const std::string& response) {
+ request_.reset();
std::string email;
if (response_code == net::HTTP_OK) {
scoped_ptr<Value> message_value(base::JSONReader::Read(response));
« no previous file with comments | « no previous file | remoting/host/host_port_allocator.h » ('j') | remoting/host/host_port_allocator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698