diff options
| author | yoshiki <yoshiki@chromium.org> | 2016-02-16 20:14:06 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-02-17 04:15:10 +0000 |
| commit | bce73718a5bdfad0dc9cf25222831ddf4c18fef2 (patch) | |
| tree | a5c5a700bf671f2a91b180f8b33e2eb19a7f54b0 | |
| parent | ee661c5a28eda6083182013b5b3dae7d178be201 (diff) | |
| download | chromium_src-bce73718a5bdfad0dc9cf25222831ddf4c18fef2.zip chromium_src-bce73718a5bdfad0dc9cf25222831ddf4c18fef2.tar.gz chromium_src-bce73718a5bdfad0dc9cf25222831ddf4c18fef2.tar.bz2 | |
ARC Notification: Fix crash on shutdown
The ARC services may quit earlier than notifications, so we need to check if the services has quitted or not before handling events.
BUG=b/27138093
TEST=none
Review URL: https://codereview.chromium.org/1701873002
Cr-Commit-Position: refs/heads/master@{#375783}
| -rw-r--r-- | ui/arc/notification/arc_notification_manager.cc | 49 | ||||
| -rw-r--r-- | ui/arc/notification/arc_notification_manager.h | 1 |
2 files changed, 39 insertions, 11 deletions
diff --git a/ui/arc/notification/arc_notification_manager.cc b/ui/arc/notification/arc_notification_manager.cc index 8221670..a98db94 100644 --- a/ui/arc/notification/arc_notification_manager.cc +++ b/ui/arc/notification/arc_notification_manager.cc @@ -22,8 +22,7 @@ ArcNotificationManager::~ArcNotificationManager() { } void ArcNotificationManager::OnNotificationsInstanceReady() { - NotificationsInstance* notifications_instance = - arc_bridge_service()->notifications_instance(); + auto notifications_instance = arc_bridge_service()->notifications_instance(); if (!notifications_instance) { VLOG(2) << "Request to refresh app list when bridge service is not ready."; return; @@ -32,6 +31,10 @@ void ArcNotificationManager::OnNotificationsInstanceReady() { notifications_instance->Init(binding_.CreateInterfacePtrAndBind()); } +void ArcNotificationManager::OnNotificationsInstanceClosed() { + // TODO(yoshiki): Handle this. +} + void ArcNotificationManager::OnNotificationPosted(ArcNotificationDataPtr data) { ArcNotificationItem* item = items_.get(data->key); if (!item) { @@ -65,11 +68,19 @@ void ArcNotificationManager::SendNotificationRemovedFromChrome( return; } - scoped_ptr<ArcNotificationItem> item(items_.take_and_erase(it)); + items_.erase(it); - arc_bridge_service() - ->notifications_instance() - ->SendNotificationEventToAndroid(key, ArcNotificationEvent::CLOSED); + auto notifications_instance = arc_bridge_service()->notifications_instance(); + + // On shutdown, the ARC channel may quit earlier then notifications. + if (!notifications_instance) { + VLOG(2) << "ARC Notification (key: " << key + << ") is closed, but the ARC channel has already gone."; + return; + } + + notifications_instance->SendNotificationEventToAndroid( + key, ArcNotificationEvent::CLOSED); } void ArcNotificationManager::SendNotificationClickedOnChrome( @@ -80,9 +91,17 @@ void ArcNotificationManager::SendNotificationClickedOnChrome( return; } - arc_bridge_service() - ->notifications_instance() - ->SendNotificationEventToAndroid(key, ArcNotificationEvent::BODY_CLICKED); + auto notifications_instance = arc_bridge_service()->notifications_instance(); + + // On shutdown, the ARC channel may quit earlier then notifications. + if (!notifications_instance) { + VLOG(2) << "ARC Notification (key: " << key + << ") is clicked, but the ARC channel has already gone."; + return; + } + + notifications_instance->SendNotificationEventToAndroid( + key, ArcNotificationEvent::BODY_CLICKED); } void ArcNotificationManager::SendNotificationButtonClickedOnChrome( @@ -93,6 +112,15 @@ void ArcNotificationManager::SendNotificationButtonClickedOnChrome( return; } + auto notifications_instance = arc_bridge_service()->notifications_instance(); + + // On shutdown, the ARC channel may quit earlier then notifications. + if (!notifications_instance) { + VLOG(2) << "ARC Notification (key: " << key + << ")'s button is clicked, but the ARC channel has already gone."; + return; + } + arc::ArcNotificationEvent command; switch (button_index) { case 0: @@ -116,8 +144,7 @@ void ArcNotificationManager::SendNotificationButtonClickedOnChrome( return; } - arc_bridge_service() - ->notifications_instance()->SendNotificationEventToAndroid(key, command); + notifications_instance->SendNotificationEventToAndroid(key, command); } } // namespace arc diff --git a/ui/arc/notification/arc_notification_manager.h b/ui/arc/notification/arc_notification_manager.h index 1d46b8f..008cfda 100644 --- a/ui/arc/notification/arc_notification_manager.h +++ b/ui/arc/notification/arc_notification_manager.h @@ -29,6 +29,7 @@ class ArcNotificationManager : public ArcService, // ArcBridgeService::Observer implementation: void OnNotificationsInstanceReady() override; + void OnNotificationsInstanceClosed() override; // NotificationsHost implementation: void OnNotificationPosted(ArcNotificationDataPtr data) override; |
