diff options
author | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 20:50:05 +0000 |
---|---|---|
committer | alexeypa@chromium.org <alexeypa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-07 20:50:05 +0000 |
commit | 435708d53a29117fe235db07991d1b0f76316405 (patch) | |
tree | f3f0a125eac241c7f164e07470c734e63041e983 /remoting/base | |
parent | 74ebfb1e113e26bb16d79ade8918d5f86035f278 (diff) | |
download | chromium_src-435708d53a29117fe235db07991d1b0f76316405.zip chromium_src-435708d53a29117fe235db07991d1b0f76316405.tar.gz chromium_src-435708d53a29117fe235db07991d1b0f76316405.tar.bz2 |
Use a weak pointer to post service control events and session change notifications.
BUG=241136
Review URL: https://chromiumcodereview.appspot.com/16143004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204918 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/stoppable.cc | 43 | ||||
-rw-r--r-- | remoting/base/stoppable.h | 63 |
2 files changed, 0 insertions, 106 deletions
diff --git a/remoting/base/stoppable.cc b/remoting/base/stoppable.cc deleted file mode 100644 index 99acba4..0000000 --- a/remoting/base/stoppable.cc +++ /dev/null @@ -1,43 +0,0 @@ -// 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() { - CHECK_EQ(state_, kStopped); -} - -void Stoppable::Stop() { - DCHECK(task_runner_->BelongsToCurrentThread()); - - if (state_ == kRunning) { - state_ = kStopping; - } - - // DoStop() can be called multiple times. - DoStop(); -} - -void Stoppable::CompleteStopping() { - DCHECK(task_runner_->BelongsToCurrentThread()); - DCHECK_EQ(state_, kStopping); - - state_ = kStopped; - task_runner_->PostTask(FROM_HERE, stopped_callback_); -} - -} // namespace remoting diff --git a/remoting/base/stoppable.h b/remoting/base/stoppable.h deleted file mode 100644 index dddfcdae..0000000 --- a/remoting/base/stoppable.h +++ /dev/null @@ -1,63 +0,0 @@ -// 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. - Stoppable(scoped_refptr<base::SingleThreadTaskRunner> task_runner, - 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_ |