Chromium Code Reviews| Index: media/audio/scoped_task_runner_observer.h |
| diff --git a/media/audio/scoped_task_runner_observer.h b/media/audio/scoped_task_runner_observer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ce9adf96713a5d2235a0786d4d73c9502e48d7c4 |
| --- /dev/null |
| +++ b/media/audio/scoped_task_runner_observer.h |
| @@ -0,0 +1,52 @@ |
| +// 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 MEDIA_AUDIO_SCOPED_TASK_RUNNER_OBSERVER_H_ |
| +#define MEDIA_AUDIO_SCOPED_TASK_RUNNER_OBSERVER_H_ |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/message_loop/message_loop.h" |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +class WaitableEvent; |
| +} |
| + |
| +namespace media { |
| + |
| +// A common base class for AudioOutputDevice and AudioInputDevice that manages |
| +// a task runner and monitors it for destruction. If the object goes out of |
| +// scope before the task runner, the object will automatically remove itself |
| +// from the task runner's list of destruction observers. |
| +// NOTE: The class that inherits from this class must implement the |
| +// WillDestroyCurrentMessageLoop virtual method from DestructionObserver. |
| +class ScopedTaskRunnerObserver |
|
DaleCurtis
2013/11/08 19:32:14
Didn't know we had this, probably a few places tha
|
| + : public base::MessageLoop::DestructionObserver { |
| + public: |
| + explicit ScopedTaskRunnerObserver( |
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner); |
|
DaleCurtis
2013/11/08 19:32:14
Just base::TaskRunner on this one no?
|
| + |
| + protected: |
| + virtual ~ScopedTaskRunnerObserver(); |
| + |
| + // Accessor to the loop that's used by the derived class. |
| + const scoped_refptr<base::SingleThreadTaskRunner>& task_runner() { |
| + return task_runner_; |
| + } |
| + |
| + private: |
| + // Call to add or remove ourselves from the list of destruction observers for |
| + // the message loop. |
| + void ObserveLoopDestruction(bool enable, base::WaitableEvent* done); |
| + |
| + // A pointer to the task runner. In case it gets destroyed before this object |
| + // goes out of scope, PostTask() etc will fail but not crash. |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ScopedTaskRunnerObserver); |
| +}; |
| + |
| +} // namespace media. |
| + |
| +#endif // MEDIA_AUDIO_SCOPED_TASK_RUNNER_OBSERVER_H_ |