| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_BASE_STOPPABLE_H_ | 5 #ifndef REMOTING_BASE_STOPPABLE_H_ |
| 6 #define REMOTING_BASE_STOPPABLE_H_ | 6 #define REMOTING_BASE_STOPPABLE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 | 11 |
| 12 namespace base { | 12 namespace base { |
| 13 class SingleThreadTaskRunner; | 13 class SingleThreadTaskRunner; |
| 14 } // namespace base | 14 } // namespace base |
| 15 | 15 |
| 16 namespace remoting { | 16 namespace remoting { |
| 17 | 17 |
| 18 // A helper base class that implements asynchronous shutdown on a specific | 18 // A helper base class that implements asynchronous shutdown on a specific |
| 19 // thread. | 19 // thread. |
| 20 class Stoppable { | 20 class Stoppable { |
| 21 public: | 21 public: |
| 22 // Constructs an object and stores the callback to be posted to |task_runner| | 22 // Constructs an object and stores the callback to be posted to |task_runner| |
| 23 // once the object has been shutdown completely. | 23 // once the object has been shutdown completely. |
| 24 explicit Stoppable(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 24 Stoppable(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 25 const base::Closure& stopped_callback); | 25 const base::Closure& stopped_callback); |
| 26 virtual ~Stoppable(); | 26 virtual ~Stoppable(); |
| 27 | 27 |
| 28 // Initiates shutdown. It can be called by both the owner of the object and | 28 // Initiates shutdown. It can be called by both the owner of the object and |
| 29 // the object itself resulting in the same shutdown sequence. | 29 // the object itself resulting in the same shutdown sequence. |
| 30 void Stop(); | 30 void Stop(); |
| 31 | 31 |
| 32 protected: | 32 protected: |
| 33 // Called by derived classes to notify about shutdown completion. Posts | 33 // Called by derived classes to notify about shutdown completion. Posts |
| 34 // the completion task on |task_runner_| message loop. | 34 // the completion task on |task_runner_| message loop. |
| 35 void CompleteStopping(); | 35 void CompleteStopping(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 | 54 |
| 55 // The target task runner where the shutdown notification will be posted. | 55 // The target task runner where the shutdown notification will be posted. |
| 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(Stoppable); | 58 DISALLOW_COPY_AND_ASSIGN(Stoppable); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 } // namespace remoting | 61 } // namespace remoting |
| 62 | 62 |
| 63 #endif // REMOTING_BASE_STOPPABLE_H_ | 63 #endif // REMOTING_BASE_STOPPABLE_H_ |
| OLD | NEW |