OLD | NEW |
---|---|
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/download_stats.h" | 13 #include "content/browser/download/download_stats.h" |
14 #include "content/browser/download/parallel_download_job.h" | 14 #include "content/browser/download/parallel_download_job.h" |
15 #include "content/browser/download/parallel_download_utils.h" | 15 #include "content/browser/download/parallel_download_utils.h" |
16 #include "content/public/common/content_features.h" | 16 #include "content/public/common/content_features.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Returns if the download should be a parallel download. | 22 // Returns if the download can be parallelized. |
23 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { | 23 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { |
xingliu
2017/04/19 02:18:11
nit: Maybe also change the function name?
qinmin
2017/04/19 22:42:33
Done.
| |
24 // To enable parallel download, following conditions need to be satisfied. | 24 // To enable parallel download, following conditions need to be satisfied. |
25 // 1. Feature |kParallelDownloading| enabled. | 25 // 1. Feature |kParallelDownloading| enabled. |
26 // 2. Strong validators response headers. i.e. ETag and Last-Modified. | 26 // 2. Strong validators response headers. i.e. ETag and Last-Modified. |
27 // 3. Accept-Ranges header. | 27 // 3. Accept-Ranges header. |
28 // 4. Content-Length header. | 28 // 4. Content-Length header. |
29 // 5. Content-Length is no less than the minimum slice size configuration. | 29 // 5. Content-Length is no less than the minimum slice size configuration. |
30 // 6. HTTP/1.1 protocol, not QUIC nor HTTP/1.0. | 30 // 6. HTTP/1.1 protocol, not QUIC nor HTTP/1.0. |
31 if (!base::FeatureList::IsEnabled(features::kParallelDownloading)) | |
32 return false; | |
33 | 31 |
34 // Etag and last modified are stored into DownloadCreateInfo in | 32 // Etag and last modified are stored into DownloadCreateInfo in |
35 // DownloadRequestCore only if the response header complies to the strong | 33 // DownloadRequestCore only if the response header complies to the strong |
36 // validator rule. | 34 // validator rule. |
37 bool has_strong_validator = | 35 bool has_strong_validator = |
38 !create_info.etag.empty() || !create_info.last_modified.empty(); | 36 !create_info.etag.empty() || !create_info.last_modified.empty(); |
39 bool has_content_length = create_info.total_bytes > 0; | 37 bool has_content_length = create_info.total_bytes > 0; |
40 bool satisfy_min_file_size = | 38 bool satisfy_min_file_size = |
41 create_info.total_bytes >= GetMinSliceSizeConfig(); | 39 create_info.total_bytes >= GetMinSliceSizeConfig(); |
42 bool satisfy_connection_type = create_info.connection_info == | 40 bool satisfy_connection_type = create_info.connection_info == |
43 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1; | 41 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1; |
44 | 42 |
45 bool should_use_parallel_download = | 43 bool should_use_parallel_download = |
46 has_strong_validator && create_info.accept_range && has_content_length && | 44 has_strong_validator && create_info.accept_range && has_content_length && |
47 satisfy_min_file_size && satisfy_connection_type; | 45 satisfy_min_file_size && satisfy_connection_type; |
48 | 46 |
47 if (!base::FeatureList::IsEnabled(features::kParallelDownloading)) | |
48 return should_use_parallel_download; | |
49 | |
49 RecordParallelDownloadCreationEvent( | 50 RecordParallelDownloadCreationEvent( |
50 should_use_parallel_download | 51 should_use_parallel_download |
51 ? ParallelDownloadCreationEvent::STARTED_PARALLEL_DOWNLOAD | 52 ? ParallelDownloadCreationEvent::STARTED_PARALLEL_DOWNLOAD |
52 : ParallelDownloadCreationEvent::FELL_BACK_TO_NORMAL_DOWNLOAD); | 53 : ParallelDownloadCreationEvent::FELL_BACK_TO_NORMAL_DOWNLOAD); |
53 | 54 |
54 if (!has_strong_validator) { | 55 if (!has_strong_validator) { |
55 RecordParallelDownloadCreationEvent( | 56 RecordParallelDownloadCreationEvent( |
56 ParallelDownloadCreationEvent::FALLBACK_REASON_STRONG_VALIDATORS); | 57 ParallelDownloadCreationEvent::FALLBACK_REASON_STRONG_VALIDATORS); |
57 } | 58 } |
58 if (!create_info.accept_range) { | 59 if (!create_info.accept_range) { |
(...skipping 15 matching lines...) Expand all Loading... | |
74 | 75 |
75 return should_use_parallel_download; | 76 return should_use_parallel_download; |
76 } | 77 } |
77 | 78 |
78 } // namespace | 79 } // namespace |
79 | 80 |
80 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( | 81 std::unique_ptr<DownloadJob> DownloadJobFactory::CreateJob( |
81 DownloadItemImpl* download_item, | 82 DownloadItemImpl* download_item, |
82 std::unique_ptr<DownloadRequestHandleInterface> req_handle, | 83 std::unique_ptr<DownloadRequestHandleInterface> req_handle, |
83 const DownloadCreateInfo& create_info) { | 84 const DownloadCreateInfo& create_info) { |
85 bool is_parallizable = ShouldUseParallelDownload(create_info); | |
84 // Build parallel download job. | 86 // Build parallel download job. |
85 if (ShouldUseParallelDownload(create_info)) { | 87 if (base::FeatureList::IsEnabled(features::kParallelDownloading) && |
88 is_parallizable) { | |
86 return base::MakeUnique<ParallelDownloadJob>(download_item, | 89 return base::MakeUnique<ParallelDownloadJob>(download_item, |
87 std::move(req_handle), | 90 std::move(req_handle), |
88 create_info); | 91 create_info); |
89 } | 92 } |
90 | 93 |
91 // An ordinary download job. | 94 // An ordinary download job. |
92 return base::MakeUnique<DownloadJobImpl>(download_item, | 95 return base::MakeUnique<DownloadJobImpl>(download_item, std::move(req_handle), |
93 std::move(req_handle)); | 96 is_parallizable); |
94 } | 97 } |
95 | 98 |
96 } // namespace | 99 } // namespace |
OLD | NEW |