| OLD | NEW |
| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/debug/alias.h" | 13 #include "base/debug/alias.h" |
| 14 #include "base/debug/dump_without_crashing.h" | 14 #include "base/debug/dump_without_crashing.h" |
| 15 #include "base/debug/stack_trace.h" | 15 #include "base/debug/stack_trace.h" |
| 16 #include "base/feature_list.h" | |
| 17 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 18 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/shared_memory.h" | 18 #include "base/memory/shared_memory.h" |
| 20 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 21 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 22 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
| 23 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 24 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 25 #include "content/child/request_extra_data.h" | 24 #include "content/child/request_extra_data.h" |
| 26 #include "content/child/resource_scheduling_filter.h" | 25 #include "content/child/resource_scheduling_filter.h" |
| 27 #include "content/child/shared_memory_received_data_factory.h" | 26 #include "content/child/shared_memory_received_data_factory.h" |
| 28 #include "content/child/site_isolation_stats_gatherer.h" | 27 #include "content/child/site_isolation_stats_gatherer.h" |
| 29 #include "content/child/sync_load_response.h" | 28 #include "content/child/sync_load_response.h" |
| 30 #include "content/child/url_loader_client_impl.h" | 29 #include "content/child/url_loader_client_impl.h" |
| 31 #include "content/common/inter_process_time_ticks_converter.h" | 30 #include "content/common/inter_process_time_ticks_converter.h" |
| 32 #include "content/common/navigation_params.h" | 31 #include "content/common/navigation_params.h" |
| 33 #include "content/common/resource_messages.h" | 32 #include "content/common/resource_messages.h" |
| 34 #include "content/common/resource_request.h" | 33 #include "content/common/resource_request.h" |
| 35 #include "content/common/resource_request_completion_status.h" | 34 #include "content/common/resource_request_completion_status.h" |
| 36 #include "content/public/child/fixed_received_data.h" | 35 #include "content/public/child/fixed_received_data.h" |
| 37 #include "content/public/child/request_peer.h" | 36 #include "content/public/child/request_peer.h" |
| 38 #include "content/public/child/resource_dispatcher_delegate.h" | 37 #include "content/public/child/resource_dispatcher_delegate.h" |
| 39 #include "content/public/common/content_features.h" | |
| 40 #include "content/public/common/resource_response.h" | 38 #include "content/public/common/resource_response.h" |
| 41 #include "content/public/common/resource_type.h" | 39 #include "content/public/common/resource_type.h" |
| 42 #include "net/base/net_errors.h" | 40 #include "net/base/net_errors.h" |
| 43 #include "net/base/request_priority.h" | 41 #include "net/base/request_priority.h" |
| 44 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
| 45 | 43 |
| 46 namespace content { | 44 namespace content { |
| 47 | 45 |
| 48 namespace { | 46 namespace { |
| 49 | 47 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 CrashOnMapFailure(); | 228 CrashOnMapFailure(); |
| 231 return; | 229 return; |
| 232 } | 230 } |
| 233 | 231 |
| 234 // TODO(erikchen): Temporary debugging. http://crbug.com/527588. | 232 // TODO(erikchen): Temporary debugging. http://crbug.com/527588. |
| 235 CHECK_GE(shm_size, 0); | 233 CHECK_GE(shm_size, 0); |
| 236 CHECK_LE(shm_size, 512 * 1024); | 234 CHECK_LE(shm_size, 512 * 1024); |
| 237 request_info->buffer_size = shm_size; | 235 request_info->buffer_size = shm_size; |
| 238 } | 236 } |
| 239 | 237 |
| 240 void ResourceDispatcher::OnReceivedInlinedDataChunk( | |
| 241 int request_id, | |
| 242 const std::vector<char>& data, | |
| 243 int encoded_data_length) { | |
| 244 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedInlinedDataChunk"); | |
| 245 DCHECK(!data.empty()); | |
| 246 DCHECK(base::FeatureList::IsEnabled( | |
| 247 features::kOptimizeLoadingIPCForSmallResources)); | |
| 248 | |
| 249 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | |
| 250 if (!request_info || data.empty()) | |
| 251 return; | |
| 252 | |
| 253 // Check whether this response data is compliant with our cross-site | |
| 254 // document blocking policy. We only do this for the first chunk of data. | |
| 255 if (request_info->site_isolation_metadata.get()) { | |
| 256 SiteIsolationStatsGatherer::OnReceivedFirstChunk( | |
| 257 request_info->site_isolation_metadata, data.data(), data.size()); | |
| 258 request_info->site_isolation_metadata.reset(); | |
| 259 } | |
| 260 | |
| 261 DCHECK(!request_info->buffer.get()); | |
| 262 | |
| 263 request_info->peer->OnReceivedData( | |
| 264 base::MakeUnique<content::FixedReceivedData>(data)); | |
| 265 | |
| 266 // Get the request info again as the client callback may modify the info. | |
| 267 request_info = GetPendingRequestInfo(request_id); | |
| 268 if (request_info && encoded_data_length > 0) | |
| 269 request_info->peer->OnTransferSizeUpdated(encoded_data_length); | |
| 270 } | |
| 271 | |
| 272 void ResourceDispatcher::OnReceivedData(int request_id, | 238 void ResourceDispatcher::OnReceivedData(int request_id, |
| 273 int data_offset, | 239 int data_offset, |
| 274 int data_length, | 240 int data_length, |
| 275 int encoded_data_length) { | 241 int encoded_data_length) { |
| 276 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData"); | 242 TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedData"); |
| 277 DCHECK_GT(data_length, 0); | 243 DCHECK_GT(data_length, 0); |
| 278 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 244 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
| 279 bool send_ack = true; | 245 bool send_ack = true; |
| 280 if (request_info && data_length > 0) { | 246 if (request_info && data_length > 0) { |
| 281 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle())); | 247 CHECK(base::SharedMemory::IsHandleValid(request_info->buffer->handle())); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 } | 518 } |
| 553 | 519 |
| 554 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { | 520 void ResourceDispatcher::DispatchMessage(const IPC::Message& message) { |
| 555 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) | 521 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcher, message) |
| 556 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) | 522 IPC_MESSAGE_HANDLER(ResourceMsg_UploadProgress, OnUploadProgress) |
| 557 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) | 523 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) |
| 558 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, | 524 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedCachedMetadata, |
| 559 OnReceivedCachedMetadata) | 525 OnReceivedCachedMetadata) |
| 560 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) | 526 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedRedirect, OnReceivedRedirect) |
| 561 IPC_MESSAGE_HANDLER(ResourceMsg_SetDataBuffer, OnSetDataBuffer) | 527 IPC_MESSAGE_HANDLER(ResourceMsg_SetDataBuffer, OnSetDataBuffer) |
| 562 IPC_MESSAGE_HANDLER(ResourceMsg_InlinedDataChunkReceived, | |
| 563 OnReceivedInlinedDataChunk) | |
| 564 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived, OnReceivedData) | 528 IPC_MESSAGE_HANDLER(ResourceMsg_DataReceived, OnReceivedData) |
| 565 IPC_MESSAGE_HANDLER(ResourceMsg_DataDownloaded, OnDownloadedData) | 529 IPC_MESSAGE_HANDLER(ResourceMsg_DataDownloaded, OnDownloadedData) |
| 566 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete) | 530 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete) |
| 567 IPC_END_MESSAGE_MAP() | 531 IPC_END_MESSAGE_MAP() |
| 568 } | 532 } |
| 569 | 533 |
| 570 void ResourceDispatcher::FlushDeferredMessages(int request_id) { | 534 void ResourceDispatcher::FlushDeferredMessages(int request_id) { |
| 571 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); | 535 PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); |
| 572 if (!request_info || request_info->is_deferred) | 536 if (!request_info || request_info->is_deferred) |
| 573 return; | 537 return; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 | 737 |
| 774 // static | 738 // static |
| 775 bool ResourceDispatcher::IsResourceDispatcherMessage( | 739 bool ResourceDispatcher::IsResourceDispatcherMessage( |
| 776 const IPC::Message& message) { | 740 const IPC::Message& message) { |
| 777 switch (message.type()) { | 741 switch (message.type()) { |
| 778 case ResourceMsg_UploadProgress::ID: | 742 case ResourceMsg_UploadProgress::ID: |
| 779 case ResourceMsg_ReceivedResponse::ID: | 743 case ResourceMsg_ReceivedResponse::ID: |
| 780 case ResourceMsg_ReceivedCachedMetadata::ID: | 744 case ResourceMsg_ReceivedCachedMetadata::ID: |
| 781 case ResourceMsg_ReceivedRedirect::ID: | 745 case ResourceMsg_ReceivedRedirect::ID: |
| 782 case ResourceMsg_SetDataBuffer::ID: | 746 case ResourceMsg_SetDataBuffer::ID: |
| 783 case ResourceMsg_InlinedDataChunkReceived::ID: | |
| 784 case ResourceMsg_DataReceived::ID: | 747 case ResourceMsg_DataReceived::ID: |
| 785 case ResourceMsg_DataDownloaded::ID: | 748 case ResourceMsg_DataDownloaded::ID: |
| 786 case ResourceMsg_RequestComplete::ID: | 749 case ResourceMsg_RequestComplete::ID: |
| 787 return true; | 750 return true; |
| 788 | 751 |
| 789 default: | 752 default: |
| 790 break; | 753 break; |
| 791 } | 754 } |
| 792 | 755 |
| 793 return false; | 756 return false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 delete message; | 788 delete message; |
| 826 } | 789 } |
| 827 } | 790 } |
| 828 | 791 |
| 829 void ResourceDispatcher::SetResourceSchedulingFilter( | 792 void ResourceDispatcher::SetResourceSchedulingFilter( |
| 830 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { | 793 scoped_refptr<ResourceSchedulingFilter> resource_scheduling_filter) { |
| 831 resource_scheduling_filter_ = resource_scheduling_filter; | 794 resource_scheduling_filter_ = resource_scheduling_filter; |
| 832 } | 795 } |
| 833 | 796 |
| 834 } // namespace content | 797 } // namespace content |
| OLD | NEW |