diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-20 07:48:49 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-20 07:48:49 +0000 |
commit | 28b8d6dd9161265877668dd556f743815a7dda94 (patch) | |
tree | a18cd3bd507ea986db6e524aa9ad497a01ea6701 /chrome | |
parent | 22b42c595b55ca0c589658d9ab6d073da728833a (diff) | |
download | chromium_src-28b8d6dd9161265877668dd556f743815a7dda94.zip chromium_src-28b8d6dd9161265877668dd556f743815a7dda94.tar.gz chromium_src-28b8d6dd9161265877668dd556f743815a7dda94.tar.bz2 |
Add URLRequestContextOverride in SocketStreamDispatcherHost
BUG=62152
TEST=none
Review URL: http://codereview.chromium.org/5882004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69697 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
6 files changed, 71 insertions, 10 deletions
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index 40ec178..677bb94 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -456,7 +456,12 @@ void BrowserRenderProcessHost::CreateMessageFilters() { channel_->AddFilter(new MimeRegistryMessageFilter()); channel_->AddFilter(new DatabaseMessageFilter( profile()->GetDatabaseTracker(), profile()->GetHostContentSettingsMap())); - channel_->AddFilter(new SocketStreamDispatcherHost()); + + SocketStreamDispatcherHost* socket_stream_dispatcher_host = + new SocketStreamDispatcherHost(); + socket_stream_dispatcher_host->set_url_request_context_override( + url_request_context_override); + channel_->AddFilter(socket_stream_dispatcher_host); } int BrowserRenderProcessHost::GetNextRoutingID() { diff --git a/chrome/browser/renderer_host/socket_stream_dispatcher_host.cc b/chrome/browser/renderer_host/socket_stream_dispatcher_host.cc index ea74513..fc642e8 100644 --- a/chrome/browser/renderer_host/socket_stream_dispatcher_host.cc +++ b/chrome/browser/renderer_host/socket_stream_dispatcher_host.cc @@ -5,9 +5,11 @@ #include "chrome/browser/renderer_host/socket_stream_dispatcher_host.h" #include "base/logging.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/renderer_host/socket_stream_host.h" #include "chrome/common/render_messages.h" #include "chrome/common/net/socket_stream.h" +#include "chrome/common/net/url_request_context_getter.h" #include "net/websockets/websocket_job.h" #include "net/websockets/websocket_throttle.h" @@ -108,7 +110,7 @@ void SocketStreamDispatcherHost::OnConnect(const GURL& url, int socket_id) { } SocketStreamHost* socket_stream_host = new SocketStreamHost(this, socket_id); hosts_.AddWithID(socket_stream_host, socket_id); - socket_stream_host->Connect(url); + socket_stream_host->Connect(url, GetURLRequestContext()); DVLOG(1) << "SocketStreamDispatcherHost::OnConnect -> " << socket_id; } @@ -143,3 +145,19 @@ void SocketStreamDispatcherHost::DeleteSocketStreamHost(int socket_id) { LOG(ERROR) << "ViewMsg_SocketStream_Closed failed."; } } + +URLRequestContext* SocketStreamDispatcherHost::GetURLRequestContext() { + URLRequestContext* rv = NULL; + if (url_request_context_override_.get()) { + rv = url_request_context_override_->GetRequestContext( + 0, ResourceType::SUB_RESOURCE); + } + if (!rv) { + URLRequestContextGetter* context_getter = + Profile::GetDefaultRequestContext(); + if (context_getter) + rv = context_getter->GetURLRequestContext(); + } + + return rv; +} diff --git a/chrome/browser/renderer_host/socket_stream_dispatcher_host.h b/chrome/browser/renderer_host/socket_stream_dispatcher_host.h index e8852c1..b57d7ce 100644 --- a/chrome/browser/renderer_host/socket_stream_dispatcher_host.h +++ b/chrome/browser/renderer_host/socket_stream_dispatcher_host.h @@ -10,6 +10,7 @@ #include "base/id_map.h" #include "chrome/browser/browser_message_filter.h" +#include "chrome/browser/renderer_host/resource_message_filter.h" #include "net/socket_stream/socket_stream.h" class GURL; @@ -39,6 +40,11 @@ class SocketStreamDispatcherHost : public BrowserMessageFilter, const char* data, int len); virtual void OnClose(net::SocketStream* socket); + void set_url_request_context_override( + ResourceMessageFilter::URLRequestContextOverride* u) { + url_request_context_override_ = u; + } + private: // Message handlers called by OnMessageReceived. void OnConnect(const GURL& url, int socket_id); @@ -47,7 +53,12 @@ class SocketStreamDispatcherHost : public BrowserMessageFilter, void DeleteSocketStreamHost(int socket_id); + // Returns the URLRequestContext. + URLRequestContext* GetURLRequestContext(); + IDMap<SocketStreamHost> hosts_; + scoped_refptr<ResourceMessageFilter::URLRequestContextOverride> + url_request_context_override_; DISALLOW_COPY_AND_ASSIGN(SocketStreamDispatcherHost); }; diff --git a/chrome/browser/renderer_host/socket_stream_host.cc b/chrome/browser/renderer_host/socket_stream_host.cc index a4b6525..6c66f79 100644 --- a/chrome/browser/renderer_host/socket_stream_host.cc +++ b/chrome/browser/renderer_host/socket_stream_host.cc @@ -5,9 +5,7 @@ #include "chrome/browser/renderer_host/socket_stream_host.h" #include "base/logging.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/common/net/socket_stream.h" -#include "chrome/common/net/url_request_context_getter.h" #include "net/socket_stream/socket_stream_job.h" static const char* kSocketIdKey = "socketId"; @@ -46,12 +44,11 @@ SocketStreamHost::~SocketStreamHost() { socket_->DetachDelegate(); } -void SocketStreamHost::Connect(const GURL& url) { +void SocketStreamHost::Connect(const GURL& url, + URLRequestContext* request_context) { VLOG(1) << "SocketStreamHost::Connect url=" << url; socket_ = net::SocketStreamJob::CreateSocketStreamJob(url, delegate_); - URLRequestContextGetter* context_getter = Profile::GetDefaultRequestContext(); - if (context_getter) - socket_->set_context(context_getter->GetURLRequestContext()); + socket_->set_context(request_context); socket_->SetUserData(kSocketIdKey, new SocketStreamId(socket_id_)); socket_->Connect(); } diff --git a/chrome/browser/renderer_host/socket_stream_host.h b/chrome/browser/renderer_host/socket_stream_host.h index 5f8fbdc..06b3e9f 100644 --- a/chrome/browser/renderer_host/socket_stream_host.h +++ b/chrome/browser/renderer_host/socket_stream_host.h @@ -12,6 +12,7 @@ #include "net/socket_stream/socket_stream.h" class GURL; +class URLRequestContext; namespace net { class SocketStreamJob; @@ -36,7 +37,7 @@ class SocketStreamHost { int socket_id() const { return socket_id_; } // Starts to open connection to |url|. - void Connect(const GURL& url); + void Connect(const GURL& url, URLRequestContext* request_context); // Sends |data| over the socket stream. // socket stream must be open to send data. diff --git a/chrome/browser/worker_host/worker_process_host.cc b/chrome/browser/worker_host/worker_process_host.cc index df61eab..7c58421 100644 --- a/chrome/browser/worker_host/worker_process_host.cc +++ b/chrome/browser/worker_host/worker_process_host.cc @@ -42,6 +42,30 @@ #include "net/base/registry_controlled_domain.h" #include "webkit/fileapi/file_system_path_manager.h" +namespace { + +// Helper class that we pass to SocketStreamDispatcherHost so that it can find +// the right URLRequestContext for a request. +class URLRequestContextOverride + : public ResourceMessageFilter::URLRequestContextOverride { + public: + explicit URLRequestContextOverride( + URLRequestContext* url_request_context) + : url_request_context_(url_request_context) { + } + virtual ~URLRequestContextOverride() {} + + virtual URLRequestContext* GetRequestContext( + uint32 request_id, ResourceType::Type resource_type) { + return url_request_context_; + } + + private: + URLRequestContext* url_request_context_; +}; + +} // namespace + // Notifies RenderViewHost that one or more worker objects crashed. class WorkerCrashTask : public Task { public: @@ -201,7 +225,12 @@ void WorkerProcessHost::CreateMessageFilters() { AddFilter(new DatabaseMessageFilter( request_context_->database_tracker(), request_context_->host_content_settings_map())); - AddFilter(new SocketStreamDispatcherHost()); + + SocketStreamDispatcherHost* socket_stream_dispatcher_host = + new SocketStreamDispatcherHost(); + socket_stream_dispatcher_host->set_url_request_context_override( + new URLRequestContextOverride(request_context_)); + AddFilter(socket_stream_dispatcher_host); } void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { |