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

Unified 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, 1 month 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/platform/message_loop.h
diff --git a/mojo/edk/platform/message_loop.h b/mojo/edk/platform/message_loop.h
new file mode 100644
index 0000000000000000000000000000000000000000..ad501776cd50f3e586867281b29110409afc63f0
--- /dev/null
+++ b/mojo/edk/platform/message_loop.h
@@ -0,0 +1,75 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file provides an interface for "message loops", which are used within
+// the EDK itself.
+
+#ifndef MOJO_EDK_PLATFORM_MESSAGE_LOOP_H_
+#define MOJO_EDK_PLATFORM_MESSAGE_LOOP_H_
+
+#include "mojo/edk/util/ref_ptr.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+namespace platform {
+
+class TaskRunner;
+
+// Interface for "message loops", which receives and executes tasks. In general,
+// a |MessageLoop| need not be thread-safe: except as otherwise noted, its
+// methods may only be called on the thread it was created on (the |MessageLoop|
+// is said to "belong to" that thread).
+//
+// In general, the result of running a |MessageLoop| "inside" a |MessageLoop|
+// (whether the same one -- the classic "nested message loop" case -- or a
+// different one) is implementation-defined.
+class MessageLoop {
+ public:
+ virtual ~MessageLoop() {}
+
+ // Runs the message loop until it is told to quit (via |QuitWhenIdle()|).
+ virtual void Run() = 0;
+
+ // Runs the message loop until there are no more tasks available to execute
+ // immediately (i.e., not including delayed tasks).
+ virtual void RunUntilIdle() = 0;
+
+ // Quits the message loop when there are no more tasks available to execute
+ // immediately. (Note that this includes "future" tasks, i.e., those that are
+ // posted as a result of executing other tasks, so this may never quit.
+ // However, it does not include delayed tasks.)
+ // TODO(vtl): Do we also want a |QuitNow()|?
+ virtual void QuitWhenIdle() = 0;
+
+ // Gets the |TaskRunner| for this message loop, which can be used to post
+ // tasks to it. For a given |MessageLoop| instance, this will always return a
+ // reference to the same |TaskRunner| (and different |MessageLoop| instances
+ // have different |TaskRunner|s). This may be called from any thread (and
+ // returned |TaskRunner| is also thread-safe).
+ //
+ // Note: The returned |TaskRunner| should only claim to run tasks on the
+ // thread which this message loop belongs to.
+ virtual const mojo::util::RefPtr<TaskRunner>& GetTaskRunner() const = 0;
+
+ // Returns true if this message loop belongs to the current thread (i.e., was
+ // created on and executes tasks on this thread) *and* if it is currently
+ // running (i.e., is called from within a task executed "under" |Run()| or
+ // |RunUntilIdle()|). This may be called from any thread.
+ //
+ // If message loops are nested on the current thread, this must return true
+ // for the "innermost" message loop. The result for "outer" message loops is
+ // implementation-defined.
+ virtual bool IsRunningOnCurrentThread() const = 0;
+
+ protected:
+ MessageLoop() {}
+
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(MessageLoop);
+};
+
+} // namespace platform
+} // namespace mojo
+
+#endif // MOJO_EDK_PLATFORM_MESSAGE_LOOP_H_
« 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