Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: chrome/renderer/websharedworker_proxy.cc

Issue 390017: Added lifecycle management and sharing support for SharedWorkers. SharedWorkers (Closed)
Patch Set: Changed WebWorkerBase not not call a virtual function from the destructor Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "chrome/renderer/websharedworker_proxy.h" 5 #include "chrome/renderer/websharedworker_proxy.h"
6 6
7 #include "chrome/common/render_messages.h" 7 #include "chrome/common/render_messages.h"
8 #include "chrome/common/webmessageportchannel_impl.h" 8 #include "chrome/common/webmessageportchannel_impl.h"
9 #include "chrome/common/worker_messages.h" 9 #include "chrome/common/worker_messages.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" 10 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
11 11
12 WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread, 12 WebSharedWorkerProxy::WebSharedWorkerProxy(ChildThread* child_thread,
13 int route_id, 13 int route_id,
14 int render_view_route_id) 14 int render_view_route_id)
15 : WebWorkerBase(child_thread, route_id, render_view_route_id), 15 : WebWorkerBase(child_thread, route_id, render_view_route_id),
16 m_connectListener(NULL) { 16 connect_listener_(NULL) {
17 } 17 }
18 18
19 bool WebSharedWorkerProxy::isStarted() { 19 bool WebSharedWorkerProxy::isStarted() {
20 return IsStarted(); 20 return IsStarted();
21 } 21 }
22 22
23 void WebSharedWorkerProxy::startWorkerContext( 23 void WebSharedWorkerProxy::startWorkerContext(
24 const WebKit::WebURL& script_url, 24 const WebKit::WebURL& script_url,
25 const WebKit::WebString& name, 25 const WebKit::WebString& name,
26 const WebKit::WebString& user_agent, 26 const WebKit::WebString& user_agent,
27 const WebKit::WebString& source_code) { 27 const WebKit::WebString& source_code) {
28 DCHECK(!isStarted());
28 CreateWorkerContext(script_url, true, name, user_agent, source_code); 29 CreateWorkerContext(script_url, true, name, user_agent, source_code);
29 } 30 }
30 31
31 void WebSharedWorkerProxy::terminateWorkerContext() { 32 void WebSharedWorkerProxy::terminateWorkerContext() {
32 // This API should only be invoked from worker context. 33 // This API should only be invoked from worker context.
33 NOTREACHED(); 34 NOTREACHED();
34 } 35 }
35 36
36 void WebSharedWorkerProxy::clientDestroyed() { 37 void WebSharedWorkerProxy::clientDestroyed() {
37 // This API should only be invoked from worker context. 38 // This API should only be invoked from worker context.
38 NOTREACHED(); 39 NOTREACHED();
39 } 40 }
40 41
41 void WebSharedWorkerProxy::connect(WebKit::WebMessagePortChannel* channel, 42 void WebSharedWorkerProxy::connect(WebKit::WebMessagePortChannel* channel,
42 ConnectListener* listener) { 43 ConnectListener* listener) {
43 WebMessagePortChannelImpl* webchannel = 44 WebMessagePortChannelImpl* webchannel =
44 static_cast<WebMessagePortChannelImpl*>(channel); 45 static_cast<WebMessagePortChannelImpl*>(channel);
45 46
46 int message_port_id = webchannel->message_port_id(); 47 int message_port_id = webchannel->message_port_id();
47 DCHECK(message_port_id != MSG_ROUTING_NONE); 48 DCHECK(message_port_id != MSG_ROUTING_NONE);
48 webchannel->QueueMessages(); 49 webchannel->QueueMessages();
49 50
50 Send(new WorkerMsg_Connect(route_id_, message_port_id, MSG_ROUTING_NONE)); 51 Send(new WorkerMsg_Connect(route_id_, message_port_id, MSG_ROUTING_NONE));
51 if (HasQueuedMessages()) { 52 if (HasQueuedMessages()) {
52 m_connectListener = listener; 53 connect_listener_ = listener;
53 } else { 54 } else {
54 listener->connected(); 55 listener->connected();
55 // The listener may free this object, so do not access the object after 56 // The listener may free this object, so do not access the object after
56 // this point. 57 // this point.
57 } 58 }
58 } 59 }
59 60
60 void WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) { 61 void WebSharedWorkerProxy::OnMessageReceived(const IPC::Message& message) {
61 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message) 62 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerProxy, message)
62 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated) 63 IPC_MESSAGE_HANDLER(ViewMsg_WorkerCreated, OnWorkerCreated)
63 IPC_END_MESSAGE_MAP() 64 IPC_END_MESSAGE_MAP()
64 } 65 }
65 66
66 void WebSharedWorkerProxy::OnWorkerCreated() { 67 void WebSharedWorkerProxy::OnWorkerCreated() {
67 // The worker is created - now send off the CreateWorkerContext message and 68 // The worker is created - now send off the CreateWorkerContext message and
68 // any other queued messages 69 // any other queued messages
69 SendQueuedMessages(); 70 SendQueuedMessages();
70 71
71 // Inform any listener that the pending connect event has been sent 72 // Inform any listener that the pending connect event has been sent
72 // (this can result in this object being freed). 73 // (this can result in this object being freed).
73 if (m_connectListener) { 74 if (connect_listener_) {
74 m_connectListener->connected(); 75 connect_listener_->connected();
75 } 76 }
76 } 77 }
77
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698