1 // Copyright 2016 The Chromium Authors 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/synchronization/waitable_event.h" 9 #include "base/task/current_thread.h" 10 11 // Must come after all headers that specialize FromJniType() / ToJniType(). 12 #include "base/test/base_unittests_jni_headers/JavaHandlerThreadHelpers_jni.h" 13 14 namespace base { 15 namespace android { 16 17 // static CreateJavaFirst()18std::unique_ptr<JavaHandlerThread> JavaHandlerThreadHelpers::CreateJavaFirst() { 19 return std::make_unique<JavaHandlerThread>( 20 nullptr, Java_JavaHandlerThreadHelpers_testAndGetJavaHandlerThread( 21 jni_zero::AttachCurrentThread())); 22 } 23 24 // static ThrowExceptionAndAbort(WaitableEvent * event)25void JavaHandlerThreadHelpers::ThrowExceptionAndAbort(WaitableEvent* event) { 26 JNIEnv* env = jni_zero::AttachCurrentThread(); 27 Java_JavaHandlerThreadHelpers_throwException(env); 28 DCHECK(jni_zero::HasException(env)); 29 base::CurrentUIThread::Get()->Abort(); 30 event->Signal(); 31 } 32 33 // static IsExceptionTestException(ScopedJavaLocalRef<jthrowable> exception)34bool JavaHandlerThreadHelpers::IsExceptionTestException( 35 ScopedJavaLocalRef<jthrowable> exception) { 36 JNIEnv* env = jni_zero::AttachCurrentThread(); 37 return Java_JavaHandlerThreadHelpers_isExceptionTestException(env, exception); 38 } 39 40 } // namespace android 41 } // namespace base 42