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( ...@@ -28,7 +28,7 @@ DownloadCreateInfo::DownloadCreateInfo(
save_info(std::move(save_info)), save_info(std::move(save_info)),
render_process_id(-1), render_process_id(-1),
render_frame_id(-1), render_frame_id(-1),
accept_range(false), accept_range(RangeRequestSupportType::kNoSupport),
connection_info(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN), connection_info(net::HttpResponseInfo::CONNECTION_INFO_UNKNOWN),
method("GET"), method("GET"),
ukm_source_id(ukm::kInvalidSourceId) {} ukm_source_id(ukm::kInvalidSourceId) {}
......
...@@ -47,10 +47,11 @@ bool IsParallelizableDownload(const DownloadCreateInfo& create_info, ...@@ -47,10 +47,11 @@ bool IsParallelizableDownload(const DownloadCreateInfo& create_info,
create_info.method == "GET" && create_info.url().SchemeIsHTTPOrHTTPS(); create_info.method == "GET" && create_info.url().SchemeIsHTTPOrHTTPS();
bool partial_response_success = bool partial_response_success =
download_item->GetReceivedSlices().empty() || create_info.offset != 0; download_item->GetReceivedSlices().empty() || create_info.offset != 0;
bool is_parallelizable = has_strong_validator && create_info.accept_range && bool is_parallelizable =
has_content_length && satisfy_min_file_size && has_strong_validator &&
satisfy_connection_type && http_get_method && create_info.accept_range == RangeRequestSupportType::kSupport &&
partial_response_success; has_content_length && satisfy_min_file_size && satisfy_connection_type &&
http_get_method && partial_response_success;
if (!IsParallelDownloadEnabled()) if (!IsParallelDownloadEnabled())
return is_parallelizable; return is_parallelizable;
...@@ -64,7 +65,7 @@ bool IsParallelizableDownload(const DownloadCreateInfo& create_info, ...@@ -64,7 +65,7 @@ bool IsParallelizableDownload(const DownloadCreateInfo& create_info,
RecordParallelDownloadCreationEvent( RecordParallelDownloadCreationEvent(
ParallelDownloadCreationEvent::FALLBACK_REASON_STRONG_VALIDATORS); ParallelDownloadCreationEvent::FALLBACK_REASON_STRONG_VALIDATORS);
} }
if (!create_info.accept_range) { if (create_info.accept_range != RangeRequestSupportType::kSupport) {
RecordParallelDownloadCreationEvent( RecordParallelDownloadCreationEvent(
ParallelDownloadCreationEvent::FALLBACK_REASON_ACCEPT_RANGE_HEADER); ParallelDownloadCreationEvent::FALLBACK_REASON_ACCEPT_RANGE_HEADER);
} }
......
...@@ -237,10 +237,15 @@ void HandleResponseHeaders(const net::HttpResponseHeaders* headers, ...@@ -237,10 +237,15 @@ void HandleResponseHeaders(const net::HttpResponseHeaders* headers,
// In RFC 7233, a single part 206 partial response must generate // In RFC 7233, a single part 206 partial response must generate
// Content-Range. Accept-Range may be sent in 200 response to indicate the // Content-Range. Accept-Range may be sent in 200 response to indicate the
// server can handle range request, but optional in 206 response. // server can handle range request, but optional in 206 response.
create_info->accept_range = if (headers->HasHeaderValue("Accept-Ranges", "bytes") ||
headers->HasHeaderValue("Accept-Ranges", "bytes") ||
(headers->HasHeader("Content-Range") && (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( std::unique_ptr<network::ResourceRequest> CreateResourceRequest(
......
...@@ -35,6 +35,16 @@ class HttpResponseHeaders; ...@@ -35,6 +35,16 @@ class HttpResponseHeaders;
namespace download { 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 // Used for informing the download manager of a new download, since we don't
// want to pass |DownloadItem|s between threads. // want to pass |DownloadItem|s between threads.
struct COMPONENTS_DOWNLOAD_EXPORT DownloadCreateInfo { struct COMPONENTS_DOWNLOAD_EXPORT DownloadCreateInfo {
...@@ -142,10 +152,8 @@ struct COMPONENTS_DOWNLOAD_EXPORT DownloadCreateInfo { ...@@ -142,10 +152,8 @@ struct COMPONENTS_DOWNLOAD_EXPORT DownloadCreateInfo {
// For continuing a download, the ETag of the file. // For continuing a download, the ETag of the file.
std::string etag; std::string etag;
// If the download response can be partial content. // Whether the server supports range requests.
// Either "Accept-Ranges" or "Content-Range" header presents in the RangeRequestSupportType accept_range;
// response header.
bool accept_range;
// The HTTP connection type. // The HTTP connection type.
net::HttpResponseInfo::ConnectionInfo connection_info; 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