Chromium Code Reviews| Index: media/midi/midi_manager.cc |
| diff --git a/media/midi/midi_manager.cc b/media/midi/midi_manager.cc |
| index 67845cef08d5b2c49add1954b5041d96045e5676..28e4026204c60b90026843b375ea9a60c8f503fd 100644 |
| --- a/media/midi/midi_manager.cc |
| +++ b/media/midi/midi_manager.cc |
| @@ -4,7 +4,10 @@ |
| #include "media/midi/midi_manager.h" |
| +#include "base/bind.h" |
| #include "base/debug/trace_event.h" |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/message_loop/message_loop_proxy.h" |
| namespace media { |
| @@ -42,6 +45,8 @@ void MidiManager::StartSession(MidiManagerClient* client, int client_id) { |
| if (!session_is_ready) { |
| if (session_needs_initialization) { |
| TRACE_EVENT0("midi", "MidiManager::StartInitialization"); |
| + session_thread_runner_ = |
| + base::MessageLoop::current()->message_loop_proxy(); |
| StartInitialization(); |
| } |
| // CompleteInitialization() will be called asynchronously when platform |
| @@ -80,23 +85,15 @@ void MidiManager::StartInitialization() { |
| } |
| void MidiManager::CompleteInitialization(MidiResult result) { |
| - TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); |
| - |
| - base::AutoLock auto_lock(clients_lock_); |
| - DCHECK(clients_.empty()); |
| - DCHECK(!pending_clients_.empty()); |
| - DCHECK(!initialized_); |
| - initialized_ = true; |
| - result_ = result; |
| - |
| - for (PendingClientMap::iterator it = pending_clients_.begin(); |
| - it != pending_clients_.end(); |
| - ++it) { |
| - if (result_ == MIDI_OK) |
| - clients_.insert(it->second); |
| - it->second->CompleteStartSession(it->first, result_); |
| - } |
| - pending_clients_.clear(); |
| + DCHECK(session_thread_runner_.get()); |
| + // It is safe to post a task to the IO thread from here because the IO thread |
| + // should have stopped if the MidiManager is going to be destructed. |
| + session_thread_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind(&MidiManager::CompleteInitializationInternal, |
| + base::Unretained(this), |
| + result)); |
| + CompleteInitializationInternal(result); |
|
yukawa
2014/05/04 23:16:02
Do we intentionally call CompleteInitializationInt
Takashi Toyoshima
2014/05/05 00:45:08
Oops, I removed it once, but somehow restored...
T
|
| } |
| void MidiManager::AddInputPort(const MidiPortInfo& info) { |
| @@ -118,4 +115,24 @@ void MidiManager::ReceiveMidiData( |
| (*i)->ReceiveMidiData(port_index, data, length, timestamp); |
| } |
| +void MidiManager::CompleteInitializationInternal(MidiResult result) { |
| + TRACE_EVENT0("midi", "MidiManager::CompleteInitialization"); |
| + |
| + base::AutoLock auto_lock(clients_lock_); |
| + DCHECK(clients_.empty()); |
| + DCHECK(!pending_clients_.empty()); |
| + DCHECK(!initialized_); |
| + initialized_ = true; |
| + result_ = result; |
| + |
| + for (PendingClientMap::iterator it = pending_clients_.begin(); |
| + it != pending_clients_.end(); |
| + ++it) { |
| + if (result_ == MIDI_OK) |
| + clients_.insert(it->second); |
| + it->second->CompleteStartSession(it->first, result_); |
| + } |
| + pending_clients_.clear(); |
| +} |
| + |
| } // namespace media |