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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 static bool did_init = false; | 65 static bool did_init = false; |
| 66 if (did_init) | 66 if (did_init) |
| 67 return; | 67 return; |
| 68 did_init = true; | 68 did_init = true; |
| 69 | 69 |
| 70 GetNumericArg("resource-buffer-size", &kBufferSize); | 70 GetNumericArg("resource-buffer-size", &kBufferSize); |
| 71 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize); | 71 GetNumericArg("resource-buffer-min-allocation-size", &kMinAllocationSize); |
| 72 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize); | 72 GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize); |
| 73 } | 73 } |
| 74 | 74 |
| 75 enum ExpectedContentSize { | |
| 76 EQ_RESPONSE_BODY = 0, | |
| 77 EQ_RESPONSE_BODY_MT_EQ_BUFFER_SIZE = 1, | |
| 78 LT_RESPONSE_BODY = 2, | |
| 79 MT_RESPONSE_BODY = 3, | |
| 80 UNKNOWN = 4, | |
| 81 EXPECTED_CONTENT_MAX, | |
| 82 }; | |
| 83 | |
| 75 } // namespace | 84 } // namespace |
| 76 | 85 |
| 77 // Used when kOptimizeLoadingIPCForSmallResources is enabled. | 86 // Used when kOptimizeLoadingIPCForSmallResources is enabled. |
| 78 // The instance hooks the buffer allocation of AsyncResourceHandler, and | 87 // The instance hooks the buffer allocation of AsyncResourceHandler, and |
| 79 // determine if we should use SharedMemory or should inline the data into | 88 // determine if we should use SharedMemory or should inline the data into |
| 80 // the IPC message. | 89 // the IPC message. |
| 81 class AsyncResourceHandler::InliningHelper { | 90 class AsyncResourceHandler::InliningHelper { |
| 82 public: | 91 public: |
| 83 | 92 |
| 84 InliningHelper() {} | 93 InliningHelper() {} |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 public: | 193 public: |
| 185 DependentIOBuffer(ResourceBuffer* backing, char* memory) | 194 DependentIOBuffer(ResourceBuffer* backing, char* memory) |
| 186 : net::WrappedIOBuffer(memory), | 195 : net::WrappedIOBuffer(memory), |
| 187 backing_(backing) { | 196 backing_(backing) { |
| 188 } | 197 } |
| 189 private: | 198 private: |
| 190 ~DependentIOBuffer() override {} | 199 ~DependentIOBuffer() override {} |
| 191 scoped_refptr<ResourceBuffer> backing_; | 200 scoped_refptr<ResourceBuffer> backing_; |
| 192 }; | 201 }; |
| 193 | 202 |
| 194 AsyncResourceHandler::AsyncResourceHandler( | 203 AsyncResourceHandler::AsyncResourceHandler(net::URLRequest* request, |
| 195 net::URLRequest* request, | 204 ResourceDispatcherHostImpl* rdh) |
| 196 ResourceDispatcherHostImpl* rdh) | |
| 197 : ResourceHandler(request), | 205 : ResourceHandler(request), |
| 198 ResourceMessageDelegate(request), | 206 ResourceMessageDelegate(request), |
| 199 rdh_(rdh), | 207 rdh_(rdh), |
| 200 pending_data_count_(0), | 208 pending_data_count_(0), |
| 201 allocation_size_(0), | 209 allocation_size_(0), |
| 210 total_read_body_bytes_(0), | |
| 202 did_defer_(false), | 211 did_defer_(false), |
| 203 has_checked_for_sufficient_resources_(false), | 212 has_checked_for_sufficient_resources_(false), |
| 204 sent_received_response_msg_(false), | 213 sent_received_response_msg_(false), |
| 205 sent_data_buffer_msg_(false), | 214 sent_data_buffer_msg_(false), |
| 206 inlining_helper_(new InliningHelper), | 215 inlining_helper_(new InliningHelper), |
| 207 reported_transfer_size_(0) { | 216 reported_transfer_size_(0) { |
| 208 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); | 217 DCHECK(GetRequestInfo()->requester_info()->IsRenderer()); |
| 209 InitializeResourceBufferConstants(); | 218 InitializeResourceBufferConstants(); |
| 210 } | 219 } |
| 211 | 220 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 first_chunk_read_ = true; | 397 first_chunk_read_ = true; |
| 389 | 398 |
| 390 // Return early if InliningHelper handled the received data. | 399 // Return early if InliningHelper handled the received data. |
| 391 if (inlining_helper_->SendInlinedDataIfApplicable( | 400 if (inlining_helper_->SendInlinedDataIfApplicable( |
| 392 bytes_read, encoded_data_length, filter, | 401 bytes_read, encoded_data_length, filter, |
| 393 GetRequestID())) | 402 GetRequestID())) |
| 394 return true; | 403 return true; |
| 395 | 404 |
| 396 buffer_->ShrinkLastAllocation(bytes_read); | 405 buffer_->ShrinkLastAllocation(bytes_read); |
| 397 | 406 |
| 407 total_read_body_bytes_ += bytes_read; | |
| 408 | |
| 398 if (!sent_data_buffer_msg_) { | 409 if (!sent_data_buffer_msg_) { |
| 399 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( | 410 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( |
| 400 buffer_->GetSharedMemory().handle()); | 411 buffer_->GetSharedMemory().handle()); |
| 401 if (!base::SharedMemory::IsHandleValid(handle)) | 412 if (!base::SharedMemory::IsHandleValid(handle)) |
| 402 return false; | 413 return false; |
| 403 filter->Send(new ResourceMsg_SetDataBuffer( | 414 filter->Send(new ResourceMsg_SetDataBuffer( |
| 404 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), | 415 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), |
| 405 filter->peer_pid())); | 416 filter->peer_pid())); |
| 406 sent_data_buffer_msg_ = true; | 417 sent_data_buffer_msg_ = true; |
| 407 } | 418 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 UMA_HISTOGRAM_CUSTOM_COUNTS( | 555 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 545 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", | 556 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", |
| 546 elapsed_time, 1, 100000, 100); | 557 elapsed_time, 1, 100000, 100); |
| 547 } else { | 558 } else { |
| 548 UMA_HISTOGRAM_CUSTOM_COUNTS( | 559 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 549 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", | 560 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", |
| 550 elapsed_time, 1, 100000, 100); | 561 elapsed_time, 1, 100000, 100); |
| 551 } | 562 } |
| 552 | 563 |
| 553 inlining_helper_->RecordHistogram(elapsed_time); | 564 inlining_helper_->RecordHistogram(elapsed_time); |
| 565 | |
| 566 // Record if content size was known in advance. | |
| 567 int64_t expected_content_size = request()->GetExpectedContentSize(); | |
| 568 if (expected_content_size >= 0) { | |
|
mmenke
2017/01/13 16:01:36
Having ExpectedContentSize be an enum that's not a
maksims (do not use this acc)
2017/01/16 07:25:22
Done.
| |
| 569 // Compare response body size to expected content size. | |
| 570 if (expected_content_size == total_read_body_bytes_ && | |
| 571 expected_content_size >= kBufferSize) { | |
| 572 UMA_HISTOGRAM_ENUMERATION( | |
| 573 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize", | |
|
mmenke
2017/01/13 16:01:36
Suggest just replacing "ExpectedContentSize.Corres
maksims (do not use this acc)
2017/01/16 07:25:22
Done.
| |
| 574 ExpectedContentSize::EQ_RESPONSE_BODY_MT_EQ_BUFFER_SIZE, | |
| 575 ExpectedContentSize::EXPECTED_CONTENT_MAX); | |
|
mmenke
2017/01/13 16:01:36
You only need one UMA_HISTOGRAM_ENUMERATION call h
maksims (do not use this acc)
2017/01/16 07:25:21
Done.
| |
| 576 } else if (expected_content_size == total_read_body_bytes_) { | |
| 577 UMA_HISTOGRAM_ENUMERATION( | |
| 578 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize", | |
| 579 ExpectedContentSize::EQ_RESPONSE_BODY, | |
| 580 ExpectedContentSize::EXPECTED_CONTENT_MAX); | |
| 581 } else if (expected_content_size < total_read_body_bytes_) { | |
| 582 UMA_HISTOGRAM_ENUMERATION( | |
| 583 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize", | |
| 584 ExpectedContentSize::LT_RESPONSE_BODY, | |
| 585 ExpectedContentSize::EXPECTED_CONTENT_MAX); | |
| 586 } else { | |
| 587 UMA_HISTOGRAM_ENUMERATION( | |
| 588 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize", | |
| 589 ExpectedContentSize::MT_RESPONSE_BODY, | |
| 590 ExpectedContentSize::EXPECTED_CONTENT_MAX); | |
| 591 } | |
| 592 } else { | |
| 593 UMA_HISTOGRAM_ENUMERATION( | |
| 594 "Net.ResourceLoader.ExpectedContentSize.CorrespondsBodySize", | |
| 595 ExpectedContentSize::UNKNOWN, | |
| 596 ExpectedContentSize::EXPECTED_CONTENT_MAX); | |
| 597 } | |
| 598 total_read_body_bytes_ = 0; | |
|
mmenke
2017/01/13 16:01:36
Not needed. This class is only used to read one r
maksims (do not use this acc)
2017/01/16 07:25:21
Done.
| |
| 554 } | 599 } |
| 555 | 600 |
| 556 void AsyncResourceHandler::SendUploadProgress(int64_t current_position, | 601 void AsyncResourceHandler::SendUploadProgress(int64_t current_position, |
| 557 int64_t total_size) { | 602 int64_t total_size) { |
| 558 ResourceMessageFilter* filter = GetFilter(); | 603 ResourceMessageFilter* filter = GetFilter(); |
| 559 if (!filter) | 604 if (!filter) |
| 560 return; | 605 return; |
| 561 filter->Send(new ResourceMsg_UploadProgress( | 606 filter->Send(new ResourceMsg_UploadProgress( |
| 562 GetRequestID(), current_position, total_size)); | 607 GetRequestID(), current_position, total_size)); |
| 563 } | 608 } |
| 564 | 609 |
| 565 } // namespace content | 610 } // namespace content |
| OLD | NEW |