Index: third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.cpp |
diff --git a/third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.cpp b/third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.cpp |
index 67a8b59d6fedf0b55b9fd8a38253956a7fcace59..178b270cd7e6167909997d8ef07535468c72b043 100644 |
--- a/third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.cpp |
+++ b/third_party/WebKit/Source/core/workers/InProcessWorkerObjectProxy.cpp |
@@ -32,23 +32,32 @@ |
#include "bindings/core/v8/SerializedScriptValue.h" |
#include "bindings/core/v8/SourceLocation.h" |
+#include "bindings/core/v8/V8GCController.h" |
#include "core/dom/CrossThreadTask.h" |
#include "core/dom/Document.h" |
#include "core/dom/ExecutionContext.h" |
#include "core/inspector/ConsoleMessage.h" |
#include "core/workers/InProcessWorkerMessagingProxy.h" |
+#include "core/workers/WorkerBackingThread.h" |
+#include "core/workers/WorkerGlobalScope.h" |
+#include "platform/WebThreadSupportingGC.h" |
#include "wtf/Functional.h" |
#include "wtf/PtrUtil.h" |
#include <memory> |
namespace blink { |
+const long long kDefaultDelayToCheckPendingActivityInMs = 1; // 1 sec |
+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.
|
+ |
std::unique_ptr<InProcessWorkerObjectProxy> InProcessWorkerObjectProxy::create(InProcessWorkerMessagingProxy* messagingProxy) |
{ |
DCHECK(messagingProxy); |
return wrapUnique(new InProcessWorkerObjectProxy(messagingProxy)); |
} |
+InProcessWorkerObjectProxy::~InProcessWorkerObjectProxy() {} |
+ |
void InProcessWorkerObjectProxy::postMessageToWorkerObject(PassRefPtr<SerializedScriptValue> message, std::unique_ptr<MessagePortChannelArray> channels) |
{ |
getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InProcessWorkerMessagingProxy::postMessageToWorkerObject, crossThreadUnretained(m_messagingProxy), message, passed(std::move(channels)))); |
@@ -59,14 +68,31 @@ void InProcessWorkerObjectProxy::postTaskToMainExecutionContext(std::unique_ptr< |
getExecutionContext()->postTask(BLINK_FROM_HERE, std::move(task)); |
} |
-void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject(bool hasPendingActivity) |
+void InProcessWorkerObjectProxy::confirmMessageFromWorkerObject() |
{ |
- getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InProcessWorkerMessagingProxy::confirmMessageFromWorkerObject, crossThreadUnretained(m_messagingProxy), hasPendingActivity)); |
+ getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InProcessWorkerMessagingProxy::confirmMessageFromWorkerObject, crossThreadUnretained(m_messagingProxy))); |
} |
-void InProcessWorkerObjectProxy::reportPendingActivity(bool hasPendingActivity) |
+void InProcessWorkerObjectProxy::reportPendingActivity(WorkerGlobalScope* workerGlobalScope) |
kinuko
2016/08/05 14:55:29
This should be probably renamed to checkPendingAct
nhiroki
2016/08/08 09:19:14
Done.
|
{ |
+ bool hasPendingActivity = workerGlobalScope->hasPendingActivity() || V8GCController::hasPendingActivity(workerGlobalScope->thread()->isolate(), workerGlobalScope); |
getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InProcessWorkerMessagingProxy::reportPendingActivity, crossThreadUnretained(m_messagingProxy), hasPendingActivity)); |
+ |
+ if (!hasPendingActivity) { |
+ m_taskCanceller.cancel(); |
+ m_currentDelayToCheckPendingActivityInMs = kDefaultDelayToCheckPendingActivityInMs; |
+ return; |
+ } |
+ |
+ // Post a delayed task to check whether there is a pending activity. |
+ std::unique_ptr<WTF::Closure> task = WTF::bind(&InProcessWorkerObjectProxy::reportPendingActivity, unretained(this), wrapWeakPersistent(workerGlobalScope)); |
+ auto result = makeCancellable(std::move(task)); |
+ m_taskCanceller = std::move(result.canceller); |
+ workerGlobalScope->thread()->workerBackingThread().backingThread().postDelayedTask(BLINK_FROM_HERE, std::move(result.function), m_currentDelayToCheckPendingActivityInMs); |
+ |
+ // Update the delay. |
+ long long newDelayInMs = m_currentDelayToCheckPendingActivityInMs * 1.5; |
+ m_currentDelayToCheckPendingActivityInMs = std::min(newDelayInMs, m_maxDelayToCheckPendingActivityInMs); |
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
|
} |
void InProcessWorkerObjectProxy::reportException(const String& errorMessage, std::unique_ptr<SourceLocation> location, int exceptionId) |
@@ -97,8 +123,16 @@ void InProcessWorkerObjectProxy::workerThreadTerminated() |
getExecutionContext()->postTask(BLINK_FROM_HERE, createCrossThreadTask(&InProcessWorkerMessagingProxy::workerThreadTerminated, crossThreadUnretained(m_messagingProxy))); |
} |
+void InProcessWorkerObjectProxy::willDestroyWorkerGlobalScope() |
+{ |
+ if (m_taskCanceller.isActive()) |
+ 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.
|
+} |
+ |
InProcessWorkerObjectProxy::InProcessWorkerObjectProxy(InProcessWorkerMessagingProxy* messagingProxy) |
: m_messagingProxy(messagingProxy) |
+ , m_currentDelayToCheckPendingActivityInMs(kDefaultDelayToCheckPendingActivityInMs) |
+ , m_maxDelayToCheckPendingActivityInMs(kMaxDelayToCheckPendingActivityInMs) |
{ |
} |