| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "config.h" | 27 #include "config.h" |
| 28 | 28 |
| 29 #include "core/workers/WorkerThread.h" | 29 #include "core/workers/WorkerThread.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/ScriptSourceCode.h" | 31 #include "bindings/core/v8/ScriptSourceCode.h" |
| 32 #include "core/dom/Microtask.h" | 32 #include "core/dom/Microtask.h" |
| 33 #include "core/inspector/InspectorInstrumentation.h" | 33 #include "core/inspector/InspectorInstrumentation.h" |
| 34 #include "core/inspector/WorkerInspectorController.h" | 34 #include "core/inspector/WorkerInspectorController.h" |
| 35 #include "core/workers/DedicatedWorkerGlobalScope.h" | 35 #include "core/workers/DedicatedWorkerGlobalScope.h" |
| 36 #include "core/workers/WorkerClients.h" | 36 #include "core/workers/WorkerClients.h" |
| 37 #include "core/workers/WorkerGlobalScope.h" |
| 38 #include "core/workers/WorkerLanguageTasks.h" |
| 37 #include "core/workers/WorkerReportingProxy.h" | 39 #include "core/workers/WorkerReportingProxy.h" |
| 38 #include "core/workers/WorkerThreadStartupData.h" | 40 #include "core/workers/WorkerThreadStartupData.h" |
| 39 #include "platform/PlatformThreadData.h" | 41 #include "platform/PlatformThreadData.h" |
| 40 #include "platform/Task.h" | 42 #include "platform/Task.h" |
| 41 #include "platform/ThreadTimers.h" | 43 #include "platform/ThreadTimers.h" |
| 42 #include "platform/heap/ThreadState.h" | 44 #include "platform/heap/ThreadState.h" |
| 43 #include "platform/weborigin/KURL.h" | 45 #include "platform/weborigin/KURL.h" |
| 44 #include "public/platform/Platform.h" | 46 #include "public/platform/Platform.h" |
| 45 #include "public/platform/WebThread.h" | 47 #include "public/platform/WebThread.h" |
| 46 #include "public/platform/WebWaitableEvent.h" | 48 #include "public/platform/WebWaitableEvent.h" |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 MutexLocker lock(threadSetMutex()); | 220 MutexLocker lock(threadSetMutex()); |
| 219 ASSERT(workerThreads().contains(this)); | 221 ASSERT(workerThreads().contains(this)); |
| 220 workerThreads().remove(this); | 222 workerThreads().remove(this); |
| 221 } | 223 } |
| 222 | 224 |
| 223 void WorkerThread::start() | 225 void WorkerThread::start() |
| 224 { | 226 { |
| 225 if (m_thread) | 227 if (m_thread) |
| 226 return; | 228 return; |
| 227 | 229 |
| 228 m_thread = WebThreadSupportingGC::create("WebCore: Worker"); | 230 m_thread = adoptPtr(blink::Platform::current()->createThread("WebCore: Worke
r")); |
| 229 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this))); | 231 m_thread->postTask(new Task(WTF::bind(&WorkerThread::initialize, this))); |
| 230 } | 232 } |
| 231 | 233 |
| 232 void WorkerThread::interruptAndDispatchInspectorCommands() | 234 void WorkerThread::interruptAndDispatchInspectorCommands() |
| 233 { | 235 { |
| 234 MutexLocker locker(m_workerInspectorControllerMutex); | 236 MutexLocker locker(m_workerInspectorControllerMutex); |
| 235 if (m_workerInspectorController) | 237 if (m_workerInspectorController) |
| 236 m_workerInspectorController->interruptAndDispatchInspectorCommands(); | 238 m_workerInspectorController->interruptAndDispatchInspectorCommands(); |
| 237 } | 239 } |
| 238 | 240 |
| 239 PlatformThreadId WorkerThread::platformThreadId() const | 241 PlatformThreadId WorkerThread::platformThreadId() const |
| 240 { | 242 { |
| 241 if (!m_thread) | 243 if (!m_thread) |
| 242 return 0; | 244 return 0; |
| 243 return m_thread->platformThread().threadId(); | 245 return m_thread->threadId(); |
| 244 } | 246 } |
| 245 | 247 |
| 246 void WorkerThread::initialize() | 248 void WorkerThread::initialize() |
| 247 { | 249 { |
| 248 KURL scriptURL = m_startupData->m_scriptURL; | 250 KURL scriptURL = m_startupData->m_scriptURL; |
| 249 String sourceCode = m_startupData->m_sourceCode; | 251 String sourceCode = m_startupData->m_sourceCode; |
| 250 WorkerThreadStartMode startMode = m_startupData->m_startMode; | 252 WorkerThreadStartMode startMode = m_startupData->m_startMode; |
| 251 | 253 |
| 252 { | 254 { |
| 253 MutexLocker lock(m_threadCreationMutex); | 255 MutexLocker lock(m_threadCreationMutex); |
| 254 | 256 |
| 255 // The worker was terminated before the thread had a chance to run. | 257 // The worker was terminated before the thread had a chance to run. |
| 256 if (m_terminated) { | 258 if (m_terminated) { |
| 257 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 259 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 258 // This can free this thread object, hence it must not be touched af
terwards. | 260 // This can free this thread object, hence it must not be touched af
terwards. |
| 259 m_workerReportingProxy.workerThreadTerminated(); | 261 m_workerReportingProxy.workerThreadTerminated(); |
| 260 return; | 262 return; |
| 261 } | 263 } |
| 262 | 264 |
| 263 m_microtaskRunner = adoptPtr(new MicrotaskRunner); | 265 m_microtaskRunner = adoptPtr(new MicrotaskRunner); |
| 264 m_thread->addTaskObserver(m_microtaskRunner.get()); | 266 m_thread->addTaskObserver(m_microtaskRunner.get()); |
| 265 m_thread->attachGC(); | 267 m_pendingGCRunner = adoptPtr(new PendingGCRunner); |
| 268 m_messageLoopInterruptor = adoptPtr(new MessageLoopInterruptor(m_thread.
get())); |
| 269 m_thread->addTaskObserver(m_pendingGCRunner.get()); |
| 270 ThreadState::attach(); |
| 271 ThreadState::current()->addInterruptor(m_messageLoopInterruptor.get()); |
| 266 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); | 272 m_workerGlobalScope = createWorkerGlobalScope(m_startupData.release()); |
| 267 | 273 |
| 268 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); | 274 m_sharedTimer = adoptPtr(new WorkerSharedTimer(this)); |
| 269 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); | 275 PlatformThreadData::current().threadTimers().setSharedTimer(m_sharedTime
r.get()); |
| 270 } | 276 } |
| 271 | 277 |
| 272 // The corresponding call to didStopWorkerRunLoop is in | 278 // The corresponding call to didStopWorkerRunLoop is in |
| 273 // ~WorkerScriptController. | 279 // ~WorkerScriptController. |
| 274 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th
is)); | 280 blink::Platform::current()->didStartWorkerRunLoop(blink::WebWorkerRunLoop(th
is)); |
| 275 | 281 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 295 | 301 |
| 296 // The below assignment will destroy the context, which will in turn notify
messaging proxy. | 302 // The below assignment will destroy the context, which will in turn notify
messaging proxy. |
| 297 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. | 303 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. |
| 298 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. | 304 // If Oilpan is enabled, we detach of the context/global scope, with the fin
al heap cleanup below sweeping it out. |
| 299 #if !ENABLE(OILPAN) | 305 #if !ENABLE(OILPAN) |
| 300 ASSERT(m_workerGlobalScope->hasOneRef()); | 306 ASSERT(m_workerGlobalScope->hasOneRef()); |
| 301 #endif | 307 #endif |
| 302 m_workerGlobalScope->dispose(); | 308 m_workerGlobalScope->dispose(); |
| 303 m_workerGlobalScope = nullptr; | 309 m_workerGlobalScope = nullptr; |
| 304 | 310 |
| 305 m_thread->detachGC(); | 311 ThreadState::current()->removeInterruptor(m_messageLoopInterruptor.get()); |
| 312 |
| 313 // Detach the ThreadState, cleaning out the thread's heap by |
| 314 // performing a final GC. The cleanup operation will at the end |
| 315 // assert that the heap is empty. If the heap does not become |
| 316 // empty, there are still pointers into the heap and those |
| 317 // pointers will be dangling after thread termination because we |
| 318 // are destroying the heap. It is important to detach while the |
| 319 // thread is still valid. In particular, finalizers for objects in |
| 320 // the heap for this thread will need to access thread local data. |
| 321 ThreadState::detach(); |
| 306 | 322 |
| 307 m_thread->removeTaskObserver(m_microtaskRunner.get()); | 323 m_thread->removeTaskObserver(m_microtaskRunner.get()); |
| 308 m_microtaskRunner = nullptr; | 324 m_microtaskRunner = nullptr; |
| 325 m_thread->removeTaskObserver(m_pendingGCRunner.get()); |
| 326 m_pendingGCRunner = nullptr; |
| 327 m_messageLoopInterruptor = nullptr; |
| 309 | 328 |
| 310 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 329 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 311 // This can free this thread object, hence it must not be touched afterwards
. | 330 // This can free this thread object, hence it must not be touched afterwards
. |
| 312 workerReportingProxy().workerThreadTerminated(); | 331 workerReportingProxy().workerThreadTerminated(); |
| 313 | 332 |
| 314 m_terminationEvent->signal(); | 333 m_terminationEvent->signal(); |
| 315 | 334 |
| 316 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! | 335 // Clean up PlatformThreadData before WTF::WTFThreadData goes away! |
| 317 PlatformThreadData::current().destroy(); | 336 PlatformThreadData::current().destroy(); |
| 318 } | 337 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 { | 497 { |
| 479 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 498 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 480 } | 499 } |
| 481 | 500 |
| 482 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 501 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
| 483 { | 502 { |
| 484 MutexLocker locker(m_workerInspectorControllerMutex); | 503 MutexLocker locker(m_workerInspectorControllerMutex); |
| 485 m_workerInspectorController = workerInspectorController; | 504 m_workerInspectorController = workerInspectorController; |
| 486 } | 505 } |
| 487 | 506 |
| 507 void WorkerThread::postTaskLanguageChanged() |
| 508 { |
| 509 postTask(WorkerThreadAcceptLanguagesChangedTask::create()); |
| 510 } |
| 511 |
| 512 void WorkerThread::notifyAcceptLanguagesChanged(const Vector<String>& newLanguag
esList) |
| 513 { |
| 514 MutexLocker lock(threadSetMutex()); |
| 515 HashSet<WorkerThread*> threads = workerThreads(); |
| 516 |
| 517 for (HashSet<WorkerThread*>::iterator itr = threads.begin(); itr != threads.
end(); ++itr) { |
| 518 // Set the new languages list |
| 519 (*itr)->postTask(WorkerThreadSetUserPreferredLanguagesTask::create(newLa
nguagesList)); |
| 520 // Mark the langs have changed and queue up an event |
| 521 (*itr)->postTask(WorkerThreadAcceptLanguagesChangedTask::create()); |
| 522 } |
| 523 } |
| 524 |
| 525 // void WorkerThread::notifyAcceptLanguagesChanged(const String& newLanguagesLis
t) |
| 526 // { |
| 527 // MutexLocker lock(threadSetMutex()); |
| 528 // HashSet<WorkerThread*> threads = workerThreads(); |
| 529 // Vector<String> languages; |
| 530 // String acceptLanguages = m_frame->host()->chrome().client().acceptLanguag
es(); |
| 531 // acceptLanguages.split(',', languages); |
| 532 |
| 533 // for (HashSet<WorkerThread*>::iterator itr = threads.begin(); itr != threa
ds.end(); ++itr) { |
| 534 // // Set the new languages list |
| 535 // (*itr)->postTask(WorkerThreadSetUserPreferredLanguagesTask::create(la
nguages)); |
| 536 // // Mark the langs have changed and queue up an event |
| 537 // (*itr)->postTask(WorkerThreadAcceptLanguagesChangedTask::create()); |
| 538 // } |
| 539 // } |
| 540 |
| 488 } // namespace blink | 541 } // namespace blink |
| OLD | NEW |