| Index: content/browser/service_worker/service_worker_version.h
|
| diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
|
| index db5392c1fcd62226bbc6a6b777293a67979c1e15..8b56be1c3cd9b2496f2112dd18f5fbd69b18a805 100644
|
| --- a/content/browser/service_worker/service_worker_version.h
|
| +++ b/content/browser/service_worker/service_worker_version.h
|
| @@ -36,6 +36,7 @@
|
| #include "ipc/ipc_message.h"
|
| #include "services/shell/public/cpp/interface_provider.h"
|
| #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerEventResult.h"
|
| +#include "third_party/WebKit/public/platform/modules/serviceworker/service_worker_global_scope.mojom.h"
|
| #include "url/gurl.h"
|
| #include "url/origin.h"
|
|
|
| @@ -233,6 +234,13 @@ class CONTENT_EXPORT ServiceWorkerVersion
|
| template <typename Interface>
|
| base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id);
|
|
|
| + template <typename Interface>
|
| + base::WeakPtr<Interface> GetMojoService();
|
| +
|
| + template <typename Interface>
|
| + bool AddMojoService(mojo::InterfacePtr<Interface> interface,
|
| + bool overwrite = false);
|
| +
|
| // Dispatches an event. If dispatching the event fails, all of the error
|
| // callbacks that were associated with |request_ids| via StartRequest are
|
| // called.
|
| @@ -347,7 +355,11 @@ class CONTENT_EXPORT ServiceWorkerVersion
|
| // requests, in-progress streaming URLRequestJobs, or pending start callbacks.
|
| bool HasWork() const;
|
|
|
| + // Interfaces called from ServiceWorkerGlobalScopeHost
|
| + void OnSimpleEventResponse(int request_id,
|
| + ServiceWorkerStatusCode result);
|
| private:
|
| + friend class ServiceWorkerGlobalScopeHostImpl;
|
| friend class base::RefCounted<ServiceWorkerVersion>;
|
| friend class ServiceWorkerMetrics;
|
| friend class ServiceWorkerReadFromCacheJobTest;
|
| @@ -741,6 +753,14 @@ base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoServiceForRequest(
|
| DCHECK(!request->mojo_service)
|
| << "Request is already associated with a mojo service";
|
|
|
| + base::WeakPtr<Interface> interface = GetMojoService<Interface>();
|
| + request->mojo_service = Interface::Name_;
|
| + return interface;
|
| +}
|
| +
|
| +template <typename Interface>
|
| +base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoService() {
|
| + DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status());
|
| MojoServiceWrapper<Interface>* service =
|
| static_cast<MojoServiceWrapper<Interface>*>(
|
| mojo_services_.get(Interface::Name_));
|
| @@ -753,10 +773,28 @@ base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoServiceForRequest(
|
| service = new MojoServiceWrapper<Interface>(this, std::move(interface));
|
| mojo_services_.add(Interface::Name_, base::WrapUnique(service));
|
| }
|
| - request->mojo_service = Interface::Name_;
|
| return service->GetWeakPtr();
|
| }
|
|
|
| +template <typename Interface>
|
| +bool ServiceWorkerVersion::AddMojoService(
|
| + mojo::InterfacePtr<Interface> interface, bool overwrite) {
|
| + LOG(ERROR) << __PRETTY_FUNCTION__;
|
| + // Fail if the interface is already registered.
|
| + if (!overwrite && mojo_services_.get(Interface::Name_)) {
|
| + return false;
|
| + }
|
| +
|
| + interface.set_connection_error_handler(
|
| + base::Bind(&ServiceWorkerVersion::OnMojoConnectionError,
|
| + weak_factory_.GetWeakPtr(), Interface::Name_));
|
| + MojoServiceWrapper<Interface>* service =
|
| + new MojoServiceWrapper<Interface>(this, std::move(interface));
|
| + mojo_services_.set(Interface::Name_, base::WrapUnique(service));
|
| + return true;
|
| +}
|
| +
|
| +
|
| template <typename ResponseMessage>
|
| void ServiceWorkerVersion::DispatchSimpleEvent(int request_id,
|
| const IPC::Message& message) {
|
| @@ -781,7 +819,7 @@ template <typename ResponseMessage>
|
| void ServiceWorkerVersion::RegisterSimpleRequest(int request_id) {
|
| RegisterRequestCallback<ResponseMessage>(
|
| request_id,
|
| - base::Bind(&ServiceWorkerVersion::OnSimpleEventResponse, this));
|
| + base::Bind(static_cast<void(ServiceWorkerVersion::*)(int, blink::WebServiceWorkerEventResult)>(&ServiceWorkerVersion::OnSimpleEventResponse), this));
|
| }
|
|
|
| template <typename ResponseMessage, typename CallbackType>
|
|
|