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

Unified Diff: chrome/browser/download/download_process_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: Get rid of cancel code in download_util. Created 9 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/download_process_handle.cc
diff --git a/chrome/browser/download/download_process_handle.cc b/chrome/browser/download/download_process_handle.cc
index f4c7f321ddda56d2205eceee447831c98efcbbde..cbc6f890f0ae0ea9d2d6128fa74a52bd3b67ff90 100644
--- a/chrome/browser/download/download_process_handle.cc
+++ b/chrome/browser/download/download_process_handle.cc
@@ -4,19 +4,23 @@
#include "chrome/browser/download/download_process_handle.h"
+#include "base/stringprintf.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "content/browser/browser_thread.h"
+#include "content/browser/renderer_host/resource_dispatcher_host.h"
#include "content/browser/tab_contents/tab_contents.h"
DownloadProcessHandle::DownloadProcessHandle()
: child_id_(-1), render_view_id_(-1), request_id_(-1) {
}
-DownloadProcessHandle::DownloadProcessHandle(int child_id,
+DownloadProcessHandle::DownloadProcessHandle(ResourceDispatcherHost* rdh,
+ int child_id,
int render_view_id,
int request_id)
- : child_id_(child_id),
+ : rdh_(rdh),
+ child_id_(child_id),
render_view_id_(render_view_id),
request_id_(request_id) {
}
@@ -37,3 +41,52 @@ DownloadManager* DownloadProcessHandle::GetDownloadManager() {
return profile->GetDownloadManager();
}
+
+void DownloadProcessHandle::PauseRequest(bool pause) {
+ if (rdh_) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(&DownloadProcessHandle::RDHPauseRequest,
+ rdh_, child_id_, request_id_, pause));
+ }
+}
+
+void DownloadProcessHandle::CancelRequest() {
+ 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.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(&DownloadProcessHandle::RDHCancelRequest,
+ rdh_, child_id_, request_id_));
+}
+
+// Static
+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.
+ ResourceDispatcherHost* rdh,
+ int process_unique_id,
+ int request_id,
+ bool pause)
+{
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ rdh->PauseRequest(process_unique_id, request_id, pause);
+}
+
+// Static
+void DownloadProcessHandle::RDHCancelRequest(
+ ResourceDispatcherHost* rdh,
+ int process_unique_id,
+ int request_id)
+{
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ rdh->CancelRequest(process_unique_id, request_id, false);
+}
+
+std::string DownloadProcessHandle::DebugString() const {
+ return base::StringPrintf("{"
+ " child_id = %d"
+ " render_view_id = %d"
+ " request_id = %d"
+ "}",
+ child_id_,
+ render_view_id_,
+ request_id_);
+}

Powered by Google App Engine
This is Rietveld 408576698