Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/WebKit/Source/web/WebSharedWorkerImpl.cpp

Issue 2513413003: Worker: Provide a way to access parent frame task runners from a worker thread (Closed)
Patch Set: update comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 createCrossThreadTask( 243 createCrossThreadTask(
244 &WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread, 244 &WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread,
245 crossThreadUnretained(this), message)); 245 crossThreadUnretained(this), message));
246 } 246 }
247 247
248 void WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread( 248 void WebSharedWorkerImpl::postMessageToPageInspectorOnMainThread(
249 const String& message) { 249 const String& message) {
250 m_workerInspectorProxy->dispatchMessageFromWorker(message); 250 m_workerInspectorProxy->dispatchMessageFromWorker(message);
251 } 251 }
252 252
253 ParentFrameTaskRunners* WebSharedWorkerImpl::getParentFrameTaskRunners() {
254 return m_parentFrameTaskRunners.get();
255 }
256
253 void WebSharedWorkerImpl::didCloseWorkerGlobalScope() { 257 void WebSharedWorkerImpl::didCloseWorkerGlobalScope() {
258 // TODO(nhiroki): Replace this with getParentFrameTaskRunners().
259 // (https://crbug.com/667310)
254 Platform::current()->mainThread()->getWebTaskRunner()->postTask( 260 Platform::current()->mainThread()->getWebTaskRunner()->postTask(
255 BLINK_FROM_HERE, 261 BLINK_FROM_HERE,
256 crossThreadBind( 262 crossThreadBind(
257 &WebSharedWorkerImpl::didCloseWorkerGlobalScopeOnMainThread, 263 &WebSharedWorkerImpl::didCloseWorkerGlobalScopeOnMainThread,
258 crossThreadUnretained(this))); 264 crossThreadUnretained(this)));
259 } 265 }
260 266
261 void WebSharedWorkerImpl::didCloseWorkerGlobalScopeOnMainThread() { 267 void WebSharedWorkerImpl::didCloseWorkerGlobalScopeOnMainThread() {
262 m_client->workerContextClosed(); 268 m_client->workerContextClosed();
263 269
264 terminateWorkerThread(); 270 terminateWorkerThread();
265 } 271 }
266 272
267 void WebSharedWorkerImpl::didTerminateWorkerThread() { 273 void WebSharedWorkerImpl::didTerminateWorkerThread() {
274 // TODO(nhiroki): Replace this with getParentFrameTaskRunners().
275 // (https://crbug.com/667310)
268 Platform::current()->mainThread()->getWebTaskRunner()->postTask( 276 Platform::current()->mainThread()->getWebTaskRunner()->postTask(
269 BLINK_FROM_HERE, 277 BLINK_FROM_HERE,
270 crossThreadBind( 278 crossThreadBind(
271 &WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread, 279 &WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread,
272 crossThreadUnretained(this))); 280 crossThreadUnretained(this)));
273 } 281 }
274 282
275 void WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread() { 283 void WebSharedWorkerImpl::didTerminateWorkerThreadOnMainThread() {
276 m_client->workerContextDestroyed(); 284 m_client->workerContextDestroyed();
277 // The lifetime of this proxy is controlled by the worker context. 285 // The lifetime of this proxy is controlled by the worker context.
278 delete this; 286 delete this;
279 } 287 }
280 288
281 // WorkerLoaderProxyProvider ------------------------------------------------- 289 // WorkerLoaderProxyProvider -------------------------------------------------
282 290
283 void WebSharedWorkerImpl::postTaskToLoader( 291 void WebSharedWorkerImpl::postTaskToLoader(
284 const WebTraceLocation& location, 292 const WebTraceLocation& location,
285 std::unique_ptr<ExecutionContextTask> task) { 293 std::unique_ptr<ExecutionContextTask> task) {
286 // TODO(hiroshige,yuryu): Make this not use ExecutionContextTask and 294 // TODO(hiroshige,yuryu): Make this not use ExecutionContextTask and
287 // consider using m_mainThreadTaskRunners->get(TaskType::Networking) 295 // consider using m_parentFrameTaskRunners->get(TaskType::Networking)
288 // instead. 296 // instead.
289 m_mainFrame->frame()->document()->postTask(location, std::move(task)); 297 m_mainFrame->frame()->document()->postTask(location, std::move(task));
290 } 298 }
291 299
292 void WebSharedWorkerImpl::postTaskToWorkerGlobalScope( 300 void WebSharedWorkerImpl::postTaskToWorkerGlobalScope(
293 const WebTraceLocation& location, 301 const WebTraceLocation& location,
294 std::unique_ptr<ExecutionContextTask> task) { 302 std::unique_ptr<ExecutionContextTask> task) {
295 m_workerThread->postTask(location, std::move(task)); 303 m_workerThread->postTask(location, std::move(task));
296 } 304 }
297 305
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 std::unique_ptr<WorkerThreadStartupData> startupData = 377 std::unique_ptr<WorkerThreadStartupData> startupData =
370 WorkerThreadStartupData::create( 378 WorkerThreadStartupData::create(
371 m_url, m_loadingDocument->userAgent(), m_mainScriptLoader->script(), 379 m_url, m_loadingDocument->userAgent(), m_mainScriptLoader->script(),
372 nullptr, startMode, 380 nullptr, startMode,
373 contentSecurityPolicy ? contentSecurityPolicy->headers().get() 381 contentSecurityPolicy ? contentSecurityPolicy->headers().get()
374 : nullptr, 382 : nullptr,
375 m_mainScriptLoader->referrerPolicy(), starterOrigin, workerClients, 383 m_mainScriptLoader->referrerPolicy(), starterOrigin, workerClients,
376 m_mainScriptLoader->responseAddressSpace(), 384 m_mainScriptLoader->responseAddressSpace(),
377 m_mainScriptLoader->originTrialTokens(), std::move(workerSettings)); 385 m_mainScriptLoader->originTrialTokens(), std::move(workerSettings));
378 386
379 // We have a dummy document here for loading but it doesn't really represent 387 // SharedWorker can sometimes run tasks that are initiated by/associated with
380 // the document/frame of associated document(s) for this worker. Here we 388 // a document's frame but these documents can be from a different process. So
381 // populate the task runners with null document not to confuse the frame 389 // we intentionally populate the task runners with null document in order to
382 // scheduler (which will end up using the thread's default task runner). 390 // use the thread's default task runner. Note that |m_document| should not be
383 m_mainThreadTaskRunners = ParentFrameTaskRunners::create(nullptr); 391 // used as it's a dummy document for loading that doesn't represent the frame
392 // of any associated document.
393 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr);
384 394
385 m_loaderProxy = WorkerLoaderProxy::create(this); 395 m_loaderProxy = WorkerLoaderProxy::create(this);
386 m_workerThread = SharedWorkerThread::create(m_name, m_loaderProxy, *this); 396 m_workerThread = SharedWorkerThread::create(m_name, m_loaderProxy, *this);
387 InspectorInstrumentation::scriptImported(m_loadingDocument.get(), 397 InspectorInstrumentation::scriptImported(m_loadingDocument.get(),
388 m_mainScriptLoader->identifier(), 398 m_mainScriptLoader->identifier(),
389 m_mainScriptLoader->script()); 399 m_mainScriptLoader->script());
390 m_mainScriptLoader.clear(); 400 m_mainScriptLoader.clear();
391 401
392 workerThread()->start(std::move(startupData)); 402 workerThread()->start(std::move(startupData));
393 m_workerInspectorProxy->workerThreadCreated( 403 m_workerInspectorProxy->workerThreadCreated(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 if (devtoolsAgent) 445 if (devtoolsAgent)
436 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, 446 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method,
437 message); 447 message);
438 } 448 }
439 449
440 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { 450 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) {
441 return new WebSharedWorkerImpl(client); 451 return new WebSharedWorkerImpl(client);
442 } 452 }
443 453
444 } // namespace blink 454 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698