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 "content/common/service_worker/embedded_worker.mojom.h" | 10 #include "content/common/service_worker/embedded_worker.mojom.h" |
10 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 11 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" |
11 | 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
| 16 // This class exposes interfaces of WebEmbeddedWorker to the browser process. |
| 17 // All methods should be called on the main thread. |
14 class EmbeddedWorkerInstanceClientImpl | 18 class EmbeddedWorkerInstanceClientImpl |
15 : public mojom::EmbeddedWorkerInstanceClient { | 19 : public mojom::EmbeddedWorkerInstanceClient { |
16 public: | 20 public: |
17 static void Create( | 21 static void Create( |
18 EmbeddedWorkerDispatcher* dispatcher, | 22 EmbeddedWorkerDispatcher* dispatcher, |
19 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request); | 23 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request); |
20 | 24 |
21 explicit EmbeddedWorkerInstanceClientImpl( | |
22 EmbeddedWorkerDispatcher* dispatcher); | |
23 ~EmbeddedWorkerInstanceClientImpl() override; | 25 ~EmbeddedWorkerInstanceClientImpl() override; |
24 | 26 |
25 // Implementation of mojo interface | 27 // Called from ServiceWorkerContextClient. Must call on the main thread. |
26 void StartWorker(const EmbeddedWorkerStartParams& params) override; | 28 void StopWorkerCompleted(); |
27 | 29 |
28 private: | 30 private: |
| 31 EmbeddedWorkerInstanceClientImpl( |
| 32 EmbeddedWorkerDispatcher* dispatcher, |
| 33 mojo::InterfaceRequest<mojom::EmbeddedWorkerInstanceClient> request); |
| 34 |
| 35 // mojom::EmbeddedWorkerInstanceClient implementation |
| 36 void StartWorker(const EmbeddedWorkerStartParams& params) override; |
| 37 void StopWorker(const StopWorkerCallback& callback) override; |
| 38 |
| 39 // Handler of connection error bound to |binding_| |
| 40 void OnError(); |
| 41 |
29 EmbeddedWorkerDispatcher* dispatcher_; | 42 EmbeddedWorkerDispatcher* dispatcher_; |
| 43 // This object will be bound to the main thread. |
| 44 mojo::Binding<mojom::EmbeddedWorkerInstanceClient> binding_; |
30 | 45 |
| 46 // This is valid before StartWorker is called. After that, this object |
| 47 // will be passed to ServiceWorkerContextClient. |
| 48 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> temporal_self_; |
| 49 |
| 50 base::Optional<int> embedded_worker_id_; |
31 EmbeddedWorkerDispatcher::WorkerWrapper* wrapper_; | 51 EmbeddedWorkerDispatcher::WorkerWrapper* wrapper_; |
32 | 52 |
| 53 // Stores callbacks |
| 54 StopWorkerCallback stop_callback_; |
| 55 |
33 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceClientImpl); | 56 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstanceClientImpl); |
34 }; | 57 }; |
35 | 58 |
36 } // namespace content | 59 } // namespace content |
37 | 60 |
38 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_
H_ | 61 #endif // CONTENT_RENDERER_SERVICE_WORKER_EMBEDDED_WORKER_INSTANCE_CLIENT_IMPL_
H_ |
OLD | NEW |