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