summaryrefslogtreecommitdiffstats
path: root/content/browser/media
diff options
context:
space:
mode:
authortoyoshim <toyoshim@chromium.org>2015-10-06 00:54:21 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-06 07:55:28 +0000
commit29aaa95a4444e6d4ce9bb789cc7996821f044e52 (patch)
treeba5f25ae3f4bbc0b927f036ec34d34ab3554128b /content/browser/media
parent20783544a35e815bd4ddfcf9bfae447d0778b9ca (diff)
downloadchromium_src-29aaa95a4444e6d4ce9bb789cc7996821f044e52.zip
chromium_src-29aaa95a4444e6d4ce9bb789cc7996821f044e52.tar.gz
chromium_src-29aaa95a4444e6d4ce9bb789cc7996821f044e52.tar.bz2
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}
Diffstat (limited to 'content/browser/media')
-rw-r--r--content/browser/media/midi_host.cc17
-rw-r--r--content/browser/media/midi_host.h5
-rw-r--r--content/browser/media/midi_host_unittest.cc4
3 files changed, 19 insertions, 7 deletions
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<uint8>& data) {
bool in_sysex = false;
diff --git a/content/browser/media/midi_host.h b/content/browser/media/midi_host.h
index c6ff3ea..a536ebe 100644
--- a/content/browser/media/midi_host.h
+++ b/content/browser/media/midi_host.h
@@ -50,6 +50,7 @@ class CONTENT_EXPORT MidiHost : public BrowserMessageFilter,
size_t length,
double timestamp) override;
void AccumulateMidiBytesSent(size_t n) override;
+ void Detach() override;
// Start session to access MIDI hardware.
void OnStartSession();
@@ -70,7 +71,7 @@ class CONTENT_EXPORT MidiHost : public BrowserMessageFilter,
friend class BrowserThread;
// Returns true if |data| fulfills the requirements of MidiOutput.send API
- // defined in the WebMIDI spec.
+ // defined in the Web MIDI spec.
// - |data| must be any number of complete MIDI messages (data abbreviation
// called "running status" is disallowed).
// - 1-byte MIDI realtime messages can be placed at any position of |data|.
@@ -90,7 +91,7 @@ class CONTENT_EXPORT MidiHost : public BrowserMessageFilter,
// does not support MIDI. If not supported then a call to
// OnRequestAccess() will always refuse access and a call to
// OnSendData() will do nothing.
- media::midi::MidiManager* const midi_manager_;
+ media::midi::MidiManager* midi_manager_;
// Buffers where data sent from each MIDI input port is stored.
ScopedVector<media::midi::MidiMessageQueue> received_messages_queues_;
diff --git a/content/browser/media/midi_host_unittest.cc b/content/browser/media/midi_host_unittest.cc
index bfe0c2f..05f2dfe 100644
--- a/content/browser/media/midi_host_unittest.cc
+++ b/content/browser/media/midi_host_unittest.cc
@@ -104,6 +104,10 @@ class MidiHostTest : public testing::Test {
host_(new MidiHostForTesting(kRenderProcessId, &manager_)),
data_(kNoteOn, kNoteOn + arraysize(kNoteOn)),
port_id_(0) {}
+ ~MidiHostTest() override {
+ manager_.Shutdown();
+ RunLoopUntilIdle();
+ }
protected:
void AddOutputPort() {