post_task_android.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2018 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. #ifndef BASE_ANDROID_TASK_SCHEDULER_POST_TASK_ANDROID_H_
  5. #define BASE_ANDROID_TASK_SCHEDULER_POST_TASK_ANDROID_H_
  6. #include "base/android/jni_weak_ref.h"
  7. #include "base/base_export.h"
  8. #include "base/task/task_traits.h"
  9. namespace base {
  10. // C++ interface for PostTask.java
  11. class BASE_EXPORT PostTaskAndroid {
  12. public:
  13. // Routes tasks posted via the Java PostTask APIs through the C++ PostTask
  14. // APIs. Invoked once the C++ PostTask APIs are fully initialized.
  15. static void SignalNativeSchedulerReady();
  16. // Signals that the C++ PostTask APIs have shutdown. Needed to make unit tests
  17. // that repeatedly create and destroy the scheduler work.
  18. static void SignalNativeSchedulerShutdownForTesting();
  19. static TaskTraits CreateTaskTraits(
  20. JNIEnv* env,
  21. jint priority,
  22. jboolean may_block,
  23. jboolean use_thread_pool,
  24. jbyte extension_id,
  25. const base::android::JavaParamRef<jbyteArray>& extension_data);
  26. // We don't know ahead of time which thread this will run on so it looks up
  27. // the JNI environment and the bindings dynamically (albeit with caching).
  28. static void RunJavaTask(base::android::ScopedJavaGlobalRef<jobject> task);
  29. DISALLOW_COPY_AND_ASSIGN(PostTaskAndroid);
  30. };
  31. } // namespace base
  32. #endif // BASE_ANDROID_TASK_SCHEDULER_POST_TASK_ANDROID_H_