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

Unified Diff: chrome/browser/extensions/api/downloads/downloads_api.cc

Issue 134373003: Return error to chrome.downloads.removeFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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
Index: chrome/browser/extensions/api/downloads/downloads_api.cc
diff --git a/chrome/browser/extensions/api/downloads/downloads_api.cc b/chrome/browser/extensions/api/downloads/downloads_api.cc
index 95fe74e03064e4481af7445b8047879b3377bb8f..4ee7dfc1f307b0dfa4797f45e7729461561b73b7 100644
--- a/chrome/browser/extensions/api/downloads/downloads_api.cc
+++ b/chrome/browser/extensions/api/downloads/downloads_api.cc
@@ -89,6 +89,7 @@ namespace download_extension_errors {
const char kEmptyFile[] = "Filename not yet determined";
const char kFileAlreadyDeleted[] = "Download file already deleted";
+const char kFileNotRemoved[] = "Unable to remove file";
const char kIconNotFound[] = "Icon not found";
const char kInvalidDangerType[] = "Invalid danger type";
const char kInvalidFilename[] = "Invalid filename";
@@ -1200,15 +1201,10 @@ bool DownloadsEraseFunction::RunImpl() {
return true;
}
-DownloadsRemoveFileFunction::DownloadsRemoveFileFunction()
- : item_(NULL) {
+DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() {
}
DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() {
- if (item_) {
- item_->RemoveObserver(this);
- item_ = NULL;
- }
}
bool DownloadsRemoveFileFunction::RunImpl() {
@@ -1223,29 +1219,18 @@ bool DownloadsRemoveFileFunction::RunImpl() {
Fault(download_item->GetFileExternallyRemoved(),
errors::kFileAlreadyDeleted, &error_))
return false;
- item_ = download_item;
- item_->AddObserver(this);
RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE);
- download_item->DeleteFile();
+ download_item->DeleteFile(
+ base::Bind(&DownloadsRemoveFileFunction::Done, this));
return true;
}
-void DownloadsRemoveFileFunction::OnDownloadUpdated(DownloadItem* download) {
+void DownloadsRemoveFileFunction::Done(bool success) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK_EQ(item_, download);
- if (!item_->GetFileExternallyRemoved())
- return;
- item_->RemoveObserver(this);
- item_ = NULL;
- SendResponse(true);
-}
-
-void DownloadsRemoveFileFunction::OnDownloadDestroyed(DownloadItem* download) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK_EQ(item_, download);
- item_->RemoveObserver(this);
- item_ = NULL;
- SendResponse(true);
+ if (!success) {
+ error_ = errors::kFileNotRemoved;
+ }
+ SendResponse(error_.empty());
}
DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {}
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.h ('k') | content/browser/download/download_item_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698