OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | |
10 #include <vector> | |
11 | |
9 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
10 #include "content/renderer/webworker_base.h" | 13 #include "base/memory/scoped_ptr.h" |
11 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "ipc/ipc_channel.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorker.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorker.h" |
13 | 17 |
14 class ChildThread; | 18 class ChildThread; |
15 | 19 |
16 // Implementation of the WebSharedWorker APIs. This object is intended to only | 20 // Implementation of the WebSharedWorker APIs. This object is intended to only |
17 // live long enough to allow the caller to send a "connect" event to the worker | 21 // live long enough to allow the caller to send a "connect" event to the worker |
18 // thread. Once the connect event has been sent, all future communication will | 22 // thread. Once the connect event has been sent, all future communication will |
19 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will | 23 // happen via the WebMessagePortChannel, and the WebSharedWorker instance will |
20 // be freed. | 24 // be freed. |
21 class WebSharedWorkerProxy : public WebKit::WebSharedWorker, | 25 class WebSharedWorkerProxy : public WebKit::WebSharedWorker, |
22 private WebWorkerBase { | 26 private IPC::Channel::Listener { |
23 public: | 27 public: |
24 // If the worker not loaded yet, route_id == MSG_ROUTING_NONE | 28 // If the worker not loaded yet, route_id == MSG_ROUTING_NONE |
25 WebSharedWorkerProxy(ChildThread* child_thread, | 29 WebSharedWorkerProxy(ChildThread* child_thread, |
26 unsigned long long document_id, | 30 unsigned long long document_id, |
27 bool exists, | 31 bool exists, |
28 int route_id, | 32 int route_id, |
29 int render_view_route_id); | 33 int render_view_route_id); |
34 virtual ~WebSharedWorkerProxy(); | |
30 | 35 |
31 // Implementations of WebSharedWorker APIs | 36 // Implementations of WebSharedWorker APIs |
32 virtual bool isStarted(); | 37 virtual bool isStarted(); |
33 virtual void connect(WebKit::WebMessagePortChannel* channel, | 38 virtual void connect(WebKit::WebMessagePortChannel* channel, |
34 ConnectListener* listener); | 39 ConnectListener* listener); |
35 virtual void startWorkerContext(const WebKit::WebURL& script_url, | 40 virtual void startWorkerContext(const WebKit::WebURL& script_url, |
36 const WebKit::WebString& name, | 41 const WebKit::WebString& name, |
37 const WebKit::WebString& user_agent, | 42 const WebKit::WebString& user_agent, |
38 const WebKit::WebString& source_code, | 43 const WebKit::WebString& source_code, |
39 long long script_resource_appcache_id); | 44 long long script_resource_appcache_id); |
40 virtual void terminateWorkerContext(); | 45 virtual void terminateWorkerContext(); |
41 virtual void clientDestroyed(); | 46 virtual void clientDestroyed(); |
42 | 47 |
48 private: | |
jam
2011/10/28 16:54:12
nit: space
| |
43 // IPC::Channel::Listener implementation. | 49 // IPC::Channel::Listener implementation. |
44 virtual bool OnMessageReceived(const IPC::Message& message); | 50 virtual bool OnMessageReceived(const IPC::Message& message); |
45 | 51 |
46 private: | 52 // Returns true if the worker is running (can send messages to it). |
53 bool IsStarted(); | |
54 | |
55 // Disconnects the worker (stops listening for incoming messages). | |
56 void Disconnect(); | |
57 | |
58 // Sends a message to the worker thread (forwarded via the RenderViewHost). | |
59 // If WorkerStarted() has not yet been called, message is queued. | |
60 bool Send(IPC::Message*); | |
61 | |
62 // Returns true if there are queued messages. | |
63 bool HasQueuedMessages() { return !queued_messages_.empty(); } | |
64 | |
65 // Sends any messages currently in the queue. | |
66 void SendQueuedMessages(); | |
67 | |
68 void CreateWorkerContext(const GURL& script_url, | |
69 bool is_shared, | |
70 const string16& name, | |
71 const string16& user_agent, | |
72 const string16& source_code, | |
73 int pending_route_id, | |
74 int64 script_resource_appcache_id); | |
47 void OnWorkerCreated(); | 75 void OnWorkerCreated(); |
48 | 76 |
77 | |
78 // Routing id associated with this worker - used to receive messages from the | |
79 // worker, and also to route messages to the worker (WorkerService contains | |
80 // a map that maps between these renderer-side route IDs and worker-side | |
81 // routing ids). | |
82 int route_id_; | |
83 | |
84 // The routing id for the RenderView that created this worker. | |
85 int render_view_route_id_; | |
86 | |
87 ChildThread* child_thread_; | |
88 | |
89 // ID of our parent document (used to shutdown workers when the parent | |
90 // document is detached). | |
91 unsigned long long document_id_; | |
92 | |
93 // ID of our parent's appcache host, only valid for dedicated workers. | |
94 int parent_appcache_host_id_; | |
95 | |
96 // Stores messages that were sent before the StartWorkerContext message. | |
97 std::vector<IPC::Message*> queued_messages_; | |
98 | |
49 // The id for the placeholder worker instance we've stored on the | 99 // The id for the placeholder worker instance we've stored on the |
50 // browser process (we need to pass this same route id back in when creating | 100 // browser process (we need to pass this same route id back in when creating |
51 // the worker). | 101 // the worker). |
52 int pending_route_id_; | 102 int pending_route_id_; |
53 ConnectListener* connect_listener_; | 103 ConnectListener* connect_listener_; |
54 | 104 |
55 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); | 105 DISALLOW_COPY_AND_ASSIGN(WebSharedWorkerProxy); |
56 }; | 106 }; |
57 | 107 |
58 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ | 108 #endif // CONTENT_RENDERER_WEBSHAREDWORKER_PROXY_H_ |
OLD | NEW |