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

Unified Diff: chrome/browser/download/download_manager.cc

Issue 6905049: Detect removed files and reflect the state in chrome://downloads and the download shelf (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Remove REMOVED state from Download.States in downloads.js Created 9 years, 6 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/download/download_manager.cc
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 58090f2d492e18f00c5dc16dca08589f9e43e6e1..acbb13e68d7feeae4815fb9b5fb4a575d74fa733 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -269,6 +269,48 @@ void DownloadManager::StartDownload(int32 download_id) {
NewCallback(this, &DownloadManager::CheckDownloadUrlDone));
}
+void DownloadManager::CheckForHistoryFilesRemoval() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ for (DownloadMap::iterator it = history_downloads_.begin();
+ it != history_downloads_.end(); ++it) {
+ CheckForFileRemoval(it->second);
+ }
+}
+
+void DownloadManager::CheckForFileRemoval(DownloadItem* download_item) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (download_item->IsComplete() &&
+ !download_item->file_externally_removed()) {
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ NewRunnableMethod(this,
+ &DownloadManager::CheckForFileRemovalOnFileThread,
+ download_item->db_handle(),
+ download_item->GetTargetFilePath()));
+ }
+}
+
+void DownloadManager::CheckForFileRemovalOnFileThread(
+ int64 db_handle, const FilePath& path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ if (!file_util::PathExists(path)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ NewRunnableMethod(this,
+ &DownloadManager::OnFileRemovalDetected,
+ db_handle));
+ }
+}
+
+void DownloadManager::OnFileRemovalDetected(int64 db_handle) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DownloadMap::iterator it = history_downloads_.find(db_handle);
+ if (it != history_downloads_.end()) {
+ DownloadItem* download_item = it->second;
+ download_item->OnDownloadedFileRemoved();
+ }
+}
+
void DownloadManager::CheckDownloadUrlDone(int32 download_id,
bool is_dangerous_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -1101,6 +1143,7 @@ void DownloadManager::OnQueryDownloadEntriesComplete(
<< " download = " << download->DebugString(true);
}
NotifyModelChanged();
+ CheckForHistoryFilesRemoval();
}
// Once the new DownloadItem's creation info has been committed to the history

Powered by Google App Engine
This is Rietveld 408576698