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

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: annotate WorkerGlobalScope interface with 'ActiveScriptWrappable' and make tests stricter 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"
41 #include "core/workers/WorkerGlobalScope.h"
42 #include "core/workers/WorkerThread.h"
40 #include "wtf/Functional.h" 43 #include "wtf/Functional.h"
41 #include "wtf/PtrUtil.h" 44 #include "wtf/PtrUtil.h"
42 #include <memory> 45 #include <memory>
43 46
44 namespace blink { 47 namespace blink {
45 48
49 const double kDefaultIntervalInSec = 1;
50 const double kMaxIntervalInSec = 30;
51
46 std::unique_ptr<InProcessWorkerObjectProxy> InProcessWorkerObjectProxy::create(I nProcessWorkerMessagingProxy* messagingProxy) 52 std::unique_ptr<InProcessWorkerObjectProxy> InProcessWorkerObjectProxy::create(I nProcessWorkerMessagingProxy* messagingProxy)
47 { 53 {
48 DCHECK(messagingProxy); 54 DCHECK(messagingProxy);
49 return wrapUnique(new InProcessWorkerObjectProxy(messagingProxy)); 55 return wrapUnique(new InProcessWorkerObjectProxy(messagingProxy));
50 } 56 }
51 57
58 InProcessWorkerObjectProxy::~InProcessWorkerObjectProxy() {}
59
52 void InProcessWorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<Serialized ScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels) 60 void InProcessWorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<Serialized ScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels)
53 { 61 {
54 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::postMessageToWorkerObject, crossThreadUnretained(m_me ssagingProxy), message, passed(std::move(channels)))); 62 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::postMessageToWorkerObject, crossThreadUnretained(m_me ssagingProxy), message, passed(std::move(channels))));
55 } 63 }
56 64
57 void InProcessWorkerObjectProxy::postTaskToMainExecutionContext(std::unique_ptr< ExecutionContextTask> task) 65 void InProcessWorkerObjectProxy::postTaskToMainExecutionContext(std::unique_ptr< ExecutionContextTask> task)
58 { 66 {
59 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task)); 67 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task));
60 } 68 }
61 69
62 void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject(bool hasPendingA ctivity) 70 void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject()
63 { 71 {
64 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::confirmMessageFromWorkerObject, crossThreadUnretained (m_messagingProxy), hasPendingActivity)); 72 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::confirmMessageFromWorkerObject, crossThreadUnretained (m_messagingProxy)));
65 } 73 }
66 74
67 void InProcessWorkerObjectProxy::reportPendingActivity(bool hasPendingActivity) 75 void InProcessWorkerObjectProxy::startPendingActivityTimer()
68 { 76 {
69 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportPendingActivity, crossThreadUnretained(m_messag ingProxy), hasPendingActivity)); 77 // Restart the timer if it's running.
78 if (m_timer->isActive())
79 m_currentIntervalInSec = kDefaultIntervalInSec;
80
81 m_timer->startOneShot(m_currentIntervalInSec, BLINK_FROM_HERE);
haraken 2016/08/16 12:17:40 Given that startPendingActivityTimer is called at
kinuko 2016/08/16 21:37:38 I think we could possibly restart the timer only i
nhiroki 2016/08/17 04:45:32 On second thought, it'd be preferable just to retu
kinuko 2016/08/17 22:15:08 One possible scenario I considered was a message f
nhiroki 2016/08/17 23:31:31 Acknowledged.
82 m_currentIntervalInSec = std::min(m_currentIntervalInSec * 1.5, m_maxInterva lInSec);
70 } 83 }
71 84
72 void InProcessWorkerObjectProxy::reportException(const String& errorMessage, std ::unique_ptr<SourceLocation> location, int exceptionId) 85 void InProcessWorkerObjectProxy::reportException(const String& errorMessage, std ::unique_ptr<SourceLocation> location, int exceptionId)
73 { 86 {
74 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportException, crossThreadUnretained(m_messagingPro xy), errorMessage, passed(location->clone()), exceptionId)); 87 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportException, crossThreadUnretained(m_messagingPro xy), errorMessage, passed(location->clone()), exceptionId));
75 } 88 }
76 89
77 void InProcessWorkerObjectProxy::reportConsoleMessage(MessageSource source, Mess ageLevel level, const String& message, SourceLocation* location) 90 void InProcessWorkerObjectProxy::reportConsoleMessage(MessageSource source, Mess ageLevel level, const String& message, SourceLocation* location)
78 { 91 {
79 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportConsoleMessage, crossThreadUnretained(m_messagi ngProxy), source, level, message, passed(location->clone()))); 92 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportConsoleMessage, crossThreadUnretained(m_messagi ngProxy), source, level, message, passed(location->clone())));
80 } 93 }
81 94
82 void InProcessWorkerObjectProxy::postMessageToPageInspector(const String& messag e) 95 void InProcessWorkerObjectProxy::postMessageToPageInspector(const String& messag e)
83 { 96 {
84 ExecutionContext* context = getExecutionContext(); 97 ExecutionContext* context = getExecutionContext();
85 if (context->isDocument()) 98 if (context->isDocument())
86 toDocument(context)->postInspectorTask(BLINK_FROM_HERE, createCrossThrea dTask(&InProcessWorkerMessagingProxy::postMessageToPageInspector, crossThreadUnr etained(m_messagingProxy), message)); 99 toDocument(context)->postInspectorTask(BLINK_FROM_HERE, createCrossThrea dTask(&InProcessWorkerMessagingProxy::postMessageToPageInspector, crossThreadUnr etained(m_messagingProxy), message));
87 } 100 }
88 101
102 void InProcessWorkerObjectProxy::didEvaluateWorkerScript(bool)
103 {
104 startPendingActivityTimer();
105 }
106
107 void InProcessWorkerObjectProxy::workerGlobalScopeStarted(WorkerOrWorkletGlobalS cope* globalScope)
108 {
109 DCHECK(!m_workerGlobalScope);
110 m_workerGlobalScope = toWorkerGlobalScope(globalScope);
111 m_timer = wrapUnique(new Timer<InProcessWorkerObjectProxy>(this, &InProcessW orkerObjectProxy::checkPendingActivity));
112 }
113
89 void InProcessWorkerObjectProxy::workerGlobalScopeClosed() 114 void InProcessWorkerObjectProxy::workerGlobalScopeClosed()
90 { 115 {
91 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::terminateWorkerGlobalScope, crossThreadUnretained(m_m essagingProxy))); 116 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::terminateWorkerGlobalScope, crossThreadUnretained(m_m essagingProxy)));
92 } 117 }
93 118
94 void InProcessWorkerObjectProxy::workerThreadTerminated() 119 void InProcessWorkerObjectProxy::workerThreadTerminated()
95 { 120 {
96 // This will terminate the MessagingProxy. 121 // This will terminate the MessagingProxy.
97 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::workerThreadTerminated, crossThreadUnretained(m_messa gingProxy))); 122 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::workerThreadTerminated, crossThreadUnretained(m_messa gingProxy)));
98 } 123 }
99 124
125 void InProcessWorkerObjectProxy::willDestroyWorkerGlobalScope()
126 {
127 m_timer.reset();
128 m_workerGlobalScope = nullptr;
129 }
130
100 InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(InProcessWorkerMessagingP roxy* messagingProxy) 131 InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(InProcessWorkerMessagingP roxy* messagingProxy)
101 : m_messagingProxy(messagingProxy) 132 : m_messagingProxy(messagingProxy)
133 , m_currentIntervalInSec(kDefaultIntervalInSec)
134 , m_maxIntervalInSec(kMaxIntervalInSec)
102 { 135 {
103 } 136 }
104 137
105 ExecutionContext* InProcessWorkerObjectProxy::getExecutionContext() 138 ExecutionContext* InProcessWorkerObjectProxy::getExecutionContext()
106 { 139 {
107 DCHECK(m_messagingProxy); 140 DCHECK(m_messagingProxy);
108 return m_messagingProxy->getExecutionContext(); 141 return m_messagingProxy->getExecutionContext();
109 } 142 }
110 143
144 void InProcessWorkerObjectProxy::checkPendingActivity(TimerBase*)
145 {
haraken 2016/08/16 12:17:40 Shall we add DCHECK(m_workerGlobalScope) (if you w
nhiroki 2016/08/17 04:45:32 WONTFIX because I changed WeakPersistent to Persis
146 bool hasPendingActivity = V8GCController::hasPendingActivity(m_workerGlobalS cope->thread()->isolate(), m_workerGlobalScope);
147 if (!hasPendingActivity) {
148 // Report all activities are done.
149 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(& InProcessWorkerMessagingProxy::pendingActivityFinished, crossThreadUnretained(m_ messagingProxy)));
150
151 // Don't schedule a timer. It will be started again when a message event
152 // is dispatched.
153 m_currentIntervalInSec = kDefaultIntervalInSec;
154 return;
155 }
156
157 // There is still a pending activity. Check it later.
158 startPendingActivityTimer();
159 }
160
111 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698