| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/browser/download/download_job_factory.h" | 5 #include "content/browser/download/download_job_factory.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "content/browser/download/download_item_impl.h" | 10 #include "content/browser/download/download_item_impl.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 // Returns if the download can be parallelized. | 22 // Returns if the download can be parallelized. |
| 23 bool IsParallelizableDownload(const DownloadCreateInfo& create_info) { | 23 bool IsParallelizableDownload(const DownloadCreateInfo& create_info) { |
| 24 // To enable parallel download, following conditions need to be satisfied. | 24 // To enable parallel download, following conditions need to be satisfied. |
| 25 // 1. Feature |kParallelDownloading| enabled. | 25 // 1. Feature |kParallelDownloading| enabled. |
| 26 // 2. Strong validators response headers. i.e. ETag and Last-Modified. | 26 // 2. Strong validators response headers. i.e. ETag and Last-Modified. |
| 27 // 3. Accept-Ranges header. | 27 // 3. Accept-Ranges header. |
| 28 // 4. Content-Length header. | 28 // 4. Content-Length header. |
| 29 // 5. Content-Length is no less than the minimum slice size configuration. | 29 // 5. Content-Length is no less than the minimum slice size configuration. |
| 30 // 6. HTTP/1.1 protocol, not QUIC nor HTTP/1.0. | 30 // 6. HTTP/1.1 protocol, not QUIC nor HTTP/1.0. |
| 31 // 7. HTTP or HTTPS scheme with GET method in the initial request. |
| 31 | 32 |
| 32 // Etag and last modified are stored into DownloadCreateInfo in | 33 // Etag and last modified are stored into DownloadCreateInfo in |
| 33 // DownloadRequestCore only if the response header complies to the strong | 34 // DownloadRequestCore only if the response header complies to the strong |
| 34 // validator rule. | 35 // validator rule. |
| 35 bool has_strong_validator = | 36 bool has_strong_validator = |
| 36 !create_info.etag.empty() || !create_info.last_modified.empty(); | 37 !create_info.etag.empty() || !create_info.last_modified.empty(); |
| 37 bool has_content_length = create_info.total_bytes > 0; | 38 bool has_content_length = create_info.total_bytes > 0; |
| 38 bool satisfy_min_file_size = | 39 bool satisfy_min_file_size = |
| 39 create_info.total_bytes >= GetMinSliceSizeConfig(); | 40 create_info.total_bytes >= GetMinSliceSizeConfig(); |
| 40 bool satisfy_connection_type = create_info.connection_info == | 41 bool satisfy_connection_type = create_info.connection_info == |
| 41 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1; | 42 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1; |
| 43 bool http_get_method = |
| 44 create_info.method == "GET" && create_info.url().SchemeIsHTTPOrHTTPS(); |
| 42 | 45 |
| 43 bool is_parallelizable = has_strong_validator && create_info.accept_range && | 46 bool is_parallelizable = has_strong_validator && create_info.accept_range && |
| 44 has_content_length && satisfy_min_file_size && | 47 has_content_length && satisfy_min_file_size && |
| 45 satisfy_connection_type; | 48 satisfy_connection_type && http_get_method; |
| 46 | 49 |
| 47 if (!IsParallelDownloadEnabled()) | 50 if (!IsParallelDownloadEnabled()) |
| 48 return is_parallelizable; | 51 return is_parallelizable; |
| 49 | 52 |
| 50 RecordParallelDownloadCreationEvent( | 53 RecordParallelDownloadCreationEvent( |
| 51 is_parallelizable | 54 is_parallelizable |
| 52 ? ParallelDownloadCreationEvent::STARTED_PARALLEL_DOWNLOAD | 55 ? ParallelDownloadCreationEvent::STARTED_PARALLEL_DOWNLOAD |
| 53 : ParallelDownloadCreationEvent::FELL_BACK_TO_NORMAL_DOWNLOAD); | 56 : ParallelDownloadCreationEvent::FELL_BACK_TO_NORMAL_DOWNLOAD); |
| 54 | 57 |
| 55 if (!has_strong_validator) { | 58 if (!has_strong_validator) { |
| 56 RecordParallelDownloadCreationEvent( | 59 RecordParallelDownloadCreationEvent( |
| 57 ParallelDownloadCreationEvent::FALLBACK_REASON_STRONG_VALIDATORS); | 60 ParallelDownloadCreationEvent::FALLBACK_REASON_STRONG_VALIDATORS); |
| 58 } | 61 } |
| 59 if (!create_info.accept_range) { | 62 if (!create_info.accept_range) { |
| 60 RecordParallelDownloadCreationEvent( | 63 RecordParallelDownloadCreationEvent( |
| 61 ParallelDownloadCreationEvent::FALLBACK_REASON_ACCEPT_RANGE_HEADER); | 64 ParallelDownloadCreationEvent::FALLBACK_REASON_ACCEPT_RANGE_HEADER); |
| 62 } | 65 } |
| 63 if (!has_content_length) { | 66 if (!has_content_length) { |
| 64 RecordParallelDownloadCreationEvent( | 67 RecordParallelDownloadCreationEvent( |
| 65 ParallelDownloadCreationEvent::FALLBACK_REASON_CONTENT_LENGTH_HEADER); | 68 ParallelDownloadCreationEvent::FALLBACK_REASON_CONTENT_LENGTH_HEADER); |
| 66 } | 69 } |
| 67 if (!satisfy_min_file_size) { | 70 if (!satisfy_min_file_size) { |
| 68 RecordParallelDownloadCreationEvent( | 71 RecordParallelDownloadCreationEvent( |
| 69 ParallelDownloadCreationEvent::FALLBACK_REASON_FILE_SIZE); | 72 ParallelDownloadCreationEvent::FALLBACK_REASON_FILE_SIZE); |
| 70 } | 73 } |
| 71 if (!satisfy_connection_type) { | 74 if (!satisfy_connection_type) { |
| 72 RecordParallelDownloadCreationEvent( | 75 RecordParallelDownloadCreationEvent( |
| 73 ParallelDownloadCreationEvent::FALLBACK_REASON_CONNECTION_TYPE); | 76 ParallelDownloadCreationEvent::FALLBACK_REASON_CONNECTION_TYPE); |
| 74 } | 77 } |
| 78 if (!http_get_method) { |
| 79 RecordParallelDownloadCreationEvent( |
| 80 ParallelDownloadCreationEvent::FALLBACK_REASON_HTTP_METHOD); |
| 81 } |
| 75 | 82 |
| 76 return is_parallelizable; | 83 return is_parallelizable; |
| 77 } | 84 } |
| 78 | 85 |
| 79 } // namespace | 86 } // namespace |
| 80 | 87 |
| 81 // static | 88 // static |
| 82 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( | 89 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( |
| 83 DownloadItemImpl* download_item, | 90 DownloadItemImpl* download_item, |
| 84 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | 91 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
| 85 const DownloadCreateInfo& create_info) { | 92 const DownloadCreateInfo& create_info) { |
| 86 bool is_parallelizable = IsParallelizableDownload(create_info); | 93 bool is_parallelizable = IsParallelizableDownload(create_info); |
| 87 // Build parallel download job. | 94 // Build parallel download job. |
| 88 if (IsParallelDownloadEnabled() && is_parallelizable) { | 95 if (IsParallelDownloadEnabled() && is_parallelizable) { |
| 89 return base::MakeUnique<ParallelDownloadJob>(download_item, | 96 return base::MakeUnique<ParallelDownloadJob>(download_item, |
| 90 std::move(req_handle), | 97 std::move(req_handle), |
| 91 create_info); | 98 create_info); |
| 92 } | 99 } |
| 93 | 100 |
| 94 // An ordinary download job. | 101 // An ordinary download job. |
| 95 return base::MakeUnique<DownloadJobImpl>(download_item, std::move(req_handle), | 102 return base::MakeUnique<DownloadJobImpl>(download_item, std::move(req_handle), |
| 96 is_parallelizable); | 103 is_parallelizable); |
| 97 } | 104 } |
| 98 | 105 |
| 99 } // namespace | 106 } // namespace |
| OLD | NEW |