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

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

Issue 2510333002: Send encoded_body_length to renderer when response completed (2/3) (Closed)
Patch Set: rebase Created 4 years 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
« no previous file with comments | « content/child/web_url_loader_impl.h ('k') | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, 383 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
384 const ResourceResponseInfo& info); 384 const ResourceResponseInfo& info);
385 void OnReceivedResponse(const ResourceResponseInfo& info); 385 void OnReceivedResponse(const ResourceResponseInfo& info);
386 void OnDownloadedData(int len, int encoded_data_length); 386 void OnDownloadedData(int len, int encoded_data_length);
387 void OnReceivedData(std::unique_ptr<ReceivedData> data); 387 void OnReceivedData(std::unique_ptr<ReceivedData> data);
388 void OnReceivedCachedMetadata(const char* data, int len); 388 void OnReceivedCachedMetadata(const char* data, int len);
389 void OnCompletedRequest(int error_code, 389 void OnCompletedRequest(int error_code,
390 bool was_ignored_by_handler, 390 bool was_ignored_by_handler,
391 bool stale_copy_in_cache, 391 bool stale_copy_in_cache,
392 const base::TimeTicks& completion_time, 392 const base::TimeTicks& completion_time,
393 int64_t total_transfer_size); 393 int64_t total_transfer_size,
394 int64_t encoded_body_size);
394 395
395 private: 396 private:
396 friend class base::RefCounted<Context>; 397 friend class base::RefCounted<Context>;
397 ~Context(); 398 ~Context();
398 399
399 // Called when the body data stream is detached from the reader side. 400 // Called when the body data stream is detached from the reader side.
400 void CancelBodyStreaming(); 401 void CancelBodyStreaming();
401 // We can optimize the handling of data URLs in most cases. 402 // We can optimize the handling of data URLs in most cases.
402 bool CanHandleDataURLRequestLocally() const; 403 bool CanHandleDataURLRequestLocally() const;
403 void HandleDataURL(); 404 void HandleDataURL();
(...skipping 27 matching lines...) Expand all
431 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, 432 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
432 const ResourceResponseInfo& info) override; 433 const ResourceResponseInfo& info) override;
433 void OnReceivedResponse(const ResourceResponseInfo& info) override; 434 void OnReceivedResponse(const ResourceResponseInfo& info) override;
434 void OnDownloadedData(int len, int encoded_data_length) override; 435 void OnDownloadedData(int len, int encoded_data_length) override;
435 void OnReceivedData(std::unique_ptr<ReceivedData> data) override; 436 void OnReceivedData(std::unique_ptr<ReceivedData> data) override;
436 void OnReceivedCachedMetadata(const char* data, int len) override; 437 void OnReceivedCachedMetadata(const char* data, int len) override;
437 void OnCompletedRequest(int error_code, 438 void OnCompletedRequest(int error_code,
438 bool was_ignored_by_handler, 439 bool was_ignored_by_handler,
439 bool stale_copy_in_cache, 440 bool stale_copy_in_cache,
440 const base::TimeTicks& completion_time, 441 const base::TimeTicks& completion_time,
441 int64_t total_transfer_size) override; 442 int64_t total_transfer_size,
443 int64_t encoded_body_size) override;
442 444
443 private: 445 private:
444 scoped_refptr<Context> context_; 446 scoped_refptr<Context> context_;
445 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); 447 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl);
446 }; 448 };
447 449
448 // WebURLLoaderImpl::Context -------------------------------------------------- 450 // WebURLLoaderImpl::Context --------------------------------------------------
449 451
450 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, 452 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader,
451 ResourceDispatcher* resource_dispatcher, 453 ResourceDispatcher* resource_dispatcher,
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 "loading", "WebURLLoaderImpl::Context::OnReceivedData", 808 "loading", "WebURLLoaderImpl::Context::OnReceivedData",
807 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); 809 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT);
808 810
809 if (ftp_listing_delegate_) { 811 if (ftp_listing_delegate_) {
810 // The FTP listing delegate will make the appropriate calls to 812 // The FTP listing delegate will make the appropriate calls to
811 // client_->didReceiveData and client_->didReceiveResponse. 813 // client_->didReceiveData and client_->didReceiveResponse.
812 ftp_listing_delegate_->OnReceivedData(payload, data_length); 814 ftp_listing_delegate_->OnReceivedData(payload, data_length);
813 } else { 815 } else {
814 // We dispatch the data even when |useStreamOnResponse()| is set, in order 816 // We dispatch the data even when |useStreamOnResponse()| is set, in order
815 // to make Devtools work. 817 // to make Devtools work.
816 client_->didReceiveData(loader_, payload, data_length, encoded_data_length, 818 client_->didReceiveData(loader_, payload, data_length, encoded_data_length);
817 data->encoded_body_length());
818 819
819 if (request_.useStreamOnResponse()) { 820 if (request_.useStreamOnResponse()) {
820 // We don't support ftp_listening_delegate_ for now. 821 // We don't support ftp_listening_delegate_ for now.
821 // TODO(yhirano): Support ftp listening. 822 // TODO(yhirano): Support ftp listening.
822 body_stream_writer_->AddData(std::move(data)); 823 body_stream_writer_->AddData(std::move(data));
823 } 824 }
824 } 825 }
825 } 826 }
826 827
827 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( 828 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata(
828 const char* data, int len) { 829 const char* data, int len) {
829 if (!client_) 830 if (!client_)
830 return; 831 return;
831 TRACE_EVENT_WITH_FLOW0( 832 TRACE_EVENT_WITH_FLOW0(
832 "loading", "WebURLLoaderImpl::Context::OnReceivedCachedMetadata", 833 "loading", "WebURLLoaderImpl::Context::OnReceivedCachedMetadata",
833 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT); 834 this, TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT);
834 client_->didReceiveCachedMetadata(loader_, data, len); 835 client_->didReceiveCachedMetadata(loader_, data, len);
835 } 836 }
836 837
837 void WebURLLoaderImpl::Context::OnCompletedRequest( 838 void WebURLLoaderImpl::Context::OnCompletedRequest(
838 int error_code, 839 int error_code,
839 bool was_ignored_by_handler, 840 bool was_ignored_by_handler,
840 bool stale_copy_in_cache, 841 bool stale_copy_in_cache,
841 const base::TimeTicks& completion_time, 842 const base::TimeTicks& completion_time,
842 int64_t total_transfer_size) { 843 int64_t total_transfer_size,
844 int64_t encoded_body_size) {
843 if (ftp_listing_delegate_) { 845 if (ftp_listing_delegate_) {
844 ftp_listing_delegate_->OnCompletedRequest(); 846 ftp_listing_delegate_->OnCompletedRequest();
845 ftp_listing_delegate_.reset(NULL); 847 ftp_listing_delegate_.reset(NULL);
846 } 848 }
847 849
848 if (body_stream_writer_ && error_code != net::OK) 850 if (body_stream_writer_ && error_code != net::OK)
849 body_stream_writer_->Fail(); 851 body_stream_writer_->Fail();
850 body_stream_writer_.reset(); 852 body_stream_writer_.reset();
851 853
852 if (client_) { 854 if (client_) {
853 TRACE_EVENT_WITH_FLOW0( 855 TRACE_EVENT_WITH_FLOW0(
854 "loading", "WebURLLoaderImpl::Context::OnCompletedRequest", 856 "loading", "WebURLLoaderImpl::Context::OnCompletedRequest",
855 this, TRACE_EVENT_FLAG_FLOW_IN); 857 this, TRACE_EVENT_FLAG_FLOW_IN);
856 858
857 if (error_code != net::OK) { 859 if (error_code != net::OK) {
858 client_->didFail(loader_, 860 client_->didFail(loader_,
859 CreateWebURLError(request_.url(), stale_copy_in_cache, 861 CreateWebURLError(request_.url(), stale_copy_in_cache,
860 error_code, was_ignored_by_handler), 862 error_code, was_ignored_by_handler),
861 total_transfer_size); 863 total_transfer_size, encoded_body_size);
862 } else { 864 } else {
863 client_->didFinishLoading(loader_, 865 client_->didFinishLoading(loader_,
864 (completion_time - TimeTicks()).InSecondsF(), 866 (completion_time - TimeTicks()).InSecondsF(),
865 total_transfer_size); 867 total_transfer_size, encoded_body_size);
866 } 868 }
867 } 869 }
868 } 870 }
869 871
870 WebURLLoaderImpl::Context::~Context() { 872 WebURLLoaderImpl::Context::~Context() {
871 // We must be already cancelled at this point. 873 // We must be already cancelled at this point.
872 DCHECK_LT(request_id_, 0); 874 DCHECK_LT(request_id_, 0);
873 } 875 }
874 876
875 void WebURLLoaderImpl::Context::CancelBodyStreaming() { 877 void WebURLLoaderImpl::Context::CancelBodyStreaming() {
876 scoped_refptr<Context> protect(this); 878 scoped_refptr<Context> protect(this);
877 879
878 // Notify renderer clients that the request is canceled. 880 // Notify renderer clients that the request is canceled.
879 if (ftp_listing_delegate_) { 881 if (ftp_listing_delegate_) {
880 ftp_listing_delegate_->OnCompletedRequest(); 882 ftp_listing_delegate_->OnCompletedRequest();
881 ftp_listing_delegate_.reset(NULL); 883 ftp_listing_delegate_.reset(NULL);
882 } 884 }
883 885
884 if (body_stream_writer_) { 886 if (body_stream_writer_) {
885 body_stream_writer_->Fail(); 887 body_stream_writer_->Fail();
886 body_stream_writer_.reset(); 888 body_stream_writer_.reset();
887 } 889 }
888 if (client_) { 890 if (client_) {
889 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible. 891 // TODO(yhirano): Set |stale_copy_in_cache| appropriately if possible.
890 client_->didFail(loader_, 892 client_->didFail(loader_,
891 CreateWebURLError(request_.url(), false, net::ERR_ABORTED), 893 CreateWebURLError(request_.url(), false, net::ERR_ABORTED),
892 WebURLLoaderClient::kUnknownEncodedDataLength); 894 WebURLLoaderClient::kUnknownEncodedDataLength, 0);
893 } 895 }
894 896
895 // Notify the browser process that the request is canceled. 897 // Notify the browser process that the request is canceled.
896 Cancel(); 898 Cancel();
897 } 899 }
898 900
899 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const { 901 bool WebURLLoaderImpl::Context::CanHandleDataURLRequestLocally() const {
900 GURL url = request_.url(); 902 GURL url = request_.url();
901 if (!url.SchemeIs(url::kDataScheme)) 903 if (!url.SchemeIs(url::kDataScheme))
902 return false; 904 return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 950
949 ResourceResponseInfo info; 951 ResourceResponseInfo info;
950 std::string data; 952 std::string data;
951 953
952 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); 954 int error_code = GetInfoFromDataURL(request_.url(), &info, &data);
953 955
954 if (error_code == net::OK) { 956 if (error_code == net::OK) {
955 OnReceivedResponse(info); 957 OnReceivedResponse(info);
956 auto size = data.size(); 958 auto size = data.size();
957 if (size != 0) 959 if (size != 0)
958 OnReceivedData( 960 OnReceivedData(base::MakeUnique<FixedReceivedData>(data.data(), size, 0));
959 base::MakeUnique<FixedReceivedData>(data.data(), size, 0, size));
960 } 961 }
961 962
962 OnCompletedRequest(error_code, false, false, base::TimeTicks::Now(), 0); 963 OnCompletedRequest(error_code, false, false, base::TimeTicks::Now(), 0,
964 data.size());
963 } 965 }
964 966
965 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------ 967 // WebURLLoaderImpl::RequestPeerImpl ------------------------------------------
966 968
967 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context) 969 WebURLLoaderImpl::RequestPeerImpl::RequestPeerImpl(Context* context)
968 : context_(context) {} 970 : context_(context) {}
969 971
970 void WebURLLoaderImpl::RequestPeerImpl::OnUploadProgress(uint64_t position, 972 void WebURLLoaderImpl::RequestPeerImpl::OnUploadProgress(uint64_t position,
971 uint64_t size) { 973 uint64_t size) {
972 context_->OnUploadProgress(position, size); 974 context_->OnUploadProgress(position, size);
(...skipping 25 matching lines...) Expand all
998 const char* data, 1000 const char* data,
999 int len) { 1001 int len) {
1000 context_->OnReceivedCachedMetadata(data, len); 1002 context_->OnReceivedCachedMetadata(data, len);
1001 } 1003 }
1002 1004
1003 void WebURLLoaderImpl::RequestPeerImpl::OnCompletedRequest( 1005 void WebURLLoaderImpl::RequestPeerImpl::OnCompletedRequest(
1004 int error_code, 1006 int error_code,
1005 bool was_ignored_by_handler, 1007 bool was_ignored_by_handler,
1006 bool stale_copy_in_cache, 1008 bool stale_copy_in_cache,
1007 const base::TimeTicks& completion_time, 1009 const base::TimeTicks& completion_time,
1008 int64_t total_transfer_size) { 1010 int64_t total_transfer_size,
1011 int64_t encoded_body_size) {
1009 context_->OnCompletedRequest(error_code, was_ignored_by_handler, 1012 context_->OnCompletedRequest(error_code, was_ignored_by_handler,
1010 stale_copy_in_cache, completion_time, 1013 stale_copy_in_cache, completion_time,
1011 total_transfer_size); 1014 total_transfer_size, encoded_body_size);
1012 } 1015 }
1013 1016
1014 // WebURLLoaderImpl ----------------------------------------------------------- 1017 // WebURLLoaderImpl -----------------------------------------------------------
1015 1018
1016 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, 1019 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher,
1017 mojom::URLLoaderFactory* url_loader_factory, 1020 mojom::URLLoaderFactory* url_loader_factory,
1018 mojo::AssociatedGroup* associated_group) 1021 mojo::AssociatedGroup* associated_group)
1019 : context_(new Context(this, 1022 : context_(new Context(this,
1020 resource_dispatcher, 1023 resource_dispatcher,
1021 url_loader_factory, 1024 url_loader_factory,
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 new_request.setHTTPMethod(WebString::fromUTF8(redirect_info.new_method)); 1197 new_request.setHTTPMethod(WebString::fromUTF8(redirect_info.new_method));
1195 if (redirect_info.new_method == old_method) 1198 if (redirect_info.new_method == old_method)
1196 new_request.setHTTPBody(request.httpBody()); 1199 new_request.setHTTPBody(request.httpBody());
1197 return new_request; 1200 return new_request;
1198 } 1201 }
1199 1202
1200 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request, 1203 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request,
1201 WebURLResponse& response, 1204 WebURLResponse& response,
1202 WebURLError& error, 1205 WebURLError& error,
1203 WebData& data, 1206 WebData& data,
1204 int64_t& encoded_data_length) { 1207 int64_t& encoded_data_length,
1208 int64_t& encoded_body_length) {
1205 TRACE_EVENT0("loading", "WebURLLoaderImpl::loadSynchronously"); 1209 TRACE_EVENT0("loading", "WebURLLoaderImpl::loadSynchronously");
1206 SyncLoadResponse sync_load_response; 1210 SyncLoadResponse sync_load_response;
1207 context_->Start(request, &sync_load_response); 1211 context_->Start(request, &sync_load_response);
1208 1212
1209 const GURL& final_url = sync_load_response.url; 1213 const GURL& final_url = sync_load_response.url;
1210 1214
1211 // TODO(tc): For file loads, we may want to include a more descriptive 1215 // TODO(tc): For file loads, we may want to include a more descriptive
1212 // status code or status text. 1216 // status code or status text.
1213 int error_code = sync_load_response.error_code; 1217 int error_code = sync_load_response.error_code;
1214 if (error_code != net::OK) { 1218 if (error_code != net::OK) {
1215 response.setURL(final_url); 1219 response.setURL(final_url);
1216 error.domain = WebString::fromUTF8(net::kErrorDomain); 1220 error.domain = WebString::fromUTF8(net::kErrorDomain);
1217 error.reason = error_code; 1221 error.reason = error_code;
1218 error.unreachableURL = final_url; 1222 error.unreachableURL = final_url;
1219 return; 1223 return;
1220 } 1224 }
1221 1225
1222 PopulateURLResponse(final_url, sync_load_response, &response, 1226 PopulateURLResponse(final_url, sync_load_response, &response,
1223 request.reportRawHeaders()); 1227 request.reportRawHeaders());
1224 response.addToEncodedBodyLength(sync_load_response.encoded_body_length);
1225 response.addToDecodedBodyLength(sync_load_response.data.size()); 1228 response.addToDecodedBodyLength(sync_load_response.data.size());
1226 encoded_data_length = sync_load_response.encoded_data_length; 1229 encoded_data_length = sync_load_response.encoded_data_length;
1230 encoded_body_length = sync_load_response.encoded_body_length;
1227 1231
1228 data.assign(sync_load_response.data.data(), sync_load_response.data.size()); 1232 data.assign(sync_load_response.data.data(), sync_load_response.data.size());
1229 } 1233 }
1230 1234
1231 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request, 1235 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request,
1232 WebURLLoaderClient* client) { 1236 WebURLLoaderClient* client) {
1233 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::loadAsynchronously", 1237 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::loadAsynchronously",
1234 this, TRACE_EVENT_FLAG_FLOW_OUT); 1238 this, TRACE_EVENT_FLAG_FLOW_OUT);
1235 DCHECK(!context_->client()); 1239 DCHECK(!context_->client());
1236 1240
(...skipping 13 matching lines...) Expand all
1250 int intra_priority_value) { 1254 int intra_priority_value) {
1251 context_->DidChangePriority(new_priority, intra_priority_value); 1255 context_->DidChangePriority(new_priority, intra_priority_value);
1252 } 1256 }
1253 1257
1254 void WebURLLoaderImpl::setLoadingTaskRunner( 1258 void WebURLLoaderImpl::setLoadingTaskRunner(
1255 base::SingleThreadTaskRunner* loading_task_runner) { 1259 base::SingleThreadTaskRunner* loading_task_runner) {
1256 context_->SetTaskRunner(loading_task_runner); 1260 context_->SetTaskRunner(loading_task_runner);
1257 } 1261 }
1258 1262
1259 } // namespace content 1263 } // namespace content
OLDNEW
« no previous file with comments | « content/child/web_url_loader_impl.h ('k') | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698