summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download/download_item.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 17:14:00 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 17:14:00 +0000
commit7ba53e1db77e3cd7c9e7b05c6e44698a142beea5 (patch)
tree1610b6881ce577e7ee1048bc5e22c7f8bb9b8d9e /chrome/browser/download/download_item.cc
parentf0f569e61980fc8077ac13012a09976f4ce5cebd (diff)
downloadchromium_src-7ba53e1db77e3cd7c9e7b05c6e44698a142beea5.zip
chromium_src-7ba53e1db77e3cd7c9e7b05c6e44698a142beea5.tar.gz
chromium_src-7ba53e1db77e3cd7c9e7b05c6e44698a142beea5.tar.bz2
Clean up download code:
- move filename generation parts and related code out of DownloadManager download_util is not the best place for it, but it's better than DownloadManager which we're trying to minimize - clean up posting tasks to different threads. There's no need to create separate methods for that, it was cluttering the file needlessly - other minor cleanups, like using static_cast instead of C-style cast TEST=unit_tests, browser_tests, ui_tests BUG=48913 Review URL: http://codereview.chromium.org/3043048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55088 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download/download_item.cc')
-rw-r--r--chrome/browser/download/download_item.cc17
1 files changed, 15 insertions, 2 deletions
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc
index 905d00f..269f0cb 100644
--- a/chrome/browser/download/download_item.cc
+++ b/chrome/browser/download/download_item.cc
@@ -4,8 +4,10 @@
#include "chrome/browser/download/download_item.h"
+#include "base/file_util.h"
#include "base/logging.h"
#include "base/timer.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/download/download_history.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_util.h"
@@ -17,6 +19,14 @@ namespace {
// Update frequency (milliseconds).
const int kUpdateTimeMs = 1000;
+void DeleteDownloadedFile(const FilePath& path) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE));
+
+ // Make sure we only delete files.
+ if (!file_util::DirectoryExists(path))
+ file_util::Delete(path, false);
+}
+
} // namespace
// Constructor for reading from the history service.
@@ -229,8 +239,11 @@ void DownloadItem::Finished(int64 size) {
void DownloadItem::Remove(bool delete_on_disk) {
Cancel(true);
state_ = REMOVING;
- if (delete_on_disk)
- download_manager_->DeleteDownload(full_path_);
+ if (delete_on_disk) {
+ ChromeThread::PostTask(
+ ChromeThread::FILE, FROM_HERE,
+ NewRunnableFunction(&DeleteDownloadedFile, full_path_));
+ }
download_manager_->RemoveDownload(db_handle_);
// We have now been deleted.
}