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

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: rebase 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Returns the RenderProcessHost associated with the given |request| 69 // Returns the RenderProcessHost associated with the given |request|
92 // authorized by the |security_origin|. Returns null if unauthorized or 70 // authorized by the |security_origin|. Returns null if unauthorized or
93 // the RPH does not exist. 71 // the RPH does not exist.
94 content::RenderProcessHost* GetRenderProcessHostFromRequest( 72 content::RenderProcessHost* GetRenderProcessHostFromRequest(
95 const api::webrtc_audio_private::RequestInfo& request, 73 const api::webrtc_audio_private::RequestInfo& request,
96 const std::string& security_origin); 74 const std::string& security_origin);
97 75
98 private: 76 private:
99 std::string device_id_salt_; 77 std::string device_id_salt_;
100 78
101 DISALLOW_COPY_AND_ASSIGN(WebrtcAudioPrivateFunction); 79 DISALLOW_COPY_AND_ASSIGN(WebrtcAudioPrivateFunction);
102 }; 80 };
103 81
104 class WebrtcAudioPrivateGetSinksFunction : public WebrtcAudioPrivateFunction { 82 class WebrtcAudioPrivateGetSinksFunction : public WebrtcAudioPrivateFunction {
105 protected: 83 protected:
106 ~WebrtcAudioPrivateGetSinksFunction() override {} 84 ~WebrtcAudioPrivateGetSinksFunction() override {}
107 85
108 private: 86 private:
87 using SinkInfoVector = std::vector<api::webrtc_audio_private::SinkInfo>;
88
109 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getSinks", 89 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getSinks",
110 WEBRTC_AUDIO_PRIVATE_GET_SINKS); 90 WEBRTC_AUDIO_PRIVATE_GET_SINKS);
111 91
112 // Sequence of events is that we query the list of sinks on the
113 // AudioManager's thread, then calculate HMACs on the IO thread,
114 // then finish on the UI thread.
115 bool RunAsync() override; 92 bool RunAsync() override;
116 void DoQuery(); 93
117 void OnOutputDeviceDescriptions( 94 // Requests output device descriptions.
118 std::unique_ptr<media::AudioDeviceDescriptions> raw_ids) override; 95 void GetOutputDeviceDescriptionsOnIOThread();
119 void DoneOnUIThread(); 96
97 // Receives output device descriptions, calculates HMACs for them and replies
98 // to UI thread with DoneOnUIThread().
99 void ReceiveOutputDeviceDescriptionsOnIOThread(
100 media::AudioDeviceDescriptions sink_devices);
101
102 // Sends the response.
103 void DoneOnUIThread(std::unique_ptr<SinkInfoVector> results);
120 }; 104 };
121 105
122 class WebrtcAudioPrivateGetAssociatedSinkFunction 106 class WebrtcAudioPrivateGetAssociatedSinkFunction
123 : public WebrtcAudioPrivateFunction { 107 : public WebrtcAudioPrivateFunction {
124 public: 108 public:
125 WebrtcAudioPrivateGetAssociatedSinkFunction(); 109 WebrtcAudioPrivateGetAssociatedSinkFunction();
126 110
127 protected: 111 protected:
128 ~WebrtcAudioPrivateGetAssociatedSinkFunction() override; 112 ~WebrtcAudioPrivateGetAssociatedSinkFunction() override;
129 113
130 private: 114 private:
131 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getAssociatedSink", 115 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.getAssociatedSink",
132 WEBRTC_AUDIO_PRIVATE_GET_ASSOCIATED_SINK); 116 WEBRTC_AUDIO_PRIVATE_GET_ASSOCIATED_SINK);
133 117
118 // UI thread: Entry point, posts GetInputDeviceDescriptions() to IO thread.
134 bool RunAsync() override; 119 bool RunAsync() override;
135 120
136 // This implementation is slightly complicated because of different 121 // Enumerates input devices.
137 // thread requirements for the various functions we need to invoke. 122 void GetInputDeviceDescriptionsOnIOThread();
138 //
139 // Each worker function will post a task to the appropriate thread
140 // for the next one.
141 //
142 // The sequence of events is:
143 // 1. Get the list of source devices on the device thread.
144 // 2. Given a source ID for an origin and that security origin, find
145 // the raw source ID. This needs to happen on the IO thread since
146 // we will be using the ResourceContext.
147 // 3. Given a raw source ID, get the raw associated sink ID on the
148 // device thread.
149 // 4. Given the raw associated sink ID, get its HMAC on the IO thread.
150 // 5. Respond with the HMAC of the associated sink ID on the UI thread.
151 123
152 // Fills in |source_devices_|. Note that these are input devices, 124 // Receives the input device descriptions, looks up the raw source device ID
153 // not output devices, so don't use 125 // basing on |params|, and requests the associated raw sink ID for it.
154 // |WebrtcAudioPrivateFunction::GetOutputDeviceDescriptions|. 126 void ReceiveInputDeviceDescriptionsOnIOThread(
155 void GetDevicesOnDeviceThread(); 127 media::AudioDeviceDescriptions source_devices);
156 128
157 // Takes the parameters of the function, retrieves the raw source 129 // IO thread: Receives the raw sink ID, calculates HMAC and replies to IO
158 // device ID, or the empty string if none. 130 // thread with ReceiveHMACOnUIThread().
159 void GetRawSourceIDOnIOThread(); 131 void CalculateHMACOnIOThread(const std::string& raw_sink_id);
160 132
161 // Gets the raw sink ID for a raw source ID. Sends it to |CalculateHMAC|. 133 // Receives the associated sink ID as HMAC and sends the response.
162 void GetAssociatedSinkOnDeviceThread(const std::string& raw_source_id); 134 void ReceiveHMACOnUIThread(const std::string& hmac);
163 135
164 // Receives the associated sink ID after its HMAC is calculated. 136 // Initialized on UI thread in RunAsync(), read-only access on IO thread - no
165 void OnHMACCalculated(const std::string& hmac) override; 137 // locking needed.
166
167 // Accessed from UI thread and device thread, but only on one at a
168 // time, no locking needed.
169 std::unique_ptr<api::webrtc_audio_private::GetAssociatedSink::Params> params_; 138 std::unique_ptr<api::webrtc_audio_private::GetAssociatedSink::Params> params_;
170
171 // Audio sources (input devices). Filled in by DoWorkOnDeviceThread.
172 media::AudioDeviceDescriptions source_devices_;
173 }; 139 };
174 140
175 class WebrtcAudioPrivateSetAudioExperimentsFunction 141 class WebrtcAudioPrivateSetAudioExperimentsFunction
176 : public WebrtcAudioPrivateFunction { 142 : public WebrtcAudioPrivateFunction {
177 public: 143 public:
178 WebrtcAudioPrivateSetAudioExperimentsFunction(); 144 WebrtcAudioPrivateSetAudioExperimentsFunction();
179 145
180 protected: 146 protected:
181 ~WebrtcAudioPrivateSetAudioExperimentsFunction() override; 147 ~WebrtcAudioPrivateSetAudioExperimentsFunction() override;
182 148
183 private: 149 private:
184 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.setAudioExperiments", 150 DECLARE_EXTENSION_FUNCTION("webrtcAudioPrivate.setAudioExperiments",
185 WEBRTC_AUDIO_PRIVATE_SET_AUDIO_EXPERIMENTS); 151 WEBRTC_AUDIO_PRIVATE_SET_AUDIO_EXPERIMENTS);
186 152
187 bool RunAsync() override; 153 bool RunAsync() override;
188 }; 154 };
189 155
190 } // namespace extensions 156 } // namespace extensions
191 157
192 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVA TE_API_H_ 158 #endif // CHROME_BROWSER_EXTENSIONS_API_WEBRTC_AUDIO_PRIVATE_WEBRTC_AUDIO_PRIVA TE_API_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/api/webrtc_audio_private/webrtc_audio_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698