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

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

Issue 2750853004: Add a delay to send the parallel requests. (Closed)
Patch Set: Polish the condition check, 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_job.h" 5 #include "content/browser/download/parallel_download_job.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "content/browser/download/download_create_info.h" 8 #include "content/browser/download/download_create_info.h"
9 #include "content/browser/download/parallel_download_utils.h" 9 #include "content/browser/download/parallel_download_utils.h"
10 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/storage_partition.h" 11 #include "content/public/browser/storage_partition.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 ParallelDownloadJob::ParallelDownloadJob( 15 ParallelDownloadJob::ParallelDownloadJob(
16 DownloadItemImpl* download_item, 16 DownloadItemImpl* download_item,
17 std::unique_ptr<DownloadRequestHandleInterface> request_handle, 17 std::unique_ptr<DownloadRequestHandleInterface> request_handle,
18 const DownloadCreateInfo& create_info) 18 const DownloadCreateInfo& create_info)
19 : DownloadJobImpl(download_item, std::move(request_handle)), 19 : DownloadJobImpl(download_item, std::move(request_handle)),
20 initial_request_offset_(create_info.save_info->offset), 20 initial_request_offset_(create_info.save_info->offset),
21 initial_request_length_(create_info.save_info->length) {} 21 initial_request_length_(create_info.save_info->length) {}
22 22
23 ParallelDownloadJob::~ParallelDownloadJob() = default; 23 ParallelDownloadJob::~ParallelDownloadJob() = default;
24 24
25 void ParallelDownloadJob::Start() { 25 void ParallelDownloadJob::Start() {
26 DownloadJobImpl::Start(); 26 DownloadJobImpl::Start();
27 27
28 BuildParallelRequests(); 28 timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this,
29 &ParallelDownloadJob::BuildParallelRequests);
29 } 30 }
30 31
31 void ParallelDownloadJob::Cancel(bool user_cancel) { 32 void ParallelDownloadJob::Cancel(bool user_cancel) {
32 DownloadJobImpl::Cancel(user_cancel); 33 DownloadJobImpl::Cancel(user_cancel);
qinmin 2017/03/15 18:32:38 you need to stop the timer_ here
xingliu 2017/03/15 19:37:11 Discussed below.
David Trainor- moved to gerrit 2017/03/15 22:39:54 Nice catch Min!
xingliu 2017/03/15 23:43:57 Done.
33 for (auto& worker : workers_) 34 for (auto& worker : workers_)
34 worker->Cancel(); 35 worker->Cancel();
35 } 36 }
36 37
37 void ParallelDownloadJob::Pause() { 38 void ParallelDownloadJob::Pause() {
38 DownloadJobImpl::Pause(); 39 DownloadJobImpl::Pause();
qinmin 2017/03/15 18:32:38 need some book keeping here. If the timer is activ
xingliu 2017/03/15 19:37:11 Yeah, we need state control in this class. Can we
qinmin 2017/03/15 21:50:57 This is different from the request handle. You don
xingliu 2017/03/15 23:43:57 Makes sense, done. This is better.
39 for (auto& worker : workers_) 40 for (auto& worker : workers_)
40 worker->Pause(); 41 worker->Pause();
41 } 42 }
42 43
43 void ParallelDownloadJob::Resume(bool resume_request) { 44 void ParallelDownloadJob::Resume(bool resume_request) {
44 DownloadJobImpl::Resume(resume_request); 45 DownloadJobImpl::Resume(resume_request);
qinmin 2017/03/15 18:32:38 Need to start the timer again if it is paused prev
xingliu 2017/03/15 19:37:11 Shall we use requests handle to control the state,
qinmin 2017/03/15 21:50:57 The timer is a one-time thing before the requests
xingliu 2017/03/15 23:43:57 Done.
45 if (!resume_request) 46 if (!resume_request)
46 return; 47 return;
47 48
48 for (auto& worker : workers_) 49 for (auto& worker : workers_)
49 worker->Resume(); 50 worker->Resume();
50 } 51 }
51 52
52 void ParallelDownloadJob::ForkRequestsForNewDownload(int64_t bytes_received, 53 void ParallelDownloadJob::ForkRequestsForNewDownload(int64_t bytes_received,
53 int64_t total_bytes, 54 int64_t total_bytes,
54 int request_count) { 55 int request_count) {
(...skipping 14 matching lines...) Expand all
69 ? slice_size + (bytes_left % slice_size) 70 ? slice_size + (bytes_left % slice_size)
70 : slice_size; 71 : slice_size;
71 CreateRequest(current_offset, length); 72 CreateRequest(current_offset, length);
72 current_offset += slice_size; 73 current_offset += slice_size;
73 } 74 }
74 } 75 }
75 76
76 void ParallelDownloadJob::BuildParallelRequests() { 77 void ParallelDownloadJob::BuildParallelRequests() {
77 // Calculate the slices to download and fork parallel requests. 78 // Calculate the slices to download and fork parallel requests.
78 std::vector<DownloadItem::ReceivedSlice> slices_to_download = 79 std::vector<DownloadItem::ReceivedSlice> slices_to_download =
79 FindSlicesToDownload(download_item_->GetReceivedSlices()); 80 FindSlicesToDownload(download_item_->GetReceivedSlices());
qinmin 2017/03/15 19:09:00 There is also an issue here. The initial request m
xingliu 2017/03/15 19:37:11 This is probably OK, if DownloadFile is smart enou
80 // The initial request has already been sent, it should cover the first slice. 81 // The initial request has already been sent, it should cover the first slice.
81 DCHECK_GE(slices_to_download[0].offset, initial_request_offset_); 82 DCHECK_GE(slices_to_download[0].offset, initial_request_offset_);
82 DCHECK(initial_request_length_ == DownloadSaveInfo::kLengthFullContent || 83 DCHECK(initial_request_length_ == DownloadSaveInfo::kLengthFullContent ||
83 initial_request_offset_ + initial_request_length_ >= 84 initial_request_offset_ + initial_request_length_ >=
84 slices_to_download[0].offset + 85 slices_to_download[0].offset +
85 slices_to_download[0].received_bytes); 86 slices_to_download[0].received_bytes);
86 if (slices_to_download.size() >= 87 if (slices_to_download.size() >=
87 static_cast<size_t>(GetParallelRequestCountConfig())) { 88 static_cast<size_t>(GetParallelRequestCountConfig())) {
88 // The size of |slices_to_download| should be no larger than 89 // The size of |slices_to_download| should be no larger than
89 // |kParallelRequestCount| unless |kParallelRequestCount| is changed after 90 // |kParallelRequestCount| unless |kParallelRequestCount| is changed after
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // Subsequent range requests have the same referrer URL as the original 123 // Subsequent range requests have the same referrer URL as the original
123 // download request. 124 // download request.
124 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), 125 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(),
125 blink::WebReferrerPolicyAlways)); 126 blink::WebReferrerPolicyAlways));
126 // Send the request. 127 // Send the request.
127 worker->SendRequest(std::move(download_params)); 128 worker->SendRequest(std::move(download_params));
128 workers_.push_back(std::move(worker)); 129 workers_.push_back(std::move(worker));
129 } 130 }
130 131
131 } // namespace content 132 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/parallel_download_job.h ('k') | content/browser/download/parallel_download_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698