OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/notifications/in_page_notification_handler.h" |
| 6 #include "chrome/browser/notifications/notification.h" |
| 7 #include "chrome/browser/notifications/notification_delegate.h" |
| 8 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 9 |
| 10 InPageNotificationHandler::InPageNotificationHandler() {} |
| 11 InPageNotificationHandler::~InPageNotificationHandler() {} |
| 12 |
| 13 void InPageNotificationHandler::HandleNotificationOperation( |
| 14 notification_operation_common::NotificationOperation operation, |
| 15 Profile* profile, |
| 16 const std::string& origin, |
| 17 const std::string& notification_id, |
| 18 int action_index) { |
| 19 if (notifications_.find(notification_id) != notifications_.end()) { |
| 20 switch (operation) { |
| 21 case notification_operation_common::NOTIFICATION_CLICK: |
| 22 notifications_[notification_id]->delegate()->Click(); |
| 23 break; |
| 24 case notification_operation_common::NOTIFICATION_CLOSE: |
| 25 notifications_[notification_id]->delegate()->Close(true /* by user */); |
| 26 notifications_.erase(notification_id); |
| 27 break; |
| 28 case notification_operation_common::NOTIFICATION_SETTINGS: |
| 29 notification_operation_common::OpenNotificationSettings(profile); |
| 30 break; |
| 31 } |
| 32 } |
| 33 } |
| 34 |
| 35 void InPageNotificationHandler::RegisterNotification( |
| 36 const std::string& notification_id, |
| 37 std::unique_ptr<Notification> notification) { |
| 38 DCHECK_EQ(notifications_.count(notification_id), 0u); |
| 39 notifications_[notification_id] = std::move(notification); |
| 40 } |
| 41 |
| 42 void InPageNotificationHandler::CloseNotification( |
| 43 Profile* profile, |
| 44 const std::string& notification_id) { |
| 45 if (notifications_.find(notification_id) != notifications_.end()) { |
| 46 notifications_[notification_id]->delegate()->Close(false /* by user */); |
| 47 notifications_.erase(notification_id); |
| 48 } |
| 49 } |
| 50 |
| 51 notification_operation_common::NotificationHandlerType |
| 52 InPageNotificationHandler::NotificationType() { |
| 53 return notification_operation_common::INPAGE_NOTIFICATION; |
| 54 } |
OLD | NEW |