OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
3 * Copyright (C) 2009 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 , m_unconfirmedMessageCount(0) | 74 , m_unconfirmedMessageCount(0) |
75 , m_workerThreadHadPendingActivity(false) | 75 , m_workerThreadHadPendingActivity(false) |
76 , m_askedToTerminate(false) | 76 , m_askedToTerminate(false) |
77 , m_workerInspectorProxy(WorkerInspectorProxy::create()) | 77 , m_workerInspectorProxy(WorkerInspectorProxy::create()) |
78 , m_workerClients(workerClients) | 78 , m_workerClients(workerClients) |
79 { | 79 { |
80 ASSERT(m_workerObject); | 80 ASSERT(m_workerObject); |
81 ASSERT((m_executionContext->isDocument() && isMainThread()) | 81 ASSERT((m_executionContext->isDocument() && isMainThread()) |
82 || (m_executionContext->isWorkerGlobalScope() && toWorkerGlobalScope(m_e xecutionContext.get())->thread()->isCurrentThread())); | 82 || (m_executionContext->isWorkerGlobalScope() && toWorkerGlobalScope(m_e xecutionContext.get())->thread()->isCurrentThread())); |
83 m_workerInspectorProxy->setWorkerGlobalScopeProxy(this); | 83 m_workerInspectorProxy->setWorkerGlobalScopeProxy(this); |
84 #if ENABLE(OILPAN) | |
85 m_keepAlive = adoptPtr(new Persistent<WorkerMessagingProxy>(this)); | |
86 #endif | |
84 } | 87 } |
85 | 88 |
86 WorkerMessagingProxy::~WorkerMessagingProxy() | 89 WorkerMessagingProxy::~WorkerMessagingProxy() |
87 { | 90 { |
88 ASSERT(!m_workerObject); | 91 ASSERT(!m_workerObject); |
92 #if !ENABLE(OILPAN) | |
89 ASSERT((m_executionContext->isDocument() && isMainThread()) | 93 ASSERT((m_executionContext->isDocument() && isMainThread()) |
90 || (m_executionContext->isWorkerGlobalScope() && toWorkerGlobalScope(m_e xecutionContext.get())->thread()->isCurrentThread())); | 94 || (m_executionContext->isWorkerGlobalScope() && toWorkerGlobalScope(m_e xecutionContext.get())->thread()->isCurrentThread())); |
95 #endif | |
91 if (m_loaderProxy) | 96 if (m_loaderProxy) |
92 m_loaderProxy->detachProvider(this); | 97 m_loaderProxy->detachProvider(this); |
93 } | 98 } |
94 | 99 |
95 void WorkerMessagingProxy::startWorkerGlobalScope(const KURL& scriptURL, const S tring& userAgent, const String& sourceCode, WorkerThreadStartMode startMode) | 100 void WorkerMessagingProxy::startWorkerGlobalScope(const KURL& scriptURL, const S tring& userAgent, const String& sourceCode, WorkerThreadStartMode startMode) |
96 { | 101 { |
97 // FIXME: This need to be revisited when we support nested worker one day | 102 // FIXME: This need to be revisited when we support nested worker one day |
98 ASSERT(m_executionContext->isDocument()); | 103 ASSERT(m_executionContext->isDocument()); |
99 if (m_askedToTerminate) { | 104 if (m_askedToTerminate) { |
100 // Worker.terminate() could be called from JS before the thread was crea ted. | 105 // Worker.terminate() could be called from JS before the thread was crea ted. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 workerThreadTerminated(); | 220 workerThreadTerminated(); |
216 } | 221 } |
217 | 222 |
218 void WorkerMessagingProxy::workerThreadTerminated() | 223 void WorkerMessagingProxy::workerThreadTerminated() |
219 { | 224 { |
220 // This method is always the last to be performed, so the proxy is not neede d for communication | 225 // This method is always the last to be performed, so the proxy is not neede d for communication |
221 // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too. | 226 // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too. |
222 m_askedToTerminate = true; | 227 m_askedToTerminate = true; |
223 m_workerThread = nullptr; | 228 m_workerThread = nullptr; |
224 terminateInternally(); | 229 terminateInternally(); |
225 if (m_mayBeDestroyed) | 230 if (m_mayBeDestroyed) { |
231 #if ENABLE(OILPAN) | |
232 m_keepAlive.release(); | |
233 #else | |
226 delete this; | 234 delete this; |
235 #endif | |
236 } | |
227 } | 237 } |
228 | 238 |
229 void WorkerMessagingProxy::terminateWorkerGlobalScope() | 239 void WorkerMessagingProxy::terminateWorkerGlobalScope() |
230 { | 240 { |
231 if (m_askedToTerminate) | 241 if (m_askedToTerminate) |
232 return; | 242 return; |
233 m_askedToTerminate = true; | 243 m_askedToTerminate = true; |
234 | 244 |
235 if (m_workerThread) | 245 if (m_workerThread) |
236 m_workerThread->terminate(); | 246 m_workerThread->terminate(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 m_workerInspectorProxy->workerThreadTerminated(); | 295 m_workerInspectorProxy->workerThreadTerminated(); |
286 | 296 |
287 // FIXME: This need to be revisited when we support nested worker one day | 297 // FIXME: This need to be revisited when we support nested worker one day |
288 ASSERT(m_executionContext->isDocument()); | 298 ASSERT(m_executionContext->isDocument()); |
289 Document* document = toDocument(m_executionContext.get()); | 299 Document* document = toDocument(m_executionContext.get()); |
290 LocalFrame* frame = document->frame(); | 300 LocalFrame* frame = document->frame(); |
291 if (frame) | 301 if (frame) |
292 frame->console().adoptWorkerMessagesAfterTermination(this); | 302 frame->console().adoptWorkerMessagesAfterTermination(this); |
293 } | 303 } |
294 | 304 |
305 void WorkerMessagingProxy::clearWeakMembers(Visitor* visitor) | |
306 { | |
307 if (Heap::isHeapObjectAlive(m_workerObject)) | |
308 return; | |
309 workerObjectDestroyed(); | |
haraken
2015/07/30 11:46:31
It is not nice to call workerObjectDestroyed() in
| |
310 } | |
311 | |
312 DEFINE_TRACE(WorkerMessagingProxy) | |
313 { | |
314 visitor->trace(m_executionContext); | |
315 visitor->trace(m_workerClients); | |
316 visitor->template registerWeakMembers<WorkerMessagingProxy, &WorkerMessaging Proxy::clearWeakMembers>(this); | |
317 WorkerGlobalScopeProxy::trace(visitor); | |
318 } | |
319 | |
295 } // namespace blink | 320 } // namespace blink |
OLD | NEW |