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

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

Issue 2789623005: Add UMA metric to track parallel download requests stats. (Closed)
Patch Set: 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
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/parallel_download_job.h" 5 #include "content/browser/download/parallel_download_job.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/browser/download/download_create_info.h" 8 #include "content/browser/download/download_create_info.h"
9 #include "content/browser/download/download_stats.h"
9 #include "content/browser/download/parallel_download_utils.h" 10 #include "content/browser/download/parallel_download_utils.h"
10 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/storage_partition.h" 12 #include "content/public/browser/storage_partition.h"
12 13
13 namespace content { 14 namespace content {
14 namespace { 15 namespace {
15 16
16 const int kVerboseLevel = 1; 17 const int kVerboseLevel = 1;
17 18
18 } // namespace 19 } // namespace
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this, 97 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this,
97 &ParallelDownloadJob::BuildParallelRequests); 98 &ParallelDownloadJob::BuildParallelRequests);
98 } 99 }
99 100
100 void ParallelDownloadJob::OnByteStreamReady( 101 void ParallelDownloadJob::OnByteStreamReady(
101 DownloadWorker* worker, 102 DownloadWorker* worker,
102 std::unique_ptr<ByteStreamReader> stream_reader) { 103 std::unique_ptr<ByteStreamReader> stream_reader) {
103 bool success = DownloadJob::AddByteStream(std::move(stream_reader), 104 bool success = DownloadJob::AddByteStream(std::move(stream_reader),
104 worker->offset(), worker->length()); 105 worker->offset(), worker->length());
106 RecordParallelDownloadAddStreamSuccess(success);
105 107
106 // Destroy the request if the sink is gone. 108 // Destroy the request if the sink is gone.
107 if (!success) { 109 if (!success) {
108 VLOG(kVerboseLevel) 110 VLOG(kVerboseLevel)
109 << "Byte stream arrived after download file is released."; 111 << "Byte stream arrived after download file is released.";
110 worker->Cancel(); 112 worker->Cancel();
111 } 113 }
112 } 114 }
113 115
114 void ParallelDownloadJob::OnServerResponseError( 116 void ParallelDownloadJob::OnServerResponseError(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 DCHECK_EQ(slices_to_download.back().received_bytes, 165 DCHECK_EQ(slices_to_download.back().received_bytes,
164 DownloadSaveInfo::kLengthFullContent); 166 DownloadSaveInfo::kLengthFullContent);
165 167
166 ForkSubRequests(slices_to_download); 168 ForkSubRequests(slices_to_download);
167 requests_sent_ = true; 169 requests_sent_ = true;
168 } 170 }
169 171
170 void ParallelDownloadJob::ForkSubRequests( 172 void ParallelDownloadJob::ForkSubRequests(
171 const DownloadItem::ReceivedSlices& slices_to_download) { 173 const DownloadItem::ReceivedSlices& slices_to_download) {
172 bool initial_request_skipped = false; 174 bool initial_request_skipped = false;
175 int requests_num = 0;
176 int early_requests_num = 0;
177
173 for (auto it = slices_to_download.begin(); it != slices_to_download.end(); 178 for (auto it = slices_to_download.begin(); it != slices_to_download.end();
174 ++it) { 179 ++it) {
175 // Create requests for holes before the |initial_request_offset_|. 180 // Create requests for holes before the |initial_request_offset_|.
176 if (it->offset < initial_request_offset_) { 181 if (it->offset < initial_request_offset_) {
177 CreateRequest(it->offset, it->received_bytes); 182 CreateRequest(it->offset, it->received_bytes);
183 early_requests_num++;
184 requests_num++;
178 continue; 185 continue;
179 } 186 }
180 187
181 // Assume the first slice to download after |initial_request_offset_| will 188 // Assume the first slice to download after |initial_request_offset_| will
182 // be handled by the initial request. 189 // be handled by the initial request.
183 if (initial_request_skipped) 190 if (initial_request_skipped) {
184 CreateRequest(it->offset, it->received_bytes); 191 CreateRequest(it->offset, it->received_bytes);
185 else 192 requests_num++;
193 } else
186 initial_request_skipped = true; 194 initial_request_skipped = true;
187 } 195 }
196
197 RecordParallelDownloadRequestCount(requests_num + 1);
198 if (early_requests_num > 0)
199 RecordParallelDownloadEarlyRequests(early_requests_num);
188 } 200 }
189 201
190 void ParallelDownloadJob::CreateRequest(int64_t offset, int64_t length) { 202 void ParallelDownloadJob::CreateRequest(int64_t offset, int64_t length) {
191 DCHECK(download_item_); 203 DCHECK(download_item_);
192 204
193 std::unique_ptr<DownloadWorker> worker = 205 std::unique_ptr<DownloadWorker> worker =
194 base::MakeUnique<DownloadWorker>(this, offset, length); 206 base::MakeUnique<DownloadWorker>(this, offset, length);
195 207
196 StoragePartition* storage_partition = 208 StoragePartition* storage_partition =
197 BrowserContext::GetStoragePartitionForSite( 209 BrowserContext::GetStoragePartitionForSite(
(...skipping 15 matching lines...) Expand all
213 // download request. 225 // download request.
214 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), 226 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(),
215 blink::WebReferrerPolicyAlways)); 227 blink::WebReferrerPolicyAlways));
216 // Send the request. 228 // Send the request.
217 worker->SendRequest(std::move(download_params)); 229 worker->SendRequest(std::move(download_params));
218 DCHECK(workers_.find(offset) == workers_.end()); 230 DCHECK(workers_.find(offset) == workers_.end());
219 workers_[offset] = std::move(worker); 231 workers_[offset] = std::move(worker);
220 } 232 }
221 233
222 } // namespace content 234 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698