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

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 2835123005: Send the decoded size when response completed and stop summing in ResourceLoader::DidReceiveData() (Closed)
Patch Set: Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/child/web_url_loader_impl.h" 5 #include "content/child/web_url_loader_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 void OnReceivedResponse(const ResourceResponseInfo& info); 379 void OnReceivedResponse(const ResourceResponseInfo& info);
380 void OnDownloadedData(int len, int encoded_data_length); 380 void OnDownloadedData(int len, int encoded_data_length);
381 void OnReceivedData(std::unique_ptr<ReceivedData> data); 381 void OnReceivedData(std::unique_ptr<ReceivedData> data);
382 void OnTransferSizeUpdated(int transfer_size_diff); 382 void OnTransferSizeUpdated(int transfer_size_diff);
383 void OnReceivedCachedMetadata(const char* data, int len); 383 void OnReceivedCachedMetadata(const char* data, int len);
384 void OnCompletedRequest(int error_code, 384 void OnCompletedRequest(int error_code,
385 bool was_ignored_by_handler, 385 bool was_ignored_by_handler,
386 bool stale_copy_in_cache, 386 bool stale_copy_in_cache,
387 const base::TimeTicks& completion_time, 387 const base::TimeTicks& completion_time,
388 int64_t total_transfer_size, 388 int64_t total_transfer_size,
389 int64_t encoded_body_size); 389 int64_t encoded_body_size,
390 int64_t decoded_body_size);
390 391
391 private: 392 private:
392 friend class base::RefCounted<Context>; 393 friend class base::RefCounted<Context>;
393 ~Context(); 394 ~Context();
394 395
395 // Called when the body data stream is detached from the reader side. 396 // Called when the body data stream is detached from the reader side.
396 void CancelBodyStreaming(); 397 void CancelBodyStreaming();
397 // We can optimize the handling of data URLs in most cases. 398 // We can optimize the handling of data URLs in most cases.
398 bool CanHandleDataURLRequestLocally() const; 399 bool CanHandleDataURLRequestLocally() const;
399 void HandleDataURL(); 400 void HandleDataURL();
(...skipping 28 matching lines...) Expand all
428 void OnReceivedResponse(const ResourceResponseInfo& info) override; 429 void OnReceivedResponse(const ResourceResponseInfo& info) override;
429 void OnDownloadedData(int len, int encoded_data_length) override; 430 void OnDownloadedData(int len, int encoded_data_length) override;
430 void OnReceivedData(std::unique_ptr<ReceivedData> data) override; 431 void OnReceivedData(std::unique_ptr<ReceivedData> data) override;
431 void OnTransferSizeUpdated(int transfer_size_diff) override; 432 void OnTransferSizeUpdated(int transfer_size_diff) override;
432 void OnReceivedCachedMetadata(const char* data, int len) override; 433 void OnReceivedCachedMetadata(const char* data, int len) override;
433 void OnCompletedRequest(int error_code, 434 void OnCompletedRequest(int error_code,
434 bool was_ignored_by_handler, 435 bool was_ignored_by_handler,
435 bool stale_copy_in_cache, 436 bool stale_copy_in_cache,
436 const base::TimeTicks& completion_time, 437 const base::TimeTicks& completion_time,
437 int64_t total_transfer_size, 438 int64_t total_transfer_size,
438 int64_t encoded_body_size) override; 439 int64_t encoded_body_size,
440 int64_t decoded_body_size) override;
439 441
440 private: 442 private:
441 scoped_refptr<Context> context_; 443 scoped_refptr<Context> context_;
442 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); 444 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl);
443 }; 445 };
444 446
445 // WebURLLoaderImpl::Context -------------------------------------------------- 447 // WebURLLoaderImpl::Context --------------------------------------------------
446 448
447 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, 449 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader,
448 ResourceDispatcher* resource_dispatcher, 450 ResourceDispatcher* resource_dispatcher,
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); 859 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT);
858 client_->DidReceiveCachedMetadata(data, len); 860 client_->DidReceiveCachedMetadata(data, len);
859 } 861 }
860 862
861 void WebURLLoaderImpl::Context::OnCompletedRequest( 863 void WebURLLoaderImpl::Context::OnCompletedRequest(
862 int error_code, 864 int error_code,
863 bool was_ignored_by_handler, 865 bool was_ignored_by_handler,
864 bool stale_copy_in_cache, 866 bool stale_copy_in_cache,
865 const base::TimeTicks& completion_time, 867 const base::TimeTicks& completion_time,
866 int64_t total_transfer_size, 868 int64_t total_transfer_size,
867 int64_t encoded_body_size) { 869 int64_t encoded_body_size,
870 int64_t decoded_body_size) {
868 if (stream_override_ && stream_override_->stream_url.is_empty()) { 871 if (stream_override_ && stream_override_->stream_url.is_empty()) {
869 // TODO(kinuko|scottmg|jam): This is wrong. https://crbug.com/705744. 872 // TODO(kinuko|scottmg|jam): This is wrong. https://crbug.com/705744.
870 total_transfer_size = stream_override_->total_transferred; 873 total_transfer_size = stream_override_->total_transferred;
871 encoded_body_size = stream_override_->total_transferred; 874 encoded_body_size = stream_override_->total_transferred;
872 } 875 }
873 876
874 if (ftp_listing_delegate_) { 877 if (ftp_listing_delegate_) {
875 ftp_listing_delegate_->OnCompletedRequest(); 878 ftp_listing_delegate_->OnCompletedRequest();
876 ftp_listing_delegate_.reset(NULL); 879 ftp_listing_delegate_.reset(NULL);
877 } 880 }
878 881
879 if (body_stream_writer_ && error_code != net::OK) 882 if (body_stream_writer_ && error_code != net::OK)
880 body_stream_writer_->Fail(); 883 body_stream_writer_->Fail();
881 body_stream_writer_.reset(); 884 body_stream_writer_.reset();
882 885
883 if (client_) { 886 if (client_) {
884 TRACE_EVENT_WITH_FLOW0( 887 TRACE_EVENT_WITH_FLOW0(
885 "loading", "WebURLLoaderImpl::Context::OnCompletedRequest", 888 "loading", "WebURLLoaderImpl::Context::OnCompletedRequest",
886 this, TRACE_EVENT_FLAG_FLOW_IN); 889 this, TRACE_EVENT_FLAG_FLOW_IN);
887 890
888 if (error_code != net::OK) { 891 if (error_code != net::OK) {
889 client_->DidFail(CreateWebURLError(request_.Url(), stale_copy_in_cache, 892 client_->DidFail(CreateWebURLError(request_.Url(), stale_copy_in_cache,
890 error_code, was_ignored_by_handler), 893 error_code, was_ignored_by_handler),
891 total_transfer_size, encoded_body_size); 894 total_transfer_size, encoded_body_size,
895 decoded_body_size);
892 } else { 896 } else {
893 // PlzNavigate: compute the accurate transfer size for navigations. 897 // PlzNavigate: compute the accurate transfer size for navigations.
894 if (stream_override_) { 898 if (stream_override_) {
895 DCHECK(IsBrowserSideNavigationEnabled()); 899 DCHECK(IsBrowserSideNavigationEnabled());
896 total_transfer_size += stream_override_->total_transfer_size_delta; 900 total_transfer_size += stream_override_->total_transfer_size_delta;
897 } 901 }
898 902
899 client_->DidFinishLoading((completion_time - TimeTicks()).InSecondsF(), 903 client_->DidFinishLoading((completion_time - TimeTicks()).InSecondsF(),
900 total_transfer_size, encoded_body_size); 904 total_transfer_size, encoded_body_size,
905 decoded_body_size);
901 } 906 }
902 } 907 }
903 } 908 }
904 909
905 WebURLLoaderImpl::Context::~Context() { 910 WebURLLoaderImpl::Context::~Context() {
906 // We must be already cancelled at this point. 911 // We must be already cancelled at this point.
907 DCHECK_LT(request_id_, 0); 912 DCHECK_LT(request_id_, 0);
908 } 913 }
909 914
910 void WebURLLoaderImpl::Context::CancelBodyStreaming() { 915 void WebURLLoaderImpl::Context::CancelBodyStreaming() {
911 scoped_refptr<Context> protect(this); 916 scoped_refptr<Context> protect(this);
912 917
913 // Notify renderer clients that the request is canceled. 918 // Notify renderer clients that the request is canceled.
914 if (ftp_listing_delegate_) { 919 if (ftp_listing_delegate_) {
915 ftp_listing_delegate_->OnCompletedRequest(); 920 ftp_listing_delegate_->OnCompletedRequest();
916 ftp_listing_delegate_.reset(NULL); 921 ftp_listing_delegate_.reset(NULL);
917 } 922 }
918 923
919 if (body_stream_writer_) { 924 if (body_stream_writer_) {
920 body_stream_writer_->Fail(); 925 body_stream_writer_->Fail();
921 body_stream_writer_.reset(); 926 body_stream_writer_.reset();
922 } 927 }
923 if (client_) { 928 if (client_) {
924 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible. 929 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible.
925 client_->DidFail(CreateWebURLError(request_.Url(), false, net::ERR_ABORTED), 930 client_->DidFail(CreateWebURLError(request_.Url(), false, net::ERR_ABORTED),
926 WebURLLoaderClient::kUnknownEncodedDataLength, 0); 931 WebURLLoaderClient::kUnknownEncodedDataLength, 0, 0);
927 } 932 }
928 933
929 // Notify the browser process that the request is canceled. 934 // Notify the browser process that the request is canceled.
930 Cancel(); 935 Cancel();
931 } 936 }
932 937
933 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const { 938 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const {
934 if (!request_.Url().ProtocolIs(url::kDataScheme)) 939 if (!request_.Url().ProtocolIs(url::kDataScheme))
935 return false; 940 return false;
936 941
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 int error_code = GetInfoFromDataURL(request_.Url(), &info, &data); 993 int error_code = GetInfoFromDataURL(request_.Url(), &info, &data);
989 994
990 if (error_code == net::OK) { 995 if (error_code == net::OK) {
991 OnReceivedResponse(info); 996 OnReceivedResponse(info);
992 auto size = data.size(); 997 auto size = data.size();
993 if (size != 0) 998 if (size != 0)
994 OnReceivedData(base::MakeUnique<FixedReceivedData>(data.data(), size)); 999 OnReceivedData(base::MakeUnique<FixedReceivedData>(data.data(), size));
995 } 1000 }
996 1001
997 OnCompletedRequest(error_code, false, false, base::TimeTicks::Now(), 0, 1002 OnCompletedRequest(error_code, false, false, base::TimeTicks::Now(), 0,
998 data.size()); 1003 data.size(), data.size());
999 } 1004 }
1000 1005
1001 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------ 1006 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------
1002 1007
1003 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context) 1008 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context)
1004 : context_(context) {} 1009 : context_(context) {}
1005 1010
1006 void WebURLLoaderImpl::RequestPeerImpl::OnUploadProgress(uint64_t position, 1011 void WebURLLoaderImpl::RequestPeerImpl::OnUploadProgress(uint64_t position,
1007 uint64_t size) { 1012 uint64_t size) {
1008 context_->OnUploadProgress(position, size); 1013 context_->OnUploadProgress(position, size);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 int len) { 1045 int len) {
1041 context_->OnReceivedCachedMetadata(data, len); 1046 context_->OnReceivedCachedMetadata(data, len);
1042 } 1047 }
1043 1048
1044 void WebURLLoaderImpl::RequestPeerImpl::OnCompletedRequest( 1049 void WebURLLoaderImpl::RequestPeerImpl::OnCompletedRequest(
1045 int error_code, 1050 int error_code,
1046 bool was_ignored_by_handler, 1051 bool was_ignored_by_handler,
1047 bool stale_copy_in_cache, 1052 bool stale_copy_in_cache,
1048 const base::TimeTicks& completion_time, 1053 const base::TimeTicks& completion_time,
1049 int64_t total_transfer_size, 1054 int64_t total_transfer_size,
1050 int64_t encoded_body_size) { 1055 int64_t encoded_body_size,
1051 context_->OnCompletedRequest(error_code, was_ignored_by_handler, 1056 int64_t decoded_body_size) {
1052 stale_copy_in_cache, completion_time, 1057 context_->OnCompletedRequest(
1053 total_transfer_size, encoded_body_size); 1058 error_code, was_ignored_by_handler, stale_copy_in_cache, completion_time,
1059 total_transfer_size, encoded_body_size, decoded_body_size);
1054 } 1060 }
1055 1061
1056 // WebURLLoaderImpl ----------------------------------------------------------- 1062 // WebURLLoaderImpl -----------------------------------------------------------
1057 1063
1058 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, 1064 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher,
1059 mojom::URLLoaderFactory* url_loader_factory) 1065 mojom::URLLoaderFactory* url_loader_factory)
1060 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {} 1066 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {}
1061 1067
1062 WebURLLoaderImpl::~WebURLLoaderImpl() { 1068 WebURLLoaderImpl::~WebURLLoaderImpl() {
1063 Cancel(); 1069 Cancel();
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 if (error_code != net::OK) { 1248 if (error_code != net::OK) {
1243 response.SetURL(final_url); 1249 response.SetURL(final_url);
1244 error.domain = WebString::FromASCII(net::kErrorDomain); 1250 error.domain = WebString::FromASCII(net::kErrorDomain);
1245 error.reason = error_code; 1251 error.reason = error_code;
1246 error.unreachable_url = final_url; 1252 error.unreachable_url = final_url;
1247 return; 1253 return;
1248 } 1254 }
1249 1255
1250 PopulateURLResponse(final_url, sync_load_response, &response, 1256 PopulateURLResponse(final_url, sync_load_response, &response,
1251 request.ReportRawHeaders()); 1257 request.ReportRawHeaders());
1252 response.AddToDecodedBodyLength(sync_load_response.data.size());
1253 encoded_data_length = sync_load_response.encoded_data_length; 1258 encoded_data_length = sync_load_response.encoded_data_length;
1254 encoded_body_length = sync_load_response.encoded_body_length; 1259 encoded_body_length = sync_load_response.encoded_body_length;
1255 1260
1256 data.Assign(sync_load_response.data.data(), sync_load_response.data.size()); 1261 data.Assign(sync_load_response.data.data(), sync_load_response.data.size());
1257 } 1262 }
1258 1263
1259 void WebURLLoaderImpl::LoadAsynchronously(const WebURLRequest& request, 1264 void WebURLLoaderImpl::LoadAsynchronously(const WebURLRequest& request,
1260 WebURLLoaderClient* client) { 1265 WebURLLoaderClient* client) {
1261 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::loadAsynchronously", 1266 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::loadAsynchronously",
1262 this, TRACE_EVENT_FLAG_FLOW_OUT); 1267 this, TRACE_EVENT_FLAG_FLOW_OUT);
(...skipping 15 matching lines...) Expand all
1278 int intra_priority_value) { 1283 int intra_priority_value) {
1279 context_->DidChangePriority(new_priority, intra_priority_value); 1284 context_->DidChangePriority(new_priority, intra_priority_value);
1280 } 1285 }
1281 1286
1282 void WebURLLoaderImpl::SetLoadingTaskRunner( 1287 void WebURLLoaderImpl::SetLoadingTaskRunner(
1283 base::SingleThreadTaskRunner* loading_task_runner) { 1288 base::SingleThreadTaskRunner* loading_task_runner) {
1284 context_->SetTaskRunner(loading_task_runner); 1289 context_->SetTaskRunner(loading_task_runner);
1285 } 1290 }
1286 1291
1287 } // namespace content 1292 } // namespace content
OLDNEW
« no previous file with comments | « content/child/url_response_body_consumer_unittest.cc ('k') | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698