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

Side by Side Diff: chrome/browser/download/notification/download_item_notification.cc

Issue 1403003004: Revert of Update first download notification correctly if there are multiple notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/download/notification/download_item_notification.h" 5 #include "chrome/browser/download/notification/download_item_notification.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/download/download_crx_util.h" 10 #include "chrome/browser/download/download_crx_util.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 break; 156 break;
157 } 157 }
158 } 158 }
159 159
160 } // anonymous namespace 160 } // anonymous namespace
161 161
162 DownloadItemNotification::DownloadItemNotification( 162 DownloadItemNotification::DownloadItemNotification(
163 content::DownloadItem* item, 163 content::DownloadItem* item,
164 DownloadNotificationManagerForProfile* manager) 164 DownloadNotificationManagerForProfile* manager)
165 : item_(item), 165 : item_(item),
166 message_center_(manager->message_center()),
167 weak_factory_(this) { 166 weak_factory_(this) {
168
169 // Creates the notification instance. |title|, |body| and |icon| will be 167 // Creates the notification instance. |title|, |body| and |icon| will be
170 // overridden by UpdateNotificationData() below. 168 // overridden by UpdateNotificationData() below.
171 notification_.reset(new Notification( 169 notification_.reset(new Notification(
172 message_center::NOTIFICATION_TYPE_PROGRESS, 170 message_center::NOTIFICATION_TYPE_PROGRESS,
173 base::string16(), // title 171 base::string16(), // title
174 base::string16(), // body 172 base::string16(), // body
175 gfx::Image(), // icon 173 gfx::Image(), // icon
176 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 174 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
177 kDownloadNotificationNotifierId), 175 kDownloadNotificationNotifierId),
178 base::string16(), // display_source 176 base::string16(), // display_source
(...skipping 15 matching lines...) Expand all
194 192
195 bool DownloadItemNotification::HasNotificationClickedListener() { 193 bool DownloadItemNotification::HasNotificationClickedListener() {
196 if (item_->IsDangerous()) { 194 if (item_->IsDangerous()) {
197 // Dangerous notifications don't have a click handler. 195 // Dangerous notifications don't have a click handler.
198 return false; 196 return false;
199 } 197 }
200 return true; 198 return true;
201 } 199 }
202 200
203 void DownloadItemNotification::OnNotificationClose() { 201 void DownloadItemNotification::OnNotificationClose() {
202 visible_ = false;
203
204 if (item_ && item_->IsDangerous() && !item_->IsDone()) { 204 if (item_ && item_->IsDangerous() && !item_->IsDone()) {
205 content::RecordAction( 205 content::RecordAction(
206 UserMetricsAction("DownloadNotification.Close_Dangerous")); 206 UserMetricsAction("DownloadNotification.Close_Dangerous"));
207 item_->Cancel(true /* by_user */); 207 item_->Cancel(true /* by_user */);
208 return; 208 return;
209 } 209 }
210 210
211 if (image_decode_status_ == IN_PROGRESS) { 211 if (image_decode_status_ == IN_PROGRESS) {
212 image_decode_status_ = NOT_STARTED; 212 image_decode_status_ = NOT_STARTED;
213 ImageDecoder::Cancel(this); 213 ImageDecoder::Cancel(this);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 g_browser_process->notification_ui_manager()-> 307 g_browser_process->notification_ui_manager()->
308 CancelById(notification_id, profile_id); 308 CancelById(notification_id, profile_id);
309 309
310 // When the message center is visible, |NotificationUIManager::CancelByID()| 310 // When the message center is visible, |NotificationUIManager::CancelByID()|
311 // delays the close hence the notification is not closed at this time. But 311 // delays the close hence the notification is not closed at this time. But
312 // from the viewpoint of UX of MessageCenter, we should close it immediately 312 // from the viewpoint of UX of MessageCenter, we should close it immediately
313 // because it's by user action. So, we request closing of it directlly to 313 // because it's by user action. So, we request closing of it directlly to
314 // MessageCenter instance. 314 // MessageCenter instance.
315 // Note that: this calling has no side-effect even when the message center 315 // Note that: this calling has no side-effect even when the message center
316 // is not opened. 316 // is not opened.
317 message_center_->RemoveNotification( 317 g_browser_process->message_center()->RemoveNotification(
318 notification_id_in_message_center, true /* by_user */); 318 notification_id_in_message_center, true /* by_user */);
319 } 319 }
320 320
321 void DownloadItemNotification::Update() { 321 void DownloadItemNotification::Update() {
322 auto download_state = item_->GetState(); 322 auto download_state = item_->GetState();
323 323
324 // When the download is just completed, interrupted or transitions to 324 // When the download is just completed, interrupted or transitions to
325 // dangerous, close the notification once and re-show it immediately so 325 // dangerous, close the notification once and re-show it immediately so
326 // it'll pop up. 326 // it'll pop up.
327 bool popup = 327 bool popup =
328 ((item_->IsDangerous() && !previous_dangerous_state_) || 328 ((item_->IsDangerous() && !previous_dangerous_state_) ||
329 (download_state == content::DownloadItem::COMPLETE && 329 (download_state == content::DownloadItem::COMPLETE &&
330 previous_download_state_ != content::DownloadItem::COMPLETE) || 330 previous_download_state_ != content::DownloadItem::COMPLETE) ||
331 (download_state == content::DownloadItem::INTERRUPTED && 331 (download_state == content::DownloadItem::INTERRUPTED &&
332 previous_download_state_ != content::DownloadItem::INTERRUPTED)); 332 previous_download_state_ != content::DownloadItem::INTERRUPTED));
333 333
334 if (IsNotificationVisible()) { 334 if (visible_) {
335 UpdateNotificationData(popup ? UPDATE_AND_POPUP : UPDATE); 335 UpdateNotificationData(popup ? UPDATE_AND_POPUP : UPDATE);
336 } else { 336 } else {
337 if (show_next_ || popup) 337 if (show_next_ || popup) {
338 UpdateNotificationData(ADD); 338 UpdateNotificationData(ADD);
339 visible_ = true;
340 }
339 } 341 }
340 342
341 show_next_ = false; 343 show_next_ = false;
342 previous_download_state_ = item_->GetState(); 344 previous_download_state_ = item_->GetState();
343 previous_dangerous_state_ = item_->IsDangerous(); 345 previous_dangerous_state_ = item_->IsDangerous();
344 } 346 }
345 347
346 void DownloadItemNotification::UpdateNotificationData( 348 void DownloadItemNotification::UpdateNotificationData(
347 NotificationUpdateType type) { 349 NotificationUpdateType type) {
348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 Add(*notification_, profile()); 422 Add(*notification_, profile());
421 } else if (type == UPDATE || 423 } else if (type == UPDATE ||
422 // If the notification is already visible as popup or in the 424 // If the notification is already visible as popup or in the
423 // notification center, doesn't pop it up. 425 // notification center, doesn't pop it up.
424 (type == UPDATE_AND_POPUP && IsNotificationVisible())) { 426 (type == UPDATE_AND_POPUP && IsNotificationVisible())) {
425 // Shows a notifiation as progress type once so the visible content will be 427 // Shows a notifiation as progress type once so the visible content will be
426 // updated. Only progress-type notification's content will be updated 428 // updated. Only progress-type notification's content will be updated
427 // immediately when the message center is visible. 429 // immediately when the message center is visible.
428 // See the comment in MessageCenterImpl::UpdateNotification() for detail. 430 // See the comment in MessageCenterImpl::UpdateNotification() for detail.
429 if (type == UPDATE_AND_POPUP && 431 if (type == UPDATE_AND_POPUP &&
430 message_center_->IsMessageCenterVisible() && 432 g_browser_process->message_center()->IsMessageCenterVisible() &&
431 (item_->GetState() == content::DownloadItem::COMPLETE || 433 (item_->GetState() == content::DownloadItem::COMPLETE ||
432 item_->GetState() == content::DownloadItem::INTERRUPTED)) { 434 item_->GetState() == content::DownloadItem::INTERRUPTED)) {
433 DCHECK_EQ(notification_->type(), 435 DCHECK_EQ(notification_->type(),
434 message_center::NOTIFICATION_TYPE_BASE_FORMAT); 436 message_center::NOTIFICATION_TYPE_BASE_FORMAT);
435 437
436 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS); 438 notification_->set_type(message_center::NOTIFICATION_TYPE_PROGRESS);
437 g_browser_process->notification_ui_manager()-> 439 g_browser_process->notification_ui_manager()->
438 Update(*notification_, profile()); 440 Update(*notification_, profile());
439 notification_->set_type(message_center::NOTIFICATION_TYPE_BASE_FORMAT); 441 notification_->set_type(message_center::NOTIFICATION_TYPE_BASE_FORMAT);
440 } 442 }
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 return browser_displayer.browser(); 894 return browser_displayer.browser();
893 } 895 }
894 896
895 Profile* DownloadItemNotification::profile() const { 897 Profile* DownloadItemNotification::profile() const {
896 return Profile::FromBrowserContext(item_->GetBrowserContext()); 898 return Profile::FromBrowserContext(item_->GetBrowserContext());
897 } 899 }
898 900
899 bool DownloadItemNotification::IsNotificationVisible() const { 901 bool DownloadItemNotification::IsNotificationVisible() const {
900 const std::string& notification_id = watcher()->id(); 902 const std::string& notification_id = watcher()->id();
901 const ProfileID profile_id = NotificationUIManager::GetProfileID(profile()); 903 const ProfileID profile_id = NotificationUIManager::GetProfileID(profile());
902 if (!g_browser_process->notification_ui_manager()) 904 const std::string notification_id_in_message_center =
903 return false; 905 ProfileNotification::GetProfileNotificationId(notification_id,
904 const Notification* notification = g_browser_process-> 906 profile_id);
905 notification_ui_manager()->FindById(notification_id, profile_id);
906 if (!notification)
907 return false;
908
909 const std::string notification_id_in_message_center = notification->id();
910 907
911 message_center::NotificationList::Notifications visible_notifications = 908 message_center::NotificationList::Notifications visible_notifications =
912 message_center_->GetVisibleNotifications(); 909 g_browser_process->message_center()->GetVisibleNotifications();
913 for (const auto& notification : visible_notifications) { 910 for (const auto& notification : visible_notifications) {
914 if (notification->id() == notification_id_in_message_center) 911 if (notification->id() == notification_id_in_message_center)
915 return true; 912 return true;
916 } 913 }
917 return false; 914 return false;
918 } 915 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698