1 // Copyright 2014 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 #ifndef CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ 6 #define CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ 7 8 #include <stdint.h> 9 10 #include <memory> 11 #include <set> 12 #include <string> 13 #include <vector> 14 15 #include "base/callback_forward.h" 16 #include "base/time/time.h" 17 #include "content/common/content_export.h" 18 #include "content/public/browser/notification_database_data.h" 19 #include "third_party/blink/public/mojom/permissions/permission_status.mojom.h" 20 21 class GURL; 22 23 namespace blink { 24 struct NotificationResources; 25 struct PlatformNotificationData; 26 } // namespace blink 27 28 namespace content { 29 30 // The service using which notifications can be presented to the user. There 31 // should be a unique instance of the PlatformNotificationService depending 32 // on the browsing context being used. 33 class CONTENT_EXPORT PlatformNotificationService { 34 public: ~PlatformNotificationService()35 virtual ~PlatformNotificationService() {} 36 37 using DisplayedNotificationsCallback = 38 base::OnceCallback<void(std::set<std::string>, 39 bool /* supports synchronization */)>; 40 41 // Displays the notification described in |notification_data| to the user. 42 // This method must be called on the UI thread. 43 virtual void DisplayNotification( 44 const std::string& notification_id, 45 const GURL& origin, 46 const blink::PlatformNotificationData& notification_data, 47 const blink::NotificationResources& notification_resources) = 0; 48 49 // Displays the persistent notification described in |notification_data| to 50 // the user. This method must be called on the UI thread. 51 virtual void DisplayPersistentNotification( 52 const std::string& notification_id, 53 const GURL& service_worker_origin, 54 const GURL& origin, 55 const blink::PlatformNotificationData& notification_data, 56 const blink::NotificationResources& notification_resources) = 0; 57 58 // Closes the notification identified by |notification_id|. This method must 59 // be called on the UI thread. 60 virtual void CloseNotification(const std::string& notification_id) = 0; 61 62 // Closes the persistent notification identified by |notification_id|. This 63 // method must be called on the UI thread. 64 virtual void ClosePersistentNotification( 65 const std::string& notification_id) = 0; 66 67 // Retrieves the ids of all currently displaying notifications and 68 // posts |callback| with the result. 69 virtual void GetDisplayedNotifications( 70 DisplayedNotificationsCallback callback) = 0; 71 72 // Schedules a job to run at |timestamp| and call TriggerNotifications 73 // on all PlatformNotificationContext instances. 74 virtual void ScheduleTrigger(base::Time timestamp) = 0; 75 76 // Reads the value of the next notification trigger time for this profile. 77 // This will return base::Time::Max if there is no trigger set. 78 virtual base::Time ReadNextTriggerTimestamp() = 0; 79 80 // Reads the value of the next persistent notification ID from the profile and 81 // increments the value, as it is called once per notification write. 82 virtual int64_t ReadNextPersistentNotificationId() = 0; 83 84 // Records a given notification to UKM. 85 virtual void RecordNotificationUkmEvent( 86 const NotificationDatabaseData& data) = 0; 87 }; 88 89 } // namespace content 90 91 #endif // CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ 92