1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
// 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/stringprintf.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
using content::DownloadManager;
using content::RenderViewHostImpl;
using content::ResourceDispatcherHostImpl;
// IO Thread indirections to resource dispatcher host.
// Provided as targets for PostTask from within this object
// only.
static void DoPauseRequest(
int process_unique_id,
int request_id,
bool pause) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ResourceDispatcherHostImpl::Get()->PauseRequest(process_unique_id,
request_id,
pause);
}
static void DoCancelRequest(
int process_unique_id,
int request_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
ResourceDispatcherHostImpl::Get()->CancelRequest(process_unique_id,
request_id,
false);
}
DownloadRequestHandle::DownloadRequestHandle()
: child_id_(-1),
render_view_id_(-1),
request_id_(-1) {
}
DownloadRequestHandle::DownloadRequestHandle(int child_id,
int render_view_id,
int request_id)
: child_id_(child_id),
render_view_id_(render_view_id),
request_id_(request_id) {
// ResourceDispatcherHostImpl should not be null for non-default instances of
// DownloadRequestHandle.
DCHECK(ResourceDispatcherHostImpl::Get());
}
content::WebContents* DownloadRequestHandle::GetWebContents() const {
RenderViewHostImpl* render_view_host =
RenderViewHostImpl::FromID(child_id_, render_view_id_);
if (!render_view_host)
return NULL;
return render_view_host->GetDelegate()->GetAsWebContents();
}
DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
RenderViewHostImpl* rvh = RenderViewHostImpl::FromID(
child_id_, render_view_id_);
if (rvh == NULL)
return NULL;
content::RenderProcessHost* rph = rvh->GetProcess();
if (rph == NULL)
return NULL;
content::BrowserContext* context = rph->GetBrowserContext();
if (context == NULL)
return NULL;
return context->GetDownloadManager();
}
void DownloadRequestHandle::PauseRequest() const {
// The post is safe because ResourceDispatcherHostImpl is guaranteed
// to outlive the IO thread.
if (ResourceDispatcherHostImpl::Get()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&DoPauseRequest, child_id_, request_id_, true));
}
}
void DownloadRequestHandle::ResumeRequest() const {
// The post is safe because ResourceDispatcherHostImpl is guaranteed
// to outlive the IO thread.
if (ResourceDispatcherHostImpl::Get()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&DoPauseRequest, child_id_, request_id_, false));
}
}
void DownloadRequestHandle::CancelRequest() const {
// The post is safe because ResourceDispatcherHostImpl is guaranteed
// to outlive the IO thread.
if (ResourceDispatcherHostImpl::Get()) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&DoCancelRequest, child_id_, request_id_));
}
}
std::string DownloadRequestHandle::DebugString() const {
return base::StringPrintf("{"
" child_id = %d"
" render_view_id = %d"
" request_id = %d"
"}",
child_id_,
render_view_id_,
request_id_);
}
|