| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 m_running = true; | 164 m_running = true; |
| 165 m_nextFireTime = currentTime() + interval; | 165 m_nextFireTime = currentTime() + interval; |
| 166 | 166 |
| 167 if (m_lastQueuedTask.get()) | 167 if (m_lastQueuedTask.get()) |
| 168 m_lastQueuedTask->cancelTask(); | 168 m_lastQueuedTask->cancelTask(); |
| 169 | 169 |
| 170 // Now queue the task as a cancellable one. | 170 // Now queue the task as a cancellable one. |
| 171 OwnPtr<WorkerThreadCancelableTask> task = WorkerThreadCancelableTask::cr
eate(bind(&WorkerSharedTimer::OnTimeout, this)); | 171 OwnPtr<WorkerThreadCancelableTask> task = WorkerThreadCancelableTask::cr
eate(bind(&WorkerSharedTimer::OnTimeout, this)); |
| 172 m_lastQueuedTask = task->createWeakPtr(); | 172 m_lastQueuedTask = task->createWeakPtr(); |
| 173 m_workerThread->postDelayedTask(FROM_HERE, task.release(), delay); | 173 m_workerThread->postDelayedTask(task.release(), delay); |
| 174 } | 174 } |
| 175 | 175 |
| 176 virtual void stop() | 176 virtual void stop() |
| 177 { | 177 { |
| 178 m_running = false; | 178 m_running = false; |
| 179 m_lastQueuedTask = nullptr; | 179 m_lastQueuedTask = nullptr; |
| 180 } | 180 } |
| 181 | 181 |
| 182 double nextFireTime() { return m_nextFireTime; } | 182 double nextFireTime() { return m_nextFireTime; } |
| 183 | 183 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 script->initializeContextIfNeeded(); | 345 script->initializeContextIfNeeded(); |
| 346 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star
tMode); | 346 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star
tMode); |
| 347 | 347 |
| 348 OwnPtr<CachedMetadataHandler> handler(workerGlobalScope()->createWorkerScrip
tCachedMetadataHandler(scriptURL, cachedMetaData.get())); | 348 OwnPtr<CachedMetadataHandler> handler(workerGlobalScope()->createWorkerScrip
tCachedMetadataHandler(scriptURL, cachedMetaData.get())); |
| 349 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL), nul
lptr, handler.get(), v8CacheOptions); | 349 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL), nul
lptr, handler.get(), v8CacheOptions); |
| 350 m_workerGlobalScope->didEvaluateWorkerScript(); | 350 m_workerGlobalScope->didEvaluateWorkerScript(); |
| 351 m_workerReportingProxy.didEvaluateWorkerScript(success); | 351 m_workerReportingProxy.didEvaluateWorkerScript(success); |
| 352 | 352 |
| 353 postInitialize(); | 353 postInitialize(); |
| 354 | 354 |
| 355 postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler,
this), kShortIdleHandlerDelayMs); | 355 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), kSho
rtIdleHandlerDelayMs); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void WorkerThread::cleanup() | 358 void WorkerThread::cleanup() |
| 359 { | 359 { |
| 360 | 360 |
| 361 // This should be called before we start the shutdown procedure. | 361 // This should be called before we start the shutdown procedure. |
| 362 workerReportingProxy().willDestroyWorkerGlobalScope(); | 362 workerReportingProxy().willDestroyWorkerGlobalScope(); |
| 363 | 363 |
| 364 // The below assignment will destroy the context, which will in turn notify
messaging proxy. | 364 // The below assignment will destroy the context, which will in turn notify
messaging proxy. |
| 365 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. | 365 // We cannot let any objects survive past thread exit, because no other thre
ad will run GC or otherwise destroy them. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); | 416 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); |
| 417 workerGlobalScope->stopActiveDOMObjects(); | 417 workerGlobalScope->stopActiveDOMObjects(); |
| 418 PlatformThreadData::current().threadTimers().setSharedTimer(nullptr); | 418 PlatformThreadData::current().threadTimers().setSharedTimer(nullptr); |
| 419 | 419 |
| 420 // Event listeners would keep DOMWrapperWorld objects alive for too long
. Also, they have references to JS objects, | 420 // Event listeners would keep DOMWrapperWorld objects alive for too long
. Also, they have references to JS objects, |
| 421 // which become dangling once Heap is destroyed. | 421 // which become dangling once Heap is destroyed. |
| 422 workerGlobalScope->removeAllEventListeners(); | 422 workerGlobalScope->removeAllEventListeners(); |
| 423 | 423 |
| 424 // Stick a shutdown command at the end of the queue, so that we deal | 424 // Stick a shutdown command at the end of the queue, so that we deal |
| 425 // with all the cleanup tasks the databases post first. | 425 // with all the cleanup tasks the databases post first. |
| 426 workerGlobalScope->postTask(FROM_HERE, WorkerThreadShutdownFinishTask::c
reate()); | 426 workerGlobalScope->postTask(WorkerThreadShutdownFinishTask::create()); |
| 427 } | 427 } |
| 428 | 428 |
| 429 virtual bool isCleanupTask() const { return true; } | 429 virtual bool isCleanupTask() const { return true; } |
| 430 }; | 430 }; |
| 431 | 431 |
| 432 void WorkerThread::stop() | 432 void WorkerThread::stop() |
| 433 { | 433 { |
| 434 // Prevent the deadlock between GC and an attempt to stop a thread. | 434 // Prevent the deadlock between GC and an attempt to stop a thread. |
| 435 ThreadState::SafePointScope safePointScope(ThreadState::HeapPointersOnStack)
; | 435 ThreadState::SafePointScope safePointScope(ThreadState::HeapPointersOnStack)
; |
| 436 stopInternal(); | 436 stopInternal(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 467 if (m_shutdownEvent) | 467 if (m_shutdownEvent) |
| 468 m_shutdownEvent->signal(); | 468 m_shutdownEvent->signal(); |
| 469 | 469 |
| 470 if (!m_workerGlobalScope) | 470 if (!m_workerGlobalScope) |
| 471 return; | 471 return; |
| 472 | 472 |
| 473 // Ensure that tasks are being handled by thread event loop. If script execu
tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve
r. | 473 // Ensure that tasks are being handled by thread event loop. If script execu
tion weren't forbidden, a while(1) loop in JS could keep the thread alive foreve
r. |
| 474 m_workerGlobalScope->script()->scheduleExecutionTermination(); | 474 m_workerGlobalScope->script()->scheduleExecutionTermination(); |
| 475 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); | 475 InspectorInstrumentation::didKillAllExecutionContextTasks(m_workerGlobalScop
e.get()); |
| 476 m_debuggerMessageQueue.kill(); | 476 m_debuggerMessageQueue.kill(); |
| 477 postTask(FROM_HERE, WorkerThreadShutdownStartTask::create()); | 477 postTask(WorkerThreadShutdownStartTask::create()); |
| 478 } | 478 } |
| 479 | 479 |
| 480 void WorkerThread::didStartRunLoop() | 480 void WorkerThread::didStartRunLoop() |
| 481 { | 481 { |
| 482 ASSERT(isCurrentThread()); | 482 ASSERT(isCurrentThread()); |
| 483 blink::Platform::current()->didStartWorkerRunLoop(WebWorkerRunLoop(this)); | 483 blink::Platform::current()->didStartWorkerRunLoop(WebWorkerRunLoop(this)); |
| 484 } | 484 } |
| 485 | 485 |
| 486 void WorkerThread::didStopRunLoop() | 486 void WorkerThread::didStopRunLoop() |
| 487 { | 487 { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 512 int64_t delay = kLongIdleHandlerDelayMs; | 512 int64_t delay = kLongIdleHandlerDelayMs; |
| 513 | 513 |
| 514 // Do a script engine idle notification if the next event is distant enough. | 514 // Do a script engine idle notification if the next event is distant enough. |
| 515 const double kMinIdleTimespan = 0.3; | 515 const double kMinIdleTimespan = 0.3; |
| 516 if (m_sharedTimer->nextFireTime() == 0.0 || m_sharedTimer->nextFireTime() >
currentTime() + kMinIdleTimespan) { | 516 if (m_sharedTimer->nextFireTime() == 0.0 || m_sharedTimer->nextFireTime() >
currentTime() + kMinIdleTimespan) { |
| 517 bool hasMoreWork = !m_workerGlobalScope->idleNotification(); | 517 bool hasMoreWork = !m_workerGlobalScope->idleNotification(); |
| 518 if (hasMoreWork) | 518 if (hasMoreWork) |
| 519 delay = kShortIdleHandlerDelayMs; | 519 delay = kShortIdleHandlerDelayMs; |
| 520 } | 520 } |
| 521 | 521 |
| 522 postDelayedTask(FROM_HERE, createSameThreadTask(&WorkerThread::idleHandler,
this), delay); | 522 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), dela
y); |
| 523 } | 523 } |
| 524 | 524 |
| 525 void WorkerThread::postTask(const WebTraceLocation& location, PassOwnPtr<Executi
onContextTask> task) | 525 void WorkerThread::postTask(PassOwnPtr<ExecutionContextTask> task) |
| 526 { | 526 { |
| 527 m_thread->postTask(location, WorkerThreadTask::create(*this, task, true).lea
kPtr()); | 527 m_thread->postTask(FROM_HERE, WorkerThreadTask::create(*this, task, true).le
akPtr()); |
| 528 } | 528 } |
| 529 | 529 |
| 530 void WorkerThread::postDelayedTask(const WebTraceLocation& location, PassOwnPtr<
ExecutionContextTask> task, long long delayMs) | 530 void WorkerThread::postDelayedTask(PassOwnPtr<ExecutionContextTask> task, long l
ong delayMs) |
| 531 { | 531 { |
| 532 m_thread->postDelayedTask(location, WorkerThreadTask::create(*this, task, tr
ue).leakPtr(), delayMs); | 532 m_thread->postDelayedTask(FROM_HERE, WorkerThreadTask::create(*this, task, t
rue).leakPtr(), delayMs); |
| 533 } | 533 } |
| 534 | 534 |
| 535 void WorkerThread::postDebuggerTask(const WebTraceLocation& location, PassOwnPtr
<ExecutionContextTask> task) | 535 void WorkerThread::postDebuggerTask(PassOwnPtr<ExecutionContextTask> task) |
| 536 { | 536 { |
| 537 m_debuggerMessageQueue.append(WorkerThreadTask::create(*this, task, false)); | 537 m_debuggerMessageQueue.append(WorkerThreadTask::create(*this, task, false)); |
| 538 postTask(location, RunDebuggerQueueTask::create(this)); | 538 postTask(RunDebuggerQueueTask::create(this)); |
| 539 } | 539 } |
| 540 | 540 |
| 541 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) | 541 MessageQueueWaitResult WorkerThread::runDebuggerTask(WaitMode waitMode) |
| 542 { | 542 { |
| 543 ASSERT(isCurrentThread()); | 543 ASSERT(isCurrentThread()); |
| 544 MessageQueueWaitResult result; | 544 MessageQueueWaitResult result; |
| 545 double absoluteTime = MessageQueue<blink::WebThread::Task>::infiniteTime(); | 545 double absoluteTime = MessageQueue<blink::WebThread::Task>::infiniteTime(); |
| 546 OwnPtr<blink::WebThread::Task> task; | 546 OwnPtr<blink::WebThread::Task> task; |
| 547 { | 547 { |
| 548 if (waitMode == DontWaitForMessage) | 548 if (waitMode == DontWaitForMessage) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 570 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 570 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) | 573 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke
rInspectorController) |
| 574 { | 574 { |
| 575 MutexLocker locker(m_workerInspectorControllerMutex); | 575 MutexLocker locker(m_workerInspectorControllerMutex); |
| 576 m_workerInspectorController = workerInspectorController; | 576 m_workerInspectorController = workerInspectorController; |
| 577 } | 577 } |
| 578 | 578 |
| 579 } // namespace blink | 579 } // namespace blink |
| OLD | NEW |