Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 * | 24 * |
| 25 */ | 25 */ |
| 26 | 26 |
| 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 "bindings/core/v8/V8Initializer.h" | 32 #include "bindings/core/v8/V8Initializer.h" |
| 33 #include "core/dom/Microtask.h" | 33 #include "core/dom/Microtask.h" |
| 34 #include "core/fetch/CachedMetadata.h" | |
| 35 #include "core/fetch/CachedMetadataHandler.h" | |
| 34 #include "core/inspector/InspectorInstrumentation.h" | 36 #include "core/inspector/InspectorInstrumentation.h" |
| 35 #include "core/inspector/WorkerInspectorController.h" | 37 #include "core/inspector/WorkerInspectorController.h" |
| 36 #include "core/workers/DedicatedWorkerGlobalScope.h" | 38 #include "core/workers/DedicatedWorkerGlobalScope.h" |
| 37 #include "core/workers/WorkerClients.h" | 39 #include "core/workers/WorkerClients.h" |
| 38 #include "core/workers/WorkerReportingProxy.h" | 40 #include "core/workers/WorkerReportingProxy.h" |
| 39 #include "core/workers/WorkerThreadStartupData.h" | 41 #include "core/workers/WorkerThreadStartupData.h" |
| 40 #include "platform/PlatformThreadData.h" | 42 #include "platform/PlatformThreadData.h" |
| 41 #include "platform/Task.h" | 43 #include "platform/Task.h" |
| 42 #include "platform/ThreadTimers.h" | 44 #include "platform/ThreadTimers.h" |
| 43 #include "platform/heap/ThreadState.h" | 45 #include "platform/heap/ThreadState.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 74 scriptController->rejectedPromises()->processQueue(); | 76 scriptController->rejectedPromises()->processQueue(); |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 private: | 80 private: |
| 79 // Thread owns the microtask runner; reference remains | 81 // Thread owns the microtask runner; reference remains |
| 80 // valid for the lifetime of this object. | 82 // valid for the lifetime of this object. |
| 81 WorkerThread* m_workerThread; | 83 WorkerThread* m_workerThread; |
| 82 }; | 84 }; |
| 83 | 85 |
| 86 class WorkerScriptCachedMetadataHandler : public CachedMetadataHandler { | |
|
kinuko
2015/02/16 14:18:38
This class can be probably in its own file, as it'
horo
2015/02/16 16:20:12
Done.
| |
| 87 public: | |
| 88 WorkerScriptCachedMetadataHandler(WorkerGlobalScope* workerGlobalScope, cons t KURL& scriptURL, const Vector<char>* metaData) | |
| 89 : m_workerGlobalScope(workerGlobalScope) | |
| 90 , m_scriptURL(scriptURL) | |
| 91 { | |
| 92 if (metaData) | |
| 93 m_cachedMetadata = CachedMetadata::deserialize(metaData->data(), met aData->size()); | |
| 94 } | |
| 95 ~WorkerScriptCachedMetadataHandler() override { } | |
| 96 void setCachedMetadata(unsigned dataTypeID, const char* data, size_t size, C acheType type) override | |
| 97 { | |
| 98 if (type != SendToPlatform) | |
| 99 return; | |
| 100 m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size); | |
| 101 const Vector<char>& serializedData = m_cachedMetadata->serialize(); | |
| 102 m_workerGlobalScope->setCachedMetadata(m_scriptURL, serializedData.data( ), serializedData.size()); | |
| 103 } | |
| 104 void clearCachedMetadata(CacheType type) override | |
| 105 { | |
| 106 if (type != SendToPlatform) | |
| 107 return; | |
| 108 m_cachedMetadata = nullptr; | |
| 109 m_workerGlobalScope->clearCachedMetadata(m_scriptURL); | |
| 110 } | |
| 111 CachedMetadata* cachedMetadata(unsigned dataTypeID) const override | |
| 112 { | |
| 113 if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID) | |
| 114 return nullptr; | |
| 115 return m_cachedMetadata.get(); | |
| 116 } | |
| 117 String encoding() const override { return ""; } | |
| 118 | |
| 119 private: | |
| 120 WorkerGlobalScope* m_workerGlobalScope; | |
| 121 KURL m_scriptURL; | |
| 122 RefPtr<CachedMetadata> m_cachedMetadata; | |
| 123 }; | |
| 124 | |
| 84 } // namespace | 125 } // namespace |
| 85 | 126 |
| 86 static Mutex& threadSetMutex() | 127 static Mutex& threadSetMutex() |
| 87 { | 128 { |
| 88 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex); | 129 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex); |
| 89 return mutex; | 130 return mutex; |
| 90 } | 131 } |
| 91 | 132 |
| 92 static HashSet<WorkerThread*>& workerThreads() | 133 static HashSet<WorkerThread*>& workerThreads() |
| 93 { | 134 { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 if (!m_thread) | 345 if (!m_thread) |
| 305 return 0; | 346 return 0; |
| 306 return m_thread->platformThread().threadId(); | 347 return m_thread->platformThread().threadId(); |
| 307 } | 348 } |
| 308 | 349 |
| 309 void WorkerThread::initialize() | 350 void WorkerThread::initialize() |
| 310 { | 351 { |
| 311 KURL scriptURL = m_startupData->m_scriptURL; | 352 KURL scriptURL = m_startupData->m_scriptURL; |
| 312 String sourceCode = m_startupData->m_sourceCode; | 353 String sourceCode = m_startupData->m_sourceCode; |
| 313 WorkerThreadStartMode startMode = m_startupData->m_startMode; | 354 WorkerThreadStartMode startMode = m_startupData->m_startMode; |
| 355 OwnPtr<Vector<char>> cachedMetaData = m_startupData->m_cachedMetaData.releas e(); | |
| 356 V8CacheOptions v8CacheOptions = m_startupData->m_v8CacheOptions; | |
| 314 | 357 |
| 315 { | 358 { |
| 316 MutexLocker lock(m_threadCreationMutex); | 359 MutexLocker lock(m_threadCreationMutex); |
| 317 | 360 |
| 318 // The worker was terminated before the thread had a chance to run. | 361 // The worker was terminated before the thread had a chance to run. |
| 319 if (m_terminated) { | 362 if (m_terminated) { |
| 320 // Notify the proxy that the WorkerGlobalScope has been disposed of. | 363 // Notify the proxy that the WorkerGlobalScope has been disposed of. |
| 321 // This can free this thread object, hence it must not be touched af terwards. | 364 // This can free this thread object, hence it must not be touched af terwards. |
| 322 m_workerReportingProxy.workerThreadTerminated(); | 365 m_workerReportingProxy.workerThreadTerminated(); |
| 323 return; | 366 return; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 335 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). | 378 // The corresponding call to stopRunLoop() is in ~WorkerScriptController(). |
| 336 didStartRunLoop(); | 379 didStartRunLoop(); |
| 337 | 380 |
| 338 // Notify proxy that a new WorkerGlobalScope has been created and started. | 381 // Notify proxy that a new WorkerGlobalScope has been created and started. |
| 339 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); | 382 m_workerReportingProxy.workerGlobalScopeStarted(m_workerGlobalScope.get()); |
| 340 | 383 |
| 341 WorkerScriptController* script = m_workerGlobalScope->script(); | 384 WorkerScriptController* script = m_workerGlobalScope->script(); |
| 342 if (!script->isExecutionForbidden()) | 385 if (!script->isExecutionForbidden()) |
| 343 script->initializeContextIfNeeded(); | 386 script->initializeContextIfNeeded(); |
| 344 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star tMode); | 387 InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), star tMode); |
| 345 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL)); | 388 WorkerScriptCachedMetadataHandler handler(workerGlobalScope(), scriptURL, ca chedMetaData.get()); |
| 389 bool success = script->evaluate(ScriptSourceCode(sourceCode, scriptURL), nul lptr, &handler, v8CacheOptions); | |
| 346 m_workerGlobalScope->didEvaluateWorkerScript(); | 390 m_workerGlobalScope->didEvaluateWorkerScript(); |
| 347 m_workerReportingProxy.didEvaluateWorkerScript(success); | 391 m_workerReportingProxy.didEvaluateWorkerScript(success); |
| 348 | 392 |
| 349 postInitialize(); | 393 postInitialize(); |
| 350 | 394 |
| 351 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), kSho rtIdleHandlerDelayMs); | 395 postDelayedTask(createSameThreadTask(&WorkerThread::idleHandler, this), kSho rtIdleHandlerDelayMs); |
| 352 } | 396 } |
| 353 | 397 |
| 354 void WorkerThread::cleanup() | 398 void WorkerThread::cleanup() |
| 355 { | 399 { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 566 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); | 610 InspectorInstrumentation::didLeaveNestedRunLoop(m_workerGlobalScope.get()); |
| 567 } | 611 } |
| 568 | 612 |
| 569 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) | 613 void WorkerThread::setWorkerInspectorController(WorkerInspectorController* worke rInspectorController) |
| 570 { | 614 { |
| 571 MutexLocker locker(m_workerInspectorControllerMutex); | 615 MutexLocker locker(m_workerInspectorControllerMutex); |
| 572 m_workerInspectorController = workerInspectorController; | 616 m_workerInspectorController = workerInspectorController; |
| 573 } | 617 } |
| 574 | 618 |
| 575 } // namespace blink | 619 } // namespace blink |
| OLD | NEW |