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

Unified Diff: third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp

Issue 2438043003: Web MIDI: move device state adjustment code from content to Blink (Closed)
Patch Set: Created 4 years, 2 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/test/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp
diff --git a/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp b/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp
index df7fddf90a9548d0f84cba197e41c8f42dbe9ab0..7114293d871718dfddd3fc777f61bfedd00db624 100644
--- a/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp
+++ b/third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp
@@ -45,8 +45,20 @@
namespace blink {
+namespace {
+
using midi::mojom::PortState;
+// Since "open" status is separately managed per MIDIAccess instance, we do not
+// expose service level PortState directly.
+PortState ToDeviceState(PortState state) {
+ if (state == PortState::OPENED)
+ return PortState::CONNECTED;
+ return state;
+}
+
+} // namespace
+
MIDIAccess::MIDIAccess(
std::unique_ptr<MIDIAccessor> accessor,
bool sysexEnabled,
@@ -132,8 +144,8 @@ void MIDIAccess::didAddInputPort(const String& id,
const String& version,
PortState state) {
DCHECK(isMainThread());
- MIDIInput* port =
- MIDIInput::create(this, id, manufacturer, name, version, state);
+ MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version,
+ ToDeviceState(state));
m_inputs.append(port);
dispatchEvent(MIDIConnectionEvent::create(port));
}
@@ -146,7 +158,7 @@ void MIDIAccess::didAddOutputPort(const String& id,
DCHECK(isMainThread());
unsigned portIndex = m_outputs.size();
MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, name,
- version, state);
+ version, ToDeviceState(state));
m_outputs.append(port);
dispatchEvent(MIDIConnectionEvent::create(port));
}
@@ -156,7 +168,9 @@ void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state) {
if (portIndex >= m_inputs.size())
return;
- m_inputs[portIndex]->setState(state);
+ PortState deviceState = ToDeviceState(state);
+ if (m_inputs[portIndex]->getState() != deviceState)
+ m_inputs[portIndex]->setState(deviceState);
}
void MIDIAccess::didSetOutputPortState(unsigned portIndex, PortState state) {
@@ -164,7 +178,9 @@ void MIDIAccess::didSetOutputPortState(unsigned portIndex, PortState state) {
if (portIndex >= m_outputs.size())
return;
- m_outputs[portIndex]->setState(state);
+ PortState deviceState = ToDeviceState(state);
+ if (m_outputs[portIndex]->getState() != deviceState)
+ m_outputs[portIndex]->setState(deviceState);
}
void MIDIAccess::didReceiveMIDIData(unsigned portIndex,
« no previous file with comments | « content/test/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698