Chromium Code Reviews| Index: chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h |
| diff --git a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h |
| index 39b5a4bc44937acc84eff2caef7ca033833d7349..96f638f092fd60bc400620a0e31b66b58c8fbc29 100644 |
| --- a/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h |
| +++ b/chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h |
| @@ -54,31 +54,9 @@ class WebrtcAudioPrivateFunction : public ChromeAsyncExtensionFunction { |
| ~WebrtcAudioPrivateFunction() override; |
| protected: |
| - // Retrieves the list of output device descriptions on the appropriate |
| - // thread. Call from UI thread, callback will occur on IO thread. |
| - void GetOutputDeviceDescriptions(); |
| - |
| - // Must override this if you call GetOutputDeviceDescriptions. Called on IO |
| - // thread. |
| - virtual void OnOutputDeviceDescriptions( |
| - std::unique_ptr<media::AudioDeviceDescriptions> device_descriptions); |
| - |
| - // Calculates a single HMAC. Call from any thread. Calls back via |
| - // OnHMACCalculated on UI thread. |
| - // |
| - // This function, and device ID HMACs in this API in general use the |
| - // calling extension's ID as the security origin. The only exception |
| - // to this rule is when calculating the input device ID HMAC in |
| - // getAssociatedSink, where we use the provided |securityOrigin|. |
| - void CalculateHMAC(const std::string& raw_id); |
| - |
| - // Must override this if you call CalculateHMAC. |
| - virtual void OnHMACCalculated(const std::string& hmac); |
| - |
| // Calculates a single HMAC, using the extension ID as the security origin. |
| - // |
| // Call only on IO thread. |
| - std::string CalculateHMACImpl(const std::string& raw_id); |
| + std::string CalculateHMAC(const std::string& raw_id); |
| // Initializes |device_id_salt_|. Must be called on the UI thread, |
| // before any calls to |device_id_salt()|. |
| @@ -99,17 +77,21 @@ class WebrtcAudioPrivateGetSinksFunction : public WebrtcAudioPrivateFunction { |
| ~WebrtcAudioPrivateGetSinksFunction() override {} |
| private: |
| + using SinkInfoVector = std::vector<api::webrtc_audio_private::SinkInfo>; |
| + |
| DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getSinks", |
| WEBRTC_AUDIO_PRIVATE_GET_SINKS); |
| - // Sequence of events is that we query the list of sinks on the |
| - // AudioManager's thread, then calculate HMACs on the IO thread, |
| - // then finish on the UI thread. |
| bool RunAsync() override; |
| - void DoQuery(); |
| - void OnOutputDeviceDescriptions( |
| - std::unique_ptr<media::AudioDeviceDescriptions> raw_ids) override; |
| - void DoneOnUIThread(); |
| + |
| + // Requests output device descriptions on IO thread. |
| + void GetOutputDeviceDescriptions(); |
| + |
| + // Receives output device descriptions on IO thread, calculates HMACs for them |
| + // and replies to UI thread with DoneOnUIThread(). |
| + void OnOutputDeviceDescriptions(media::AudioDeviceDescriptions sink_devices); |
| + |
| + void DoneOnUIThread(std::unique_ptr<SinkInfoVector> results); |
| }; |
| class WebrtcAudioPrivateGetAssociatedSinkFunction |
| @@ -124,45 +106,26 @@ class WebrtcAudioPrivateGetAssociatedSinkFunction |
| DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getAssociatedSink", |
| WEBRTC_AUDIO_PRIVATE_GET_ASSOCIATED_SINK); |
| + // UI thread: Entry point, posts GetInputDeviceDescriptions() to IO thread. |
| bool RunAsync() override; |
| - // This implementation is slightly complicated because of different |
| - // thread requirements for the various functions we need to invoke. |
| - // |
| - // Each worker function will post a task to the appropriate thread |
| - // for the next one. |
| - // |
| - // The sequence of events is: |
| - // 1. Get the list of source devices on the device thread. |
| - // 2. Given a source ID for an origin and that security origin, find |
| - // the raw source ID. This needs to happen on the IO thread since |
| - // we will be using the ResourceContext. |
| - // 3. Given a raw source ID, get the raw associated sink ID on the |
| - // device thread. |
| - // 4. Given the raw associated sink ID, get its HMAC on the IO thread. |
| - // 5. Respond with the HMAC of the associated sink ID on the UI thread. |
| - |
| - // Fills in |source_devices_|. Note that these are input devices, |
| - // not output devices, so don't use |
| - // |WebrtcAudioPrivateFunction::GetOutputDeviceDescriptions|. |
| - void GetDevicesOnDeviceThread(); |
| - |
| - // Takes the parameters of the function, retrieves the raw source |
| - // device ID, or the empty string if none. |
| - void GetRawSourceIDOnIOThread(); |
| - |
| - // Gets the raw sink ID for a raw source ID. Sends it to |CalculateHMAC|. |
| - void GetAssociatedSinkOnDeviceThread(const std::string& raw_source_id); |
| - |
| - // Receives the associated sink ID after its HMAC is calculated. |
| - void OnHMACCalculated(const std::string& hmac) override; |
| - |
| - // Accessed from UI thread and device thread, but only on one at a |
| - // time, no locking needed. |
| - std::unique_ptr<api::webrtc_audio_private::GetAssociatedSink::Params> params_; |
| + // IO thread: Enumerates input devices. |
| + void GetInputDeviceDescriptions(); |
|
Devlin
2017/04/06 21:23:27
As Guido mentioned, we often have the OnFooThread
|
| + |
| + // IO thread: Looks up the raw source device ID basing on |params| and |
| + // requests associated raw sink device id for it. |
| + void OnInputDeviceDescriptions(media::AudioDeviceDescriptions source_devices); |
| - // Audio sources (input devices). Filled in by DoWorkOnDeviceThread. |
| - media::AudioDeviceDescriptions source_devices_; |
| + // IO thread: Receives the raw sink ID, calculate HMAC for it and sends it to |
| + // |OnHMACCalculated|. |
| + void CalculateHMACAndReplyOnUIThread(const std::string& raw_sink_id); |
| + |
| + // UI thread: Receives the associated sink ID after its HMAC is calculated. |
| + void OnHMACCalculated(const std::string& hmac); |
| + |
| + // Initialized on UI thread in RunAsync(), read-only access on IO thread - no |
| + // locking needed. |
| + std::unique_ptr<api::webrtc_audio_private::GetAssociatedSink::Params> params_; |
| }; |
| } // namespace extensions |