| 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" |
| 11 #include "content/browser/download/download_job.h" | 11 #include "content/browser/download/download_job.h" |
| 12 #include "content/browser/download/download_job_impl.h" | 12 #include "content/browser/download/download_job_impl.h" |
| 13 #include "content/browser/download/parallel_download_job.h" | 13 #include "content/browser/download/parallel_download_job.h" |
| 14 #include "content/browser/download/parallel_download_utils.h" |
| 14 #include "content/public/common/content_features.h" | 15 #include "content/public/common/content_features.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 // Default minimum file size in bytes to enable a parallel download, 2048KB. | |
| 21 // TODO(xingliu): Use finch parameters to configure minimum file size. | |
| 22 const int64_t kMinFileSizeParallelDownload = 2097152; | |
| 23 | |
| 24 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { | 21 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { |
| 25 // 1. Accept-Ranges, Content-Length and strong validators response headers. | 22 // 1. Accept-Ranges, Content-Length and strong validators response headers. |
| 26 // 2. Feature |kParallelDownloading| enabled. | 23 // 2. Feature |kParallelDownloading| enabled. |
| 27 // 3. Content-Length is no less than |kMinFileSizeParallelDownload|. | 24 // 3. Content-Length is no less than the minimum slice size configuration. |
| 28 // 3. (Undetermined) Http/1.1 protocol. | 25 // 3. (Undetermined) Http/1.1 protocol. |
| 29 // 4. (Undetermined) Not under http proxy, e.g. data saver. | 26 // 4. (Undetermined) Not under http proxy, e.g. data saver. |
| 30 | 27 |
| 31 // Etag and last modified are stored into DownloadCreateInfo in | 28 // Etag and last modified are stored into DownloadCreateInfo in |
| 32 // DownloadRequestCore only if the response header complies to the strong | 29 // DownloadRequestCore only if the response header complies to the strong |
| 33 // validator rule. | 30 // validator rule. |
| 34 bool has_strong_validator = | 31 bool has_strong_validator = |
| 35 !create_info.etag.empty() || !create_info.last_modified.empty(); | 32 !create_info.etag.empty() || !create_info.last_modified.empty(); |
| 36 | 33 |
| 37 return has_strong_validator && create_info.accept_range && | 34 return has_strong_validator && create_info.accept_range && |
| 38 create_info.total_bytes >= kMinFileSizeParallelDownload && | 35 create_info.total_bytes >= GetMinSliceSizeConfig() && |
| 39 base::FeatureList::IsEnabled(features::kParallelDownloading); | 36 base::FeatureList::IsEnabled(features::kParallelDownloading); |
| 40 } | 37 } |
| 41 | 38 |
| 42 } // namespace | 39 } // namespace |
| 43 | 40 |
| 44 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( | 41 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( |
| 45 DownloadItemImpl* download_item, | 42 DownloadItemImpl* download_item, |
| 46 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | 43 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
| 47 const DownloadCreateInfo& create_info) { | 44 const DownloadCreateInfo& create_info) { |
| 48 // Build parallel download job. | 45 // Build parallel download job. |
| 49 if (ShouldUseParallelDownload(create_info)) { | 46 if (ShouldUseParallelDownload(create_info)) { |
| 50 return base::MakeUnique<ParallelDownloadJob>(download_item, | 47 return base::MakeUnique<ParallelDownloadJob>(download_item, |
| 51 std::move(req_handle), | 48 std::move(req_handle), |
| 52 create_info); | 49 create_info); |
| 53 } | 50 } |
| 54 | 51 |
| 55 // An ordinary download job. | 52 // An ordinary download job. |
| 56 return base::MakeUnique<DownloadJobImpl>(download_item, | 53 return base::MakeUnique<DownloadJobImpl>(download_item, |
| 57 std::move(req_handle)); | 54 std::move(req_handle)); |
| 58 } | 55 } |
| 59 | 56 |
| 60 } // namespace | 57 } // namespace |
| OLD | NEW |