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

Side by Side Diff: chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.h

Issue 2791203002: Switching WebRtc private API from AudioManager to AudioSystem (Closed)
Patch Set: browser_tests fixed Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVATE_ API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVATE_ API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVATE_ API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVATE_ API_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 }; 47 };
48 48
49 // Common base for WebrtcAudioPrivate functions, that provides a 49 // Common base for WebrtcAudioPrivate functions, that provides a
50 // couple of optionally-used common implementations. 50 // couple of optionally-used common implementations.
51 class WebrtcAudioPrivateFunction : public ChromeAsyncExtensionFunction { 51 class WebrtcAudioPrivateFunction : public ChromeAsyncExtensionFunction {
52 protected: 52 protected:
53 WebrtcAudioPrivateFunction(); 53 WebrtcAudioPrivateFunction();
54 ~WebrtcAudioPrivateFunction() override; 54 ~WebrtcAudioPrivateFunction() override;
55 55
56 protected: 56 protected:
57 // Retrieves the list of output device descriptions on the appropriate
58 // thread. Call from UI thread, callback will occur on IO thread.
59 void GetOutputDeviceDescriptions();
60
61 // Must override this if you call GetOutputDeviceDescriptions. Called on IO
62 // thread.
63 virtual void OnOutputDeviceDescriptions(
64 std::unique_ptr<media::AudioDeviceDescriptions> device_descriptions);
65
66 // Calculates a single HMAC. Call from any thread. Calls back via
67 // OnHMACCalculated on UI thread.
68 //
69 // This function, and device ID HMACs in this API in general use the
70 // calling extension's ID as the security origin. The only exception
71 // to this rule is when calculating the input device ID HMAC in
72 // getAssociatedSink, where we use the provided |securityOrigin|.
73 void CalculateHMAC(const std::string& raw_id);
74
75 // Must override this if you call CalculateHMAC.
76 virtual void OnHMACCalculated(const std::string& hmac);
77
78 // Calculates a single HMAC, using the extension ID as the security origin. 57 // Calculates a single HMAC, using the extension ID as the security origin.
79 //
80 // Call only on IO thread. 58 // Call only on IO thread.
81 std::string CalculateHMACImpl(const std::string& raw_id); 59 std::string CalculateHMAC(const std::string& raw_id);
82 60
83 // Initializes |device_id_salt_|. Must be called on the UI thread, 61 // Initializes |device_id_salt_|. Must be called on the UI thread,
84 // before any calls to |device_id_salt()|. 62 // before any calls to |device_id_salt()|.
85 void InitDeviceIDSalt(); 63 void InitDeviceIDSalt();
86 64
87 // Callable from any thread. Must previously have called 65 // Callable from any thread. Must previously have called
88 // |InitDeviceIDSalt()|. 66 // |InitDeviceIDSalt()|.
89 std::string device_id_salt() const; 67 std::string device_id_salt() const;
90 68
91 private: 69 private:
92 std::string device_id_salt_; 70 std::string device_id_salt_;
93 71
94 DISALLOW_COPY_AND_ASSIGN(WebrtcAudioPrivateFunction); 72 DISALLOW_COPY_AND_ASSIGN(WebrtcAudioPrivateFunction);
95 }; 73 };
96 74
97 class WebrtcAudioPrivateGetSinksFunction : public WebrtcAudioPrivateFunction { 75 class WebrtcAudioPrivateGetSinksFunction : public WebrtcAudioPrivateFunction {
98 protected: 76 protected:
99 ~WebrtcAudioPrivateGetSinksFunction() override {} 77 ~WebrtcAudioPrivateGetSinksFunction() override {}
100 78
101 private: 79 private:
80 using SyncInfoVector = std::vector<api::webrtc_audio_private::SinkInfo>;
Max Morin 2017/04/06 07:41:20 "Sink"?
o1ka 2017/04/06 11:01:22 Done.
81
102 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getSinks", 82 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getSinks",
103 WEBRTC_AUDIO_PRIVATE_GET_SINKS); 83 WEBRTC_AUDIO_PRIVATE_GET_SINKS);
104 84
105 // Sequence of events is that we query the list of sinks on the
106 // AudioManager's thread, then calculate HMACs on the IO thread,
107 // then finish on the UI thread.
108 bool RunAsync() override; 85 bool RunAsync() override;
109 void DoQuery(); 86
110 void OnOutputDeviceDescriptions( 87 // Requests output device descriptions on IO thread.
111 std::unique_ptr<media::AudioDeviceDescriptions> raw_ids) override; 88 void GetOutputDeviceDescriptions();
112 void DoneOnUIThread(); 89
90 // Receives output device descriptions on IO thread, calculates HMACs for them
91 // and replies to UI thread with DoneOnUIThread().
92 void OnOutputDeviceDescriptions(media::AudioDeviceDescriptions sink_devices);
93
94 void DoneOnUIThread(std::unique_ptr<SyncInfoVector> results);
113 }; 95 };
114 96
115 class WebrtcAudioPrivateGetAssociatedSinkFunction 97 class WebrtcAudioPrivateGetAssociatedSinkFunction
116 : public WebrtcAudioPrivateFunction { 98 : public WebrtcAudioPrivateFunction {
117 public: 99 public:
118 WebrtcAudioPrivateGetAssociatedSinkFunction(); 100 WebrtcAudioPrivateGetAssociatedSinkFunction();
119 101
120 protected: 102 protected:
121 ~WebrtcAudioPrivateGetAssociatedSinkFunction() override; 103 ~WebrtcAudioPrivateGetAssociatedSinkFunction() override;
122 104
123 private: 105 private:
124 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getAssociatedSink", 106 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getAssociatedSink",
125 WEBRTC_AUDIO_PRIVATE_GET_ASSOCIATED_SINK); 107 WEBRTC_AUDIO_PRIVATE_GET_ASSOCIATED_SINK);
126 108
109 // UI thread: Entry point, posts GetInputDeviceDescriptions() to IO thread.
127 bool RunAsync() override; 110 bool RunAsync() override;
128 111
129 // This implementation is slightly complicated because of different 112 // IO thread: Enumertaes input devices.
Max Morin 2017/04/06 07:41:20 Enumerates.
o1ka 2017/04/06 11:01:22 Done.
130 // thread requirements for the various functions we need to invoke. 113 void GetInputDeviceDescriptions();
131 //
132 // Each worker function will post a task to the appropriate thread
133 // for the next one.
134 //
135 // The sequence of events is:
136 // 1. Get the list of source devices on the device thread.
137 // 2. Given a source ID for an origin and that security origin, find
138 // the raw source ID. This needs to happen on the IO thread since
139 // we will be using the ResourceContext.
140 // 3. Given a raw source ID, get the raw associated sink ID on the
141 // device thread.
142 // 4. Given the raw associated sink ID, get its HMAC on the IO thread.
143 // 5. Respond with the HMAC of the associated sink ID on the UI thread.
144 114
145 // Fills in |source_devices_|. Note that these are input devices, 115 // IO thread: Looks up the raw source device ID basing on |params| and
146 // not output devices, so don't use 116 // requests associated raw sink device id for it.
147 // |WebrtcAudioPrivateFunction::GetOutputDeviceDescriptions|. 117 void OnInputDeviceDescriptions(media::AudioDeviceDescriptions source_devices);
148 void GetDevicesOnDeviceThread();
149 118
150 // Takes the parameters of the function, retrieves the raw source 119 // IO thread: Receives the raw sink ID, calculate HMAC for it and sends it to
151 // device ID, or the empty string if none. 120 // |OnHMACCalculated|.
152 void GetRawSourceIDOnIOThread(); 121 void CalculateHMACAndReplyOnUIThread(const std::string& raw_sink_id);
153 122
154 // Gets the raw sink ID for a raw source ID. Sends it to |CalculateHMAC|. 123 // UI thread: Receives the associated sink ID after its HMAC is calculated.
155 void GetAssociatedSinkOnDeviceThread(const std::string& raw_source_id); 124 void OnHMACCalculated(const std::string& hmac);
156 125
157 // Receives the associated sink ID after its HMAC is calculated. 126 // Initialized on UI thread in RunAsync(), read-only access on IO thread - no
158 void OnHMACCalculated(const std::string& hmac) override; 127 // locking needed.
159
160 // Accessed from UI thread and device thread, but only on one at a
161 // time, no locking needed.
162 std::unique_ptr<api::webrtc_audio_private::GetAssociatedSink::Params> params_; 128 std::unique_ptr<api::webrtc_audio_private::GetAssociatedSink::Params> params_;
163
164 // Audio sources (input devices). Filled in by DoWorkOnDeviceThread.
165 media::AudioDeviceDescriptions source_devices_;
166 }; 129 };
167 130
168 } // namespace extensions 131 } // namespace extensions
169 132
170 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVA TE_API_H_ 133 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVA TE_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698