diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 21:06:26 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-31 21:06:26 +0000 |
commit | 18c1dbb1e68b980fd62a817764fc800a8f6ced42 (patch) | |
tree | 1094465c98ba9ab3835e3fa92ff23930afb944cd /remoting/base/stoppable.cc | |
parent | f53465f9cdb624155f8e5441396da9c8c427c1c1 (diff) | |
download | chromium_src-18c1dbb1e68b980fd62a817764fc800a8f6ced42.zip chromium_src-18c1dbb1e68b980fd62a817764fc800a8f6ced42.tar.gz chromium_src-18c1dbb1e68b980fd62a817764fc800a8f6ced42.tar.bz2 |
Introducing remoting::Stoppable helper base class implementing asynchronous shutdown on a specific thread.
Review URL: https://chromiumcodereview.appspot.com/10796099
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base/stoppable.cc')
-rw-r--r-- | remoting/base/stoppable.cc | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/remoting/base/stoppable.cc b/remoting/base/stoppable.cc new file mode 100644 index 0000000..88b3c95 --- /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 |