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

Side by Side Diff: content/browser/loader/async_resource_handler.cc

Issue 2092993002: Browser process changes for Resource Timing sizes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compilation of resource_dispatcher_unittest.cc Created 4 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
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 #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
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 // Returns the value of new_length - *cached_length, also updating
76 // *cached_length to new_length.
Mike West 2016/06/24 10:49:20 "length" is a weird-looking word. Especially when
Adam Rice 2016/07/07 06:50:09 You could try filing a bug against the English lan
77 int CalculateLengthDifference(int64_t new_length, int64_t* cached_length) {
78 int length_difference = new_length - *cached_length;
79 *cached_length = new_length;
80 return length_difference;
81 }
82
75 } // namespace 83 } // namespace
76 84
77 // Used when kOptimizeLoadingIPCForSmallResources is enabled. 85 // Used when kOptimizeLoadingIPCForSmallResources is enabled.
78 // The instance hooks the buffer allocation of AsyncResourceHandler, and 86 // The instance hooks the buffer allocation of AsyncResourceHandler, and
79 // determine if we should use SharedMemory or should inline the data into 87 // determine if we should use SharedMemory or should inline the data into
80 // the IPC message. 88 // the IPC message.
81 class AsyncResourceHandler::InliningHelper { 89 class AsyncResourceHandler::InliningHelper {
82 public: 90 public:
83 91
84 InliningHelper() {} 92 InliningHelper() {}
(...skipping 25 matching lines...) Expand all
110 118
111 leading_chunk_buffer_ = new net::IOBuffer(kInlinedLeadingChunkSize); 119 leading_chunk_buffer_ = new net::IOBuffer(kInlinedLeadingChunkSize);
112 *buf = leading_chunk_buffer_; 120 *buf = leading_chunk_buffer_;
113 *buf_size = kInlinedLeadingChunkSize; 121 *buf_size = kInlinedLeadingChunkSize;
114 return true; 122 return true;
115 } 123 }
116 124
117 // Returns true if the received data is sent to the consumer. 125 // Returns true if the received data is sent to the consumer.
118 bool SendInlinedDataIfApplicable(int bytes_read, 126 bool SendInlinedDataIfApplicable(int bytes_read,
119 int encoded_data_length, 127 int encoded_data_length,
128 int encoded_body_length,
120 IPC::Sender* sender, 129 IPC::Sender* sender,
121 int request_id) { 130 int request_id) {
122 DCHECK(sender); 131 DCHECK(sender);
123 if (!leading_chunk_buffer_) 132 if (!leading_chunk_buffer_)
124 return false; 133 return false;
125 134
126 std::vector<char> data( 135 std::vector<char> data(
127 leading_chunk_buffer_->data(), 136 leading_chunk_buffer_->data(),
128 leading_chunk_buffer_->data() + bytes_read); 137 leading_chunk_buffer_->data() + bytes_read);
129 leading_chunk_buffer_ = nullptr; 138 leading_chunk_buffer_ = nullptr;
130 139
131 sender->Send(new ResourceMsg_InlinedDataChunkReceived( 140 sender->Send(new ResourceMsg_InlinedDataChunkReceived(
132 request_id, data, encoded_data_length)); 141 request_id, data, encoded_data_length, encoded_body_length));
133 return true; 142 return true;
134 } 143 }
135 144
136 void RecordHistogram(int64_t elapsed_time) { 145 void RecordHistogram(int64_t elapsed_time) {
137 if (inlining_applicable_) { 146 if (inlining_applicable_) {
138 UMA_HISTOGRAM_CUSTOM_COUNTS( 147 UMA_HISTOGRAM_CUSTOM_COUNTS(
139 "Net.ResourceLoader.ResponseStartToEnd.InliningApplicable", 148 "Net.ResourceLoader.ResponseStartToEnd.InliningApplicable",
140 elapsed_time, 1, 100000, 100); 149 elapsed_time, 1, 100000, 100);
141 } 150 }
142 } 151 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 rdh_(rdh), 208 rdh_(rdh),
200 pending_data_count_(0), 209 pending_data_count_(0),
201 allocation_size_(0), 210 allocation_size_(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 last_upload_position_(0), 216 last_upload_position_(0),
208 waiting_for_upload_progress_ack_(false), 217 waiting_for_upload_progress_ack_(false),
209 reported_transfer_size_(0) { 218 reported_transfer_size_(0),
219 reported_encoded_body_length_(0) {
210 InitializeResourceBufferConstants(); 220 InitializeResourceBufferConstants();
211 } 221 }
212 222
213 AsyncResourceHandler::~AsyncResourceHandler() { 223 AsyncResourceHandler::~AsyncResourceHandler() {
214 if (has_checked_for_sufficient_resources_) 224 if (has_checked_for_sufficient_resources_)
215 rdh_->FinishedWithResourcesForRequest(request()); 225 rdh_->FinishedWithResourcesForRequest(request());
216 } 226 }
217 227
218 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) { 228 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) {
219 bool handled = true; 229 bool handled = true;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 DCHECK_GE(bytes_read, 0); 443 DCHECK_GE(bytes_read, 0);
434 444
435 if (!bytes_read) 445 if (!bytes_read)
436 return true; 446 return true;
437 447
438 ResourceMessageFilter* filter = GetFilter(); 448 ResourceMessageFilter* filter = GetFilter();
439 if (!filter) 449 if (!filter)
440 return false; 450 return false;
441 451
442 int encoded_data_length = CalculateEncodedDataLengthToReport(); 452 int encoded_data_length = CalculateEncodedDataLengthToReport();
453 int encoded_body_length = CalculateEncodedBodyLengthToReport();
443 454
444 // Return early if InliningHelper handled the received data. 455 // Return early if InliningHelper handled the received data.
445 if (inlining_helper_->SendInlinedDataIfApplicable( 456 if (inlining_helper_->SendInlinedDataIfApplicable(
446 bytes_read, encoded_data_length, filter, GetRequestID())) 457 bytes_read, encoded_data_length, encoded_body_length, filter,
458 GetRequestID()))
447 return true; 459 return true;
448 460
449 buffer_->ShrinkLastAllocation(bytes_read); 461 buffer_->ShrinkLastAllocation(bytes_read);
450 462
451 if (!sent_data_buffer_msg_) { 463 if (!sent_data_buffer_msg_) {
452 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( 464 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle(
453 buffer_->GetSharedMemory().handle()); 465 buffer_->GetSharedMemory().handle());
454 if (!base::SharedMemory::IsHandleValid(handle)) 466 if (!base::SharedMemory::IsHandleValid(handle))
455 return false; 467 return false;
456 filter->Send(new ResourceMsg_SetDataBuffer( 468 filter->Send(new ResourceMsg_SetDataBuffer(
457 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), 469 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(),
458 filter->peer_pid())); 470 filter->peer_pid()));
459 sent_data_buffer_msg_ = true; 471 sent_data_buffer_msg_ = true;
460 } 472 }
461 473
462 int data_offset = buffer_->GetLastAllocationOffset(); 474 int data_offset = buffer_->GetLastAllocationOffset();
463 475
464 filter->Send(new ResourceMsg_DataReceived( 476 filter->Send(new ResourceMsg_DataReceived(GetRequestID(), data_offset,
465 GetRequestID(), data_offset, bytes_read, encoded_data_length)); 477 bytes_read, encoded_data_length,
478 encoded_body_length));
466 ++pending_data_count_; 479 ++pending_data_count_;
467 480
468 if (!buffer_->CanAllocate()) { 481 if (!buffer_->CanAllocate()) {
469 *defer = did_defer_ = true; 482 *defer = did_defer_ = true;
470 OnDefer(); 483 OnDefer();
471 } 484 }
472 485
473 return true; 486 return true;
474 } 487 }
475 488
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 has_checked_for_sufficient_resources_ = true; 582 has_checked_for_sufficient_resources_ = true;
570 583
571 if (rdh_->HasSufficientResourcesForRequest(request())) 584 if (rdh_->HasSufficientResourcesForRequest(request()))
572 return true; 585 return true;
573 586
574 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); 587 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
575 return false; 588 return false;
576 } 589 }
577 590
578 int AsyncResourceHandler::CalculateEncodedDataLengthToReport() { 591 int AsyncResourceHandler::CalculateEncodedDataLengthToReport() {
579 int64_t current_transfer_size = request()->GetTotalReceivedBytes(); 592 return CalculateLengthDifference(request()->GetTotalReceivedBytes(),
580 int encoded_data_length = current_transfer_size - reported_transfer_size_; 593 &reported_transfer_size_);
581 reported_transfer_size_ = current_transfer_size; 594 }
582 return encoded_data_length; 595
596 int AsyncResourceHandler::CalculateEncodedBodyLengthToReport() {
597 return CalculateLengthDifference(request()->GetRawBodyBytes(),
598 &reported_encoded_body_length_);
583 } 599 }
584 600
585 void AsyncResourceHandler::RecordHistogram() { 601 void AsyncResourceHandler::RecordHistogram() {
586 int64_t elapsed_time = 602 int64_t elapsed_time =
587 (base::TimeTicks::Now() - response_started_ticks_).InMicroseconds(); 603 (base::TimeTicks::Now() - response_started_ticks_).InMicroseconds();
588 int64_t encoded_length = request()->GetTotalReceivedBytes(); 604 int64_t encoded_length = request()->GetTotalReceivedBytes();
589 if (encoded_length < 2 * 1024) { 605 if (encoded_length < 2 * 1024) {
590 // The resource was smaller than the smallest required buffer size. 606 // The resource was smaller than the smallest required buffer size.
591 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_2kB", 607 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_2kB",
592 elapsed_time, 1, 100000, 100); 608 elapsed_time, 1, 100000, 100);
593 } else if (encoded_length < 32 * 1024) { 609 } else if (encoded_length < 32 * 1024) {
594 // The resource was smaller than single chunk. 610 // The resource was smaller than single chunk.
595 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_32kB", 611 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_32kB",
596 elapsed_time, 1, 100000, 100); 612 elapsed_time, 1, 100000, 100);
597 } else if (encoded_length < 512 * 1024) { 613 } else if (encoded_length < 512 * 1024) {
598 // The resource was smaller than single chunk. 614 // The resource was smaller than single chunk.
599 UMA_HISTOGRAM_CUSTOM_COUNTS( 615 UMA_HISTOGRAM_CUSTOM_COUNTS(
600 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", 616 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB",
601 elapsed_time, 1, 100000, 100); 617 elapsed_time, 1, 100000, 100);
602 } else { 618 } else {
603 UMA_HISTOGRAM_CUSTOM_COUNTS( 619 UMA_HISTOGRAM_CUSTOM_COUNTS(
604 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", 620 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB",
605 elapsed_time, 1, 100000, 100); 621 elapsed_time, 1, 100000, 100);
606 } 622 }
607 623
608 inlining_helper_->RecordHistogram(elapsed_time); 624 inlining_helper_->RecordHistogram(elapsed_time);
609 } 625 }
610 626
611 } // namespace content 627 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698