OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 | |
5 // This file provides an interface for "task runners", which are used within the | |
6 // EDK itself. | |
7 | |
8 #ifndef MOJO_EDK_EMBEDDER_PLATFORM_TASK_RUNNER_H_ | |
9 #define MOJO_EDK_EMBEDDER_PLATFORM_TASK_RUNNER_H_ | |
10 | |
11 #include "base/callback_forward.h" | |
12 #include "mojo/edk/util/ref_counted.h" | |
13 #include "mojo/public/cpp/system/macros.h" | |
14 | |
15 namespace mojo { | |
16 namespace embedder { | |
17 | |
18 // Interface for "task runners", which can be used to schedule tasks to be run | |
19 // asynchronously (possibly on a different thread). Implementations must be | |
20 // thread-safe. | |
21 class PlatformTaskRunner | |
22 : public util::RefCountedThreadSafe<PlatformTaskRunner> { | |
23 public: | |
24 virtual ~PlatformTaskRunner() {} | |
25 | |
26 // Posts a task to this task runner (i.e., schedule the task). The task must | |
27 // be run (insofar as this can be guaranteed). (This must not run the task | |
28 // synchronously.) | |
29 // TODO(vtl): Replace the |base::Closure| with |std::function<void()>|. | |
30 virtual void PostTask(const base::Closure& task) = 0; | |
31 | |
32 // Returns true if this task runner may run tasks on the current thread, false | |
33 // otherwise (e.g., if this task runner only runs tasks on a different | |
34 // thread). | |
35 virtual bool RunsTasksOnCurrentThread() const = 0; | |
36 | |
37 protected: | |
38 PlatformTaskRunner() {} | |
39 | |
40 private: | |
41 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformTaskRunner); | |
42 }; | |
43 | |
44 } // namespace embedder | |
45 } // namespace mojo | |
46 | |
47 #endif // MOJO_EDK_EMBEDDER_PLATFORM_TASK_RUNNER_H_ | |
OLD | NEW |