Commit 7c3bb860 authored by akalin@chromium.org's avatar akalin@chromium.org

Make AssociateWithRenderView() a free function in the 'content' namespace

Rename it to AssociateURLFetcherWithRenderView().

This will enable us to remove content::URLFetcher completely and use
net::URLFetcher exclusively.

BUG=118220
TEST=
TBR=sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10383271

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138178 0039d316-1c4b-4281-b951-d872f2087c98
parent 54dc7f0c
......@@ -197,7 +197,8 @@ void AlternateNavURLFetcher::StartFetch(NavigationController* controller) {
controller_->GetBrowserContext()->GetRequestContext());
content::WebContents* web_contents = controller_->GetWebContents();
fetcher_->AssociateWithRenderView(
content::AssociateURLFetcherWithRenderView(
fetcher_.get(),
web_contents->GetURL(),
web_contents->GetRenderProcessHost()->GetID(),
web_contents->GetRenderViewHost()->GetRoutingID());
......
......@@ -108,7 +108,8 @@ TemplateURLFetcher::RequestDelegate::RequestDelegate(
url_fetcher_->SetRequestContext(fetcher->profile()->GetRequestContext());
// Can be NULL during tests.
if (web_contents) {
url_fetcher_->AssociateWithRenderView(
content::AssociateURLFetcherWithRenderView(
url_fetcher_.get(),
web_contents->GetURL(),
web_contents->GetRenderProcessHost()->GetID(),
web_contents->GetRenderViewHost()->GetRoutingID());
......
......@@ -77,7 +77,8 @@ struct WebPluginAction;
// void Start(const GURL* url, net::URLRequestContextGetter* context) {
// fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this));
// fetcher_->SetRequestContext(context);
// fetcher_->AssociateWithRenderView(
// content::AssociateURLFetcherWithRenderView(
// fetcher_.get(),
// proxy_->GetRenderViewHost()->GetSiteInstance()->GetSite(),
// proxy_->GetRenderViewHost()->GetProcess()->GetID(),
// proxy_->GetRenderViewHost()->GetRoutingID());
......
......@@ -406,7 +406,8 @@ void URLFetcherCore::SetFirstPartyForCookies(
}
void URLFetcherCore::SetURLRequestUserData(
const void* key, const CreateDataCallback& create_data_callback) {
const void* key,
const URLFetcher::CreateDataCallback& create_data_callback) {
DCHECK(key);
DCHECK(!create_data_callback.is_null());
url_request_data_key_ = key;
......
......@@ -10,7 +10,6 @@
#include <string>
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/debug/stack_trace.h"
#include "base/file_path.h"
......@@ -19,12 +18,12 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/platform_file.h"
#include "base/supports_user_data.h"
#include "base/timer.h"
#include "content/public/common/url_fetcher.h"
#include "googleurl/src/gurl.h"
#include "net/base/host_port_pair.h"
#include "net/http/http_request_headers.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_status.h"
......@@ -47,10 +46,6 @@ class URLFetcherCore
: public base::RefCountedThreadSafe<URLFetcherCore>,
public net::URLRequest::Delegate {
public:
// Used by SetURLRequestUserData. The callback should make a fresh
// Data* object every time it's called.
typedef base::Callback<base::SupportsUserData::Data*()> CreateDataCallback;
URLFetcherCore(URLFetcher* fetcher,
const GURL& original_url,
URLFetcher::RequestType request_type,
......@@ -87,12 +82,14 @@ class URLFetcherCore
void AddExtraRequestHeader(const std::string& header_line);
void GetExtraRequestHeaders(net::HttpRequestHeaders* headers) const;
void SetRequestContext(net::URLRequestContextGetter* request_context_getter);
// Set the URL that should be consulted for the third-party cookie
// blocking policy.
void SetFirstPartyForCookies(const GURL& first_party_for_cookies);
// Whenever a URLRequest object is created, SetUserData() will be
// called on it with the given key and the result of the given
// callback.
// Set the key and data callback that is used when setting the user
// data on any URLRequest objects this object creates.
void SetURLRequestUserData(
const void* key, const CreateDataCallback& create_data_callback);
const void* key,
const net::URLFetcher::CreateDataCallback& create_data_callback);
void SetAutomaticallyRetryOn5xx(bool retry);
void SetMaxRetries(int max_retries);
int GetMaxRetries() const;
......@@ -325,7 +322,7 @@ class URLFetcherCore
GURL first_party_for_cookies_; // The first party URL for the request
// The user data to add to each newly-created URLRequest.
const void* url_request_data_key_;
CreateDataCallback url_request_create_data_callback_;
net::URLFetcher::CreateDataCallback url_request_create_data_callback_;
net::ResponseCookies cookies_; // Response cookies
net::HttpRequestHeaders extra_request_headers_;
scoped_refptr<net::HttpResponseHeaders> response_headers_;
......
......@@ -40,6 +40,30 @@ void content::URLFetcher::SetEnableInterceptionForTests(bool enabled) {
URLFetcherCore::SetEnableInterceptionForTests(enabled);
}
namespace {
base::SupportsUserData::Data* CreateURLRequestUserData(
int render_process_id,
int render_view_id) {
return new URLRequestUserData(render_process_id, render_view_id);
}
} // namespace
namespace content {
void AssociateURLFetcherWithRenderView(net::URLFetcher* url_fetcher,
const GURL& first_party_for_cookies,
int render_process_id,
int render_view_id) {
url_fetcher->SetFirstPartyForCookies(first_party_for_cookies);
url_fetcher->SetURLRequestUserData(
URLRequestUserData::kUserDataKey,
base::Bind(&CreateURLRequestUserData,
render_process_id, render_view_id));
}
} // namespace content
URLFetcherImpl::URLFetcherImpl(const GURL& url,
RequestType request_type,
......@@ -98,25 +122,15 @@ void URLFetcherImpl::SetRequestContext(
core_->SetRequestContext(request_context_getter);
}
namespace {
base::SupportsUserData::Data* CreateURLRequestUserData(
int render_process_id,
int render_view_id) {
return new URLRequestUserData(render_process_id, render_view_id);
void URLFetcherImpl::SetFirstPartyForCookies(
const GURL& first_party_for_cookies) {
core_->SetFirstPartyForCookies(first_party_for_cookies);
}
} // namespace
void URLFetcherImpl::AssociateWithRenderView(
const GURL& first_party_for_cookies,
int render_process_id,
int render_view_id) {
core_->SetFirstPartyForCookies(first_party_for_cookies);
core_->SetURLRequestUserData(
URLRequestUserData::kUserDataKey,
base::Bind(&CreateURLRequestUserData,
render_process_id, render_view_id));
void URLFetcherImpl::SetURLRequestUserData(
const void* key,
const CreateDataCallback& create_data_callback) {
core_->SetURLRequestUserData(key, create_data_callback);
}
void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) {
......
......@@ -53,9 +53,11 @@ class CONTENT_EXPORT URLFetcherImpl : public content::URLFetcher {
net::HttpRequestHeaders* headers) const OVERRIDE;
virtual void SetRequestContext(
net::URLRequestContextGetter* request_context_getter) OVERRIDE;
virtual void AssociateWithRenderView(const GURL& first_party_for_cookies,
int render_process_id,
int render_view_id) OVERRIDE;
virtual void SetFirstPartyForCookies(
const GURL& first_party_for_cookies) OVERRIDE;
virtual void SetURLRequestUserData(
const void* key,
const CreateDataCallback& create_data_callback) OVERRIDE;
virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE;
virtual void SetMaxRetries(int max_retries) OVERRIDE;
virtual int GetMaxRetries() const OVERRIDE;
......
......@@ -13,14 +13,10 @@ namespace content {
class URLFetcherDelegate;
// Extend net::URLFetcher to add content-specific methods.
//
// TODO(akalin): Move some more content-specific methods from
// net::URLFetcher.
// TODO(akalin): Move the static functions to net::URLFetcher and
// remove content::URLFetcher.
class CONTENT_EXPORT URLFetcher : public net::URLFetcher {
public:
// TODO(akalin): Move the static functions to net::URLFetcher.
// |url| is the URL to send the request to.
// |request_type| is the type of request to make.
// |d| the object that will receive the callback on fetch completion.
......@@ -48,14 +44,16 @@ class CONTENT_EXPORT URLFetcher : public net::URLFetcher {
// to enable it for tests. Also see ScopedURLFetcherFactory for another way
// of testing code that uses an URLFetcher.
static void SetEnableInterceptionForTests(bool enabled);
// Mark URLRequests started by the URLFetcher to stem from the given render
// view.
virtual void AssociateWithRenderView(const GURL& first_party_for_cookies,
int render_process_id,
int render_view_id) = 0;
};
// Mark URLRequests started by the URLFetcher to stem from the given render
// view.
CONTENT_EXPORT void AssociateURLFetcherWithRenderView(
net::URLFetcher* url_fetcher,
const GURL& first_party_for_cookies,
int render_process_id,
int render_view_id);
} // namespace content
#endif // CONTENT_PUBLIC_COMMON_URL_FETCHER_H_
......@@ -89,10 +89,13 @@ void TestURLFetcher::SetRequestContext(
net::URLRequestContextGetter* request_context_getter) {
}
void TestURLFetcher::AssociateWithRenderView(
const GURL& first_party_for_cookies,
int render_process_id,
int render_view_id) {
void TestURLFetcher::SetFirstPartyForCookies(
const GURL& first_party_for_cookies) {
}
void TestURLFetcher::SetURLRequestUserData(
const void* key,
const CreateDataCallback& create_data_callback) {
}
void TestURLFetcher::SetAutomaticallyRetryOn5xx(bool retry) {
......
......@@ -80,9 +80,11 @@ class TestURLFetcher : public content::URLFetcher {
net::HttpRequestHeaders* headers) const OVERRIDE;
virtual void SetRequestContext(
net::URLRequestContextGetter* request_context_getter) OVERRIDE;
virtual void AssociateWithRenderView(const GURL& first_party_for_cookies,
int render_process_id,
int render_view_id) OVERRIDE;
virtual void SetFirstPartyForCookies(
const GURL& first_party_for_cookies) OVERRIDE;
virtual void SetURLRequestUserData(
const void* key,
const CreateDataCallback& create_data_callback) OVERRIDE;
virtual void SetAutomaticallyRetryOn5xx(bool retry) OVERRIDE;
virtual void SetMaxRetries(int max_retries) OVERRIDE;
virtual int GetMaxRetries() const OVERRIDE;
......
......@@ -9,8 +9,10 @@
#include <string>
#include <vector>
#include "base/callback_forward.h"
#include "base/memory/ref_counted.h"
#include "base/platform_file.h"
#include "base/supports_user_data.h"
#include "net/base/net_export.h"
class FilePath;
......@@ -75,6 +77,10 @@ class NET_EXPORT URLFetcher {
PUT,
};
// Used by SetURLRequestUserData. The callback should make a fresh
// base::SupportsUserData::Data object every time it's called.
typedef base::Callback<base::SupportsUserData::Data*()> CreateDataCallback;
virtual ~URLFetcher();
// Sets data only needed by POSTs. All callers making POST requests should
......@@ -125,6 +131,16 @@ class NET_EXPORT URLFetcher {
virtual void SetRequestContext(
URLRequestContextGetter* request_context_getter) = 0;
// Set the URL that should be consulted for the third-party cookie
// blocking policy.
virtual void SetFirstPartyForCookies(
const GURL& first_party_for_cookies) = 0;
// Set the key and data callback that is used when setting the user
// data on any URLRequest objects this object creates.
virtual void SetURLRequestUserData(
const void* key, const CreateDataCallback& create_data_callback) = 0;
// If |retry| is false, 5xx responses will be propagated to the observer,
// if it is true URLFetcher will automatically re-execute the request,
// after backoff_delay() elapses. URLFetcher has it set to true by default.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment