Index: remoting/base/auto_message_loop.h |
diff --git a/remoting/base/auto_message_loop.h b/remoting/base/auto_message_loop.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bf7cc1f9a2e56ab36cd7aba91ce81bded81d2068 |
--- /dev/null |
+++ b/remoting/base/auto_message_loop.h |
@@ -0,0 +1,53 @@ |
+// Copyright (c) 2012 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. |
+ |
+#ifndef REMOTING_BASE_AUTO_MESSAGE_LOOP_H_ |
+#define REMOTING_BASE_AUTO_MESSAGE_LOOP_H_ |
+ |
+#include "base/basictypes.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/message_loop.h" |
+#include "base/single_thread_task_runner.h" |
+ |
+class MessageLoop; |
+ |
+namespace remoting { |
+ |
+// This class along with |scoped_refptr| provides automatic life time management |
+// for a message loop. The message loop is stopped when the last |scoped_refptr| |
+// reference to |AutoMessageLoop| is deleted. |
+// |
+// Unlike |AutoThread| this class does not manage its own life time. It expects |
+// that |this| to be deleted sometime after Run() method is exited. |
+class AutoMessageLoop : public base::SingleThreadTaskRunner { |
+ public: |
+ explicit AutoMessageLoop(MessageLoop::Type type); |
+ virtual ~AutoMessageLoop(); |
+ |
+ // A wapper around the corresponding method of |MessageLoop|. |
+ void Run(); |
+ |
+ // SingleThreadTaskRunner implementation |
+ virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
+ const base::Closure& task, |
+ base::TimeDelta delay) OVERRIDE; |
+ virtual bool PostNonNestableDelayedTask( |
+ const tracked_objects::Location& from_here, |
+ const base::Closure& task, |
+ base::TimeDelta delay) OVERRIDE; |
+ virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
+ |
+ protected: |
+ // Quits the message loop by posting MessageLoop::QuitClosure. |
+ virtual void OnDestruct() const OVERRIDE; |
+ |
+ private: |
+ scoped_ptr<MessageLoop> message_loop_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AutoMessageLoop); |
+}; |
+ |
+} // namespace remoting |
+ |
+#endif // REMOTING_BASE_AUTO_MESSAGE_LOOP_H_ |