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_WEBSHAREDWORKER_PROXY_H_ | 5 #ifndef CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ |
6 #define CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | 6 #define CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 // Implementation of the WebSharedWorker APIs. This object is intended to only | 23 // Implementation of the WebSharedWorker APIs. This object is intended to only |
24 // live long enough to allow the caller to send a "connect" event to the worker | 24 // live long enough to allow the caller to send a "connect" event to the worker |
25 // thread. Once the connect event has been sent, all future communication will | 25 // thread. Once the connect event has been sent, all future communication will |
26 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will | 26 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will |
27 // be freed. | 27 // be freed. |
28 class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector, | 28 class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector, |
29 private IPC::Listener { | 29 private IPC::Listener { |
30 public: | 30 public: |
31 // If the worker not loaded yet, route_id == MSG_ROUTING_NONE | |
32 WebSharedWorkerProxy(IPC::MessageRouter* router, int route_id); | 31 WebSharedWorkerProxy(IPC::MessageRouter* router, int route_id); |
33 ~WebSharedWorkerProxy() override; | 32 ~WebSharedWorkerProxy() override; |
34 | 33 |
35 // Implementations of WebSharedWorkerConnector APIs | 34 // Implementations of WebSharedWorkerConnector APIs |
36 void connect(blink::WebMessagePortChannel* channel, | 35 void connect(blink::WebMessagePortChannel* channel, |
37 ConnectListener* listener) override; | 36 ConnectListener* listener) override; |
38 | 37 |
39 private: | 38 private: |
40 // IPC::Listener implementation. | 39 // IPC::Listener implementation. |
41 bool OnMessageReceived(const IPC::Message& message) override; | 40 bool OnMessageReceived(const IPC::Message& message) override; |
42 | 41 |
43 // Disconnects the worker (stops listening for incoming messages). | |
44 void Disconnect(); | |
45 | |
46 // Sends a message to the worker thread (forwarded via the RenderViewHost). | 42 // Sends a message to the worker thread (forwarded via the RenderViewHost). |
47 // If WorkerStarted() has not yet been called, message is queued. | 43 // If WorkerStarted() has not yet been called, message is queued. |
48 bool Send(std::unique_ptr<IPC::Message> message); | 44 bool Send(std::unique_ptr<IPC::Message> message); |
49 | 45 |
50 // Sends any messages currently in the queue. | 46 // Sends any messages currently in the queue. |
51 void SendQueuedMessages(); | 47 void SendQueuedMessages(); |
52 | 48 |
53 void OnWorkerCreated(); | 49 void OnWorkerCreated(); |
54 void OnWorkerScriptLoadFailed(); | 50 void OnWorkerScriptLoadFailed(); |
55 void OnWorkerConnected(); | 51 void OnWorkerConnected(); |
56 | 52 |
57 // Routing id associated with this worker - used to receive messages from the | 53 // Routing id associated with this worker - used to receive messages from the |
58 // worker, and also to route messages to the worker (WorkerService contains | 54 // worker, and also to route messages to the worker (WorkerService contains |
59 // a map that maps between these renderer-side route IDs and worker-side | 55 // a map that maps between these renderer-side route IDs and worker-side |
60 // routing ids). | 56 // routing ids). |
61 int route_id_; | 57 const int route_id_; |
62 | 58 |
63 IPC::MessageRouter* const router_; | 59 IPC::MessageRouter* const router_; |
64 | 60 |
65 // Stores messages that were sent before the StartWorkerContext message. | 61 // Stores messages that were sent before the StartWorkerContext message. |
66 std::vector<std::unique_ptr<IPC::Message>> queued_messages_; | 62 std::vector<std::unique_ptr<IPC::Message>> queued_messages_; |
67 | 63 |
68 ConnectListener* connect_listener_; | 64 ConnectListener* connect_listener_; |
69 bool created_; | 65 bool created_; |
70 | 66 |
71 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); | 67 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); |
72 }; | 68 }; |
73 | 69 |
74 } // namespace content | 70 } // namespace content |
75 | 71 |
76 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | 72 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ |
OLD | NEW |