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/ThreadedMessagingProxyBase.h" | 5 #include "core/workers/ThreadedMessagingProxyBase.h" |
6 | 6 |
7 #include "bindings/core/v8/SourceLocation.h" | 7 #include "bindings/core/v8/SourceLocation.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/dom/ExecutionContextTask.h" | 9 #include "core/dom/ExecutionContextTask.h" |
10 #include "core/frame/Deprecation.h" | 10 #include "core/frame/Deprecation.h" |
11 #include "core/loader/DocumentLoader.h" | 11 #include "core/loader/DocumentLoader.h" |
12 #include "core/workers/WorkerInspectorProxy.h" | 12 #include "core/workers/WorkerInspectorProxy.h" |
13 #include "core/workers/WorkerThreadStartupData.h" | 13 #include "core/workers/WorkerThreadStartupData.h" |
14 #include "wtf/CurrentTime.h" | 14 #include "wtf/CurrentTime.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 static int s_liveMessagingProxyCount = 0; | 20 static int s_liveMessagingProxyCount = 0; |
21 | 21 |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 ThreadedMessagingProxyBase::ThreadedMessagingProxyBase( | 24 ThreadedMessagingProxyBase::ThreadedMessagingProxyBase( |
25 ExecutionContext* executionContext) | 25 ExecutionContext* executionContext) |
26 : m_executionContext(executionContext), | 26 : m_executionContext(executionContext), |
27 m_workerInspectorProxy(WorkerInspectorProxy::create()), | 27 m_workerInspectorProxy(WorkerInspectorProxy::create()), |
28 m_parentFrameTaskRunners(ParentFrameTaskRunners::create( | |
29 toDocument(m_executionContext.get())->frame())), | |
30 m_mayBeDestroyed(false), | 28 m_mayBeDestroyed(false), |
31 m_askedToTerminate(false) { | 29 m_askedToTerminate(false) { |
32 DCHECK(isParentContextThread()); | 30 DCHECK(isParentContextThread()); |
33 s_liveMessagingProxyCount++; | 31 s_liveMessagingProxyCount++; |
34 } | 32 } |
35 | 33 |
36 ThreadedMessagingProxyBase::~ThreadedMessagingProxyBase() { | 34 ThreadedMessagingProxyBase::~ThreadedMessagingProxyBase() { |
37 DCHECK(isParentContextThread()); | 35 DCHECK(isParentContextThread()); |
38 if (m_loaderProxy) | 36 if (m_loaderProxy) |
39 m_loaderProxy->detachProvider(this); | 37 m_loaderProxy->detachProvider(this); |
40 s_liveMessagingProxyCount--; | 38 s_liveMessagingProxyCount--; |
41 } | 39 } |
42 | 40 |
43 int ThreadedMessagingProxyBase::proxyCount() { | 41 int ThreadedMessagingProxyBase::proxyCount() { |
44 DCHECK(isMainThread()); | 42 DCHECK(isMainThread()); |
45 return s_liveMessagingProxyCount; | 43 return s_liveMessagingProxyCount; |
46 } | 44 } |
47 | 45 |
48 void ThreadedMessagingProxyBase::initializeWorkerThread( | 46 void ThreadedMessagingProxyBase::initializeWorkerThread( |
49 std::unique_ptr<WorkerThreadStartupData> startupData) { | 47 std::unique_ptr<WorkerThreadStartupData> startupData) { |
50 DCHECK(isParentContextThread()); | 48 DCHECK(isParentContextThread()); |
51 | 49 |
52 Document* document = toDocument(getExecutionContext()); | 50 Document* document = toDocument(getExecutionContext()); |
53 double originTime = | 51 double originTime = |
54 document->loader() ? document->loader()->timing().referenceMonotonicTime() | 52 document->loader() ? document->loader()->timing().referenceMonotonicTime() |
55 : monotonicallyIncreasingTime(); | 53 : monotonicallyIncreasingTime(); |
56 | 54 |
57 m_loaderProxy = WorkerLoaderProxy::create(this); | 55 m_loaderProxy = WorkerLoaderProxy::create(this); |
58 m_workerThread = createWorkerThread(originTime); | 56 m_workerThread = createWorkerThread(originTime); |
59 m_workerThread->start(std::move(startupData), getParentFrameTaskRunners()); | 57 m_workerThread->start(std::move(startupData), |
| 58 FrameTaskRunnersHolder::create(document->frame())); |
60 workerThreadCreated(); | 59 workerThreadCreated(); |
61 } | 60 } |
62 | 61 |
63 void ThreadedMessagingProxyBase::postTaskToWorkerGlobalScope( | 62 void ThreadedMessagingProxyBase::postTaskToWorkerGlobalScope( |
64 const WebTraceLocation& location, | 63 const WebTraceLocation& location, |
65 std::unique_ptr<WTF::CrossThreadClosure> task) { | 64 std::unique_ptr<WTF::CrossThreadClosure> task) { |
66 if (m_askedToTerminate) | 65 if (m_askedToTerminate) |
67 return; | 66 return; |
68 | 67 |
69 DCHECK(m_workerThread); | 68 DCHECK(m_workerThread); |
70 m_workerThread->postTask(location, std::move(task)); | 69 m_workerThread->postTask(location, std::move(task)); |
71 } | 70 } |
72 | 71 |
73 void ThreadedMessagingProxyBase::postTaskToLoader( | 72 void ThreadedMessagingProxyBase::postTaskToLoader( |
74 const WebTraceLocation& location, | 73 const WebTraceLocation& location, |
75 std::unique_ptr<WTF::CrossThreadClosure> task) { | 74 std::unique_ptr<WTF::CrossThreadClosure> task) { |
76 m_parentFrameTaskRunners->get(TaskType::Networking) | 75 FrameTaskRunnerHelper::get(TaskType::Networking, m_workerThread.get()) |
77 ->postTask(BLINK_FROM_HERE, std::move(task)); | 76 ->postTask(BLINK_FROM_HERE, std::move(task)); |
78 } | 77 } |
79 | 78 |
80 ExecutionContext* ThreadedMessagingProxyBase::getLoaderExecutionContext() { | 79 ExecutionContext* ThreadedMessagingProxyBase::getLoaderExecutionContext() { |
81 DCHECK(isParentContextThread()); | 80 DCHECK(isParentContextThread()); |
82 return getExecutionContext(); | 81 return getExecutionContext(); |
83 } | 82 } |
84 | 83 |
85 void ThreadedMessagingProxyBase::countFeature(UseCounter::Feature feature) { | 84 void ThreadedMessagingProxyBase::countFeature(UseCounter::Feature feature) { |
86 DCHECK(isParentContextThread()); | 85 DCHECK(isParentContextThread()); |
(...skipping 19 matching lines...) Expand all Loading... |
106 } | 105 } |
107 | 106 |
108 void ThreadedMessagingProxyBase::workerThreadCreated() { | 107 void ThreadedMessagingProxyBase::workerThreadCreated() { |
109 DCHECK(isParentContextThread()); | 108 DCHECK(isParentContextThread()); |
110 DCHECK(!m_askedToTerminate); | 109 DCHECK(!m_askedToTerminate); |
111 DCHECK(m_workerThread); | 110 DCHECK(m_workerThread); |
112 } | 111 } |
113 | 112 |
114 void ThreadedMessagingProxyBase::parentObjectDestroyed() { | 113 void ThreadedMessagingProxyBase::parentObjectDestroyed() { |
115 DCHECK(isParentContextThread()); | 114 DCHECK(isParentContextThread()); |
116 | 115 FrameTaskRunnerHelper::get(TaskType::UnspecedTimer, m_workerThread.get()) |
117 getParentFrameTaskRunners() | |
118 ->get(TaskType::UnspecedTimer) | |
119 ->postTask( | 116 ->postTask( |
120 BLINK_FROM_HERE, | 117 BLINK_FROM_HERE, |
121 WTF::bind(&ThreadedMessagingProxyBase::parentObjectDestroyedInternal, | 118 WTF::bind(&ThreadedMessagingProxyBase::parentObjectDestroyedInternal, |
122 WTF::unretained(this))); | 119 WTF::unretained(this))); |
123 } | 120 } |
124 | 121 |
125 void ThreadedMessagingProxyBase::parentObjectDestroyedInternal() { | 122 void ThreadedMessagingProxyBase::parentObjectDestroyedInternal() { |
126 DCHECK(isParentContextThread()); | 123 DCHECK(isParentContextThread()); |
127 m_mayBeDestroyed = true; | 124 m_mayBeDestroyed = true; |
128 if (m_workerThread) | 125 if (m_workerThread) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 } | 162 } |
166 | 163 |
167 bool ThreadedMessagingProxyBase::isParentContextThread() const { | 164 bool ThreadedMessagingProxyBase::isParentContextThread() const { |
168 // TODO(nhiroki): Nested worker is not supported yet, so the parent context | 165 // TODO(nhiroki): Nested worker is not supported yet, so the parent context |
169 // thread should be equal to the main thread (http://crbug.com/31666). | 166 // thread should be equal to the main thread (http://crbug.com/31666). |
170 DCHECK(m_executionContext->isDocument()); | 167 DCHECK(m_executionContext->isDocument()); |
171 return isMainThread(); | 168 return isMainThread(); |
172 } | 169 } |
173 | 170 |
174 } // namespace blink | 171 } // namespace blink |
OLD | NEW |