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

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: merge a new slice with existing ones 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 "base/metrics/field_trial_params.h" 7 #include "base/metrics/field_trial_params.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "content/public/browser/download_save_info.h" 9 #include "content/public/browser/download_save_info.h"
10 #include "content/public/common/content_features.h" 10 #include "content/public/common/content_features.h"
(...skipping 10 matching lines...) Expand all
21 const int64_t kMinSliceSizeParallelDownload = 2097152; 21 const int64_t kMinSliceSizeParallelDownload = 2097152;
22 22
23 // Finch parameter key value for number of parallel requests in a parallel 23 // Finch parameter key value for number of parallel requests in a parallel
24 // download, including the original request. 24 // download, including the original request.
25 const char kParallelRequestCountFinchKey[] = "request_count"; 25 const char kParallelRequestCountFinchKey[] = "request_count";
26 26
27 // Default value for |kParallelRequestCountFinchKey|, when no parameter is 27 // Default value for |kParallelRequestCountFinchKey|, when no parameter is
28 // specified. 28 // specified.
29 const int kParallelRequestCount = 2; 29 const int kParallelRequestCount = 2;
30 30
31 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs,
32 const DownloadItem::ReceivedSlice& rhs) {
33 return lhs.offset < rhs.offset;
34 }
35
31 } // namespace 36 } // namespace
32 37
33 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload( 38 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload(
34 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { 39 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
35 std::vector<DownloadItem::ReceivedSlice> result; 40 std::vector<DownloadItem::ReceivedSlice> result;
36 if (received_slices.empty()) { 41 if (received_slices.empty()) {
37 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent); 42 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent);
38 return result; 43 return result;
39 } 44 }
40 45
(...skipping 13 matching lines...) Expand all
54 } 59 }
55 60
56 DCHECK_GE(next->offset, offset); 61 DCHECK_GE(next->offset, offset);
57 if (next->offset > offset) 62 if (next->offset > offset)
58 result.emplace_back(offset, next->offset - offset); 63 result.emplace_back(offset, next->offset - offset);
59 iter = next; 64 iter = next;
60 } 65 }
61 return result; 66 return result;
62 } 67 }
63 68
69 size_t AddOrMergeReceivedSliceIntoSortedArray(
70 const DownloadItem::ReceivedSlice& new_slice,
71 std::vector<DownloadItem::ReceivedSlice>& received_slices) {
72 std::vector<DownloadItem::ReceivedSlice>::iterator it =
73 std::upper_bound(received_slices.begin(), received_slices.end(),
74 new_slice, compareReceivedSlices);
75 if (it != received_slices.begin()) {
76 std::vector<DownloadItem::ReceivedSlice>::iterator prev = std::prev(it);
77 if (prev->offset + prev->received_bytes == new_slice.offset) {
xingliu 2017/03/09 01:33:53 Do we merge when (prev->offset + prev->received_by
qinmin 2017/03/09 05:43:53 No. That shouldn't happen. If that happens, there
xingliu 2017/03/09 05:46:07 sgtm.
78 prev->received_bytes += new_slice.received_bytes;
79 return static_cast<size_t>(std::distance(received_slices.begin(), prev));
80 }
81 }
82
83 it = received_slices.emplace(it, new_slice);
84 return static_cast<size_t>(std::distance(received_slices.begin(), it));
85 }
86
64 int64_t GetMinSliceSizeConfig() { 87 int64_t GetMinSliceSizeConfig() {
65 std::string finch_value = base::GetFieldTrialParamValueByFeature( 88 std::string finch_value = base::GetFieldTrialParamValueByFeature(
66 features::kParallelDownloading, kMinSliceSizeFinchKey); 89 features::kParallelDownloading, kMinSliceSizeFinchKey);
67 int64_t result; 90 int64_t result;
68 return !finch_value.empty() && base::StringToInt64(finch_value, &result) 91 return !finch_value.empty() && base::StringToInt64(finch_value, &result)
69 ? result 92 ? result
70 : kMinSliceSizeParallelDownload; 93 : kMinSliceSizeParallelDownload;
71 } 94 }
72 95
73 int GetParallelRequestCountConfig() { 96 int GetParallelRequestCountConfig() {
74 std::string finch_value = base::GetFieldTrialParamValueByFeature( 97 std::string finch_value = base::GetFieldTrialParamValueByFeature(
75 features::kParallelDownloading, kParallelRequestCountFinchKey); 98 features::kParallelDownloading, kParallelRequestCountFinchKey);
76 int result; 99 int result;
77 return !finch_value.empty() && base::StringToInt(finch_value, &result) 100 return !finch_value.empty() && base::StringToInt(finch_value, &result)
78 ? result 101 ? result
79 : kParallelRequestCount; 102 : kParallelRequestCount;
80 } 103 }
81 104
82 } // namespace content 105 } // 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