summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 10:10:19 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 10:10:19 +0000
commita2631f83c6adddc769ab470defa9ddd21f91dee3 (patch)
tree7bca6d8361159a7cd9a82bb25b551ef76cab7438
parentf51a712deb178ed12e01621efa87f86d14012368 (diff)
downloadchromium_src-a2631f83c6adddc769ab470defa9ddd21f91dee3.zip
chromium_src-a2631f83c6adddc769ab470defa9ddd21f91dee3.tar.gz
chromium_src-a2631f83c6adddc769ab470defa9ddd21f91dee3.tar.bz2
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
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate.cc16
-rw-r--r--chrome/browser/download/download_path_reservation_tracker.cc41
2 files changed, 35 insertions, 22 deletions
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
index 1134636..2a8d6c6 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate.cc
@@ -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(
- FROM_HERE,
- base::Bind(&GetMimeTypeAndReplyOnUIThread, path, callback));
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ base::PostTaskAndReplyWithResult(BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&GetMimeType, path),
+ callback);
}
#if defined(FULL_SAFE_BROWSING)
diff --git a/chrome/browser/download/download_path_reservation_tracker.cc b/chrome/browser/download/download_path_reservation_tracker.cc
index ce8bbb9..397aa99 100644
--- a/chrome/browser/download/download_path_reservation_tracker.cc
+++ b/chrome/browser/download/download_path_reservation_tracker.cc
@@ -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,
- download_item,
- target_path,
- default_path,
- create_directory,
- conflict_action,
- callback));
+ 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,
+ reserved_path),
+ base::Bind(&RunGetReservedPathCallback,
+ callback,
+ base::Owned(reserved_path)));
}
// static