Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / download / download_request_handle.cc
blob32c5b987799d510d79fb6e12c4327784498fdd86
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"
7 #include "base/bind.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"
14 namespace content {
16 DownloadRequestHandle::~DownloadRequestHandle() {
19 DownloadRequestHandle::DownloadRequestHandle()
20 : child_id_(-1),
21 render_view_id_(-1),
22 request_id_(-1) {
25 DownloadRequestHandle::DownloadRequestHandle(
26 const base::WeakPtr<DownloadResourceHandler>& handler,
27 int child_id,
28 int render_view_id,
29 int request_id)
30 : handler_(handler),
31 child_id_(child_id),
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)
41 return NULL;
43 return render_view_host->GetDelegate()->GetAsWebContents();
46 DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
47 RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(
48 child_id_, render_view_id_);
49 if (rvh == NULL)
50 return NULL;
51 RenderProcessHost* rph = rvh->GetProcess();
52 if (rph == NULL)
53 return NULL;
54 BrowserContext* context = rph->GetBrowserContext();
55 if (context == NULL)
56 return NULL;
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("{"
80 " child_id = %d"
81 " render_view_id = %d"
82 " request_id = %d"
83 "}",
84 child_id_,
85 render_view_id_,
86 request_id_);
89 } // namespace content