| OLD | NEW |
| 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 Loading... |
| 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 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1191 it != results.end(); ++it) { | 1192 it != results.end(); ++it) { |
| 1192 json_results->Append( | 1193 json_results->Append( |
| 1193 new base::FundamentalValue(static_cast<int>((*it)->GetId()))); | 1194 new base::FundamentalValue(static_cast<int>((*it)->GetId()))); |
| 1194 (*it)->Remove(); | 1195 (*it)->Remove(); |
| 1195 } | 1196 } |
| 1196 SetResult(json_results); | 1197 SetResult(json_results); |
| 1197 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); | 1198 RecordApiFunctions(DOWNLOADS_FUNCTION_ERASE); |
| 1198 return true; | 1199 return true; |
| 1199 } | 1200 } |
| 1200 | 1201 |
| 1201 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() | 1202 DownloadsRemoveFileFunction::DownloadsRemoveFileFunction() { |
| 1202 : item_(NULL) { | |
| 1203 } | 1203 } |
| 1204 | 1204 |
| 1205 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { | 1205 DownloadsRemoveFileFunction::~DownloadsRemoveFileFunction() { |
| 1206 if (item_) { | |
| 1207 item_->RemoveObserver(this); | |
| 1208 item_ = NULL; | |
| 1209 } | |
| 1210 } | 1206 } |
| 1211 | 1207 |
| 1212 bool DownloadsRemoveFileFunction::RunImpl() { | 1208 bool DownloadsRemoveFileFunction::RunImpl() { |
| 1213 scoped_ptr<downloads::RemoveFile::Params> params( | 1209 scoped_ptr<downloads::RemoveFile::Params> params( |
| 1214 downloads::RemoveFile::Params::Create(*args_)); | 1210 downloads::RemoveFile::Params::Create(*args_)); |
| 1215 EXTENSION_FUNCTION_VALIDATE(params.get()); | 1211 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 1216 DownloadItem* download_item = | 1212 DownloadItem* download_item = |
| 1217 GetDownload(GetProfile(), include_incognito(), params->download_id); | 1213 GetDownload(GetProfile(), include_incognito(), params->download_id); |
| 1218 if (InvalidId(download_item, &error_) || | 1214 if (InvalidId(download_item, &error_) || |
| 1219 Fault((download_item->GetState() != DownloadItem::COMPLETE), | 1215 Fault((download_item->GetState() != DownloadItem::COMPLETE), |
| 1220 errors::kNotComplete, &error_) || | 1216 errors::kNotComplete, &error_) || |
| 1221 Fault(download_item->GetFileExternallyRemoved(), | 1217 Fault(download_item->GetFileExternallyRemoved(), |
| 1222 errors::kFileAlreadyDeleted, &error_)) | 1218 errors::kFileAlreadyDeleted, &error_)) |
| 1223 return false; | 1219 return false; |
| 1224 item_ = download_item; | |
| 1225 item_->AddObserver(this); | |
| 1226 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE); | 1220 RecordApiFunctions(DOWNLOADS_FUNCTION_REMOVE_FILE); |
| 1227 download_item->DeleteFile(); | 1221 download_item->DeleteFile( |
| 1222 base::Bind(&DownloadsRemoveFileFunction::Done, this)); |
| 1228 return true; | 1223 return true; |
| 1229 } | 1224 } |
| 1230 | 1225 |
| 1231 void DownloadsRemoveFileFunction::OnDownloadUpdated(DownloadItem* download) { | 1226 void DownloadsRemoveFileFunction::Done(bool success) { |
| 1232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1233 DCHECK_EQ(item_, download); | 1228 if (!success) { |
| 1234 if (!item_->GetFileExternallyRemoved()) | 1229 error_ = errors::kFileNotRemoved; |
| 1235 return; | 1230 } |
| 1236 item_->RemoveObserver(this); | 1231 SendResponse(error_.empty()); |
| 1237 item_ = NULL; | |
| 1238 SendResponse(true); | |
| 1239 } | |
| 1240 | |
| 1241 void DownloadsRemoveFileFunction::OnDownloadDestroyed(DownloadItem* download) { | |
| 1242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1243 DCHECK_EQ(item_, download); | |
| 1244 item_->RemoveObserver(this); | |
| 1245 item_ = NULL; | |
| 1246 SendResponse(true); | |
| 1247 } | 1232 } |
| 1248 | 1233 |
| 1249 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} | 1234 DownloadsAcceptDangerFunction::DownloadsAcceptDangerFunction() {} |
| 1250 | 1235 |
| 1251 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} | 1236 DownloadsAcceptDangerFunction::~DownloadsAcceptDangerFunction() {} |
| 1252 | 1237 |
| 1253 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* | 1238 DownloadsAcceptDangerFunction::OnPromptCreatedCallback* |
| 1254 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; | 1239 DownloadsAcceptDangerFunction::on_prompt_created_ = NULL; |
| 1255 | 1240 |
| 1256 bool DownloadsAcceptDangerFunction::RunImpl() { | 1241 bool DownloadsAcceptDangerFunction::RunImpl() { |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1904 extensions::UnloadedExtensionInfo* unloaded = | 1889 extensions::UnloadedExtensionInfo* unloaded = |
| 1905 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 1890 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
| 1906 std::set<const extensions::Extension*>::iterator iter = | 1891 std::set<const extensions::Extension*>::iterator iter = |
| 1907 shelf_disabling_extensions_.find(unloaded->extension); | 1892 shelf_disabling_extensions_.find(unloaded->extension); |
| 1908 if (iter != shelf_disabling_extensions_.end()) | 1893 if (iter != shelf_disabling_extensions_.end()) |
| 1909 shelf_disabling_extensions_.erase(iter); | 1894 shelf_disabling_extensions_.erase(iter); |
| 1910 break; | 1895 break; |
| 1911 } | 1896 } |
| 1912 } | 1897 } |
| 1913 } | 1898 } |
| OLD | NEW |