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

Unified Diff: media/base/audio_output_device_callback_util.h

Issue 1184473002: Add support for the audio-output-device switching IPC mechanism to the renderer lower layers (media… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 | « media/base/BUILD.gn ('k') | media/base/audio_output_device_callback_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_output_device_callback_util.h
diff --git a/media/base/audio_output_device_callback_util.h b/media/base/audio_output_device_callback_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..148f5a4ffeebc1fd56a32ed061f7446ed9a7d7dc
--- /dev/null
+++ b/media/base/audio_output_device_callback_util.h
@@ -0,0 +1,52 @@
+// Copyright (c) 2015 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.
+//
+// Provides an utility class to support invocation of callbacks in the correct
DaleCurtis 2015/06/11 17:58:47 Why not use media::BindToCurrentLoop?
Guido Urdaneta 2015/06/11 20:10:09 Done.
+// thread for the SwitchOutputDevice operation provided by
+// media::AudioRendererSink and other related classes.
+// The rationale for this class is that SwitchOutputDevice operations go
+// through many layers (i.e., from blink to the browser and back), and
+// the request can move throughout multiple threads. It is impossible for
+// the lower layers to know the right thread where the callback should be run.
+// This class provides a convenient way for users to create callbacks that
+// can assume they will be run on the correct thread, and for implementors of
+// SwitchOutputDevice, which can easily invoke the callback without having
+// to worry about threads.
+// Note that the methods of this class can be called on any thread, but they
+// cannot be called concurrently by multiple threads.
+
+#ifndef MEDIA_BASE_AUDIO_OUTPUT_DEVICE_CALLBACK_UTIL_H_
+#define MEDIA_BASE_AUDIO_OUTPUT_DEVICE_CALLBACK_UTIL_H_
+
+#include "base/callback.h"
+#include "base/single_thread_task_runner.h"
+#include "media/audio/audio_output_ipc.h"
+
+namespace media {
+
+typedef base::Callback<void(SwitchOutputDeviceResult)>
+ SwitchOutputDeviceCallback;
+
+class MEDIA_EXPORT SwitchOutputDeviceCallbackRunner {
+ public:
+ SwitchOutputDeviceCallbackRunner(
+ scoped_ptr<SwitchOutputDeviceCallback> callback,
+ const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner);
+
+ ~SwitchOutputDeviceCallbackRunner();
+
+ // Posts the execution of |callback_| to |callback task runner_|, and
+ // relinquishes ownership of both afterwards. |result| is passed as the
+ // argument for |callback_|.
+ // Calling this method a second time has no effect.
+ void Run(SwitchOutputDeviceResult result);
+
+ private:
+ scoped_ptr<SwitchOutputDeviceCallback> callback_;
+ scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_;
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_AUDIO_OUTPUT_DEVICE_CALLBACK_UTIL_H_
« no previous file with comments | « media/base/BUILD.gn ('k') | media/base/audio_output_device_callback_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698