| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 TerminateWorkerThread(); | 234 TerminateWorkerThread(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void WebSharedWorkerImpl::DidTerminateWorkerThread() { | 237 void WebSharedWorkerImpl::DidTerminateWorkerThread() { |
| 238 DCHECK(IsMainThread()); | 238 DCHECK(IsMainThread()); |
| 239 client_->WorkerContextDestroyed(); | 239 client_->WorkerContextDestroyed(); |
| 240 // The lifetime of this proxy is controlled by the worker context. | 240 // The lifetime of this proxy is controlled by the worker context. |
| 241 delete this; | 241 delete this; |
| 242 } | 242 } |
| 243 | 243 |
| 244 // WorkerLoaderProxyProvider ------------------------------------------------- | |
| 245 | |
| 246 void WebSharedWorkerImpl::PostTaskToLoader( | |
| 247 const WebTraceLocation& location, | |
| 248 std::unique_ptr<WTF::CrossThreadClosure> task) { | |
| 249 DCHECK(worker_thread_->IsCurrentThread()); | |
| 250 parent_frame_task_runners_->Get(TaskType::kNetworking) | |
| 251 ->PostTask(FROM_HERE, std::move(task)); | |
| 252 } | |
| 253 | |
| 254 void WebSharedWorkerImpl::PostTaskToWorkerGlobalScope( | |
| 255 const WebTraceLocation& location, | |
| 256 std::unique_ptr<WTF::CrossThreadClosure> task) { | |
| 257 DCHECK(IsMainThread()); | |
| 258 TaskRunnerHelper::Get(TaskType::kNetworking, GetWorkerThread()) | |
| 259 ->PostTask(location, std::move(task)); | |
| 260 } | |
| 261 | |
| 262 ThreadableLoadingContext* WebSharedWorkerImpl::GetThreadableLoadingContext() { | 244 ThreadableLoadingContext* WebSharedWorkerImpl::GetThreadableLoadingContext() { |
| 263 if (!loading_context_) { | 245 if (!loading_context_) { |
| 264 loading_context_ = | 246 loading_context_ = |
| 265 ThreadableLoadingContext::Create(*ToDocument(loading_document_.Get())); | 247 ThreadableLoadingContext::Create(*ToDocument(loading_document_.Get())); |
| 266 } | 248 } |
| 267 return loading_context_; | 249 return loading_context_; |
| 268 } | 250 } |
| 269 | 251 |
| 270 void WebSharedWorkerImpl::Connect( | 252 void WebSharedWorkerImpl::Connect( |
| 271 std::unique_ptr<WebMessagePortChannel> web_channel) { | 253 std::unique_ptr<WebMessagePortChannel> web_channel) { |
| 272 DCHECK(IsMainThread()); | 254 DCHECK(IsMainThread()); |
| 255 // The HTML spec requires to queue a connect event using the DOM manipulation |
| 256 // task source. |
| 257 // https://html.spec.whatwg.org/multipage/workers.html#shared-workers-and-the-
sharedworker-interface |
| 273 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) | 258 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) |
| 274 ->PostTask( | 259 ->PostTask( |
| 275 BLINK_FROM_HERE, | 260 BLINK_FROM_HERE, |
| 276 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, | 261 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, |
| 277 WTF::CrossThreadUnretained(this), | 262 WTF::CrossThreadUnretained(this), |
| 278 WTF::Passed(std::move(web_channel)))); | 263 WTF::Passed(std::move(web_channel)))); |
| 279 } | 264 } |
| 280 | 265 |
| 281 void WebSharedWorkerImpl::ConnectTaskOnWorkerThread( | 266 void WebSharedWorkerImpl::ConnectTaskOnWorkerThread( |
| 282 std::unique_ptr<WebMessagePortChannel> channel) { | 267 std::unique_ptr<WebMessagePortChannel> channel) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 worker_clients, main_script_loader_->ResponseAddressSpace(), | 343 worker_clients, main_script_loader_->ResponseAddressSpace(), |
| 359 main_script_loader_->OriginTrialTokens(), std::move(worker_settings), | 344 main_script_loader_->OriginTrialTokens(), std::move(worker_settings), |
| 360 WorkerV8Settings::Default()); | 345 WorkerV8Settings::Default()); |
| 361 | 346 |
| 362 // SharedWorker can sometimes run tasks that are initiated by/associated with | 347 // SharedWorker can sometimes run tasks that are initiated by/associated with |
| 363 // a document's frame but these documents can be from a different process. So | 348 // a document's frame but these documents can be from a different process. So |
| 364 // we intentionally populate the task runners with null document in order to | 349 // we intentionally populate the task runners with null document in order to |
| 365 // use the thread's default task runner. Note that |m_document| should not be | 350 // use the thread's default task runner. Note that |m_document| should not be |
| 366 // used as it's a dummy document for loading that doesn't represent the frame | 351 // used as it's a dummy document for loading that doesn't represent the frame |
| 367 // of any associated document. | 352 // of any associated document. |
| 368 parent_frame_task_runners_ = ParentFrameTaskRunners::Create(nullptr); | 353 ParentFrameTaskRunners* task_runners = |
| 354 ParentFrameTaskRunners::Create(nullptr); |
| 369 | 355 |
| 370 loader_proxy_ = WorkerLoaderProxy::Create(this); | 356 loader_proxy_ = WorkerLoaderProxy::Create(this); |
| 371 reporting_proxy_ = new WebSharedWorkerReportingProxyImpl( | 357 reporting_proxy_ = new WebSharedWorkerReportingProxyImpl(this, task_runners); |
| 372 this, parent_frame_task_runners_.Get()); | |
| 373 worker_thread_ = | 358 worker_thread_ = |
| 374 SharedWorkerThread::Create(name_, loader_proxy_, *reporting_proxy_); | 359 SharedWorkerThread::Create(name_, loader_proxy_, *reporting_proxy_); |
| 375 probe::scriptImported(loading_document_, main_script_loader_->Identifier(), | 360 probe::scriptImported(loading_document_, main_script_loader_->Identifier(), |
| 376 main_script_loader_->SourceText()); | 361 main_script_loader_->SourceText()); |
| 377 main_script_loader_.Clear(); | 362 main_script_loader_.Clear(); |
| 378 | 363 |
| 379 GetWorkerThread()->Start(std::move(startup_data), | 364 GetWorkerThread()->Start(std::move(startup_data), task_runners); |
| 380 parent_frame_task_runners_.Get()); | |
| 381 worker_inspector_proxy_->WorkerThreadCreated(ToDocument(loading_document_), | 365 worker_inspector_proxy_->WorkerThreadCreated(ToDocument(loading_document_), |
| 382 GetWorkerThread(), url_); | 366 GetWorkerThread(), url_); |
| 383 client_->WorkerScriptLoaded(); | 367 client_->WorkerScriptLoaded(); |
| 384 } | 368 } |
| 385 | 369 |
| 386 void WebSharedWorkerImpl::TerminateWorkerContext() { | 370 void WebSharedWorkerImpl::TerminateWorkerContext() { |
| 387 DCHECK(IsMainThread()); | 371 DCHECK(IsMainThread()); |
| 388 TerminateWorkerThread(); | 372 TerminateWorkerThread(); |
| 389 } | 373 } |
| 390 | 374 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 if (devtools_agent) | 408 if (devtools_agent) |
| 425 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, | 409 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, |
| 426 message); | 410 message); |
| 427 } | 411 } |
| 428 | 412 |
| 429 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { | 413 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { |
| 430 return new WebSharedWorkerImpl(client); | 414 return new WebSharedWorkerImpl(client); |
| 431 } | 415 } |
| 432 | 416 |
| 433 } // namespace blink | 417 } // namespace blink |
| OLD | NEW |