Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 namespace content { | 38 namespace content { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 // Tracks the maximum number of simultaneous output streams browser-wide. | 42 // Tracks the maximum number of simultaneous output streams browser-wide. |
| 43 // Accessed on IO thread. | 43 // Accessed on IO thread. |
| 44 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker = | 44 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker = |
| 45 LAZY_INSTANCE_INITIALIZER; | 45 LAZY_INSTANCE_INITIALIZER; |
| 46 | 46 |
| 47 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( | 47 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( |
| 48 int stream_id, | 48 int stream_id) { |
| 49 bool authorized, | 49 return std::make_pair(stream_id, std::make_pair(false, std::string())); |
|
o1ka
2016/11/24 13:17:36
call it directly?
Max Morin
2016/11/24 14:12:20
Done.
| |
| 50 const std::string& device_unique_id) { | |
| 51 return std::make_pair(stream_id, | |
| 52 std::make_pair(authorized, device_unique_id)); | |
| 53 } | 50 } |
| 54 | 51 |
| 55 | 52 |
| 56 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { | 53 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { |
| 57 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 54 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 58 | 55 |
| 59 RenderProcessHost* render_process_host = | 56 RenderProcessHost* render_process_host = |
| 60 RenderProcessHost::FromID(render_process_id); | 57 RenderProcessHost::FromID(render_process_id); |
| 61 | 58 |
| 62 if (render_process_host) | 59 if (render_process_host) |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 : BrowserMessageFilter(AudioMsgStart), | 189 : BrowserMessageFilter(AudioMsgStart), |
| 193 render_process_id_(render_process_id), | 190 render_process_id_(render_process_id), |
| 194 audio_manager_(audio_manager), | 191 audio_manager_(audio_manager), |
| 195 mirroring_manager_(mirroring_manager), | 192 mirroring_manager_(mirroring_manager), |
| 196 audio_log_(media_internals->CreateAudioLog( | 193 audio_log_(media_internals->CreateAudioLog( |
| 197 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER)), | 194 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER)), |
| 198 num_playing_streams_(0), | 195 num_playing_streams_(0), |
| 199 salt_(salt), | 196 salt_(salt), |
| 200 validate_render_frame_id_function_(&ValidateRenderFrameId), | 197 validate_render_frame_id_function_(&ValidateRenderFrameId), |
| 201 max_simultaneous_streams_(0), | 198 max_simultaneous_streams_(0), |
| 202 authorization_handler_(media_stream_manager, render_process_id_, salt) { | 199 authorization_handler_(audio_manager_, |
| 200 media_stream_manager, | |
| 201 render_process_id_, | |
| 202 salt) { | |
| 203 DCHECK(audio_manager_); | 203 DCHECK(audio_manager_); |
| 204 } | 204 } |
| 205 | 205 |
| 206 AudioRendererHost::~AudioRendererHost() { | 206 AudioRendererHost::~AudioRendererHost() { |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 208 CHECK(audio_entries_.empty()); | 208 CHECK(audio_entries_.empty()); |
| 209 | 209 |
| 210 // If we had any streams, report UMA stats for the maximum number of | 210 // If we had any streams, report UMA stats for the maximum number of |
| 211 // simultaneous streams for this render process and for the whole browser | 211 // simultaneous streams for this render process and for the whole browser |
| 212 // process since last reported. | 212 // process since last reported. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 const url::Origin& security_origin) { | 380 const url::Origin& security_origin) { |
| 381 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 381 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 382 const base::TimeTicks auth_start_time = base::TimeTicks::Now(); | 382 const base::TimeTicks auth_start_time = base::TimeTicks::Now(); |
| 383 DVLOG(1) << "AudioRendererHost@" << this << "::OnRequestDeviceAuthorization" | 383 DVLOG(1) << "AudioRendererHost@" << this << "::OnRequestDeviceAuthorization" |
| 384 << "(stream_id=" << stream_id | 384 << "(stream_id=" << stream_id |
| 385 << ", render_frame_id=" << render_frame_id | 385 << ", render_frame_id=" << render_frame_id |
| 386 << ", session_id=" << session_id << ", device_id=" << device_id | 386 << ", session_id=" << session_id << ", device_id=" << device_id |
| 387 << ", security_origin=" << security_origin << ")"; | 387 << ", security_origin=" << security_origin << ")"; |
| 388 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) | 388 if (LookupById(stream_id) || IsAuthorizationStarted(stream_id)) |
| 389 return; | 389 return; |
| 390 authorizations_.insert(MakeAuthorizationData(stream_id, false, device_id)); | 390 authorizations_.insert(MakeAuthorizationData(stream_id)); |
| 391 // Unretained is ok here since |this| owns |authorization_handler_| and | 391 // Unretained is ok here since |this| owns |authorization_handler_| and |
| 392 // |authorization_handler_| owns the callback. | 392 // |authorization_handler_| owns the callback. |
| 393 authorization_handler_.RequestDeviceAuthorization( | 393 authorization_handler_.RequestDeviceAuthorization( |
| 394 render_frame_id, session_id, device_id, security_origin, | 394 render_frame_id, session_id, device_id, security_origin, |
| 395 base::Bind(&AudioRendererHost::AuthorizationCompleted, | 395 base::Bind(&AudioRendererHost::AuthorizationCompleted, |
| 396 base::Unretained(this), stream_id, security_origin, | 396 base::Unretained(this), stream_id, security_origin, |
| 397 auth_start_time)); | 397 auth_start_time)); |
| 398 } | 398 } |
| 399 | 399 |
| 400 void AudioRendererHost::AuthorizationCompleted( | 400 void AudioRendererHost::AuthorizationCompleted( |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 } | 650 } |
| 651 | 651 |
| 652 bool AudioRendererHost::HasActiveAudio() { | 652 bool AudioRendererHost::HasActiveAudio() { |
| 653 return !base::AtomicRefCountIsZero(&num_playing_streams_); | 653 return !base::AtomicRefCountIsZero(&num_playing_streams_); |
| 654 } | 654 } |
| 655 | 655 |
| 656 void AudioRendererHost::OverrideDevicePermissionsForTesting(bool has_access) { | 656 void AudioRendererHost::OverrideDevicePermissionsForTesting(bool has_access) { |
| 657 authorization_handler_.OverridePermissionsForTesting(has_access); | 657 authorization_handler_.OverridePermissionsForTesting(has_access); |
| 658 } | 658 } |
| 659 } // namespace content | 659 } // namespace content |
| OLD | NEW |