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

Side by Side Diff: third_party/WebKit/Source/core/mojo/Mojo.cpp

Issue 2732163002: Implements JS bindings for mojo data pipe. (Closed)
Patch Set: rebase Created 3 years, 9 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 // 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/Mojo.h" 5 #include "core/mojo/Mojo.h"
6 6
7 #include "core/mojo/MojoCreateDataPipeOptions.h"
8 #include "core/mojo/MojoCreateDataPipeResult.h"
7 #include "core/mojo/MojoCreateMessagePipeResult.h" 9 #include "core/mojo/MojoCreateMessagePipeResult.h"
8 #include "core/mojo/MojoCreateSharedBufferResult.h" 10 #include "core/mojo/MojoCreateSharedBufferResult.h"
9 #include "core/mojo/MojoHandle.h" 11 #include "core/mojo/MojoHandle.h"
10 12
11 namespace blink { 13 namespace blink {
12 14
13 // static 15 // static
14 void Mojo::createMessagePipe(MojoCreateMessagePipeResult& resultDict) { 16 void Mojo::createMessagePipe(MojoCreateMessagePipeResult& resultDict) {
15 MojoCreateMessagePipeOptions options = {0}; 17 MojoCreateMessagePipeOptions options = {0};
16 options.struct_size = sizeof(::MojoCreateMessagePipeOptions); 18 options.struct_size = sizeof(::MojoCreateMessagePipeOptions);
17 options.flags = MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE; 19 options.flags = MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE;
18 20
19 mojo::ScopedMessagePipeHandle handle0, handle1; 21 mojo::ScopedMessagePipeHandle handle0, handle1;
20 MojoResult result = mojo::CreateMessagePipe(&options, &handle0, &handle1); 22 MojoResult result = mojo::CreateMessagePipe(&options, &handle0, &handle1);
21 23
22 resultDict.setResult(result); 24 resultDict.setResult(result);
23 if (result == MOJO_RESULT_OK) { 25 if (result == MOJO_RESULT_OK) {
24 resultDict.setHandle0( 26 resultDict.setHandle0(
25 MojoHandle::create(mojo::ScopedHandle::From(std::move(handle0)))); 27 MojoHandle::create(mojo::ScopedHandle::From(std::move(handle0))));
26 resultDict.setHandle1( 28 resultDict.setHandle1(
27 MojoHandle::create(mojo::ScopedHandle::From(std::move(handle1)))); 29 MojoHandle::create(mojo::ScopedHandle::From(std::move(handle1))));
28 } 30 }
29 } 31 }
30 32
31 // static 33 // static
34 void Mojo::createDataPipe(const MojoCreateDataPipeOptions& optionsDict,
35 MojoCreateDataPipeResult& resultDict) {
36 ::MojoCreateDataPipeOptions options = {0};
37 options.struct_size = sizeof(options);
38 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE;
39 options.element_num_bytes = optionsDict.elementNumBytes();
40 options.capacity_num_bytes = optionsDict.capacityNumBytes();
41
42 mojo::ScopedDataPipeProducerHandle producer;
43 mojo::ScopedDataPipeConsumerHandle consumer;
44 MojoResult result = mojo::CreateDataPipe(&options, &producer, &consumer);
45 resultDict.setResult(result);
46 if (result == MOJO_RESULT_OK) {
47 resultDict.setProducer(
48 MojoHandle::create(mojo::ScopedHandle::From(std::move(producer))));
49 resultDict.setConsumer(
50 MojoHandle::create(mojo::ScopedHandle::From(std::move(consumer))));
51 }
52 }
53
54 // static
32 void Mojo::createSharedBuffer(unsigned numBytes, 55 void Mojo::createSharedBuffer(unsigned numBytes,
33 MojoCreateSharedBufferResult& resultDict) { 56 MojoCreateSharedBufferResult& resultDict) {
34 MojoCreateSharedBufferOptions* options = nullptr; 57 MojoCreateSharedBufferOptions* options = nullptr;
35 mojo::Handle handle; 58 mojo::Handle handle;
36 MojoResult result = 59 MojoResult result =
37 MojoCreateSharedBuffer(options, numBytes, handle.mutable_value()); 60 MojoCreateSharedBuffer(options, numBytes, handle.mutable_value());
38 61
39 resultDict.setResult(result); 62 resultDict.setResult(result);
40 if (result == MOJO_RESULT_OK) { 63 if (result == MOJO_RESULT_OK) {
41 resultDict.setHandle(MojoHandle::create(mojo::MakeScopedHandle(handle))); 64 resultDict.setHandle(MojoHandle::create(mojo::MakeScopedHandle(handle)));
42 } 65 }
43 } 66 }
44 67
45 } // namespace blink 68 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/mojo/Mojo.h ('k') | third_party/WebKit/Source/core/mojo/Mojo.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698