| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_STUB_NOTIFICATION_DISPLAY_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_STUB_NOTIFICATION_DISPLAY_SERVICE_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_STUB_NOTIFICATION_DISPLAY_SERVICE_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_STUB_NOTIFICATION_DISPLAY_SERVICE_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
| 14 #include "chrome/browser/notifications/notification_common.h" | 14 #include "chrome/browser/notifications/notification_common.h" |
| 15 #include "chrome/browser/notifications/notification_display_service.h" | 15 #include "chrome/browser/notifications/notification_display_service.h" |
| 16 | 16 |
| 17 class Profile; |
| 18 |
| 17 // Implementation of the NotificationDisplayService interface that can be used | 19 // Implementation of the NotificationDisplayService interface that can be used |
| 18 // for testing purposes. Supports additional methods enabling instrumenting the | 20 // for testing purposes. Supports additional methods enabling instrumenting the |
| 19 // faked underlying notification system. | 21 // faked underlying notification system. |
| 20 class StubNotificationDisplayService : public NotificationDisplayService { | 22 class StubNotificationDisplayService : public NotificationDisplayService { |
| 21 public: | 23 public: |
| 22 // Factory function to be used with NotificationDisplayServiceFactory's | 24 // Factory function to be used with NotificationDisplayServiceFactory's |
| 23 // SetTestingFactory method, overriding the default display service. | 25 // SetTestingFactory method, overriding the default display service. |
| 24 static std::unique_ptr<KeyedService> FactoryForTests( | 26 static std::unique_ptr<KeyedService> FactoryForTests( |
| 25 content::BrowserContext* browser_context); | 27 content::BrowserContext* browser_context); |
| 26 | 28 |
| 27 StubNotificationDisplayService(); | 29 explicit StubNotificationDisplayService(Profile* profile); |
| 28 ~StubNotificationDisplayService() override; | 30 ~StubNotificationDisplayService() override; |
| 29 | 31 |
| 30 // Removes the notification identified by |notification_id|. | 32 // Removes the notification identified by |notification_id|. |
| 31 void RemoveNotification(NotificationCommon::Type notification_type, | 33 void RemoveNotification(NotificationCommon::Type notification_type, |
| 32 const std::string& notification_id, | 34 const std::string& notification_id, |
| 33 bool by_user); | 35 bool by_user); |
| 34 | 36 |
| 35 // Removes all notifications shown by this display service. | 37 // Removes all notifications shown by this display service. |
| 36 void RemoveAllNotifications(NotificationCommon::Type notification_type, | 38 void RemoveAllNotifications(NotificationCommon::Type notification_type, |
| 37 bool by_user); | 39 bool by_user); |
| 38 | 40 |
| 39 // NotificationDisplayService implementation: | 41 // NotificationDisplayService implementation: |
| 40 void Display(NotificationCommon::Type notification_type, | 42 void Display(NotificationCommon::Type notification_type, |
| 41 const std::string& notification_id, | 43 const std::string& notification_id, |
| 42 const Notification& notification) override; | 44 const Notification& notification) override; |
| 43 void Close(NotificationCommon::Type notification_type, | 45 void Close(NotificationCommon::Type notification_type, |
| 44 const std::string& notification_id) override; | 46 const std::string& notification_id) override; |
| 45 void GetDisplayed(const DisplayedNotificationsCallback& callback) override; | 47 void GetDisplayed(const DisplayedNotificationsCallback& callback) override; |
| 46 | 48 |
| 47 private: | 49 private: |
| 48 // Data to store for a notification that's being shown through this service. | 50 // Data to store for a notification that's being shown through this service. |
| 49 using NotificationData = std::pair<NotificationCommon::Type, Notification>; | 51 using NotificationData = std::pair<NotificationCommon::Type, Notification>; |
| 50 | 52 |
| 51 std::vector<NotificationData> notifications_; | 53 std::vector<NotificationData> notifications_; |
| 52 | 54 |
| 53 DISALLOW_COPY_AND_ASSIGN(StubNotificationDisplayService); | 55 DISALLOW_COPY_AND_ASSIGN(StubNotificationDisplayService); |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 #endif // CHROME_BROWSER_NOTIFICATIONS_STUB_NOTIFICATION_DISPLAY_SERVICE_H_ | 58 #endif // CHROME_BROWSER_NOTIFICATIONS_STUB_NOTIFICATION_DISPLAY_SERVICE_H_ |
| OLD | NEW |