| Index: content/browser/notifications/blink_notification_service_impl.h
|
| diff --git a/content/browser/notifications/blink_notification_service_impl.h b/content/browser/notifications/blink_notification_service_impl.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e1dc4c83ffa264b5704cdc36e5e3879f941ef4e9
|
| --- /dev/null
|
| +++ b/content/browser/notifications/blink_notification_service_impl.h
|
| @@ -0,0 +1,129 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef CONTENT_BROWSER_NOTIFICATIONS_BLINK_NOTIFICATION_SERVICE_IMPL_H_
|
| +#define CONTENT_BROWSER_NOTIFICATIONS_BLINK_NOTIFICATION_SERVICE_IMPL_H_
|
| +
|
| +#include <stdint.h>
|
| +#include <memory>
|
| +#include <unordered_map>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/macros.h"
|
| +#include "base/memory/weak_ptr.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| +#include "mojo/public/cpp/bindings/interface_request.h"
|
| +#include "third_party/WebKit/public/platform/modules/notifications/notification_service.mojom.h"
|
| +
|
| +class GURL;
|
| +
|
| +namespace content {
|
| +
|
| +class BrowserContext;
|
| +struct NotificationDatabaseData;
|
| +class NotificationIdGenerator;
|
| +class PlatformNotificationContextImpl;
|
| +class PlatformNotificationService;
|
| +class ResourceContext;
|
| +
|
| +// Implementation of the NotificationService used for Web Notifications. Is
|
| +// responsible for displaying, updating and reading of both non-persistent
|
| +// and persistent notifications. Lives on the IO thread.
|
| +class BlinkNotificationServiceImpl : public blink::mojom::NotificationService {
|
| + public:
|
| + BlinkNotificationServiceImpl(
|
| + PlatformNotificationContextImpl* notification_context,
|
| + BrowserContext* browser_context,
|
| + ResourceContext* resource_context,
|
| + int render_process_id,
|
| + mojo::InterfaceRequest<blink::mojom::NotificationService> request);
|
| + ~BlinkNotificationServiceImpl() override;
|
| +
|
| + // blink::mojom::NotificationService implementation.
|
| + void GetPermissionStatus(
|
| + const mojo::String& origin,
|
| + const GetPermissionStatusCallback& callback) override;
|
| + void Display(const mojo::String& origin,
|
| + blink::mojom::NotificationPtr notification,
|
| + blink::mojom::NotificationResourcesPtr notification_resources,
|
| + blink::mojom::NotificationClientPtr notification_client,
|
| + const DisplayCallback& callback) override;
|
| + void DisplayPersistent(
|
| + const mojo::String& origin,
|
| + int64_t service_worker_registration_id,
|
| + blink::mojom::NotificationPtr notification,
|
| + blink::mojom::NotificationResourcesPtr notification_resources,
|
| + const DisplayPersistentCallback& callback) override;
|
| + void GetNotifications(const mojo::String& origin,
|
| + int64_t service_worker_registration_id,
|
| + const mojo::String& tag,
|
| + const GetNotificationsCallback& callback) override;
|
| + void Close(const mojo::String& origin,
|
| + const mojo::String& notification_id,
|
| + const CloseCallback& callback) override;
|
| +
|
| + private:
|
| + // To be called when the non-persistent notification identified by the
|
| + // |notification_id| has been displayed. Will store the |close_closure| so
|
| + // that it can be programmatically closed, and will invoke the |callback|.
|
| + void DidDisplay(const std::string& notification_id,
|
| + std::unique_ptr<base::Closure> close_closure,
|
| + const DisplayCallback& callback);
|
| +
|
| + // To be called when the information associated with a persistent notification
|
| + // has been stored in the database, and is ready to be displayed to the user.
|
| + void DidStorePersistent(
|
| + const GURL& origin,
|
| + blink::mojom::NotificationPtr notification,
|
| + blink::mojom::NotificationResourcesPtr notification_resources,
|
| + const DisplayPersistentCallback& callback,
|
| + bool success,
|
| + int64_t persistent_notification_id);
|
| +
|
| + // To be called when a list of notifications for a given Service Worker has
|
| + // been read from the database, and can be forwarded to |callback|.
|
| + void DidGetNotifications(
|
| + const std::string& tag,
|
| + const GetNotificationsCallback& callback,
|
| + bool success,
|
| + const std::vector<NotificationDatabaseData>& notifications);
|
| +
|
| + // To be called when a persistent notification has been closed and removed
|
| + // from the notification database.
|
| + void DidClosePersistent(const CloseCallback& callback, bool success);
|
| +
|
| + // Called when an error is detected on binding_.
|
| + void OnConnectionError();
|
| +
|
| + // The platform notification context owns this instance.
|
| + PlatformNotificationContextImpl* notification_context_;
|
| +
|
| + BrowserContext* browser_context_;
|
| + ResourceContext* resource_context_;
|
| +
|
| + int render_process_id_;
|
| +
|
| + // Counter generating IDs unique to this Mojo service for each non-persistent
|
| + // notification that has been shown by websites.
|
| + // TODO(peter): Share a single counter among all Mojo service instances.
|
| + int non_persistent_notification_id_ = 0;
|
| +
|
| + // Generator responsible for creating appropriate Ids for notifications.
|
| + // TODO(peter): Share a single instance among all Mojo service instances.
|
| + std::unique_ptr<NotificationIdGenerator> notification_id_generator_;
|
| +
|
| + // Map of notification Id to closures that enable non-persistent notifications
|
| + // to be closed programmatically by the developer.
|
| + std::unordered_map<std::string, base::Closure> close_closures_;
|
| +
|
| + mojo::Binding<blink::mojom::NotificationService> binding_;
|
| +
|
| + base::WeakPtrFactory<BlinkNotificationServiceImpl> weak_ptr_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(BlinkNotificationServiceImpl);
|
| +};
|
| +
|
| +} // namespace content
|
| +
|
| +#endif // CONTENT_BROWSER_NOTIFICATIONS_BLINK_NOTIFICATION_SERVICE_IMPL_H_
|
|
|