summaryrefslogtreecommitdiffstats
path: root/chrome/common/resource_dispatcher.cc
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-12 21:42:52 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-12 21:42:52 +0000
commiteb9989097eb86b7cc6e535a1d69112b3a38a02c0 (patch)
treec9918e47c10ae09ca9d0f82928075624b10c9c2a /chrome/common/resource_dispatcher.cc
parent3e896efc285b9656fab36fa855d796b16634bd94 (diff)
downloadchromium_src-eb9989097eb86b7cc6e535a1d69112b3a38a02c0.zip
chromium_src-eb9989097eb86b7cc6e535a1d69112b3a38a02c0.tar.gz
chromium_src-eb9989097eb86b7cc6e535a1d69112b3a38a02c0.tar.bz2
Switch to using one ResourceDispatcher per render process, and move it to ChildThread so that the same code is used by the plugin process (and soon, workers).
Review URL: http://codereview.chromium.org/42108 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11581 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/resource_dispatcher.cc')
-rw-r--r--chrome/common/resource_dispatcher.cc68
1 files changed, 32 insertions, 36 deletions
diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc
index 9b57396..61c5013 100644
--- a/chrome/common/resource_dispatcher.cc
+++ b/chrome/common/resource_dispatcher.cc
@@ -52,7 +52,8 @@ class IPCResourceLoaderBridge : public ResourceLoaderBridge {
int origin_pid,
ResourceType::Type resource_type,
bool mixed_content,
- uint32 request_context);
+ uint32 request_context,
+ int route_id);
virtual ~IPCResourceLoaderBridge();
// ResourceLoaderBridge
@@ -71,8 +72,9 @@ class IPCResourceLoaderBridge : public ResourceLoaderBridge {
private:
ResourceLoaderBridge::Peer* peer_;
- // The resource dispatcher for this loader.
- scoped_refptr<ResourceDispatcher> dispatcher_;
+ // The resource dispatcher for this loader. The bridge doesn't own it, but
+ // it's guaranteed to outlive the bridge.
+ ResourceDispatcher* dispatcher_;
// The request to send, created on initialization for modification and
// appending data.
@@ -81,6 +83,9 @@ class IPCResourceLoaderBridge : public ResourceLoaderBridge {
// ID for the request, valid once Start()ed, -1 if not valid yet.
int request_id_;
+ // The routing id used when sending IPC messages.
+ int route_id_;
+
#ifdef LOG_RESOURCE_REQUESTS
// indicates the URL of this resource request for help debugging
std::string url_;
@@ -98,10 +103,12 @@ IPCResourceLoaderBridge::IPCResourceLoaderBridge(
int origin_pid,
ResourceType::Type resource_type,
bool mixed_content,
- uint32 request_context)
+ uint32 request_context,
+ int route_id)
: peer_(NULL),
dispatcher_(dispatcher),
- request_id_(-1) {
+ request_id_(-1),
+ route_id_(route_id) {
DCHECK(dispatcher_) << "no resource dispatcher";
request_.method = method;
request_.url = url;
@@ -164,13 +171,8 @@ bool IPCResourceLoaderBridge::Start(Peer* peer) {
request_id_ = dispatcher_->AddPendingRequest(peer_, request_.resource_type,
request_.mixed_content);
- IPC::Message::Sender* sender = dispatcher_->message_sender();
- bool ret = false;
- if (sender)
- ret = sender->Send(new ViewHostMsg_RequestResource(MSG_ROUTING_NONE,
- request_id_,
- request_));
- return ret;
+ return dispatcher_->message_sender()->Send(
+ new ViewHostMsg_RequestResource(route_id_, request_id_, request_));
}
void IPCResourceLoaderBridge::Cancel() {
@@ -181,9 +183,8 @@ void IPCResourceLoaderBridge::Cancel() {
RESOURCE_LOG("Canceling request for " << url_);
- IPC::Message::Sender* sender = dispatcher_->message_sender();
- if (sender)
- sender->Send(new ViewHostMsg_CancelRequest(MSG_ROUTING_NONE, request_id_));
+ dispatcher_->message_sender()->Send(
+ new ViewHostMsg_CancelRequest(route_id_, request_id_));
// We can't remove the request ID from the resource dispatcher because more
// data might be pending. Sending the cancel message may cause more data
@@ -211,15 +212,11 @@ void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) {
request_id_ = MakeRequestID();
SyncLoadResult result;
- IPC::Message::Sender* sender = dispatcher_->message_sender();
-
- if (sender) {
- IPC::Message* msg = new ViewHostMsg_SyncLoad(MSG_ROUTING_NONE, request_id_,
- request_, &result);
- if (!sender->Send(msg)) {
- response->status.set_status(URLRequestStatus::FAILED);
- return;
- }
+ IPC::Message* msg = new ViewHostMsg_SyncLoad(route_id_, request_id_,
+ request_, &result);
+ if (!dispatcher_->message_sender()->Send(msg)) {
+ response->status.set_status(URLRequestStatus::FAILED);
+ return;
}
response->status = result.status;
@@ -279,7 +276,7 @@ bool ResourceDispatcher::OnMessageReceived(const IPC::Message& message) {
}
void ResourceDispatcher::OnUploadProgress(
- int request_id, int64 position, int64 size) {
+ const IPC::Message& message, int request_id, int64 position, int64 size) {
PendingRequestList::iterator it = pending_requests_.find(request_id);
if (it == pending_requests_.end()) {
// this might happen for kill()ed requests on the webkit end, so perhaps
@@ -296,10 +293,8 @@ void ResourceDispatcher::OnUploadProgress(
request_info.peer->OnUploadProgress(position, size);
// Acknowlegde reciept
- IPC::Message::Sender* sender = message_sender();
- if (sender)
- sender->Send(
- new ViewHostMsg_UploadProgress_ACK(MSG_ROUTING_NONE, request_id));
+ message_sender()->Send(
+ new ViewHostMsg_UploadProgress_ACK(message.routing_id(), request_id));
}
void ResourceDispatcher::OnReceivedResponse(
@@ -333,14 +328,13 @@ void ResourceDispatcher::OnReceivedResponse(
peer->OnReceivedResponse(response_head, false);
}
-void ResourceDispatcher::OnReceivedData(int request_id,
+void ResourceDispatcher::OnReceivedData(const IPC::Message& message,
+ int request_id,
base::SharedMemoryHandle shm_handle,
int data_len) {
// Acknowlegde the reception of this data.
- IPC::Message::Sender* sender = message_sender();
- if (sender)
- sender->Send(
- new ViewHostMsg_DataReceived_ACK(MSG_ROUTING_NONE, request_id));
+ message_sender()->Send(
+ new ViewHostMsg_DataReceived_ACK(message.routing_id(), request_id));
const bool shm_valid = base::SharedMemory::IsHandleValid(shm_handle);
DCHECK((shm_valid && data_len > 0) || (!shm_valid && !data_len));
@@ -495,12 +489,14 @@ webkit_glue::ResourceLoaderBridge* ResourceDispatcher::CreateBridge(
int origin_pid,
ResourceType::Type resource_type,
bool mixed_content,
- uint32 request_context) {
+ uint32 request_context,
+ int route_id) {
return new webkit_glue::IPCResourceLoaderBridge(this, method, url, policy_url,
referrer, headers, flags,
origin_pid, resource_type,
mixed_content,
- request_context);
+ request_context,
+ route_id);
}