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 package org.chromium.base.task; 6 7 /** 8 * The Java equivalent of base::TaskExecutor, which can execute Tasks with a specific TaskTraits 9 * id. To handle tasks posted via the PostTask API, the TaskExecutor should be registered by 10 * calling {@link PostTask.registerTaskExecutor}. 11 */ 12 public interface TaskExecutor { 13 /** 14 * @param traits The TaskTraits that describe the desired TaskRunner. 15 * @param task The task to be run with the specified traits. 16 * @param delay The delay in milliseconds before the task can be run. 17 */ postDelayedTask(@askTraits int traits, Runnable task, long delay)18 public void postDelayedTask(@TaskTraits int traits, Runnable task, long delay); 19 20 /** 21 * @param traits The TaskTraits that describe the desired TaskRunner. 22 * @return The TaskRunner for the specified TaskTraits. 23 */ createTaskRunner(@askTraits int traits)24 public TaskRunner createTaskRunner(@TaskTraits int traits); 25 26 /** 27 * @param traits The TaskTraits that describe the desired TaskRunner. 28 * @return The TaskRunner for the specified TaskTraits. 29 */ createSequencedTaskRunner(@askTraits int traits)30 public SequencedTaskRunner createSequencedTaskRunner(@TaskTraits int traits); 31 32 /** 33 * @param traits The TaskTraits that describe the desired TaskRunner. 34 * @return The TaskRunner for the specified TaskTraits. 35 */ createSingleThreadTaskRunner(@askTraits int traits)36 public SingleThreadTaskRunner createSingleThreadTaskRunner(@TaskTraits int traits); 37 38 /** 39 * @return true iff the executor for these traits is backed by a SingleThreadTaskRunner 40 * associated with the current thread. 41 */ canRunTaskImmediately(@askTraits int traits)42 public boolean canRunTaskImmediately(@TaskTraits int traits); 43 } 44