1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/test/android/java_handler_thread_helpers.h" 6 7 #include "base/android/java_handler_thread.h" 8 #include "base/message_loop/message_loop_current.h" 9 #include "base/synchronization/waitable_event.h" 10 #include "jni/JavaHandlerThreadHelpers_jni.h" 11 12 namespace base { 13 namespace android { 14 15 // static CreateJavaFirst()16std::unique_ptr<JavaHandlerThread> JavaHandlerThreadHelpers::CreateJavaFirst() { 17 return std::make_unique<JavaHandlerThread>( 18 Java_JavaHandlerThreadHelpers_testAndGetJavaHandlerThread( 19 base::android::AttachCurrentThread())); 20 } 21 22 // static ThrowExceptionAndAbort(WaitableEvent * event)23void JavaHandlerThreadHelpers::ThrowExceptionAndAbort(WaitableEvent* event) { 24 JNIEnv* env = AttachCurrentThread(); 25 Java_JavaHandlerThreadHelpers_throwException(env); 26 DCHECK(HasException(env)); 27 base::MessageLoopCurrentForUI::Get()->Abort(); 28 event->Signal(); 29 } 30 31 // static IsExceptionTestException(ScopedJavaLocalRef<jthrowable> exception)32bool JavaHandlerThreadHelpers::IsExceptionTestException( 33 ScopedJavaLocalRef<jthrowable> exception) { 34 JNIEnv* env = AttachCurrentThread(); 35 return Java_JavaHandlerThreadHelpers_isExceptionTestException(env, exception); 36 } 37 38 } // namespace android 39 } // namespace base 40