| Index: remoting/base/shutdownable.cc
|
| diff --git a/remoting/base/shutdownable.cc b/remoting/base/shutdownable.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ca9cb7c6f0cabe06d9294ae682ba68b894f1b506
|
| --- /dev/null
|
| +++ b/remoting/base/shutdownable.cc
|
| @@ -0,0 +1,44 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "remoting/base/shutdownable.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| +#include "base/message_loop.h"
|
| +#include "base/single_thread_task_runner.h"
|
| +
|
| +namespace remoting {
|
| +
|
| +Shutdownable::Shutdownable(
|
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner,
|
| + const Callback& done)
|
| + : task_runner_(task_runner),
|
| + done_(done),
|
| + state_(kRunning) {
|
| +}
|
| +
|
| +Shutdownable::~Shutdownable() {
|
| + DCHECK_EQ(state_, kStopped);
|
| +}
|
| +
|
| +void Shutdownable::Shutdown() {
|
| + if (state_ == kRunning) {
|
| + state_ = kShutdown;
|
| + DoShutdown();
|
| + }
|
| +}
|
| +
|
| +void Shutdownable::CompleteShutdown() {
|
| + DCHECK_EQ(state_, kShutdown);
|
| +
|
| + state_ = kStopped;
|
| + task_runner_->PostTask(FROM_HERE, base::Bind(done_, this));
|
| +}
|
| +
|
| +void Shutdownable::DoShutdown() {
|
| + CompleteShutdown();
|
| +}
|
| +
|
| +} // namespace remoting
|
|
|