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

Unified Diff: remoting/base/stoppable.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: Fixing case of the include file name. 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/stoppable.cc
diff --git a/remoting/base/stoppable.cc b/remoting/base/stoppable.cc
new file mode 100644
index 0000000000000000000000000000000000000000..88b3c95ef953cdf9fbe840ab4db168954d745a40
--- /dev/null
+++ b/remoting/base/stoppable.cc
@@ -0,0 +1,41 @@
+// 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/stoppable.h"
+
+#include "base/message_loop.h"
+#include "base/single_thread_task_runner.h"
+
+namespace remoting {
+
+Stoppable::Stoppable(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ const base::Closure& stopped_callback)
+ : state_(kRunning),
+ stopped_callback_(stopped_callback),
+ task_runner_(task_runner) {
+}
+
+Stoppable::~Stoppable() {
+ DCHECK_EQ(state_, kStopped);
+}
+
+void Stoppable::Stop() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ if (state_ == kRunning) {
+ state_ = kStopping;
+ DoStop();
+ }
+}
+
+void Stoppable::CompleteStopping() {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+ DCHECK_EQ(state_, kStopping);
+
+ state_ = kStopped;
+ task_runner_->PostTask(FROM_HERE, stopped_callback_);
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698