| Index: content/browser/download/download_resource_handler.cc
|
| diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc
|
| index 44d3652c42cd47dd3a43f92832ea957de900c3dc..8325b3d0915e724ac54bbeed873922acb01b81c0 100644
|
| --- a/content/browser/download/download_resource_handler.cc
|
| +++ b/content/browser/download/download_resource_handler.cc
|
| @@ -36,6 +36,20 @@ using content::DownloadItem;
|
| using content::DownloadManager;
|
| using content::ResourceRequestInfoImpl;
|
|
|
| +namespace {
|
| +
|
| +void CallStartedCBOnUIThread(
|
| + const DownloadResourceHandler::OnStartedCallback& started_cb,
|
| + DownloadId id,
|
| + net::Error error) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + if (started_cb.is_null())
|
| + return;
|
| + started_cb.Run(id, error);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| DownloadResourceHandler::DownloadResourceHandler(
|
| ResourceDispatcherHost* rdh,
|
| int render_process_host_id,
|
| @@ -161,10 +175,11 @@ bool DownloadResourceHandler::OnResponseStarted(
|
| }
|
|
|
| void DownloadResourceHandler::CallStartedCB(DownloadId id, net::Error error) {
|
| - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| if (started_cb_.is_null())
|
| return;
|
| - started_cb_.Run(id, error);
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI, FROM_HERE,
|
| + base::Bind(&CallStartedCBOnUIThread, started_cb_, id, error));
|
| started_cb_.Reset();
|
| }
|
|
|
| @@ -300,10 +315,7 @@ void DownloadResourceHandler::OnResponseCompletedInternal(
|
| download_stats::RecordAcceptsRanges(accept_ranges_, bytes_read_);
|
|
|
| // If the callback was already run on the UI thread, this will be a noop.
|
| - BrowserThread::PostTask(
|
| - BrowserThread::UI, FROM_HERE,
|
| - base::Bind(&DownloadResourceHandler::CallStartedCB, this,
|
| - download_id_, error_code));
|
| + CallStartedCB(download_id_, error_code);
|
|
|
| // We transfer ownership to |DownloadFileManager| to delete |buffer_|,
|
| // so that any functions queued up on the FILE thread are executed
|
| @@ -328,6 +340,7 @@ void DownloadResourceHandler::StartOnUIThread(
|
| if (!download_manager) {
|
| // NULL in unittests or if the page closed right after starting the
|
| // download.
|
| + CallStartedCB(download_id_, net::ERR_ACCESS_DENIED);
|
| return;
|
| }
|
| DownloadId download_id = download_manager->delegate()->GetNextId();
|
| @@ -383,6 +396,10 @@ void DownloadResourceHandler::CheckWriteProgress() {
|
| }
|
|
|
| DownloadResourceHandler::~DownloadResourceHandler() {
|
| + // This won't do anything if the callback was called before.
|
| + // If it goes through, it will likely be because OnWillStart() returned
|
| + // false somewhere in the chain of resource handlers.
|
| + CallStartedCB(download_id_, net::ERR_ACCESS_DENIED);
|
| }
|
|
|
| void DownloadResourceHandler::StartPauseTimer() {
|
| @@ -403,7 +420,9 @@ std::string DownloadResourceHandler::DebugString() const {
|
| " render_view_id_ = " "%d"
|
| " save_info_.file_path = \"%" PRFilePath "\""
|
| " }",
|
| - request_->url().spec().c_str(),
|
| + request_ ?
|
| + request_->url().spec().c_str() :
|
| + "<NULL request>",
|
| download_id_.local(),
|
| global_id_.child_id,
|
| global_id_.request_id,
|
|
|