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

Side by Side Diff: content/browser/download/parallel_download_utils.cc

Issue 2737033002: Update the received slices vector when stream is written to disk (Closed)
Patch Set: 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/download/parallel_download_utils.h" 5 #include "content/browser/download/parallel_download_utils.h"
6 6
7 #include "content/public/browser/download_save_info.h" 7 #include "content/public/browser/download_save_info.h"
8 8
9 namespace content { 9 namespace content {
10 10
11 namespace {
12
13 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs,
14 const DownloadItem::ReceivedSlice& rhs) {
15 return lhs.offset < rhs.offset;
16 }
17
18 } // namespace
19
11 DownloadItem::ReceivedSlice FindNextSliceToDownload( 20 DownloadItem::ReceivedSlice FindNextSliceToDownload(
12 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { 21 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
13 if (received_slices.empty()) 22 if (received_slices.empty())
14 return DownloadItem::ReceivedSlice(0, DownloadSaveInfo::kLengthFullContent); 23 return DownloadItem::ReceivedSlice(0, DownloadSaveInfo::kLengthFullContent);
15 24
16 std::vector<DownloadItem::ReceivedSlice>::const_iterator iter = 25 std::vector<DownloadItem::ReceivedSlice>::const_iterator iter =
17 received_slices.begin(); 26 received_slices.begin();
18 DCHECK_GE(iter->offset, 0); 27 DCHECK_GE(iter->offset, 0);
19 if (iter->offset != 0) 28 if (iter->offset != 0)
20 return DownloadItem::ReceivedSlice(0, iter->offset); 29 return DownloadItem::ReceivedSlice(0, iter->offset);
(...skipping 10 matching lines...) Expand all
31 DCHECK_GE(next->offset, offset); 40 DCHECK_GE(next->offset, offset);
32 if (next->offset > offset) { 41 if (next->offset > offset) {
33 remaining_bytes = next->offset - offset; 42 remaining_bytes = next->offset - offset;
34 break; 43 break;
35 } 44 }
36 iter = next; 45 iter = next;
37 } 46 }
38 return DownloadItem::ReceivedSlice(offset, remaining_bytes); 47 return DownloadItem::ReceivedSlice(offset, remaining_bytes);
39 } 48 }
40 49
50 int AddReceivedSliceToSortedArray(
51 const DownloadItem::ReceivedSlice& new_slice,
52 std::vector<DownloadItem::ReceivedSlice>& received_slices) {
53 std::vector<DownloadItem::ReceivedSlice>::iterator it =
54 std::upper_bound(received_slices.begin(), received_slices.end(),
55 new_slice, compareReceivedSlices);
56 it = received_slices.emplace(it, new_slice);
57 return std::distance(received_slices.begin(), it);
58 }
59
41 } // namespace content 60 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698