| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_H_ |
| 6 #define CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_H_ | 6 #define CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
| 9 #include "base/optional.h" | 9 #include "base/optional.h" |
| 10 #include "content/child/child_thread_impl.h" | 10 #include "content/child/child_thread_impl.h" |
| 11 #include "content/common/service_worker/embedded_worker.mojom.h" | 11 #include "content/common/service_worker/embedded_worker.mojom.h" |
| 12 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 12 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "mojo/public/cpp/bindings/interface_ptr.h" | 14 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 15 #include "services/service_manager/public/cpp/interface_provider.h" | |
| 16 | 15 |
| 17 namespace content { | 16 namespace content { |
| 18 | 17 |
| 19 // This class exposes interfaces of WebEmbeddedWorker to the browser process. | 18 // This class exposes interfaces of WebEmbeddedWorker to the browser process. |
| 20 // Unless otherwise noted, all methods should be called on the main thread. | 19 // Unless otherwise noted, all methods should be called on the main thread. |
| 21 class EmbeddedWorkerInstanceClientImpl | 20 class EmbeddedWorkerInstanceClientImpl |
| 22 : public mojom::EmbeddedWorkerInstanceClient { | 21 : public mojom::EmbeddedWorkerInstanceClient { |
| 23 public: | 22 public: |
| 24 static void Create( | 23 static void Create( |
| 25 EmbeddedWorkerDispatcher* dispatcher, | 24 EmbeddedWorkerDispatcher* dispatcher, |
| 26 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request); | 25 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request); |
| 27 | 26 |
| 28 ~EmbeddedWorkerInstanceClientImpl() override; | 27 ~EmbeddedWorkerInstanceClientImpl() override; |
| 29 | 28 |
| 30 // This method can be called from any threads. | |
| 31 void ExposeInterfacesToBrowser( | |
| 32 service_manager::InterfaceRegistry* interface_registry); | |
| 33 | |
| 34 // Called from ServiceWorkerContextClient. | 29 // Called from ServiceWorkerContextClient. |
| 35 void StopWorkerCompleted(); | 30 void StopWorkerCompleted(); |
| 36 | 31 |
| 37 private: | 32 private: |
| 38 EmbeddedWorkerInstanceClientImpl( | 33 EmbeddedWorkerInstanceClientImpl( |
| 39 EmbeddedWorkerDispatcher* dispatcher, | 34 EmbeddedWorkerDispatcher* dispatcher, |
| 40 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request); | 35 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request); |
| 41 | 36 |
| 42 // mojom::EmbeddedWorkerInstanceClient implementation | 37 // mojom::EmbeddedWorkerInstanceClient implementation |
| 43 void StartWorker( | 38 void StartWorker( |
| 44 const EmbeddedWorkerStartParams& params, | 39 const EmbeddedWorkerStartParams& params, |
| 45 service_manager::mojom::InterfaceProviderPtr browser_interfaces, | 40 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request) override; |
| 46 service_manager::mojom::InterfaceProviderRequest renderer_request) | |
| 47 override; | |
| 48 void StopWorker(const StopWorkerCallback& callback) override; | 41 void StopWorker(const StopWorkerCallback& callback) override; |
| 49 | 42 |
| 50 // Handler of connection error bound to |binding_| | 43 // Handler of connection error bound to |binding_| |
| 51 void OnError(); | 44 void OnError(); |
| 52 | 45 |
| 53 EmbeddedWorkerDispatcher* dispatcher_; | 46 EmbeddedWorkerDispatcher* dispatcher_; |
| 54 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; | 47 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; |
| 55 service_manager::InterfaceProvider remote_interfaces_; | |
| 56 | 48 |
| 57 // This is valid before StartWorker is called. After that, this object | 49 // This is valid before StartWorker is called. After that, this object |
| 58 // will be passed to ServiceWorkerContextClient. | 50 // will be passed to ServiceWorkerContextClient. |
| 59 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> temporal_self_; | 51 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> temporal_self_; |
| 60 | 52 |
| 61 // This is drained by ServiceWorkerContextClient after the worker thread is | |
| 62 // launched. | |
| 63 service_manager::mojom::InterfaceProviderRequest renderer_request_; | |
| 64 | |
| 65 base::Optional<int> embedded_worker_id_; | 53 base::Optional<int> embedded_worker_id_; |
| 66 | 54 |
| 67 // Owned by EmbeddedWorkerDispatcher. This can be nullptr while a worker is | 55 // Owned by EmbeddedWorkerDispatcher. This can be nullptr while a worker is |
| 68 // not running. | 56 // not running. |
| 69 EmbeddedWorkerDispatcher::WorkerWrapper* wrapper_; | 57 EmbeddedWorkerDispatcher::WorkerWrapper* wrapper_; |
| 70 | 58 |
| 71 StopWorkerCallback stop_callback_; | 59 StopWorkerCallback stop_callback_; |
| 72 | 60 |
| 73 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceClientImpl); | 61 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceClientImpl); |
| 74 }; | 62 }; |
| 75 | 63 |
| 76 } // namespace content | 64 } // namespace content |
| 77 | 65 |
| 78 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_
H_ | 66 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_
H_ |
| OLD | NEW |