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 #include "remoting/base/stoppable.h" | 5 #include "remoting/base/stoppable.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 | 9 |
10 namespace remoting { | 10 namespace remoting { |
11 | 11 |
12 Stoppable::Stoppable( | 12 Stoppable::Stoppable( |
13 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 13 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
14 const base::Closure& stopped_callback) | 14 const base::Closure& stopped_callback) |
15 : state_(kRunning), | 15 : state_(kRunning), |
16 stopped_callback_(stopped_callback), | 16 stopped_callback_(stopped_callback), |
17 task_runner_(task_runner) { | 17 task_runner_(task_runner) { |
18 } | 18 } |
19 | 19 |
20 Stoppable::~Stoppable() { | 20 Stoppable::~Stoppable() { |
21 DCHECK_EQ(state_, kStopped); | 21 CHECK_EQ(state_, kStopped); |
22 } | 22 } |
23 | 23 |
24 void Stoppable::Stop() { | 24 void Stoppable::Stop() { |
25 DCHECK(task_runner_->BelongsToCurrentThread()); | 25 DCHECK(task_runner_->BelongsToCurrentThread()); |
26 | 26 |
27 if (state_ == kRunning) { | 27 if (state_ == kRunning) { |
28 state_ = kStopping; | 28 state_ = kStopping; |
29 } | 29 } |
30 | 30 |
31 // DoStop() can be called multiple times. | 31 // DoStop() can be called multiple times. |
32 DoStop(); | 32 DoStop(); |
33 } | 33 } |
34 | 34 |
35 void Stoppable::CompleteStopping() { | 35 void Stoppable::CompleteStopping() { |
36 DCHECK(task_runner_->BelongsToCurrentThread()); | 36 DCHECK(task_runner_->BelongsToCurrentThread()); |
37 DCHECK_EQ(state_, kStopping); | 37 DCHECK_EQ(state_, kStopping); |
38 | 38 |
39 state_ = kStopped; | 39 state_ = kStopped; |
40 task_runner_->PostTask(FROM_HERE, stopped_callback_); | 40 task_runner_->PostTask(FROM_HERE, stopped_callback_); |
41 } | 41 } |
42 | 42 |
43 } // namespace remoting | 43 } // namespace remoting |
OLD | NEW |