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

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

Issue 2728673003: Add a utility function to calculate the next slice to download (Closed)
Patch Set: Created 3 years, 10 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_utils.cc
diff --git a/content/browser/download/parallel_download_utils.cc b/content/browser/download/parallel_download_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1999e726c6c0f0ecdc80f8bae1d30c0a4442eea3
--- /dev/null
+++ b/content/browser/download/parallel_download_utils.cc
@@ -0,0 +1,33 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/download/parallel_download_utils.h"
+
+#include "content/public/browser/download_save_info.h"
+
+namespace content {
+
+DownloadItem::ReceivedSlice FindNextSliceToDownload(
+ const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
+ std::vector<DownloadItem::ReceivedSlice>::const_iterator iter =
+ received_slices.begin();
+ while (iter != received_slices.end()) {
+ int64_t offset = iter->offset + iter->received_bytes;
+ std::vector<DownloadItem::ReceivedSlice>::const_iterator next =
+ std::next(iter);
+ if (next == received_slices.end()) {
xingliu 2017/03/01 23:03:59 Is it possible that the vector only contains one e
qinmin 2017/03/01 23:25:28 hmm... good catch, this is actually possible. The
+ return DownloadItem::ReceivedSlice(offset,
+ DownloadSaveInfo::kLengthFullContent);
+ }
+
+ int64_t remaining_bytes = next->offset - offset;
+ DCHECK_LT(remaining_bytes, 0);
xingliu 2017/03/01 23:03:59 Maybe DCHECK_GE(remaining_bytes, 0) or DCHECK_GT()
qinmin 2017/03/01 23:25:28 Yes, this should be GE. Somehow I messed up the DC
qinmin 2017/03/01 23:41:16 well, merging the slices requires 2 updates to the
xingliu 2017/03/02 00:23:51 Agree, probably no need to merge. Also easier to d
+ if (remaining_bytes > 0)
+ return DownloadItem::ReceivedSlice(offset, remaining_bytes);
+ iter = next;
+ }
+ return DownloadItem::ReceivedSlice(0, DownloadSaveInfo::kLengthFullContent);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698