Chromium Code Reviews| 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_THREAD_H_ | |
| 6 #define REMOTING_BASE_AUTO_THREAD_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/memory/ref_counted.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/threading/thread.h" | |
| 12 | |
| 13 class MessageLoop; | |
| 14 | |
| 15 namespace remoting { | |
| 16 | |
| 17 // This class provides automatic life time management for a thread running | |
| 18 // a message loop. The thread is stopped when the last reference to |AutoThread| | |
| 19 // is dropped. |AutoThread| is deleted from a a task running on the parent | |
| 20 // message loop. | |
| 21 class AutoThread : public base::SingleThreadTaskRunner { | |
| 22 public: | |
| 23 AutoThread( | |
| 24 const char* name, | |
| 25 scoped_refptr<base::SingleThreadTaskRunner> parent); | |
| 
 
Wez
2012/08/24 21:30:49
I don't really see the point of this class; why ca
 
alexeypa (please no reviews)
2012/08/27 21:19:40
MessageLoop and Thread should be stopped different
 
 | |
| 26 | |
| 27 // A backdoor to the enclosed message loop for the cases when an external | |
| 28 // interface does not take |base::SingleThreadTaskRunner|. | |
| 29 MessageLoop* message_loop() { return thread_.message_loop(); } | |
| 30 | |
| 31 // Wrappers around the corresponding methods of |base::Thread|. | |
| 32 bool Start(); | |
| 33 bool StartWithOptions(const base::Thread::Options& options); | |
| 34 | |
| 35 // SingleThreadTaskRunner implementation | |
| 36 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | |
| 37 const base::Closure& task, | |
| 38 base::TimeDelta delay) OVERRIDE; | |
| 39 virtual bool PostNonNestableDelayedTask( | |
| 40 const tracked_objects::Location& from_here, | |
| 41 const base::Closure& task, | |
| 42 base::TimeDelta delay) OVERRIDE; | |
| 43 virtual bool RunsTasksOnCurrentThread() const OVERRIDE; | |
| 44 | |
| 45 protected: | |
| 46 // Stops the thread and deletes itself. | |
| 47 virtual void OnDestruct() const OVERRIDE; | |
| 48 | |
| 49 private: | |
| 50 virtual ~AutoThread(); | |
| 51 | |
| 52 friend class base::DeleteHelper<AutoThread>; | |
| 53 | |
| 54 // The parent task runner that will be used to destroy |this|. | |
| 55 scoped_refptr<base::SingleThreadTaskRunner> parent_; | |
| 56 | |
| 57 // The wrapped thread object. | |
| 58 base::Thread thread_; | |
| 59 | |
| 60 DISALLOW_COPY_AND_ASSIGN(AutoThread); | |
| 61 }; | |
| 62 | |
| 63 } // namespace remoting | |
| 64 | |
| 65 #endif // REMOTING_BASE_AUTO_THREAD_H_ | |
| OLD | NEW |