Index: remoting/base/shutdownable.cc |
diff --git a/remoting/base/shutdownable.cc b/remoting/base/shutdownable.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..14babbb2c8b23ad56386a3e220bc698cfb29186e |
--- /dev/null |
+++ b/remoting/base/shutdownable.cc |
@@ -0,0 +1,47 @@ |
+// 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() { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ |
+ if (state_ == kRunning) { |
+ state_ = kShutdown; |
+ DoShutdown(); |
+ } |
+} |
+ |
+void Shutdownable::CompleteShutdown() { |
+ DCHECK(task_runner_->BelongsToCurrentThread()); |
+ DCHECK_EQ(state_, kShutdown); |
+ |
+ state_ = kStopped; |
+ task_runner_->PostTask(FROM_HERE, base::Bind(done_, this)); |
+} |
+ |
+void Shutdownable::DoShutdown() { |
+ CompleteShutdown(); |
+} |
+ |
+} // namespace remoting |