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

Unified Diff: remoting/base/stoppable.h

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
« no previous file with comments | « no previous file | remoting/base/stoppable.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/base/stoppable.h
diff --git a/remoting/base/stoppable.h b/remoting/base/stoppable.h
new file mode 100644
index 0000000000000000000000000000000000000000..4d58a59c521153a77c99d12fea72635547f8b393
--- /dev/null
+++ b/remoting/base/stoppable.h
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef REMOTING_BASE_STOPPABLE_H_
+#define REMOTING_BASE_STOPPABLE_H_
+
+#include "base/basictypes.h"
+#include "base/callback.h"
+#include "base/memory/ref_counted.h"
+
+namespace base {
+class SingleThreadTaskRunner;
+} // namespace base
+
+namespace remoting {
+
+// A helper base class that implements asynchronous shutdown on a specific
+// thread.
+class Stoppable {
+ public:
+ // Constructs an object and stores the callback to be posted to |task_runner|
+ // once the object has been shutdown completely.
+ explicit Stoppable(scoped_refptr<base::SingleThreadTaskRunner> task_runner,
Wez 2012/08/18 01:08:29 This doesn't need to be explicit, does it?
alexeypa (please no reviews) 2012/08/18 01:25:35 Yes, you are right. It should not be explicit. I'l
+ const base::Closure& stopped_callback);
+ virtual ~Stoppable();
+
+ // Initiates shutdown. It can be called by both the owner of the object and
+ // the object itself resulting in the same shutdown sequence.
+ void Stop();
+
+ protected:
+ // Called by derived classes to notify about shutdown completion. Posts
+ // the completion task on |task_runner_| message loop.
+ void CompleteStopping();
+
+ // Derived classes have to override this method to implement the shutdown
+ // logic.
+ virtual void DoStop() = 0;
+
+ enum State {
+ kRunning,
+ kStopping,
+ kStopped
+ };
+
+ State stoppable_state() const { return state_; }
+
+ private:
+ State state_;
+
+ // A callback to be called when shutdown is completed.
+ base::Closure stopped_callback_;
+
+ // The target task runner where the shutdown notification will be posted.
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(Stoppable);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_BASE_STOPPABLE_H_
« no previous file with comments | « no previous file | remoting/base/stoppable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698