| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/download/download_job_factory.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "content/browser/download/download_item_impl.h" |
| 11 #include "content/browser/download/download_job.h" |
| 12 #include "content/browser/download/download_job_impl.h" |
| 13 #include "content/browser/download/parallel_download_job.h" |
| 14 #include "content/public/common/content_features.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 namespace { |
| 19 |
| 20 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { |
| 21 // 1. Accept-Ranges, Content-Length and strong validators response headers. |
| 22 // 2. Feature |kParallelDownloading| enabled. |
| 23 // 3. (Undetermined) Http/1.1 protocol. |
| 24 // 4. (Undetermined) Not under http proxy, e.g. data saver. |
| 25 |
| 26 // Etag and last modified are stored into DownloadCreateInfo in |
| 27 // DownloadRequestCore only if the response header complies to the strong |
| 28 // validator rule. |
| 29 bool has_strong_validator = |
| 30 !create_info.etag.empty() || !create_info.last_modified.empty(); |
| 31 |
| 32 return has_strong_validator && create_info.accept_range && |
| 33 create_info.total_bytes > 0 && |
| 34 base::FeatureList::IsEnabled(features::kParallelDownloading); |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 39 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( |
| 40 DownloadItemImpl* download_item, |
| 41 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
| 42 const DownloadCreateInfo& create_info) { |
| 43 std::unique_ptr<DownloadJob> job; |
| 44 |
| 45 // Build parallel download job. |
| 46 if (ShouldUseParallelDownload(create_info)) { |
| 47 return base::MakeUnique<ParallelDownloadJob>(download_item, |
| 48 std::move(req_handle)); |
| 49 } |
| 50 |
| 51 // An ordinary download job. |
| 52 job = base::MakeUnique<DownloadJobImpl>(download_item, std::move(req_handle)); |
| 53 return job; |
| 54 } |
| 55 |
| 56 } // namespace |
| OLD | NEW |