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

Side by Side Diff: content/worker/websharedworker_stub.cc

Issue 171943002: Don't terminate SharedWorker while loading the script. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months 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
« no previous file with comments | « content/worker/websharedworker_stub.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "content/worker/websharedworker_stub.h" 5 #include "content/worker/websharedworker_stub.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "content/child/child_process.h" 8 #include "content/child/child_process.h"
9 #include "content/child/child_thread.h" 9 #include "content/child/child_thread.h"
10 #include "content/child/fileapi/file_system_dispatcher.h" 10 #include "content/child/fileapi/file_system_dispatcher.h"
11 #include "content/child/shared_worker_devtools_agent.h" 11 #include "content/child/shared_worker_devtools_agent.h"
12 #include "content/child/webmessageportchannel_impl.h" 12 #include "content/child/webmessageportchannel_impl.h"
13 #include "content/common/worker_messages.h" 13 #include "content/common/worker_messages.h"
14 #include "content/worker/worker_thread.h" 14 #include "content/worker/worker_thread.h"
15 #include "third_party/WebKit/public/web/WebSharedWorker.h" 15 #include "third_party/WebKit/public/web/WebSharedWorker.h"
16 #include "third_party/WebKit/public/platform/WebString.h" 16 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "third_party/WebKit/public/platform/WebURL.h" 17 #include "third_party/WebKit/public/platform/WebURL.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 WebSharedWorkerStub::WebSharedWorkerStub( 21 WebSharedWorkerStub::WebSharedWorkerStub(
22 const GURL& url, 22 const GURL& url,
23 const base::string16& name, 23 const base::string16& name,
24 const base::string16& content_security_policy, 24 const base::string16& content_security_policy,
25 blink::WebContentSecurityPolicyType security_policy_type, 25 blink::WebContentSecurityPolicyType security_policy_type,
26 int route_id) 26 int route_id)
27 : route_id_(route_id), 27 : route_id_(route_id),
28 client_(route_id, this), 28 client_(route_id, this),
29 running_(false), 29 running_(false),
30 terminating_(false),
30 url_(url) { 31 url_(url) {
31 32
32 WorkerThread* worker_thread = WorkerThread::current(); 33 WorkerThread* worker_thread = WorkerThread::current();
33 DCHECK(worker_thread); 34 DCHECK(worker_thread);
34 worker_thread->AddWorkerStub(this); 35 worker_thread->AddWorkerStub(this);
35 // Start processing incoming IPCs for this worker. 36 // Start processing incoming IPCs for this worker.
36 worker_thread->AddRoute(route_id_, this); 37 worker_thread->AddRoute(route_id_, this);
37 38
38 // TODO(atwilson): Add support for NaCl when they support MessagePorts. 39 // TODO(atwilson): Add support for NaCl when they support MessagePorts.
39 impl_ = blink::WebSharedWorker::create(client()); 40 impl_ = blink::WebSharedWorker::create(client());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } else { 96 } else {
96 // If two documents try to load a SharedWorker at the same time, the 97 // If two documents try to load a SharedWorker at the same time, the
97 // WorkerMsg_Connect for one of the documents can come in before the 98 // WorkerMsg_Connect for one of the documents can come in before the
98 // worker is started. Just queue up the connect and deliver it once the 99 // worker is started. Just queue up the connect and deliver it once the
99 // worker starts. 100 // worker starts.
100 pending_channels_.push_back(channel); 101 pending_channels_.push_back(channel);
101 } 102 }
102 } 103 }
103 104
104 void WebSharedWorkerStub::OnTerminateWorkerContext() { 105 void WebSharedWorkerStub::OnTerminateWorkerContext() {
105 impl_->terminateWorkerContext(); 106 if (running_) {
106 107 impl_->terminateWorkerContext();
kinuko 2014/02/19 04:24:08 It feels like we should always nullify the impl_ a
horo 2014/02/19 05:29:09 The bug is caused by "delete this" in Shutdown() w
107 // Call the client to make sure context exits. 108 // Call the client to make sure context exits.
108 EnsureWorkerContextTerminates(); 109 EnsureWorkerContextTerminates();
109 running_ = false; 110 running_ = false;
111 } else {
112 terminating_ = true;
113 }
110 } 114 }
111 115
112 void WebSharedWorkerStub::WorkerScriptLoaded() { 116 void WebSharedWorkerStub::WorkerScriptLoaded() {
113 running_ = true; 117 running_ = true;
118 if (terminating_) {
119 OnTerminateWorkerContext();
120 return;
121 }
114 // Process any pending connections. 122 // Process any pending connections.
115 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); 123 for (PendingChannelList::const_iterator iter = pending_channels_.begin();
116 iter != pending_channels_.end(); 124 iter != pending_channels_.end();
117 ++iter) { 125 ++iter) {
118 impl_->connect(*iter); 126 impl_->connect(*iter);
119 WorkerThread::current()->Send( 127 WorkerThread::current()->Send(
120 new WorkerHostMsg_WorkerConnected((*iter)->message_port_id(), 128 new WorkerHostMsg_WorkerConnected((*iter)->message_port_id(),
121 route_id_)); 129 route_id_));
122 } 130 }
123 pending_channels_.clear(); 131 pending_channels_.clear();
124 } 132 }
125 133
126 void WebSharedWorkerStub::WorkerScriptLoadFailed() { 134 void WebSharedWorkerStub::WorkerScriptLoadFailed() {
127 for (PendingChannelList::const_iterator iter = pending_channels_.begin(); 135 for (PendingChannelList::const_iterator iter = pending_channels_.begin();
128 iter != pending_channels_.end(); 136 iter != pending_channels_.end();
129 ++iter) { 137 ++iter) {
130 blink::WebMessagePortChannel* channel = *iter; 138 blink::WebMessagePortChannel* channel = *iter;
131 channel->destroy(); 139 channel->destroy();
132 } 140 }
133 pending_channels_.clear(); 141 pending_channels_.clear();
134 Shutdown(); 142 Shutdown();
135 } 143 }
136 144
137 } // namespace content 145 } // namespace content
OLDNEW
« no previous file with comments | « content/worker/websharedworker_stub.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698