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

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

Issue 1103813002: Make WebURLLoader capable of retaining received buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 <algorithm> 7 #include <algorithm>
8 #include <deque> 8 #include <deque>
9 #include <string> 9 #include <string>
10 #include <vector>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "components/mime_util/mime_util.h" 19 #include "components/mime_util/mime_util.h"
19 #include "content/child/child_thread_impl.h" 20 #include "content/child/child_thread_impl.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 namespace content { 69 namespace content {
69 70
70 // Utilities ------------------------------------------------------------------ 71 // Utilities ------------------------------------------------------------------
71 72
72 namespace { 73 namespace {
73 74
74 const size_t kBodyStreamPipeCapacity = 4 * 1024; 75 const size_t kBodyStreamPipeCapacity = 4 * 1024;
75 76
76 typedef ResourceDevToolsInfo::HeadersVector HeadersVector; 77 typedef ResourceDevToolsInfo::HeadersVector HeadersVector;
77 78
79 class FixedReceivedData final : public RequestPeer::ReceivedData {
80 public:
81 FixedReceivedData(const char* payload, int length, int encoded_length)
82 : data_(&payload[0], &payload[length]), encoded_length_(encoded_length) {}
83 ~FixedReceivedData() override {}
84
85 const char* payload() const override {
86 // TODO(yhirano): Use |data_.data()| when we can use c++11.
87 return data_.empty() ? nullptr : &data_[0];
88 }
89 int length() const override { return data_.size(); }
90 int encoded_length() const override { return encoded_length_; }
91
92 private:
93 const std::vector<char> data_;
94 const int encoded_length_;
95
96 DISALLOW_COPY_AND_ASSIGN(FixedReceivedData);
97 };
98
78 // Converts timing data from |load_timing| to the format used by WebKit. 99 // Converts timing data from |load_timing| to the format used by WebKit.
79 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, 100 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing,
80 WebURLLoadTiming* url_timing) { 101 WebURLLoadTiming* url_timing) {
81 DCHECK(!load_timing.request_start.is_null()); 102 DCHECK(!load_timing.request_start.is_null());
82 103
83 const TimeTicks kNullTicks; 104 const TimeTicks kNullTicks;
84 url_timing->initialize(); 105 url_timing->initialize();
85 url_timing->setRequestTime( 106 url_timing->setRequestTime(
86 (load_timing.request_start - kNullTicks).InSecondsF()); 107 (load_timing.request_start - kNullTicks).InSecondsF());
87 url_timing->setProxyStart( 108 url_timing->setProxyStart(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 blink::WebThreadedDataReceiver* threaded_data_receiver); 327 blink::WebThreadedDataReceiver* threaded_data_receiver);
307 void Start(const WebURLRequest& request, 328 void Start(const WebURLRequest& request,
308 SyncLoadResponse* sync_load_response); 329 SyncLoadResponse* sync_load_response);
309 330
310 // RequestPeer methods: 331 // RequestPeer methods:
311 void OnUploadProgress(uint64 position, uint64 size) override; 332 void OnUploadProgress(uint64 position, uint64 size) override;
312 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, 333 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
313 const ResourceResponseInfo& info) override; 334 const ResourceResponseInfo& info) override;
314 void OnReceivedResponse(const ResourceResponseInfo& info) override; 335 void OnReceivedResponse(const ResourceResponseInfo& info) override;
315 void OnDownloadedData(int len, int encoded_data_length) override; 336 void OnDownloadedData(int len, int encoded_data_length) override;
316 void OnReceivedData(const char* data, 337 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
317 int data_length,
318 int encoded_data_length) override;
319 void OnReceivedCachedMetadata(const char* data, int len) override; 338 void OnReceivedCachedMetadata(const char* data, int len) override;
320 void OnCompletedRequest(int error_code, 339 void OnCompletedRequest(int error_code,
321 bool was_ignored_by_handler, 340 bool was_ignored_by_handler,
322 bool stale_copy_in_cache, 341 bool stale_copy_in_cache,
323 const std::string& security_info, 342 const std::string& security_info,
324 const base::TimeTicks& completion_time, 343 const base::TimeTicks& completion_time,
325 int64 total_transfer_size) override; 344 int64 total_transfer_size) override;
326 345
327 private: 346 private:
328 friend class base::RefCounted<Context>; 347 friend class base::RefCounted<Context>;
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 new FtpDirectoryListingResponseDelegate(client_, loader_, response)); 690 new FtpDirectoryListingResponseDelegate(client_, loader_, response));
672 } 691 }
673 } 692 }
674 693
675 void WebURLLoaderImpl::Context::OnDownloadedData(int len, 694 void WebURLLoaderImpl::Context::OnDownloadedData(int len,
676 int encoded_data_length) { 695 int encoded_data_length) {
677 if (client_) 696 if (client_)
678 client_->didDownloadData(loader_, len, encoded_data_length); 697 client_->didDownloadData(loader_, len, encoded_data_length);
679 } 698 }
680 699
681 void WebURLLoaderImpl::Context::OnReceivedData(const char* data, 700 void WebURLLoaderImpl::Context::OnReceivedData(scoped_ptr<ReceivedData> data) {
682 int data_length, 701 const char* payload = data->payload();
683 int encoded_data_length) { 702 int data_length = data->length();
703 int encoded_data_length = data->encoded_length();
684 if (!client_) 704 if (!client_)
685 return; 705 return;
686 706
687 if (request_.useStreamOnResponse()) { 707 if (request_.useStreamOnResponse()) {
688 // We don't support ftp_listening_delegate_ and multipart_delegate_ for now. 708 // We don't support ftp_listening_delegate_ and multipart_delegate_ for now.
689 // TODO(yhirano): Support ftp listening and multipart. 709 // TODO(yhirano): Support ftp listening and multipart.
690 MojoResult rv = WriteDataOnBodyStream(data, data_length); 710 MojoResult rv = WriteDataOnBodyStream(payload, data_length);
691 if (rv != MOJO_RESULT_OK && client_) { 711 if (rv != MOJO_RESULT_OK && client_) {
692 client_->didFail( 712 client_->didFail(
693 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED)); 713 loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED));
694 } 714 }
695 } else if (ftp_listing_delegate_) { 715 } else if (ftp_listing_delegate_) {
696 // The FTP listing delegate will make the appropriate calls to 716 // The FTP listing delegate will make the appropriate calls to
697 // client_->didReceiveData and client_->didReceiveResponse. Since the 717 // client_->didReceiveData and client_->didReceiveResponse. Since the
698 // delegate may want to do work after sending data to the delegate, keep 718 // delegate may want to do work after sending data to the delegate, keep
699 // |this| and the delegate alive until it's finished handling the data. 719 // |this| and the delegate alive until it's finished handling the data.
700 scoped_refptr<Context> protect(this); 720 scoped_refptr<Context> protect(this);
701 ftp_listing_delegate_->OnReceivedData(data, data_length); 721 ftp_listing_delegate_->OnReceivedData(payload, data_length);
702 } else if (multipart_delegate_) { 722 } else if (multipart_delegate_) {
703 // The multipart delegate will make the appropriate calls to 723 // The multipart delegate will make the appropriate calls to
704 // client_->didReceiveData and client_->didReceiveResponse. Since the 724 // client_->didReceiveData and client_->didReceiveResponse. Since the
705 // delegate may want to do work after sending data to the delegate, keep 725 // delegate may want to do work after sending data to the delegate, keep
706 // |this| and the delegate alive until it's finished handling the data. 726 // |this| and the delegate alive until it's finished handling the data.
707 scoped_refptr<Context> protect(this); 727 scoped_refptr<Context> protect(this);
708 multipart_delegate_->OnReceivedData(data, data_length, encoded_data_length); 728 multipart_delegate_->OnReceivedData(payload, data_length,
729 encoded_data_length);
709 } else { 730 } else {
710 client_->didReceiveData(loader_, data, data_length, encoded_data_length); 731 client_->didReceiveData(loader_, payload, data_length, encoded_data_length);
711 } 732 }
712 } 733 }
713 734
714 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata( 735 void WebURLLoaderImpl::Context::OnReceivedCachedMetadata(
715 const char* data, int len) { 736 const char* data, int len) {
716 if (client_) 737 if (client_)
717 client_->didReceiveCachedMetadata(loader_, data, len); 738 client_->didReceiveCachedMetadata(loader_, data, len);
718 } 739 }
719 740
720 void WebURLLoaderImpl::Context::OnCompletedRequest( 741 void WebURLLoaderImpl::Context::OnCompletedRequest(
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 } 838 }
818 839
819 ResourceResponseInfo info; 840 ResourceResponseInfo info;
820 std::string data; 841 std::string data;
821 842
822 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); 843 int error_code = GetInfoFromDataURL(request_.url(), &info, &data);
823 844
824 if (error_code == net::OK) { 845 if (error_code == net::OK) {
825 OnReceivedResponse(info); 846 OnReceivedResponse(info);
826 if (!data.empty()) 847 if (!data.empty())
827 OnReceivedData(data.data(), data.size(), 0); 848 OnReceivedData(
849 make_scoped_ptr(new FixedReceivedData(data.data(), data.size(), 0)));
828 } 850 }
829 851
830 OnCompletedRequest(error_code, false, false, info.security_info, 852 OnCompletedRequest(error_code, false, false, info.security_info,
831 base::TimeTicks::Now(), 0); 853 base::TimeTicks::Now(), 0);
832 } 854 }
833 855
834 MojoResult WebURLLoaderImpl::Context::WriteDataOnBodyStream(const char* data, 856 MojoResult WebURLLoaderImpl::Context::WriteDataOnBodyStream(const char* data,
835 size_t size) { 857 size_t size) {
836 if (body_stream_buffer_.empty() && size == 0) { 858 if (body_stream_buffer_.empty() && size == 0) {
837 // Nothing to do. 859 // Nothing to do.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 int intra_priority_value) { 1139 int intra_priority_value) {
1118 context_->DidChangePriority(new_priority, intra_priority_value); 1140 context_->DidChangePriority(new_priority, intra_priority_value);
1119 } 1141 }
1120 1142
1121 bool WebURLLoaderImpl::attachThreadedDataReceiver( 1143 bool WebURLLoaderImpl::attachThreadedDataReceiver(
1122 blink::WebThreadedDataReceiver* threaded_data_receiver) { 1144 blink::WebThreadedDataReceiver* threaded_data_receiver) {
1123 return context_->AttachThreadedDataReceiver(threaded_data_receiver); 1145 return context_->AttachThreadedDataReceiver(threaded_data_receiver);
1124 } 1146 }
1125 1147
1126 } // namespace content 1148 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698