Send the decoded size when response completed and stop summing in ResourceLoader::DidReceiveData()
When the size properties of PerformanceResourceTiming were introduced by
https://crrev.com/2105713002, both encodedBodySize and decodedBodySize were
summed up in ResourceLoader::DidReceiveData().
The CL https://crrev.com/2510333002 changed this to send encodedBodySize when
response completed. And currently only decodedBodySize is summed up in
ResourceLoader::DidReceiveData().
We are planning to directly pass the mojo data pipe to FetchResponseData when
fetch() API is used. If we do so, ResourceLoader::DidReceiveData() will not be
called. And it will not be guaranteed that the renderer process read the all
data before the RequestComplete IPC. This will be a problem because the size
properties are passed to the ResourceTimingInfo structure when the renderer
receives the RequestComplete IPC message.
So this cl change it to send the decodedBodySize when response completed same as
encodedBodySize.
And this is also useful to support the resource timing info for service worker
navigation preload response where we don't use ResourceLoader.
BUG=712809
Review-Url: https://codereview.chromium.org/2835123005
Cr-Commit-Position: refs/heads/master@{#467744}
diff --git a/content/browser/loader/async_resource_handler.cc b/content/browser/loader/async_resource_handler.cc
index 07d4aaa..a9b2e0e 100644
--- a/content/browser/loader/async_resource_handler.cc
+++ b/content/browser/loader/async_resource_handler.cc
@@ -381,6 +381,7 @@
request_complete_data.encoded_data_length =
request()->GetTotalReceivedBytes();
request_complete_data.encoded_body_length = request()->GetRawBodyBytes();
+ request_complete_data.decoded_body_length = total_read_body_bytes_;
filter->Send(
new ResourceMsg_RequestComplete(GetRequestID(), request_complete_data));
diff --git a/content/browser/loader/mojo_async_resource_handler.cc b/content/browser/loader/mojo_async_resource_handler.cc
index 24735cc..938915e 100644
--- a/content/browser/loader/mojo_async_resource_handler.cc
+++ b/content/browser/loader/mojo_async_resource_handler.cc
@@ -400,8 +400,10 @@
MojoResult MojoAsyncResourceHandler::EndWrite(uint32_t written) {
MojoResult result = mojo::EndWriteDataRaw(shared_writer_->writer(), written);
- if (result == MOJO_RESULT_OK)
+ if (result == MOJO_RESULT_OK) {
+ total_written_bytes_ += written;
handle_watcher_.ArmOrNotify();
+ }
return result;
}
@@ -452,6 +454,7 @@
request_complete_data.encoded_data_length =
request()->GetTotalReceivedBytes();
request_complete_data.encoded_body_length = request()->GetRawBodyBytes();
+ request_complete_data.decoded_body_length = total_written_bytes_;
url_loader_client_->OnComplete(request_complete_data);
controller->Resume();
diff --git a/content/browser/loader/mojo_async_resource_handler.h b/content/browser/loader/mojo_async_resource_handler.h
index 57198253..bbe3370 100644
--- a/content/browser/loader/mojo_async_resource_handler.h
+++ b/content/browser/loader/mojo_async_resource_handler.h
@@ -139,6 +139,7 @@
bool did_defer_on_redirect_ = false;
base::TimeTicks response_started_ticks_;
int64_t reported_total_received_bytes_ = 0;
+ int64_t total_written_bytes_ = 0;
// Pointer to parent's information about the read buffer. Only non-null while
// OnWillRead is deferred.