OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/workers/WorkerOrWorkletGlobalScope.h" | 5 #include "core/workers/WorkerOrWorkletGlobalScope.h" |
6 | 6 |
7 #include "core/dom/ExecutionContextTask.h" | 7 #include "core/dom/ExecutionContextTask.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" |
8 #include "core/frame/Deprecation.h" | 9 #include "core/frame/Deprecation.h" |
9 #include "core/inspector/ConsoleMessage.h" | 10 #include "core/inspector/ConsoleMessage.h" |
10 #include "core/probe/CoreProbes.h" | 11 #include "core/probe/CoreProbes.h" |
11 #include "core/workers/WorkerReportingProxy.h" | 12 #include "core/workers/WorkerReportingProxy.h" |
12 #include "core/workers/WorkerThread.h" | 13 #include "core/workers/WorkerThread.h" |
13 #include "platform/CrossThreadFunctional.h" | 14 #include "platform/CrossThreadFunctional.h" |
14 #include "platform/wtf/Functional.h" | 15 #include "platform/wtf/Functional.h" |
15 | 16 |
16 namespace blink { | 17 namespace blink { |
17 | 18 |
18 WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope() | 19 WorkerOrWorkletGlobalScope::WorkerOrWorkletGlobalScope() |
19 : deprecation_warning_bits_(UseCounter::kNumberOfFeatures) {} | 20 : deprecation_warning_bits_(UseCounter::kNumberOfFeatures) {} |
20 | 21 |
21 WorkerOrWorkletGlobalScope::~WorkerOrWorkletGlobalScope() {} | 22 WorkerOrWorkletGlobalScope::~WorkerOrWorkletGlobalScope() = default; |
22 | 23 |
23 void WorkerOrWorkletGlobalScope::AddDeprecationMessage( | 24 void WorkerOrWorkletGlobalScope::AddDeprecationMessage( |
24 UseCounter::Feature feature) { | 25 UseCounter::Feature feature) { |
25 DCHECK_NE(UseCounter::kOBSOLETE_PageDestruction, feature); | 26 DCHECK_NE(UseCounter::kOBSOLETE_PageDestruction, feature); |
26 DCHECK_GT(UseCounter::kNumberOfFeatures, feature); | 27 DCHECK_GT(UseCounter::kNumberOfFeatures, feature); |
27 | 28 |
28 // For each deprecated feature, send console message at most once | 29 // For each deprecated feature, send console message at most once |
29 // per worker lifecycle. | 30 // per worker lifecycle. |
30 if (deprecation_warning_bits_.QuickGet(feature)) | 31 if (deprecation_warning_bits_.QuickGet(feature)) |
31 return; | 32 return; |
32 deprecation_warning_bits_.QuickSet(feature); | 33 deprecation_warning_bits_.QuickSet(feature); |
33 DCHECK(!Deprecation::DeprecationMessage(feature).IsEmpty()); | 34 DCHECK(!Deprecation::DeprecationMessage(feature).IsEmpty()); |
34 AddConsoleMessage( | 35 AddConsoleMessage( |
35 ConsoleMessage::Create(kDeprecationMessageSource, kWarningMessageLevel, | 36 ConsoleMessage::Create(kDeprecationMessageSource, kWarningMessageLevel, |
36 Deprecation::DeprecationMessage(feature))); | 37 Deprecation::DeprecationMessage(feature))); |
37 } | 38 } |
38 | 39 |
39 void WorkerOrWorkletGlobalScope::PostTask( | 40 void WorkerOrWorkletGlobalScope::PostTask( |
40 TaskType, | 41 TaskType type, |
41 const WebTraceLocation& location, | 42 const WebTraceLocation& location, |
42 std::unique_ptr<ExecutionContextTask> task, | 43 std::unique_ptr<ExecutionContextTask> task, |
43 const String& task_name_for_instrumentation) { | 44 const String& task_name_for_instrumentation) { |
44 if (!GetThread()) | 45 if (!GetThread()) |
45 return; | 46 return; |
46 | 47 |
47 bool is_instrumented = !task_name_for_instrumentation.IsEmpty(); | 48 bool is_instrumented = !task_name_for_instrumentation.IsEmpty(); |
48 if (is_instrumented) { | 49 if (is_instrumented) { |
49 probe::AsyncTaskScheduled(this, "Worker task", task.get()); | 50 probe::AsyncTaskScheduled(this, "Worker task", task.get()); |
50 } | 51 } |
51 | 52 |
52 GetThread()->PostTask( | 53 TaskRunnerHelper::Get(type, this) |
53 location, CrossThreadBind(&WorkerOrWorkletGlobalScope::RunTask, | 54 ->PostTask(location, CrossThreadBind(&WorkerOrWorkletGlobalScope::RunTask, |
54 WrapCrossThreadWeakPersistent(this), | 55 WrapCrossThreadWeakPersistent(this), |
55 WTF::Passed(std::move(task)), is_instrumented)); | 56 WTF::Passed(std::move(task)), |
| 57 is_instrumented)); |
56 } | 58 } |
57 | 59 |
58 void WorkerOrWorkletGlobalScope::RunTask( | 60 void WorkerOrWorkletGlobalScope::RunTask( |
59 std::unique_ptr<ExecutionContextTask> task, | 61 std::unique_ptr<ExecutionContextTask> task, |
60 bool is_instrumented) { | 62 bool is_instrumented) { |
61 DCHECK(GetThread()->IsCurrentThread()); | 63 DCHECK(GetThread()->IsCurrentThread()); |
62 probe::AsyncTask async_task(this, task.get(), nullptr, is_instrumented); | 64 probe::AsyncTask async_task(this, task.get(), nullptr, is_instrumented); |
63 task->PerformTask(this); | 65 task->PerformTask(this); |
64 } | 66 } |
65 | 67 |
66 } // namespace blink | 68 } // namespace blink |
OLD | NEW |