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