| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | |
| 6 #define CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "ipc/ipc_listener.h" | |
| 14 #include "third_party/WebKit/public/web/WebSharedWorkerConnector.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace IPC { | |
| 18 class MessageRouter; | |
| 19 } | |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 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 | |
| 25 // thread. Once the connect event has been sent, all future communication will | |
| 26 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will | |
| 27 // be freed. | |
| 28 class WebSharedWorkerProxy : public blink::WebSharedWorkerConnector, | |
| 29 private IPC::Listener { | |
| 30 public: | |
| 31 WebSharedWorkerProxy(IPC::MessageRouter* router, int route_id); | |
| 32 ~WebSharedWorkerProxy() override; | |
| 33 | |
| 34 // Implementations of WebSharedWorkerConnector APIs | |
| 35 void connect(blink::WebMessagePortChannel* channel, | |
| 36 ConnectListener* listener) override; | |
| 37 | |
| 38 private: | |
| 39 // IPC::Listener implementation. | |
| 40 bool OnMessageReceived(const IPC::Message& message) override; | |
| 41 | |
| 42 // Sends a message to the worker thread (forwarded via the RenderViewHost). | |
| 43 // If WorkerStarted() has not yet been called, message is queued. | |
| 44 bool Send(std::unique_ptr<IPC::Message> message); | |
| 45 | |
| 46 // Sends any messages currently in the queue. | |
| 47 void SendQueuedMessages(); | |
| 48 | |
| 49 void OnWorkerCreated(); | |
| 50 void OnWorkerScriptLoadFailed(); | |
| 51 void OnWorkerConnected(); | |
| 52 | |
| 53 // Routing id associated with this worker - used to receive messages from the | |
| 54 // worker, and also to route messages to the worker (WorkerService contains | |
| 55 // a map that maps between these renderer-side route IDs and worker-side | |
| 56 // routing ids). | |
| 57 const int route_id_; | |
| 58 | |
| 59 IPC::MessageRouter* const router_; | |
| 60 | |
| 61 // Stores messages that were sent before the StartWorkerContext message. | |
| 62 std::vector<std::unique_ptr<IPC::Message>> queued_messages_; | |
| 63 | |
| 64 ConnectListener* connect_listener_; | |
| 65 bool created_; | |
| 66 | |
| 67 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); | |
| 68 }; | |
| 69 | |
| 70 } // namespace content | |
| 71 | |
| 72 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | |
| OLD | NEW |