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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <iterator> 9 #include <iterator>
10 #include <set> 10 #include <set>
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 using content::BrowserContext; 83 using content::BrowserContext;
84 using content::BrowserThread; 84 using content::BrowserThread;
85 using content::DownloadItem; 85 using content::DownloadItem;
86 using content::DownloadManager; 86 using content::DownloadManager;
87 87
88 namespace download_extension_errors { 88 namespace download_extension_errors {
89 89
90 const char kEmptyFile[] = "Filename not yet determined"; 90 const char kEmptyFile[] = "Filename not yet determined";
91 const char kFileAlreadyDeleted[] = "Download file already deleted"; 91 const char kFileAlreadyDeleted[] = "Download file already deleted";
92 const char kFileNotRemoved[] = "Unable to remove file";
92 const char kIconNotFound[] = "Icon not found"; 93 const char kIconNotFound[] = "Icon not found";
93 const char kInvalidDangerType[] = "Invalid danger type"; 94 const char kInvalidDangerType[] = "Invalid danger type";
94 const char kInvalidFilename[] = "Invalid filename"; 95 const char kInvalidFilename[] = "Invalid filename";
95 const char kInvalidFilter[] = "Invalid query filter"; 96 const char kInvalidFilter[] = "Invalid query filter";
96 const char kInvalidHeader[] = "Invalid request header"; 97 const char kInvalidHeader[] = "Invalid request header";
97 const char kInvalidId[] = "Invalid downloadId"; 98 const char kInvalidId[] = "Invalid downloadId";
98 const char kInvalidOrderBy[] = "Invalid orderBy field"; 99 const char kInvalidOrderBy[] = "Invalid orderBy field";
99 const char kInvalidQueryLimit[] = "Invalid query limit"; 100 const char kInvalidQueryLimit[] = "Invalid query limit";
100 const char kInvalidState[] = "Invalid state"; 101 const char kInvalidState[] = "Invalid state";
101 const char kInvalidURL[] = "Invalid URL"; 102 const char kInvalidURL[] = "Invalid URL";
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 it != results.end(); ++it) { 1194 it != results.end(); ++it) {
1194 json_results->Append( 1195 json_results->Append(
1195 new base::FundamentalValue(static_cast<int>((*it)->GetId()))); 1196 new base::FundamentalValue(static_cast<int>((*it)->GetId())));
1196 (*it)->Remove(); 1197 (*it)->Remove();
1197 } 1198 }
1198 SetResult(json_results); 1199 SetResult(json_results);
1199 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); 1200 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE);
1200 return true; 1201 return true;
1201 } 1202 }
1202 1203
1203 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() 1204 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() {
1204 : item_(NULL) {
1205 } 1205 }
1206 1206
1207 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { 1207 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() {
1208 if (item_) {
1209 item_->RemoveObserver(this);
1210 item_ = NULL;
1211 }
1212 } 1208 }
1213 1209
1214 bool DownloadsRemoveFileFunction::RunImpl() { 1210 bool DownloadsRemoveFileFunction::RunImpl() {
1215 scoped_ptr<downloads::RemoveFile::Params> params( 1211 scoped_ptr<downloads::RemoveFile::Params> params(
1216 downloads::RemoveFile::Params::Create(*args_)); 1212 downloads::RemoveFile::Params::Create(*args_));
1217 EXTENSION_FUNCTION_VALIDATE(params.get()); 1213 EXTENSION_FUNCTION_VALIDATE(params.get());
1218 DownloadItem* download_item = 1214 DownloadItem* download_item =
1219 GetDownload(GetProfile(), include_incognito(), params->download_id); 1215 GetDownload(GetProfile(), include_incognito(), params->download_id);
1220 if (InvalidId(download_item, &error_) || 1216 if (InvalidId(download_item, &error_) ||
1221 Fault((download_item->GetState() != DownloadItem::COMPLETE), 1217 Fault((download_item->GetState() != DownloadItem::COMPLETE),
1222 errors::kNotComplete, &error_) || 1218 errors::kNotComplete, &error_) ||
1223 Fault(download_item->GetFileExternallyRemoved(), 1219 Fault(download_item->GetFileExternallyRemoved(),
1224 errors::kFileAlreadyDeleted, &error_)) 1220 errors::kFileAlreadyDeleted, &error_))
1225 return false; 1221 return false;
1226 item_ = download_item;
1227 item_->AddObserver(this);
1228 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE); 1222 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE);
1229 download_item->DeleteFile(); 1223 download_item->DeleteFile(
1224 base::Bind(&DownloadsRemoveFileFunction::Done, this));
1230 return true; 1225 return true;
1231 } 1226 }
1232 1227
1233 void DownloadsRemoveFileFunction::OnDownloadUpdated(DownloadItem* download) { 1228 void DownloadsRemoveFileFunction::Done(bool success) {
1234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1235 DCHECK_EQ(item_, download); 1230 if (!success) {
1236 if (!item_->GetFileExternallyRemoved()) 1231 error_ = errors::kFileNotRemoved;
1237 return; 1232 }
1238 item_->RemoveObserver(this); 1233 SendResponse(error_.empty());
1239 item_ = NULL;
1240 SendResponse(true);
1241 }
1242
1243 void DownloadsRemoveFileFunction::OnDownloadDestroyed(DownloadItem* download) {
1244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1245 DCHECK_EQ(item_, download);
1246 item_->RemoveObserver(this);
1247 item_ = NULL;
1248 SendResponse(true);
1249 } 1234 }
1250 1235
1251 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} 1236 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {}
1252 1237
1253 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} 1238 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {}
1254 1239
1255 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* 1240 DownloadsAcceptDangerFunction::OnPromptCreatedCallback*
1256 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; 1241 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL;
1257 1242
1258 bool DownloadsAcceptDangerFunction::RunImpl() { 1243 bool DownloadsAcceptDangerFunction::RunImpl() {
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 extensions::UnloadedExtensionInfo* unloaded = 1891 extensions::UnloadedExtensionInfo* unloaded =
1907 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); 1892 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
1908 std::set<const extensions::Extension*>::iterator iter = 1893 std::set<const extensions::Extension*>::iterator iter =
1909 shelf_disabling_extensions_.find(unloaded->extension); 1894 shelf_disabling_extensions_.find(unloaded->extension);
1910 if (iter != shelf_disabling_extensions_.end()) 1895 if (iter != shelf_disabling_extensions_.end())
1911 shelf_disabling_extensions_.erase(iter); 1896 shelf_disabling_extensions_.erase(iter);
1912 break; 1897 break;
1913 } 1898 }
1914 } 1899 }
1915 } 1900 }
OLDNEW
« 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