OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_SHARED_WORKER_WEBSHAREDWORKER_PROXY_H_ | 5 #ifndef CONTENT_RENDERER_SHARED_WORKER_WEBSHAREDWORKER_PROXY_H_ |
6 #define CONTENT_RENDERER_SHARED_WORKER_WEBSHAREDWORKER_PROXY_H_ | 6 #define CONTENT_RENDERER_SHARED_WORKER_WEBSHAREDWORKER_PROXY_H_ |
7 | 7 |
| 8 #include <set> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "ipc/ipc_listener.h" | 11 #include "ipc/ipc_listener.h" |
10 #include "third_party/WebKit/public/web/WebSharedWorkerConnectListener.h" | 12 #include "third_party/WebKit/public/web/WebSharedWorkerConnectListener.h" |
11 #include "third_party/WebKit/public/web/WebSharedWorkerCreationErrors.h" | 13 #include "third_party/WebKit/public/web/WebSharedWorkerCreationErrors.h" |
12 | 14 |
13 struct ViewHostMsg_CreateWorker_Params; | 15 struct ViewHostMsg_CreateWorker_Params; |
14 | 16 |
15 namespace blink { | 17 namespace blink { |
16 class WebMessagePortChannel; | 18 class WebMessagePortChannel; |
17 } | 19 } |
18 | 20 |
19 namespace IPC { | 21 namespace IPC { |
20 class MessageRouter; | 22 class MessageRouter; |
21 } | 23 } |
22 | 24 |
23 namespace content { | 25 namespace content { |
24 | 26 |
25 // Implementation of the WebSharedWorker APIs. This object is intended to only | 27 // A proxy between a renderer process hosting a document and the browser |
26 // live long enough to allow the caller to send a "connect" event to the worker | 28 // process. This instance has the same lifetime as a shared worker, and |
27 // thread. Once the connect event has been sent, all future communication will | 29 // self-destructs when the worker is destroyed. |
28 // happen via the WebMessagePortChannel. This instance will self-destruct when a | |
29 // connection is established. | |
30 class WebSharedWorkerProxy : private IPC::Listener { | 30 class WebSharedWorkerProxy : private IPC::Listener { |
31 public: | 31 public: |
32 // |channel| should be passed with its ownership. | 32 // |channel| should be passed with its ownership. |
33 WebSharedWorkerProxy( | 33 WebSharedWorkerProxy( |
34 std::unique_ptr<blink::WebSharedWorkerConnectListener> listener, | 34 std::unique_ptr<blink::WebSharedWorkerConnectListener> listener, |
35 ViewHostMsg_CreateWorker_Params params, | 35 ViewHostMsg_CreateWorker_Params params, |
36 blink::WebMessagePortChannel* channel); | 36 blink::WebMessagePortChannel* channel); |
37 ~WebSharedWorkerProxy() override; | 37 ~WebSharedWorkerProxy() override; |
38 | 38 |
39 private: | 39 private: |
40 void connect(ViewHostMsg_CreateWorker_Params params, | 40 void connect(ViewHostMsg_CreateWorker_Params params, |
41 blink::WebMessagePortChannel* channel); | 41 blink::WebMessagePortChannel* channel); |
42 | 42 |
43 // IPC::Listener implementation. | 43 // IPC::Listener implementation. |
44 bool OnMessageReceived(const IPC::Message& message) override; | 44 bool OnMessageReceived(const IPC::Message& message) override; |
45 | 45 |
46 void OnWorkerCreated(); | 46 void OnWorkerCreated(); |
47 void OnWorkerScriptLoadFailed(); | 47 void OnWorkerScriptLoadFailed(); |
48 void OnWorkerConnected(); | 48 void OnWorkerConnected(const std::set<uint32_t>& use_counter); |
| 49 void OnWorkerDestroyed(); |
| 50 void OnCountFeature(uint32_t use_counter_id); |
49 | 51 |
50 // Routing id associated with this worker - used to receive messages from the | 52 // Routing id associated with this worker - used to receive messages from the |
51 // worker, and also to route messages to the worker (WorkerService contains | 53 // worker, and also to route messages to the worker (WorkerService contains |
52 // a map that maps between these renderer-side route IDs and worker-side | 54 // a map that maps between these renderer-side route IDs and worker-side |
53 // routing ids). | 55 // routing ids). |
54 int route_id_; | 56 int route_id_; |
55 | 57 |
56 IPC::MessageRouter* const router_; | 58 IPC::MessageRouter* const router_; |
57 | 59 |
58 int message_port_id_; | 60 int message_port_id_; |
59 std::unique_ptr<blink::WebSharedWorkerConnectListener> listener_; | 61 std::unique_ptr<blink::WebSharedWorkerConnectListener> listener_; |
60 | 62 |
61 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); | 63 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); |
62 }; | 64 }; |
63 | 65 |
64 } // namespace content | 66 } // namespace content |
65 | 67 |
66 #endif // CONTENT_RENDERER_SHARED_WORKER_WEBSHAREDWORKER_PROXY_H_ | 68 #endif // CONTENT_RENDERER_SHARED_WORKER_WEBSHAREDWORKER_PROXY_H_ |
OLD | NEW |