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

Unified Diff: chrome/browser/download/notification/download_notification_item.cc

Issue 1105953002: Pop up the notification when the download is interrupted or completed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dn-xxxx-close-bug
Patch Set: Adressed comment and pop up the notification after completion Created 5 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
« no previous file with comments | « chrome/browser/download/notification/download_notification_item.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/download/notification/download_notification_item.cc
diff --git a/chrome/browser/download/notification/download_notification_item.cc b/chrome/browser/download/notification/download_notification_item.cc
index 8345ff2a915801186c502248225b3f6ad0fa7dd6..8a74d213203a3a3681a50671bfce7e72950a7444 100644
--- a/chrome/browser/download/notification/download_notification_item.cc
+++ b/chrome/browser/download/notification/download_notification_item.cc
@@ -72,7 +72,6 @@ DownloadNotificationItem::DownloadNotificationItem(content::DownloadItem* item,
Profile* profile,
Delegate* delegate)
: openable_(false),
- downloading_(false),
image_resource_id_(0),
profile_(profile),
watcher_(new NotificationWatcher(this)),
@@ -147,6 +146,16 @@ void DownloadNotificationItem::OnDownloadUpdated(content::DownloadItem* item) {
UpdateNotificationData(UPDATE_EXISTING);
}
+void DownloadNotificationItem::CloseNotificationByNonUser() {
+ const std::string& notification_id = watcher_->id();
+ const ProfileID profile_id = NotificationUIManager::GetProfileID(profile_);
+ const std::string notification_id_in_message_center =
+ ProfileNotification::GetProfileNotificationId(notification_id,
+ profile_id);
+
+ notification_ui_manager()->CancelById(notification_id, profile_id);
+}
+
void DownloadNotificationItem::CloseNotificationByUser() {
const std::string& notification_id = watcher_->id();
const ProfileID profile_id = NotificationUIManager::GetProfileID(profile_);
@@ -172,16 +181,12 @@ void DownloadNotificationItem::UpdateNotificationData(
DownloadItemModel model(item_);
DownloadCommands command(item_);
- if (!downloading_) {
- if (item_->GetState() == content::DownloadItem::IN_PROGRESS) {
+ if (previous_download_state_ != content::DownloadItem::IN_PROGRESS) {
yoshiki 2015/05/12 14:49:33 The semantics is same as the previous. Just rewrit
+ if (item_->GetState() == content::DownloadItem::IN_PROGRESS)
delegate_->OnDownloadStarted(this);
- downloading_ = true;
- }
} else {
- if (item_->GetState() != content::DownloadItem::IN_PROGRESS) {
+ if (item_->GetState() != content::DownloadItem::IN_PROGRESS)
delegate_->OnDownloadStopped(this);
- downloading_ = false;
- }
}
if (item_->IsDangerous()) {
@@ -210,15 +215,22 @@ void DownloadNotificationItem::UpdateNotificationData(
}
break;
case content::DownloadItem::COMPLETE:
- notification_->set_type(message_center::NOTIFICATION_TYPE_SIMPLE);
+ DCHECK_EQ(100, item_->PercentComplete());
+ DCHECK(item_->IsDone());
+
+ // Shows a notifiation as progress type once so the visible content will
+ // be updated.
+ // Note: only progress-type notification's content will be updated
+ // immediately when the message center is visible.
+ notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
+ notification_->set_progress(100);
+
if (is_off_the_record) {
// TODO(yoshiki): Replace the tentative image.
SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_INCOGNITO);
} else {
SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_DOWNLOADING);
}
-
- // TODO(yoshiki): Popup a notification again.
break;
case content::DownloadItem::CANCELLED:
// Confgirms that a download is cancelled by user action.
@@ -228,12 +240,15 @@ void DownloadNotificationItem::UpdateNotificationData(
content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN);
CloseNotificationByUser();
+
+ previous_download_state_ = item_->GetState();
return; // Skips the remaining since the notification has closed.
case content::DownloadItem::INTERRUPTED:
- notification_->set_type(message_center::NOTIFICATION_TYPE_SIMPLE);
+ // Shows a notifiation as progress type once so the visible content will
+ // be updated. (same as the case of type = COMPLETE)
+ notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
+ notification_->set_progress(0);
SetNotificationImage(IDR_DOWNLOAD_NOTIFICATION_WARNING);
-
- // TODO(yoshiki): Popup a notification again.
break;
case content::DownloadItem::MAX_DOWNLOAD_STATE: // sentinel
NOTREACHED();
@@ -263,12 +278,33 @@ void DownloadNotificationItem::UpdateNotificationData(
// TODO(yoshiki): If the downloaded file is an image, show the thumbnail.
}
- if (type == ADD_NEW)
+ if (type == ADD_NEW) {
notification_ui_manager()->Add(*notification_, profile_);
- else if (type == UPDATE_EXISTING)
+ } else if (type == UPDATE_EXISTING) {
notification_ui_manager()->Update(*notification_, profile_);
- else
+
+ // When the download is just completed, close the notification once and
+ // re-show it immediately so it'll be poped up.
+ if (item_->GetState() == content::DownloadItem::COMPLETE &&
+ previous_download_state_ != content::DownloadItem::COMPLETE) {
+ CloseNotificationByNonUser();
+ // Changes the type from PROGRESS to SIMPLE.
+ notification_->set_type(message_center::NOTIFICATION_TYPE_SIMPLE);
+ notification_ui_manager()->Add(*notification_, profile_);
+ }
+
+ // When the download is just interruppted, close the notification once and
+ // re-show it immediately so it'll be poped up.
+ if (item_->GetState() == content::DownloadItem::INTERRUPTED &&
+ previous_download_state_ != content::DownloadItem::INTERRUPTED) {
+ CloseNotificationByNonUser();
+ notification_ui_manager()->Add(*notification_, profile_);
+ }
+ } else {
NOTREACHED();
+ }
+
+ previous_download_state_ = item_->GetState();
}
void DownloadNotificationItem::OnDownloadOpened(content::DownloadItem* item) {
@@ -356,7 +392,7 @@ base::string16 DownloadNotificationItem::GetTitle() const {
IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, file_name);
case content::DownloadItem::INTERRUPTED:
title_text = l10n_util::GetStringFUTF16(
- IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, file_name);
+ IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, file_name);
yoshiki 2015/05/12 14:49:33 just fixing wrong ID for failure download.
break;
case content::DownloadItem::CANCELLED:
title_text = l10n_util::GetStringFUTF16(
« no previous file with comments | « chrome/browser/download/notification/download_notification_item.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698