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

Unified Diff: content/browser/download/parallel_download_job.cc

Issue 2806923002: Don't create parallel request if download is about to complete (Closed)
Patch Set: add UMA and finch 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/parallel_download_job.cc
diff --git a/content/browser/download/parallel_download_job.cc b/content/browser/download/parallel_download_job.cc
index 0dc7cdda3a196687fac868df8e99c3642f4e67c3..5a3af37402aec99f0743fa73cbc5b583f4a12cb0 100644
--- a/content/browser/download/parallel_download_job.cc
+++ b/content/browser/download/parallel_download_job.cc
@@ -4,7 +4,11 @@
#include "content/browser/download/parallel_download_job.h"
+#include <algorithm>
+
#include "base/memory/ptr_util.h"
+#include "base/metrics/histogram_macros.h"
+#include "base/time/time.h"
#include "content/browser/download/download_create_info.h"
#include "content/browser/download/download_stats.h"
#include "content/browser/download/parallel_download_utils.h"
@@ -80,10 +84,15 @@ void ParallelDownloadJob::Resume(bool resume_request) {
int ParallelDownloadJob::GetParallelRequestCount() const {
return GetParallelRequestCountConfig();
}
+
int64_t ParallelDownloadJob::GetMinSliceSize() const {
return GetMinSliceSizeConfig();
}
+int ParallelDownloadJob::GetMinRemainingTimeInSeconds() const {
+ return GetParallelRequestRemainingTimeConfig().InSeconds();
+}
+
bool ParallelDownloadJob::UsesParallelRequests() const {
return true;
}
@@ -149,15 +158,30 @@ void ParallelDownloadJob::BuildParallelRequests() {
// Create more slices for a new download. The initial request may generate
// a received slice.
- if (slices_to_download.size() <= 1 &&
- initial_request_offset_ <= first_slice_offset) {
- // TODO(qinmin): Check the size of the last slice. If it is huge, we can
- // split it into N pieces and pass the last N-1 pieces to different workers.
- // Otherwise, just fork |slices_to_download.size()| number of workers.
- slices_to_download = FindSlicesForRemainingContent(
- first_slice_offset,
- content_length_ - first_slice_offset + initial_request_offset_,
- GetParallelRequestCount(), GetMinSliceSize());
+ if (slices_to_download.size() <= 1 && download_item_->GetTotalBytes() > 0) {
+ int64_t current_bytes_per_second =
+ std::max(static_cast<int64_t>(1), download_item_->CurrentSpeed());
+ int64_t remaining_bytes =
+ download_item_->GetTotalBytes() - download_item_->GetReceivedBytes();
+
+ int64_t remaining_time = remaining_bytes / current_bytes_per_second;
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Download.ParallelDownload.RemainingTimeWhenBuildingRequests",
+ remaining_time, 0, base::TimeDelta::FromDays(1).InSeconds(), 50);
+ if (remaining_bytes / current_bytes_per_second >
+ GetMinRemainingTimeInSeconds()) {
+ // TODO(qinmin): Check the size of the last slice. If it is huge, we can
+ // split it into N pieces and pass the last N-1 pieces to different
+ // workers. Otherwise, just fork |slices_to_download.size()| number of
+ // workers.
+ slices_to_download = FindSlicesForRemainingContent(
+ first_slice_offset,
+ content_length_ - first_slice_offset + initial_request_offset_,
+ GetParallelRequestCount(), GetMinSliceSize());
+ } else {
+ RecordParallelDownloadCreationEvent(
+ ParallelDownloadCreationEvent::FALLBACK_REASON_REMAINING_TIME);
+ }
}
DCHECK(!slices_to_download.empty());
« no previous file with comments | « content/browser/download/parallel_download_job.h ('k') | content/browser/download/parallel_download_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698