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

Unified Diff: content/browser/media/audio_stream_monitor.cc

Issue 2698813007: Fix teardown of stale AudioStreamMonitor poll callbacks. (Closed)
Patch Set: Created 3 years, 10 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/media/audio_stream_monitor.cc
diff --git a/content/browser/media/audio_stream_monitor.cc b/content/browser/media/audio_stream_monitor.cc
index f2782a6be18f5ebe2fccfa2fff1d87c686a816e6..61f55f77a9d0746e179865ba0d08edfd2ea39155 100644
--- a/content/browser/media/audio_stream_monitor.cc
+++ b/content/browser/media/audio_stream_monitor.cc
@@ -65,6 +65,29 @@ bool AudioStreamMonitor::IsCurrentlyAudible() const {
return is_audible_;
}
+void AudioStreamMonitor::RenderProcessGone(int render_process_id) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // Note: It's possible for the RenderProcessHost and WebContents (and thus
+ // this class) to survive the death of the render process and subsequently be
+ // reused. During this period StartStopMonitoringHelper() will be unable to
+ // lookup the WebContents using the now-dead |render_frame_id|. We must thus
+ // have this secondary mechanism for clearing stale callbacks.
+
+ for (auto it = poll_callbacks_.begin(); it != poll_callbacks_.end();) {
+ if (it->first.first == render_process_id) {
+ it = poll_callbacks_.erase(it);
+ if (!power_level_monitoring_available())
+ OnStreamRemoved();
+ } else {
+ ++it;
+ }
+ }
+
+ if (poll_callbacks_.empty())
+ poll_timer_.Stop();
+}
+
// static
void AudioStreamMonitor::StartMonitoringStream(
int render_process_id,
@@ -147,10 +170,12 @@ void AudioStreamMonitor::StopMonitoringStreamOnUIThread(int render_process_id,
int stream_id) {
DCHECK(thread_checker_.CalledOnValidThread());
- const StreamID qualified_id(render_process_id, stream_id);
- DCHECK(poll_callbacks_.find(qualified_id) != poll_callbacks_.end());
- poll_callbacks_.erase(qualified_id);
+ // In the event of render process death, these may have already been cleared.
+ auto it = poll_callbacks_.find(StreamID(render_process_id, stream_id));
+ if (it == poll_callbacks_.end())
+ return;
+ poll_callbacks_.erase(it);
if (poll_callbacks_.empty())
poll_timer_.Stop();
}

Powered by Google App Engine
This is Rietveld 408576698