Chromium Code Reviews| Index: content/browser/renderer_host/media/audio_renderer_host.cc |
| diff --git a/content/browser/renderer_host/media/audio_renderer_host.cc b/content/browser/renderer_host/media/audio_renderer_host.cc |
| index dddeee21626a31f30aff5b4f749c396fcd5024b8..f71dcdf920592003b7daa7c8371891744944de86 100644 |
| --- a/content/browser/renderer_host/media/audio_renderer_host.cc |
| +++ b/content/browser/renderer_host/media/audio_renderer_host.cc |
| @@ -61,6 +61,26 @@ void NotifyResourceDispatcherOfAudioStateChange(int render_process_id, |
| render_process_id, render_view_id, is_playing); |
| } |
| +void NotifyRenderProcessHostThatAudioStarted(int render_process_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + RenderProcessHost* render_process_host = |
| + RenderProcessHost::FromID(render_process_id); |
| + |
| + if (render_process_host) |
| + render_process_host->AudioStarted(); |
| +} |
| + |
| +void NotifyRenderProcessHostThatAudioStopped(int render_process_id) { |
| + DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| + |
| + RenderProcessHost* render_process_host = |
| + RenderProcessHost::FromID(render_process_id); |
| + |
| + if (render_process_host) |
| + render_process_host->AudioStopped(); |
| +} |
| + |
| } // namespace |
| class AudioRendererHost::AudioEntry |
| @@ -651,11 +671,28 @@ void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry, |
| !RenderFrameHasActiveAudio(entry->render_frame_id()); |
| entry->set_playing(true); |
| base::AtomicRefCountInc(&num_playing_streams_); |
| + |
| + // Inform the renderer that audio started playing for the first time so the |
|
gab
2015/07/02 13:11:53
s/renderer/renderer host/
gab
2015/07/02 13:11:53
Since this comment is outside the "if", I'd s/that
sebsg
2015/07/06 18:24:53
Done.
sebsg
2015/07/06 18:24:53
Done.
|
| + // process can be un-backgrounded if necessary. |
|
gab
2015/07/02 13:11:53
Remove " so the process can be...". What the Rende
sebsg
2015/07/06 18:24:53
Done.
|
| + if (base::AtomicRefCountIsOne(&num_playing_streams_)) { |
|
gab
2015/07/06 17:24:09
Note that this depends on this thread being the on
sebsg
2015/07/06 18:24:53
Done.
|
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&NotifyRenderProcessHostThatAudioStarted, |
| + render_process_id_)); |
| + } |
| } else { |
| entry->set_playing(false); |
| should_alert_resource_scheduler = |
| !RenderFrameHasActiveAudio(entry->render_frame_id()); |
| - base::AtomicRefCountDec(&num_playing_streams_); |
| + |
| + // Inform the renderer that there is no more audio playing so the process |
|
gab
2015/07/02 13:11:53
s/that there is/when there is/
sebsg
2015/07/06 18:24:53
Done.
|
| + // can be backgrounded if possible. |
|
gab
2015/07/02 13:11:53
Remove " so the process (...)".
sebsg
2015/07/06 18:24:53
Done.
|
| + if (!base::AtomicRefCountDec(&num_playing_streams_)) { |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&NotifyRenderProcessHostThatAudioStopped, |
| + render_process_id_)); |
| + } |
| } |
| if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) { |