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

Unified Diff: remoting/base/auto_thread.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/auto_thread.cc
diff --git a/remoting/base/auto_thread.cc b/remoting/base/auto_thread.cc
new file mode 100644
index 0000000000000000000000000000000000000000..00d78355653bbe236c231a5ee07aa4645b746762
--- /dev/null
+++ b/remoting/base/auto_thread.cc
@@ -0,0 +1,55 @@
+// 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/auto_thread.h"
+
+#include "base/logging.h"
+#include "base/message_loop.h"
+
+namespace remoting {
+
+AutoThread::AutoThread(const char* name,
+ scoped_refptr<base::SingleThreadTaskRunner> parent)
+ : parent_(parent),
+ thread_(name) {
+}
+
+AutoThread::~AutoThread() {
+ thread_.Stop();
Sergey Ulanov 2012/07/23 22:44:37 Ref-count may go to zero on any thread, but you ca
alexeypa (please no reviews) 2012/07/23 23:44:53 It is partially addressed. AutoThread is destroyed
+}
+
+bool AutoThread::Start() {
+ return thread_.Start();
+}
+
+bool AutoThread::StartWithOptions(const base::Thread::Options& options) {
+ return thread_.StartWithOptions(options);
+}
+
+bool AutoThread::PostDelayedTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) {
+ thread_.message_loop()->PostDelayedTask(from_here, task, delay);
+ return true;
+}
+
+bool AutoThread::PostNonNestableDelayedTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) {
+ thread_.message_loop()->PostNonNestableDelayedTask(from_here, task, delay);
+ return true;
+}
+
+bool AutoThread::RunsTasksOnCurrentThread() const {
+ return MessageLoop::current() == thread_.message_loop();
+}
+
+void AutoThread::OnDestruct() const {
+ // Deletes |this| on the parent's message loop.
+ parent_->DeleteSoon(FROM_HERE, this);
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698