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

Unified Diff: chrome/browser/download/download_item.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_item.cc
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc
index 2c4ba1e5e98aab05938356b3acd2e187c1300c99..6caf68317593dc951498f5085ecd4ac7b2da4a2a 100644
--- a/chrome/browser/download/download_item.cc
+++ b/chrome/browser/download/download_item.cc
@@ -132,6 +132,7 @@ DownloadItem::DownloadItem(DownloadManager* download_manager,
download_manager_(download_manager),
is_paused_(false),
open_when_complete_(false),
+ file_externally_removed_(false),
safety_state_(SAFE),
auto_opened_(false),
is_otr_(false),
@@ -173,6 +174,7 @@ DownloadItem::DownloadItem(DownloadManager* download_manager,
download_manager_(download_manager),
is_paused_(false),
open_when_complete_(false),
+ file_externally_removed_(false),
safety_state_(SAFE),
auto_opened_(false),
is_otr_(is_otr),
@@ -202,6 +204,7 @@ DownloadItem::DownloadItem(DownloadManager* download_manager,
download_manager_(download_manager),
is_paused_(false),
open_when_complete_(false),
+ file_externally_removed_(false),
safety_state_(SAFE),
auto_opened_(false),
is_otr_(is_otr),
@@ -229,6 +232,10 @@ void DownloadItem::UpdateObservers() {
FOR_EACH_OBSERVER(Observer, observers_, OnDownloadUpdated(this));
}
+bool DownloadItem::CanShowInFolder() {
+ return !IsCancelled() && !file_externally_removed_;
+}
+
bool DownloadItem::CanOpenDownload() {
return !Extension::IsExtension(state_info_.target_name);
Paweł Hajdan Jr. 2011/06/08 09:58:41 Shouldn't you check file_externally_removed_ here?
haraken1 2011/06/08 10:35:07 I fixed it. (However, we may not have to check |
}
@@ -249,7 +256,12 @@ void DownloadItem::OpenFilesBasedOnExtension(bool open) {
void DownloadItem::OpenDownload() {
if (IsPartialDownload()) {
open_when_complete_ = !open_when_complete_;
- } else if (IsComplete()) {
+ } else if (IsComplete() && !file_externally_removed_) {
+ // Ideally, we want to detect errors in opening and report them, but we
+ // don't generally have the proper interface for that to the external
+ // program that opens the file. So instead we spawn a check to update
+ // the UI if the file has been deleted in parallel with the open.
+ download_manager_->CheckForFileRemoval(this);
opened_ = true;
FOR_EACH_OBSERVER(Observer, observers_, OnDownloadOpened(this));
@@ -353,6 +365,11 @@ void DownloadItem::OnAllDataSaved(int64 size) {
StopProgressTimer();
}
+void DownloadItem::OnDownloadedFileRemoved() {
+ file_externally_removed_ = true;
+ UpdateObservers();
+}
+
void DownloadItem::Completed() {
VLOG(20) << __FUNCTION__ << "() " << DebugString(false);

Powered by Google App Engine
This is Rietveld 408576698