Commit a2631f83 authored by thestig@chromium.org's avatar thestig@chromium.org

Cleanup: Use PostTaskAndReplyWithResults instead of passing callbacks around in downloads code.

Review URL: https://codereview.chromium.org/324883006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276613 0039d316-1c4b-4281-b951-d872f2087c98
parent f51a712d
......@@ -17,6 +17,7 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task_runner.h"
#include "base/task_runner_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
......@@ -177,13 +178,10 @@ void CheckDownloadUrlDone(
#endif // FULL_SAFE_BROWSING
// Called on the blocking pool to determine the MIME type for |path|.
void GetMimeTypeAndReplyOnUIThread(
const base::FilePath& path,
const base::Callback<void(const std::string&)>& callback) {
std::string GetMimeType(const base::FilePath& path) {
std::string mime_type;
net::GetMimeTypeFromFile(path, &mime_type);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, base::Bind(callback, mime_type));
return mime_type;
}
bool IsOpenInBrowserPreferreredForFile(const base::FilePath& path) {
......@@ -636,9 +634,11 @@ void ChromeDownloadManagerDelegate::CheckDownloadUrl(
void ChromeDownloadManagerDelegate::GetFileMimeType(
const base::FilePath& path,
const GetFileMimeTypeCallback& callback) {
BrowserThread::PostBlockingPoolTask(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(),
FROM_HERE,
base::Bind(&GetMimeTypeAndReplyOnUIThread, path, callback));
base::Bind(&GetMimeType, path),
callback);
}
#if defined(FULL_SAFE_BROWSING)
......
......@@ -147,15 +147,14 @@ bool TruncateFileName(base::FilePath* path, size_t limit) {
// writeable.
// - Truncates the suggested name if it exceeds the filesystem's limit.
// - Uniquifies |suggested_path| if |should_uniquify_path| is true.
// - Schedules |callback| on the UI thread with the reserved path and a flag
// indicating whether the returned path has been successfully verified.
void CreateReservation(
// - Returns true if |reserved_path| has been successfully verified.
bool CreateReservation(
ReservationKey key,
const base::FilePath& suggested_path,
const base::FilePath& default_download_path,
bool create_directory,
DownloadPathReservationTracker::FilenameConflictAction conflict_action,
const DownloadPathReservationTracker::ReservedPathCallback& callback) {
base::FilePath* reserved_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DCHECK(suggested_path.IsAbsolute());
......@@ -243,8 +242,8 @@ void CreateReservation(
reservations[key] = target_path;
bool verified = (is_path_writeable && !has_conflicts && !name_too_long);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(callback, target_path, verified));
*reserved_path = target_path;
return verified;
}
// Called on the FILE thread to update the path of the reservation associated
......@@ -277,6 +276,14 @@ void RevokeReservation(ReservationKey key) {
}
}
void RunGetReservedPathCallback(
const DownloadPathReservationTracker::ReservedPathCallback& callback,
const base::FilePath* reserved_path,
bool verified) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
callback.Run(*reserved_path, verified);
}
DownloadItemObserver::DownloadItemObserver(DownloadItem* download_item)
: download_item_(download_item),
last_target_path_(download_item->GetTargetFilePath()) {
......@@ -349,14 +356,20 @@ void DownloadPathReservationTracker::GetReservedPath(
new DownloadItemObserver(download_item);
// DownloadItemObserver deletes itself.
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind(
&CreateReservation,
base::FilePath* reserved_path = new base::FilePath;
BrowserThread::PostTaskAndReplyWithResult(
BrowserThread::FILE,
FROM_HERE,
base::Bind(&CreateReservation,
download_item,
target_path,
default_path,
create_directory,
conflict_action,
callback));
reserved_path),
base::Bind(&RunGetReservedPathCallback,
callback,
base::Owned(reserved_path)));
}
// static
......
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