Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1622)

Unified Diff: content/child/resource_dispatcher.cc

Issue 109283006: Redirect HTML resource bytes directly to parser thread (Chrome side CL) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/child/resource_dispatcher.cc
diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc
index c332de4c9c438caf1c7344ffe7abb56fd8d8591c..35580929546a56b2190e41d424ab8ed1d74ef469 100644
--- a/content/child/resource_dispatcher.cc
+++ b/content/child/resource_dispatcher.cc
@@ -17,6 +17,7 @@
#include "base/strings/string_util.h"
#include "content/child/request_extra_data.h"
#include "content/child/site_isolation_policy.h"
+#include "content/child/threadeddataprovider.h"
#include "content/common/inter_process_time_ticks_converter.h"
#include "content/common/resource_messages.h"
#include "content/common/service_worker/service_worker_types.h"
@@ -78,6 +79,8 @@ class IPCResourceLoaderBridge : public ResourceLoaderBridge {
virtual void Cancel() OVERRIDE;
virtual void SetDefersLoading(bool value) OVERRIDE;
virtual void DidChangePriority(net::RequestPriority new_priority) OVERRIDE;
+ virtual bool AttachThreadedDataReceiver(
+ blink::WebThreadedDataReceiver* threaded_data_receiver) OVERRIDE;
virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE;
private:
@@ -234,6 +237,17 @@ void IPCResourceLoaderBridge::DidChangePriority(
dispatcher_->DidChangePriority(routing_id_, request_id_, new_priority);
}
+bool IPCResourceLoaderBridge::AttachThreadedDataReceiver(
+ blink::WebThreadedDataReceiver* threaded_data_receiver) {
+ if (request_id_ < 0) {
+ NOTREACHED() << "Trying to attach threaded receiver on unstarted request";
+ return false;
+ }
+
+ return dispatcher_->AttachThreadedDataReceiver(request_id_,
+ threaded_data_receiver);
+}
+
void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) {
if (request_id_ != -1) {
NOTREACHED() << "Starting a request twice";
@@ -419,6 +433,7 @@ void ResourceDispatcher::OnReceivedData(int request_id,
TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData");
DCHECK_GT(data_length, 0);
PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
+ bool send_ack = true;
if (request_info && data_length > 0) {
CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle()));
CHECK_GE(request_info->buffer_size, data_offset + data_length);
@@ -430,9 +445,10 @@ void ResourceDispatcher::OnReceivedData(int request_id,
base::TimeTicks time_start = base::TimeTicks::Now();
- const char* data_ptr = static_cast<char*>(request_info->buffer->memory());
- CHECK(data_ptr);
- CHECK(data_ptr + data_offset);
+ const char* data_start = static_cast<char*>(request_info->buffer->memory());
+ CHECK(data_start);
+ CHECK(data_start + data_offset);
+ const char* data_ptr = data_start + data_offset;
// Check whether this response data is compliant with our cross-site
// document blocking policy. We only do this for the first packet.
@@ -440,22 +456,31 @@ void ResourceDispatcher::OnReceivedData(int request_id,
if (request_info->site_isolation_metadata.get()) {
request_info->blocked_response =
SiteIsolationPolicy::ShouldBlockResponse(
- request_info->site_isolation_metadata, data_ptr + data_offset,
- data_length, &alternative_data);
+ request_info->site_isolation_metadata, data_ptr, data_length,
+ &alternative_data);
request_info->site_isolation_metadata.reset();
- }
- // When the response is not blocked.
- if (!request_info->blocked_response) {
- request_info->peer->OnReceivedData(
- data_ptr + data_offset, data_length, encoded_data_length);
- } else if (alternative_data.size() > 0) {
- // When the response is blocked, and when we have any alternative data to
+ // When the response is blocked we may have any alternative data to
// send to the renderer. When |alternative_data| is zero-sized, we do not
// call peer's callback.
- request_info->peer->OnReceivedData(alternative_data.data(),
- alternative_data.size(),
- alternative_data.size());
+ if (request_info->blocked_response && alternative_data.size() > 0) {
darin (slow to review) 2014/03/31 17:00:01 nit: it is generally preferred with STL to do !con
+ data_ptr = alternative_data.data();
+ data_length = alternative_data.size();
+ encoded_data_length = alternative_data.size();
+ }
+ }
+
+ if (!request_info->blocked_response || alternative_data.size() > 0) {
darin (slow to review) 2014/03/31 17:00:01 ditto
+ if (request_info->threaded_data_provider) {
+ request_info->threaded_data_provider->OnReceivedDataOnForegroundThread(
+ data_ptr, data_length, encoded_data_length);
+ // A threaded data provider will take care of its own ACKing, as the
+ // data may be processed later on another thread.
+ send_ack = false;
+ } else {
+ request_info->peer->OnReceivedData(
+ data_ptr, data_length, encoded_data_length);
+ }
}
UMA_HISTOGRAM_TIMES("ResourceDispatcher.OnReceivedDataTime",
@@ -463,7 +488,8 @@ void ResourceDispatcher::OnReceivedData(int request_id,
}
// Acknowledge the reception of this data.
- message_sender()->Send(new ResourceHostMsg_DataReceived_ACK(request_id));
+ if (send_ack)
+ message_sender()->Send(new ResourceHostMsg_DataReceived_ACK(request_id));
}
void ResourceDispatcher::OnDownloadedData(int request_id,
@@ -627,8 +653,21 @@ void ResourceDispatcher::DidChangePriority(
request_id, new_priority));
}
+bool ResourceDispatcher::AttachThreadedDataReceiver(
+ int request_id, blink::WebThreadedDataReceiver* threaded_data_receiver) {
+ PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
+ DCHECK(request_info);
+ DCHECK(!request_info->threaded_data_provider);
+ request_info->threaded_data_provider = new ThreadedDataProvider(
+ request_id, threaded_data_receiver, request_info->buffer,
+ request_info->buffer_size);
+
+ return true;
+}
+
ResourceDispatcher::PendingRequestInfo::PendingRequestInfo()
: peer(NULL),
+ threaded_data_provider(NULL),
resource_type(ResourceType::SUB_RESOURCE),
is_deferred(false),
blocked_response(false),
@@ -642,6 +681,7 @@ ResourceDispatcher::PendingRequestInfo::PendingRequestInfo(
const GURL& frame_origin,
const GURL& request_url)
: peer(peer),
+ threaded_data_provider(NULL),
resource_type(resource_type),
origin_pid(origin_pid),
is_deferred(false),
@@ -652,7 +692,10 @@ ResourceDispatcher::PendingRequestInfo::PendingRequestInfo(
blocked_response(false) {
}
-ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {}
+ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {
+ if (threaded_data_provider)
+ threaded_data_provider->Stop();
+}
void ResourceDispatcher::DispatchMessage(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message)

Powered by Google App Engine
This is Rietveld 408576698