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

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

Issue 2689373003: Introduce ParallelDownloadJob. (Closed)
Patch Set: Make compilers happy. 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.
21 const int64_t kMinFileSizeParallelDownload = 2048;
qinmin 2017/02/23 07:26:57 Bytes or KB? 2048 bytes is too small to kick off p
xingliu 2017/02/24 23:43:13 Done, yeah, make sense.
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 std::unique_ptr<DownloadJob> job;
qinmin 2017/02/23 07:26:57 seems this is not needed
xingliu 2017/02/24 23:43:13 Done. Sorry I should change it in the previous pat
48
49 // Build parallel download job.
50 if (ShouldUseParallelDownload(create_info)) {
51 return base::MakeUnique<ParallelDownloadJob>(download_item,
52 std::move(req_handle));
53 }
54
55 // An ordinary download job.
56 job = base::MakeUnique<DownloadJobImpl>(download_item, std::move(req_handle));
57 return job;
58 }
59
60 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698