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 { | |
| 77 EQ_RESPONSE_BODY = 0, | |
| 78 EQ_RESPONSE_BODY_MT_EQ_BUFFER_SIZE = 1, | |
| 79 LT_RESPONSE_BODY = 2, | |
| 80 MT_RESPONSE_BODY = 3, | |
| 81 UNKNOWN = 4, | |
| 82 EXPECTED_CONTENT_MAX, | |
| 83 }; | |
| 84 | |
| 76 } // namespace | 85 } // namespace |
| 77 | 86 |
| 78 // Used when kOptimizeLoadingIPCForSmallResources is enabled. | 87 // Used when kOptimizeLoadingIPCForSmallResources is enabled. |
| 79 // The instance hooks the buffer allocation of AsyncResourceHandler, and | 88 // The instance hooks the buffer allocation of AsyncResourceHandler, and |
| 80 // determine if we should use SharedMemory or should inline the data into | 89 // determine if we should use SharedMemory or should inline the data into |
| 81 // the IPC message. | 90 // the IPC message. |
| 82 class AsyncResourceHandler::InliningHelper { | 91 class AsyncResourceHandler::InliningHelper { |
| 83 public: | 92 public: |
| 84 | 93 |
| 85 InliningHelper() {} | 94 InliningHelper() {} |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 public: | 194 public: |
| 186 DependentIOBuffer(ResourceBuffer* backing, char* memory) | 195 DependentIOBuffer(ResourceBuffer* backing, char* memory) |
| 187 : net::WrappedIOBuffer(memory), | 196 : net::WrappedIOBuffer(memory), |
| 188 backing_(backing) { | 197 backing_(backing) { |
| 189 } | 198 } |
| 190 private: | 199 private: |
| 191 ~DependentIOBuffer() override {} | 200 ~DependentIOBuffer() override {} |
| 192 scoped_refptr<ResourceBuffer> backing_; | 201 scoped_refptr<ResourceBuffer> backing_; |
| 193 }; | 202 }; |
| 194 | 203 |
| 195 AsyncResourceHandler::AsyncResourceHandler( | 204 AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request, |
| 196 net::URLRequest* request, | 205 ResourceDispatcherHostImpl* rdh) |
| 197 ResourceDispatcherHostImpl* rdh) | |
| 198 : ResourceHandler(request), | 206 : ResourceHandler(request), |
| 199 ResourceMessageDelegate(request), | 207 ResourceMessageDelegate(request), |
| 200 rdh_(rdh), | 208 rdh_(rdh), |
| 201 pending_data_count_(0), | 209 pending_data_count_(0), |
| 202 allocation_size_(0), | 210 allocation_size_(0), |
| 211 total_read_body_bytes_(0), | |
| 203 did_defer_(false), | 212 did_defer_(false), |
| 204 has_checked_for_sufficient_resources_(false), | 213 has_checked_for_sufficient_resources_(false), |
| 205 sent_received_response_msg_(false), | 214 sent_received_response_msg_(false), |
| 206 sent_data_buffer_msg_(false), | 215 sent_data_buffer_msg_(false), |
| 207 inlining_helper_(new InliningHelper), | 216 inlining_helper_(new InliningHelper), |
| 208 reported_transfer_size_(0) { | 217 reported_transfer_size_(0) { |
| 209 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); | 218 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); |
| 210 InitializeResourceBufferConstants(); | 219 InitializeResourceBufferConstants(); |
| 211 } | 220 } |
| 212 | 221 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 first_chunk_read_ = true; | 398 first_chunk_read_ = true; |
| 390 | 399 |
| 391 // Return early if InliningHelper handled the received data. | 400 // Return early if InliningHelper handled the received data. |
| 392 if (inlining_helper_->SendInlinedDataIfApplicable( | 401 if (inlining_helper_->SendInlinedDataIfApplicable( |
| 393 bytes_read, encoded_data_length, filter, | 402 bytes_read, encoded_data_length, filter, |
| 394 GetRequestID())) | 403 GetRequestID())) |
| 395 return true; | 404 return true; |
| 396 | 405 |
| 397 buffer_->ShrinkLastAllocation(bytes_read); | 406 buffer_->ShrinkLastAllocation(bytes_read); |
| 398 | 407 |
| 408 total_read_body_bytes_ += bytes_read; | |
| 409 | |
| 399 if (!sent_data_buffer_msg_) { | 410 if (!sent_data_buffer_msg_) { |
| 400 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( | 411 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( |
| 401 buffer_->GetSharedMemory().handle()); | 412 buffer_->GetSharedMemory().handle()); |
| 402 if (!base::SharedMemory::IsHandleValid(handle)) | 413 if (!base::SharedMemory::IsHandleValid(handle)) |
| 403 return false; | 414 return false; |
| 404 filter->Send(new ResourceMsg_SetDataBuffer( | 415 filter->Send(new ResourceMsg_SetDataBuffer( |
| 405 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), | 416 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), |
| 406 filter->peer_pid())); | 417 filter->peer_pid())); |
| 407 sent_data_buffer_msg_ = true; | 418 sent_data_buffer_msg_ = true; |
| 408 } | 419 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 UMA_HISTOGRAM_CUSTOM_COUNTS( | 556 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 546 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", | 557 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", |
| 547 elapsed_time, 1, 100000, 100); | 558 elapsed_time, 1, 100000, 100); |
| 548 } else { | 559 } else { |
| 549 UMA_HISTOGRAM_CUSTOM_COUNTS( | 560 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 550 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", | 561 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", |
| 551 elapsed_time, 1, 100000, 100); | 562 elapsed_time, 1, 100000, 100); |
| 552 } | 563 } |
| 553 | 564 |
| 554 inlining_helper_->RecordHistogram(elapsed_time); | 565 inlining_helper_->RecordHistogram(elapsed_time); |
| 566 | |
| 567 // Record if content size was known in advance. | |
| 568 int64_t expected_content_size = request()->GetExpectedContentSize(); | |
| 569 ExpectedContentSizeResult expected_content_size_result = | |
| 570 ExpectedContentSizeResult::UNKNOWN; | |
| 571 if (expected_content_size >= 0) { | |
| 572 // Compare response body size to expected content size. | |
| 573 if (expected_content_size == total_read_body_bytes_ && | |
| 574 expected_content_size >= kBufferSize) { | |
| 575 expected_content_size_result = | |
| 576 ExpectedContentSizeResult::EQ_RESPONSE_BODY_MT_EQ_BUFFER_SIZE; | |
|
mmenke
2017/01/17 15:58:27
I think we should have another bucket for other "e
maksims (do not use this acc)
2017/01/18 07:50:26
I see. Added!
| |
| 577 } else if (expected_content_size == total_read_body_bytes_) { | |
| 578 expected_content_size_result = | |
| 579 ExpectedContentSizeResult::EQ_RESPONSE_BODY; | |
| 580 } else if (expected_content_size < total_read_body_bytes_) { | |
| 581 expected_content_size_result = | |
| 582 ExpectedContentSizeResult::LT_RESPONSE_BODY; | |
| 583 } else { | |
| 584 expected_content_size_result = | |
| 585 ExpectedContentSizeResult::MT_RESPONSE_BODY; | |
|
mmenke
2017/01/17 15:58:27
nit: GT's more common.
maksims (do not use this acc)
2017/01/18 07:50:26
Done.
| |
| 586 } | |
| 587 } | |
| 588 UMA_HISTOGRAM_ENUMERATION("Net.ResourceLoader.ExpectedContentSizeResult", | |
| 589 expected_content_size_result, | |
| 590 ExpectedContentSizeResult::EXPECTED_CONTENT_MAX); | |
| 555 } | 591 } |
| 556 | 592 |
| 557 void AsyncResourceHandler::SendUploadProgress( | 593 void AsyncResourceHandler::SendUploadProgress( |
| 558 const net::UploadProgress& progress) { | 594 const net::UploadProgress& progress) { |
| 559 ResourceMessageFilter* filter = GetFilter(); | 595 ResourceMessageFilter* filter = GetFilter(); |
| 560 if (!filter) | 596 if (!filter) |
| 561 return; | 597 return; |
| 562 filter->Send(new ResourceMsg_UploadProgress( | 598 filter->Send(new ResourceMsg_UploadProgress( |
| 563 GetRequestID(), progress.position(), progress.size())); | 599 GetRequestID(), progress.position(), progress.size())); |
| 564 } | 600 } |
| 565 | 601 |
| 566 } // namespace content | 602 } // namespace content |
| OLD | NEW |