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_SHUTDOWNABLE_H_ | |
6 #define REMOTING_BASE_SHUTDOWNABLE_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/callback.h" | |
10 #include "base/memory/ref_counted.h" | |
11 | |
12 namespace base { | |
13 class SingleThreadTaskRunner; | |
14 } // namespace base | |
15 | |
16 namespace remoting { | |
17 | |
18 // A wrapper implementing two-step shutdown for an object. | |
Sergey Ulanov
2012/07/30 19:46:22
suggest rewording it as "A helper base class that
alexeypa (please no reviews)
2012/07/30 20:41:43
Done.
| |
19 class Shutdownable { | |
Sergey Ulanov
2012/07/30 19:46:22
Maybe call it Stoppable? - it's easier to write an
alexeypa (please no reviews)
2012/07/30 20:41:43
Done.
| |
20 public: | |
21 typedef base::Callback<void(Shutdownable*)> Callback; | |
Sergey Ulanov
2012/07/30 19:46:22
Why not just use base::Closure? If users of that i
alexeypa (please no reviews)
2012/07/30 20:41:43
It was just a way to get |this| and pass a callbac
| |
22 | |
23 // Constructs an object and stores the callback to be posted to |task_runner| | |
24 // once the object has been shutdown completely. | |
25 explicit Shutdownable(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | |
26 const Callback& done); | |
27 virtual ~Shutdownable(); | |
28 | |
29 // Initiates shutdown. It can be called by both the owner of the object and | |
30 // the object itself resulting in the same shutdown sequence. | |
31 void Shutdown(); | |
32 | |
33 protected: | |
34 // Completes shutdown by posting the completion task on the caller's message | |
35 // loop. | |
36 void CompleteShutdown(); | |
37 | |
38 // Derived classes can override this method to implement additional shutdown | |
39 // logic. | |
Sergey Ulanov
2012/07/30 19:46:22
Do we need this default implementation? If a class
alexeypa (please no reviews)
2012/07/30 20:41:43
Done.
| |
40 virtual void DoShutdown(); | |
41 | |
42 enum State { | |
43 kRunning, | |
44 kShutdown, | |
45 kStopped | |
Sergey Ulanov
2012/07/30 19:46:22
it should be either kShuttingDown/kShutdown or kSt
alexeypa (please no reviews)
2012/07/30 20:41:43
Done.
| |
46 }; | |
47 | |
48 State get_shutdownable_state() const { return state_; } | |
Sergey Ulanov
2012/07/30 19:46:22
drop get_, just shutdownable_state()
alexeypa (please no reviews)
2012/07/30 20:41:43
Done.
| |
49 | |
50 private: | |
51 // The target task runner where the shutdown notification will be posted. | |
52 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
53 | |
54 // The shutdown notification callback. | |
55 Callback done_; | |
56 | |
57 State state_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(Shutdownable); | |
60 }; | |
61 | |
62 } // namespace remoting | |
63 | |
64 #endif // REMOTING_BASE_SHUTDOWNABLE_H_ | |
OLD | NEW |