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

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

Issue 2689373003: Introduce ParallelDownloadJob. (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
(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 const int64_t kMinFileSizeParallelDownload = 2097152;
qinmin 2017/02/27 21:54:46 nit: make this finch configurable, or add a TODO f
xingliu 2017/02/27 23:53:26 Done.
22
23 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) {
24 // 1. Accept-Ranges, Content-Length and strong validators response headers.
25 // 2. Feature |kParallelDownloading| enabled.
26 // 3. Content-Length is no less than |kMinFileSizeParallelDownload|.
27 // 3. (Undetermined) Http/1.1 protocol.
28 // 4. (Undetermined) Not under http proxy, e.g. data saver.
29
30 // Etag and last modified are stored into DownloadCreateInfo in
31 // DownloadRequestCore only if the response header complies to the strong
32 // validator rule.
33 bool has_strong_validator =
34 !create_info.etag.empty() || !create_info.last_modified.empty();
35
36 return has_strong_validator && create_info.accept_range &&
37 create_info.total_bytes >= kMinFileSizeParallelDownload &&
38 base::FeatureList::IsEnabled(features::kParallelDownloading);
39 }
40
41 } // namespace
42
43 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob(
44 DownloadItemImpl* download_item,
45 std::unique_ptr<DownloadRequestHandleInterface> req_handle,
46 const DownloadCreateInfo& create_info) {
47 // Build parallel download job.
48 if (ShouldUseParallelDownload(create_info)) {
49 return base::MakeUnique<ParallelDownloadJob>(download_item,
50 std::move(req_handle));
51 }
52
53 // An ordinary download job.
54 return base::MakeUnique<DownloadJobImpl>(download_item,
55 std::move(req_handle));
56 }
57
58 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698