Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1776)

Side by Side Diff: mojo/edk/platform/message_loop.h

Issue 1469193002: EDK: Add a mojo::platform::MessageLoop abstraction. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/platform/BUILD.gn ('k') | mojo/edk/platform/test_message_loop.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 "message loops", which are used within
6 // the EDK itself.
7
8 #ifndef MOJO_EDK_PLATFORM_MESSAGE_LOOP_H_
9 #define MOJO_EDK_PLATFORM_MESSAGE_LOOP_H_
10
11 #include "mojo/edk/util/ref_ptr.h"
12 #include "mojo/public/cpp/system/macros.h"
13
14 namespace mojo {
15 namespace platform {
16
17 class TaskRunner;
18
19 // Interface for "message loops", which receives and executes tasks. In general,
20 // a |MessageLoop| need not be thread-safe: except as otherwise noted, its
21 // methods may only be called on the thread it was created on (the |MessageLoop|
22 // is said to "belong to" that thread).
23 //
24 // In general, the result of running a |MessageLoop| "inside" a |MessageLoop|
25 // (whether the same one -- the classic "nested message loop" case -- or a
26 // different one) is implementation-defined.
27 class MessageLoop {
28 public:
29 virtual ~MessageLoop() {}
30
31 // Runs the message loop until it is told to quit (via |QuitWhenIdle()|).
32 virtual void Run() = 0;
33
34 // Runs the message loop until there are no more tasks available to execute
35 // immediately (i.e., not including delayed tasks).
36 virtual void RunUntilIdle() = 0;
37
38 // Quits the message loop when there are no more tasks available to execute
39 // immediately. (Note that this includes "future" tasks, i.e., those that are
40 // posted as a result of executing other tasks, so this may never quit.
41 // However, it does not include delayed tasks.)
42 // TODO(vtl): Do we also want a |QuitNow()|?
43 virtual void QuitWhenIdle() = 0;
44
45 // Gets the |TaskRunner| for this message loop, which can be used to post
46 // tasks to it. For a given |MessageLoop| instance, this will always return a
47 // reference to the same |TaskRunner| (and different |MessageLoop| instances
48 // have different |TaskRunner|s). This may be called from any thread (and
49 // returned |TaskRunner| is also thread-safe).
50 //
51 // Note: The returned |TaskRunner| should only claim to run tasks on the
52 // thread which this message loop belongs to.
53 virtual const mojo::util::RefPtr<TaskRunner>& GetTaskRunner() const = 0;
54
55 // Returns true if this message loop belongs to the current thread (i.e., was
56 // created on and executes tasks on this thread) *and* if it is currently
57 // running (i.e., is called from within a task executed "under" |Run()| or
58 // |RunUntilIdle()|). This may be called from any thread.
59 //
60 // If message loops are nested on the current thread, this must return true
61 // for the "innermost" message loop. The result for "outer" message loops is
62 // implementation-defined.
63 virtual bool IsRunningOnCurrentThread() const = 0;
64
65 protected:
66 MessageLoop() {}
67
68 private:
69 MOJO_DISALLOW_COPY_AND_ASSIGN(MessageLoop);
70 };
71
72 } // namespace platform
73 } // namespace mojo
74
75 #endif // MOJO_EDK_PLATFORM_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « mojo/edk/platform/BUILD.gn ('k') | mojo/edk/platform/test_message_loop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698