Index: chrome/browser/download/download_manager.cc |
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc |
index 6ef4a2b1e812ba36598d087e77f7925cacde2c3a..a30af6fcf092ae0255a51cafb436c8a6fe7857b4 100644 |
--- a/chrome/browser/download/download_manager.cc |
+++ b/chrome/browser/download/download_manager.cc |
@@ -265,6 +265,57 @@ void DownloadManager::StartDownload(DownloadCreateInfo* info) { |
info, NewCallback(this, &DownloadManager::CheckDownloadUrlDone)); |
} |
+void DownloadManager::CheckForFilesRemoval() { |
Paweł Hajdan Jr.
2011/05/10 11:37:51
nit: Could you add a DCHECK(BrowserThread::Cureent
|
+ PathVector existing_paths; |
+ for (DownloadMap::iterator it = history_downloads_.begin(); |
+ it != history_downloads_.end(); ++it) { |
+ DownloadItem* download_item = it->second; |
+ if (download_item->IsComplete() && download_item->file_exists()) { |
+ existing_paths.push_back(std::pair<int64, FilePath>( |
+ it->first, download_item->GetTargetFilePath())); |
+ } |
+ } |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::FILE, FROM_HERE, |
+ NewRunnableMethod(this, |
+ &DownloadManager::CheckForFilesRemovalOnFileThread, |
+ existing_paths)); |
+} |
+ |
+void DownloadManager::CheckForFilesRemovalOnFileThread( |
+ const PathVector& existing_paths) { |
+ PathVector removed_paths; |
+ for (PathVector::const_iterator it = existing_paths.begin(); |
+ it != existing_paths.end(); ++it) { |
+ if (!file_util::PathExists(it->second)) { |
+ removed_paths.push_back(std::pair<int64, FilePath>( |
+ it->first, it->second)); |
+ } |
+ } |
+ |
+ BrowserThread::PostTask( |
+ BrowserThread::UI, FROM_HERE, |
+ NewRunnableMethod(this, |
+ &DownloadManager::OnFilesRemovalDetected, |
+ removed_paths)); |
+} |
+ |
+void DownloadManager::OnFilesRemovalDetected(const PathVector& removed_paths) { |
+ for (PathVector::const_iterator it = removed_paths.begin(); |
+ it != removed_paths.end(); ++it) { |
+ DownloadMap::iterator map_it = history_downloads_.find(it->first); |
+ // Since all download items are registered to DownloadDOMHandler's |
Paweł Hajdan Jr.
2011/05/10 11:37:51
nit: I'd rather remove this comment. It might beco
|
+ // observer, we can update the display of chrome://downloads page |
+ // by calling UpdateObservers() |
+ if (map_it != history_downloads_.end()) { |
+ DownloadItem* download_item = map_it->second; |
+ download_item->set_file_exists(false); |
+ download_item->UpdateObservers(); |
+ } |
+ } |
+} |
+ |
void DownloadManager::CheckDownloadUrlDone(DownloadCreateInfo* info, |
bool is_dangerous_url) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |