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