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

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

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: nits. 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
(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 // 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) {
25 // 1. Accept-Ranges, Content-Length and strong validators response headers.
26 // 2. Feature |kParallelDownloading| enabled.
27 // 3. Content-Length is no less than |kMinFileSizeParallelDownload|.
28 // 3. (Undetermined) Http/1.1 protocol.
29 // 4. (Undetermined) Not under http proxy, e.g. data saver.
30
31 // Etag and last modified are stored into DownloadCreateInfo in
32 // DownloadRequestCore only if the response header complies to the strong
33 // validator rule.
34 bool has_strong_validator =
35 !create_info.etag.empty() || !create_info.last_modified.empty();
36
37 return has_strong_validator && create_info.accept_range &&
38 create_info.total_bytes >= kMinFileSizeParallelDownload &&
39 base::FeatureList::IsEnabled(features::kParallelDownloading);
40 }
41
42 } // namespace
43
44 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob(
45 DownloadItemImpl* download_item,
46 std::unique_ptr<DownloadRequestHandleInterface> req_handle,
47 const DownloadCreateInfo& create_info) {
48 // Build parallel download job.
49 if (ShouldUseParallelDownload(create_info)) {
50 return base::MakeUnique<ParallelDownloadJob>(download_item,
51 std::move(req_handle));
52 }
53
54 // An ordinary download job.
55 return base::MakeUnique<DownloadJobImpl>(download_item,
56 std::move(req_handle));
57 }
58
59 } // namespace
OLDNEW
« no previous file with comments | « content/browser/download/download_job_factory.h ('k') | content/browser/download/download_job_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698