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

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: Merge with the latest revision 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
« no previous file with comments | « chrome/browser/download/download_item.h ('k') | chrome/browser/download/download_item_model.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/download_item.cc
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc
index 62aa272bba71c9267db8d9220f016ff22f631a3f..1b2f7cfd143a4a280fd4342a912d04bb8d7d589d 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),
@@ -242,8 +245,13 @@ 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);
+ return !Extension::IsExtension(state_info_.target_name) &&
+ !file_externally_removed_;
}
bool DownloadItem::ShouldOpenFileBasedOnExtension() {
@@ -265,7 +273,12 @@ 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));
@@ -396,6 +409,11 @@ void DownloadItem::OnAllDataSaved(int64 size) {
StopProgressTimer();
}
+void DownloadItem::OnDownloadedFileRemoved() {
+ file_externally_removed_ = true;
+ UpdateObservers();
+}
+
void DownloadItem::Completed() {
// TODO(rdsmith): Change to DCHECK after http://crbug.com/85408 resolved.
CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
« no previous file with comments | « chrome/browser/download/download_item.h ('k') | chrome/browser/download/download_item_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698