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

Side by Side Diff: ui/message_center/views/message_center_view.cc

Issue 2833403002: [Notifications] Fix crash in AddNotification. (Closed)
Patch Set: Add check back. Created 3 years, 8 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
« no previous file with comments | « ui/message_center/views/message_center_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/message_center/views/message_center_view.h" 5 #include "ui/message_center/views/message_center_view.h"
6 6
7 #include <list> 7 #include <list>
8 #include <map> 8 #include <map>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 if (hover_view->IsMouseHovered()) { 400 if (hover_view->IsMouseHovered()) {
401 message_list_view_->SetRepositionTarget(hover_view->bounds()); 401 message_list_view_->SetRepositionTarget(hover_view->bounds());
402 return true; 402 return true;
403 } 403 }
404 } 404 }
405 } 405 }
406 return false; 406 return false;
407 } 407 }
408 408
409 void MessageCenterView::OnNotificationUpdated(const std::string& id) { 409 void MessageCenterView::OnNotificationUpdated(const std::string& id) {
410 // TODO(edcourtney): We may be able to remove this, since |UpdateNotification|
411 // checks it anyway.
yoshiki 2017/04/25 04:58:00 How about adding NOTREACHED() before return?
Eliot Courtney 2017/04/25 05:06:52 This can still be reached, but it's possible we do
Eliot Courtney 2017/04/25 06:29:12 Discussed offline - added a TODO below to investig
410 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id); 412 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id);
411 if (view_iter == notification_views_.end()) 413 if (view_iter == notification_views_.end())
412 return; 414 return;
413 415
414 // If there is no reposition target anymore, make sure to reset the reposition 416 // If there is no reposition target anymore, make sure to reset the reposition
415 // session. 417 // session.
416 if (!SetRepositionTarget()) 418 if (!SetRepositionTarget())
417 message_list_view_->ResetRepositionSession(); 419 message_list_view_->ResetRepositionSession();
418 420
419 // TODO(dimich): add MessageCenter::GetVisibleNotificationById(id) 421 UpdateNotification(id);
420 MessageView* view = view_iter->second;
421 const NotificationList::Notifications& notifications =
422 message_center_->GetVisibleNotifications();
423 for (NotificationList::Notifications::const_iterator iter =
424 notifications.begin(); iter != notifications.end(); ++iter) {
425 if ((*iter)->id() == id) {
426 int old_width = view->width();
427 int old_height = view->height();
428 bool old_pinned = view->IsPinned();
429 message_list_view_->UpdateNotification(view, **iter);
430 if (view->GetHeightForWidth(old_width) != old_height) {
431 Update(true /* animate */);
432 } else if (view->IsPinned() != old_pinned) {
433 // Animate flag is false, since the pinned flag transition doesn't need
434 // animation.
435 Update(false /* animate */);
436 }
437 break;
438 }
439 }
440
441 // Notify accessibility that the contents have changed.
442 view->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false);
443 } 422 }
444 423
445 void MessageCenterView::OnLockedStateChanged(bool locked) { 424 void MessageCenterView::OnLockedStateChanged(bool locked) {
446 is_locked_ = locked; 425 is_locked_ = locked;
447 UpdateButtonBarStatus(); 426 UpdateButtonBarStatus();
448 Update(true /* animate */); 427 Update(true /* animate */);
449 } 428 }
450 429
451 void MessageCenterView::ClickOnNotification( 430 void MessageCenterView::ClickOnNotification(
452 const std::string& notification_id) { 431 const std::string& notification_id) {
(...skipping 21 matching lines...) Expand all
474 message_center_->ClickOnNotificationButton(notification_id, button_index); 453 message_center_->ClickOnNotificationButton(notification_id, button_index);
475 } 454 }
476 455
477 void MessageCenterView::ClickOnSettingsButton( 456 void MessageCenterView::ClickOnSettingsButton(
478 const std::string& notification_id) { 457 const std::string& notification_id) {
479 message_center_->ClickOnSettingsButton(notification_id); 458 message_center_->ClickOnSettingsButton(notification_id);
480 } 459 }
481 460
482 void MessageCenterView::UpdateNotificationSize( 461 void MessageCenterView::UpdateNotificationSize(
483 const std::string& notification_id) { 462 const std::string& notification_id) {
484 OnNotificationUpdated(notification_id); 463 // TODO(edcourtney, yoshiki): We don't call OnNotificationUpdated directly
464 // because it resets the reposition session, which can end up deleting
465 // notification items when it cancels animations. This causes problems for
466 // ARC notifications. See crbug.com/714493. OnNotificationUpdated should not
467 // have to consider the reposition session, but OnMouseEntered and
468 // OnMouseExited don't work properly for ARC notifications at the moment.
469 // See crbug.com/714587.
470 UpdateNotification(notification_id);
485 } 471 }
486 472
487 void MessageCenterView::AnimationEnded(const gfx::Animation* animation) { 473 void MessageCenterView::AnimationEnded(const gfx::Animation* animation) {
488 DCHECK_EQ(animation, settings_transition_animation_.get()); 474 DCHECK_EQ(animation, settings_transition_animation_.get());
489 475
490 Visibility visibility = 476 Visibility visibility =
491 mode_ == Mode::SETTINGS ? VISIBILITY_SETTINGS : VISIBILITY_MESSAGE_CENTER; 477 mode_ == Mode::SETTINGS ? VISIBILITY_SETTINGS : VISIBILITY_MESSAGE_CENTER;
492 message_center_->SetVisibility(visibility); 478 message_center_->SetVisibility(visibility);
493 479
494 if (source_view_) { 480 if (source_view_) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } else { 652 } else {
667 // Disable the close-all button since no notification is visible. 653 // Disable the close-all button since no notification is visible.
668 button_bar_->SetCloseAllButtonEnabled(false); 654 button_bar_->SetCloseAllButtonEnabled(false);
669 } 655 }
670 } 656 }
671 657
672 void MessageCenterView::SetNotificationViewForTest(MessageView* view) { 658 void MessageCenterView::SetNotificationViewForTest(MessageView* view) {
673 message_list_view_->AddNotificationAt(view, 0); 659 message_list_view_->AddNotificationAt(view, 0);
674 } 660 }
675 661
662 void MessageCenterView::UpdateNotification(const std::string& id) {
663 NotificationViewsMap::const_iterator view_iter = notification_views_.find(id);
664 if (view_iter == notification_views_.end())
665 return;
yoshiki 2017/04/25 04:58:01 This should also not be happened. How about adding
Eliot Courtney 2017/04/25 05:06:52 I believe this can happen when ResetRepositionSess
Eliot Courtney 2017/04/25 06:29:12 I investigated a bit, and it seems that when close
666
667 // TODO(dimich): add MessageCenter::GetVisibleNotificationById(id)
668 MessageView* view = view_iter->second;
669 const NotificationList::Notifications& notifications =
670 message_center_->GetVisibleNotifications();
671 for (NotificationList::Notifications::const_iterator iter =
672 notifications.begin();
673 iter != notifications.end(); ++iter) {
674 if ((*iter)->id() == id) {
675 int old_width = view->width();
676 int old_height = view->height();
677 bool old_pinned = view->IsPinned();
678 message_list_view_->UpdateNotification(view, **iter);
679 if (view->GetHeightForWidth(old_width) != old_height) {
680 Update(true /* animate */);
681 } else if (view->IsPinned() != old_pinned) {
682 // Animate flag is false, since the pinned flag transition doesn't need
683 // animation.
684 Update(false /* animate */);
685 }
686 break;
687 }
688 }
689
690 // Notify accessibility that the contents have changed.
691 view->NotifyAccessibilityEvent(ui::AX_EVENT_CHILDREN_CHANGED, false);
692 }
693
676 } // namespace message_center 694 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/message_center_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698