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

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: Fixed bad rebase merge Created 5 years, 2 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
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 df16bce5d9655443698009f1fc8820c89bc1a94f..8555aab6ada708b02cbccd2d85d83c5eb49fbf07 100644
--- a/content/browser/renderer_host/media/audio_renderer_host.cc
+++ b/content/browser/renderer_host/media/audio_renderer_host.cc
@@ -104,6 +104,16 @@ std::string TranslateDefaultId(const std::string& device_id) {
: device_id;
}
+void NotifyRenderProcessHostThatAudioStateChanged(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->AudioStateChanged();
+}
+
} // namespace
class AudioRendererHost::AudioEntry
@@ -756,11 +766,27 @@ void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry,
!RenderFrameHasActiveAudio(entry->render_frame_id());
entry->set_playing(true);
base::AtomicRefCountInc(&num_playing_streams_);
+
+ // Inform the RenderProcessHost when audio starts playing for the first
+ // time.
+ if (base::AtomicRefCountIsOne(&num_playing_streams_)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
+ render_process_id_));
+ }
} else {
entry->set_playing(false);
should_alert_resource_scheduler =
!RenderFrameHasActiveAudio(entry->render_frame_id());
- base::AtomicRefCountDec(&num_playing_streams_);
+
+ // Inform the RenderProcessHost when there is no more audio playing.
+ if (!base::AtomicRefCountDec(&num_playing_streams_)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&NotifyRenderProcessHostThatAudioStateChanged,
+ render_process_id_));
+ }
}
if (should_alert_resource_scheduler && ResourceDispatcherHostImpl::Get()) {
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698