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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "chrome/browser/notifications/message_center_display_service.h" | 8 #include "chrome/browser/notifications/message_center_display_service.h" |
9 | 9 |
10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
| 11 #include "chrome/browser/notifications/notification_handler.h" |
11 #include "chrome/browser/notifications/notification_ui_manager.h" | 12 #include "chrome/browser/notifications/notification_ui_manager.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_event_dispatcher.h" |
14 | 16 |
15 MessageCenterDisplayService::MessageCenterDisplayService( | 17 MessageCenterDisplayService::MessageCenterDisplayService( |
16 Profile* profile, | 18 Profile* profile, |
17 NotificationUIManager* ui_manager) | 19 NotificationUIManager* ui_manager) |
18 : NotificationDisplayService(profile), | 20 : NotificationDisplayService(profile), |
19 profile_(profile), | 21 profile_(profile), |
20 ui_manager_(ui_manager) {} | 22 ui_manager_(ui_manager) {} |
21 | 23 |
22 MessageCenterDisplayService::~MessageCenterDisplayService() {} | 24 MessageCenterDisplayService::~MessageCenterDisplayService() {} |
23 | 25 |
24 void MessageCenterDisplayService::Display( | 26 void MessageCenterDisplayService::Display( |
25 NotificationCommon::Type notification_type, | 27 NotificationCommon::Type notification_type, |
26 const std::string& notification_id, | 28 const std::string& notification_id, |
27 const Notification& notification) { | 29 const Notification& notification) { |
28 // TODO(miguelg): MCDS should stop relying on the |notification|'s delegate | 30 // TODO(miguelg): MCDS should stop relying on the |notification|'s delegate |
29 // for Close/Click operations once the Notification object becomes a mojom | 31 // for Close/Click operations once the Notification object becomes a mojom |
30 // type. | 32 // type. |
| 33 |
| 34 NotificationHandler* handler = GetNotificationHandler(notification_type); |
| 35 handler->OnShow(profile_, notification_id); |
31 ui_manager_->Add(notification, profile_); | 36 ui_manager_->Add(notification, profile_); |
32 } | 37 } |
33 | 38 |
34 void MessageCenterDisplayService::Close( | 39 void MessageCenterDisplayService::Close( |
35 NotificationCommon::Type notification_type, | 40 NotificationCommon::Type notification_type, |
36 const std::string& notification_id) { | 41 const std::string& notification_id) { |
37 ui_manager_->CancelById(notification_id, | 42 ui_manager_->CancelById(notification_id, |
38 NotificationUIManager::GetProfileID(profile_)); | 43 NotificationUIManager::GetProfileID(profile_)); |
39 } | 44 } |
40 | 45 |
41 void MessageCenterDisplayService::GetDisplayed( | 46 void MessageCenterDisplayService::GetDisplayed( |
42 const DisplayedNotificationsCallback& callback) { | 47 const DisplayedNotificationsCallback& callback) { |
43 auto displayed_notifications = | 48 auto displayed_notifications = |
44 base::MakeUnique<std::set<std::string>>(ui_manager_->GetAllIdsByProfile( | 49 base::MakeUnique<std::set<std::string>>(ui_manager_->GetAllIdsByProfile( |
45 NotificationUIManager::GetProfileID(profile_))); | 50 NotificationUIManager::GetProfileID(profile_))); |
46 | 51 |
47 content::BrowserThread::PostTask( | 52 content::BrowserThread::PostTask( |
48 content::BrowserThread::UI, FROM_HERE, | 53 content::BrowserThread::UI, FROM_HERE, |
49 base::BindOnce(callback, base::Passed(&displayed_notifications), | 54 base::BindOnce(callback, base::Passed(&displayed_notifications), |
50 true /* supports_synchronization */)); | 55 true /* supports_synchronization */)); |
51 } | 56 } |
OLD | NEW |