From 29aaa95a4444e6d4ce9bb789cc7996821f044e52 Mon Sep 17 00:00:00 2001 From: toyoshim Date: Tue, 6 Oct 2015 00:54:21 -0700 Subject: Web MIDI: introduce MidiManager::Shutdown to shutdown gracefully Platform dependent MidiManager implementations allocate extra threads lazily on the IO thread, but it does not have a chance to stop them correctly on the same IO thread, and stop it on the main thread. This patch introduces Shutdown() method to be called before the IO thread stopped so that the MidiManager implementations can stop the extra threads gracefully on the right thread. Platform specific fixes follow this change. BUG=374341 Review URL: https://codereview.chromium.org/1315793008 Cr-Commit-Position: refs/heads/master@{#352564} --- content/browser/media/midi_host.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'content/browser/media/midi_host.cc') diff --git a/content/browser/media/midi_host.cc b/content/browser/media/midi_host.cc index c26a719..bc697ed 100644 --- a/content/browser/media/midi_host.cc +++ b/content/browser/media/midi_host.cc @@ -56,12 +56,12 @@ MidiHost::MidiHost(int renderer_process_id, sent_bytes_in_flight_(0), bytes_sent_since_last_acknowledgement_(0), output_port_count_(0) { - CHECK(midi_manager_); + DCHECK(midi_manager_); } MidiHost::~MidiHost() { // Close an open session, or abort opening a session. - if (is_session_requested_) + if (is_session_requested_ && midi_manager_) midi_manager_->EndSession(this); } @@ -84,7 +84,8 @@ bool MidiHost::OnMessageReceived(const IPC::Message& message) { void MidiHost::OnStartSession() { is_session_requested_ = true; - midi_manager_->StartSession(this); + if (midi_manager_) + midi_manager_->StartSession(this); } void MidiHost::OnSendData(uint32 port, @@ -122,12 +123,14 @@ void MidiHost::OnSendData(uint32 port, return; sent_bytes_in_flight_ += data.size(); } - midi_manager_->DispatchSendMidiData(this, port, data, timestamp); + if (midi_manager_) + midi_manager_->DispatchSendMidiData(this, port, data, timestamp); } void MidiHost::OnEndSession() { is_session_requested_ = false; - midi_manager_->EndSession(this); + if (midi_manager_) + midi_manager_->EndSession(this); } void MidiHost::CompleteStartSession(media::midi::Result result) { @@ -216,6 +219,10 @@ void MidiHost::AccumulateMidiBytesSent(size_t n) { } } +void MidiHost::Detach() { + midi_manager_ = nullptr; +} + // static bool MidiHost::IsValidWebMIDIData(const std::vector& data) { bool in_sysex = false; -- cgit v1.1