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

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: is_path_exists_ => file_exists_, aggregate scattered AddObserver()s into one AddObserver() Created 9 years, 7 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 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));

Powered by Google App Engine
This is Rietveld 408576698