1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/download/download_request_handle.h"
8 #include "base/strings/stringprintf.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h"
16 DownloadRequestHandle::~DownloadRequestHandle() {
19 DownloadRequestHandle::DownloadRequestHandle()
25 DownloadRequestHandle::DownloadRequestHandle(
26 const base::WeakPtr
<DownloadResourceHandler
>& handler
,
32 render_view_id_(render_view_id
),
33 request_id_(request_id
) {
34 DCHECK(handler_
.get());
37 WebContents
* DownloadRequestHandle::GetWebContents() const {
38 RenderViewHostImpl
* render_view_host
=
39 RenderViewHostImpl::FromID(child_id_
, render_view_id_
);
40 if (!render_view_host
)
43 return render_view_host
->GetDelegate()->GetAsWebContents();
46 DownloadManager
* DownloadRequestHandle::GetDownloadManager() const {
47 RenderViewHostImpl
* rvh
= RenderViewHostImpl::FromID(
48 child_id_
, render_view_id_
);
51 RenderProcessHost
* rph
= rvh
->GetProcess();
54 BrowserContext
* context
= rph
->GetBrowserContext();
57 return BrowserContext::GetDownloadManager(context
);
60 void DownloadRequestHandle::PauseRequest() const {
61 BrowserThread::PostTask(
62 BrowserThread::IO
, FROM_HERE
,
63 base::Bind(&DownloadResourceHandler::PauseRequest
, handler_
));
66 void DownloadRequestHandle::ResumeRequest() const {
67 BrowserThread::PostTask(
68 BrowserThread::IO
, FROM_HERE
,
69 base::Bind(&DownloadResourceHandler::ResumeRequest
, handler_
));
72 void DownloadRequestHandle::CancelRequest() const {
73 BrowserThread::PostTask(
74 BrowserThread::IO
, FROM_HERE
,
75 base::Bind(&DownloadResourceHandler::CancelRequest
, handler_
));
78 std::string
DownloadRequestHandle::DebugString() const {
79 return base::StringPrintf("{"
81 " render_view_id = %d"
89 } // namespace content