| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/notifications/non_persistent_notification_handler.h" | 5 #include "chrome/browser/notifications/non_persistent_notification_handler.h" |
| 6 | 6 |
| 7 #include "base/strings/nullable_string16.h" | 7 #include "base/strings/nullable_string16.h" |
| 8 #include "chrome/browser/notifications/notification_delegate.h" | 8 #include "chrome/browser/notifications/notification_delegate.h" |
| 9 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 9 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 10 | 10 |
| 11 NonPersistentNotificationHandler::NonPersistentNotificationHandler() {} | 11 NonPersistentNotificationHandler::NonPersistentNotificationHandler() = default; |
| 12 NonPersistentNotificationHandler::~NonPersistentNotificationHandler() {} | 12 NonPersistentNotificationHandler::~NonPersistentNotificationHandler() = default; |
| 13 | 13 |
| 14 void NonPersistentNotificationHandler::OnClose( | 14 void NonPersistentNotificationHandler::OnClose( |
| 15 Profile* profile, | 15 Profile* profile, |
| 16 const std::string& origin, | 16 const std::string& origin, |
| 17 const std::string& notification_id, | 17 const std::string& notification_id, |
| 18 bool by_user) { | 18 bool by_user) { |
| 19 if (notifications_.find(notification_id) != notifications_.end()) { | 19 if (notifications_.find(notification_id) != notifications_.end()) { |
| 20 notifications_[notification_id]->Close(by_user); | 20 notifications_[notification_id]->Close(by_user); |
| 21 notifications_.erase(notification_id); | 21 notifications_.erase(notification_id); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 void NonPersistentNotificationHandler::OnClick( | 25 void NonPersistentNotificationHandler::OnClick( |
| 26 Profile* profile, | 26 Profile* profile, |
| 27 const std::string& origin, | 27 const std::string& origin, |
| 28 const std::string& notification_id, | 28 const std::string& notification_id, |
| 29 int action_index, | 29 int action_index, |
| 30 const base::NullableString16& reply) { | 30 const base::NullableString16& reply) { |
| 31 // Buttons and replies not supported for non persistent notifications. | |
| 32 DCHECK_EQ(action_index, -1); | |
| 33 DCHECK(reply.is_null()); | 31 DCHECK(reply.is_null()); |
| 34 | 32 |
| 35 if (notifications_.find(notification_id) != notifications_.end()) { | 33 if (notifications_.find(notification_id) != notifications_.end()) { |
| 36 notifications_[notification_id]->Click(); | 34 notifications_[notification_id]->Click(); |
| 37 } | 35 } |
| 38 } | 36 } |
| 39 | 37 |
| 40 void NonPersistentNotificationHandler::OpenSettings(Profile* profile) { | 38 void NonPersistentNotificationHandler::OpenSettings(Profile* profile) { |
| 41 NotificationCommon::OpenNotificationSettings(profile); | 39 NotificationCommon::OpenNotificationSettings(profile); |
| 42 } | 40 } |
| 43 | 41 |
| 44 void NonPersistentNotificationHandler::RegisterNotification( | 42 void NonPersistentNotificationHandler::RegisterNotification( |
| 45 const std::string& notification_id, | 43 const std::string& notification_id, |
| 46 NotificationDelegate* delegate) { | 44 NotificationDelegate* delegate) { |
| 47 DCHECK_EQ(notifications_.count(notification_id), 0u); | 45 DCHECK_EQ(notifications_.count(notification_id), 0u); |
| 48 notifications_[notification_id] = | 46 notifications_[notification_id] = |
| 49 scoped_refptr<NotificationDelegate>(delegate); | 47 scoped_refptr<NotificationDelegate>(delegate); |
| 50 } | 48 } |
| OLD | NEW |