OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_ |
| 6 #define CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_ |
| 7 |
| 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" |
| 13 |
| 14 namespace blink { |
| 15 class WebServiceWorkerContextProxy; |
| 16 } |
| 17 |
| 18 namespace content { |
| 19 |
| 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 { |
| 27 public: |
| 28 static void Create(base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy, |
| 29 mojo::InterfaceRequest<ServicePortDispatcher> request); |
| 30 |
| 31 ~ServicePortDispatcherImpl() override; |
| 32 |
| 33 private: |
| 34 ServicePortDispatcherImpl( |
| 35 base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy, |
| 36 mojo::InterfaceRequest<ServicePortDispatcher> request); |
| 37 |
| 38 // WorkerTaskRunner::Observer implementation. |
| 39 void OnWorkerRunLoopStopped() override; |
| 40 |
| 41 // ServicePortDispatcher implementation. |
| 42 void Connect(const mojo::String& target_url, |
| 43 const mojo::String& origin, |
| 44 int32_t port_id, |
| 45 const ConnectCallback& callback) override; |
| 46 |
| 47 mojo::StrongBinding<ServicePortDispatcher> binding_; |
| 48 base::WeakPtr<blink::WebServiceWorkerContextProxy> proxy_; |
| 49 |
| 50 DISALLOW_COPY_AND_ASSIGN(ServicePortDispatcherImpl); |
| 51 }; |
| 52 |
| 53 } // namespace content |
| 54 |
| 55 #endif // CONTENT_CHILD_NAVIGATOR_CONNECT_SERVICE_PORT_DISPATCHER_IMPL_H_ |
OLD | NEW |