void ensureStartLoader() { if (m_loaderStarted) return; m_loaderStarted = true; m_loaderContextHolder->postTask(crossThreadBind(&LoaderContext::start)); }
TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) { m_lazyDecoder->setData(m_data, true); sk_sp<SkImage> image = m_lazyDecoder->createFrameAtIndex(0); ASSERT_TRUE(image); EXPECT_EQ(1, image->width()); EXPECT_EQ(1, image->height()); SkPictureRecorder recorder; SkCanvas* tempCanvas = recorder.beginRecording(100, 100, 0, 0); tempCanvas->drawImage(image.get(), 0, 0); sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture(); EXPECT_EQ(0, m_decodeRequestCount); // Create a thread to rasterize SkPicture. std::unique_ptr<WebThread> thread = WTF::wrapUnique(Platform::current()->createThread("RasterThread")); thread->getWebTaskRunner()->postTask( BLINK_FROM_HERE, crossThreadBind(&rasterizeMain, crossThreadUnretained(m_surface->getCanvas()), crossThreadUnretained(picture.get()))); thread.reset(); EXPECT_EQ(0, m_decodeRequestCount); SkBitmap canvasBitmap; canvasBitmap.allocN32Pixels(100, 100); ASSERT_TRUE(m_surface->getCanvas()->readPixels(&canvasBitmap, 0, 0)); SkAutoLockPixels autoLock(canvasBitmap); EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); }
void WebSharedWorkerImpl::didTerminateWorkerThread() { Platform::current()->mainThread()->getWebTaskRunner()->postTask( BLINK_FROM_HERE, crossThreadBind( &WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread, crossThreadUnretained(this))); }
void DataConsumerHandleTestUtil::ReplayingHandle::Context::notify() { if (!m_client) return; DCHECK(m_readerThread); m_readerThread->getWebTaskRunner()->postTask( BLINK_FROM_HERE, crossThreadBind(&Context::notifyInternal, wrapPassRefPtr(this))); }
void InProcessWorkerObjectProxy::didCloseWorkerGlobalScope() { getParentFrameTaskRunners() ->get(TaskType::Internal) ->postTask( BLINK_FROM_HERE, crossThreadBind(&InProcessWorkerMessagingProxy::terminateGlobalScope, m_messagingProxyWeakPtr)); }
void InProcessWorkerObjectProxy::didTerminateWorkerThread() { // This will terminate the MessagingProxy. getParentFrameTaskRunners() ->get(TaskType::Internal) ->postTask(BLINK_FROM_HERE, crossThreadBind( &InProcessWorkerMessagingProxy::workerThreadTerminated, m_messagingProxyWeakPtr)); }
WorkletBackingThreadHolder::WorkletBackingThreadHolder( std::unique_ptr<WorkerBackingThread> backingThread) : m_thread(std::move(backingThread)), m_initialized(false) { DCHECK(isMainThread()); m_thread->backingThread().postTask( BLINK_FROM_HERE, crossThreadBind(&WorkletBackingThreadHolder::initializeOnThread, crossThreadUnretained(this))); }
void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject() { getParentFrameTaskRunners() ->get(TaskType::Internal) ->postTask( BLINK_FROM_HERE, crossThreadBind( &InProcessWorkerMessagingProxy::confirmMessageFromWorkerObject, m_messagingProxyWeakPtr)); }
void WorkletBackingThreadHolder::shutdownAndWait() { DCHECK(isMainThread()); WaitableEvent waitableEvent; m_thread->backingThread().postTask( BLINK_FROM_HERE, crossThreadBind(&WorkletBackingThreadHolder::shutdownOnThread, crossThreadUnretained(this), crossThreadUnretained(&waitableEvent))); waitableEvent.wait(); }
void DatabaseThread::start() { ASSERT(isMainThread()); if (m_thread) return; m_thread = WebThreadSupportingGC::create("WebCore: Database", BlinkGC::PerThreadHeapMode); m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseThread::setupDatabaseThread, wrapCrossThreadPersistent(this))); }
void HTMLParserThread::postTask(std::unique_ptr<CrossThreadClosure> closure) { ASSERT(isMainThread()); if (!m_thread) { m_thread = WebThreadSupportingGC::create("HTMLParserThread", BlinkGC::MainThreadHeapMode); postTask(crossThreadBind(&HTMLParserThread::setupHTMLParserThread, crossThreadUnretained(this))); } m_thread->postTask(BLINK_FROM_HERE, std::move(closure)); }
void InProcessWorkerObjectProxy::postMessageToWorkerObject( PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels) { getParentFrameTaskRunners() ->get(TaskType::PostedMessage) ->postTask(BLINK_FROM_HERE, crossThreadBind( &InProcessWorkerMessagingProxy::postMessageToWorkerObject, m_messagingProxyWeakPtr, std::move(message), passed(std::move(channels)))); }
void OffscreenCanvasPlaceholder::releasePlaceholderFrame() { DCHECK(isPlaceholderRegistered()); if (m_placeholderFrame) { m_placeholderFrame->transfer(); m_frameDispatcherTaskRunner->postTask( BLINK_FROM_HERE, crossThreadBind(releaseFrameToDispatcher, std::move(m_frameDispatcher), std::move(m_placeholderFrame), m_placeholderFrameResourceId)); } }
void InProcessWorkerObjectProxy::reportException( const String& errorMessage, std::unique_ptr<SourceLocation> location, int exceptionId) { getParentFrameTaskRunners() ->get(TaskType::Internal) ->postTask( BLINK_FROM_HERE, crossThreadBind(&InProcessWorkerMessagingProxy::dispatchErrorEvent, m_messagingProxyWeakPtr, errorMessage, passed(location->clone()), exceptionId)); }
void DeferredTaskHandler::requestToDeleteHandlersOnMainThread() { ASSERT(isGraphOwner()); DCHECK(isAudioThread()); if (m_renderingOrphanHandlers.isEmpty()) return; m_deletableOrphanHandlers.appendVector(m_renderingOrphanHandlers); m_renderingOrphanHandlers.clear(); Platform::current()->mainThread()->getWebTaskRunner()->postTask( BLINK_FROM_HERE, crossThreadBind(&DeferredTaskHandler::deleteHandlersOnMainThread, PassRefPtr<DeferredTaskHandler>(this))); }
void ServiceWorkerGlobalScopeProxy::postMessageToPageInspector( const String& message) { DCHECK(m_embeddedWorker); // The TaskType of Inspector tasks need to be Unthrottled because they need to // run even on a suspended page. getParentFrameTaskRunners() ->get(TaskType::Unthrottled) ->postTask( BLINK_FROM_HERE, crossThreadBind(&WebEmbeddedWorkerImpl::postMessageToPageInspector, crossThreadUnretained(m_embeddedWorker), message)); }
DataConsumerHandleTestUtil::Thread::Thread( const char* name, InitializationPolicy initializationPolicy) : m_thread( WebThreadSupportingGC::create(name, BlinkGC::MainThreadHeapMode)), m_initializationPolicy(initializationPolicy), m_waitableEvent(wrapUnique(new WaitableEvent())) { m_thread->postTask( BLINK_FROM_HERE, crossThreadBind(&Thread::initialize, crossThreadUnretained(this))); m_waitableEvent->wait(); }
void DatabaseThread::scheduleTask(std::unique_ptr<DatabaseTask> task) { ASSERT(m_thread); #if ENABLE(ASSERT) { MutexLocker lock(m_terminationRequestedMutex); ASSERT(!m_terminationRequested); } #endif // WebThread takes ownership of the task. m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseTask::run, std::move(task))); }
void InProcessWorkerObjectProxy::reportConsoleMessage( MessageSource source, MessageLevel level, const String& message, SourceLocation* location) { getParentFrameTaskRunners() ->get(TaskType::Internal) ->postTask( BLINK_FROM_HERE, crossThreadBind(&InProcessWorkerMessagingProxy::reportConsoleMessage, m_messagingProxyWeakPtr, source, level, message, passed(location->clone()))); }
void CompositorProxy::disconnectInternal() { if (!m_connected) return; m_connected = false; if (isMainThread()) { decrementCompositorProxiedPropertiesForElement( m_elementId, m_compositorMutableProperties); } else { Platform::current()->mainThread()->getWebTaskRunner()->postTask( BLINK_FROM_HERE, crossThreadBind(&decrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties)); } }
std::unique_ptr<CompositorMutatorClient> CompositorMutatorImpl::createClient() { std::unique_ptr<CompositorMutatorClient> mutatorClient; WaitableEvent doneEvent; if (WebThread* compositorThread = Platform::current()->compositorThread()) { compositorThread->getWebTaskRunner()->postTask(BLINK_FROM_HERE, crossThreadBind(&createCompositorMutatorClient, crossThreadUnretained(&mutatorClient), crossThreadUnretained(&doneEvent))); } else { createCompositorMutatorClient(&mutatorClient, &doneEvent); } // TODO(flackr): Instead of waiting for this event, we may be able to just set the // mutator on the CompositorProxyClient directly from the compositor thread before // it gets used there. We still need to make sure we only create one mutator though. doneEvent.wait(); return mutatorClient; }
void HTMLParserThread::shutdown() { ASSERT(isMainThread()); ASSERT(s_sharedThread); // currentThread will always be non-null in production, but can be null in // Chromium unit tests. if (Platform::current()->currentThread() && s_sharedThread->m_thread) { WaitableEvent waitableEvent; s_sharedThread->postTask( crossThreadBind(&HTMLParserThread::cleanupHTMLParserThread, crossThreadUnretained(s_sharedThread), crossThreadUnretained(&waitableEvent))); waitableEvent.wait(); } delete s_sharedThread; s_sharedThread = nullptr; }
void DatabaseThread::terminate() { ASSERT(isMainThread()); WaitableEvent sync; { MutexLocker lock(m_terminationRequestedMutex); ASSERT(!m_terminationRequested); m_terminationRequested = true; m_cleanupSync = &sync; STORAGE_DVLOG(1) << "DatabaseThread " << this << " was asked to terminate"; m_thread->postTask(BLINK_FROM_HERE, crossThreadBind(&DatabaseThread::cleanupDatabaseThread, wrapCrossThreadPersistent(this))); } sync.wait(); // The WebThread destructor blocks until all the tasks of the database // thread are processed. However, it shouldn't block at all because // the database thread has already finished processing the cleanup task. m_thread.reset(); }
void MailboxTextureHolder::releaseTextureThreadSafe() { // If this member is still null, it means we are still at the thread where // the m_texture was created. std::unique_ptr<gpu::SyncToken> passedSyncToken( new gpu::SyncToken(m_syncToken)); if (!wasTransferred()) { releaseTexture(m_isConvertedFromSkiaTexture, m_textureId, m_contextProvider, std::move(passedSyncToken)); } else if (wasTransferred() && textureThreadTaskRunner()) { textureThreadTaskRunner()->postTask( BLINK_FROM_HERE, crossThreadBind(&releaseTexture, m_isConvertedFromSkiaTexture, m_textureId, passed(std::move(m_contextProvider)), passed(std::move(passedSyncToken)))); } m_textureId = 0u; // invalidate the texture. setWasTransferred(false); setTextureThreadTaskRunner(nullptr); }
CompositorProxy::CompositorProxy(uint64_t elementId, uint32_t compositorMutableProperties) : m_elementId(elementId), m_compositorMutableProperties(compositorMutableProperties), m_client(nullptr) { DCHECK(m_compositorMutableProperties); #if DCHECK_IS_ON() DCHECK(sanityCheckMutableProperties(m_compositorMutableProperties)); #endif if (isMainThread()) { incrementCompositorProxiedPropertiesForElement( m_elementId, m_compositorMutableProperties); } else { Platform::current()->mainThread()->getWebTaskRunner()->postTask( BLINK_FROM_HERE, crossThreadBind(&incrementCompositorProxiedPropertiesForElement, m_elementId, m_compositorMutableProperties)); } }
void InProcessWorkerObjectProxy::checkPendingActivity(TimerBase*) { bool hasPendingActivity = V8GCController::hasPendingActivity( m_workerGlobalScope->thread()->isolate(), m_workerGlobalScope); if (!hasPendingActivity) { // Report all activities are done. getParentFrameTaskRunners() ->get(TaskType::Internal) ->postTask(BLINK_FROM_HERE, crossThreadBind( &InProcessWorkerMessagingProxy::pendingActivityFinished, m_messagingProxyWeakPtr)); // Don't schedule a timer. It will be started again when a message event // is dispatched. m_nextIntervalInSec = m_defaultIntervalInSec; return; } // There is still a pending activity. Check it later. startPendingActivityTimer(); }
DataConsumerHandleTestUtil::Thread::~Thread() { m_thread->postTask( BLINK_FROM_HERE, crossThreadBind(&Thread::shutdown, crossThreadUnretained(this))); m_waitableEvent->wait(); }