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

Unified Diff: media/midi/midi_manager.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.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/midi/midi_manager.cc
diff --git a/media/midi/midi_manager.cc b/media/midi/midi_manager.cc
index 21f6c2309d77e684373f2ebb5ad01c9c8f9a574c..55b5a3777d19531f3155f2771389786df1e11a08 100644
--- a/media/midi/midi_manager.cc
+++ b/media/midi/midi_manager.cc
@@ -126,11 +126,14 @@ void MidiManager::StartSession(MidiManagerClient* client) {
pending_clients_.insert(client);
}
}
+
+ if (completion == Completion::COMPLETE_SYNCHRONOUSLY) {
+ client->CompleteStartSession(result);
+ return;
+ }
}
- if (completion == Completion::COMPLETE_SYNCHRONOUSLY) {
- client->CompleteStartSession(result);
- } else if (completion == Completion::INVOKE_INITIALIZATION) {
+ if (completion == Completion::INVOKE_INITIALIZATION) {
// Lazily initialize the MIDI back-end.
TRACE_EVENT0("midi", "MidiManager::StartInitialization");
// CompleteInitialization() will be called asynchronously when platform
@@ -143,7 +146,8 @@ void MidiManager::EndSession(MidiManagerClient* client) {
ReportUsage(Usage::SESSION_ENDED);
// At this point, |client| can be in the destruction process, and calling
- // any method of |client| is dangerous.
+ // any method of |client| is dangerous. Calls on clients *must* be protected
+ // by |lock_| to prevent race conditions.
base::AutoLock auto_lock(lock_);
clients_.erase(client);
pending_clients_.erase(client);
@@ -156,9 +160,6 @@ void MidiManager::AccumulateMidiBytesSent(MidiManagerClient* client, size_t n) {
// Continue to hold lock_ here in case another thread is currently doing
// EndSession.
- // Note that if we are in EndSession, then a destructor is being called and
- // it isn't really safe to call this method. But we don't have another way to
- // check this right now.
client->AccumulateMidiBytesSent(n);
}
« no previous file with comments | « content/browser/media/midi_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698