Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Unified Diff: remoting/base/shutdownable.cc

Issue 10796099: Introducing remoting::Stoppable helper base class implementing asynchronous shutdown on a specific t (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698