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

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: addressing comments 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..5846e1eb8ee58005c561380ed9f0721364a483e1
--- /dev/null
+++ b/content/browser/download/parallel_download_utils.cc
@@ -0,0 +1,41 @@
+// 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) {
+ if (received_slices.empty())
+ return DownloadItem::ReceivedSlice(0, DownloadSaveInfo::kLengthFullContent);
+
+ std::vector<DownloadItem::ReceivedSlice>::const_iterator iter =
+ received_slices.begin();
+ DCHECK_GE(iter->offset, 0);
+ if (iter->offset != 0)
+ return DownloadItem::ReceivedSlice(0, iter->offset);
+
+ int64_t offset = 0;
+ int64_t remaining_bytes = DownloadSaveInfo::kLengthFullContent;
+ while (iter != received_slices.end()) {
+ offset = iter->offset + iter->received_bytes;
+ std::vector<DownloadItem::ReceivedSlice>::const_iterator next =
+ std::next(iter);
+ if (next == received_slices.end())
+ break;
+
+ DCHECK_GE(next->offset, offset);
+ if (next->offset > offset) {
+ remaining_bytes = next->offset - offset;
+ break;
+ }
+ iter = next;
+ }
+ return DownloadItem::ReceivedSlice(offset, remaining_bytes);
+}
+
+} // namespace content
« no previous file with comments | « content/browser/download/parallel_download_utils.h ('k') | content/browser/download/parallel_download_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698