java_handler_thread_helpers.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include "base/test/android/java_handler_thread_helpers.h"
  5. #include "base/android/java_handler_thread.h"
  6. #include "base/synchronization/waitable_event.h"
  7. #include "base/task/current_thread.h"
  8. #include "base/test/base_unittests_jni_headers/JavaHandlerThreadHelpers_jni.h"
  9. namespace base {
  10. namespace android {
  11. // static
  12. std::unique_ptr<JavaHandlerThread> JavaHandlerThreadHelpers::CreateJavaFirst() {
  13. return std::make_unique<JavaHandlerThread>(
  14. nullptr, Java_JavaHandlerThreadHelpers_testAndGetJavaHandlerThread(
  15. base::android::AttachCurrentThread()));
  16. }
  17. // static
  18. void JavaHandlerThreadHelpers::ThrowExceptionAndAbort(WaitableEvent* event) {
  19. JNIEnv* env = AttachCurrentThread();
  20. Java_JavaHandlerThreadHelpers_throwException(env);
  21. DCHECK(HasException(env));
  22. base::CurrentUIThread::Get()->Abort();
  23. event->Signal();
  24. }
  25. // static
  26. bool JavaHandlerThreadHelpers::IsExceptionTestException(
  27. ScopedJavaLocalRef<jthrowable> exception) {
  28. JNIEnv* env = AttachCurrentThread();
  29. return Java_JavaHandlerThreadHelpers_isExceptionTestException(env, exception);
  30. }
  31. } // namespace android
  32. } // namespace base