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 ------------------------------------------------- | 244 // WorkerLoaderProxyProvider ------------------------------------------------- |
kinuko
2017/04/21 06:05:10
Let's remove this comment too
nhiroki
2017/04/21 08:46:01
Done.
| |
245 | 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() { | 246 ThreadableLoadingContext* WebSharedWorkerImpl::GetThreadableLoadingContext() { |
263 if (!loading_context_) { | 247 if (!loading_context_) { |
264 loading_context_ = | 248 loading_context_ = |
265 ThreadableLoadingContext::Create(*ToDocument(loading_document_.Get())); | 249 ThreadableLoadingContext::Create(*ToDocument(loading_document_.Get())); |
266 } | 250 } |
267 return loading_context_; | 251 return loading_context_; |
268 } | 252 } |
269 | 253 |
270 void WebSharedWorkerImpl::Connect( | 254 void WebSharedWorkerImpl::Connect( |
271 std::unique_ptr<WebMessagePortChannel> web_channel) { | 255 std::unique_ptr<WebMessagePortChannel> web_channel) { |
272 DCHECK(IsMainThread()); | 256 DCHECK(IsMainThread()); |
257 // The HTML spec requires to queue a connect event using the DOM manipulation | |
258 // task source. | |
259 // https://html.spec.whatwg.org/multipage/workers.html#shared-workers-and-the- sharedworker-interface | |
273 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) | 260 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) |
274 ->PostTask( | 261 ->PostTask( |
275 BLINK_FROM_HERE, | 262 BLINK_FROM_HERE, |
276 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, | 263 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, |
277 WTF::CrossThreadUnretained(this), | 264 WTF::CrossThreadUnretained(this), |
278 WTF::Passed(std::move(web_channel)))); | 265 WTF::Passed(std::move(web_channel)))); |
279 } | 266 } |
280 | 267 |
281 void WebSharedWorkerImpl::ConnectTaskOnWorkerThread( | 268 void WebSharedWorkerImpl::ConnectTaskOnWorkerThread( |
282 std::unique_ptr<WebMessagePortChannel> channel) { | 269 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(), | 345 worker_clients, main_script_loader_->ResponseAddressSpace(), |
359 main_script_loader_->OriginTrialTokens(), std::move(worker_settings), | 346 main_script_loader_->OriginTrialTokens(), std::move(worker_settings), |
360 WorkerV8Settings::Default()); | 347 WorkerV8Settings::Default()); |
361 | 348 |
362 // SharedWorker can sometimes run tasks that are initiated by/associated with | 349 // 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 | 350 // 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 | 351 // 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 | 352 // 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 | 353 // used as it's a dummy document for loading that doesn't represent the frame |
367 // of any associated document. | 354 // of any associated document. |
368 parent_frame_task_runners_ = ParentFrameTaskRunners::Create(nullptr); | 355 ParentFrameTaskRunners* task_runners = |
356 ParentFrameTaskRunners::Create(nullptr); | |
369 | 357 |
370 loader_proxy_ = WorkerLoaderProxy::Create(this); | 358 loader_proxy_ = WorkerLoaderProxy::Create(this); |
371 reporting_proxy_ = new WebSharedWorkerReportingProxyImpl( | 359 reporting_proxy_ = new WebSharedWorkerReportingProxyImpl(this, task_runners); |
372 this, parent_frame_task_runners_.Get()); | |
373 worker_thread_ = | 360 worker_thread_ = |
374 SharedWorkerThread::Create(name_, loader_proxy_, *reporting_proxy_); | 361 SharedWorkerThread::Create(name_, loader_proxy_, *reporting_proxy_); |
375 probe::scriptImported(loading_document_, main_script_loader_->Identifier(), | 362 probe::scriptImported(loading_document_, main_script_loader_->Identifier(), |
376 main_script_loader_->SourceText()); | 363 main_script_loader_->SourceText()); |
377 main_script_loader_.Clear(); | 364 main_script_loader_.Clear(); |
378 | 365 |
379 GetWorkerThread()->Start(std::move(startup_data), | 366 GetWorkerThread()->Start(std::move(startup_data), task_runners); |
380 parent_frame_task_runners_.Get()); | |
381 worker_inspector_proxy_->WorkerThreadCreated(ToDocument(loading_document_), | 367 worker_inspector_proxy_->WorkerThreadCreated(ToDocument(loading_document_), |
382 GetWorkerThread(), url_); | 368 GetWorkerThread(), url_); |
383 client_->WorkerScriptLoaded(); | 369 client_->WorkerScriptLoaded(); |
384 } | 370 } |
385 | 371 |
386 void WebSharedWorkerImpl::TerminateWorkerContext() { | 372 void WebSharedWorkerImpl::TerminateWorkerContext() { |
387 DCHECK(IsMainThread()); | 373 DCHECK(IsMainThread()); |
388 TerminateWorkerThread(); | 374 TerminateWorkerThread(); |
389 } | 375 } |
390 | 376 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 if (devtools_agent) | 410 if (devtools_agent) |
425 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, | 411 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, |
426 message); | 412 message); |
427 } | 413 } |
428 | 414 |
429 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { | 415 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { |
430 return new WebSharedWorkerImpl(client); | 416 return new WebSharedWorkerImpl(client); |
431 } | 417 } |
432 | 418 |
433 } // namespace blink | 419 } // namespace blink |
OLD | NEW |