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

Unified Diff: Source/modules/fetch/DataConsumerHandleTestUtil.cpp

Issue 1198443002: Fetch DataConsumerHandle test cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@tee
Patch Set: rebase Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/fetch/DataConsumerHandleTestUtil.h ('k') | Source/modules/fetch/DataConsumerTeeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/fetch/DataConsumerHandleTestUtil.cpp
diff --git a/Source/modules/fetch/DataConsumerHandleTestUtil.cpp b/Source/modules/fetch/DataConsumerHandleTestUtil.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..19c76b9dbae1b1c574896af456652052acbea50c
--- /dev/null
+++ b/Source/modules/fetch/DataConsumerHandleTestUtil.cpp
@@ -0,0 +1,56 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/fetch/DataConsumerHandleTestUtil.h"
+
+#include "bindings/core/v8/DOMWrapperWorld.h"
+
+namespace blink {
+
+DataConsumerHandleTestUtil::Thread::Thread(const char* name, InitializationPolicy initializationPolicy)
+ : m_thread(WebThreadSupportingGC::create(name))
+ , m_initializationPolicy(initializationPolicy)
+ , m_waitableEvent(adoptPtr(Platform::current()->createWaitableEvent()))
+{
+ m_thread->postTask(FROM_HERE, new Task(threadSafeBind(&Thread::initialize, AllowCrossThreadAccess(this))));
+ m_waitableEvent->wait();
+}
+
+DataConsumerHandleTestUtil::Thread::~Thread()
+{
+ m_thread->postTask(FROM_HERE, new Task(threadSafeBind(&Thread::shutdown, AllowCrossThreadAccess(this))));
+ m_waitableEvent->wait();
+}
+
+void DataConsumerHandleTestUtil::Thread::initialize()
+{
+ if (m_initializationPolicy >= ScriptExecution) {
+ m_isolateHolder = adoptPtr(new gin::IsolateHolder());
+ isolate()->Enter();
+ }
+ m_thread->initialize();
+ if (m_initializationPolicy >= ScriptExecution) {
+ v8::HandleScope handleScope(isolate());
+ m_scriptState = ScriptState::create(v8::Context::New(isolate()), DOMWrapperWorld::create(isolate()));
Nico 2015/08/26 03:54:51 It looks like this is leaked somehow, see e.g. htt
+ }
+ if (m_initializationPolicy >= WithExecutionContext) {
+ m_executionContext = adoptRefWillBeNoop(new NullExecutionContext());
+ }
+ m_waitableEvent->signal();
+}
+
+void DataConsumerHandleTestUtil::Thread::shutdown()
+{
+ m_executionContext = nullptr;
+ m_scriptState = nullptr;
+ m_thread->shutdown();
+ if (m_isolateHolder) {
+ isolate()->Exit();
+ m_isolateHolder = nullptr;
+ }
+ m_waitableEvent->signal();
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/fetch/DataConsumerHandleTestUtil.h ('k') | Source/modules/fetch/DataConsumerTeeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698