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

Side by Side Diff: trunk/src/content/child/resource_dispatcher.cc

Issue 326403005: Revert 275655 "Redirect HTML resource bytes directly to parser t..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/child/resource_dispatcher.h" 7 #include "content/child/resource_dispatcher.h"
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/memory/shared_memory.h" 14 #include "base/memory/shared_memory.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/metrics/histogram.h" 16 #include "base/metrics/histogram.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "content/child/request_extra_data.h" 18 #include "content/child/request_extra_data.h"
19 #include "content/child/request_info.h" 19 #include "content/child/request_info.h"
20 #include "content/child/site_isolation_policy.h" 20 #include "content/child/site_isolation_policy.h"
21 #include "content/child/sync_load_response.h" 21 #include "content/child/sync_load_response.h"
22 #include "content/child/threaded_data_provider.h"
23 #include "content/common/inter_process_time_ticks_converter.h" 22 #include "content/common/inter_process_time_ticks_converter.h"
24 #include "content/common/resource_messages.h" 23 #include "content/common/resource_messages.h"
25 #include "content/public/child/request_peer.h" 24 #include "content/public/child/request_peer.h"
26 #include "content/public/child/resource_dispatcher_delegate.h" 25 #include "content/public/child/resource_dispatcher_delegate.h"
27 #include "content/public/common/resource_response.h" 26 #include "content/public/common/resource_response.h"
28 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
29 #include "net/base/net_util.h" 28 #include "net/base/net_util.h"
30 #include "net/base/request_priority.h" 29 #include "net/base/request_priority.h"
31 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
32 #include "webkit/child/resource_loader_bridge.h" 31 #include "webkit/child/resource_loader_bridge.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 const RequestInfo& request_info); 73 const RequestInfo& request_info);
75 virtual ~IPCResourceLoaderBridge(); 74 virtual ~IPCResourceLoaderBridge();
76 75
77 // ResourceLoaderBridge 76 // ResourceLoaderBridge
78 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE; 77 virtual void SetRequestBody(ResourceRequestBody* request_body) OVERRIDE;
79 virtual bool Start(RequestPeer* peer) OVERRIDE; 78 virtual bool Start(RequestPeer* peer) OVERRIDE;
80 virtual void Cancel() OVERRIDE; 79 virtual void Cancel() OVERRIDE;
81 virtual void SetDefersLoading(bool value) OVERRIDE; 80 virtual void SetDefersLoading(bool value) OVERRIDE;
82 virtual void DidChangePriority(net::RequestPriority new_priority, 81 virtual void DidChangePriority(net::RequestPriority new_priority,
83 int intra_priority_value) OVERRIDE; 82 int intra_priority_value) OVERRIDE;
84 virtual bool AttachThreadedDataReceiver(
85 blink::WebThreadedDataReceiver* threaded_data_receiver) OVERRIDE;
86 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE; 83 virtual void SyncLoad(SyncLoadResponse* response) OVERRIDE;
87 84
88 private: 85 private:
89 // The resource dispatcher for this loader. The bridge doesn't own it, but 86 // The resource dispatcher for this loader. The bridge doesn't own it, but
90 // it's guaranteed to outlive the bridge. 87 // it's guaranteed to outlive the bridge.
91 ResourceDispatcher* dispatcher_; 88 ResourceDispatcher* dispatcher_;
92 89
93 // The request to send, created on initialization for modification and 90 // The request to send, created on initialization for modification and
94 // appending data. 91 // appending data.
95 ResourceHostMsg_Request request_; 92 ResourceHostMsg_Request request_;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 int intra_priority_value) { 213 int intra_priority_value) {
217 if (request_id_ < 0) { 214 if (request_id_ < 0) {
218 NOTREACHED() << "Trying to change priority of an unstarted request"; 215 NOTREACHED() << "Trying to change priority of an unstarted request";
219 return; 216 return;
220 } 217 }
221 218
222 dispatcher_->DidChangePriority( 219 dispatcher_->DidChangePriority(
223 request_id_, new_priority, intra_priority_value); 220 request_id_, new_priority, intra_priority_value);
224 } 221 }
225 222
226 bool IPCResourceLoaderBridge::AttachThreadedDataReceiver(
227 blink::WebThreadedDataReceiver* threaded_data_receiver) {
228 if (request_id_ < 0) {
229 NOTREACHED() << "Trying to attach threaded receiver on unstarted request";
230 return false;
231 }
232
233 return dispatcher_->AttachThreadedDataReceiver(request_id_,
234 threaded_data_receiver);
235 }
236
237 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) { 223 void IPCResourceLoaderBridge::SyncLoad(SyncLoadResponse* response) {
238 if (request_id_ != -1) { 224 if (request_id_ != -1) {
239 NOTREACHED() << "Starting a request twice"; 225 NOTREACHED() << "Starting a request twice";
240 response->error_code = net::ERR_FAILED; 226 response->error_code = net::ERR_FAILED;
241 return; 227 return;
242 } 228 }
243 229
244 request_id_ = MakeRequestID(); 230 request_id_ = MakeRequestID();
245 is_synchronous_request_ = true; 231 is_synchronous_request_ = true;
246 232
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 request_info->buffer_size = shm_size; 398 request_info->buffer_size = shm_size;
413 } 399 }
414 400
415 void ResourceDispatcher::OnReceivedData(int request_id, 401 void ResourceDispatcher::OnReceivedData(int request_id,
416 int data_offset, 402 int data_offset,
417 int data_length, 403 int data_length,
418 int encoded_data_length) { 404 int encoded_data_length) {
419 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData"); 405 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData");
420 DCHECK_GT(data_length, 0); 406 DCHECK_GT(data_length, 0);
421 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 407 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
422 bool send_ack = true;
423 if (request_info && data_length > 0) { 408 if (request_info && data_length > 0) {
424 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle())); 409 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle()));
425 CHECK_GE(request_info->buffer_size, data_offset + data_length); 410 CHECK_GE(request_info->buffer_size, data_offset + data_length);
426 411
427 // Ensure that the SHM buffer remains valid for the duration of this scope. 412 // Ensure that the SHM buffer remains valid for the duration of this scope.
428 // It is possible for CancelPendingRequest() to be called before we exit 413 // It is possible for CancelPendingRequest() to be called before we exit
429 // this scope. 414 // this scope.
430 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer); 415 linked_ptr<base::SharedMemory> retain_buffer(request_info->buffer);
431 416
432 base::TimeTicks time_start = base::TimeTicks::Now(); 417 base::TimeTicks time_start = base::TimeTicks::Now();
433 418
434 const char* data_start = static_cast<char*>(request_info->buffer->memory()); 419 const char* data_ptr = static_cast<char*>(request_info->buffer->memory());
435 CHECK(data_start); 420 CHECK(data_ptr);
436 CHECK(data_start + data_offset); 421 CHECK(data_ptr + data_offset);
437 const char* data_ptr = data_start + data_offset;
438 422
439 // Check whether this response data is compliant with our cross-site 423 // Check whether this response data is compliant with our cross-site
440 // document blocking policy. We only do this for the first packet. 424 // document blocking policy. We only do this for the first packet.
441 std::string alternative_data; 425 std::string alternative_data;
442 if (request_info->site_isolation_metadata.get()) { 426 if (request_info->site_isolation_metadata.get()) {
443 request_info->blocked_response = 427 request_info->blocked_response =
444 SiteIsolationPolicy::ShouldBlockResponse( 428 SiteIsolationPolicy::ShouldBlockResponse(
445 request_info->site_isolation_metadata, data_ptr, data_length, 429 request_info->site_isolation_metadata, data_ptr + data_offset,
446 &alternative_data); 430 data_length, &alternative_data);
447 request_info->site_isolation_metadata.reset(); 431 request_info->site_isolation_metadata.reset();
432 }
448 433
449 // When the response is blocked we may have any alternative data to 434 // When the response is not blocked.
435 if (!request_info->blocked_response) {
436 request_info->peer->OnReceivedData(
437 data_ptr + data_offset, data_length, encoded_data_length);
438 } else if (alternative_data.size() > 0) {
439 // When the response is blocked, and when we have any alternative data to
450 // send to the renderer. When |alternative_data| is zero-sized, we do not 440 // send to the renderer. When |alternative_data| is zero-sized, we do not
451 // call peer's callback. 441 // call peer's callback.
452 if (request_info->blocked_response && !alternative_data.empty()) { 442 request_info->peer->OnReceivedData(alternative_data.data(),
453 data_ptr = alternative_data.data(); 443 alternative_data.size(),
454 data_length = alternative_data.size(); 444 alternative_data.size());
455 encoded_data_length = alternative_data.size();
456 }
457 }
458
459 if (!request_info->blocked_response || !alternative_data.empty()) {
460 if (request_info->threaded_data_provider) {
461 request_info->threaded_data_provider->OnReceivedDataOnForegroundThread(
462 data_ptr, data_length, encoded_data_length);
463 // A threaded data provider will take care of its own ACKing, as the
464 // data may be processed later on another thread.
465 send_ack = false;
466 } else {
467 request_info->peer->OnReceivedData(
468 data_ptr, data_length, encoded_data_length);
469 }
470 } 445 }
471 446
472 UMA_HISTOGRAM_TIMES("ResourceDispatcher.OnReceivedDataTime", 447 UMA_HISTOGRAM_TIMES("ResourceDispatcher.OnReceivedDataTime",
473 base::TimeTicks::Now() - time_start); 448 base::TimeTicks::Now() - time_start);
474 } 449 }
475 450
476 // Acknowledge the reception of this data. 451 // Acknowledge the reception of this data.
477 if (send_ack) 452 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id));
478 message_sender_->Send(new ResourceHostMsg_DataReceived_ACK(request_id));
479 } 453 }
480 454
481 void ResourceDispatcher::OnDownloadedData(int request_id, 455 void ResourceDispatcher::OnDownloadedData(int request_id,
482 int data_len, 456 int data_len,
483 int encoded_data_length) { 457 int encoded_data_length) {
484 // Acknowledge the reception of this message. 458 // Acknowledge the reception of this message.
485 message_sender_->Send(new ResourceHostMsg_DataDownloaded_ACK(request_id)); 459 message_sender_->Send(new ResourceHostMsg_DataDownloaded_ACK(request_id));
486 460
487 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); 461 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
488 if (!request_info) 462 if (!request_info)
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 } 616 }
643 617
644 void ResourceDispatcher::DidChangePriority(int request_id, 618 void ResourceDispatcher::DidChangePriority(int request_id,
645 net::RequestPriority new_priority, 619 net::RequestPriority new_priority,
646 int intra_priority_value) { 620 int intra_priority_value) {
647 DCHECK(ContainsKey(pending_requests_, request_id)); 621 DCHECK(ContainsKey(pending_requests_, request_id));
648 message_sender_->Send(new ResourceHostMsg_DidChangePriority( 622 message_sender_->Send(new ResourceHostMsg_DidChangePriority(
649 request_id, new_priority, intra_priority_value)); 623 request_id, new_priority, intra_priority_value));
650 } 624 }
651 625
652 bool ResourceDispatcher::AttachThreadedDataReceiver(
653 int request_id, blink::WebThreadedDataReceiver* threaded_data_receiver) {
654 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id);
655 DCHECK(request_info);
656 DCHECK(!request_info->threaded_data_provider);
657 request_info->threaded_data_provider = new ThreadedDataProvider(
658 request_id, threaded_data_receiver, request_info->buffer,
659 request_info->buffer_size);
660
661 return true;
662 }
663
664 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo() 626 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo()
665 : peer(NULL), 627 : peer(NULL),
666 threaded_data_provider(NULL),
667 resource_type(ResourceType::SUB_RESOURCE), 628 resource_type(ResourceType::SUB_RESOURCE),
668 is_deferred(false), 629 is_deferred(false),
669 download_to_file(false), 630 download_to_file(false),
670 blocked_response(false), 631 blocked_response(false),
671 buffer_size(0) { 632 buffer_size(0) {
672 } 633 }
673 634
674 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo( 635 ResourceDispatcher::PendingRequestInfo::PendingRequestInfo(
675 RequestPeer* peer, 636 RequestPeer* peer,
676 ResourceType::Type resource_type, 637 ResourceType::Type resource_type,
677 int origin_pid, 638 int origin_pid,
678 const GURL& frame_origin, 639 const GURL& frame_origin,
679 const GURL& request_url, 640 const GURL& request_url,
680 bool download_to_file) 641 bool download_to_file)
681 : peer(peer), 642 : peer(peer),
682 threaded_data_provider(NULL),
683 resource_type(resource_type), 643 resource_type(resource_type),
684 origin_pid(origin_pid), 644 origin_pid(origin_pid),
685 is_deferred(false), 645 is_deferred(false),
686 url(request_url), 646 url(request_url),
687 frame_origin(frame_origin), 647 frame_origin(frame_origin),
688 response_url(request_url), 648 response_url(request_url),
689 download_to_file(download_to_file), 649 download_to_file(download_to_file),
690 request_start(base::TimeTicks::Now()), 650 request_start(base::TimeTicks::Now()),
691 blocked_response(false) {} 651 blocked_response(false) {}
692 652
693 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() { 653 ResourceDispatcher::PendingRequestInfo::~PendingRequestInfo() {}
694 if (threaded_data_provider)
695 threaded_data_provider->Stop();
696 }
697 654
698 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { 655 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) {
699 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) 656 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message)
700 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) 657 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress)
701 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) 658 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse)
702 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, 659 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata,
703 OnReceivedCachedMetadata) 660 OnReceivedCachedMetadata)
704 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) 661 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect)
705 IPC_MESSAGE_HANDLER(ResourceMsg_SetDataBuffer, OnSetDataBuffer) 662 IPC_MESSAGE_HANDLER(ResourceMsg_SetDataBuffer, OnSetDataBuffer)
706 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived, OnReceivedData) 663 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived, OnReceivedData)
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) { 808 void ResourceDispatcher::ReleaseResourcesInMessageQueue(MessageQueue* queue) {
852 while (!queue->empty()) { 809 while (!queue->empty()) {
853 IPC::Message* message = queue->front(); 810 IPC::Message* message = queue->front();
854 ReleaseResourcesInDataMessage(*message); 811 ReleaseResourcesInDataMessage(*message);
855 queue->pop_front(); 812 queue->pop_front();
856 delete message; 813 delete message;
857 } 814 }
858 } 815 }
859 816
860 } // namespace content 817 } // namespace content
OLDNEW
« no previous file with comments | « trunk/src/content/child/resource_dispatcher.h ('k') | trunk/src/content/child/threaded_data_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698