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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.h

Issue 2301353007: Fix race in AudioRendererHost around render frame ID validation. (Closed)
Patch Set: Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // AudioRendererHost serves audio related requests from AudioRenderer which 5 // AudioRendererHost serves audio related requests from AudioRenderer which
6 // lives inside the render process and provide access to audio hardware. 6 // lives inside the render process and provide access to audio hardware.
7 // 7 //
8 // This class is owned by RenderProcessHostImpl, and instantiated on UI 8 // This class is owned by RenderProcessHostImpl, and instantiated on UI
9 // thread, but all other operations and method calls happen on IO thread, so we 9 // thread, but all other operations and method calls happen on IO thread, so we
10 // need to be extra careful about the lifetime of this object. AudioManager is a 10 // need to be extra careful about the lifetime of this object. AudioManager is a
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 const url::Origin& security_origin, 181 const url::Origin& security_origin,
182 base::TimeTicks auth_start_time, 182 base::TimeTicks auth_start_time,
183 bool have_access); 183 bool have_access);
184 184
185 // Proceed with device authorization after translating device ID. 185 // Proceed with device authorization after translating device ID.
186 void OnDeviceIDTranslated(int stream_id, 186 void OnDeviceIDTranslated(int stream_id,
187 base::TimeTicks auth_start_time, 187 base::TimeTicks auth_start_time,
188 bool device_found, 188 bool device_found,
189 const AudioOutputDeviceInfo& device_info); 189 const AudioOutputDeviceInfo& device_info);
190 190
191 // Start the actual creation of an audio stream, after the device
192 // authorization process is complete.
193 void DoCreateStream(int stream_id,
194 int render_frame_id,
195 const media::AudioParameters& params,
196 const std::string& device_unique_id,
197 bool render_frame_id_is_valid);
198
199 // Complete the process of creating an audio stream. This will set up the 191 // Complete the process of creating an audio stream. This will set up the
200 // shared memory or shared socket in low latency mode and send the 192 // shared memory or shared socket in low latency mode and send the
201 // NotifyStreamCreated message to the peer. 193 // NotifyStreamCreated message to the peer.
202 void DoCompleteCreation(int stream_id); 194 void DoCompleteCreation(int stream_id);
203 195
196 // Called after the |render_frame_id| provided to OnCreateStream() was
197 // validated. When |is_valid| is false, this calls ReportErrorAndClose().
198 void DidValidateRenderFrame(int stream_id, bool is_valid);
199
204 // Send playing/paused status to the renderer. 200 // Send playing/paused status to the renderer.
205 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); 201 void DoNotifyStreamStateChanged(int stream_id, bool is_playing);
206 202
207 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; 203 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const;
208 204
209 // Send an error message to the renderer. 205 // Send an error message to the renderer.
210 void SendErrorMessage(int stream_id); 206 void SendErrorMessage(int stream_id);
211 207
212 // Delete an audio entry, notifying observers first. This is called by 208 // Delete an audio entry, notifying observers first. This is called by
213 // AudioOutputController after it has closed. 209 // AudioOutputController after it has closed.
(...skipping 24 matching lines...) Expand all
238 // Translate the hashed |device_id| to a unique device ID. 234 // Translate the hashed |device_id| to a unique device ID.
239 void TranslateDeviceID(const std::string& device_id, 235 void TranslateDeviceID(const std::string& device_id,
240 const url::Origin& security_origin, 236 const url::Origin& security_origin,
241 const OutputDeviceInfoCB& callback, 237 const OutputDeviceInfoCB& callback,
242 const AudioOutputDeviceEnumeration& enumeration); 238 const AudioOutputDeviceEnumeration& enumeration);
243 239
244 // Helper method to check if the authorization procedure for stream 240 // Helper method to check if the authorization procedure for stream
245 // |stream_id| has started. 241 // |stream_id| has started.
246 bool IsAuthorizationStarted(int stream_id); 242 bool IsAuthorizationStarted(int stream_id);
247 243
248 #if DCHECK_IS_ON()
249 // Called from AudioRendererHostTest to override the function that checks for 244 // Called from AudioRendererHostTest to override the function that checks for
250 // the existence of the RenderFrameHost at stream creation time. 245 // the existence of the RenderFrameHost at stream creation time.
251 void set_render_frame_id_validate_function_for_testing( 246 void set_render_frame_id_validate_function_for_testing(
252 ValidateRenderFrameIdFunction function) { 247 ValidateRenderFrameIdFunction function) {
253 validate_render_frame_id_function_ = function; 248 validate_render_frame_id_function_ = function;
254 } 249 }
255 #endif // DCHECK_IS_ON()
256 250
257 // ID of the RenderProcessHost that owns this instance. 251 // ID of the RenderProcessHost that owns this instance.
258 const int render_process_id_; 252 const int render_process_id_;
259 253
260 media::AudioManager* const audio_manager_; 254 media::AudioManager* const audio_manager_;
261 AudioMirroringManager* const mirroring_manager_; 255 AudioMirroringManager* const mirroring_manager_;
262 std::unique_ptr<media::AudioLog> audio_log_; 256 std::unique_ptr<media::AudioLog> audio_log_;
263 257
264 // Used to access to AudioInputDeviceManager. 258 // Used to access to AudioInputDeviceManager.
265 MediaStreamManager* media_stream_manager_; 259 MediaStreamManager* media_stream_manager_;
266 260
267 // A map of stream IDs to audio sources. 261 // A map of stream IDs to audio sources.
268 AudioEntryMap audio_entries_; 262 AudioEntryMap audio_entries_;
269 263
270 // The number of streams in the playing state. Atomic read safe from any 264 // The number of streams in the playing state. Atomic read safe from any
271 // thread, but should only be updated from the IO thread. 265 // thread, but should only be updated from the IO thread.
272 base::AtomicRefCount num_playing_streams_; 266 base::AtomicRefCount num_playing_streams_;
273 267
274 // Salt required to translate renderer device IDs to raw device unique IDs 268 // Salt required to translate renderer device IDs to raw device unique IDs
275 std::string salt_; 269 std::string salt_;
276 270
277 // Map of device authorizations for streams that are not yet created 271 // Map of device authorizations for streams that are not yet created
278 // The key is the stream ID, and the value is a pair. The pair's first element 272 // The key is the stream ID, and the value is a pair. The pair's first element
279 // is a bool that is true if the authorization process completes successfully. 273 // is a bool that is true if the authorization process completes successfully.
280 // The second element contains the unique ID of the authorized device. 274 // The second element contains the unique ID of the authorized device.
281 std::map<int, std::pair<bool, std::string>> authorizations_; 275 std::map<int, std::pair<bool, std::string>> authorizations_;
282 276
283 #if DCHECK_IS_ON() 277 // At stream creation time, AudioRendererHost will call this function on the
284 // When DCHECKs are turned on, AudioRendererHost will call this function on 278 // UI thread to validate render frame IDs. A default is set by the
285 // the UI thread to validate render frame IDs. A default is set by the
286 // constructor, but this can be overridden by unit tests. 279 // constructor, but this can be overridden by unit tests.
287 ValidateRenderFrameIdFunction validate_render_frame_id_function_; 280 ValidateRenderFrameIdFunction validate_render_frame_id_function_;
288 #endif // DCHECK_IS_ON()
289 281
290 // The maximum number of simultaneous streams during the lifetime of this 282 // The maximum number of simultaneous streams during the lifetime of this
291 // host. Reported as UMA stat at shutdown. 283 // host. Reported as UMA stat at shutdown.
292 size_t max_simultaneous_streams_; 284 size_t max_simultaneous_streams_;
293 285
294 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 286 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
295 }; 287 };
296 288
297 } // namespace content 289 } // namespace content
298 290
299 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 291 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698