Chromium Code Reviews| 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 #include "content/browser/loader/async_resource_handler.h" | 5 #include "content/browser/loader/async_resource_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 static bool did_init = false; | 66 static bool did_init = false; |
| 67 if (did_init) | 67 if (did_init) |
| 68 return; | 68 return; |
| 69 did_init = true; | 69 did_init = true; |
| 70 | 70 |
| 71 GetNumericArg("resource-buffer-size", &kBufferSize); | 71 GetNumericArg("resource-buffer-size", &kBufferSize); |
| 72 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize); | 72 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize); |
| 73 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize); | 73 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize); |
| 74 } | 74 } |
| 75 | 75 |
| 76 enum ExpectedContentSizeResult { | |
|
jwd
2017/01/18 20:03:06
Please add comment saying this enum is used for lo
maksims (do not use this acc)
2017/01/19 05:56:50
Done.
| |
| 77 EQ_RESPONSE_BODY = 0, | |
| 78 EQ_RESPONSE_BODY_GT_EQ_BUFFER_SIZE = 1, | |
| 79 GT_EQ_BUFFER_SIZE = 2, | |
| 80 LT_RESPONSE_BODY = 3, | |
| 81 GT_RESPONSE_BODY = 4, | |
| 82 UNKNOWN = 5, | |
| 83 EXPECTED_CONTENT_MAX, | |
| 84 }; | |
| 85 | |
| 76 } // namespace | 86 } // namespace |
| 77 | 87 |
| 78 // Used when kOptimizeLoadingIPCForSmallResources is enabled. | 88 // Used when kOptimizeLoadingIPCForSmallResources is enabled. |
| 79 // The instance hooks the buffer allocation of AsyncResourceHandler, and | 89 // The instance hooks the buffer allocation of AsyncResourceHandler, and |
| 80 // determine if we should use SharedMemory or should inline the data into | 90 // determine if we should use SharedMemory or should inline the data into |
| 81 // the IPC message. | 91 // the IPC message. |
| 82 class AsyncResourceHandler::InliningHelper { | 92 class AsyncResourceHandler::InliningHelper { |
| 83 public: | 93 public: |
| 84 | 94 |
| 85 InliningHelper() {} | 95 InliningHelper() {} |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 public: | 195 public: |
| 186 DependentIOBuffer(ResourceBuffer* backing, char* memory) | 196 DependentIOBuffer(ResourceBuffer* backing, char* memory) |
| 187 : net::WrappedIOBuffer(memory), | 197 : net::WrappedIOBuffer(memory), |
| 188 backing_(backing) { | 198 backing_(backing) { |
| 189 } | 199 } |
| 190 private: | 200 private: |
| 191 ~DependentIOBuffer() override {} | 201 ~DependentIOBuffer() override {} |
| 192 scoped_refptr<ResourceBuffer> backing_; | 202 scoped_refptr<ResourceBuffer> backing_; |
| 193 }; | 203 }; |
| 194 | 204 |
| 195 AsyncResourceHandler::AsyncResourceHandler( | 205 AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request, |
| 196 net::URLRequest* request, | 206 ResourceDispatcherHostImpl* rdh) |
| 197 ResourceDispatcherHostImpl* rdh) | |
| 198 : ResourceHandler(request), | 207 : ResourceHandler(request), |
| 199 ResourceMessageDelegate(request), | 208 ResourceMessageDelegate(request), |
| 200 rdh_(rdh), | 209 rdh_(rdh), |
| 201 pending_data_count_(0), | 210 pending_data_count_(0), |
| 202 allocation_size_(0), | 211 allocation_size_(0), |
| 212 total_read_body_bytes_(0), | |
| 203 did_defer_(false), | 213 did_defer_(false), |
| 204 has_checked_for_sufficient_resources_(false), | 214 has_checked_for_sufficient_resources_(false), |
| 205 sent_received_response_msg_(false), | 215 sent_received_response_msg_(false), |
| 206 sent_data_buffer_msg_(false), | 216 sent_data_buffer_msg_(false), |
| 207 inlining_helper_(new InliningHelper), | 217 inlining_helper_(new InliningHelper), |
| 208 reported_transfer_size_(0) { | 218 reported_transfer_size_(0) { |
| 209 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); | 219 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); |
| 210 InitializeResourceBufferConstants(); | 220 InitializeResourceBufferConstants(); |
| 211 } | 221 } |
| 212 | 222 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 first_chunk_read_ = true; | 399 first_chunk_read_ = true; |
| 390 | 400 |
| 391 // Return early if InliningHelper handled the received data. | 401 // Return early if InliningHelper handled the received data. |
| 392 if (inlining_helper_->SendInlinedDataIfApplicable( | 402 if (inlining_helper_->SendInlinedDataIfApplicable( |
| 393 bytes_read, encoded_data_length, filter, | 403 bytes_read, encoded_data_length, filter, |
| 394 GetRequestID())) | 404 GetRequestID())) |
| 395 return true; | 405 return true; |
| 396 | 406 |
| 397 buffer_->ShrinkLastAllocation(bytes_read); | 407 buffer_->ShrinkLastAllocation(bytes_read); |
| 398 | 408 |
| 409 total_read_body_bytes_ += bytes_read; | |
| 410 | |
| 399 if (!sent_data_buffer_msg_) { | 411 if (!sent_data_buffer_msg_) { |
| 400 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( | 412 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( |
| 401 buffer_->GetSharedMemory().handle()); | 413 buffer_->GetSharedMemory().handle()); |
| 402 if (!base::SharedMemory::IsHandleValid(handle)) | 414 if (!base::SharedMemory::IsHandleValid(handle)) |
| 403 return false; | 415 return false; |
| 404 filter->Send(new ResourceMsg_SetDataBuffer( | 416 filter->Send(new ResourceMsg_SetDataBuffer( |
| 405 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), | 417 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), |
| 406 filter->peer_pid())); | 418 filter->peer_pid())); |
| 407 sent_data_buffer_msg_ = true; | 419 sent_data_buffer_msg_ = true; |
| 408 } | 420 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 UMA_HISTOGRAM_CUSTOM_COUNTS( | 557 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 546 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", | 558 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", |
| 547 elapsed_time, 1, 100000, 100); | 559 elapsed_time, 1, 100000, 100); |
| 548 } else { | 560 } else { |
| 549 UMA_HISTOGRAM_CUSTOM_COUNTS( | 561 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 550 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", | 562 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", |
| 551 elapsed_time, 1, 100000, 100); | 563 elapsed_time, 1, 100000, 100); |
| 552 } | 564 } |
| 553 | 565 |
| 554 inlining_helper_->RecordHistogram(elapsed_time); | 566 inlining_helper_->RecordHistogram(elapsed_time); |
| 567 | |
| 568 // Record if content size was known in advance. | |
| 569 int64_t expected_content_size = request()->GetExpectedContentSize(); | |
| 570 ExpectedContentSizeResult expected_content_size_result = | |
| 571 ExpectedContentSizeResult::UNKNOWN; | |
| 572 if (expected_content_size >= 0) { | |
| 573 // Compare response body size to expected content size. | |
| 574 if (expected_content_size == total_read_body_bytes_ && | |
| 575 expected_content_size >= kBufferSize) { | |
| 576 expected_content_size_result = | |
| 577 ExpectedContentSizeResult::EQ_RESPONSE_BODY_GT_EQ_BUFFER_SIZE; | |
| 578 } else if (expected_content_size >= kBufferSize) { | |
| 579 expected_content_size_result = | |
| 580 ExpectedContentSizeResult::GT_EQ_BUFFER_SIZE; | |
| 581 } else if (expected_content_size == total_read_body_bytes_) { | |
| 582 expected_content_size_result = | |
| 583 ExpectedContentSizeResult::EQ_RESPONSE_BODY; | |
| 584 } else if (expected_content_size < total_read_body_bytes_) { | |
| 585 expected_content_size_result = | |
| 586 ExpectedContentSizeResult::LT_RESPONSE_BODY; | |
| 587 } else { | |
| 588 expected_content_size_result = | |
| 589 ExpectedContentSizeResult::GT_RESPONSE_BODY; | |
| 590 } | |
| 591 } | |
| 592 UMA_HISTOGRAM_ENUMERATION("Net.ResourceLoader.ExpectedContentSizeResult", | |
| 593 expected_content_size_result, | |
| 594 ExpectedContentSizeResult::EXPECTED_CONTENT_MAX); | |
| 555 } | 595 } |
| 556 | 596 |
| 557 void AsyncResourceHandler::SendUploadProgress( | 597 void AsyncResourceHandler::SendUploadProgress( |
| 558 const net::UploadProgress& progress) { | 598 const net::UploadProgress& progress) { |
| 559 ResourceMessageFilter* filter = GetFilter(); | 599 ResourceMessageFilter* filter = GetFilter(); |
| 560 if (!filter) | 600 if (!filter) |
| 561 return; | 601 return; |
| 562 filter->Send(new ResourceMsg_UploadProgress( | 602 filter->Send(new ResourceMsg_UploadProgress( |
| 563 GetRequestID(), progress.position(), progress.size())); | 603 GetRequestID(), progress.position(), progress.size())); |
| 564 } | 604 } |
| 565 | 605 |
| 566 } // namespace content | 606 } // namespace content |
| OLD | NEW |