blob: 7be96910b20ab6efa93cac65a46379e43f0d95a0 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/download/download_request_handle.h"
#include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
namespace content {
DownloadRequestHandleInterface::~DownloadRequestHandleInterface() {}
DownloadRequestHandle::DownloadRequestHandle(
const DownloadRequestHandle& other) = default;
DownloadRequestHandle::~DownloadRequestHandle() {}
DownloadRequestHandle::DownloadRequestHandle() {}
DownloadRequestHandle::DownloadRequestHandle(
const base::WeakPtr<DownloadResourceHandler>& handler,
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter)
: handler_(handler), web_contents_getter_(web_contents_getter) {
DCHECK(handler_.get());
}
WebContents* DownloadRequestHandle::GetWebContents() const {
return web_contents_getter_.is_null() ? nullptr : web_contents_getter_.Run();
}
DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
WebContents* web_contents = GetWebContents();
if (web_contents == nullptr)
return nullptr;
BrowserContext* context = web_contents->GetBrowserContext();
if (context == nullptr)
return nullptr;
return BrowserContext::GetDownloadManager(context);
}
void DownloadRequestHandle::PauseRequest() const {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DownloadResourceHandler::PauseRequest, handler_));
}
void DownloadRequestHandle::ResumeRequest() const {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DownloadResourceHandler::ResumeRequest, handler_));
}
void DownloadRequestHandle::CancelRequest(bool user_cancel) const {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::BindOnce(&DownloadResourceHandler::CancelRequest, handler_));
}
} // namespace content