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

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

Issue 10834129: Implement chrome.downloads.erase() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: @r172329 Created 8 years 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 10058314bd2185e00b8f7704ac3e6174ccde33db..c7b13dcbd2934432ddcea03d7c14e7bc4d030836 100644
--- a/chrome/browser/extensions/api/downloads/downloads_api.cc
+++ b/chrome/browser/extensions/api/downloads/downloads_api.cc
@@ -748,9 +748,8 @@ bool DownloadsCancelFunction::RunImpl() {
// |download_item| can be NULL if the download ID was invalid or if the
// download is not currently active. Either way, we don't consider it a
// failure.
- if (error_.empty())
- RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL);
- return error_.empty();
+ RecordApiFunctions(DOWNLOADS_FUNCTION_CANCEL);
+ return true;
}
DownloadsEraseFunction::DownloadsEraseFunction() {}
@@ -760,10 +759,26 @@ bool DownloadsEraseFunction::RunImpl() {
scoped_ptr<extensions::api::downloads::Erase::Params> params(
extensions::api::downloads::Erase::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- error_ = download_extension_errors::kNotImplementedError;
- if (error_.empty())
- RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE);
- return error_.empty();
+ DownloadManager* manager = NULL;
+ DownloadManager* incognito_manager = NULL;
+ GetManagers(profile(), include_incognito(), &manager, &incognito_manager);
+ DownloadQuery::DownloadVector results;
+ RunDownloadQuery(params->query,
+ manager,
+ incognito_manager,
+ &error_,
+ &results);
+ if (!error_.empty())
+ return false;
+ base::ListValue* json_results = new base::ListValue();
+ for (DownloadManager::DownloadVector::const_iterator it = results.begin();
+ it != results.end(); ++it) {
+ json_results->Append(base::Value::CreateIntegerValue((*it)->GetId()));
+ (*it)->Remove();
+ }
+ SetResult(json_results);
+ RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE);
+ return true;
}
DownloadsSetDestinationFunction::DownloadsSetDestinationFunction() {}

Powered by Google App Engine
This is Rietveld 408576698