| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef Mojo_h |
| 6 #define Mojo_h |
| 7 |
| 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "core/mojo/MojoHandleWatcher.h" |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 class DOMArrayBuffer; |
| 14 class MojoCreateMessagePipeOptions; |
| 15 class MojoCreateMessagePipeResult; |
| 16 class MojoHandle; |
| 17 class MojoMessagePipeHandle; |
| 18 class MojoReadMessageResult; |
| 19 class MojoWatchCallback; |
| 20 class ScriptState; |
| 21 |
| 22 class Mojo final : public GarbageCollectedFinalized<Mojo>, |
| 23 public ScriptWrappable { |
| 24 DEFINE_WRAPPERTYPEINFO(); |
| 25 |
| 26 public: |
| 27 CORE_EXPORT static Mojo* create(); |
| 28 virtual ~Mojo(); |
| 29 |
| 30 // MojoResult |
| 31 static const MojoResult kResultOk = MOJO_HANDLE_SIGNAL_NONE; |
| 32 static const MojoResult kResultCancelled = MOJO_RESULT_CANCELLED; |
| 33 static const MojoResult kResultUnknown = MOJO_RESULT_UNKNOWN; |
| 34 static const MojoResult kResultInvalidArgument = MOJO_RESULT_INVALID_ARGUMENT; |
| 35 static const MojoResult kResultDeadlineExceeded = |
| 36 MOJO_RESULT_DEADLINE_EXCEEDED; |
| 37 static const MojoResult kResultNotFound = MOJO_RESULT_NOT_FOUND; |
| 38 static const MojoResult kResultAlreadyExists = MOJO_RESULT_ALREADY_EXISTS; |
| 39 static const MojoResult kResultPermissionDenied = |
| 40 MOJO_RESULT_PERMISSION_DENIED; |
| 41 static const MojoResult kResultResourceExhausted = |
| 42 MOJO_RESULT_RESOURCE_EXHAUSTED; |
| 43 static const MojoResult kResultFailedPrecondition = |
| 44 MOJO_RESULT_FAILED_PRECONDITION; |
| 45 static const MojoResult kResultAborted = MOJO_RESULT_ABORTED; |
| 46 static const MojoResult kResultOutOfRange = MOJO_RESULT_OUT_OF_RANGE; |
| 47 static const MojoResult kResultUnimplemented = MOJO_RESULT_UNIMPLEMENTED; |
| 48 static const MojoResult kResultInternal = MOJO_RESULT_INTERNAL; |
| 49 static const MojoResult kResultUnavailable = MOJO_RESULT_UNAVAILABLE; |
| 50 static const MojoResult kResultDataLoss = MOJO_RESULT_DATA_LOSS; |
| 51 static const MojoResult kResultBusy = MOJO_RESULT_BUSY; |
| 52 static const MojoResult kResultShouldWait = MOJO_RESULT_SHOULD_WAIT; |
| 53 |
| 54 // MojoHandleSignals |
| 55 static const MojoHandleSignals kHandleSignalNone = MOJO_HANDLE_SIGNAL_NONE; |
| 56 static const MojoHandleSignals kHandleSignalReadable = |
| 57 MOJO_HANDLE_SIGNAL_READABLE; |
| 58 static const MojoHandleSignals kHandleSignalWritable = |
| 59 MOJO_HANDLE_SIGNAL_WRITABLE; |
| 60 static const MojoHandleSignals kHandleSignalPeerClosed = |
| 61 MOJO_HANDLE_SIGNAL_PEER_CLOSED; |
| 62 |
| 63 // MessagePipe flags. |
| 64 static const MojoCreateMessagePipeOptionsFlags |
| 65 kCreateMessagePipeOptionsFlagNone = |
| 66 MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE; |
| 67 static const MojoWriteMessageFlags kWriteMessageFlagNone = |
| 68 MOJO_WRITE_MESSAGE_FLAG_NONE; |
| 69 static const MojoReadMessageFlags kReadMessageFlagNone = |
| 70 MOJO_READ_MESSAGE_FLAG_NONE; |
| 71 static const MojoReadMessageFlags kReadMessageFlagMayDiscard = |
| 72 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD; |
| 73 |
| 74 unsigned watch(ScriptState*, |
| 75 MojoHandle*, |
| 76 MojoHandleSignals, |
| 77 MojoWatchCallback*); |
| 78 void cancelWatch(unsigned watchId); |
| 79 |
| 80 void createMessagePipe(const MojoCreateMessagePipeOptions&, |
| 81 MojoCreateMessagePipeResult&); |
| 82 MojoResult writeMessage(MojoMessagePipeHandle*, |
| 83 DOMArrayBuffer*, |
| 84 const HeapVector<Member<MojoHandle>>&, |
| 85 MojoWriteMessageFlags); |
| 86 void readMessage(MojoMessagePipeHandle*, |
| 87 MojoReadMessageFlags, |
| 88 MojoReadMessageResult&); |
| 89 |
| 90 DECLARE_TRACE(); |
| 91 |
| 92 private: |
| 93 class WatchEntry : public GarbageCollectedFinalized<WatchEntry> { |
| 94 public: |
| 95 WatchEntry(WebTaskRunner* taskRunner) : m_watcher(taskRunner) {} |
| 96 DECLARE_TRACE(); |
| 97 |
| 98 private: |
| 99 friend class Mojo; |
| 100 MojoHandleWatcher m_watcher; |
| 101 RefPtr<ScriptState> m_scriptState; |
| 102 Member<MojoWatchCallback> m_callback; |
| 103 }; |
| 104 using WatchMap = HeapHashMap<unsigned, Member<WatchEntry>>; |
| 105 |
| 106 Mojo(std::unique_ptr<WebTaskRunner>); |
| 107 void watchCallback(unsigned, MojoResult); |
| 108 |
| 109 std::unique_ptr<WebTaskRunner> m_taskRunner; |
| 110 unsigned m_nextWatchId; |
| 111 WatchMap m_watchMap; |
| 112 }; |
| 113 |
| 114 } // namespace blink |
| 115 |
| 116 #endif // Mojo_h |
| OLD | NEW |