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

Unified Diff: chrome/browser/download/download_path_reservation_tracker.cc

Issue 324883006: Cleanup: Use PostTaskAndReplyWithResults instead of passing callbacks around in downloads code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 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/chrome_download_manager_delegate.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_path_reservation_tracker.cc
===================================================================
--- chrome/browser/download/download_path_reservation_tracker.cc (revision 275705)
+++ chrome/browser/download/download_path_reservation_tracker.cc (working copy)
@@ -147,15 +147,14 @@
// 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 @@
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 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 @@
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
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698