| 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 provides automatic life time management for a message loop. |
| 18 // The message loop is exited (i.e. Run() method exits) when the last reference |
| 19 // to |AutoMessageLoop| is dropped. |AutoMessageLoop| does not control the life |
| 20 // time of the message loop object. |
| 21 class AutoMessageLoop : public base::SingleThreadTaskRunner { |
| 22 public: |
| 23 // |message_loop| must outlive |AutoMessageLoop|. |
| 24 explicit AutoMessageLoop(MessageLoop* message_loop); |
| 25 |
| 26 // SingleThreadTaskRunner implementation |
| 27 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 28 const base::Closure& task, |
| 29 base::TimeDelta delay) OVERRIDE; |
| 30 virtual bool PostNonNestableDelayedTask( |
| 31 const tracked_objects::Location& from_here, |
| 32 const base::Closure& task, |
| 33 base::TimeDelta delay) OVERRIDE; |
| 34 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; |
| 35 |
| 36 protected: |
| 37 // Quits the message loop by posting MessageLoop::QuitClosure. |
| 38 virtual void OnDestruct() const OVERRIDE; |
| 39 |
| 40 private: |
| 41 virtual ~AutoMessageLoop(); |
| 42 |
| 43 friend class base::DeleteHelper<AutoMessageLoop>; |
| 44 |
| 45 MessageLoop* message_loop_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(AutoMessageLoop); |
| 48 }; |
| 49 |
| 50 } // namespace remoting |
| 51 |
| 52 #endif // REMOTING_BASE_AUTO_MESSAGE_LOOP_H_ |
| OLD | NEW |