Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 // We have a dummy document here for loading but it doesn't really represent |
| 380 // the document/frame of associated document(s) for this worker. Here we | 388 // the document/frame of associated document(s) for this worker. Here we |
| 381 // populate the task runners with null document not to confuse the frame | 389 // populate the task runners with null document not to confuse the frame |
| 382 // scheduler (which will end up using the thread's default task runner). | 390 // scheduler (which will end up using the thread's default task runner). |
| 383 m_mainThreadTaskRunners = ParentFrameTaskRunners::create(nullptr); | 391 m_parentFrameTaskRunners = ParentFrameTaskRunners::create(nullptr); |
|
haraken
2016/11/22 01:26:17
When is the correct document set to m_parentFrameT
nhiroki
2016/11/22 03:27:21
Ditto. A shared worker can be associated with mult
| |
| 384 | 392 |
| 385 m_loaderProxy = WorkerLoaderProxy::create(this); | 393 m_loaderProxy = WorkerLoaderProxy::create(this); |
| 386 m_workerThread = SharedWorkerThread::create(m_name, m_loaderProxy, *this); | 394 m_workerThread = SharedWorkerThread::create(m_name, m_loaderProxy, *this); |
| 387 InspectorInstrumentation::scriptImported(m_loadingDocument.get(), | 395 InspectorInstrumentation::scriptImported(m_loadingDocument.get(), |
| 388 m_mainScriptLoader->identifier(), | 396 m_mainScriptLoader->identifier(), |
| 389 m_mainScriptLoader->script()); | 397 m_mainScriptLoader->script()); |
| 390 m_mainScriptLoader.clear(); | 398 m_mainScriptLoader.clear(); |
| 391 | 399 |
| 392 workerThread()->start(std::move(startupData)); | 400 workerThread()->start(std::move(startupData)); |
| 393 m_workerInspectorProxy->workerThreadCreated( | 401 m_workerInspectorProxy->workerThreadCreated( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 if (devtoolsAgent) | 443 if (devtoolsAgent) |
| 436 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, | 444 devtoolsAgent->dispatchOnInspectorBackend(sessionId, callId, method, |
| 437 message); | 445 message); |
| 438 } | 446 } |
| 439 | 447 |
| 440 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { | 448 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) { |
| 441 return new WebSharedWorkerImpl(client); | 449 return new WebSharedWorkerImpl(client); |
| 442 } | 450 } |
| 443 | 451 |
| 444 } // namespace blink | 452 } // namespace blink |
| OLD | NEW |