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 2e9438b5600690ed144436fab192f9cad4c56239..94075beb6e77c9f0d4c49a6cd0567317179d7ced 100644 |
| --- a/chrome/browser/download/notification/download_notification_item.cc |
| +++ b/chrome/browser/download/notification/download_notification_item.cc |
| @@ -159,6 +159,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 = |
|
asanka
2015/05/14 21:36:17
unused?
yoshiki
2015/05/15 06:27:09
Done.
|
| + 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_); |
| @@ -184,16 +194,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) { |
| + 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()) { |
| @@ -222,15 +228,21 @@ void DownloadNotificationItem::UpdateNotificationData( |
| } |
| break; |
| case content::DownloadItem::COMPLETE: |
| - notification_->set_type(message_center::NOTIFICATION_TYPE_SIMPLE); |
| + 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. |
| @@ -240,12 +252,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(); |
| @@ -275,12 +290,27 @@ 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 (or interrupted), close the |
| + // notification once and re-show it immediately so it'll be poped up. |
|
asanka
2015/05/14 21:36:17
so it'll pop up.
yoshiki
2015/05/15 06:27:09
Done.
|
| + if ((item_->GetState() == content::DownloadItem::COMPLETE && |
| + previous_download_state_ != content::DownloadItem::COMPLETE) || |
| + (item_->GetState() == content::DownloadItem::INTERRUPTED && |
| + previous_download_state_ != content::DownloadItem::INTERRUPTED)) { |
| + CloseNotificationByNonUser(); |
| + // Changes the type from PROGRESS to SIMPLE. |
| + notification_->set_type(message_center::NOTIFICATION_TYPE_SIMPLE); |
| + notification_ui_manager()->Add(*notification_, profile_); |
| + } |
| + } else { |
| NOTREACHED(); |
| + } |
| + |
| + previous_download_state_ = item_->GetState(); |
| } |
| void DownloadNotificationItem::OnDownloadOpened(content::DownloadItem* item) { |
| @@ -367,9 +397,10 @@ base::string16 DownloadNotificationItem::GetTitle() const { |
| case content::DownloadItem::COMPLETE: |
| title_text = l10n_util::GetStringFUTF16( |
| IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, file_name); |
| + break; |
| case content::DownloadItem::INTERRUPTED: |
| title_text = l10n_util::GetStringFUTF16( |
| - IDS_DOWNLOAD_STATUS_DOWNLOADED_TITLE, file_name); |
| + IDS_DOWNLOAD_STATUS_DOWNLOAD_FAILED_TITLE, file_name); |
| break; |
| case content::DownloadItem::CANCELLED: |
| title_text = l10n_util::GetStringFUTF16( |