Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/download/download_process_handle.h" | 5 #include "chrome/browser/download/download_process_handle.h" |
| 6 | 6 |
| 7 #include "base/stringprintf.h" | |
| 7 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/tab_contents/tab_util.h" | 9 #include "chrome/browser/tab_contents/tab_util.h" |
| 9 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| 11 #include "content/browser/renderer_host/resource_dispatcher_host.h" | |
| 10 #include "content/browser/tab_contents/tab_contents.h" | 12 #include "content/browser/tab_contents/tab_contents.h" |
| 11 | 13 |
| 12 DownloadProcessHandle::DownloadProcessHandle() | 14 DownloadProcessHandle::DownloadProcessHandle() |
| 13 : child_id_(-1), render_view_id_(-1), request_id_(-1) { | 15 : child_id_(-1), render_view_id_(-1), request_id_(-1) { |
| 14 } | 16 } |
| 15 | 17 |
| 16 DownloadProcessHandle::DownloadProcessHandle(int child_id, | 18 DownloadProcessHandle::DownloadProcessHandle(ResourceDispatcherHost* rdh, |
| 19 int child_id, | |
| 17 int render_view_id, | 20 int render_view_id, |
| 18 int request_id) | 21 int request_id) |
| 19 : child_id_(child_id), | 22 : rdh_(rdh), |
| 23 child_id_(child_id), | |
| 20 render_view_id_(render_view_id), | 24 render_view_id_(render_view_id), |
| 21 request_id_(request_id) { | 25 request_id_(request_id) { |
| 22 } | 26 } |
| 23 | 27 |
| 24 TabContents* DownloadProcessHandle::GetTabContents() { | 28 TabContents* DownloadProcessHandle::GetTabContents() { |
| 25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 26 return tab_util::GetTabContentsByID(child_id_, render_view_id_); | 30 return tab_util::GetTabContentsByID(child_id_, render_view_id_); |
| 27 } | 31 } |
| 28 | 32 |
| 29 DownloadManager* DownloadProcessHandle::GetDownloadManager() { | 33 DownloadManager* DownloadProcessHandle::GetDownloadManager() { |
| 30 TabContents* contents = GetTabContents(); | 34 TabContents* contents = GetTabContents(); |
| 31 if (!contents) | 35 if (!contents) |
| 32 return NULL; | 36 return NULL; |
| 33 | 37 |
| 34 Profile* profile = contents->profile(); | 38 Profile* profile = contents->profile(); |
| 35 if (!profile) | 39 if (!profile) |
| 36 return NULL; | 40 return NULL; |
| 37 | 41 |
| 38 return profile->GetDownloadManager(); | 42 return profile->GetDownloadManager(); |
| 39 } | 43 } |
| 44 | |
| 45 void DownloadProcessHandle::PauseRequest(bool pause) { | |
| 46 if (rdh_) { | |
| 47 BrowserThread::PostTask( | |
| 48 BrowserThread::IO, FROM_HERE, | |
| 49 NewRunnableFunction(&DownloadProcessHandle::RDHPauseRequest, | |
| 50 rdh_, child_id_, request_id_, pause)); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void DownloadProcessHandle::CancelRequest() { | |
| 55 if (rdh_) | |
|
Paweł Hajdan Jr.
2011/06/04 08:58:51
nit: Please use braces {} for multi-line "if" body
Randy Smith (Not in Mondays)
2011/06/07 22:41:11
Done.
| |
| 56 BrowserThread::PostTask( | |
| 57 BrowserThread::IO, FROM_HERE, | |
| 58 NewRunnableFunction(&DownloadProcessHandle::RDHCancelRequest, | |
| 59 rdh_, child_id_, request_id_)); | |
| 60 } | |
| 61 | |
| 62 // Static | |
| 63 void DownloadProcessHandle::RDHPauseRequest( | |
|
Paweł Hajdan Jr.
2011/06/04 08:58:51
Why are those methods declared as static members o
Randy Smith (Not in Mondays)
2011/06/07 22:41:11
D'oh! Quite right, much cleaner.
| |
| 64 ResourceDispatcherHost* rdh, | |
| 65 int process_unique_id, | |
| 66 int request_id, | |
| 67 bool pause) | |
| 68 { | |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 70 rdh->PauseRequest(process_unique_id, request_id, pause); | |
| 71 } | |
| 72 | |
| 73 // Static | |
| 74 void DownloadProcessHandle::RDHCancelRequest( | |
| 75 ResourceDispatcherHost* rdh, | |
| 76 int process_unique_id, | |
| 77 int request_id) | |
| 78 { | |
| 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 80 rdh->CancelRequest(process_unique_id, request_id, false); | |
| 81 } | |
| 82 | |
| 83 std::string DownloadProcessHandle::DebugString() const { | |
| 84 return base::StringPrintf("{" | |
| 85 " child_id = %d" | |
| 86 " render_view_id = %d" | |
| 87 " request_id = %d" | |
| 88 "}", | |
| 89 child_id_, | |
| 90 render_view_id_, | |
| 91 request_id_); | |
| 92 } | |
| OLD | NEW |