Commit 07f997d1 authored by Min Qin's avatar Min Qin Committed by Commit Bot

Use enum for accept_range field

"Accept-Ranges" header are not required for servers supporting range
requests. This CL changes the accept_range field in DownloadCreateInfo
to use an enum so that we can experiment parallel download even if
range support is unsure.

BUG=917366

Change-Id: I9d6d444437650957b12225da0cada85d0cce5473
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1645480Reviewed-by: default avatarMin Qin <qinmin@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Min Qin <qinmin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#666527}
parent 259f4adc
......@@ -28,7 +28,7 @@ DownloadCreateInfo::DownloadCreateInfo(
save_info(std::move(save_info)),
render_process_id(-1),
render_frame_id(-1),
accept_range(false),
accept_range(RangeRequestSupportType::kNoSupport),
connection_info(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN),
method("GET"),
ukm_source_id(ukm::kInvalidSourceId) {}
......
......@@ -47,10 +47,11 @@ bool IsParallelizableDownload(const DownloadCreateInfo& create_info,
create_info.method == "GET" && create_info.url().SchemeIsHTTPOrHTTPS();
bool partial_response_success =
download_item->GetReceivedSlices().empty() || create_info.offset != 0;
bool is_parallelizable = has_strong_validator && create_info.accept_range &&
has_content_length && satisfy_min_file_size &&
satisfy_connection_type && http_get_method &&
partial_response_success;
bool is_parallelizable =
has_strong_validator &&
create_info.accept_range == RangeRequestSupportType::kSupport &&
has_content_length && satisfy_min_file_size && satisfy_connection_type &&
http_get_method && partial_response_success;
if (!IsParallelDownloadEnabled())
return is_parallelizable;
......@@ -64,7 +65,7 @@ bool IsParallelizableDownload(const DownloadCreateInfo& create_info,
RecordParallelDownloadCreationEvent(
ParallelDownloadCreationEvent::FALLBACK_REASON_STRONG_VALIDATORS);
}
if (!create_info.accept_range) {
if (create_info.accept_range != RangeRequestSupportType::kSupport) {
RecordParallelDownloadCreationEvent(
ParallelDownloadCreationEvent::FALLBACK_REASON_ACCEPT_RANGE_HEADER);
}
......
......@@ -237,10 +237,15 @@ void HandleResponseHeaders(const net::HttpResponseHeaders* headers,
// In RFC 7233, a single part 206 partial response must generate
// Content-Range. Accept-Range may be sent in 200 response to indicate the
// server can handle range request, but optional in 206 response.
create_info->accept_range =
headers->HasHeaderValue("Accept-Ranges", "bytes") ||
if (headers->HasHeaderValue("Accept-Ranges", "bytes") ||
(headers->HasHeader("Content-Range") &&
headers->response_code() == net::HTTP_PARTIAL_CONTENT);
headers->response_code() == net::HTTP_PARTIAL_CONTENT)) {
create_info->accept_range = RangeRequestSupportType::kSupport;
} else if (headers->HasHeaderValue("Accept-Ranges", "none")) {
create_info->accept_range = RangeRequestSupportType::kNoSupport;
} else {
create_info->accept_range = RangeRequestSupportType::kUnknown;
}
}
std::unique_ptr<network::ResourceRequest> CreateResourceRequest(
......
......@@ -35,6 +35,16 @@ class HttpResponseHeaders;
namespace download {
// Server support for range request inferred from the response headers.
// |kSupport| value means the server supports range requests. |kNoSupport|
// means no range request is accepted by server. and |kUnknown| is used if
// range request support cannot be inferred from response headers.
enum class RangeRequestSupportType {
kSupport = 0,
kUnknown,
kNoSupport,
};
// Used for informing the download manager of a new download, since we don't
// want to pass |DownloadItem|s between threads.
struct COMPONENTS_DOWNLOAD_EXPORT DownloadCreateInfo {
......@@ -142,10 +152,8 @@ struct COMPONENTS_DOWNLOAD_EXPORT DownloadCreateInfo {
// For continuing a download, the ETag of the file.
std::string etag;
// If the download response can be partial content.
// Either "Accept-Ranges" or "Content-Range" header presents in the
// response header.
bool accept_range;
// Whether the server supports range requests.
RangeRequestSupportType accept_range;
// The HTTP connection type.
net::HttpResponseInfo::ConnectionInfo connection_info;
......
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