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

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: 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/WorkerBackingThread.h"
42 #include "core/workers/WorkerGlobalScope.h"
43 #include "platform/WebThreadSupportingGC.h"
40 #include "wtf/Functional.h" 44 #include "wtf/Functional.h"
41 #include "wtf/PtrUtil.h" 45 #include "wtf/PtrUtil.h"
42 #include <memory> 46 #include <memory>
43 47
44 namespace blink { 48 namespace blink {
45 49
50 const long long kDefaultDelayToCheckPendingActivityInMs = 1; // 1 sec
51 const long long kMaxDelayToCheckPendingActivityInMs = 30; // 30 secs
haraken 2016/08/05 08:20:58 If we have the exponential-backoff timer, maybe ca
nhiroki 2016/08/08 09:19:14 I think it couldn't work in some cases. For exampl
haraken 2016/08/08 11:00:55 Are you worrying about the following case? 1) The
nhiroki 2016/08/08 11:35:33 Yes, that's right.
52
46 std::unique_ptr<InProcessWorkerObjectProxy> InProcessWorkerObjectProxy::create(I nProcessWorkerMessagingProxy* messagingProxy) 53 std::unique_ptr<InProcessWorkerObjectProxy> InProcessWorkerObjectProxy::create(I nProcessWorkerMessagingProxy* messagingProxy)
47 { 54 {
48 DCHECK(messagingProxy); 55 DCHECK(messagingProxy);
49 return wrapUnique(new InProcessWorkerObjectProxy(messagingProxy)); 56 return wrapUnique(new InProcessWorkerObjectProxy(messagingProxy));
50 } 57 }
51 58
59 InProcessWorkerObjectProxy::~InProcessWorkerObjectProxy() {}
60
52 void InProcessWorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<Serialized ScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels) 61 void InProcessWorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<Serialized ScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels)
53 { 62 {
54 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::postMessageToWorkerObject, crossThreadUnretained(m_me ssagingProxy), message, passed(std::move(channels)))); 63 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::postMessageToWorkerObject, crossThreadUnretained(m_me ssagingProxy), message, passed(std::move(channels))));
55 } 64 }
56 65
57 void InProcessWorkerObjectProxy::postTaskToMainExecutionContext(std::unique_ptr< ExecutionContextTask> task) 66 void InProcessWorkerObjectProxy::postTaskToMainExecutionContext(std::unique_ptr< ExecutionContextTask> task)
58 { 67 {
59 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task)); 68 getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task));
60 } 69 }
61 70
62 void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject(bool hasPendingA ctivity) 71 void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject()
63 { 72 {
64 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::confirmMessageFromWorkerObject, crossThreadUnretained (m_messagingProxy), hasPendingActivity)); 73 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::confirmMessageFromWorkerObject, crossThreadUnretained (m_messagingProxy)));
65 } 74 }
66 75
67 void InProcessWorkerObjectProxy::reportPendingActivity(bool hasPendingActivity) 76 void InProcessWorkerObjectProxy::reportPendingActivity(WorkerGlobalScope* worker GlobalScope)
kinuko 2016/08/05 14:55:29 This should be probably renamed to checkPendingAct
nhiroki 2016/08/08 09:19:14 Done.
68 { 77 {
78 bool hasPendingActivity = workerGlobalScope->hasPendingActivity() || V8GCCon troller::hasPendingActivity(workerGlobalScope->thread()->isolate(), workerGlobal Scope);
69 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportPendingActivity, crossThreadUnretained(m_messag ingProxy), hasPendingActivity)); 79 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportPendingActivity, crossThreadUnretained(m_messag ingProxy), hasPendingActivity));
80
81 if (!hasPendingActivity) {
82 m_taskCanceller.cancel();
83 m_currentDelayToCheckPendingActivityInMs = kDefaultDelayToCheckPendingAc tivityInMs;
84 return;
85 }
86
87 // Post a delayed task to check whether there is a pending activity.
88 std::unique_ptr<WTF::Closure> task = WTF::bind(&InProcessWorkerObjectProxy:: reportPendingActivity, unretained(this), wrapWeakPersistent(workerGlobalScope));
89 auto result = makeCancellable(std::move(task));
90 m_taskCanceller = std::move(result.canceller);
91 workerGlobalScope->thread()->workerBackingThread().backingThread().postDelay edTask(BLINK_FROM_HERE, std::move(result.function), m_currentDelayToCheckPending ActivityInMs);
92
93 // Update the delay.
94 long long newDelayInMs = m_currentDelayToCheckPendingActivityInMs * 1.5;
95 m_currentDelayToCheckPendingActivityInMs = std::min(newDelayInMs, m_maxDelay ToCheckPendingActivityInMs);
kinuko 2016/08/05 14:55:29 Hmm.. it feels what the class-level comment in the
nhiroki 2016/08/08 09:19:14 Slightly updated the header comment. Checking pen
70 } 96 }
71 97
72 void InProcessWorkerObjectProxy::reportException(const String& errorMessage, std ::unique_ptr<SourceLocation> location, int exceptionId) 98 void InProcessWorkerObjectProxy::reportException(const String& errorMessage, std ::unique_ptr<SourceLocation> location, int exceptionId)
73 { 99 {
74 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportException, crossThreadUnretained(m_messagingPro xy), errorMessage, passed(location->clone()), exceptionId)); 100 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportException, crossThreadUnretained(m_messagingPro xy), errorMessage, passed(location->clone()), exceptionId));
75 } 101 }
76 102
77 void InProcessWorkerObjectProxy::reportConsoleMessage(MessageSource source, Mess ageLevel level, const String& message, SourceLocation* location) 103 void InProcessWorkerObjectProxy::reportConsoleMessage(MessageSource source, Mess ageLevel level, const String& message, SourceLocation* location)
78 { 104 {
79 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportConsoleMessage, crossThreadUnretained(m_messagi ngProxy), source, level, message, passed(location->clone()))); 105 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::reportConsoleMessage, crossThreadUnretained(m_messagi ngProxy), source, level, message, passed(location->clone())));
(...skipping 10 matching lines...) Expand all
90 { 116 {
91 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::terminateWorkerGlobalScope, crossThreadUnretained(m_m essagingProxy))); 117 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::terminateWorkerGlobalScope, crossThreadUnretained(m_m essagingProxy)));
92 } 118 }
93 119
94 void InProcessWorkerObjectProxy::workerThreadTerminated() 120 void InProcessWorkerObjectProxy::workerThreadTerminated()
95 { 121 {
96 // This will terminate the MessagingProxy. 122 // This will terminate the MessagingProxy.
97 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::workerThreadTerminated, crossThreadUnretained(m_messa gingProxy))); 123 getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InPr ocessWorkerMessagingProxy::workerThreadTerminated, crossThreadUnretained(m_messa gingProxy)));
98 } 124 }
99 125
126 void InProcessWorkerObjectProxy::willDestroyWorkerGlobalScope()
127 {
128 if (m_taskCanceller.isActive())
129 m_taskCanceller.cancel();
tzik 2016/08/05 05:16:06 nit: cancel() is noop if isActive() returns false.
nhiroki 2016/08/08 09:19:14 Done.
130 }
131
100 InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(InProcessWorkerMessagingP roxy* messagingProxy) 132 InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(InProcessWorkerMessagingP roxy* messagingProxy)
101 : m_messagingProxy(messagingProxy) 133 : m_messagingProxy(messagingProxy)
134 , m_currentDelayToCheckPendingActivityInMs(kDefaultDelayToCheckPendingActivi tyInMs)
135 , m_maxDelayToCheckPendingActivityInMs(kMaxDelayToCheckPendingActivityInMs)
102 { 136 {
103 } 137 }
104 138
105 ExecutionContext* InProcessWorkerObjectProxy::getExecutionContext() 139 ExecutionContext* InProcessWorkerObjectProxy::getExecutionContext()
106 { 140 {
107 DCHECK(m_messagingProxy); 141 DCHECK(m_messagingProxy);
108 return m_messagingProxy->getExecutionContext(); 142 return m_messagingProxy->getExecutionContext();
109 } 143 }
110 144
111 } // namespace blink 145 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698