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

Side by Side Diff: chrome/worker/websharedworker_stub.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/worker/websharedworker_stub.h" 5 #include "chrome/worker/websharedworker_stub.h"
6 6
7 #include "chrome/common/webmessageportchannel_impl.h" 7 #include "chrome/common/webmessageportchannel_impl.h"
8 #include "chrome/common/worker_messages.h" 8 #include "chrome/common/worker_messages.h"
9 #include "third_party/WebKit/WebKit/chromium/public/WebSharedWorker.h" 9 #include "third_party/WebKit/WebKit/chromium/public/WebSharedWorker.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" 10 #include "third_party/WebKit/WebKit/chromium/public/WebString.h"
11 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" 11 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h"
12 12
13 WebSharedWorkerStub::WebSharedWorkerStub( 13 WebSharedWorkerStub::WebSharedWorkerStub(
14 const string16& name, int route_id) 14 const string16& name, int route_id)
15 : WebWorkerStubBase(route_id), 15 : WebWorkerStubBase(route_id),
16 name_(name) { 16 name_(name),
17 started_(false) {
17 18
18 // TODO(atwilson): Add support for NaCl when they support MessagePorts. 19 // TODO(atwilson): Add support for NaCl when they support MessagePorts.
19 impl_ = WebKit::WebSharedWorker::create(client()); 20 impl_ = WebKit::WebSharedWorker::create(client());
20 21
21 } 22 }
22 23
23 WebSharedWorkerStub::~WebSharedWorkerStub() { 24 WebSharedWorkerStub::~WebSharedWorkerStub() {
24 impl_->clientDestroyed(); 25 impl_->clientDestroyed();
25 } 26 }
26 27
27 void WebSharedWorkerStub::OnMessageReceived(const IPC::Message& message) { 28 void WebSharedWorkerStub::OnMessageReceived(const IPC::Message& message) {
28 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerStub, message) 29 IPC_BEGIN_MESSAGE_MAP(WebSharedWorkerStub, message)
29 IPC_MESSAGE_HANDLER(WorkerMsg_StartWorkerContext, OnStartWorkerContext) 30 IPC_MESSAGE_HANDLER(WorkerMsg_StartWorkerContext, OnStartWorkerContext)
30 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext, 31 IPC_MESSAGE_HANDLER(WorkerMsg_TerminateWorkerContext,
31 OnTerminateWorkerContext) 32 OnTerminateWorkerContext)
32 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect) 33 IPC_MESSAGE_HANDLER(WorkerMsg_Connect, OnConnect)
33 IPC_END_MESSAGE_MAP() 34 IPC_END_MESSAGE_MAP()
34 } 35 }
35 36
36 void WebSharedWorkerStub::OnStartWorkerContext( 37 void WebSharedWorkerStub::OnStartWorkerContext(
37 const GURL& url, const string16& user_agent, const string16& source_code) { 38 const GURL& url, const string16& user_agent, const string16& source_code) {
39 // Ignore multiple attempts to start this worker (can happen if two pages
40 // try to start it simultaneously).
41 if (started_)
42 return;
38 impl_->startWorkerContext(url, name_, user_agent, source_code); 43 impl_->startWorkerContext(url, name_, user_agent, source_code);
44 started_ = true;
39 } 45 }
40 46
41 void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) { 47 void WebSharedWorkerStub::OnConnect(int sent_message_port_id, int routing_id) {
48 DCHECK(started_);
42 WebKit::WebMessagePortChannel* channel = 49 WebKit::WebMessagePortChannel* channel =
43 new WebMessagePortChannelImpl(routing_id, sent_message_port_id); 50 new WebMessagePortChannelImpl(routing_id, sent_message_port_id);
44 impl_->connect(channel, NULL); 51 impl_->connect(channel, NULL);
45 } 52 }
46 53
47 void WebSharedWorkerStub::OnTerminateWorkerContext() { 54 void WebSharedWorkerStub::OnTerminateWorkerContext() {
48 impl_->terminateWorkerContext(); 55 impl_->terminateWorkerContext();
49 56
50 // Call the client to make sure context exits. 57 // Call the client to make sure context exits.
51 EnsureWorkerContextTerminates(); 58 EnsureWorkerContextTerminates();
59 started_ = false;
52 } 60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698