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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: content/child/web_url_loader_impl.cc
diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc
index a1a5beb4b281d6f4a625d33b26f497db68b30b81..c7159ee01f2470e735191433c02a8fc5c04908ff 100644
--- a/content/child/web_url_loader_impl.cc
+++ b/content/child/web_url_loader_impl.cc
@@ -7,6 +7,7 @@
#include <algorithm>
#include <deque>
#include <string>
+#include <vector>
#include "base/bind.h"
#include "base/command_line.h"
@@ -75,6 +76,26 @@ const size_t kBodyStreamPipeCapacity = 4 * 1024;
typedef ResourceDevToolsInfo::HeadersVector HeadersVector;
+class FixedReceivedData final : public RequestPeer::ReceivedData {
+ public:
+ FixedReceivedData(const char* payload, int length, int encoded_length)
+ : data_(&payload[0], &payload[length]), encoded_length_(encoded_length) {}
+ ~FixedReceivedData() override {}
+
+ const char* payload() const override {
+ // TODO(yhirano): Use |data_.data()| when we can use c++11.
+ return data_.empty() ? nullptr : &data_[0];
+ }
+ int length() const override { return data_.size(); }
+ int encoded_length() const override { return encoded_length_; }
+
+ private:
+ const std::vector<char> data_;
+ const int encoded_length_;
+
+ DISALLOW_COPY_AND_ASSIGN(FixedReceivedData);
+};
+
// Converts timing data from |load_timing| to the format used by WebKit.
void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing,
WebURLLoadTiming* url_timing) {
@@ -313,9 +334,7 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
const ResourceResponseInfo& info) override;
void OnReceivedResponse(const ResourceResponseInfo& info) override;
void OnDownloadedData(int len, int encoded_data_length) override;
- void OnReceivedData(const char* data,
- int data_length,
- int encoded_data_length) override;
+ void OnReceivedData(scoped_ptr<ReceivedData> data) override;
void OnReceivedCachedMetadata(const char* data, int len) override;
void OnCompletedRequest(int error_code,
bool was_ignored_by_handler,
@@ -678,16 +697,17 @@ void WebURLLoaderImpl::Context::OnDownloadedData(int len,
client_->didDownloadData(loader_, len, encoded_data_length);
}
-void WebURLLoaderImpl::Context::OnReceivedData(const char* data,
- int data_length,
- int encoded_data_length) {
+void WebURLLoaderImpl::Context::OnReceivedData(scoped_ptr<ReceivedData> data) {
+ const char* payload = data->payload();
+ int data_length = data->length();
+ int encoded_data_length = data->encoded_length();
if (!client_)
return;
if (request_.useStreamOnResponse()) {
// We don't support ftp_listening_delegate_ and multipart_delegate_ for now.
// TODO(yhirano): Support ftp listening and multipart.
- MojoResult rv = WriteDataOnBodyStream(data, data_length);
+ MojoResult rv = WriteDataOnBodyStream(payload, data_length);
if (rv != MOJO_RESULT_OK && client_) {
client_->didFail(
loader_, CreateWebURLError(request_.url(), false, net::ERR_FAILED));
@@ -698,16 +718,17 @@ void WebURLLoaderImpl::Context::OnReceivedData(const char* data,
// delegate may want to do work after sending data to the delegate, keep
// |this| and the delegate alive until it's finished handling the data.
scoped_refptr<Context> protect(this);
- ftp_listing_delegate_->OnReceivedData(data, data_length);
+ ftp_listing_delegate_->OnReceivedData(payload, data_length);
} else if (multipart_delegate_) {
// The multipart delegate will make the appropriate calls to
// client_->didReceiveData and client_->didReceiveResponse. Since the
// delegate may want to do work after sending data to the delegate, keep
// |this| and the delegate alive until it's finished handling the data.
scoped_refptr<Context> protect(this);
- multipart_delegate_->OnReceivedData(data, data_length, encoded_data_length);
+ multipart_delegate_->OnReceivedData(payload, data_length,
+ encoded_data_length);
} else {
- client_->didReceiveData(loader_, data, data_length, encoded_data_length);
+ client_->didReceiveData(loader_, payload, data_length, encoded_data_length);
}
}
@@ -824,7 +845,8 @@ void WebURLLoaderImpl::Context::HandleDataURL() {
if (error_code == net::OK) {
OnReceivedResponse(info);
if (!data.empty())
- OnReceivedData(data.data(), data.size(), 0);
+ OnReceivedData(
+ make_scoped_ptr(new FixedReceivedData(data.c_str(), data.size(), 0)));
tyoshino (SeeGerritForStatus) 2015/04/27 05:20:15 why c_str?
yhirano 2015/04/27 05:29:38 Done.
}
OnCompletedRequest(error_code, false, false, info.security_info,

Powered by Google App Engine
This is Rietveld 408576698