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

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: nit 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 // TODO(qinmin): replace this with a comparator operator in
32 // DownloadItem::ReceivedSlice.
33 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs,
34 const DownloadItem::ReceivedSlice& rhs) {
35 return lhs.offset < rhs.offset;
36 }
37
31 } // namespace 38 } // namespace
32 39
33 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload( 40 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload(
34 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { 41 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
35 std::vector<DownloadItem::ReceivedSlice> result; 42 std::vector<DownloadItem::ReceivedSlice> result;
36 if (received_slices.empty()) { 43 if (received_slices.empty()) {
37 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent); 44 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent);
38 return result; 45 return result;
39 } 46 }
40 47
(...skipping 13 matching lines...) Expand all
54 } 61 }
55 62
56 DCHECK_GE(next->offset, offset); 63 DCHECK_GE(next->offset, offset);
57 if (next->offset > offset) 64 if (next->offset > offset)
58 result.emplace_back(offset, next->offset - offset); 65 result.emplace_back(offset, next->offset - offset);
59 iter = next; 66 iter = next;
60 } 67 }
61 return result; 68 return result;
62 } 69 }
63 70
71 size_t AddOrMergeReceivedSliceIntoSortedArray(
72 const DownloadItem::ReceivedSlice& new_slice,
73 std::vector<DownloadItem::ReceivedSlice>& received_slices) {
74 std::vector<DownloadItem::ReceivedSlice>::iterator it =
75 std::upper_bound(received_slices.begin(), received_slices.end(),
76 new_slice, compareReceivedSlices);
77 if (it != received_slices.begin()) {
78 std::vector<DownloadItem::ReceivedSlice>::iterator prev = std::prev(it);
79 if (prev->offset + prev->received_bytes == new_slice.offset) {
80 prev->received_bytes += new_slice.received_bytes;
81 return static_cast<size_t>(std::distance(received_slices.begin(), prev));
82 }
83 }
84
85 it = received_slices.emplace(it, new_slice);
86 return static_cast<size_t>(std::distance(received_slices.begin(), it));
87 }
88
64 int64_t GetMinSliceSizeConfig() { 89 int64_t GetMinSliceSizeConfig() {
65 std::string finch_value = base::GetFieldTrialParamValueByFeature( 90 std::string finch_value = base::GetFieldTrialParamValueByFeature(
66 features::kParallelDownloading, kMinSliceSizeFinchKey); 91 features::kParallelDownloading, kMinSliceSizeFinchKey);
67 int64_t result; 92 int64_t result;
68 return !finch_value.empty() && base::StringToInt64(finch_value, &result) 93 return !finch_value.empty() && base::StringToInt64(finch_value, &result)
69 ? result 94 ? result
70 : kMinSliceSizeParallelDownload; 95 : kMinSliceSizeParallelDownload;
71 } 96 }
72 97
73 int GetParallelRequestCountConfig() { 98 int GetParallelRequestCountConfig() {
74 std::string finch_value = base::GetFieldTrialParamValueByFeature( 99 std::string finch_value = base::GetFieldTrialParamValueByFeature(
75 features::kParallelDownloading, kParallelRequestCountFinchKey); 100 features::kParallelDownloading, kParallelRequestCountFinchKey);
76 int result; 101 int result;
77 return !finch_value.empty() && base::StringToInt(finch_value, &result) 102 return !finch_value.empty() && base::StringToInt(finch_value, &result)
78 ? result 103 ? result
79 : kParallelRequestCount; 104 : kParallelRequestCount;
80 } 105 }
81 106
82 } // namespace content 107 } // 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