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

Unified 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: Stop using AllocateForTesting() Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/loader/async_resource_handler.cc
diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc
index 321b0de619bf68d689a4476e6487286ff235210e..4c7b2fb6ff93e5cc7f3176dfd2ce4db873caa8c8 100644
--- a/content/browser/loader/async_resource_handler.cc
+++ b/content/browser/loader/async_resource_handler.cc
@@ -29,6 +29,7 @@
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/common/content_features.h"
#include "content/public/common/resource_response.h"
+#include "ipc/ipc_message_macros.h"
#include "net/base/io_buffer.h"
#include "net/base/load_flags.h"
#include "net/log/net_log.h"
@@ -72,6 +73,14 @@ void InitializeResourceBufferConstants() {
GetNumericArg("resource-buffer-max-allocation-size", &kMaxAllocationSize);
}
+// Updates |*cached| to |updated| and returns the difference from the old
+// value.
+int TrackDifference(int64_t updated, int64_t* cached) {
+ int difference = updated - *cached;
+ *cached = updated;
+ return difference;
+}
+
} // namespace
// Used when kOptimizeLoadingIPCForSmallResources is enabled.
@@ -117,6 +126,7 @@ class AsyncResourceHandler::InliningHelper {
// Returns true if the received data is sent to the consumer.
bool SendInlinedDataIfApplicable(int bytes_read,
int encoded_data_length,
+ int encoded_body_length,
IPC::Sender* sender,
int request_id) {
DCHECK(sender);
@@ -129,7 +139,7 @@ class AsyncResourceHandler::InliningHelper {
leading_chunk_buffer_ = nullptr;
sender->Send(new ResourceMsg_InlinedDataChunkReceived(
- request_id, data, encoded_data_length));
+ request_id, data, encoded_data_length, encoded_body_length));
return true;
}
@@ -206,7 +216,8 @@ AsyncResourceHandler::AsyncResourceHandler(
inlining_helper_(new InliningHelper),
last_upload_position_(0),
waiting_for_upload_progress_ack_(false),
- reported_transfer_size_(0) {
+ reported_transfer_size_(0),
+ reported_encoded_body_length_(0) {
InitializeResourceBufferConstants();
}
@@ -440,10 +451,12 @@ bool AsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
return false;
int encoded_data_length = CalculateEncodedDataLengthToReport();
+ int encoded_body_length = CalculateEncodedBodyLengthToReport();
// Return early if InliningHelper handled the received data.
if (inlining_helper_->SendInlinedDataIfApplicable(
- bytes_read, encoded_data_length, filter, GetRequestID()))
+ bytes_read, encoded_data_length, encoded_body_length, filter,
+ GetRequestID()))
return true;
buffer_->ShrinkLastAllocation(bytes_read);
@@ -461,8 +474,9 @@ bool AsyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
int data_offset = buffer_->GetLastAllocationOffset();
- filter->Send(new ResourceMsg_DataReceived(
- GetRequestID(), data_offset, bytes_read, encoded_data_length));
+ filter->Send(new ResourceMsg_DataReceived(GetRequestID(), data_offset,
+ bytes_read, encoded_data_length,
+ encoded_body_length));
++pending_data_count_;
if (!buffer_->CanAllocate()) {
@@ -576,10 +590,13 @@ bool AsyncResourceHandler::CheckForSufficientResource() {
}
int AsyncResourceHandler::CalculateEncodedDataLengthToReport() {
- int64_t current_transfer_size = request()->GetTotalReceivedBytes();
- int encoded_data_length = current_transfer_size - reported_transfer_size_;
- reported_transfer_size_ = current_transfer_size;
- return encoded_data_length;
+ return TrackDifference(request()->GetTotalReceivedBytes(),
+ &reported_transfer_size_);
+}
+
+int AsyncResourceHandler::CalculateEncodedBodyLengthToReport() {
+ return TrackDifference(request()->GetRawBodyBytes(),
+ &reported_encoded_body_length_);
}
void AsyncResourceHandler::RecordHistogram() {

Powered by Google App Engine
This is Rietveld 408576698