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

Side by Side 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, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/download/parallel_download_utils.h"
6
7 #include "content/public/browser/download_save_info.h"
8
9 namespace content {
10
11 DownloadItem::ReceivedSlice FindNextSliceToDownload(
12 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
13 if (received_slices.empty())
14 return DownloadItem::ReceivedSlice(0, DownloadSaveInfo::kLengthFullContent);
15
16 std::vector<DownloadItem::ReceivedSlice>::const_iterator iter =
17 received_slices.begin();
18 DCHECK_GE(iter->offset, 0);
19 if (iter->offset != 0)
20 return DownloadItem::ReceivedSlice(0, iter->offset);
21
22 int64_t offset = 0;
23 int64_t remaining_bytes = DownloadSaveInfo::kLengthFullContent;
24 while (iter != received_slices.end()) {
25 offset = iter->offset + iter->received_bytes;
26 std::vector<DownloadItem::ReceivedSlice>::const_iterator next =
27 std::next(iter);
28 if (next == received_slices.end())
29 break;
30
31 DCHECK_GE(next->offset, offset);
32 if (next->offset > offset) {
33 remaining_bytes = next->offset - offset;
34 break;
35 }
36 iter = next;
37 }
38 return DownloadItem::ReceivedSlice(offset, remaining_bytes);
39 }
40
41 } // namespace content
OLDNEW
« 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