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

Side by Side Diff: third_party/WebKit/Source/modules/webmidi/MIDIAccess.cpp

Issue 1901103006: Web MIDI: Replace ASSERT macros with DCHECK macros (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 if (outputs.size() != ids.size()) { 123 if (outputs.size() != ids.size()) {
124 // There is id duplication that violates the spec. 124 // There is id duplication that violates the spec.
125 outputs.clear(); 125 outputs.clear();
126 } 126 }
127 return new MIDIOutputMap(outputs); 127 return new MIDIOutputMap(outputs);
128 } 128 }
129 129
130 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version, PortState state) 130 void MIDIAccess::didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version, PortState state)
131 { 131 {
132 ASSERT(isMainThread()); 132 DCHECK(isMainThread());
133 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, s tate); 133 MIDIInput* port = MIDIInput::create(this, id, manufacturer, name, version, s tate);
134 m_inputs.append(port); 134 m_inputs.append(port);
135 dispatchEvent(MIDIConnectionEvent::create(port)); 135 dispatchEvent(MIDIConnectionEvent::create(port));
136 } 136 }
137 137
138 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version, PortState state) 138 void MIDIAccess::didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version, PortState state)
139 { 139 {
140 ASSERT(isMainThread()); 140 DCHECK(isMainThread());
141 unsigned portIndex = m_outputs.size(); 141 unsigned portIndex = m_outputs.size();
142 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, nam e, version, state); 142 MIDIOutput* port = MIDIOutput::create(this, portIndex, id, manufacturer, nam e, version, state);
143 m_outputs.append(port); 143 m_outputs.append(port);
144 dispatchEvent(MIDIConnectionEvent::create(port)); 144 dispatchEvent(MIDIConnectionEvent::create(port));
145 } 145 }
146 146
147 void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state) 147 void MIDIAccess::didSetInputPortState(unsigned portIndex, PortState state)
148 { 148 {
149 ASSERT(isMainThread()); 149 DCHECK(isMainThread());
150 if (portIndex >= m_inputs.size()) 150 if (portIndex >= m_inputs.size())
151 return; 151 return;
152 152
153 m_inputs[portIndex]->setState(state); 153 m_inputs[portIndex]->setState(state);
154 } 154 }
155 155
156 void MIDIAccess::didSetOutputPortState(unsigned portIndex, PortState state) 156 void MIDIAccess::didSetOutputPortState(unsigned portIndex, PortState state)
157 { 157 {
158 ASSERT(isMainThread()); 158 DCHECK(isMainThread());
159 if (portIndex >= m_outputs.size()) 159 if (portIndex >= m_outputs.size())
160 return; 160 return;
161 161
162 m_outputs[portIndex]->setState(state); 162 m_outputs[portIndex]->setState(state);
163 } 163 }
164 164
165 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) 165 void MIDIAccess::didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp)
166 { 166 {
167 ASSERT(isMainThread()); 167 DCHECK(isMainThread());
168 if (portIndex >= m_inputs.size()) 168 if (portIndex >= m_inputs.size())
169 return; 169 return;
170 170
171 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime() 171 // Convert from time in seconds which is based on the time coordinate system of monotonicallyIncreasingTime()
172 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now(). 172 // into time in milliseconds (a DOMHighResTimeStamp) according to the same t ime coordinate system as performance.now().
173 // This is how timestamps are defined in the Web MIDI spec. 173 // This is how timestamps are defined in the Web MIDI spec.
174 Document* document = toDocument(getExecutionContext()); 174 Document* document = toDocument(getExecutionContext());
175 ASSERT(document); 175 DCHECK(document);
176 176
177 double timeStampInMilliseconds = 1000 * document->loader()->timing().monoton icTimeToZeroBasedDocumentTime(timeStamp); 177 double timeStampInMilliseconds = 1000 * document->loader()->timing().monoton icTimeToZeroBasedDocumentTime(timeStamp);
178 178
179 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeStampIn Milliseconds); 179 m_inputs[portIndex]->didReceiveMIDIData(portIndex, data, length, timeStampIn Milliseconds);
180 } 180 }
181 181
182 void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz e_t length, double timeStampInMilliseconds) 182 void MIDIAccess::sendMIDIData(unsigned portIndex, const unsigned char* data, siz e_t length, double timeStampInMilliseconds)
183 { 183 {
184 if (!data || !length || portIndex >= m_outputs.size()) 184 if (!data || !length || portIndex >= m_outputs.size())
185 return; 185 return;
186 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to the same time coordinate system as performance.now() 186 // Convert from a time in milliseconds (a DOMHighResTimeStamp) according to the same time coordinate system as performance.now()
187 // into a time in seconds which is based on the time coordinate system of mo notonicallyIncreasingTime(). 187 // into a time in seconds which is based on the time coordinate system of mo notonicallyIncreasingTime().
188 double timeStamp; 188 double timeStamp;
189 189
190 if (!timeStampInMilliseconds) { 190 if (!timeStampInMilliseconds) {
191 // We treat a value of 0 (which is the default value) as special, meanin g "now". 191 // We treat a value of 0 (which is the default value) as special, meanin g "now".
192 // We need to translate it exactly to 0 seconds. 192 // We need to translate it exactly to 0 seconds.
193 timeStamp = 0; 193 timeStamp = 0;
194 } else { 194 } else {
195 Document* document = toDocument(getExecutionContext()); 195 Document* document = toDocument(getExecutionContext());
196 ASSERT(document); 196 DCHECK(document);
197 double documentStartTime = document->loader()->timing().referenceMonoton icTime(); 197 double documentStartTime = document->loader()->timing().referenceMonoton icTime();
198 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds; 198 timeStamp = documentStartTime + 0.001 * timeStampInMilliseconds;
199 } 199 }
200 200
201 m_accessor->sendMIDIData(portIndex, data, length, timeStamp); 201 m_accessor->sendMIDIData(portIndex, data, length, timeStamp);
202 } 202 }
203 203
204 void MIDIAccess::stop() 204 void MIDIAccess::stop()
205 { 205 {
206 m_accessor.clear(); 206 m_accessor.clear();
207 } 207 }
208 208
209 DEFINE_TRACE(MIDIAccess) 209 DEFINE_TRACE(MIDIAccess)
210 { 210 {
211 visitor->trace(m_inputs); 211 visitor->trace(m_inputs);
212 visitor->trace(m_outputs); 212 visitor->trace(m_outputs);
213 EventTargetWithInlineData::trace(visitor); 213 EventTargetWithInlineData::trace(visitor);
214 ActiveDOMObject::trace(visitor); 214 ActiveDOMObject::trace(visitor);
215 } 215 }
216 216
217 } // namespace blink 217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698