| Index: content/child/resource_dispatcher.cc
|
| diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc
|
| index c332de4c9c438caf1c7344ffe7abb56fd8d8591c..8d28b54c4c10341e64ade3d19c82ce38937c6c26 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* threadedDataReceiver) 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* threadedDataReceiver) {
|
| + if (request_id_ < 0) {
|
| + NOTREACHED() << "Trying to attach threaded receiver on unstarted request";
|
| + return false;
|
| + }
|
| +
|
| + return dispatcher_->AttachThreadedDataReceiver(request_id_,
|
| + threadedDataReceiver);
|
| +}
|
| +
|
| 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,29 @@ 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) {
|
| + 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) {
|
| + if (request_info->threaded_data_provider) {
|
| + request_info->threaded_data_provider->OnReceivedDataOnForegroundThread(
|
| + data_ptr, data_length, encoded_data_length);
|
| + send_ack = false;
|
| + } else {
|
| + request_info->peer->OnReceivedData(
|
| + data_ptr, data_length, encoded_data_length);
|
| + }
|
| }
|
|
|
| UMA_HISTOGRAM_TIMES("ResourceDispatcher.OnReceivedDataTime",
|
| @@ -463,7 +486,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 +651,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 +679,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 +690,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)
|
|
|