Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 // | |
| 5 // 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.
| |
| 6 // thread for the SwitchOutputDevice operation provided by | |
| 7 // media::AudioRendererSink and other related classes. | |
| 8 // The rationale for this class is that SwitchOutputDevice operations go | |
| 9 // through many layers (i.e., from blink to the browser and back), and | |
| 10 // the request can move throughout multiple threads. It is impossible for | |
| 11 // the lower layers to know the right thread where the callback should be run. | |
| 12 // This class provides a convenient way for users to create callbacks that | |
| 13 // can assume they will be run on the correct thread, and for implementors of | |
| 14 // SwitchOutputDevice, which can easily invoke the callback without having | |
| 15 // to worry about threads. | |
| 16 // Note that the methods of this class can be called on any thread, but they | |
| 17 // cannot be called concurrently by multiple threads. | |
| 18 | |
| 19 #ifndef MEDIA_BASE_AUDIO_OUTPUT_DEVICE_CALLBACK_UTIL_H_ | |
| 20 #define MEDIA_BASE_AUDIO_OUTPUT_DEVICE_CALLBACK_UTIL_H_ | |
| 21 | |
| 22 #include "base/callback.h" | |
| 23 #include "base/single_thread_task_runner.h" | |
| 24 #include "media/audio/audio_output_ipc.h" | |
| 25 | |
| 26 namespace media { | |
| 27 | |
| 28 typedef base::Callback<void(SwitchOutputDeviceResult)> | |
| 29 SwitchOutputDeviceCallback; | |
| 30 | |
| 31 class MEDIA_EXPORT SwitchOutputDeviceCallbackRunner { | |
| 32 public: | |
| 33 SwitchOutputDeviceCallbackRunner( | |
| 34 scoped_ptr<SwitchOutputDeviceCallback> callback, | |
| 35 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner); | |
| 36 | |
| 37 ~SwitchOutputDeviceCallbackRunner(); | |
| 38 | |
| 39 // Posts the execution of |callback_| to |callback task runner_|, and | |
| 40 // relinquishes ownership of both afterwards. |result| is passed as the | |
| 41 // argument for |callback_|. | |
| 42 // Calling this method a second time has no effect. | |
| 43 void Run(SwitchOutputDeviceResult result); | |
| 44 | |
| 45 private: | |
| 46 scoped_ptr<SwitchOutputDeviceCallback> callback_; | |
| 47 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_; | |
| 48 }; | |
| 49 | |
| 50 } // namespace media | |
| 51 | |
| 52 #endif // MEDIA_BASE_AUDIO_OUTPUT_DEVICE_CALLBACK_UTIL_H_ | |
| OLD | NEW |