Chromium Code Reviews| 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_url_job.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 // TODO(xingliu): We should follow RFC 7232 section 2 on strong validators. | |
| 22 // Parallel download requires: | |
| 23 // 1. Accept-Ranges, Content-Length and strong validators response headers. | |
| 24 // 2. Feature |kParallelDownloading| enabled. | |
| 25 // 3. (Undetermined) Http/1.1 protocol. | |
| 26 // 4. (Undetermined) Not under http proxy, e.g. data saver. | |
| 27 bool has_strong_validator = | |
|
asanka
2017/02/16 16:27:39
Not the place to determine this.
See https://cs.c
xingliu
2017/02/20 18:59:11
Oh, I see. Thanks.
| |
| 28 !create_info.etag.empty() || !create_info.last_modified.empty(); | |
| 29 | |
| 30 return has_strong_validator && create_info.accept_range && | |
| 31 create_info.total_bytes > 0 && | |
| 32 base::FeatureList::IsEnabled(features::kParallelDownloading); | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( | |
| 38 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | |
| 39 const DownloadCreateInfo& create_info) { | |
| 40 std::unique_ptr<DownloadJob> job; | |
| 41 | |
| 42 // Build parallel download job. | |
| 43 if (ShouldUseParallelDownload(create_info)) { | |
| 44 job = base::MakeUnique<ParallelDownloadJob>(std::move(req_handle)); | |
|
asanka
2017/02/16 16:27:39
return base::MakeUnique<...>(...)
No need to stor
xingliu
2017/02/20 18:59:11
Done.
| |
| 45 return job; | |
| 46 } | |
| 47 | |
| 48 // An ordinary download job. | |
| 49 job = base::MakeUnique<DownloadUrlJob>(std::move(req_handle)); | |
|
asanka
2017/02/16 16:27:39
Let's rename DownloadUrlJob to something else so t
xingliu
2017/02/20 18:59:11
Done. Renamed to DownloadJobImpl.
| |
| 50 return job; | |
| 51 } | |
| 52 | |
| 53 } // namespace | |
| OLD | NEW |