1 // Copyright 2015 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.
5 #ifndef CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_
6 #define CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/child/worker_task_runner.h"
11 #include "content/common/service_port_service.mojom.h"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
15 class WebServiceWorkerContextProxy
;
20 // Mojo service that dispatches ServicePort related events to a service worker.
21 // Instances are always created on a worker thread, and all methods are only
22 // called on that same thread. Lifetime of this class is tied to both the mojo
23 // channel and the lifetime of the worker thread. If either the channel is
24 // disconnected or the worker thread stops the instance deletes itself.
25 class ServicePortDispatcherImpl
: public ServicePortDispatcher
,
26 public WorkerTaskRunner::Observer
{
28 static void Create(base::WeakPtr
<blink::WebServiceWorkerContextProxy
> proxy
,
29 mojo::InterfaceRequest
<ServicePortDispatcher
> request
);
31 ~ServicePortDispatcherImpl() override
;
34 ServicePortDispatcherImpl(
35 base::WeakPtr
<blink::WebServiceWorkerContextProxy
> proxy
,
36 mojo::InterfaceRequest
<ServicePortDispatcher
> request
);
38 // WorkerTaskRunner::Observer implementation.
39 void OnWorkerRunLoopStopped() override
;
41 // ServicePortDispatcher implementation.
42 void Connect(const mojo::String
& target_url
,
43 const mojo::String
& origin
,
45 const ConnectCallback
& callback
) override
;
47 mojo::StrongBinding
<ServicePortDispatcher
> binding_
;
48 base::WeakPtr
<blink::WebServiceWorkerContextProxy
> proxy_
;
50 DISALLOW_COPY_AND_ASSIGN(ServicePortDispatcherImpl
);
53 } // namespace content
55 #endif // CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_