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

Side by Side Diff: Source/modules/webmidi/MIDIAccess.h

Issue 77773003: Make WebMIDI use blink Promise. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Reduce protect(this). Created 6 years, 10 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 13 matching lines...) Expand all
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef MIDIAccess_h 31 #ifndef MIDIAccess_h
32 #define MIDIAccess_h 32 #define MIDIAccess_h
33 33
34 #include "bindings/v8/MIDIAccessResolver.h"
35 #include "bindings/v8/ScriptPromise.h"
34 #include "bindings/v8/ScriptWrappable.h" 36 #include "bindings/v8/ScriptWrappable.h"
35 #include "core/dom/ActiveDOMObject.h" 37 #include "core/dom/ActiveDOMObject.h"
36 #include "core/events/EventTarget.h" 38 #include "core/events/EventTarget.h"
37 #include "heap/Handle.h" 39 #include "heap/Handle.h"
38 #include "modules/webmidi/MIDIAccessor.h" 40 #include "modules/webmidi/MIDIAccessor.h"
39 #include "modules/webmidi/MIDIAccessorClient.h" 41 #include "modules/webmidi/MIDIAccessorClient.h"
40 #include "modules/webmidi/MIDIInput.h" 42 #include "modules/webmidi/MIDIInput.h"
43 #include "modules/webmidi/MIDIOptions.h"
41 #include "modules/webmidi/MIDIOutput.h" 44 #include "modules/webmidi/MIDIOutput.h"
45 #include "platform/Timer.h"
42 #include "wtf/RefCounted.h" 46 #include "wtf/RefCounted.h"
43 #include "wtf/RefPtr.h" 47 #include "wtf/RefPtr.h"
44 #include "wtf/Vector.h" 48 #include "wtf/Vector.h"
45 49
46 namespace WebCore { 50 namespace WebCore {
47 51
48 class ExecutionContext; 52 class ExecutionContext;
49 class MIDIAccessPromise;
50 53
51 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn lineData, public MIDIAccessorClient { 54 class MIDIAccess FINAL : public RefCountedWillBeRefCountedGarbageCollected<MIDIA ccess>, public ScriptWrappable, public ActiveDOMObject, public EventTargetWithIn lineData, public MIDIAccessorClient {
52 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M IDIAccess>); 55 DEFINE_EVENT_TARGET_REFCOUNTING(RefCountedWillBeRefCountedGarbageCollected<M IDIAccess>);
53 public: 56 public:
54 virtual ~MIDIAccess(); 57 virtual ~MIDIAccess();
55 static PassRefPtrWillBeRawPtr<MIDIAccess> create(ExecutionContext*, MIDIAcce ssPromise*); 58 static PassRefPtrWillBeRawPtr<MIDIAccess> create(const MIDIOptions&, Executi onContext*);
56 59
57 MIDIInputVector inputs() const { return m_inputs; } 60 MIDIInputVector inputs() const { return m_inputs; }
58 MIDIOutputVector outputs() const { return m_outputs; } 61 MIDIOutputVector outputs() const { return m_outputs; }
59 62
60 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect); 63 DEFINE_ATTRIBUTE_EVENT_LISTENER(connect);
61 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect); 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(disconnect);
62 65
63 void setSysExEnabled(bool); 66 void setSysExEnabled(bool);
64 bool sysExEnabled() const { return m_sysExEnabled; } 67 bool sysExEnabled() const { return m_sysExEnabled; }
65 68
66 // EventTarget 69 // EventTarget
67 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; } 70 virtual const AtomicString& interfaceName() const OVERRIDE { return EventTar getNames::MIDIAccess; }
68 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); } 71 virtual ExecutionContext* executionContext() const OVERRIDE { return ActiveD OMObject::executionContext(); }
69 72
70 // ActiveDOMObject 73 // ActiveDOMObject
74 virtual void suspend() OVERRIDE;
75 virtual void resume() OVERRIDE;
71 virtual void stop() OVERRIDE; 76 virtual void stop() OVERRIDE;
72 77
73 // MIDIAccessorClient 78 // MIDIAccessorClient
74 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE; 79 virtual void didAddInputPort(const String& id, const String& manufacturer, c onst String& name, const String& version) OVERRIDE;
75 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE; 80 virtual void didAddOutputPort(const String& id, const String& manufacturer, const String& name, const String& version) OVERRIDE;
76 virtual void didStartSession(bool success) OVERRIDE; 81 virtual void didStartSession(bool success) OVERRIDE;
77 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE; 82 virtual void didReceiveMIDIData(unsigned portIndex, const unsigned char* dat a, size_t length, double timeStamp) OVERRIDE;
78 83
79 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now(). 84 // |timeStampInMilliseconds| is in the same time coordinate system as perfor mance.now().
80 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds); 85 void sendMIDIData(unsigned portIndex, const unsigned char* data, size_t leng th, double timeStampInMilliseconds);
81 86
82 void trace(Visitor*); 87 void trace(Visitor*);
88 ScriptPromise startRequest();
83 89
84 private: 90 private:
85 MIDIAccess(ExecutionContext*, MIDIAccessPromise*); 91 enum ActiveDOMObjectState {
92 Active,
93 Suspended,
94 Stopped,
95 };
96 enum PromiseState {
97 Pending,
98 Resolving,
99 Rejecting,
100 ResolvedOrRejected,
101 };
haraken 2014/02/26 11:30:39 This kind of state management looks too complicate
86 102
87 void startRequest(); 103 MIDIAccess(const MIDIOptions&, ExecutionContext*);
104
88 void permissionDenied(); 105 void permissionDenied();
89 106
107 void setRequesting(bool);
108
109 void resolve();
110 void reject(PassRefPtr<DOMError>);
111 void resolveNow();
112 void rejectNow(PassRefPtr<DOMError>);
113
114 void resumeTimerFired(Timer<MIDIAccess>*);
115
116 ActiveDOMObjectState m_activeDOMObjectState;
117 PromiseState m_promiseState;
90 MIDIInputVector m_inputs; 118 MIDIInputVector m_inputs;
91 MIDIOutputVector m_outputs; 119 MIDIOutputVector m_outputs;
92 RawPtrWillBeMember<MIDIAccessPromise> m_promise;
93 120
94 OwnPtr<MIDIAccessor> m_accessor; 121 OwnPtr<MIDIAccessor> m_accessor;
122 OwnPtr<MIDIAccessResolver> m_resolver;
123 MIDIOptions m_options;
95 bool m_hasAccess; 124 bool m_hasAccess;
96 bool m_sysExEnabled; 125 bool m_sysExEnabled;
97 bool m_requesting; 126 bool m_requesting;
127 Timer<MIDIAccess> m_resumeTimer;
128 RefPtr<DOMError> m_error;
98 }; 129 };
99 130
100 } // namespace WebCore 131 } // namespace WebCore
101 132
102 #endif // MIDIAccess_h 133 #endif // MIDIAccess_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698