task_runner_android.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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_TASK_RUNNER_ANDROID_H_
  5. #define BASE_ANDROID_TASK_SCHEDULER_TASK_RUNNER_ANDROID_H_
  6. #include "base/android/jni_weak_ref.h"
  7. #include "base/single_thread_task_runner.h"
  8. namespace base {
  9. // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.base.task
  10. enum class TaskRunnerType { BASE, SEQUENCED, SINGLE_THREAD };
  11. // Native implementation backing TaskRunnerImpl.java which posts java tasks onto
  12. // a C++ TaskRunner.
  13. class TaskRunnerAndroid {
  14. public:
  15. explicit TaskRunnerAndroid(scoped_refptr<TaskRunner> task_runner,
  16. TaskRunnerType type);
  17. ~TaskRunnerAndroid();
  18. void Destroy(JNIEnv* env);
  19. void PostDelayedTask(JNIEnv* env,
  20. const base::android::JavaRef<jobject>& task,
  21. jlong delay);
  22. bool BelongsToCurrentThread(JNIEnv* env);
  23. private:
  24. const scoped_refptr<TaskRunner> task_runner_;
  25. const TaskRunnerType type_;
  26. DISALLOW_COPY_AND_ASSIGN(TaskRunnerAndroid);
  27. };
  28. } // namespace base
  29. #endif // BASE_ANDROID_TASK_SCHEDULER_TASK_RUNNER_ANDROID_H_