| Index: content/renderer/notifications/notification_service_worker_client_impl.cc
|
| diff --git a/content/renderer/notifications/notification_service_worker_client_impl.cc b/content/renderer/notifications/notification_service_worker_client_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..821910136957ae8513f5dddb115e6296a5c991ab
|
| --- /dev/null
|
| +++ b/content/renderer/notifications/notification_service_worker_client_impl.cc
|
| @@ -0,0 +1,78 @@
|
| +// 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.
|
| +
|
| +#include "content/renderer/notifications/notification_service_worker_client_impl.h"
|
| +
|
| +#include "base/logging.h"
|
| +#include "content/renderer/service_worker/service_worker_context_client.h"
|
| +#include "third_party/WebKit/public/platform/Platform.h"
|
| +#include "third_party/WebKit/public/platform/WebThread.h"
|
| +#include "third_party/WebKit/public/platform/modules/notifications/notification.mojom-blink.h"
|
| +
|
| +namespace content {
|
| +
|
| +namespace {
|
| +
|
| +// Converts |status| to the Blink variant of the enum and invokes the |callback|
|
| +// with the result of the conversion.
|
| +void ConvertToBlinkStatus(
|
| + const mojo::Callback<void(mojom::blink::ServiceWorkerEventStatus)>&
|
| + callback,
|
| + mojom::ServiceWorkerEventStatus status) {
|
| + callback.Run(static_cast<mojom::blink::ServiceWorkerEventStatus>(status));
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +// static
|
| +void NotificationServiceWorkerClientImpl::Create(
|
| + mojo::InterfaceRequest<mojom::blink::NotificationServiceWorkerClient>
|
| + request) {
|
| + new NotificationServiceWorkerClientImpl(std::move(request));
|
| +}
|
| +
|
| +NotificationServiceWorkerClientImpl::NotificationServiceWorkerClientImpl(
|
| + mojo::InterfaceRequest<mojom::blink::NotificationServiceWorkerClient>
|
| + request)
|
| + : binding_(this, std::move(request)) {}
|
| +
|
| +NotificationServiceWorkerClientImpl::~NotificationServiceWorkerClientImpl() {}
|
| +
|
| +void NotificationServiceWorkerClientImpl::Click(
|
| + blink::mojom::blink::NotificationPtr notification,
|
| + int32_t action_index,
|
| + const ClickCallback& callback) {
|
| + DCHECK(!blink::Platform::current()->mainThread()->isCurrentThread());
|
| +
|
| + ServiceWorkerContextClient* client =
|
| + ServiceWorkerContextClient::ThreadSpecificInstance();
|
| +
|
| + if (!client) {
|
| + callback.Run(mojom::blink::ServiceWorkerEventStatus::ABORTED);
|
| + return;
|
| + }
|
| +
|
| + client->DispatchNotificationClickEvent(
|
| + std::move(notification), action_index,
|
| + base::Bind(&ConvertToBlinkStatus, callback));
|
| +}
|
| +
|
| +void NotificationServiceWorkerClientImpl::Close(
|
| + blink::mojom::blink::NotificationPtr notification,
|
| + const CloseCallback& callback) {
|
| + DCHECK(!blink::Platform::current()->mainThread()->isCurrentThread());
|
| +
|
| + ServiceWorkerContextClient* client =
|
| + ServiceWorkerContextClient::ThreadSpecificInstance();
|
| +
|
| + if (!client) {
|
| + callback.Run(mojom::blink::ServiceWorkerEventStatus::ABORTED);
|
| + return;
|
| + }
|
| +
|
| + client->DispatchNotificationCloseEvent(
|
| + std::move(notification), base::Bind(&ConvertToBlinkStatus, callback));
|
| +}
|
| +
|
| +} // namespace content
|
|
|