Chromium Code Reviews| Index: Source/modules/webmidi/MIDIAccessFuture.cpp |
| diff --git a/Source/modules/webmidi/MIDIAccessFuture.cpp b/Source/modules/webmidi/MIDIAccessFuture.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1e3df05b98297e3d6e6743656da9826a5f6451fe |
| --- /dev/null |
| +++ b/Source/modules/webmidi/MIDIAccessFuture.cpp |
| @@ -0,0 +1,97 @@ |
| +/* |
| + * Copyright (C) 2013 Google Inc. All rights reserved. |
| + * |
| + * Redistribution and use in source and binary forms, with or without |
| + * modification, are permitted provided that the following conditions are |
| + * met: |
| + * |
| + * * Redistributions of source code must retain the above copyright |
| + * notice, this list of conditions and the following disclaimer. |
| + * * Redistributions in binary form must reproduce the above |
| + * copyright notice, this list of conditions and the following disclaimer |
| + * in the documentation and/or other materials provided with the |
| + * distribution. |
| + * * Neither the name of Google Inc. nor the names of its |
| + * contributors may be used to endorse or promote products derived from |
| + * this software without specific prior written permission. |
| + * |
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| + */ |
| + |
| +#include "config.h" |
| +#include "modules/webmidi/MIDIAccessFuture.h" |
| + |
| +#include "core/dom/DOMError.h" |
| +#include "modules/webmidi/MIDIAccess.h" |
| +#include "modules/webmidi/MIDIErrorCallback.h" |
| +#include "modules/webmidi/MIDISuccessCallback.h" |
| + |
| +namespace WebCore { |
| + |
| +PassRefPtr<MIDIAccessFuture> MIDIAccessFuture::create(ScriptExecutionContext* context) |
| +{ |
| + return adoptRef(new MIDIAccessFuture(context)); |
| +} |
| + |
| +MIDIAccessFuture::MIDIAccessFuture(ScriptExecutionContext* context) |
| + : m_context(context) |
| + , m_state(Pending) |
| +{ |
| + ScriptWrappable::init(this); |
| +} |
| + |
| +void MIDIAccessFuture::done(PassRefPtr<MIDISuccessCallback> successCallback, PassRefPtr<MIDIErrorCallback> errorCallback) |
| +{ |
| + switch (m_state) { |
| + case Accepted: |
| + successCallback->scheduleCallback(m_context); |
| + m_state = Invoked; |
| + break; |
| + case Rejected: |
| + successCallback->scheduleCallback(m_context); |
|
Chris Rogers
2013/06/04 04:28:58
shouldn't this be errorCallback?
Takashi Toyoshima
2013/06/04 11:44:37
Done.
|
| + m_state = Invoked; |
| + break; |
| + case Pending: |
| + m_successCallback = successCallback; |
| + m_errorCallback = errorCallback; |
| + break; |
| + case Invoked: |
| + break; |
| + default: |
| + ASSERT_NOT_REACHED(); |
| + } |
| +} |
| + |
| +void MIDIAccessFuture::accept(MIDIOptions* options) |
| +{ |
| + if (m_state != Pending || !m_successCallback) |
|
dglazkov
2013/06/04 08:08:03
Should you clear error callback before returning?
Takashi Toyoshima
2013/06/04 11:44:37
Thank you.
I reconstruct this function to meet thi
|
| + return; |
| + m_state = Invoked; |
| + m_successCallback->handleEvent(MIDIAccess::create(m_context).leakRef(), options->sysexEnabled); |
| + m_successCallback.clear(); |
| + if (m_errorCallback) |
|
dglazkov
2013/06/04 08:08:03
Don't need this check, right?
Takashi Toyoshima
2013/06/04 11:44:37
Done.
|
| + m_errorCallback.clear(); |
| +} |
| + |
| +void MIDIAccessFuture::reject(DOMError* error) |
| +{ |
| + if (m_state != Pending || !m_errorCallback) |
|
dglazkov
2013/06/04 08:08:03
Should you clear success callback before returning
Takashi Toyoshima
2013/06/04 11:44:37
Done.
|
| + return; |
| + m_state = Invoked; |
| + m_errorCallback->handleEvent(error); |
| + m_errorCallback.clear(); |
| + if (m_successCallback) |
|
dglazkov
2013/06/04 08:08:03
Ditto.
Takashi Toyoshima
2013/06/04 11:44:37
Done.
|
| + m_successCallback.clear(); |
| +} |
| + |
| +} // namespace WebCore |