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 #include "remoting/base/shutdownable.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop.h" |
| 10 #include "base/single_thread_task_runner.h" |
| 11 |
| 12 namespace remoting { |
| 13 |
| 14 Shutdownable::Shutdownable( |
| 15 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 16 const Callback& done) |
| 17 : task_runner_(task_runner), |
| 18 done_(done), |
| 19 state_(kRunning) { |
| 20 } |
| 21 |
| 22 Shutdownable::~Shutdownable() { |
| 23 DCHECK_EQ(state_, kStopped); |
| 24 } |
| 25 |
| 26 void Shutdownable::Shutdown() { |
| 27 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 28 |
| 29 if (state_ == kRunning) { |
| 30 state_ = kShutdown; |
| 31 DoShutdown(); |
| 32 } |
| 33 } |
| 34 |
| 35 void Shutdownable::CompleteShutdown() { |
| 36 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 37 DCHECK_EQ(state_, kShutdown); |
| 38 |
| 39 state_ = kStopped; |
| 40 task_runner_->PostTask(FROM_HERE, base::Bind(done_, this)); |
| 41 } |
| 42 |
| 43 void Shutdownable::DoShutdown() { |
| 44 CompleteShutdown(); |
| 45 } |
| 46 |
| 47 } // namespace remoting |
OLD | NEW |