Commit a364dd1e authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download service: Adds the fetch_error_body flag in request params.


This CL exposes the content layer's fetch_error_body flag in download
service.

Bug: 765778
Change-Id: I2f9ea5b437387e6e1864fb1867436869b6348472
Reviewed-on: https://chromium-review.googlesource.com/707780Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510173}
parent 17376274
...@@ -166,6 +166,8 @@ void DownloadDriverImpl::Start( ...@@ -166,6 +166,8 @@ void DownloadDriverImpl::Start(
download_url_params->set_transient(true); download_url_params->set_transient(true);
download_url_params->set_method(request_params.method); download_url_params->set_method(request_params.method);
download_url_params->set_file_path(file_path); download_url_params->set_file_path(file_path);
if (request_params.fetch_error_body)
download_url_params->set_fetch_error_body(true);
download_manager_->DownloadUrl(std::move(download_url_params)); download_manager_->DownloadUrl(std::move(download_url_params));
} }
......
...@@ -18,4 +18,5 @@ message RequestParams { ...@@ -18,4 +18,5 @@ message RequestParams {
optional string url = 1; optional string url = 1;
optional string method = 2; optional string method = 2;
repeated RequestHeader headers = 3; repeated RequestHeader headers = 3;
optional bool fetch_error_body = 4;
} }
...@@ -232,6 +232,7 @@ RequestParams ProtoConversions::RequestParamsFromProto( ...@@ -232,6 +232,7 @@ RequestParams ProtoConversions::RequestParamsFromProto(
RequestParams request_params; RequestParams request_params;
request_params.url = GURL(proto.url()); request_params.url = GURL(proto.url());
request_params.method = proto.method(); request_params.method = proto.method();
request_params.fetch_error_body = proto.fetch_error_body();
for (int i = 0; i < proto.headers_size(); i++) { for (int i = 0; i < proto.headers_size(); i++) {
protodb::RequestHeader header = proto.headers(i); protodb::RequestHeader header = proto.headers(i);
...@@ -245,6 +246,7 @@ void ProtoConversions::RequestParamsToProto(const RequestParams& request_params, ...@@ -245,6 +246,7 @@ void ProtoConversions::RequestParamsToProto(const RequestParams& request_params,
protodb::RequestParams* proto) { protodb::RequestParams* proto) {
proto->set_url(request_params.url.spec()); proto->set_url(request_params.url.spec());
proto->set_method(request_params.method); proto->set_method(request_params.method);
proto->set_fetch_error_body(request_params.fetch_error_body);
int i = 0; int i = 0;
net::HttpRequestHeaders::Iterator iter(request_params.request_headers); net::HttpRequestHeaders::Iterator iter(request_params.request_headers);
......
...@@ -96,6 +96,7 @@ TEST_F(ProtoConversionsTest, RequestParamsWithHeadersConversion) { ...@@ -96,6 +96,7 @@ TEST_F(ProtoConversionsTest, RequestParamsWithHeadersConversion) {
RequestParams expected; RequestParams expected;
expected.url = GURL(TEST_URL); expected.url = GURL(TEST_URL);
expected.method = "GET"; expected.method = "GET";
expected.fetch_error_body = true;
expected.request_headers.SetHeader("key1", "value1"); expected.request_headers.SetHeader("key1", "value1");
expected.request_headers.SetHeader("key2", "value2"); expected.request_headers.SetHeader("key2", "value2");
...@@ -105,6 +106,7 @@ TEST_F(ProtoConversionsTest, RequestParamsWithHeadersConversion) { ...@@ -105,6 +106,7 @@ TEST_F(ProtoConversionsTest, RequestParamsWithHeadersConversion) {
EXPECT_EQ(expected.url, actual.url); EXPECT_EQ(expected.url, actual.url);
EXPECT_EQ(expected.method, actual.method); EXPECT_EQ(expected.method, actual.method);
EXPECT_EQ(expected.fetch_error_body, actual.fetch_error_body);
std::string out; std::string out;
actual.request_headers.GetHeader("key1", &out); actual.request_headers.GetHeader("key1", &out);
......
...@@ -20,7 +20,9 @@ bool SchedulingParams::operator==(const SchedulingParams& rhs) const { ...@@ -20,7 +20,9 @@ bool SchedulingParams::operator==(const SchedulingParams& rhs) const {
priority == rhs.priority && cancel_time == rhs.cancel_time; priority == rhs.priority && cancel_time == rhs.cancel_time;
} }
RequestParams::RequestParams() : method("GET") {} RequestParams::RequestParams() : method("GET"), fetch_error_body(false) {}
RequestParams::RequestParams(const RequestParams& other) = default;
DownloadParams::DownloadParams() : client(DownloadClient::INVALID) {} DownloadParams::DownloadParams() : client(DownloadClient::INVALID) {}
......
...@@ -94,7 +94,7 @@ struct SchedulingParams { ...@@ -94,7 +94,7 @@ struct SchedulingParams {
struct RequestParams { struct RequestParams {
public: public:
RequestParams(); RequestParams();
RequestParams(const RequestParams& other) = default; RequestParams(const RequestParams& other);
~RequestParams() = default; ~RequestParams() = default;
GURL url; GURL url;
...@@ -102,6 +102,10 @@ struct RequestParams { ...@@ -102,6 +102,10 @@ struct RequestParams {
// The request method ("GET" is the default value). // The request method ("GET" is the default value).
std::string method; std::string method;
net::HttpRequestHeaders request_headers; net::HttpRequestHeaders request_headers;
// If the request will fetch HTTP error response body and treat them as
// a successful download.
bool fetch_error_body;
}; };
// The parameters that describe a download request made to the DownloadService. // The parameters that describe a download request made to the DownloadService.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment