| OLD | NEW |
| (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 |
| OLD | NEW |