• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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/task/thread_pool/thread_pool_instance.h"
6 
7 // Must come after all headers that specialize FromJniType() / ToJniType().
8 #include "base/test/test_support_jni_headers/ThreadPoolTestHelpers_jni.h"
9 
10 namespace base {
11 
12 // ThreadPoolTestHelpers is a friend of ThreadPoolInstance which grants access
13 // to SetCanRun().
14 class ThreadPoolTestHelpers {
15  public:
16   // Enables/disables an execution fence that prevents tasks from running.
17   static void BeginFenceForTesting();
18   static void EndFenceForTesting();
19 };
20 
21 // static
BeginFenceForTesting()22 void ThreadPoolTestHelpers::BeginFenceForTesting() {
23   ThreadPoolInstance::Get()->BeginFence();
24 }
25 
26 // static
EndFenceForTesting()27 void ThreadPoolTestHelpers::EndFenceForTesting() {
28   ThreadPoolInstance::Get()->EndFence();
29 }
30 
31 }  // namespace base
32 
JNI_ThreadPoolTestHelpers_EnableThreadPoolExecutionForTesting(JNIEnv * env)33 void JNI_ThreadPoolTestHelpers_EnableThreadPoolExecutionForTesting(
34     JNIEnv* env) {
35   base::ThreadPoolTestHelpers::EndFenceForTesting();
36 }
37 
JNI_ThreadPoolTestHelpers_DisableThreadPoolExecutionForTesting(JNIEnv * env)38 void JNI_ThreadPoolTestHelpers_DisableThreadPoolExecutionForTesting(
39     JNIEnv* env) {
40   base::ThreadPoolTestHelpers::BeginFenceForTesting();
41 }