Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: chrome/browser/download/download_request_handle.cc

Issue 7112011: Change DownloadProcessHandle to be more of an encapsulated class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed unneeded include file. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "chrome/browser/download/download_request_handle.h"
6
7 #include "base/stringprintf.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/tab_contents/tab_util.h"
10 #include "content/browser/browser_thread.h"
11 #include "content/browser/renderer_host/resource_dispatcher_host.h"
12 #include "content/browser/tab_contents/tab_contents.h"
13
14 // IO Thread indirections to resource dispatcher host.
15 // Provided as targets for PostTask from within this object
16 // only.
17 static void ResourceDispatcherHostPauseRequest(
18 ResourceDispatcherHost* rdh,
19 int process_unique_id,
20 int request_id,
21 bool pause)
22 {
Paweł Hajdan Jr. 2011/06/08 09:36:58 nit: Shouldn't that be on the previous line?
Randy Smith (Not in Mondays) 2011/06/09 13:17:43 Done.
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
24 rdh->PauseRequest(process_unique_id, request_id, pause);
25 }
26
27 static void ResourceDispatcherHostCancelRequest(
28 ResourceDispatcherHost* rdh,
29 int process_unique_id,
30 int request_id)
31 {
Paweł Hajdan Jr. 2011/06/08 09:36:58 nit: Shouldn't that be on the previous line?
Randy Smith (Not in Mondays) 2011/06/09 13:17:43 Done.
32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
33 rdh->CancelRequest(process_unique_id, request_id, false);
34 }
35
36 DownloadRequestHandle::DownloadRequestHandle()
37 : rdh_(NULL), child_id_(-1), render_view_id_(-1), request_id_(-1) {
Paweł Hajdan Jr. 2011/06/08 09:36:58 nit: I think each initializer should be on its own
Randy Smith (Not in Mondays) 2011/06/09 13:17:43 Done.
38 }
39
40 DownloadRequestHandle::DownloadRequestHandle(ResourceDispatcherHost* rdh,
41 int child_id,
42 int render_view_id,
43 int request_id)
44 : rdh_(rdh),
45 child_id_(child_id),
46 render_view_id_(render_view_id),
47 request_id_(request_id) {
48 DCHECK(rdh); // ResourceDispatcherHost may not be null in normal operation.
49 }
50
51 TabContents* DownloadRequestHandle::GetTabContents() const{
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
53 return tab_util::GetTabContentsByID(child_id_, render_view_id_);
54 }
55
56 DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
57 TabContents* contents = GetTabContents();
58 if (!contents)
59 return NULL;
60
61 Profile* profile = contents->profile();
62 if (!profile)
63 return NULL;
64
65 return profile->GetDownloadManager();
66 }
67
68 void DownloadRequestHandle::PauseRequest() {
69 DCHECK(!IsNull());
70
71 // The post is safe because ResourceDispatcherHost is guaranteed
72 // to outlive the IO thread.
73 if (!IsNop()) {
74 BrowserThread::PostTask(
75 BrowserThread::IO, FROM_HERE,
76 NewRunnableFunction(&ResourceDispatcherHostPauseRequest,
77 rdh_, child_id_, request_id_, true));
78 }
79 }
80
81 void DownloadRequestHandle::ResumeRequest() {
82 DCHECK(!IsNull());
83 // The post is safe because ResourceDispatcherHost is guaranteed
84 // to outlive the IO thread.
85 if (!IsNop()) {
86 BrowserThread::PostTask(
87 BrowserThread::IO, FROM_HERE,
88 NewRunnableFunction(&ResourceDispatcherHostPauseRequest,
89 rdh_, child_id_, request_id_, false));
90 }
91 }
92
93 void DownloadRequestHandle::CancelRequest() {
94 // The post is safe because ResourceDispatcherHost is guaranteed
95 // to outlive the IO thread.
96 if (rdh_) {
97 BrowserThread::PostTask(
98 BrowserThread::IO, FROM_HERE,
99 NewRunnableFunction(&ResourceDispatcherHostCancelRequest,
100 rdh_, child_id_, request_id_));
101 }
102 }
103
104 std::string DownloadRequestHandle::DebugString() const {
105 return base::StringPrintf("{"
106 " child_id = %d"
107 " render_view_id = %d"
108 " request_id = %d"
109 "}",
110 child_id_,
111 render_view_id_,
112 request_id_);
113 }
114
115 // static
116 DownloadRequestHandle DownloadRequestHandle::GetNopDownloadRequestHandle() {
117 DownloadRequestHandle result;
118 result.child_id_ = 0;
119 result.render_view_id_ = 0;
120 result.request_id_ = 0;
121 return result;
122 }
123
124 bool DownloadRequestHandle::IsNull() const {
Paweł Hajdan Jr. 2011/06/08 09:36:58 Ouch, I don't like this distinction between null a
Randy Smith (Not in Mondays) 2011/06/09 13:17:43 Went back to just making no RDH be a no-op, as dis
125 return (rdh_ == NULL && child_id_ == -1 &&
126 render_view_id_ == -1 && request_id_ == -1);
127 }
128
129 bool DownloadRequestHandle::IsNop() const {
130 return (rdh_ == NULL && child_id_ == 0 &&
131 render_view_id_ == 0 && request_id_ == 0);
132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698