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

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

Issue 1576323002: Prevent a race condition with MidiHost IPC sending. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: style Created 4 years, 11 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 | « content/browser/media/midi_host.h ('k') | media/midi/midi_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/media/midi_host.cc
diff --git a/content/browser/media/midi_host.cc b/content/browser/media/midi_host.cc
index 1e6de1e234f1b6b5eebdf01a97c68de307b3a139..30261ef7f35475ff060fa87dd61433ed90c1befd 100644
--- a/content/browser/media/midi_host.cc
+++ b/content/browser/media/midi_host.cc
@@ -59,10 +59,19 @@ MidiHost::MidiHost(int renderer_process_id,
DCHECK(midi_manager_);
}
-MidiHost::~MidiHost() {
- // Close an open session, or abort opening a session.
- if (is_session_requested_ && midi_manager_)
+MidiHost::~MidiHost() = default;
+
+void MidiHost::OnChannelClosing() {
+ // If we get here the MidiHost is going to be destroyed soon. Prevent any
+ // subsequent calls from MidiManager by closing our session.
+ // If Send() is called from a different thread (e.g. a separate thread owned
+ // by the MidiManager implementation), it will get posted to the IO thread.
+ // There is a race condition here if our refcount is 0 and we're about to or
+ // have already entered OnDestruct().
+ if (is_session_requested_ && midi_manager_) {
midi_manager_->EndSession(this);
+ is_session_requested_ = false;
+ }
}
void MidiHost::OnDestruct() const {
« no previous file with comments | « content/browser/media/midi_host.h ('k') | media/midi/midi_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698