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

Unified 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: Merged to LKGR. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/download/download_request_handle.h ('k') | chrome/browser/download/download_util.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_request_handle.cc
diff --git a/chrome/browser/download/download_request_handle.cc b/chrome/browser/download/download_request_handle.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e7f581f30fcfd7592093afda408fd51b883777a
--- /dev/null
+++ b/chrome/browser/download/download_request_handle.cc
@@ -0,0 +1,113 @@
+// Copyright (c) 2011 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 "chrome/browser/download/download_request_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"
+
+// IO Thread indirections to resource dispatcher host.
+// Provided as targets for PostTask from within this object
+// only.
+static void ResourceDispatcherHostPauseRequest(
+ 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 ResourceDispatcherHostCancelRequest(
+ ResourceDispatcherHost* rdh,
+ int process_unique_id,
+ int request_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ rdh->CancelRequest(process_unique_id, request_id, false);
+}
+
+DownloadRequestHandle::DownloadRequestHandle()
+ : rdh_(NULL),
+ child_id_(-1),
+ render_view_id_(-1),
+ request_id_(-1) {
+}
+
+DownloadRequestHandle::DownloadRequestHandle(ResourceDispatcherHost* rdh,
+ int child_id,
+ int render_view_id,
+ int request_id)
+ : rdh_(rdh),
+ child_id_(child_id),
+ render_view_id_(render_view_id),
+ request_id_(request_id) {
+ // ResourceDispatcherHost should not be null for non-default instances
+ // of DownloadRequestHandle.
+ DCHECK(rdh);
+}
+
+TabContents* DownloadRequestHandle::GetTabContents() const{
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ return tab_util::GetTabContentsByID(child_id_, render_view_id_);
+}
+
+DownloadManager* DownloadRequestHandle::GetDownloadManager() const {
+ TabContents* contents = GetTabContents();
+ if (!contents)
+ return NULL;
+
+ Profile* profile = contents->profile();
+ if (!profile)
+ return NULL;
+
+ return profile->GetDownloadManager();
+}
+
+void DownloadRequestHandle::PauseRequest() {
+ // The post is safe because ResourceDispatcherHost is guaranteed
+ // to outlive the IO thread.
+ if (rdh_) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(&ResourceDispatcherHostPauseRequest,
+ rdh_, child_id_, request_id_, true));
+ }
+}
+
+void DownloadRequestHandle::ResumeRequest() {
+ // The post is safe because ResourceDispatcherHost is guaranteed
+ // to outlive the IO thread.
+ if (rdh_) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(&ResourceDispatcherHostPauseRequest,
+ rdh_, child_id_, request_id_, false));
+ }
+}
+
+void DownloadRequestHandle::CancelRequest() {
+ // The post is safe because ResourceDispatcherHost is guaranteed
+ // to outlive the IO thread.
+ if (rdh_) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ NewRunnableFunction(&ResourceDispatcherHostCancelRequest,
+ rdh_, 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_);
+}
« no previous file with comments | « chrome/browser/download/download_request_handle.h ('k') | chrome/browser/download/download_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698