Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Side by Side Diff: content/browser/download/download_job_factory.cc

Issue 2742093002: Glue parallel download job and download file together. (Closed)
Patch Set: Work on feedback. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/download/parallel_download_utils.h"
15 #include "content/public/common/content_features.h" 15 #include "content/public/common/content_features.h"
16 16
17 namespace content { 17 namespace content {
18 18
19 namespace {
20
21 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) {
22 // 1. Accept-Ranges, Content-Length and strong validators response headers.
23 // 2. Feature |kParallelDownloading| enabled.
24 // 3. Content-Length is no less than the minimum slice size configuration.
25 // 3. (Undetermined) Http/1.1 protocol.
26 // 4. (Undetermined) Not under http proxy, e.g. data saver.
27
28 // Etag and last modified are stored into DownloadCreateInfo in
29 // DownloadRequestCore only if the response header complies to the strong
30 // validator rule.
31 bool has_strong_validator =
32 !create_info.etag.empty() || !create_info.last_modified.empty();
33
34 return has_strong_validator && create_info.accept_range &&
35 create_info.total_bytes >= GetMinSliceSizeConfig() &&
36 base::FeatureList::IsEnabled(features::kParallelDownloading);
37 }
38
39 } // namespace
40
41 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( 19 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob(
42 DownloadItemImpl* download_item, 20 DownloadItemImpl* download_item,
43 std::unique_ptr<DownloadRequestHandleInterface> req_handle, 21 std::unique_ptr<DownloadRequestHandleInterface> req_handle,
44 const DownloadCreateInfo& create_info) { 22 const DownloadCreateInfo& create_info) {
45 // Build parallel download job. 23 // Build parallel download job.
46 if (ShouldUseParallelDownload(create_info)) { 24 if (ShouldUseParallelDownload(create_info)) {
47 return base::MakeUnique<ParallelDownloadJob>(download_item, 25 return base::MakeUnique<ParallelDownloadJob>(download_item,
48 std::move(req_handle), 26 std::move(req_handle),
49 create_info); 27 create_info);
50 } 28 }
51 29
52 // An ordinary download job. 30 // An ordinary download job.
53 return base::MakeUnique<DownloadJobImpl>(download_item, 31 return base::MakeUnique<DownloadJobImpl>(download_item,
54 std::move(req_handle)); 32 std::move(req_handle));
55 } 33 }
56 34
57 } // namespace 35 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698