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

Unified Diff: remoting/base/auto_message_loop.h

Issue 10796099: Introducing remoting::Stoppable helper base class implementing asynchronous shutdown on a specific t (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months 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 | « no previous file | remoting/base/auto_message_loop.cc » ('j') | remoting/base/auto_thread.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« no previous file with comments | « no previous file | remoting/base/auto_message_loop.cc » ('j') | remoting/base/auto_thread.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698