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

Unified Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 1214883004: Fixed the audio backgrounding bug (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a check to null before calling the render_process_host Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()) {
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698