summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/download/download_create_info.cc8
-rw-r--r--chrome/browser/download/download_create_info.h8
-rw-r--r--chrome/browser/download/download_file.cc14
-rw-r--r--chrome/browser/download/download_file.h8
-rw-r--r--chrome/browser/download/download_file_manager.cc29
-rw-r--r--chrome/browser/download/download_file_manager.h8
-rw-r--r--chrome/browser/download/download_file_unittest.cc5
-rw-r--r--chrome/browser/download/download_item.cc7
-rw-r--r--chrome/browser/download/download_item.h10
-rw-r--r--chrome/browser/download/download_manager.cc47
-rw-r--r--chrome/browser/download/download_manager.h15
-rw-r--r--chrome/browser/download/download_process_handle.cc39
-rw-r--r--chrome/browser/download/download_process_handle.h42
-rw-r--r--chrome/browser/download/download_request_handle.cc113
-rw-r--r--chrome/browser/download/download_request_handle.h63
-rw-r--r--chrome/browser/download/download_util.cc20
-rw-r--r--chrome/browser/download/download_util.h8
-rw-r--r--chrome/browser/renderer_host/download_resource_handler.cc5
-rw-r--r--chrome/chrome_browser.gypi4
19 files changed, 228 insertions, 225 deletions
diff --git a/chrome/browser/download/download_create_info.cc b/chrome/browser/download/download_create_info.cc
index 8a77e82..5dd192b 100644
--- a/chrome/browser/download/download_create_info.cc
+++ b/chrome/browser/download/download_create_info.cc
@@ -53,9 +53,7 @@ std::string DownloadCreateInfo::DebugString() const {
" path = \"%" PRFilePath "\""
" received_bytes = %" PRId64
" total_bytes = %" PRId64
- " child_id = %d"
- " render_view_id = %d"
- " request_id = %d"
+ " request_handle = %s"
" prompt_user_for_save_location = %c"
" }",
download_id,
@@ -63,9 +61,7 @@ std::string DownloadCreateInfo::DebugString() const {
path.value().c_str(),
received_bytes,
total_bytes,
- process_handle.child_id(),
- process_handle.render_view_id(),
- process_handle.request_id(),
+ request_handle.DebugString().c_str(),
prompt_user_for_save_location ? 'T' : 'F');
}
diff --git a/chrome/browser/download/download_create_info.h b/chrome/browser/download/download_create_info.h
index 5adeac2..a9f5ec1 100644
--- a/chrome/browser/download/download_create_info.h
+++ b/chrome/browser/download/download_create_info.h
@@ -13,7 +13,7 @@
#include "base/file_path.h"
#include "base/time.h"
#include "chrome/browser/download/download_file.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "googleurl/src/gurl.h"
// Used for informing the download manager of a new download, since we don't
@@ -71,9 +71,9 @@ struct DownloadCreateInfo {
// True if the download was initiated by user action.
bool has_user_gesture;
- // The handle to the process information. Used for operations outside the
- // download system.
- DownloadProcessHandle process_handle;
+ // The handle to the download request information. Used for operations
+ // outside the download system.
+ DownloadRequestHandle request_handle;
// The handle of the download in the history database.
int64 db_handle;
diff --git a/chrome/browser/download/download_file.cc b/chrome/browser/download/download_file.cc
index d1a3470..a64a99f 100644
--- a/chrome/browser/download/download_file.cc
+++ b/chrome/browser/download/download_file.cc
@@ -21,7 +21,7 @@ DownloadFile::DownloadFile(const DownloadCreateInfo* info,
info->received_bytes,
info->save_info.file_stream),
id_(info->download_id),
- process_handle_(info->process_handle),
+ request_handle_(info->request_handle),
download_manager_(download_manager) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
}
@@ -30,9 +30,9 @@ DownloadFile::~DownloadFile() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
}
-void DownloadFile::CancelDownloadRequest(ResourceDispatcherHost* rdh) {
+void DownloadFile::CancelDownloadRequest() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- download_util::CancelDownloadRequest(rdh, process_handle_);
+ request_handle_.CancelRequest();
}
DownloadManager* DownloadFile::GetDownloadManager() {
@@ -43,14 +43,10 @@ DownloadManager* DownloadFile::GetDownloadManager() {
std::string DownloadFile::DebugString() const {
return base::StringPrintf("{"
" id_ = " "%d"
- " child_id = " "%d"
- " request_id = " "%d"
- " render_view_id = " "%d"
+ " request_handle = %s"
" Base File = %s"
" }",
id_,
- process_handle_.child_id(),
- process_handle_.request_id(),
- process_handle_.render_view_id(),
+ request_handle_.DebugString().c_str(),
BaseFile::DebugString().c_str());
}
diff --git a/chrome/browser/download/download_file.h b/chrome/browser/download/download_file.h
index 63060fe..4fa3bfc 100644
--- a/chrome/browser/download/download_file.h
+++ b/chrome/browser/download/download_file.h
@@ -11,7 +11,7 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/download/base_file.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "chrome/browser/download/download_types.h"
struct DownloadCreateInfo;
@@ -29,7 +29,7 @@ class DownloadFile : public BaseFile {
virtual ~DownloadFile();
// Cancels the download request associated with this file.
- void CancelDownloadRequest(ResourceDispatcherHost* rdh);
+ void CancelDownloadRequest();
int id() const { return id_; }
DownloadManager* GetDownloadManager();
@@ -41,9 +41,9 @@ class DownloadFile : public BaseFile {
// the DownloadFileManager for its internal record keeping.
int id_;
- // The handle to the process information. Used for operations outside the
+ // The handle to the request information. Used for operations outside the
// download system, specifically canceling a download.
- DownloadProcessHandle process_handle_;
+ DownloadRequestHandle request_handle_;
// DownloadManager this download belongs to.
scoped_refptr<DownloadManager> download_manager_;
diff --git a/chrome/browser/download/download_file_manager.cc b/chrome/browser/download/download_file_manager.cc
index 1604905..16a0ac7 100644
--- a/chrome/browser/download/download_file_manager.cc
+++ b/chrome/browser/download/download_file_manager.cc
@@ -13,7 +13,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_create_info.h"
#include "chrome/browser/download/download_manager.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/platform_util.h"
@@ -69,8 +69,7 @@ void DownloadFileManager::CreateDownloadFile(DownloadCreateInfo* info,
scoped_ptr<DownloadFile>
download_file(new DownloadFile(info, download_manager));
if (!download_file->Initialize(get_hash)) {
- download_util::CancelDownloadRequest(resource_dispatcher_host_,
- info->process_handle);
+ info->request_handle.CancelRequest();
return;
}
@@ -79,10 +78,7 @@ void DownloadFileManager::CreateDownloadFile(DownloadCreateInfo* info,
downloads_[id] = download_file.release();
// The file is now ready, we can un-pause the request and start saving data.
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &DownloadFileManager::ResumeDownloadRequest,
- info->process_handle));
+ info->request_handle.ResumeRequest();
StartUpdateTimer();
@@ -92,16 +88,6 @@ void DownloadFileManager::CreateDownloadFile(DownloadCreateInfo* info,
&DownloadManager::StartDownload, id));
}
-void DownloadFileManager::ResumeDownloadRequest(
- DownloadProcessHandle process) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- // This balances the pause in DownloadResourceHandler::OnResponseStarted.
- resource_dispatcher_host_->PauseRequest(process.child_id(),
- process.request_id(),
- false);
-}
-
DownloadFile* DownloadFileManager::GetDownloadFile(int id) {
DownloadFileMap::iterator it = downloads_.find(id);
return it == downloads_.end() ? NULL : it->second;
@@ -146,10 +132,9 @@ void DownloadFileManager::StartDownload(DownloadCreateInfo* info) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(info);
- DownloadManager* manager = info->process_handle.GetDownloadManager();
+ DownloadManager* manager = info->request_handle.GetDownloadManager();
if (!manager) {
- download_util::CancelDownloadRequest(resource_dispatcher_host_,
- info->process_handle);
+ info->request_handle.CancelRequest();
delete info;
return;
}
@@ -270,7 +255,7 @@ void DownloadFileManager::OnDownloadManagerShutdown(DownloadManager* manager) {
i != downloads_.end(); ++i) {
DownloadFile* download_file = i->second;
if (download_file->GetDownloadManager() == manager) {
- download_file->CancelDownloadRequest(resource_dispatcher_host_);
+ download_file->CancelDownloadRequest();
to_remove.insert(download_file);
}
}
@@ -385,7 +370,7 @@ void DownloadFileManager::CancelDownloadOnRename(int id) {
// Without a download manager, we can't cancel the request normally, so we
// need to do it here. The normal path will also update the download
// history before cancelling the request.
- download_file->CancelDownloadRequest(resource_dispatcher_host_);
+ download_file->CancelDownloadRequest();
return;
}
diff --git a/chrome/browser/download/download_file_manager.h b/chrome/browser/download/download_file_manager.h
index 6047aee..2b52636 100644
--- a/chrome/browser/download/download_file_manager.h
+++ b/chrome/browser/download/download_file_manager.h
@@ -47,7 +47,7 @@
#include "base/hash_tables.h"
#include "base/memory/ref_counted.h"
#include "base/timer.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "ui/gfx/native_widget_types.h"
struct DownloadBuffer;
@@ -142,12 +142,6 @@ class DownloadFileManager
DownloadManager* download_manager,
bool hash_needed);
- // Tells the ResourceDispatcherHost to resume a download request
- // that was paused to wait for the on-disk file to be created.
- // |process| is passed by value because this is called from other
- // threads, and this way we don't have to worry about object lifetimes.
- void ResumeDownloadRequest(DownloadProcessHandle process);
-
// Called only on the download thread.
DownloadFile* GetDownloadFile(int id);
diff --git a/chrome/browser/download/download_file_unittest.cc b/chrome/browser/download/download_file_unittest.cc
index 19d0712..f4a2a28 100644
--- a/chrome/browser/download/download_file_unittest.cc
+++ b/chrome/browser/download/download_file_unittest.cc
@@ -9,7 +9,7 @@
#include "chrome/browser/download/download_create_info.h"
#include "chrome/browser/download/download_file.h"
#include "chrome/browser/download/download_manager.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "chrome/browser/download/download_status_updater.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/download/mock_download_manager.h"
@@ -58,8 +58,7 @@ class DownloadFileTest : public testing::Test {
virtual void CreateDownloadFile(scoped_ptr<DownloadFile>* file, int offset) {
DownloadCreateInfo info;
info.download_id = kDummyDownloadId + offset;
- info.process_handle =
- DownloadProcessHandle(kDummyChildId, -1, kDummyRequestId - offset);
+ // info.request_handle default constructed to null.
info.save_info.file_stream = file_stream_;
file->reset(new DownloadFile(&info, download_manager_));
}
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc
index 2c4ba1e..bf6e533 100644
--- a/chrome/browser/download/download_item.cc
+++ b/chrome/browser/download/download_item.cc
@@ -154,7 +154,7 @@ DownloadItem::DownloadItem(DownloadManager* download_manager,
info.has_user_gesture, info.prompt_user_for_save_location,
info.path_uniquifier, false, false,
info.is_extension_install),
- process_handle_(info.process_handle),
+ request_handle_(info.request_handle),
download_id_(info.download_id),
full_path_(info.path),
url_chain_(info.url_chain),
@@ -499,7 +499,10 @@ void DownloadItem::Rename(const FilePath& full_path) {
void DownloadItem::TogglePause() {
DCHECK(IsInProgress());
- download_manager_->PauseDownload(download_id_, !is_paused_);
+ if (is_paused_)
+ request_handle_.ResumeRequest();
+ else
+ request_handle_.PauseRequest();
is_paused_ = !is_paused_;
UpdateObservers();
}
diff --git a/chrome/browser/download/download_item.h b/chrome/browser/download/download_item.h
index 6aa5c8e..ef262d6 100644
--- a/chrome/browser/download/download_item.h
+++ b/chrome/browser/download/download_item.h
@@ -25,7 +25,7 @@
#include "base/observer_list.h"
#include "base/time.h"
#include "base/timer.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "chrome/browser/download/download_state_info.h"
#include "content/common/notification_observer.h"
#include "content/common/notification_registrar.h"
@@ -302,8 +302,8 @@ class DownloadItem : public NotificationObserver {
DownloadHistoryInfo GetHistoryInfo() const;
DownloadStateInfo state_info() const { return state_info_; }
- const DownloadProcessHandle& process_handle() const {
- return process_handle_;
+ const DownloadRequestHandle& request_handle() const {
+ return request_handle_;
}
// Returns the final target file path for the download.
@@ -360,9 +360,9 @@ class DownloadItem : public NotificationObserver {
// State information used by the download manager.
DownloadStateInfo state_info_;
- // The handle to the process information. Used for operations outside the
+ // The handle to the request information. Used for operations outside the
// download system.
- DownloadProcessHandle process_handle_;
+ DownloadRequestHandle request_handle_;
// Download ID assigned by DownloadResourceHandler.
int32 download_id_;
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 58090f2..7475915 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -23,7 +23,7 @@
#include "chrome/browser/download/download_history.h"
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/download_prefs.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "chrome/browser/download/download_safe_browsing_client.h"
#include "chrome/browser/download/download_status_updater.h"
#include "chrome/browser/download/download_util.h"
@@ -472,8 +472,8 @@ void DownloadManager::OnPathExistenceAvailable(int32 download_id,
if (!select_file_dialog_.get())
select_file_dialog_ = SelectFileDialog::Create(this);
- DownloadProcessHandle process_handle = download->process_handle();
- TabContents* contents = process_handle.GetTabContents();
+ DownloadRequestHandle request_handle = download->request_handle();
+ TabContents* contents = request_handle.GetTabContents();
SelectFileDialog::FileTypeInfo file_type_info;
FilePath::StringType extension = suggested_path.Extension();
if (!extension.empty()) {
@@ -749,15 +749,13 @@ void DownloadManager::DownloadCancelled(int32 download_id) {
download_history_->UpdateEntry(download);
}
- DownloadCancelledInternal(download_id, download->process_handle());
+ DownloadCancelledInternal(download_id, download->request_handle());
}
void DownloadManager::DownloadCancelledInternal(
- int download_id, DownloadProcessHandle process_handle) {
+ int download_id, DownloadRequestHandle request_handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- // Cancel the network request. RDH is guaranteed to outlive the IO thread.
- download_util::CancelDownloadRequest(
- g_browser_process->resource_dispatcher_host(), process_handle);
+ request_handle.CancelRequest();
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
@@ -801,38 +799,11 @@ void DownloadManager::OnDownloadError(int32 download_id,
file_manager_, &DownloadFileManager::CancelDownload, download_id));
}
-void DownloadManager::PauseDownload(int32 download_id, bool pause) {
- DownloadMap::iterator it = in_progress_.find(download_id);
- if (it == in_progress_.end())
- return;
-
- DownloadItem* download = it->second;
- if (pause == download->is_paused())
- return;
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this,
- &DownloadManager::PauseDownloadRequest,
- g_browser_process->resource_dispatcher_host(),
- download->process_handle(),
- pause));
-}
-
void DownloadManager::UpdateAppIcon() {
if (status_updater_)
status_updater_->Update();
}
-void DownloadManager::PauseDownloadRequest(ResourceDispatcherHost* rdh,
- DownloadProcessHandle process_handle,
- bool pause) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- rdh->PauseRequest(process_handle.child_id(),
- process_handle.request_id(),
- pause);
-}
-
void DownloadManager::RemoveDownload(int64 download_handle) {
DownloadMap::iterator it = history_downloads_.find(download_handle);
if (it == history_downloads_.end())
@@ -1047,7 +1018,7 @@ void DownloadManager::FileSelectionCanceled(void* params) {
VLOG(20) << __FUNCTION__ << "()"
<< " download = " << download->DebugString(true);
- DownloadCancelledInternal(download_id, download->process_handle());
+ DownloadCancelledInternal(download_id, download->request_handle());
}
// TODO(phajdan.jr): This is apparently not being exercised in tests.
@@ -1162,8 +1133,8 @@ void DownloadManager::ShowDownloadInBrowser(DownloadItem* download) {
// The 'contents' may no longer exist if the user closed the tab before we
// get this start completion event. If it does, tell the origin TabContents
// to display its download shelf.
- DownloadProcessHandle process_handle = download->process_handle();
- TabContents* contents = process_handle.GetTabContents();
+ DownloadRequestHandle request_handle = download->request_handle();
+ TabContents* contents = request_handle.GetTabContents();
TabContentsWrapper* wrapper = NULL;
if (contents)
wrapper = TabContentsWrapper::GetCurrentWrapperForContents(contents);
diff --git a/chrome/browser/download/download_manager.h b/chrome/browser/download/download_manager.h
index 79018be..2ad7030 100644
--- a/chrome/browser/download/download_manager.h
+++ b/chrome/browser/download/download_manager.h
@@ -42,8 +42,8 @@
#include "base/scoped_ptr.h"
#include "base/time.h"
#include "chrome/browser/download/download_item.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "chrome/browser/download/download_status_updater_delegate.h"
-#include "chrome/browser/download/download_process_handle.h"
#include "chrome/browser/ui/shell_dialogs.h"
#include "content/browser/browser_thread.h"
@@ -124,7 +124,6 @@ class DownloadManager
// Called from a view when a user clicks a UI button or link.
void DownloadCancelled(int32 download_id);
- void PauseDownload(int32 download_id, bool pause);
void RemoveDownload(int64 download_handle);
// Determine if the download is ready for completion, i.e. has had
@@ -299,10 +298,10 @@ class DownloadManager
const FilePath& chosen_file);
// Download cancel helper function.
- // |process_handle| is passed by value because it is ultimately passed to
+ // |request_handle| is passed by value because it is ultimately passed to
// other threads, and this way we don't have to worry about object lifetimes.
void DownloadCancelledInternal(int download_id,
- DownloadProcessHandle process_handle);
+ DownloadRequestHandle request_handle);
// All data has been downloaded.
// |hash| is sha256 hash for the downloaded file. It is empty when the hash
@@ -315,14 +314,6 @@ class DownloadManager
// Updates the app icon about the overall download progress.
void UpdateAppIcon();
- // Makes the ResourceDispatcherHost pause/un-pause a download request.
- // Called on the IO thread.
- // |process_handle| is passed by value because this is called from other
- // threads, and this way we don't have to worry about object lifetimes.
- void PauseDownloadRequest(ResourceDispatcherHost* rdh,
- DownloadProcessHandle process_handle,
- bool pause);
-
// Inform observers that the model has changed.
void NotifyModelChanged();
diff --git a/chrome/browser/download/download_process_handle.cc b/chrome/browser/download/download_process_handle.cc
deleted file mode 100644
index f4c7f32..0000000
--- a/chrome/browser/download/download_process_handle.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// 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_process_handle.h"
-
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/tab_contents/tab_util.h"
-#include "content/browser/browser_thread.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,
- int render_view_id,
- int request_id)
- : child_id_(child_id),
- render_view_id_(render_view_id),
- request_id_(request_id) {
-}
-
-TabContents* DownloadProcessHandle::GetTabContents() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- return tab_util::GetTabContentsByID(child_id_, render_view_id_);
-}
-
-DownloadManager* DownloadProcessHandle::GetDownloadManager() {
- TabContents* contents = GetTabContents();
- if (!contents)
- return NULL;
-
- Profile* profile = contents->profile();
- if (!profile)
- return NULL;
-
- return profile->GetDownloadManager();
-}
diff --git a/chrome/browser/download/download_process_handle.h b/chrome/browser/download/download_process_handle.h
deleted file mode 100644
index b722d61..0000000
--- a/chrome/browser/download/download_process_handle.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// 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.
-
-#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROCESS_HANDLE_H_
-#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROCESS_HANDLE_H_
-#pragma once
-
-class DownloadManager;
-class ResourceDispatcherHost;
-class TabContents;
-
-// A handle used by the download system for operations on external
-// objects associated with the download (e.g. URLRequest, TabContents,
-// DownloadManager).
-// This class needs to be copyable, so we can pass it across threads and not
-// worry about lifetime or const-ness.
-class DownloadProcessHandle {
- public:
- DownloadProcessHandle();
- DownloadProcessHandle(int child_id, int render_view_id, int request_id);
-
- // These functions must be called on the UI thread.
- TabContents* GetTabContents();
- DownloadManager* GetDownloadManager();
-
- int child_id() const { return child_id_; }
- int render_view_id() const { return render_view_id_; }
- int request_id() const { return request_id_; }
-
- private:
- // The ID of the child process that started the download.
- int child_id_;
-
- // The ID of the render view that started the download.
- int render_view_id_;
-
- // The ID associated with the request used for the download.
- int request_id_;
-};
-
-#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_PROCESS_HANDLE_H_
diff --git a/chrome/browser/download/download_request_handle.cc b/chrome/browser/download/download_request_handle.cc
new file mode 100644
index 0000000..9e7f581
--- /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_);
+}
diff --git a/chrome/browser/download/download_request_handle.h b/chrome/browser/download/download_request_handle.h
new file mode 100644
index 0000000..e591cb8
--- /dev/null
+++ b/chrome/browser/download/download_request_handle.h
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
+#define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
+#pragma once
+
+#include <string>
+
+class DownloadManager;
+class ResourceDispatcherHost;
+class TabContents;
+
+// A handle used by the download system for operations on the URLRequest
+// or objects conditional on it (e.g. TabContents).
+// This class needs to be copyable, so we can pass it across threads and not
+// worry about lifetime or const-ness.
+class DownloadRequestHandle {
+ public:
+ // Create a null DownloadRequestHandle: getters will return null, and
+ // all actions are no-ops.
+ // TODO(rdsmith): Ideally, actions would be forbidden rather than
+ // no-ops, to confirm that no non-testing code actually uses
+ // a null DownloadRequestHandle. But for now, we need the no-op
+ // behavior for unit tests. Long-term, this should be fixed by
+ // allowing mocking of ResourceDispatcherHost in unit tests.
+ DownloadRequestHandle();
+
+ // Note that |rdh| is required to be non-null.
+ DownloadRequestHandle(ResourceDispatcherHost* rdh,
+ int child_id,
+ int render_view_id,
+ int request_id);
+
+ // These functions must be called on the UI thread.
+ TabContents* GetTabContents() const;
+ DownloadManager* GetDownloadManager() const;
+
+ // Pause or resume the matching URL request.
+ void PauseRequest();
+ void ResumeRequest();
+
+ // Cancel the request
+ void CancelRequest();
+
+ std::string DebugString() const;
+
+ private:
+ // The resource dispatcher host.
+ ResourceDispatcherHost* rdh_;
+
+ // The ID of the child process that started the download.
+ int child_id_;
+
+ // The ID of the render view that started the download.
+ int render_view_id_;
+
+ // The ID associated with the request used for the download.
+ int request_id_;
+};
+
+#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 108aa7a..06c03b2 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -849,26 +849,6 @@ void DownloadUrl(
*context);
}
-static void CancelDownloadRequestOnIOThread(
- ResourceDispatcherHost* rdh, DownloadProcessHandle process_handle) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- // |rdh| may be NULL in unit tests.
- if (!rdh)
- return;
-
- rdh->CancelRequest(process_handle.child_id(),
- process_handle.request_id(),
- false);
-}
-
-void CancelDownloadRequest(ResourceDispatcherHost* rdh,
- DownloadProcessHandle process_handle) {
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableFunction(&download_util::CancelDownloadRequestOnIOThread,
- rdh, process_handle));
-}
-
void NotifyDownloadInitiated(int render_process_id, int render_view_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
RenderViewHost* rvh = RenderViewHost::FromID(render_process_id,
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index e7726a9..c279973 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -14,7 +14,6 @@
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/string16.h"
-#include "chrome/browser/download/download_process_handle.h"
#include "ui/gfx/native_widget_types.h"
#if defined(TOOLKIT_VIEWS)
@@ -269,13 +268,6 @@ void DownloadUrl(const GURL& url,
int render_view_id,
const content::ResourceContext* context);
-// Tells the resource dispatcher host to cancel a download request.
-// Must be called on the IO thread.
-// |process_handle| is passed by value because it is ultimately passed to
-// other threads, and this way we don't have to worry about object lifetimes.
-void CancelDownloadRequest(ResourceDispatcherHost* rdh,
- DownloadProcessHandle process_handle);
-
// Sends a notification on downloads being initiated
// Must be called on the UI thread.
void NotifyDownloadInitiated(int render_process_id, int render_view_id);
diff --git a/chrome/browser/renderer_host/download_resource_handler.cc b/chrome/browser/renderer_host/download_resource_handler.cc
index b333bf4..f35d5e4 100644
--- a/chrome/browser/renderer_host/download_resource_handler.cc
+++ b/chrome/browser/renderer_host/download_resource_handler.cc
@@ -13,7 +13,7 @@
#include "chrome/browser/download/download_create_info.h"
#include "chrome/browser/download/download_item.h"
#include "chrome/browser/download/download_file_manager.h"
-#include "chrome/browser/download/download_process_handle.h"
+#include "chrome/browser/download/download_request_handle.h"
#include "chrome/browser/download/download_util.h"
#include "content/browser/browser_thread.h"
#include "content/browser/renderer_host/global_request_id.h"
@@ -89,7 +89,8 @@ bool DownloadResourceHandler::OnResponseStarted(int request_id,
info->state = DownloadItem::IN_PROGRESS;
info->download_id = download_id_;
info->has_user_gesture = request_info->has_user_gesture();
- info->process_handle = DownloadProcessHandle(global_id_.child_id,
+ info->request_handle = DownloadRequestHandle(rdh_,
+ global_id_.child_id,
render_view_id_,
global_id_.request_id);
info->content_disposition = content_disposition_;
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 1a6f1d8..99ed95f 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -828,8 +828,8 @@
'browser/download/download_manager.h',
'browser/download/download_prefs.cc',
'browser/download/download_prefs.h',
- 'browser/download/download_process_handle.cc',
- 'browser/download/download_process_handle.h',
+ 'browser/download/download_request_handle.cc',
+ 'browser/download/download_request_handle.h',
'browser/download/download_request_infobar_delegate.cc',
'browser/download/download_request_infobar_delegate.h',
'browser/download/download_request_limiter.cc',