Index: base/test/android/java_handler_thread_for_testing.cc |
diff --git a/base/test/android/java_handler_thread_for_testing.cc b/base/test/android/java_handler_thread_for_testing.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..896f78550399a9eebbbc8fcfcfd88ba9a999c9e9 |
--- /dev/null |
+++ b/base/test/android/java_handler_thread_for_testing.cc |
@@ -0,0 +1,49 @@ |
+// Copyright 2016 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 "base/test/android/java_handler_thread_for_testing.h" |
+ |
+#include "base/message_loop/message_loop.h" |
+ |
+namespace base { |
+namespace android { |
+ |
+base::android::ScopedJavaLocalRef<jobject> |
+TestJavaMessageHandlerFactory::CreateMessageHandler( |
+ JNIEnv* env, |
+ base::MessagePump::Delegate* delegate, |
+ MessagePumpForUI* message_pump, |
+ WaitableEvent* test_done_event) { |
+ return TestSystemMessageHandlerLink::createTestSystemMessageHandler( |
+ env, delegate, message_pump, test_done_event); |
+} |
+ |
+JavaHandlerThreadForTesting::JavaHandlerThreadForTesting( |
+ const char* name, |
+ base::WaitableEvent* test_done_event) |
+ : JavaHandlerThread(name), |
+ message_handler_factory_(new TestJavaMessageHandlerFactory()), |
+ test_done_event_(test_done_event) {} |
+ |
+JavaHandlerThreadForTesting::~JavaHandlerThreadForTesting() = default; |
+ |
+void JavaHandlerThreadForTesting::StartMessageLoop() { |
+ static_cast<MessageLoopForUI*>(message_loop_.get()) |
+ ->StartForTesting( |
+ message_handler_factory_.get(), |
+ reinterpret_cast<base::WaitableEvent*>(test_done_event_)); |
+} |
+ |
+void JavaHandlerThreadForTesting::StopMessageLoop() { |
+ // Instead of calling MessageLoop::QuitWhenIdle here we call |
+ // MessageLoop::QuitNow. This is because QuitWhenIdle will have no effect on |
+ // the message loop after MessageLoop::Abort has been called (which should |
+ // have happened at this point). |
+ static_cast<MessageLoopForUI*>(message_loop_.get())->QuitNow(); |
+ // The message loop must be destroyed on the thread it is attached to. |
+ message_loop_.reset(); |
+} |
+ |
+} // namespace base |
+} // namespace android |