OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/media/midi_host.h" | 5 #include "content/browser/renderer_host/media/midi_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 input_ports, | 87 input_ports, |
88 output_ports)); | 88 output_ports)); |
89 } | 89 } |
90 | 90 |
91 void MIDIHost::OnSendData(int port, | 91 void MIDIHost::OnSendData(int port, |
92 const std::vector<uint8>& data, | 92 const std::vector<uint8>& data, |
93 double timestamp) { | 93 double timestamp) { |
94 if (!midi_manager_) | 94 if (!midi_manager_) |
95 return; | 95 return; |
96 | 96 |
| 97 if (data.empty()) |
| 98 return; |
| 99 |
97 base::AutoLock auto_lock(in_flight_lock_); | 100 base::AutoLock auto_lock(in_flight_lock_); |
98 | 101 |
99 // Sanity check that we won't send too much. | 102 // Sanity check that we won't send too much. |
100 if (sent_bytes_in_flight_ > kMaxInFlightBytes || | 103 if (sent_bytes_in_flight_ > kMaxInFlightBytes || |
101 data.size() > kMaxInFlightBytes || | 104 data.size() > kMaxInFlightBytes || |
102 data.size() + sent_bytes_in_flight_ > kMaxInFlightBytes) | 105 data.size() + sent_bytes_in_flight_ > kMaxInFlightBytes) |
103 return; | 106 return; |
104 | 107 |
105 // For now disallow all System Exclusive messages even if we | 108 // For now disallow all System Exclusive messages even if we |
106 // have permission. | 109 // have permission. |
107 // TODO(toyoshim): allow System Exclusive if browser has granted | 110 // TODO(toyoshim): allow System Exclusive if browser has granted |
108 // this client access. We'll likely need to pass a GURL | 111 // this client access. We'll likely need to pass a GURL |
109 // here to compare against our permissions. | 112 // here to compare against our permissions. |
110 if (data.size() > 0 && data[0] >= kSysExMessage) | 113 if (data[0] >= kSysExMessage) |
111 return; | 114 return; |
112 | 115 |
113 #if defined(OS_ANDROID) | |
114 // TODO(toyoshim): figure out why data() method does not compile on Android. | |
115 NOTIMPLEMENTED(); | |
116 #else | |
117 midi_manager_->DispatchSendMIDIData( | 116 midi_manager_->DispatchSendMIDIData( |
118 this, | 117 this, |
119 port, | 118 port, |
120 data.data(), | 119 &data[0], |
121 data.size(), | 120 data.size(), |
122 timestamp); | 121 timestamp); |
123 #endif | |
124 | 122 |
125 sent_bytes_in_flight_ += data.size(); | 123 sent_bytes_in_flight_ += data.size(); |
126 } | 124 } |
127 | 125 |
128 void MIDIHost::ReceiveMIDIData( | 126 void MIDIHost::ReceiveMIDIData( |
129 int port_index, | 127 int port_index, |
130 const uint8* data, | 128 const uint8* data, |
131 size_t length, | 129 size_t length, |
132 double timestamp) { | 130 double timestamp) { |
133 TRACE_EVENT0("midi", "MIDIHost::ReceiveMIDIData"); | 131 TRACE_EVENT0("midi", "MIDIHost::ReceiveMIDIData"); |
(...skipping 24 matching lines...) Expand all Loading... |
158 | 156 |
159 if (bytes_sent_since_last_acknowledgement_ >= | 157 if (bytes_sent_since_last_acknowledgement_ >= |
160 kAcknowledgementThresholdBytes) { | 158 kAcknowledgementThresholdBytes) { |
161 Send(new MIDIMsg_AcknowledgeSentData( | 159 Send(new MIDIMsg_AcknowledgeSentData( |
162 bytes_sent_since_last_acknowledgement_)); | 160 bytes_sent_since_last_acknowledgement_)); |
163 bytes_sent_since_last_acknowledgement_ = 0; | 161 bytes_sent_since_last_acknowledgement_ = 0; |
164 } | 162 } |
165 } | 163 } |
166 | 164 |
167 } // namespace content | 165 } // namespace content |
OLD | NEW |