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

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

Issue 2767593003: Handle early pause, cancel for parallel requests. (Closed)
Patch Set: Work on feedback. 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/download_worker.h" 5 #include "content/browser/download/download_worker.h"
6 6
7 #include "content/browser/download/download_create_info.h" 7 #include "content/browser/download/download_create_info.h"
8 #include "content/public/browser/download_interrupt_reasons.h" 8 #include "content/public/browser/download_interrupt_reasons.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 request_handle_->CancelRequest(); 70 request_handle_->CancelRequest();
71 } 71 }
72 72
73 void DownloadWorker::OnUrlDownloaderStarted( 73 void DownloadWorker::OnUrlDownloaderStarted(
74 std::unique_ptr<DownloadCreateInfo> create_info, 74 std::unique_ptr<DownloadCreateInfo> create_info,
75 std::unique_ptr<ByteStreamReader> stream_reader, 75 std::unique_ptr<ByteStreamReader> stream_reader,
76 const DownloadUrlParameters::OnStartedCallback& callback) { 76 const DownloadUrlParameters::OnStartedCallback& callback) {
77 // |callback| is not used in subsequent requests. 77 // |callback| is not used in subsequent requests.
78 DCHECK(callback.is_null()); 78 DCHECK(callback.is_null());
79 79
80 // Destroy the request if user canceled.
81 if (delegate_->IsCanceled()) {
82 VLOG(kVerboseLevel) << "Byte stream arrived after user cancel the request.";
83 create_info->request_handle->CancelRequest();
84 return;
85 }
86
80 // TODO(xingliu): Add the interrupt reason and metric data for precondition 87 // TODO(xingliu): Add the interrupt reason and metric data for precondition
81 // failure. Make DownloadRequestCore know if it should return error if the 88 // failure. Make DownloadRequestCore know if it should return error if the
82 // the server gives a different part of the content, e.g. "If-Match" return 89 // the server gives a different part of the content, e.g. "If-Match" return
83 // http 200. 90 // http 200.
84 if (create_info->result != 91 if (create_info->result !=
85 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) { 92 DownloadInterruptReason::DOWNLOAD_INTERRUPT_REASON_NONE) {
86 VLOG(kVerboseLevel) << "Parallel download sub-request failed. reason = " 93 VLOG(kVerboseLevel) << "Parallel download sub-request failed. reason = "
87 << create_info->result; 94 << create_info->result;
88 delegate_->OnServerResponseError(this, create_info->result); 95 delegate_->OnServerResponseError(this, create_info->result);
89 return; 96 return;
90 } 97 }
91 98
92 request_handle_ = std::move(create_info->request_handle); 99 request_handle_ = std::move(create_info->request_handle);
93 if (delegate_) 100
94 delegate_->OnByteStreamReady(this, std::move(stream_reader)); 101 // Pause the stream if user paused, still push the stream reader to the sink.
102 if (delegate_->IsPaused()) {
103 VLOG(kVerboseLevel) << "Byte stream arrived after user pause the request.";
104 Pause();
105 }
106
107 delegate_->OnByteStreamReady(this, std::move(stream_reader));
95 } 108 }
96 109
97 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) { 110 void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) {
98 // Release the |url_downloader_|, the object will be deleted on IO thread. 111 // Release the |url_downloader_|, the object will be deleted on IO thread.
99 url_downloader_.reset(); 112 url_downloader_.reset();
100 } 113 }
101 114
102 void DownloadWorker::AddUrlDownloader( 115 void DownloadWorker::AddUrlDownloader(
103 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread> 116 std::unique_ptr<UrlDownloader, BrowserThread::DeleteOnIOThread>
104 downloader) { 117 downloader) {
105 url_downloader_ = std::move(downloader); 118 url_downloader_ = std::move(downloader);
106 } 119 }
107 120
108 } // namespace content 121 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698