Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.cpp

Issue 2124693002: Worker: Fix broken GC logic on Dedicated Worker while DOMTimer is set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "core/workers/InProcessWorkerObjectProxy.h" 31 #include "core/workers/InProcessWorkerObjectProxy.h"
32 32
33 #include "bindings/core/v8/SerializedScriptValue.h" 33 #include "bindings/core/v8/SerializedScriptValue.h"
34 #include "bindings/core/v8/SourceLocation.h" 34 #include "bindings/core/v8/SourceLocation.h"
35 #include "bindings/core/v8/V8GCController.h"
35 #include "core/dom/CrossThreadTask.h" 36 #include "core/dom/CrossThreadTask.h"
36 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
37 #include "core/dom/ExecutionContext.h" 38 #include "core/dom/ExecutionContext.h"
38 #include "core/inspector/ConsoleMessage.h" 39 #include "core/inspector/ConsoleMessage.h"
39 #include "core/workers/InProcessWorkerMessagingProxy.h" 40 #include "core/workers/InProcessWorkerMessagingProxy.h"
40 #include "core/workers/ParentFrameTaskRunners.h" 41 #include "core/workers/ParentFrameTaskRunners.h"
42 #include "core/workers/WorkerGlobalScope.h"
43 #include "core/workers/WorkerThread.h"
41 #include "platform/CrossThreadFunctional.h" 44 #include "platform/CrossThreadFunctional.h"
42 #include "public/platform/WebTaskRunner.h" 45 #include "public/platform/WebTaskRunner.h"
43 #include "wtf/Functional.h" 46 #include "wtf/Functional.h"
44 #include "wtf/PtrUtil.h" 47 #include "wtf/PtrUtil.h"
45 #include <memory> 48 #include <memory>
46 49
47 namespace blink { 50 namespace blink {
48 51
52 const double kDefaultIntervalInSec = 1;
53 const double kMaxIntervalInSec = 30;
54
49 std::unique_ptr<InProcessWorkerObjectProxy> InProcessWorkerObjectProxy::create(I nProcessWorkerMessagingProxy* messagingProxy) 55 std::unique_ptr<InProcessWorkerObjectProxy> InProcessWorkerObjectProxy::create(I nProcessWorkerMessagingProxy* messagingProxy)
50 { 56 {
51 DCHECK(messagingProxy); 57 DCHECK(messagingProxy);
52 return wrapUnique(new InProcessWorkerObjectProxy(messagingProxy)); 58 return wrapUnique(new InProcessWorkerObjectProxy(messagingProxy));
53 } 59 }
54 60
61 InProcessWorkerObjectProxy::~InProcessWorkerObjectProxy() {}
62
55 void InProcessWorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<Serialized ScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels) 63 void InProcessWorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<Serialized ScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels)
56 { 64 {
57 getParentFrameTaskRunners()->get(TaskType::PostedMessage)->postTask(BLINK_FR OM_HERE, crossThreadBind(&InProcessWorkerMessagingProxy::postMessageToWorkerObje ct, crossThreadUnretained(m_messagingProxy), message, passed(std::move(channels) ))); 65 getParentFrameTaskRunners()->get(TaskType::PostedMessage)->postTask(BLINK_FR OM_HERE, crossThreadBind(&InProcessWorkerMessagingProxy::postMessageToWorkerObje ct, crossThreadUnretained(m_messagingProxy), message, passed(std::move(channels) )));
58 } 66 }
59 67
60 void InProcessWorkerObjectProxy::postTaskToMainExecutionContext(std::unique_ptr< ExecutionContextTask> task) 68 void InProcessWorkerObjectProxy::postTaskToMainExecutionContext(std::unique_ptr< ExecutionContextTask> task)
61 { 69 {
62 // TODO(hiroshige,yuryu): Make this not use ExecutionContextTask and use 70 // TODO(hiroshige,yuryu): Make this not use ExecutionContextTask and use
63 // getParentFrameTaskRunners() instead. 71 // getParentFrameTaskRunners() instead.
64 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task)); 72 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task));
65 } 73 }
66 74
67 void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject(bool hasPendingA ctivity) 75 void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject()
68 { 76 {
69 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::confirmMessageFromWorkerObje ct, crossThreadUnretained(m_messagingProxy), hasPendingActivity)); 77 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::confirmMessageFromWorkerObje ct, crossThreadUnretained(m_messagingProxy)));
70 } 78 }
71 79
72 void InProcessWorkerObjectProxy::reportPendingActivity(bool hasPendingActivity) 80 void InProcessWorkerObjectProxy::startPendingActivityTimer()
73 { 81 {
74 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::reportPendingActivity, cross ThreadUnretained(m_messagingProxy), hasPendingActivity)); 82 if (m_timer->isActive()) {
83 // Avoid a timer flood, for example, caused by a burst of posted
84 // messages.
85 if (m_currentIntervalInSec == kDefaultIntervalInSec)
haraken 2016/08/17 06:30:47 Does this branch really work? You're updating m_cu
kinuko 2016/08/17 22:50:10 m_currentIntervalInSec is actually a next interval
nhiroki 2016/08/17 23:31:31 Acknowledged.
nhiroki 2016/08/17 23:31:31 Ooops... yes, this doesn't work.
86 return;
87
88 // Restart the timer with the default interval duration to check newly
89 // initiated pending activities timely.
90 m_currentIntervalInSec = kDefaultIntervalInSec;
91 }
92
93 m_timer->startOneShot(m_currentIntervalInSec, BLINK_FROM_HERE);
94 m_currentIntervalInSec = std::min(m_currentIntervalInSec * 1.5, m_maxInterva lInSec);
75 } 95 }
76 96
77 void InProcessWorkerObjectProxy::reportException(const String& errorMessage, std ::unique_ptr<SourceLocation> location, int exceptionId) 97 void InProcessWorkerObjectProxy::reportException(const String& errorMessage, std ::unique_ptr<SourceLocation> location, int exceptionId)
78 { 98 {
79 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::reportException, crossThread Unretained(m_messagingProxy), errorMessage, passed(location->clone()), exception Id)); 99 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::reportException, crossThread Unretained(m_messagingProxy), errorMessage, passed(location->clone()), exception Id));
80 } 100 }
81 101
82 void InProcessWorkerObjectProxy::reportConsoleMessage(MessageSource source, Mess ageLevel level, const String& message, SourceLocation* location) 102 void InProcessWorkerObjectProxy::reportConsoleMessage(MessageSource source, Mess ageLevel level, const String& message, SourceLocation* location)
83 { 103 {
84 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::reportConsoleMessage, crossT hreadUnretained(m_messagingProxy), source, level, message, passed(location->clon e()))); 104 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::reportConsoleMessage, crossT hreadUnretained(m_messagingProxy), source, level, message, passed(location->clon e())));
85 } 105 }
86 106
87 void InProcessWorkerObjectProxy::postMessageToPageInspector(const String& messag e) 107 void InProcessWorkerObjectProxy::postMessageToPageInspector(const String& messag e)
88 { 108 {
89 ExecutionContext* context = getExecutionContext(); 109 ExecutionContext* context = getExecutionContext();
90 if (context->isDocument()) { 110 if (context->isDocument()) {
91 // TODO(hiroshige): consider using getParentFrameTaskRunners() here 111 // TODO(hiroshige): consider using getParentFrameTaskRunners() here
92 // too. 112 // too.
93 toDocument(context)->postInspectorTask(BLINK_FROM_HERE, createCrossThrea dTask(&InProcessWorkerMessagingProxy::postMessageToPageInspector, crossThreadUnr etained(m_messagingProxy), message)); 113 toDocument(context)->postInspectorTask(BLINK_FROM_HERE, createCrossThrea dTask(&InProcessWorkerMessagingProxy::postMessageToPageInspector, crossThreadUnr etained(m_messagingProxy), message));
94 } 114 }
95 } 115 }
96 116
117 void InProcessWorkerObjectProxy::didEvaluateWorkerScript(bool)
118 {
119 startPendingActivityTimer();
120 }
121
122 void InProcessWorkerObjectProxy::workerGlobalScopeStarted(WorkerOrWorkletGlobalS cope* globalScope)
123 {
124 DCHECK(!m_workerGlobalScope);
125 m_workerGlobalScope = toWorkerGlobalScope(globalScope);
126 m_timer = wrapUnique(new Timer<InProcessWorkerObjectProxy>(this, &InProcessW orkerObjectProxy::checkPendingActivity));
127 }
128
97 void InProcessWorkerObjectProxy::workerGlobalScopeClosed() 129 void InProcessWorkerObjectProxy::workerGlobalScopeClosed()
98 { 130 {
99 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::terminateWorkerGlobalScope, crossThreadUnretained(m_messagingProxy))); 131 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::terminateWorkerGlobalScope, crossThreadUnretained(m_messagingProxy)));
100 } 132 }
101 133
102 void InProcessWorkerObjectProxy::workerThreadTerminated() 134 void InProcessWorkerObjectProxy::workerThreadTerminated()
103 { 135 {
104 // This will terminate the MessagingProxy. 136 // This will terminate the MessagingProxy.
105 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::workerThreadTerminated, cros sThreadUnretained(m_messagingProxy))); 137 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FROM_HE RE, crossThreadBind(&InProcessWorkerMessagingProxy::workerThreadTerminated, cros sThreadUnretained(m_messagingProxy)));
106 } 138 }
107 139
140 void InProcessWorkerObjectProxy::willDestroyWorkerGlobalScope()
141 {
142 m_timer.reset();
143 m_workerGlobalScope = nullptr;
144 }
145
108 InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(InProcessWorkerMessagingP roxy* messagingProxy) 146 InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(InProcessWorkerMessagingP roxy* messagingProxy)
109 : m_messagingProxy(messagingProxy) 147 : m_messagingProxy(messagingProxy)
148 , m_currentIntervalInSec(kDefaultIntervalInSec)
149 , m_maxIntervalInSec(kMaxIntervalInSec)
110 { 150 {
111 } 151 }
112 152
113 ParentFrameTaskRunners* InProcessWorkerObjectProxy::getParentFrameTaskRunners() 153 ParentFrameTaskRunners* InProcessWorkerObjectProxy::getParentFrameTaskRunners()
114 { 154 {
115 DCHECK(m_messagingProxy); 155 DCHECK(m_messagingProxy);
116 return m_messagingProxy->getParentFrameTaskRunners(); 156 return m_messagingProxy->getParentFrameTaskRunners();
117 } 157 }
118 158
119 ExecutionContext* InProcessWorkerObjectProxy::getExecutionContext() 159 ExecutionContext* InProcessWorkerObjectProxy::getExecutionContext()
120 { 160 {
121 DCHECK(m_messagingProxy); 161 DCHECK(m_messagingProxy);
122 return m_messagingProxy->getExecutionContext(); 162 return m_messagingProxy->getExecutionContext();
123 } 163 }
124 164
165 void InProcessWorkerObjectProxy::checkPendingActivity(TimerBase*)
166 {
167 bool hasPendingActivity = V8GCController::hasPendingActivity(m_workerGlobalS cope->thread()->isolate(), m_workerGlobalScope);
168 if (!hasPendingActivity) {
169 // Report all activities are done.
170 getParentFrameTaskRunners()->get(TaskType::Internal)->postTask(BLINK_FRO M_HERE, crossThreadBind(&InProcessWorkerMessagingProxy::pendingActivityFinished, crossThreadUnretained(m_messagingProxy)));
171
172 // Don't schedule a timer. It will be started again when a message event
173 // is dispatched.
174 m_currentIntervalInSec = kDefaultIntervalInSec;
175 return;
176 }
177
178 // There is still a pending activity. Check it later.
179 startPendingActivityTimer();
180 }
181
125 } // namespace blink 182 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698