| 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 #ifndef CONTENT_BROWSER_NOTIFICATIONS_BLINK_NOTIFICATION_SERVICE_IMPL_H_ |
| 6 #define CONTENT_BROWSER_NOTIFICATIONS_BLINK_NOTIFICATION_SERVICE_IMPL_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 #include <memory> |
| 10 #include <unordered_map> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "mojo/public/cpp/bindings/binding.h" |
| 16 #include "mojo/public/cpp/bindings/interface_request.h" |
| 17 #include "third_party/WebKit/public/platform/modules/notifications/notification_
service.mojom.h" |
| 18 |
| 19 class GURL; |
| 20 |
| 21 namespace content { |
| 22 |
| 23 class BrowserContext; |
| 24 struct NotificationDatabaseData; |
| 25 class NotificationIdGenerator; |
| 26 class PlatformNotificationContextImpl; |
| 27 class PlatformNotificationService; |
| 28 class ResourceContext; |
| 29 |
| 30 // Implementation of the NotificationService used for Web Notifications. Is |
| 31 // responsible for displaying, updating and reading of both non-persistent |
| 32 // and persistent notifications. Lives on the IO thread. |
| 33 class BlinkNotificationServiceImpl : public blink::mojom::NotificationService { |
| 34 public: |
| 35 BlinkNotificationServiceImpl( |
| 36 PlatformNotificationContextImpl* notification_context, |
| 37 BrowserContext* browser_context, |
| 38 ResourceContext* resource_context, |
| 39 int render_process_id, |
| 40 mojo::InterfaceRequest<blink::mojom::NotificationService> request); |
| 41 ~BlinkNotificationServiceImpl() override; |
| 42 |
| 43 // blink::mojom::NotificationService implementation. |
| 44 void GetPermissionStatus( |
| 45 const mojo::String& origin, |
| 46 const GetPermissionStatusCallback& callback) override; |
| 47 void Display(const mojo::String& origin, |
| 48 blink::mojom::NotificationPtr notification, |
| 49 blink::mojom::NotificationResourcesPtr notification_resources, |
| 50 blink::mojom::NotificationClientPtr notification_client, |
| 51 const DisplayCallback& callback) override; |
| 52 void DisplayPersistent( |
| 53 const mojo::String& origin, |
| 54 int64_t service_worker_registration_id, |
| 55 blink::mojom::NotificationPtr notification, |
| 56 blink::mojom::NotificationResourcesPtr notification_resources, |
| 57 const DisplayPersistentCallback& callback) override; |
| 58 void GetNotifications(const mojo::String& origin, |
| 59 int64_t service_worker_registration_id, |
| 60 const mojo::String& tag, |
| 61 const GetNotificationsCallback& callback) override; |
| 62 void Close(const mojo::String& origin, |
| 63 const mojo::String& notification_id, |
| 64 const CloseCallback& callback) override; |
| 65 |
| 66 private: |
| 67 // To be called when the non-persistent notification identified by the |
| 68 // |notification_id| has been displayed. Will store the |close_closure| so |
| 69 // that it can be programmatically closed, and will invoke the |callback|. |
| 70 void DidDisplay(const std::string& notification_id, |
| 71 std::unique_ptr<base::Closure> close_closure, |
| 72 const DisplayCallback& callback); |
| 73 |
| 74 // To be called when the information associated with a persistent notification |
| 75 // has been stored in the database, and is ready to be displayed to the user. |
| 76 void DidStorePersistent( |
| 77 const GURL& origin, |
| 78 blink::mojom::NotificationPtr notification, |
| 79 blink::mojom::NotificationResourcesPtr notification_resources, |
| 80 const DisplayPersistentCallback& callback, |
| 81 bool success, |
| 82 int64_t persistent_notification_id); |
| 83 |
| 84 // To be called when a list of notifications for a given Service Worker has |
| 85 // been read from the database, and can be forwarded to |callback|. |
| 86 void DidGetNotifications( |
| 87 const std::string& tag, |
| 88 const GetNotificationsCallback& callback, |
| 89 bool success, |
| 90 const std::vector<NotificationDatabaseData>& notifications); |
| 91 |
| 92 // To be called when a persistent notification has been closed and removed |
| 93 // from the notification database. |
| 94 void DidClosePersistent(const CloseCallback& callback, bool success); |
| 95 |
| 96 // Called when an error is detected on binding_. |
| 97 void OnConnectionError(); |
| 98 |
| 99 // The platform notification context owns this instance. |
| 100 PlatformNotificationContextImpl* notification_context_; |
| 101 |
| 102 BrowserContext* browser_context_; |
| 103 ResourceContext* resource_context_; |
| 104 |
| 105 int render_process_id_; |
| 106 |
| 107 // Counter generating IDs unique to this Mojo service for each non-persistent |
| 108 // notification that has been shown by websites. |
| 109 // TODO(peter): Share a single counter among all Mojo service instances. |
| 110 int non_persistent_notification_id_ = 0; |
| 111 |
| 112 // Generator responsible for creating appropriate Ids for notifications. |
| 113 // TODO(peter): Share a single instance among all Mojo service instances. |
| 114 std::unique_ptr<NotificationIdGenerator> notification_id_generator_; |
| 115 |
| 116 // Map of notification Id to closures that enable non-persistent notifications |
| 117 // to be closed programmatically by the developer. |
| 118 std::unordered_map<std::string, base::Closure> close_closures_; |
| 119 |
| 120 mojo::Binding<blink::mojom::NotificationService> binding_; |
| 121 |
| 122 base::WeakPtrFactory<BlinkNotificationServiceImpl> weak_ptr_factory_; |
| 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(BlinkNotificationServiceImpl); |
| 125 }; |
| 126 |
| 127 } // namespace content |
| 128 |
| 129 #endif // CONTENT_BROWSER_NOTIFICATIONS_BLINK_NOTIFICATION_SERVICE_IMPL_H_ |
| OLD | NEW |