webrtc_audio_private_api.h revision 010d83a9304c5a91596085d917d248abff47903a
11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVATE_API_H_
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVATE_API_H_
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/memory/ref_counted.h"
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "base/system_monitor/system_monitor.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/browser/extensions/chrome_extension_function.h"
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/common/extensions/api/webrtc_audio_private.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "content/public/browser/render_view_host.h"
13a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "extensions/browser/browser_context_keyed_api_factory.h"
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "media/audio/audio_device_name.h"
151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "url/gurl.h"
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace content {
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ResourceContext;
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace extensions {
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Listens for device changes and forwards as an extension event.
241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WebrtcAudioPrivateEventService
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    : public BrowserContextKeyedAPI,
261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      public base::SystemMonitor::DevicesChangedObserver {
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  explicit WebrtcAudioPrivateEventService(content::BrowserContext* context);
291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~WebrtcAudioPrivateEventService();
301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // BrowserContextKeyedAPI implementation.
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void Shutdown() OVERRIDE;
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  static BrowserContextKeyedAPIFactory<WebrtcAudioPrivateEventService>*
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      GetFactoryInstance();
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  static const char* service_name();
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // base::SystemMonitor::DevicesChangedObserver implementation.
381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnDevicesChanged(
391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      base::SystemMonitor::DeviceType device_type) OVERRIDE;
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  friend class BrowserContextKeyedAPIFactory<WebrtcAudioPrivateEventService>;
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void SignalEvent();
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  content::BrowserContext* browser_context_;
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Common base for WebrtcAudioPrivate functions, that provides a
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// couple of optionally-used common implementations.
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class WebrtcAudioPrivateFunction : public ChromeAsyncExtensionFunction {
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected:
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  WebrtcAudioPrivateFunction();
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual ~WebrtcAudioPrivateFunction();
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) protected:
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Retrieves the list of output device names on the appropriate
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // thread. Call from UI thread, callback will occur on IO thread.
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void GetOutputDeviceNames();
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Must override this if you call GetOutputDeviceNames. Called on IO thread.
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnOutputDeviceNames(
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      scoped_ptr<media::AudioDeviceNames> device_names);
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Retrieve the list of AudioOutputController objects. Calls back
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // via OnControllerList.
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Returns false on error, in which case it has set |error_| and the
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // entire function should fail.
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Call from any thread. Callback will occur on originating thread.
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool GetControllerList(int tab_id);
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Must override this if you call GetControllerList.
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnControllerList(
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      const content::RenderViewHost::AudioOutputControllerList& list);
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Calculates a single HMAC. Call from any thread. Calls back via
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // OnHMACCalculated on UI thread.
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // This function, and device ID HMACs in this API in general use the
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // calling extension's ID as the security origin. The only exception
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // to this rule is when calculating the input device ID HMAC in
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // getAssociatedSink, where we use the provided |securityOrigin|.
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void CalculateHMAC(const std::string& raw_id);
865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Must override this if you call CalculateHMAC.
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnHMACCalculated(const std::string& hmac);
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Calculates a single HMAC, using the extension ID as the security origin.
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Call only on IO thread.
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  std::string CalculateHMACImpl(const std::string& raw_id);
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Initializes |resource_context_|. Must be called on the UI thread,
965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // before any calls to |resource_context()|.
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void InitResourceContext();
985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Callable from any thread. Must previously have called
1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |InitResourceContext()|.
1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::ResourceContext* resource_context() const;
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private:
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::ResourceContext* resource_context_;
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WebrtcAudioPrivateFunction);
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class WebrtcAudioPrivateGetSinksFunction : public WebrtcAudioPrivateFunction {
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected:
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~WebrtcAudioPrivateGetSinksFunction() {}
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getSinks",
1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             WEBRTC_AUDIO_PRIVATE_GET_SINKS);
1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Sequence of events is that we query the list of sinks on the
1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // AudioManager's thread, then calculate HMACs on the IO thread,
1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // then finish on the UI thread.
120010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool RunAsync() OVERRIDE;
1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void DoQuery();
1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnOutputDeviceNames(
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      scoped_ptr<media::AudioDeviceNames> raw_ids) OVERRIDE;
1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void DoneOnUIThread();
1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WebrtcAudioPrivateGetActiveSinkFunction
1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : public WebrtcAudioPrivateFunction {
1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected:
1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~WebrtcAudioPrivateGetActiveSinkFunction() {}
1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getActiveSink",
1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             WEBRTC_AUDIO_PRIVATE_GET_ACTIVE_SINK);
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
136010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool RunAsync() OVERRIDE;
1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnControllerList(
1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const content::RenderViewHost::AudioOutputControllerList&
1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      controllers) OVERRIDE;
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnHMACCalculated(const std::string& hmac) OVERRIDE;
1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WebrtcAudioPrivateSetActiveSinkFunction
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : public WebrtcAudioPrivateFunction {
1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
1461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  WebrtcAudioPrivateSetActiveSinkFunction();
1471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected:
1491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~WebrtcAudioPrivateSetActiveSinkFunction();
1501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.setActiveSink",
1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             WEBRTC_AUDIO_PRIVATE_SET_ACTIVE_SINK);
1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
155010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool RunAsync() OVERRIDE;
1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnControllerList(
1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      const content::RenderViewHost::AudioOutputControllerList&
1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      controllers) OVERRIDE;
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnOutputDeviceNames(
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      scoped_ptr<media::AudioDeviceNames> device_names) OVERRIDE;
1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void SwitchDone();
1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void DoneOnUIThread();
1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  int tab_id_;
1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  std::string sink_id_;
1661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Filled in by OnControllerList.
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  content::RenderViewHost::AudioOutputControllerList controllers_;
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Number of sink IDs we are still waiting for. Can become greater
1711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // than 0 in OnControllerList, decreases on every OnSinkId call.
1721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  size_t num_remaining_sink_ids_;
1731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class WebrtcAudioPrivateGetAssociatedSinkFunction
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : public WebrtcAudioPrivateFunction {
177a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public:
178a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  WebrtcAudioPrivateGetAssociatedSinkFunction();
179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) protected:
1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~WebrtcAudioPrivateGetAssociatedSinkFunction();
1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private:
1841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getAssociatedSink",
1851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             WEBRTC_AUDIO_PRIVATE_GET_ASSOCIATED_SINK);
1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
187010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool RunAsync() OVERRIDE;
1881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
189a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // This implementation is slightly complicated because of different
190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // thread requirements for the various functions we need to invoke.
191a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  //
1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Each worker function will post a task to the appropriate thread
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // for the next one.
194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  //
195a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The sequence of events is:
196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // 1. Get the list of source devices on the device thread.
197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // 2. Given a source ID for an origin and that security origin, find
198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  //    the raw source ID. This needs to happen on the IO thread since
199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  //    we will be using the ResourceContext.
2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 3. Given a raw source ID, get the raw associated sink ID on the
201a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  //    device thread.
2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 4. Given the raw associated sink ID, get its HMAC on the IO thread.
2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // 5. Respond with the HMAC of the associated sink ID on the UI thread.
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Fills in |source_devices_|. Note that these are input devices,
2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // not output devices, so don't use
2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // |WebrtcAudioPrivateFunction::GetOutputDeviceNames|.
208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  void GetDevicesOnDeviceThread();
209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Takes the parameters of the function, retrieves the raw source
211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // device ID, or the empty string if none.
2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void GetRawSourceIDOnIOThread();
2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Gets the raw sink ID for a raw source ID. Sends it to |CalculateHMAC|.
2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  void GetAssociatedSinkOnDeviceThread(const std::string& raw_source_id);
216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Receives the associated sink ID after its HMAC is calculated.
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void OnHMACCalculated(const std::string& hmac) OVERRIDE;
219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Accessed from UI thread and device thread, but only on one at a
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // time, no locking needed.
222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  scoped_ptr<api::webrtc_audio_private::GetAssociatedSink::Params> params_;
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Audio sources (input devices). Filled in by DoWorkOnDeviceThread.
225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  media::AudioDeviceNames source_devices_;
2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace extensions
2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif  // CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVATE_API_H_
231