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

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

Issue 2506363005: Send encoded_body_length to renderer when response completed (3/3) (Closed)
Patch Set: fix Created 4 years, 1 month 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 leading_chunk_buffer_ = new net::IOBuffer(kInlinedLeadingChunkSize); 119 leading_chunk_buffer_ = new net::IOBuffer(kInlinedLeadingChunkSize);
120 *buf = leading_chunk_buffer_; 120 *buf = leading_chunk_buffer_;
121 *buf_size = kInlinedLeadingChunkSize; 121 *buf_size = kInlinedLeadingChunkSize;
122 return true; 122 return true;
123 } 123 }
124 124
125 // Returns true if the received data is sent to the consumer. 125 // Returns true if the received data is sent to the consumer.
126 bool SendInlinedDataIfApplicable(int bytes_read, 126 bool SendInlinedDataIfApplicable(int bytes_read,
127 int encoded_data_length, 127 int encoded_data_length,
128 int encoded_body_length,
129 IPC::Sender* sender, 128 IPC::Sender* sender,
130 int request_id) { 129 int request_id) {
131 DCHECK(sender); 130 DCHECK(sender);
132 if (!leading_chunk_buffer_) 131 if (!leading_chunk_buffer_)
133 return false; 132 return false;
134 133
135 std::vector<char> data( 134 std::vector<char> data(
136 leading_chunk_buffer_->data(), 135 leading_chunk_buffer_->data(),
137 leading_chunk_buffer_->data() + bytes_read); 136 leading_chunk_buffer_->data() + bytes_read);
138 leading_chunk_buffer_ = nullptr; 137 leading_chunk_buffer_ = nullptr;
139 138
140 sender->Send(new ResourceMsg_InlinedDataChunkReceived( 139 sender->Send(new ResourceMsg_InlinedDataChunkReceived(
141 request_id, data, encoded_data_length, encoded_body_length)); 140 request_id, data, encoded_data_length));
142 return true; 141 return true;
143 } 142 }
144 143
145 void RecordHistogram(int64_t elapsed_time) { 144 void RecordHistogram(int64_t elapsed_time) {
146 if (inlining_applicable_) { 145 if (inlining_applicable_) {
147 UMA_HISTOGRAM_CUSTOM_COUNTS( 146 UMA_HISTOGRAM_CUSTOM_COUNTS(
148 "Net.ResourceLoader.ResponseStartToEnd.InliningApplicable", 147 "Net.ResourceLoader.ResponseStartToEnd.InliningApplicable",
149 elapsed_time, 1, 100000, 100); 148 elapsed_time, 1, 100000, 100);
150 } 149 }
151 } 150 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 rdh_(rdh), 207 rdh_(rdh),
209 pending_data_count_(0), 208 pending_data_count_(0),
210 allocation_size_(0), 209 allocation_size_(0),
211 did_defer_(false), 210 did_defer_(false),
212 has_checked_for_sufficient_resources_(false), 211 has_checked_for_sufficient_resources_(false),
213 sent_received_response_msg_(false), 212 sent_received_response_msg_(false),
214 sent_data_buffer_msg_(false), 213 sent_data_buffer_msg_(false),
215 inlining_helper_(new InliningHelper), 214 inlining_helper_(new InliningHelper),
216 last_upload_position_(0), 215 last_upload_position_(0),
217 waiting_for_upload_progress_ack_(false), 216 waiting_for_upload_progress_ack_(false),
218 reported_transfer_size_(0), 217 reported_transfer_size_(0) {
219 reported_encoded_body_length_(0) {
220 InitializeResourceBufferConstants(); 218 InitializeResourceBufferConstants();
221 } 219 }
222 220
223 AsyncResourceHandler::~AsyncResourceHandler() { 221 AsyncResourceHandler::~AsyncResourceHandler() {
224 if (has_checked_for_sufficient_resources_) 222 if (has_checked_for_sufficient_resources_)
225 rdh_->FinishedWithResourcesForRequest(request()); 223 rdh_->FinishedWithResourcesForRequest(request());
226 } 224 }
227 225
228 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) { 226 bool AsyncResourceHandler::OnMessageReceived(const IPC::Message& message) {
229 bool handled = true; 227 bool handled = true;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return true; 421 return true;
424 422
425 ResourceMessageFilter* filter = GetFilter(); 423 ResourceMessageFilter* filter = GetFilter();
426 if (!filter) 424 if (!filter)
427 return false; 425 return false;
428 426
429 int encoded_data_length = CalculateEncodedDataLengthToReport(); 427 int encoded_data_length = CalculateEncodedDataLengthToReport();
430 if (!first_chunk_read_) 428 if (!first_chunk_read_)
431 encoded_data_length -= request()->raw_header_size(); 429 encoded_data_length -= request()->raw_header_size();
432 430
433 int encoded_body_length = CalculateEncodedBodyLengthToReport();
434 first_chunk_read_ = true; 431 first_chunk_read_ = true;
435 432
436 // Return early if InliningHelper handled the received data. 433 // Return early if InliningHelper handled the received data.
437 if (inlining_helper_->SendInlinedDataIfApplicable( 434 if (inlining_helper_->SendInlinedDataIfApplicable(
438 bytes_read, encoded_data_length, encoded_body_length, filter, 435 bytes_read, encoded_data_length, filter,
439 GetRequestID())) 436 GetRequestID()))
440 return true; 437 return true;
441 438
442 buffer_->ShrinkLastAllocation(bytes_read); 439 buffer_->ShrinkLastAllocation(bytes_read);
443 440
444 if (!sent_data_buffer_msg_) { 441 if (!sent_data_buffer_msg_) {
445 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle( 442 base::SharedMemoryHandle handle = base::SharedMemory::DuplicateHandle(
446 buffer_->GetSharedMemory().handle()); 443 buffer_->GetSharedMemory().handle());
447 if (!base::SharedMemory::IsHandleValid(handle)) 444 if (!base::SharedMemory::IsHandleValid(handle))
448 return false; 445 return false;
449 filter->Send(new ResourceMsg_SetDataBuffer( 446 filter->Send(new ResourceMsg_SetDataBuffer(
450 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(), 447 GetRequestID(), handle, buffer_->GetSharedMemory().mapped_size(),
451 filter->peer_pid())); 448 filter->peer_pid()));
452 sent_data_buffer_msg_ = true; 449 sent_data_buffer_msg_ = true;
453 } 450 }
454 451
455 int data_offset = buffer_->GetLastAllocationOffset(); 452 int data_offset = buffer_->GetLastAllocationOffset();
456 453
457 filter->Send(new ResourceMsg_DataReceived(GetRequestID(), data_offset, 454 filter->Send(new ResourceMsg_DataReceived(GetRequestID(), data_offset,
458 bytes_read, encoded_data_length, 455 bytes_read, encoded_data_length));
459 encoded_body_length));
460 ++pending_data_count_; 456 ++pending_data_count_;
461 457
462 if (!buffer_->CanAllocate()) { 458 if (!buffer_->CanAllocate()) {
463 *defer = did_defer_ = true; 459 *defer = did_defer_ = true;
464 OnDefer(); 460 OnDefer();
465 } 461 }
466 462
467 return true; 463 return true;
468 } 464 }
469 465
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 has_checked_for_sufficient_resources_ = true; 548 has_checked_for_sufficient_resources_ = true;
553 549
554 if (rdh_->HasSufficientResourcesForRequest(request())) 550 if (rdh_->HasSufficientResourcesForRequest(request()))
555 return true; 551 return true;
556 552
557 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES); 553 controller()->CancelWithError(net::ERR_INSUFFICIENT_RESOURCES);
558 return false; 554 return false;
559 } 555 }
560 556
561 int AsyncResourceHandler::CalculateEncodedDataLengthToReport() { 557 int AsyncResourceHandler::CalculateEncodedDataLengthToReport() {
562 return TrackDifference(request()->GetTotalReceivedBytes(), 558 return TrackDifference(request()->GetTotalReceivedBytes(),
Adam Rice 2016/11/21 09:46:41 Optional: this is now the only caller of TrackDiff
563 &reported_transfer_size_); 559 &reported_transfer_size_);
564 } 560 }
565 561
566 int AsyncResourceHandler::CalculateEncodedBodyLengthToReport() {
567 return TrackDifference(request()->GetRawBodyBytes(),
568 &reported_encoded_body_length_);
569 }
570
571 void AsyncResourceHandler::RecordHistogram() { 562 void AsyncResourceHandler::RecordHistogram() {
572 int64_t elapsed_time = 563 int64_t elapsed_time =
573 (base::TimeTicks::Now() - response_started_ticks_).InMicroseconds(); 564 (base::TimeTicks::Now() - response_started_ticks_).InMicroseconds();
574 int64_t encoded_length = request()->GetTotalReceivedBytes(); 565 int64_t encoded_length = request()->GetTotalReceivedBytes();
575 if (encoded_length < 2 * 1024) { 566 if (encoded_length < 2 * 1024) {
576 // The resource was smaller than the smallest required buffer size. 567 // The resource was smaller than the smallest required buffer size.
577 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_2kB", 568 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_2kB",
578 elapsed_time, 1, 100000, 100); 569 elapsed_time, 1, 100000, 100);
579 } else if (encoded_length < 32 * 1024) { 570 } else if (encoded_length < 32 * 1024) {
580 // The resource was smaller than single chunk. 571 // The resource was smaller than single chunk.
581 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_32kB", 572 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.ResourceLoader.ResponseStartToEnd.LT_32kB",
582 elapsed_time, 1, 100000, 100); 573 elapsed_time, 1, 100000, 100);
583 } else if (encoded_length < 512 * 1024) { 574 } else if (encoded_length < 512 * 1024) {
584 // The resource was smaller than single chunk. 575 // The resource was smaller than single chunk.
585 UMA_HISTOGRAM_CUSTOM_COUNTS( 576 UMA_HISTOGRAM_CUSTOM_COUNTS(
586 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB", 577 "Net.ResourceLoader.ResponseStartToEnd.LT_512kB",
587 elapsed_time, 1, 100000, 100); 578 elapsed_time, 1, 100000, 100);
588 } else { 579 } else {
589 UMA_HISTOGRAM_CUSTOM_COUNTS( 580 UMA_HISTOGRAM_CUSTOM_COUNTS(
590 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB", 581 "Net.ResourceLoader.ResponseStartToEnd.Over_512kB",
591 elapsed_time, 1, 100000, 100); 582 elapsed_time, 1, 100000, 100);
592 } 583 }
593 584
594 inlining_helper_->RecordHistogram(elapsed_time); 585 inlining_helper_->RecordHistogram(elapsed_time);
595 } 586 }
596 587
597 } // namespace content 588 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/async_resource_handler.h ('k') | content/browser/loader/async_resource_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698