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

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

Issue 2823273004: Add new UMA stats for parallelizable download (Closed)
Patch Set: fix test Created 3 years, 8 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
« no previous file with comments | « content/browser/download/download_job.cc ('k') | content/browser/download/download_job_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 IsParallelizableDownload(const DownloadCreateInfo& create_info) {
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 is_parallelizable = has_strong_validator && create_info.accept_range &&
46 has_strong_validator && create_info.accept_range && has_content_length && 44 has_content_length && satisfy_min_file_size &&
47 satisfy_min_file_size && satisfy_connection_type; 45 satisfy_connection_type;
46
47 if (!IsParallelDownloadEnabled())
48 return is_parallelizable;
48 49
49 RecordParallelDownloadCreationEvent( 50 RecordParallelDownloadCreationEvent(
50 should_use_parallel_download 51 is_parallelizable
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) {
59 RecordParallelDownloadCreationEvent( 60 RecordParallelDownloadCreationEvent(
60 ParallelDownloadCreationEvent::FALLBACK_REASON_ACCEPT_RANGE_HEADER); 61 ParallelDownloadCreationEvent::FALLBACK_REASON_ACCEPT_RANGE_HEADER);
61 } 62 }
62 if (!has_content_length) { 63 if (!has_content_length) {
63 RecordParallelDownloadCreationEvent( 64 RecordParallelDownloadCreationEvent(
64 ParallelDownloadCreationEvent::FALLBACK_REASON_CONTENT_LENGTH_HEADER); 65 ParallelDownloadCreationEvent::FALLBACK_REASON_CONTENT_LENGTH_HEADER);
65 } 66 }
66 if (!satisfy_min_file_size) { 67 if (!satisfy_min_file_size) {
67 RecordParallelDownloadCreationEvent( 68 RecordParallelDownloadCreationEvent(
68 ParallelDownloadCreationEvent::FALLBACK_REASON_FILE_SIZE); 69 ParallelDownloadCreationEvent::FALLBACK_REASON_FILE_SIZE);
69 } 70 }
70 if (!satisfy_connection_type) { 71 if (!satisfy_connection_type) {
71 RecordParallelDownloadCreationEvent( 72 RecordParallelDownloadCreationEvent(
72 ParallelDownloadCreationEvent::FALLBACK_REASON_CONNECTION_TYPE); 73 ParallelDownloadCreationEvent::FALLBACK_REASON_CONNECTION_TYPE);
73 } 74 }
74 75
75 return should_use_parallel_download; 76 return is_parallelizable;
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_parallelizable = IsParallelizableDownload(create_info);
84 // Build parallel download job. 86 // Build parallel download job.
85 if (ShouldUseParallelDownload(create_info)) { 87 if (IsParallelDownloadEnabled() && is_parallelizable) {
86 return base::MakeUnique<ParallelDownloadJob>(download_item, 88 return base::MakeUnique<ParallelDownloadJob>(download_item,
87 std::move(req_handle), 89 std::move(req_handle),
88 create_info); 90 create_info);
89 } 91 }
90 92
91 // An ordinary download job. 93 // An ordinary download job.
92 return base::MakeUnique<DownloadJobImpl>(download_item, 94 return base::MakeUnique<DownloadJobImpl>(download_item, std::move(req_handle),
93 std::move(req_handle)); 95 is_parallelizable);
94 } 96 }
95 97
96 } // namespace 98 } // namespace
OLDNEW
« no previous file with comments | « content/browser/download/download_job.cc ('k') | content/browser/download/download_job_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698