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

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

Issue 2424163004: Factor out authorization from AudioRendererHost. (Closed)
Patch Set: Rename things. Created 4 years, 1 month 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include <string> 47 #include <string>
48 #include <utility> 48 #include <utility>
49 49
50 #include "base/atomic_ref_count.h" 50 #include "base/atomic_ref_count.h"
51 #include "base/gtest_prod_util.h" 51 #include "base/gtest_prod_util.h"
52 #include "base/logging.h" 52 #include "base/logging.h"
53 #include "base/macros.h" 53 #include "base/macros.h"
54 #include "base/memory/ref_counted.h" 54 #include "base/memory/ref_counted.h"
55 #include "base/process/process.h" 55 #include "base/process/process.h"
56 #include "base/sequenced_task_runner_helpers.h" 56 #include "base/sequenced_task_runner_helpers.h"
57 #include "content/browser/renderer_host/media/audio_output_authorization_handler .h"
57 #include "content/browser/renderer_host/media/media_devices_manager.h" 58 #include "content/browser/renderer_host/media/media_devices_manager.h"
58 #include "content/common/content_export.h" 59 #include "content/common/content_export.h"
59 #include "content/public/browser/browser_message_filter.h" 60 #include "content/public/browser/browser_message_filter.h"
60 #include "content/public/browser/browser_thread.h" 61 #include "content/public/browser/browser_thread.h"
61 #include "content/public/browser/render_process_host.h" 62 #include "content/public/browser/render_process_host.h"
62 #include "content/public/browser/resource_context.h" 63 #include "content/public/browser/resource_context.h"
63 #include "media/audio/audio_io.h" 64 #include "media/audio/audio_io.h"
64 #include "media/audio/audio_logging.h" 65 #include "media/audio/audio_logging.h"
65 #include "media/audio/audio_output_controller.h" 66 #include "media/audio/audio_output_controller.h"
66 #include "media/audio/simple_sources.h" 67 #include "media/audio/simple_sources.h"
68 #include "media/base/output_device_info.h"
67 #include "url/origin.h" 69 #include "url/origin.h"
68 70
69 namespace media { 71 namespace media {
70 class AudioManager; 72 class AudioManager;
71 class AudioParameters; 73 class AudioParameters;
72 } 74 }
73 75
74 namespace content { 76 namespace content {
75 77
76 class AudioMirroringManager; 78 class AudioMirroringManager;
(...skipping 17 matching lines...) Expand all
94 96
95 // BrowserMessageFilter implementation. 97 // BrowserMessageFilter implementation.
96 void OnChannelClosing() override; 98 void OnChannelClosing() override;
97 void OnDestruct() const override; 99 void OnDestruct() const override;
98 bool OnMessageReceived(const IPC::Message& message) override; 100 bool OnMessageReceived(const IPC::Message& message) override;
99 101
100 // Returns true if any streams managed by this host are actively playing. Can 102 // Returns true if any streams managed by this host are actively playing. Can
101 // be called from any thread. 103 // be called from any thread.
102 bool HasActiveAudio(); 104 bool HasActiveAudio();
103 105
106 void OverrideDevicePermissionsForTesting(bool has_access);
107
104 private: 108 private:
105 friend class AudioRendererHostTest; 109 friend class AudioRendererHostTest;
106 friend class BrowserThread; 110 friend class BrowserThread;
107 friend class base::DeleteHelper<AudioRendererHost>; 111 friend class base::DeleteHelper<AudioRendererHost>;
108 friend class MockAudioRendererHost; 112 friend class MockAudioRendererHost;
109 friend class TestAudioRendererHost; 113 friend class TestAudioRendererHost;
110 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); 114 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream);
111 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); 115 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation);
112 116
113 class AudioEntry; 117 class AudioEntry;
(...skipping 24 matching lines...) Expand all
138 // |session_id| will be ignored and the given |device_id| and 142 // |session_id| will be ignored and the given |device_id| and
139 // |security_origin| will be used to select the output device. 143 // |security_origin| will be used to select the output device.
140 // Upon completion of the process, the peer is notified with the device output 144 // Upon completion of the process, the peer is notified with the device output
141 // parameters via the NotifyDeviceAuthorized message. 145 // parameters via the NotifyDeviceAuthorized message.
142 void OnRequestDeviceAuthorization(int stream_id, 146 void OnRequestDeviceAuthorization(int stream_id,
143 int render_frame_id, 147 int render_frame_id,
144 int session_id, 148 int session_id,
145 const std::string& device_id, 149 const std::string& device_id,
146 const url::Origin& security_origin); 150 const url::Origin& security_origin);
147 151
152 void AuthorizationCompleted(int stream_id,
153 url::Origin security_origin,
154 base::TimeTicks auth_start_time,
155 media::OutputDeviceStatus status,
156 bool should_send_id,
157 const media::AudioParameters& params,
158 const std::string& unique_id);
o1ka 2016/11/16 15:11:28 raw_id?
Max Morin 2016/11/16 15:54:36 Done.
159
148 // Creates an audio output stream with the specified format. 160 // Creates an audio output stream with the specified format.
149 // Upon success/failure, the peer is notified via the NotifyStreamCreated 161 // Upon success/failure, the peer is notified via the NotifyStreamCreated
150 // message. 162 // message.
151 void OnCreateStream(int stream_id, 163 void OnCreateStream(int stream_id,
152 int render_frame_id, 164 int render_frame_id,
153 const media::AudioParameters& params); 165 const media::AudioParameters& params);
154 166
155 // Play the audio stream referenced by |stream_id|. 167 // Play the audio stream referenced by |stream_id|.
156 void OnPlayStream(int stream_id); 168 void OnPlayStream(int stream_id);
157 169
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 void ReportErrorAndClose(int stream_id); 204 void ReportErrorAndClose(int stream_id);
193 205
194 // A helper method to look up a AudioEntry identified by |stream_id|. 206 // A helper method to look up a AudioEntry identified by |stream_id|.
195 // Returns NULL if not found. 207 // Returns NULL if not found.
196 AudioEntry* LookupById(int stream_id); 208 AudioEntry* LookupById(int stream_id);
197 209
198 // A helper method to update the number of playing streams and alert the 210 // A helper method to update the number of playing streams and alert the
199 // ResourceScheduler when the renderer starts or stops playing an audiostream. 211 // ResourceScheduler when the renderer starts or stops playing an audiostream.
200 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); 212 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing);
201 213
202 // Check if the renderer process has access to the requested output device.
203 void CheckOutputDeviceAccess(int render_frame_id,
204 const std::string& device_id,
205 const url::Origin& security_origin,
206 int stream_id,
207 base::TimeTicks auth_start_time);
208
209 // Proceed with device authorization after checking permissions.
210 void AccessChecked(const std::string& device_id,
211 const url::Origin& security_origin,
212 int stream_id,
213 base::TimeTicks auth_start_time,
214 bool have_access);
215
216 // Translate the hashed |device_id| to a unique device ID.
217 void TranslateDeviceID(const std::string& device_id,
218 const url::Origin& security_origin,
219 int stream_id,
220 base::TimeTicks auth_start_time,
221 const MediaDeviceEnumeration& enumeration);
222
223 // Get audio hardware parameters on the device thread.
224 media::AudioParameters GetDeviceParametersOnDeviceThread(
225 const std::string& device_id);
226
227 // Proceed with device authorization after translating device ID and
228 // receiving hardware parameters.
229 void DeviceParametersReceived(int stream_id,
230 base::TimeTicks auth_start_time,
231 bool device_found,
232 const std::string& unique_id,
233 const media::AudioParameters& output_params);
234
235 // Helper method to check if the authorization procedure for stream 214 // Helper method to check if the authorization procedure for stream
236 // |stream_id| has started. 215 // |stream_id| has started.
237 bool IsAuthorizationStarted(int stream_id); 216 bool IsAuthorizationStarted(int stream_id);
238 217
239 // Called from AudioRendererHostTest to override the function that checks for 218 // Called from AudioRendererHostTest to override the function that checks for
240 // the existence of the RenderFrameHost at stream creation time. 219 // the existence of the RenderFrameHost at stream creation time.
241 void set_render_frame_id_validate_function_for_testing( 220 void set_render_frame_id_validate_function_for_testing(
242 ValidateRenderFrameIdFunction function) { 221 ValidateRenderFrameIdFunction function) {
243 validate_render_frame_id_function_ = function; 222 validate_render_frame_id_function_ = function;
244 } 223 }
245 224
246 // ID of the RenderProcessHost that owns this instance. 225 // ID of the RenderProcessHost that owns this instance.
247 const int render_process_id_; 226 const int render_process_id_;
248 227
249 media::AudioManager* const audio_manager_; 228 media::AudioManager* const audio_manager_;
250 AudioMirroringManager* const mirroring_manager_; 229 AudioMirroringManager* const mirroring_manager_;
251 std::unique_ptr<media::AudioLog> audio_log_; 230 std::unique_ptr<media::AudioLog> audio_log_;
252 231
253 // Used to access to AudioInputDeviceManager.
254 MediaStreamManager* media_stream_manager_;
255
256 // A map of stream IDs to audio sources. 232 // A map of stream IDs to audio sources.
257 AudioEntryMap audio_entries_; 233 AudioEntryMap audio_entries_;
258 234
259 // The number of streams in the playing state. Atomic read safe from any 235 // The number of streams in the playing state. Atomic read safe from any
260 // thread, but should only be updated from the IO thread. 236 // thread, but should only be updated from the IO thread.
261 base::AtomicRefCount num_playing_streams_; 237 base::AtomicRefCount num_playing_streams_;
262 238
263 // Salt required to translate renderer device IDs to raw device unique IDs 239 // Salt required to translate renderer device IDs to raw device unique IDs
264 std::string salt_; 240 std::string salt_;
265 241
266 // Map of device authorizations for streams that are not yet created 242 // Map of device authorizations for streams that are not yet created
267 // The key is the stream ID, and the value is a pair. The pair's first element 243 // The key is the stream ID, and the value is a pair. The pair's first element
268 // is a bool that is true if the authorization process completes successfully. 244 // is a bool that is true if the authorization process completes successfully.
269 // The second element contains the unique ID of the authorized device. 245 // The second element contains the unique ID of the authorized device.
270 std::map<int, std::pair<bool, std::string>> authorizations_; 246 std::map<int, std::pair<bool, std::string>> authorizations_;
271 247
272 // At stream creation time, AudioRendererHost will call this function on the 248 // At stream creation time, AudioRendererHost will call this function on the
273 // UI thread to validate render frame IDs. A default is set by the 249 // UI thread to validate render frame IDs. A default is set by the
274 // constructor, but this can be overridden by unit tests. 250 // constructor, but this can be overridden by unit tests.
275 ValidateRenderFrameIdFunction validate_render_frame_id_function_; 251 ValidateRenderFrameIdFunction validate_render_frame_id_function_;
276 252
277 // The maximum number of simultaneous streams during the lifetime of this 253 // The maximum number of simultaneous streams during the lifetime of this
278 // host. Reported as UMA stat at shutdown. 254 // host. Reported as UMA stat at shutdown.
279 size_t max_simultaneous_streams_; 255 size_t max_simultaneous_streams_;
280 256
257 AudioOutputAuthorizationHandler authorization_handler_;
258
281 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 259 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
282 }; 260 };
283 261
284 } // namespace content 262 } // namespace content
285 263
286 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 264 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698