Commit fabf36d2 authored by achuith@chromium.org's avatar achuith@chromium.org

Replace NewRunnable with Callback in DownloadManager.

BUG=chromium-os:22024
TEST=compiles, tests pass.
Review URL: http://codereview.chromium.org/8417009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107802 0039d316-1c4b-4281-b951-d872f2087c98
parent 9963020f
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "base/task.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/browser_context.h" #include "content/browser/browser_context.h"
#include "content/browser/download/download_create_info.h" #include "content/browser/download/download_create_info.h"
...@@ -37,23 +36,34 @@ ...@@ -37,23 +36,34 @@
namespace { namespace {
void BeginDownload( // Param structs exist because base::Bind can only handle 6 args.
const GURL& url, struct URLParams {
const GURL& referrer, URLParams(const GURL& url, const GURL& referrer)
const DownloadSaveInfo& save_info, : url_(url), referrer_(referrer) {}
ResourceDispatcherHost* resource_dispatcher_host, GURL url_;
int render_process_id, GURL referrer_;
int render_view_id, };
const content::ResourceContext* context) {
net::URLRequest* request = new net::URLRequest(url, resource_dispatcher_host); struct RenderParams {
request->set_referrer(referrer.spec()); RenderParams(int rpi, int rvi)
: render_process_id_(rpi), render_view_id_(rvi) {}
int render_process_id_;
int render_view_id_;
};
void BeginDownload(const URLParams& url_params,
const DownloadSaveInfo& save_info,
ResourceDispatcherHost* resource_dispatcher_host,
const RenderParams& render_params,
const content::ResourceContext* context) {
net::URLRequest* request = new net::URLRequest(url_params.url_,
resource_dispatcher_host);
request->set_referrer(url_params.referrer_.spec());
resource_dispatcher_host->BeginDownload( resource_dispatcher_host->BeginDownload(
request, request, save_info, true,
save_info,
true,
DownloadResourceHandler::OnStartedCallback(), DownloadResourceHandler::OnStartedCallback(),
render_process_id, render_params.render_process_id_,
render_view_id, render_params.render_view_id_,
*context); *context);
} }
...@@ -94,9 +104,8 @@ void DownloadManager::Shutdown() { ...@@ -94,9 +104,8 @@ void DownloadManager::Shutdown() {
if (file_manager_) { if (file_manager_) {
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(file_manager_, base::Bind(&DownloadFileManager::OnDownloadManagerShutdown,
&DownloadFileManager::OnDownloadManagerShutdown, file_manager_, make_scoped_refptr(this)));
make_scoped_refptr(this)));
} }
AssertContainersConsistent(); AssertContainersConsistent();
...@@ -263,10 +272,9 @@ void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) { ...@@ -263,10 +272,9 @@ void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) {
!download_item->file_externally_removed()) { !download_item->file_externally_removed()) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE, BrowserThread::FILE, FROM_HERE,
NewRunnableMethod(this, base::Bind(&DownloadManager::CheckForFileRemovalOnFileThread,
&DownloadManager::CheckForFileRemovalOnFileThread, this, download_item->db_handle(),
download_item->db_handle(), download_item->GetTargetFilePath()));
download_item->GetTargetFilePath()));
} }
} }
...@@ -276,9 +284,7 @@ void DownloadManager::CheckForFileRemovalOnFileThread( ...@@ -276,9 +284,7 @@ void DownloadManager::CheckForFileRemovalOnFileThread(
if (!file_util::PathExists(path)) { if (!file_util::PathExists(path)) {
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this, base::Bind(&DownloadManager::OnFileRemovalDetected, this, db_handle));
&DownloadManager::OnFileRemovalDetected,
db_handle));
} }
} }
...@@ -371,9 +377,8 @@ void DownloadManager::ContinueDownloadWithPath(DownloadItem* download, ...@@ -371,9 +377,8 @@ void DownloadManager::ContinueDownloadWithPath(DownloadItem* download,
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE, BrowserThread::FILE, FROM_HERE,
NewRunnableMethod( base::Bind(&DownloadFileManager::RenameInProgressDownloadFile,
file_manager_, &DownloadFileManager::RenameInProgressDownloadFile, file_manager_, download->global_id(), download_path));
download->global_id(), download_path));
download->Rename(download_path); download->Rename(download_path);
...@@ -534,10 +539,10 @@ void DownloadManager::OnDownloadRenamedToFinalName(int download_id, ...@@ -534,10 +539,10 @@ void DownloadManager::OnDownloadRenamedToFinalName(int download_id,
DCHECK_EQ(0, uniquifier) << "We should not uniquify SAFE downloads twice"; DCHECK_EQ(0, uniquifier) << "We should not uniquify SAFE downloads twice";
} }
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, NewRunnableMethod( BrowserThread::PostTask(
file_manager_, BrowserThread::FILE, FROM_HERE,
&DownloadFileManager::CompleteDownload, base::Bind(&DownloadFileManager::CompleteDownload,
item->global_id())); file_manager_, item->global_id()));
if (uniquifier) if (uniquifier)
item->set_path_uniquifier(uniquifier); item->set_path_uniquifier(uniquifier);
...@@ -718,16 +723,14 @@ void DownloadManager::DownloadUrlToFile(const GURL& url, ...@@ -718,16 +723,14 @@ void DownloadManager::DownloadUrlToFile(const GURL& url,
content::GetContentClient()->browser()->GetResourceDispatcherHost(); content::GetContentClient()->browser()->GetResourceDispatcherHost();
// We send a pointer to content::ResourceContext, instead of the usual // We send a pointer to content::ResourceContext, instead of the usual
// reference, so that a copy of the object isn't made. // reference, so that a copy of the object isn't made.
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, // base::Bind can't handle 7 args, so we use URLParams and RenderParams.
NewRunnableFunction(&BeginDownload, BrowserThread::PostTask(
url, BrowserThread::IO, FROM_HERE,
referrer, base::Bind(&BeginDownload,
save_info, URLParams(url, referrer), save_info, resource_dispatcher_host,
resource_dispatcher_host, RenderParams(tab_contents->GetRenderProcessHost()->id(),
tab_contents->GetRenderProcessHost()->id(), tab_contents->render_view_host()->routing_id()),
tab_contents->render_view_host()->routing_id(), &tab_contents->browser_context()->GetResourceContext()));
&tab_contents->browser_context()->
GetResourceContext()));
} }
void DownloadManager::AddObserver(Observer* observer) { void DownloadManager::AddObserver(Observer* observer) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment