OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef REMOTING_BASE_AUTO_MESSAGE_LOOP_H_ |
| 6 #define REMOTING_BASE_AUTO_MESSAGE_LOOP_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 12 |
| 13 class MessageLoop; |
| 14 |
| 15 namespace remoting { |
| 16 |
| 17 // This class along with |scoped_refptr| provides automatic life time management |
| 18 // for a message loop. The message loop is stopped when the last |scoped_refptr| |
| 19 // reference to |AutoMessageLoop| is deleted. |
| 20 // |
| 21 // Unlike |AutoThread| this class does not manage its own life time. It expects |
| 22 // that |this| to be deleted sometime after Run() method is exited. |
| 23 class AutoMessageLoop : public base::SingleThreadTaskRunner { |
| 24 public: |
| 25 explicit AutoMessageLoop(MessageLoop::Type type); |
| 26 virtual ~AutoMessageLoop(); |
| 27 |
| 28 // A wapper around the corresponding method of |MessageLoop|. |
| 29 void Run(); |
| 30 |
| 31 // SingleThreadTaskRunner implementation |
| 32 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 33 const base::Closure& task, |
| 34 base::TimeDelta delay) OVERRIDE; |
| 35 virtual bool PostNonNestableDelayedTask( |
| 36 const tracked_objects::Location& from_here, |
| 37 const base::Closure& task, |
| 38 base::TimeDelta delay) OVERRIDE; |
| 39 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
| 40 |
| 41 protected: |
| 42 // Quits the message loop by posting MessageLoop::QuitClosure. |
| 43 virtual void OnDestruct() const OVERRIDE; |
| 44 |
| 45 private: |
| 46 scoped_ptr<MessageLoop> message_loop_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(AutoMessageLoop); |
| 49 }; |
| 50 |
| 51 } // namespace remoting |
| 52 |
| 53 #endif // REMOTING_BASE_AUTO_MESSAGE_LOOP_H_ |
OLD | NEW |