diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 17:56:12 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 17:56:12 +0000 |
commit | 7cc6e5639982a9f912c46572dafa4a42682fbd04 (patch) | |
tree | aeda0f815ef8b72e5c2c154d66ab21c43dc9f9dc /chrome/common/net | |
parent | ea725b3aa4fe6ffdb15610d3a6a14d620088d878 (diff) | |
download | chromium_src-7cc6e5639982a9f912c46572dafa4a42682fbd04.zip chromium_src-7cc6e5639982a9f912c46572dafa4a42682fbd04.tar.gz chromium_src-7cc6e5639982a9f912c46572dafa4a42682fbd04.tar.bz2 |
Create a content::UrlFetcher interface that lives in content/public/common and convert users to it. I have added a static create function, but will switch instantiations to use it in another change since this has grown a lot. Basically this change converts function names away from unix_hacker style, which they shouldn't have been using anyways since some are virtual, and made all of the other functions virtual.
BUG=98716
Review URL: http://codereview.chromium.org/8375039
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107151 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/net')
-rw-r--r-- | chrome/common/net/gaia/gaia_auth_fetcher.cc | 18 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_auth_fetcher.h | 15 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc | 10 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_auth_fetcher_unittest.h | 8 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_oauth_client.cc | 30 | ||||
-rw-r--r-- | chrome/common/net/gaia/gaia_oauth_client_unittest.cc | 9 |
6 files changed, 47 insertions, 43 deletions
diff --git a/chrome/common/net/gaia/gaia_auth_fetcher.cc b/chrome/common/net/gaia/gaia_auth_fetcher.cc index a66032b..08cb74b 100644 --- a/chrome/common/net/gaia/gaia_auth_fetcher.cc +++ b/chrome/common/net/gaia/gaia_auth_fetcher.cc @@ -125,7 +125,7 @@ void GaiaAuthFetcher::CancelRequest() { } // static -URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( +content::URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( net::URLRequestContextGetter* getter, const std::string& body, const GURL& gaia_gurl, @@ -137,8 +137,8 @@ URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( gaia_gurl, URLFetcher::POST, delegate); - to_return->set_request_context(getter); - to_return->set_upload_data("application/x-www-form-urlencoded", body); + to_return->SetRequestContext(getter); + to_return->SetUploadData("application/x-www-form-urlencoded", body); // The Gaia token exchange requests do not require any cookie-based // identification as part of requests. We suppress sending any cookies to @@ -146,7 +146,7 @@ URLFetcher* GaiaAuthFetcher::CreateGaiaFetcher( // services. Where such mixing is desired (MergeSession), it will be done // explicitly. if (!send_cookies) - to_return->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES); + to_return->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES); return to_return; } @@ -580,11 +580,11 @@ void GaiaAuthFetcher::OnMergeSessionFetched(const std::string& data, } } -void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source) { +void GaiaAuthFetcher::OnURLFetchComplete(const content::URLFetcher* source) { fetch_pending_ = false; - const GURL& url = source->url(); - const net::URLRequestStatus& status = source->status(); - int response_code = source->response_code(); + const GURL& url = source->GetUrl(); + const net::URLRequestStatus& status = source->GetStatus(); + int response_code = source->GetResponseCode(); std::string data; source->GetResponseAsString(&data); if (url == client_login_gurl_) { @@ -596,7 +596,7 @@ void GaiaAuthFetcher::OnURLFetchComplete(const URLFetcher* source) { } else if (url == token_auth_gurl_) { OnTokenAuthFetched(data, status, response_code); } else if (url == merge_session_gurl_ || - (source && source->original_url() == merge_session_gurl_)) { + (source && source->GetOriginalUrl() == merge_session_gurl_)) { // MergeSession may redirect, so check the original URL of the fetcher. OnMergeSessionFetched(data, status, response_code); } else { diff --git a/chrome/common/net/gaia/gaia_auth_fetcher.h b/chrome/common/net/gaia/gaia_auth_fetcher.h index 4e95cc6..e5cf31e 100644 --- a/chrome/common/net/gaia/gaia_auth_fetcher.h +++ b/chrome/common/net/gaia/gaia_auth_fetcher.h @@ -82,7 +82,7 @@ class GaiaAuthFetcher : public content::URLFetcherDelegate { void StartMergeSession(const std::string& auth_token); // Implementation of content::URLFetcherDelegate - virtual void OnURLFetchComplete(const URLFetcher* source); + virtual void OnURLFetchComplete(const content::URLFetcher* source); // StartClientLogin been called && results not back yet? bool HasPendingFetch(); @@ -197,11 +197,12 @@ class GaiaAuthFetcher : public content::URLFetcherDelegate { const std::string& source); // Create a fetcher useable for making any Gaia request. - static URLFetcher* CreateGaiaFetcher(net::URLRequestContextGetter* getter, - const std::string& body, - const GURL& gaia_gurl, - bool send_cookies, - content::URLFetcherDelegate* delegate); + static content::URLFetcher* CreateGaiaFetcher( + net::URLRequestContextGetter* getter, + const std::string& body, + const GURL& gaia_gurl, + bool send_cookies, + content::URLFetcherDelegate* delegate); // From a URLFetcher result, generate an appropriate error. // From the API documentation, both IssueAuthToken and ClientLogin have @@ -221,7 +222,7 @@ class GaiaAuthFetcher : public content::URLFetcherDelegate { const GURL merge_session_gurl_; // While a fetch is going on: - scoped_ptr<URLFetcher> fetcher_; + scoped_ptr<content::URLFetcher> fetcher_; std::string request_body_; std::string requested_service_; // Currently tracked for IssueAuthToken only std::string requested_info_key_; // Currently tracked for GetUserInfo only diff --git a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc index 5d8426c..941ae74 100644 --- a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc +++ b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc @@ -71,19 +71,19 @@ void MockFetcher::Start() { delegate()->OnURLFetchComplete(this); } -const GURL& MockFetcher::url() const { +const GURL& MockFetcher::GetUrl() const { return url_; } -const net::URLRequestStatus& MockFetcher::status() const { +const net::URLRequestStatus& MockFetcher::GetStatus() const { return status_; } -int MockFetcher::response_code() const { +int MockFetcher::GetResponseCode() const { return response_code_; } -const net::ResponseCookies& MockFetcher::cookies() const { +const net::ResponseCookies& MockFetcher::GetCookies() const { return cookies_; } @@ -646,7 +646,7 @@ TEST_F(GaiaAuthFetcherTest, MergeSessionSuccessRedirect) { // properties to reflect a redirect. TestURLFetcher* test_fetcher = factory.GetFetcherByID(0); EXPECT_TRUE(test_fetcher != NULL); - EXPECT_TRUE(test_fetcher->load_flags() == net::LOAD_NORMAL); + EXPECT_TRUE(test_fetcher->GetLoadFlags() == net::LOAD_NORMAL); EXPECT_TRUE(auth.HasPendingFetch()); GURL final_url("http://www.google.com/CheckCookie"); diff --git a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h index 95550fc..dbc377a 100644 --- a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h +++ b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h @@ -42,10 +42,10 @@ class MockFetcher : public URLFetcher { virtual void Start(); - virtual const GURL& url() const; - virtual const net::URLRequestStatus& status() const; - virtual int response_code() const; - virtual const net::ResponseCookies& cookies() const; + virtual const GURL& GetUrl() const OVERRIDE; + virtual const net::URLRequestStatus& GetStatus() const OVERRIDE; + virtual int GetResponseCode() const OVERRIDE; + virtual const net::ResponseCookies& GetCookies() const OVERRIDE; virtual bool GetResponseAsString(std::string* out_response_string) const; private: diff --git a/chrome/common/net/gaia/gaia_oauth_client.cc b/chrome/common/net/gaia/gaia_oauth_client.cc index fadf589..5a1e5b5 100644 --- a/chrome/common/net/gaia/gaia_oauth_client.cc +++ b/chrome/common/net/gaia/gaia_oauth_client.cc @@ -45,19 +45,20 @@ class GaiaOAuthClient::Core GaiaOAuthClient::Delegate* delegate); // content::URLFetcherDelegate implementation. - virtual void OnURLFetchComplete(const URLFetcher* source); + virtual void OnURLFetchComplete(const content::URLFetcher* source); private: void MakeGaiaRequest(std::string post_body, int max_retries, GaiaOAuthClient::Delegate* delegate); - void HandleResponse(const URLFetcher* source, bool* should_retry_request); + void HandleResponse(const content::URLFetcher* source, + bool* should_retry_request); GURL gaia_url_; int num_retries_; scoped_refptr<net::URLRequestContextGetter> request_context_getter_; GaiaOAuthClient::Delegate* delegate_; - scoped_ptr<URLFetcher> request_; + scoped_ptr<content::URLFetcher> request_; }; void GaiaOAuthClient::Core::GetTokensFromAuthCode( @@ -96,14 +97,15 @@ void GaiaOAuthClient::Core::MakeGaiaRequest( delegate_ = delegate; num_retries_ = 0; request_.reset(URLFetcher::Create(0, gaia_url_, URLFetcher::POST, this)); - request_->set_request_context(request_context_getter_); - request_->set_upload_data("application/x-www-form-urlencoded", post_body); - request_->set_max_retries(max_retries); + request_->SetRequestContext(request_context_getter_); + request_->SetUploadData("application/x-www-form-urlencoded", post_body); + request_->SetMaxRetries(max_retries); request_->Start(); } // URLFetcher::Delegate implementation. -void GaiaOAuthClient::Core::OnURLFetchComplete(const URLFetcher* source) { +void GaiaOAuthClient::Core::OnURLFetchComplete( + const content::URLFetcher* source) { bool should_retry = false; HandleResponse(source, &should_retry); if (should_retry) { @@ -115,7 +117,7 @@ void GaiaOAuthClient::Core::OnURLFetchComplete(const URLFetcher* source) { num_retries_++; // We must set our request_context_getter_ again because // URLFetcher::Core::RetryOrCompleteUrlFetch resets it to NULL... - request_->set_request_context(request_context_getter_); + request_->SetRequestContext(request_context_getter_); request_->Start(); } else { request_.reset(); @@ -123,19 +125,19 @@ void GaiaOAuthClient::Core::OnURLFetchComplete(const URLFetcher* source) { } void GaiaOAuthClient::Core::HandleResponse( - const URLFetcher* source, + const content::URLFetcher* source, bool* should_retry_request) { *should_retry_request = false; // RC_BAD_REQUEST means the arguments are invalid. No point retrying. We are // done here. - if (source->response_code() == RC_BAD_REQUEST) { + if (source->GetResponseCode() == RC_BAD_REQUEST) { delegate_->OnOAuthError(); return; } std::string access_token; std::string refresh_token; int expires_in_seconds = 0; - if (source->response_code() == RC_REQUEST_OK) { + if (source->GetResponseCode() == RC_REQUEST_OK) { std::string data; source->GetResponseAsString(&data); scoped_ptr<Value> message_value(base::JSONReader::Read(data, false)); @@ -151,10 +153,10 @@ void GaiaOAuthClient::Core::HandleResponse( if (access_token.empty()) { // If we don't have an access token yet and the the error was not // RC_BAD_REQUEST, we may need to retry. - if ((-1 != source->max_retries()) && - (num_retries_ > source->max_retries())) { + if ((-1 != source->GetMaxRetries()) && + (num_retries_ > source->GetMaxRetries())) { // Retry limit reached. Give up. - delegate_->OnNetworkError(source->response_code()); + delegate_->OnNetworkError(source->GetResponseCode()); } else { *should_retry_request = true; } diff --git a/chrome/common/net/gaia/gaia_oauth_client_unittest.cc b/chrome/common/net/gaia/gaia_oauth_client_unittest.cc index f5d5cfb..bccb172 100644 --- a/chrome/common/net/gaia/gaia_oauth_client_unittest.cc +++ b/chrome/common/net/gaia/gaia_oauth_client_unittest.cc @@ -57,19 +57,20 @@ class MockOAuthFetcher : public URLFetcher { delegate()->OnURLFetchComplete(this); } - virtual const GURL& url() const { + virtual const GURL& GetUrl() const OVERRIDE { return url_; } - virtual const net::URLRequestStatus& status() const { + virtual const net::URLRequestStatus& GetStatus() const OVERRIDE { return status_; } - virtual int response_code() const { + virtual int GetResponseCode() const OVERRIDE { return response_code_; } - virtual bool GetResponseAsString(std::string* out_response_string) const { + virtual bool GetResponseAsString( + std::string* out_response_string) const OVERRIDE { *out_response_string = results_; return true; } |