Chromium Code Reviews| 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( |