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

Issue 2811293004: Fix an issue that we didn't clean url request properly. (Closed)

Created:
3 years, 8 months ago by xingliu
Modified:
3 years, 8 months ago
CC:
chromium-reviews, jam, David Trainor- moved to gerrit, darin-cc_chromium.org
Target Ref:
refs/heads/master
Project:
chromium
Visibility:
Public.

Description

Fix an issue that we didn't clean url request properly. The ByteStreamReader we used in DownloadFile does not support Close() api, so we need to close the url request on UI thread if "ByteStreamReader::Close" should be called. Before we implement parallel download, we null out the callback on ByteStreamReader during download interruption, and on UI thread, we cancel the url request. But for parallel download, at some point, we won't interrupt the download but need to cancel a particular request. There is another CL that implements a browser test for parallel download and it will test the code here. https://codereview.chromium.org/2819483002/ BUG=710576, 644352 Review-Url: https://codereview.chromium.org/2811293004 Cr-Commit-Position: refs/heads/master@{#465289} Committed: https://chromium.googlesource.com/chromium/src/+/b444a98187571cf9ec627ac52fee7e81ffcecb93

Patch Set 1 #

Patch Set 2 : Fixed compiling for unit tests. #

Total comments: 6

Patch Set 3 : Work on feedback. #

Total comments: 4

Patch Set 4 : Polish on details. #

Patch Set 5 : Clean rebase. #

Patch Set 6 : Fix the tests. #

Patch Set 7 : Removed a DCHECK for unit test. #

Total comments: 11
Unified diffs Side-by-side diffs Delta from patch set Stats (+94 lines, -31 lines) Patch
M content/browser/download/download_browsertest.cc View 1 2 3 4 5 1 chunk +3 lines, -1 line 0 comments Download
M content/browser/download/download_file.h View 1 2 3 1 chunk +7 lines, -2 lines 0 comments Download
M content/browser/download/download_file_impl.h View 1 2 4 chunks +9 lines, -2 lines 0 comments Download
M content/browser/download/download_file_impl.cc View 1 2 3 4 5 6 7 chunks +19 lines, -5 lines 2 comments Download
M content/browser/download/download_file_unittest.cc View 1 2 3 4 5 1 chunk +1 line, -1 line 0 comments Download
M content/browser/download/download_item_impl.h View 1 2 1 chunk +3 lines, -0 lines 0 comments Download
M content/browser/download/download_item_impl.cc View 1 2 3 4 2 chunks +8 lines, -0 lines 2 comments Download
M content/browser/download/download_item_impl_unittest.cc View 1 2 3 4 5 7 chunks +7 lines, -7 lines 0 comments Download
M content/browser/download/download_job.h View 1 2 1 chunk +4 lines, -0 lines 0 comments Download
M content/browser/download/download_job.cc View 1 2 1 chunk +2 lines, -0 lines 2 comments Download
M content/browser/download/mock_download_file.h View 1 2 3 4 5 1 chunk +2 lines, -1 line 0 comments Download
M content/browser/download/mock_download_file.cc View 1 2 3 4 5 2 chunks +7 lines, -4 lines 0 comments Download
M content/browser/download/parallel_download_job.h View 1 2 1 chunk +1 line, -0 lines 0 comments Download
M content/browser/download/parallel_download_job.cc View 1 2 3 1 chunk +11 lines, -0 lines 5 comments Download
M content/public/test/test_file_error_injector.cc View 1 2 3 4 5 3 chunks +10 lines, -8 lines 0 comments Download

Messages

Total messages: 38 (24 generated)
xingliu
Hi, PTAL, thanks.
3 years, 8 months ago (2017-04-13 03:52:19 UTC) #6
qinmin
Overall looks ok. But just one question, will it be better to a callback to ...
3 years, 8 months ago (2017-04-14 20:04:44 UTC) #13
xingliu
On 2017/04/14 20:04:44, qinmin wrote: > Overall looks ok. > But just one question, will ...
3 years, 8 months ago (2017-04-14 21:31:02 UTC) #14
xingliu
Thanks for the review. For this issue, the long term solution is probably to implement ...
3 years, 8 months ago (2017-04-15 00:26:30 UTC) #15
qinmin
lgtm % comments https://codereview.chromium.org/2811293004/diff/40001/content/browser/download/download_file.h File content/browser/download/download_file.h (right): https://codereview.chromium.org/2811293004/diff/40001/content/browser/download/download_file.h#newcode51 content/browser/download/download_file.h:51: // Upon completion, |callback| will be ...
3 years, 8 months ago (2017-04-17 21:39:59 UTC) #16
xingliu
Thanks for the review. Polished on details. https://codereview.chromium.org/2811293004/diff/40001/content/browser/download/download_file.h File content/browser/download/download_file.h (right): https://codereview.chromium.org/2811293004/diff/40001/content/browser/download/download_file.h#newcode51 content/browser/download/download_file.h:51: // Upon ...
3 years, 8 months ago (2017-04-17 23:41:51 UTC) #17
xingliu
alexmos@chromium.org: Could you help to take a look at the change in this file? content/public/test/test_file_error_injector.cc
3 years, 8 months ago (2017-04-18 01:13:11 UTC) #21
alexmos
On 2017/04/18 01:13:11, xingliu wrote: > mailto:alexmos@chromium.org: Could you help to take a look at ...
3 years, 8 months ago (2017-04-18 16:49:06 UTC) #28
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2811293004/120001
3 years, 8 months ago (2017-04-18 18:04:09 UTC) #31
commit-bot: I haz the power
Committed patchset #7 (id:120001) as https://chromium.googlesource.com/chromium/src/+/b444a98187571cf9ec627ac52fee7e81ffcecb93
3 years, 8 months ago (2017-04-18 18:10:03 UTC) #34
asanka
https://codereview.chromium.org/2811293004/diff/120001/content/browser/download/download_file_impl.cc File content/browser/download/download_file_impl.cc (right): https://codereview.chromium.org/2811293004/diff/120001/content/browser/download/download_file_impl.cc#newcode690 content/browser/download/download_file_impl.cc:690: void DownloadFileImpl::CancelRequestOnUIThread(int64_t offset) { Nit : The naming convention ...
3 years, 8 months ago (2017-04-21 15:09:28 UTC) #35
xingliu
On 2017/04/21 15:09:28, asanka wrote: > https://codereview.chromium.org/2811293004/diff/120001/content/browser/download/download_file_impl.cc > File content/browser/download/download_file_impl.cc (right): > > https://codereview.chromium.org/2811293004/diff/120001/content/browser/download/download_file_impl.cc#newcode690 > ...
3 years, 8 months ago (2017-04-21 16:59:20 UTC) #36
xingliu
https://codereview.chromium.org/2811293004/diff/120001/content/browser/download/parallel_download_job.cc File content/browser/download/parallel_download_job.cc (right): https://codereview.chromium.org/2811293004/diff/120001/content/browser/download/parallel_download_job.cc#newcode102 content/browser/download/parallel_download_job.cc:102: DownloadJobImpl::Cancel(false); On 2017/04/21 15:09:28, asanka wrote: > I guess ...
3 years, 8 months ago (2017-04-21 18:07:00 UTC) #37
xingliu
3 years, 8 months ago (2017-04-22 00:07:24 UTC) #38
Message was sent while issue was closed.
Thanks for the feedback.

Please refer to 
https://codereview.chromium.org/2829853011/#
for change.

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
File content/browser/download/download_file_impl.cc (right):

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
content/browser/download/download_file_impl.cc:690: void
DownloadFileImpl::CancelRequestOnUIThread(int64_t offset) {
On 2017/04/21 15:09:28, asanka wrote:
> Nit : The naming convention is to name the function based on which thread it
> runs on if it differs from surrounding code. In this case the function runs on
> the IO thread. That reduces the chance of accidentally calling a function that
> needs to be scheduled on a different thread.
> 
> In this case, you could just call this CancelRequest() since it shares the
> thread affinity with the surrounding code.

Done. Thanks.

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
File content/browser/download/download_item_impl.cc (right):

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
content/browser/download/download_item_impl.cc:1067:
job_->CancelRequestWithOffset(offset);
On 2017/04/21 15:09:28, asanka wrote:
> It is possible that this will cancel the only request, correct? In which case
> the download should be canceled?
> 
> I ask because I don't see any tests that exercise that possibility. The
control
> paths that are affected are quite convoluted and currently in flux. There
should
> be tests for these cases or there's a pretty good chance that things will
break.

If this call cancelled the only request, the download file should inform the
download item interruption or completion right after that.

It's not expected to cancel the download with this function in any case, but to
clean up a particular request, since the way we null out the ByteStreamReader in
DownloadFileImpl does not actually close the url request.

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
File content/browser/download/download_job.cc (right):

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
content/browser/download/download_job.cc:69: void
DownloadJob::CancelRequestWithOffset(int64_t offset) {}
On 2017/04/21 15:09:28, asanka wrote:
> Nit: Add a NOTREACHED()

Done.

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
File content/browser/download/parallel_download_job.cc (right):

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
content/browser/download/parallel_download_job.cc:102:
DownloadJobImpl::Cancel(false);
On 2017/04/21 18:07:00, xingliu wrote:
> On 2017/04/21 15:09:28, asanka wrote:
> > I guess the expectation is that this will go through the DownloadJobImpl ->
> > DownloadResourceHandle -> ResourceDispatcherHost -> ResourceLoader ->
> > net::URLRequest -> ResourceLoader -> DownloadResourceHandler ->
> > DownloadRequestCore -> DownloadFileImpl -> DownloadItemImpl and cancel the
> > download? Can you add a test for this case because that's a pretty big chunk
> of
> > code with a good chance of breaking. I don't know if this even works for
> > anything other than http/s.
> 
> ParallelDownloadComplete browser test covers this flow. Will add more unit
tests
> in later CL.
> 
> 
> The flow is used when we need to close the ByteStream in DownloadFileImpl, so
> the beginning point of the flow is actually DownloadFileImpl.
> 
> After we refactor the download file to be owned by DownloadJob, this function
> will be removed.
> 
> One question about the non http cases, do we mean quic here? or other protocol
> also supported in UrlRequest like ftp?

The flow is DownloadFileImpl ==> DownloadItemImpl ==> DownloadJob ==> close a
particular connection.

https://codereview.chromium.org/2811293004/diff/120001/content/browser/downlo...
content/browser/download/parallel_download_job.cc:108: it->second->Cancel();
On 2017/04/21 15:09:28, asanka wrote:
> Is there a reason to consider the |it == workers_.end()| as a valid outcome
> here? It looks like workers are added to workers_, but never removed.

Done, added a DCHECK.

In the long term, after the job owns the download file, job's life cycle may be
changed to be the similar to download file.

Powered by Google App Engine
This is Rietveld 408576698