OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "core/mojo/MojoHandle.h" | 5 #include "core/mojo/MojoHandle.h" |
6 | 6 |
7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" | 7 #include "bindings/core/v8/ArrayBufferOrArrayBufferView.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
10 #include "core/dom/DOMArrayBufferView.h" | 10 #include "core/dom/DOMArrayBufferView.h" |
11 #include "core/mojo/MojoMapBufferResult.h" | |
11 #include "core/mojo/MojoReadMessageFlags.h" | 12 #include "core/mojo/MojoReadMessageFlags.h" |
12 #include "core/mojo/MojoReadMessageResult.h" | 13 #include "core/mojo/MojoReadMessageResult.h" |
14 #include "core/mojo/MojoSharedBuffer.h" | |
13 #include "core/mojo/MojoWatcher.h" | 15 #include "core/mojo/MojoWatcher.h" |
14 | 16 |
15 // Mojo messages typically do not contain many handles. In fact most | 17 // Mojo messages typically do not contain many handles. In fact most |
16 // messages do not contain any handle. An inline capacity of 4 should avoid | 18 // messages do not contain any handle. An inline capacity of 4 should avoid |
17 // heap allocation in vast majority of cases. | 19 // heap allocation in vast majority of cases. |
18 static const size_t kHandleVectorInlineCapacity = 4; | 20 static const size_t kHandleVectorInlineCapacity = 4; |
19 | 21 |
20 namespace blink { | 22 namespace blink { |
21 | 23 |
22 MojoHandle* MojoHandle::create(mojo::ScopedHandle handle) { | 24 MojoHandle* MojoHandle::create(mojo::ScopedHandle handle) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 for (size_t i = 0; i < numHandles; ++i) { | 87 for (size_t i = 0; i < numHandles; ++i) { |
86 handles[i] = | 88 handles[i] = |
87 MojoHandle::create(mojo::MakeScopedHandle(mojo::Handle(rawHandles[i]))); | 89 MojoHandle::create(mojo::MakeScopedHandle(mojo::Handle(rawHandles[i]))); |
88 } | 90 } |
89 | 91 |
90 resultDict.setResult(result); | 92 resultDict.setResult(result); |
91 resultDict.setBuffer(buffer); | 93 resultDict.setBuffer(buffer); |
92 resultDict.setHandles(handles); | 94 resultDict.setHandles(handles); |
93 } | 95 } |
94 | 96 |
97 void MojoHandle::mapBuffer(unsigned offset, | |
98 unsigned numBytes, | |
99 MojoMapBufferResult& resultDict) { | |
100 void* data = nullptr; | |
101 MojoResult result = MojoMapBuffer(m_handle->value(), offset, numBytes, &data, | |
102 MOJO_MAP_BUFFER_FLAG_NONE); | |
103 resultDict.setResult(result); | |
104 if (result == MOJO_RESULT_OK) { | |
105 // TODO(alokp): Check if we need to track all mappings so that they can be | |
alokp
2017/02/27 19:50:45
yzshen@: The current js-binding implementation doe
yzshen1
2017/02/27 21:05:27
The lifetime of mappings is not tied to that of th
| |
106 // unmapped when this handle is closed. | |
107 resultDict.setBuffer(new MojoSharedBuffer(data, numBytes)); | |
108 } | |
109 } | |
110 | |
95 } // namespace blink | 111 } // namespace blink |
OLD | NEW |