提交 989b29a6 编写于 作者: A Adam Barth

Merge pull request #2543 from abarth/update_mojo2

Update to mojo 891577b0517de5aeca538d99669787c6dc72412a
......@@ -19,7 +19,7 @@
vars = {
'chromium_git': 'https://chromium.googlesource.com',
'mojo_sdk_revision': '5c0d7cd229bff7e2dfbcdea8310592ec90482919',
'mojo_sdk_revision': '8d13caec84db234e320129722d2f0d5d873def11',
'base_revision': '6c89618151eb0e23d330778e6d6ea16fc6105010',
'skia_revision': 'ddf0713f0ba4ea75ca49a4ed6b4249eef72da1ce',
......
b76db373e90403dbf8f63d86efb80f07ae9b128c
\ No newline at end of file
891577b0517de5aeca538d99669787c6dc72412a
\ No newline at end of file
......@@ -226,4 +226,12 @@ public class HandleMock implements UntypedHandle, MessagePipeHandle,
// Do nothing.
}
/**
* @see SharedBufferHandle#getBufferInformation()
*/
@Override
public BufferInformation getBufferInformation() {
// Do nothing.
return null;
}
}
......@@ -24,6 +24,8 @@ import org.chromium.mojo.system.MojoResult;
import org.chromium.mojo.system.Pair;
import org.chromium.mojo.system.ResultAnd;
import org.chromium.mojo.system.SharedBufferHandle;
import org.chromium.mojo.system.SharedBufferHandle.BufferInformation;
import org.chromium.mojo.system.SharedBufferHandle.BufferInformationFlags;
import java.nio.ByteBuffer;
import java.util.ArrayList;
......@@ -535,6 +537,19 @@ public class CoreImplTest extends MojoTestCase {
checkSharing(newHandle, handle);
}
/**
* Testing {@link SharedBufferHandle}.
*/
@SmallTest
public void testSharedBufferInformation() {
Core core = CoreImpl.getInstance();
SharedBufferHandle handle = core.createSharedBuffer(null, 8);
addHandleToClose(handle);
BufferInformation information = handle.getBufferInformation();
assertEquals(BufferInformationFlags.NONE, information.getFlags());
assertEquals(8, information.getBufferSize());
}
/**
* Testing that invalid handle can be used with this implementation.
*/
......
......@@ -14,7 +14,13 @@
#include "base/message_loop/message_loop.h"
#include "jni/CoreImpl_jni.h"
#include "mojo/public/c/environment/async_waiter.h"
#include "mojo/public/c/system/core.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/c/system/wait.h"
#include "mojo/public/cpp/environment/environment.h"
namespace {
......@@ -400,6 +406,19 @@ static jint GetNativeBufferOffset(JNIEnv* env,
return alignment - offset;
}
static jobject GetBufferInformation(JNIEnv* env,
jobject jcaller,
jint mojo_handle) {
MojoBufferInformation buffer_information;
MojoResult result =
MojoGetBufferInformation(static_cast<MojoHandle>(mojo_handle),
&buffer_information, sizeof(buffer_information));
return Java_CoreImpl_newResultAndBufferInformation(
env, result, buffer_information.flags,
buffer_information.num_bytes)
.Release();
}
bool RegisterCoreImpl(JNIEnv* env) {
return RegisterNativesImpl(env);
}
......
......@@ -19,6 +19,8 @@ import org.chromium.mojo.system.Pair;
import org.chromium.mojo.system.ResultAnd;
import org.chromium.mojo.system.RunLoop;
import org.chromium.mojo.system.SharedBufferHandle;
import org.chromium.mojo.system.SharedBufferHandle.BufferInformation;
import org.chromium.mojo.system.SharedBufferHandle.BufferInformationFlags;
import org.chromium.mojo.system.SharedBufferHandle.DuplicateOptions;
import org.chromium.mojo.system.SharedBufferHandle.MapFlags;
import org.chromium.mojo.system.UntypedHandle;
......@@ -469,6 +471,17 @@ public class CoreImpl implements Core, AsyncWaiter {
}
}
/**
* @see SharedBufferHandle#getBufferInformation()
*/
BufferInformation getBufferInformation(SharedBufferHandleImpl handle) {
ResultAnd<BufferInformation> result = nativeGetBufferInformation(handle.getMojoHandle());
if (result.getMojoResult() != MojoResult.OK) {
throw new MojoException(result.getMojoResult());
}
return result.getValue();
}
/**
* @return the mojo handle associated to the given handle, considering invalid handles.
*/
......@@ -565,6 +578,13 @@ public class CoreImpl implements Core, AsyncWaiter {
return new ResultAnd<>(mojoResult, buffer);
}
@CalledByNative
private static ResultAnd<BufferInformation> newResultAndBufferInformation(
int mojoResult, int flags, long bufferSize) {
return new ResultAnd<>(
mojoResult, new BufferInformation(new BufferInformationFlags(flags), bufferSize));
}
/**
* Trivial alias for Pair<Integer, Integer>. This is needed because our jni generator is unable
* to handle class that contains space.
......@@ -645,4 +665,6 @@ public class CoreImpl implements Core, AsyncWaiter {
private native void nativeCancelAsyncWait(long mId, long dataPtr);
private native int nativeGetNativeBufferOffset(ByteBuffer buffer, int alignment);
private native ResultAnd<BufferInformation> nativeGetBufferInformation(int mojoHandle);
}
......@@ -59,4 +59,11 @@ class SharedBufferHandleImpl extends HandleBase implements SharedBufferHandle {
mCore.unmap(buffer);
}
/**
* @see SharedBufferHandle#getBufferInformation()
*/
@Override
public BufferInformation getBufferInformation() {
return mCore.getBufferInformation(this);
}
}
......@@ -7,11 +7,12 @@
#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/debug/stack_trace.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/message_pipe.h"
namespace mojo {
......@@ -23,7 +24,7 @@ void ApplicationImpl::Terminate() {
ApplicationRunnerChromium::ApplicationRunnerChromium(
ApplicationDelegate* delegate)
: delegate_(scoped_ptr<ApplicationDelegate>(delegate)),
: delegate_(delegate),
message_loop_type_(base::MessageLoop::TYPE_CUSTOM),
has_run_(false) {}
......@@ -50,7 +51,7 @@ MojoResult ApplicationRunnerChromium::Run(
#endif
{
scoped_ptr<base::MessageLoop> loop;
std::unique_ptr<base::MessageLoop> loop;
if (message_loop_type_ == base::MessageLoop::TYPE_CUSTOM)
loop.reset(new base::MessageLoop(common::MessagePumpMojo::Create()));
else
......
......@@ -5,9 +5,12 @@
#ifndef MOJO_APPLICATION_APPLICATION_RUNNER_CHROMIUM_H_
#define MOJO_APPLICATION_APPLICATION_RUNNER_CHROMIUM_H_
#include "base/memory/scoped_ptr.h"
#include <memory>
#include "base/message_loop/message_loop.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......@@ -38,7 +41,7 @@ class ApplicationRunnerChromium {
MojoResult Run(MojoHandle application_request);
private:
scoped_ptr<ApplicationDelegate> delegate_;
std::unique_ptr<ApplicationDelegate> delegate_;
// MessageLoop type. TYPE_CUSTOM is default (MessagePumpMojo will be used as
// the underlying message pump).
......
......@@ -293,9 +293,9 @@ class _ApplicationRequestQuitParams extends bindings.Struct {
}
}
const int _Application_initializeName = 0;
const int _Application_acceptConnectionName = 1;
const int _Application_requestQuitName = 2;
const int _applicationMethodInitializeName = 0;
const int _applicationMethodAcceptConnectionName = 1;
const int _applicationMethodRequestQuitName = 2;
class _ApplicationServiceDescription implements service_describer.ServiceDescription {
dynamic getTopLevelInterface([Function responseFactory]) =>
......@@ -363,7 +363,7 @@ class _ApplicationProxyCalls implements Application {
params.shell = shell;
params.args = args;
params.url = url;
_proxyImpl.sendMessage(params, _Application_initializeName);
_proxyImpl.sendMessage(params, _applicationMethodInitializeName);
}
void acceptConnection(String requestorUrl, Object services, Object exposedServices, String resolvedUrl) {
if (!_proxyImpl.isBound) {
......@@ -375,7 +375,7 @@ class _ApplicationProxyCalls implements Application {
params.services = services;
params.exposedServices = exposedServices;
params.resolvedUrl = resolvedUrl;
_proxyImpl.sendMessage(params, _Application_acceptConnectionName);
_proxyImpl.sendMessage(params, _applicationMethodAcceptConnectionName);
}
void requestQuit() {
if (!_proxyImpl.isBound) {
......@@ -383,7 +383,7 @@ class _ApplicationProxyCalls implements Application {
return;
}
var params = new _ApplicationRequestQuitParams();
_proxyImpl.sendMessage(params, _Application_requestQuitName);
_proxyImpl.sendMessage(params, _applicationMethodRequestQuitName);
}
}
......@@ -475,17 +475,17 @@ class ApplicationStub extends bindings.Stub {
}
assert(_impl != null);
switch (message.header.type) {
case _Application_initializeName:
case _applicationMethodInitializeName:
var params = _ApplicationInitializeParams.deserialize(
message.payload);
_impl.initialize(params.shell, params.args, params.url);
break;
case _Application_acceptConnectionName:
case _applicationMethodAcceptConnectionName:
var params = _ApplicationAcceptConnectionParams.deserialize(
message.payload);
_impl.acceptConnection(params.requestorUrl, params.services, params.exposedServices, params.resolvedUrl);
break;
case _Application_requestQuitName:
case _applicationMethodRequestQuitName:
_impl.requestQuit();
break;
default:
......
......@@ -178,8 +178,8 @@ class _ApplicationConnectorDuplicateParams extends bindings.Struct {
}
}
const int _ApplicationConnector_connectToApplicationName = 0;
const int _ApplicationConnector_duplicateName = 1;
const int _applicationConnectorMethodConnectToApplicationName = 0;
const int _applicationConnectorMethodDuplicateName = 1;
class _ApplicationConnectorServiceDescription implements service_describer.ServiceDescription {
dynamic getTopLevelInterface([Function responseFactory]) =>
......@@ -246,7 +246,7 @@ class _ApplicationConnectorProxyCalls implements ApplicationConnector {
params.applicationUrl = applicationUrl;
params.services = services;
params.exposedServices = exposedServices;
_proxyImpl.sendMessage(params, _ApplicationConnector_connectToApplicationName);
_proxyImpl.sendMessage(params, _applicationConnectorMethodConnectToApplicationName);
}
void duplicate(Object applicationConnectorRequest) {
if (!_proxyImpl.isBound) {
......@@ -255,7 +255,7 @@ class _ApplicationConnectorProxyCalls implements ApplicationConnector {
}
var params = new _ApplicationConnectorDuplicateParams();
params.applicationConnectorRequest = applicationConnectorRequest;
_proxyImpl.sendMessage(params, _ApplicationConnector_duplicateName);
_proxyImpl.sendMessage(params, _applicationConnectorMethodDuplicateName);
}
}
......@@ -347,12 +347,12 @@ class ApplicationConnectorStub extends bindings.Stub {
}
assert(_impl != null);
switch (message.header.type) {
case _ApplicationConnector_connectToApplicationName:
case _applicationConnectorMethodConnectToApplicationName:
var params = _ApplicationConnectorConnectToApplicationParams.deserialize(
message.payload);
_impl.connectToApplication(params.applicationUrl, params.services, params.exposedServices);
break;
case _ApplicationConnector_duplicateName:
case _applicationConnectorMethodDuplicateName:
var params = _ApplicationConnectorDuplicateParams.deserialize(
message.payload);
_impl.duplicate(params.applicationConnectorRequest);
......
......@@ -19,7 +19,7 @@ class MojomFile extends bindings.Struct {
List<mojom_types_mojom.Attribute> attributes = null;
List<String> imports = null;
KeysByType declaredMojomObjects = null;
List<int> serializedRuntimeTypeInfo = null;
String serializedRuntimeTypeInfo = null;
MojomFile() : super(kVersions.last.size);
......@@ -104,7 +104,7 @@ class MojomFile extends bindings.Struct {
}
if (mainDataHeader.version >= 0) {
result.serializedRuntimeTypeInfo = decoder0.decodeUint8Array(56, bindings.kArrayNullable, bindings.kUnspecifiedArrayLength);
result.serializedRuntimeTypeInfo = decoder0.decodeString(56, true);
}
return result;
}
......@@ -168,7 +168,7 @@ class MojomFile extends bindings.Struct {
rethrow;
}
try {
encoder0.encodeUint8Array(serializedRuntimeTypeInfo, 56, bindings.kArrayNullable, bindings.kUnspecifiedArrayLength);
encoder0.encodeString(serializedRuntimeTypeInfo, 56, true);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"serializedRuntimeTypeInfo of struct MojomFile: $e";
......
......@@ -766,12 +766,14 @@ class TypeReference extends bindings.Struct {
class StructField extends bindings.Struct {
static const List<bindings.StructDataHeader> kVersions = const [
const bindings.StructDataHeader(56, 0)
const bindings.StructDataHeader(64, 0)
];
DeclarationData declData = null;
Type type = null;
DefaultFieldValue defaultValue = null;
int offset = 0;
int bit = 0;
int minVersion = 0;
StructField() : super(kVersions.last.size);
......@@ -829,6 +831,14 @@ class StructField extends bindings.Struct {
result.offset = decoder0.decodeInt32(48);
}
if (mainDataHeader.version >= 0) {
result.bit = decoder0.decodeInt8(52);
}
if (mainDataHeader.version >= 0) {
result.minVersion = decoder0.decodeUint32(56);
}
return result;
}
......@@ -862,6 +872,20 @@ class StructField extends bindings.Struct {
"offset of struct StructField: $e";
rethrow;
}
try {
encoder0.encodeInt8(bit, 52);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"bit of struct StructField: $e";
rethrow;
}
try {
encoder0.encodeUint32(minVersion, 56);
} on bindings.MojoCodecError catch(e) {
e.message = "Error encountered while encoding field "
"minVersion of struct StructField: $e";
rethrow;
}
}
String toString() {
......@@ -869,7 +893,9 @@ class StructField extends bindings.Struct {
"declData: $declData" ", "
"type: $type" ", "
"defaultValue: $defaultValue" ", "
"offset: $offset" ")";
"offset: $offset" ", "
"bit: $bit" ", "
"minVersion: $minVersion" ")";
}
Map toJson() {
......@@ -878,6 +904,8 @@ class StructField extends bindings.Struct {
map["type"] = type;
map["defaultValue"] = defaultValue;
map["offset"] = offset;
map["bit"] = bit;
map["minVersion"] = minVersion;
return map;
}
}
......@@ -2887,7 +2915,7 @@ enum TypeTag {
}
class Type extends bindings.Union {
static final _tag_to_int = const {
static final _tagToInt = const {
TypeTag.simpleType: 0,
TypeTag.stringType: 1,
TypeTag.arrayType: 2,
......@@ -2896,7 +2924,7 @@ class Type extends bindings.Union {
TypeTag.typeReference: 5,
};
static final _int_to_tag = const {
static final _intToTag = const {
0: TypeTag.simpleType,
1: TypeTag.stringType,
2: TypeTag.arrayType,
......@@ -2984,7 +3012,7 @@ class Type extends bindings.Union {
Type result = new Type();
TypeTag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)];
TypeTag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
switch (tag) {
case TypeTag.simpleType:
......@@ -3029,7 +3057,7 @@ class Type extends bindings.Union {
void encode(bindings.Encoder encoder0, int offset) {
encoder0.encodeUint32(16, offset);
encoder0.encodeUint32(_tag_to_int[_tag], offset + 4);
encoder0.encodeUint32(_tagToInt[_tag], offset + 4);
switch (_tag) {
case TypeTag.simpleType:
encoder0.encodeEnum(simpleType, offset + 8);
......@@ -3093,14 +3121,14 @@ enum UserDefinedTypeTag {
}
class UserDefinedType extends bindings.Union {
static final _tag_to_int = const {
static final _tagToInt = const {
UserDefinedTypeTag.enumType: 0,
UserDefinedTypeTag.structType: 1,
UserDefinedTypeTag.unionType: 2,
UserDefinedTypeTag.interfaceType: 3,
};
static final _int_to_tag = const {
static final _intToTag = const {
0: UserDefinedTypeTag.enumType,
1: UserDefinedTypeTag.structType,
2: UserDefinedTypeTag.unionType,
......@@ -3164,7 +3192,7 @@ class UserDefinedType extends bindings.Union {
UserDefinedType result = new UserDefinedType();
UserDefinedTypeTag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)];
UserDefinedTypeTag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
switch (tag) {
case UserDefinedTypeTag.enumType:
......@@ -3196,7 +3224,7 @@ class UserDefinedType extends bindings.Union {
void encode(bindings.Encoder encoder0, int offset) {
encoder0.encodeUint32(16, offset);
encoder0.encodeUint32(_tag_to_int[_tag], offset + 4);
encoder0.encodeUint32(_tagToInt[_tag], offset + 4);
switch (_tag) {
case UserDefinedTypeTag.enumType:
encoder0.encodeStruct(enumType, offset + 8, false);
......@@ -3246,12 +3274,12 @@ enum DefaultFieldValueTag {
}
class DefaultFieldValue extends bindings.Union {
static final _tag_to_int = const {
static final _tagToInt = const {
DefaultFieldValueTag.value: 0,
DefaultFieldValueTag.defaultKeyword: 1,
};
static final _int_to_tag = const {
static final _intToTag = const {
0: DefaultFieldValueTag.value,
1: DefaultFieldValueTag.defaultKeyword,
};
......@@ -3291,7 +3319,7 @@ class DefaultFieldValue extends bindings.Union {
DefaultFieldValue result = new DefaultFieldValue();
DefaultFieldValueTag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)];
DefaultFieldValueTag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
switch (tag) {
case DefaultFieldValueTag.value:
var decoder1 = decoder0.decodePointer(offset + 8, false);
......@@ -3312,7 +3340,7 @@ class DefaultFieldValue extends bindings.Union {
void encode(bindings.Encoder encoder0, int offset) {
encoder0.encodeUint32(16, offset);
encoder0.encodeUint32(_tag_to_int[_tag], offset + 4);
encoder0.encodeUint32(_tagToInt[_tag], offset + 4);
switch (_tag) {
case DefaultFieldValueTag.value:
encoder0.encodeNestedUnion(value, offset + 8, false);
......@@ -3351,13 +3379,13 @@ enum ValueTag {
}
class Value extends bindings.Union {
static final _tag_to_int = const {
static final _tagToInt = const {
ValueTag.literalValue: 0,
ValueTag.userValueReference: 1,
ValueTag.builtinValue: 2,
};
static final _int_to_tag = const {
static final _intToTag = const {
0: ValueTag.literalValue,
1: ValueTag.userValueReference,
2: ValueTag.builtinValue,
......@@ -3409,7 +3437,7 @@ class Value extends bindings.Union {
Value result = new Value();
ValueTag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)];
ValueTag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
switch (tag) {
case ValueTag.literalValue:
var decoder1 = decoder0.decodePointer(offset + 8, false);
......@@ -3438,7 +3466,7 @@ class Value extends bindings.Union {
void encode(bindings.Encoder encoder0, int offset) {
encoder0.encodeUint32(16, offset);
encoder0.encodeUint32(_tag_to_int[_tag], offset + 4);
encoder0.encodeUint32(_tagToInt[_tag], offset + 4);
switch (_tag) {
case ValueTag.literalValue:
encoder0.encodeNestedUnion(literalValue, offset + 8, false);
......@@ -3492,7 +3520,7 @@ enum LiteralValueTag {
}
class LiteralValue extends bindings.Union {
static final _tag_to_int = const {
static final _tagToInt = const {
LiteralValueTag.boolValue: 0,
LiteralValueTag.doubleValue: 1,
LiteralValueTag.floatValue: 2,
......@@ -3507,7 +3535,7 @@ class LiteralValue extends bindings.Union {
LiteralValueTag.uint64Value: 11,
};
static final _int_to_tag = const {
static final _intToTag = const {
0: LiteralValueTag.boolValue,
1: LiteralValueTag.doubleValue,
2: LiteralValueTag.floatValue,
......@@ -3667,7 +3695,7 @@ class LiteralValue extends bindings.Union {
LiteralValue result = new LiteralValue();
LiteralValueTag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)];
LiteralValueTag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
switch (tag) {
case LiteralValueTag.boolValue:
......@@ -3727,7 +3755,7 @@ class LiteralValue extends bindings.Union {
void encode(bindings.Encoder encoder0, int offset) {
encoder0.encodeUint32(16, offset);
encoder0.encodeUint32(_tag_to_int[_tag], offset + 4);
encoder0.encodeUint32(_tagToInt[_tag], offset + 4);
switch (_tag) {
case LiteralValueTag.boolValue:
encoder0.encodeBool(boolValue, offset + 8, 0);
......@@ -3825,12 +3853,12 @@ enum UserDefinedValueTag {
}
class UserDefinedValue extends bindings.Union {
static final _tag_to_int = const {
static final _tagToInt = const {
UserDefinedValueTag.enumValue: 0,
UserDefinedValueTag.declaredConstant: 1,
};
static final _int_to_tag = const {
static final _intToTag = const {
0: UserDefinedValueTag.enumValue,
1: UserDefinedValueTag.declaredConstant,
};
......@@ -3870,7 +3898,7 @@ class UserDefinedValue extends bindings.Union {
UserDefinedValue result = new UserDefinedValue();
UserDefinedValueTag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)];
UserDefinedValueTag tag = _intToTag[decoder0.decodeUint32(offset + 4)];
switch (tag) {
case UserDefinedValueTag.enumValue:
......@@ -3892,7 +3920,7 @@ class UserDefinedValue extends bindings.Union {
void encode(bindings.Encoder encoder0, int offset) {
encoder0.encodeUint32(16, offset);
encoder0.encodeUint32(_tag_to_int[_tag], offset + 4);
encoder0.encodeUint32(_tagToInt[_tag], offset + 4);
switch (_tag) {
case UserDefinedValueTag.enumValue:
encoder0.encodeStruct(enumValue, offset + 8, false);
......
......@@ -556,7 +556,7 @@ class ServiceDescriptionGetAllTypeDefinitionsResponseParams extends bindings.Str
}
}
const int _ServiceDescriber_describeServiceName = 0;
const int _serviceDescriberMethodDescribeServiceName = 0;
class _ServiceDescriberServiceDescription implements ServiceDescription {
dynamic getTopLevelInterface([Function responseFactory]) =>
......@@ -621,7 +621,7 @@ class _ServiceDescriberProxyCalls implements ServiceDescriber {
var params = new _ServiceDescriberDescribeServiceParams();
params.interfaceName = interfaceName;
params.descriptionRequest = descriptionRequest;
_proxyImpl.sendMessage(params, _ServiceDescriber_describeServiceName);
_proxyImpl.sendMessage(params, _serviceDescriberMethodDescribeServiceName);
}
}
......@@ -713,7 +713,7 @@ class ServiceDescriberStub extends bindings.Stub {
}
assert(_impl != null);
switch (message.header.type) {
case _ServiceDescriber_describeServiceName:
case _serviceDescriberMethodDescribeServiceName:
var params = _ServiceDescriberDescribeServiceParams.deserialize(
message.payload);
_impl.describeService(params.interfaceName, params.descriptionRequest);
......@@ -747,9 +747,9 @@ class ServiceDescriberStub extends bindings.Stub {
}
}
const int _ServiceDescription_getTopLevelInterfaceName = 0;
const int _ServiceDescription_getTypeDefinitionName = 1;
const int _ServiceDescription_getAllTypeDefinitionsName = 2;
const int _serviceDescriptionMethodGetTopLevelInterfaceName = 0;
const int _serviceDescriptionMethodGetTypeDefinitionName = 1;
const int _serviceDescriptionMethodGetAllTypeDefinitionsName = 2;
class _ServiceDescriptionServiceDescription implements ServiceDescription {
dynamic getTopLevelInterface([Function responseFactory]) =>
......@@ -790,7 +790,7 @@ class _ServiceDescriptionProxyImpl extends bindings.Proxy {
void handleResponse(bindings.ServiceMessage message) {
switch (message.header.type) {
case _ServiceDescription_getTopLevelInterfaceName:
case _serviceDescriptionMethodGetTopLevelInterfaceName:
var r = ServiceDescriptionGetTopLevelInterfaceResponseParams.deserialize(
message.payload);
if (!message.header.hasRequestId) {
......@@ -810,7 +810,7 @@ class _ServiceDescriptionProxyImpl extends bindings.Proxy {
}
c.complete(r);
break;
case _ServiceDescription_getTypeDefinitionName:
case _serviceDescriptionMethodGetTypeDefinitionName:
var r = ServiceDescriptionGetTypeDefinitionResponseParams.deserialize(
message.payload);
if (!message.header.hasRequestId) {
......@@ -830,7 +830,7 @@ class _ServiceDescriptionProxyImpl extends bindings.Proxy {
}
c.complete(r);
break;
case _ServiceDescription_getAllTypeDefinitionsName:
case _serviceDescriptionMethodGetAllTypeDefinitionsName:
var r = ServiceDescriptionGetAllTypeDefinitionsResponseParams.deserialize(
message.payload);
if (!message.header.hasRequestId) {
......@@ -872,7 +872,7 @@ class _ServiceDescriptionProxyCalls implements ServiceDescription {
var params = new _ServiceDescriptionGetTopLevelInterfaceParams();
return _proxyImpl.sendMessageWithRequestId(
params,
_ServiceDescription_getTopLevelInterfaceName,
_serviceDescriptionMethodGetTopLevelInterfaceName,
-1,
bindings.MessageHeader.kMessageExpectsResponse);
}
......@@ -881,7 +881,7 @@ class _ServiceDescriptionProxyCalls implements ServiceDescription {
params.typeKey = typeKey;
return _proxyImpl.sendMessageWithRequestId(
params,
_ServiceDescription_getTypeDefinitionName,
_serviceDescriptionMethodGetTypeDefinitionName,
-1,
bindings.MessageHeader.kMessageExpectsResponse);
}
......@@ -889,7 +889,7 @@ class _ServiceDescriptionProxyCalls implements ServiceDescription {
var params = new _ServiceDescriptionGetAllTypeDefinitionsParams();
return _proxyImpl.sendMessageWithRequestId(
params,
_ServiceDescription_getAllTypeDefinitionsName,
_serviceDescriptionMethodGetAllTypeDefinitionsName,
-1,
bindings.MessageHeader.kMessageExpectsResponse);
}
......@@ -974,20 +974,20 @@ class ServiceDescriptionStub extends bindings.Stub {
}
ServiceDescriptionGetTopLevelInterfaceResponseParams _ServiceDescriptionGetTopLevelInterfaceResponseParamsFactory(mojom_types_mojom.MojomInterface mojomInterface) {
var mojo_factory_result = new ServiceDescriptionGetTopLevelInterfaceResponseParams();
mojo_factory_result.mojomInterface = mojomInterface;
return mojo_factory_result;
ServiceDescriptionGetTopLevelInterfaceResponseParams _serviceDescriptionGetTopLevelInterfaceResponseParamsFactory(mojom_types_mojom.MojomInterface mojomInterface) {
var result = new ServiceDescriptionGetTopLevelInterfaceResponseParams();
result.mojomInterface = mojomInterface;
return result;
}
ServiceDescriptionGetTypeDefinitionResponseParams _ServiceDescriptionGetTypeDefinitionResponseParamsFactory(mojom_types_mojom.UserDefinedType type) {
var mojo_factory_result = new ServiceDescriptionGetTypeDefinitionResponseParams();
mojo_factory_result.type = type;
return mojo_factory_result;
ServiceDescriptionGetTypeDefinitionResponseParams _serviceDescriptionGetTypeDefinitionResponseParamsFactory(mojom_types_mojom.UserDefinedType type) {
var result = new ServiceDescriptionGetTypeDefinitionResponseParams();
result.type = type;
return result;
}
ServiceDescriptionGetAllTypeDefinitionsResponseParams _ServiceDescriptionGetAllTypeDefinitionsResponseParamsFactory(Map<String, mojom_types_mojom.UserDefinedType> definitions) {
var mojo_factory_result = new ServiceDescriptionGetAllTypeDefinitionsResponseParams();
mojo_factory_result.definitions = definitions;
return mojo_factory_result;
ServiceDescriptionGetAllTypeDefinitionsResponseParams _serviceDescriptionGetAllTypeDefinitionsResponseParamsFactory(Map<String, mojom_types_mojom.UserDefinedType> definitions) {
var result = new ServiceDescriptionGetAllTypeDefinitionsResponseParams();
result.definitions = definitions;
return result;
}
dynamic handleMessage(bindings.ServiceMessage message) {
......@@ -998,14 +998,14 @@ class ServiceDescriptionStub extends bindings.Stub {
}
assert(_impl != null);
switch (message.header.type) {
case _ServiceDescription_getTopLevelInterfaceName:
var response = _impl.getTopLevelInterface(_ServiceDescriptionGetTopLevelInterfaceResponseParamsFactory);
case _serviceDescriptionMethodGetTopLevelInterfaceName:
var response = _impl.getTopLevelInterface(_serviceDescriptionGetTopLevelInterfaceResponseParamsFactory);
if (response is Future) {
return response.then((response) {
if (response != null) {
return buildResponseWithId(
response,
_ServiceDescription_getTopLevelInterfaceName,
_serviceDescriptionMethodGetTopLevelInterfaceName,
message.header.requestId,
bindings.MessageHeader.kMessageIsResponse);
}
......@@ -1013,21 +1013,21 @@ class ServiceDescriptionStub extends bindings.Stub {
} else if (response != null) {
return buildResponseWithId(
response,
_ServiceDescription_getTopLevelInterfaceName,
_serviceDescriptionMethodGetTopLevelInterfaceName,
message.header.requestId,
bindings.MessageHeader.kMessageIsResponse);
}
break;
case _ServiceDescription_getTypeDefinitionName:
case _serviceDescriptionMethodGetTypeDefinitionName:
var params = _ServiceDescriptionGetTypeDefinitionParams.deserialize(
message.payload);
var response = _impl.getTypeDefinition(params.typeKey,_ServiceDescriptionGetTypeDefinitionResponseParamsFactory);
var response = _impl.getTypeDefinition(params.typeKey,_serviceDescriptionGetTypeDefinitionResponseParamsFactory);
if (response is Future) {
return response.then((response) {
if (response != null) {
return buildResponseWithId(
response,
_ServiceDescription_getTypeDefinitionName,
_serviceDescriptionMethodGetTypeDefinitionName,
message.header.requestId,
bindings.MessageHeader.kMessageIsResponse);
}
......@@ -1035,19 +1035,19 @@ class ServiceDescriptionStub extends bindings.Stub {
} else if (response != null) {
return buildResponseWithId(
response,
_ServiceDescription_getTypeDefinitionName,
_serviceDescriptionMethodGetTypeDefinitionName,
message.header.requestId,
bindings.MessageHeader.kMessageIsResponse);
}
break;
case _ServiceDescription_getAllTypeDefinitionsName:
var response = _impl.getAllTypeDefinitions(_ServiceDescriptionGetAllTypeDefinitionsResponseParamsFactory);
case _serviceDescriptionMethodGetAllTypeDefinitionsName:
var response = _impl.getAllTypeDefinitions(_serviceDescriptionGetAllTypeDefinitionsResponseParamsFactory);
if (response is Future) {
return response.then((response) {
if (response != null) {
return buildResponseWithId(
response,
_ServiceDescription_getAllTypeDefinitionsName,
_serviceDescriptionMethodGetAllTypeDefinitionsName,
message.header.requestId,
bindings.MessageHeader.kMessageIsResponse);
}
......@@ -1055,7 +1055,7 @@ class ServiceDescriptionStub extends bindings.Stub {
} else if (response != null) {
return buildResponseWithId(
response,
_ServiceDescription_getAllTypeDefinitionsName,
_serviceDescriptionMethodGetAllTypeDefinitionsName,
message.header.requestId,
bindings.MessageHeader.kMessageIsResponse);
}
......
......@@ -93,7 +93,7 @@ class _ServiceProviderConnectToServiceParams extends bindings.Struct {
}
}
const int _ServiceProvider_connectToServiceName = 0;
const int _serviceProviderMethodConnectToServiceName = 0;
class _ServiceProviderServiceDescription implements service_describer.ServiceDescription {
dynamic getTopLevelInterface([Function responseFactory]) =>
......@@ -158,7 +158,7 @@ class _ServiceProviderProxyCalls implements ServiceProvider {
var params = new _ServiceProviderConnectToServiceParams();
params.interfaceName = interfaceName;
params.pipe = pipe;
_proxyImpl.sendMessage(params, _ServiceProvider_connectToServiceName);
_proxyImpl.sendMessage(params, _serviceProviderMethodConnectToServiceName);
}
}
......@@ -250,7 +250,7 @@ class ServiceProviderStub extends bindings.Stub {
}
assert(_impl != null);
switch (message.header.type) {
case _ServiceProvider_connectToServiceName:
case _serviceProviderMethodConnectToServiceName:
var params = _ServiceProviderConnectToServiceParams.deserialize(
message.payload);
_impl.connectToService(params.interfaceName, params.pipe);
......
......@@ -179,8 +179,8 @@ class _ShellCreateApplicationConnectorParams extends bindings.Struct {
}
}
const int _Shell_connectToApplicationName = 0;
const int _Shell_createApplicationConnectorName = 1;
const int _shellMethodConnectToApplicationName = 0;
const int _shellMethodCreateApplicationConnectorName = 1;
class _ShellServiceDescription implements service_describer.ServiceDescription {
dynamic getTopLevelInterface([Function responseFactory]) =>
......@@ -247,7 +247,7 @@ class _ShellProxyCalls implements Shell {
params.applicationUrl = applicationUrl;
params.services = services;
params.exposedServices = exposedServices;
_proxyImpl.sendMessage(params, _Shell_connectToApplicationName);
_proxyImpl.sendMessage(params, _shellMethodConnectToApplicationName);
}
void createApplicationConnector(Object applicationConnectorRequest) {
if (!_proxyImpl.isBound) {
......@@ -256,7 +256,7 @@ class _ShellProxyCalls implements Shell {
}
var params = new _ShellCreateApplicationConnectorParams();
params.applicationConnectorRequest = applicationConnectorRequest;
_proxyImpl.sendMessage(params, _Shell_createApplicationConnectorName);
_proxyImpl.sendMessage(params, _shellMethodCreateApplicationConnectorName);
}
}
......@@ -348,12 +348,12 @@ class ShellStub extends bindings.Stub {
}
assert(_impl != null);
switch (message.header.type) {
case _Shell_connectToApplicationName:
case _shellMethodConnectToApplicationName:
var params = _ShellConnectToApplicationParams.deserialize(
message.payload);
_impl.connectToApplication(params.applicationUrl, params.services, params.exposedServices);
break;
case _Shell_createApplicationConnectorName:
case _shellMethodCreateApplicationConnectorName:
var params = _ShellCreateApplicationConnectorParams.deserialize(
message.payload);
_impl.createApplicationConnector(params.applicationConnectorRequest);
......
......@@ -4,6 +4,14 @@
part of core;
class MojoSharedBufferInformation {
final int flags;
final int sizeInBytes;
MojoSharedBufferInformation(this.flags, this.sizeInBytes);
}
class MojoSharedBuffer {
static const int createFlagNone = 0;
static const int duplicateFlagNone = 0;
......@@ -46,6 +54,23 @@ class MojoSharedBuffer {
return dupe;
}
MojoSharedBufferInformation get information {
if (handle == null) {
_status = MojoResult.kInvalidArgument;
return null;
}
List result =
MojoSharedBufferNatives.GetInformation(handle.h);
if (result[0] != MojoResult.kOk) {
_status = result[0];
return null;
}
return new MojoSharedBufferInformation(result[1], result[2]);
}
int close() {
if (handle == null) {
_status = MojoResult.kInvalidArgument;
......
......@@ -540,4 +540,17 @@ class MojoSharedBufferNatives {
/// set to [MojoSharedBuffer.mapFlagNone] (equal to 0).
static List Map(int bufferHandleToken, int offset, int numBytes, int flags)
native "MojoSharedBuffer_Map";
/// Returns information about [bufferHandleToken].
///
/// Returns a list of exactly 3 elements:
/// 1. The result integer, encoded as specified in [MojoResult]. In
/// particular, [MojoResult.kOk] signals a successful operation.
/// 2. The flags of the buffer (currently unused).
/// 3. The size of the buffer (in bytes).
///
/// The [bufferHandleToken] must be a handle created by [Create].
static List GetInformation(int bufferHandleToken)
native "MojoSharedBuffer_GetInformation";
}
......@@ -5,9 +5,10 @@
#ifndef MOJO_DATA_PIPE_UTILS_DATA_PIPE_DRAINER_H_
#define MOJO_DATA_PIPE_UTILS_DATA_PIPE_DRAINER_H_
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "mojo/message_pump/handle_watcher.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/data_pipe.h"
namespace mojo {
namespace common {
......
......@@ -11,6 +11,7 @@
#include "base/threading/platform_thread.h"
#include "base/trace_event/trace_event.h"
#include "mojo/data_pipe_utils/data_pipe_utils_internal.h"
#include "mojo/public/cpp/system/wait.h"
namespace mojo {
namespace common {
......@@ -111,5 +112,18 @@ bool BlockingCopyFromString(const std::string& source,
}
}
ScopedDataPipeConsumerHandle WriteStringToConsumerHandle(
const std::string& source) {
TRACE_EVENT0("data_pipe_utils", "WriteStringToConsumerHandle");
static const size_t max_buffer_size = 2 * 1024 * 1024; // 2MB
CHECK_LE(static_cast<uint32_t>(source.size()), max_buffer_size);
MojoCreateDataPipeOptions options = {sizeof(MojoCreateDataPipeOptions),
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
1, source.size()};
DataPipe pipe(options);
BlockingCopyFromString(source, pipe.producer_handle.Pass());
return pipe.consumer_handle.Pass();
}
} // namespace common
} // namespace mojo
......@@ -11,7 +11,7 @@
#include "base/callback_forward.h"
#include "base/files/scoped_file.h"
#include "base/threading/platform_thread.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/data_pipe.h"
namespace base {
class FilePath;
......@@ -55,6 +55,11 @@ base::ScopedFILE BlockingCopyToTempFile(ScopedDataPipeConsumerHandle source);
// Returns true on success, false on failure.
bool BlockingCopyToFile(ScopedDataPipeConsumerHandle source, FILE* fp);
// Copies the string |contents| to a temporary data pipe and returns the
// consumer handle.
ScopedDataPipeConsumerHandle WriteStringToConsumerHandle(
const std::string& source);
} // namespace common
} // namespace mojo
......
......@@ -6,7 +6,7 @@
#define MOJO_DATA_PIPE_UTILS_DATA_PIPE_UTILS_INTERNAL_H_
#include "base/callback_forward.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/data_pipe.h"
namespace mojo {
namespace common {
......
......@@ -6,12 +6,13 @@
#include "base/logging.h"
#include "mojo/edk/embedder/embedder_internal.h"
//#include "mojo/edk/embedder/platform_support.h"
#include "mojo/edk/system/configuration.h"
#include "mojo/edk/system/core.h"
#include "mojo/edk/system/platform_handle_dispatcher.h"
#include "mojo/edk/util/ref_ptr.h"
using mojo::platform::ScopedPlatformHandle;
using mojo::util::RefPtr;
namespace mojo {
namespace embedder {
......@@ -69,10 +70,11 @@ MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
DCHECK(platform_handle);
DCHECK(internal::g_core);
auto dispatcher =
internal::g_core->GetDispatcher(platform_handle_wrapper_handle);
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<system::Dispatcher> dispatcher;
MojoResult result = internal::g_core->GetDispatcher(
platform_handle_wrapper_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
if (dispatcher->GetType() != system::Dispatcher::Type::PLATFORM_HANDLE)
return MOJO_RESULT_INVALID_ARGUMENT;
......
......@@ -9,7 +9,8 @@
#include <memory>
#include "mojo/edk/platform/scoped_platform_handle.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/result.h"
namespace mojo {
......
......@@ -12,7 +12,8 @@
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/edk/util/waitable_event.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/macros.h"
#include "mojo/public/cpp/system/message_pipe.h"
......
......@@ -6,8 +6,10 @@
#include "mojo/edk/system/core.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/c/system/wait.h"
using mojo::embedder::internal::g_core;
using mojo::system::MakeUserPointer;
......@@ -24,9 +26,9 @@ MojoResult MojoClose(MojoHandle handle) {
}
MojoResult MojoWait(MojoHandle handle,
MojoHandleSignals signals,
MojoDeadline deadline,
MojoHandleSignalsState* signals_state) {
MojoHandleSignals signals,
MojoDeadline deadline,
MojoHandleSignalsState* signals_state) {
return g_core->Wait(handle, signals, deadline,
MakeUserPointer(signals_state));
}
......
......@@ -19,11 +19,13 @@
#include "mojo/edk/util/command_line.h"
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/edk/util/waitable_event.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/c/system/wait.h"
#include "mojo/public/cpp/system/handle.h"
#include "mojo/public/cpp/system/macros.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "mojo/public/cpp/system/wait.h"
#include "testing/gtest/include/gtest/gtest.h"
using mojo::platform::PlatformHandleWatcher;
......
......@@ -9,8 +9,11 @@
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/c/system/wait.h"
#include "mojo/public/platform/native/system_impl_private.h"
using mojo::embedder::internal::g_core;
......
......@@ -7,7 +7,7 @@
#ifndef MOJO_EDK_PLATFORM_TEST_STOPWATCH_H_
#define MOJO_EDK_PLATFORM_TEST_STOPWATCH_H_
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -5,7 +5,7 @@
#ifndef MOJO_EDK_PLATFORM_THREAD_UTILS_H_
#define MOJO_EDK_PLATFORM_THREAD_UTILS_H_
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/time.h"
namespace mojo {
namespace platform {
......
......@@ -5,7 +5,7 @@
#ifndef MOJO_EDK_PLATFORM_TIME_TICKS_H_
#define MOJO_EDK_PLATFORM_TIME_TICKS_H_
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/time.h"
namespace mojo {
namespace platform {
......
......@@ -8,7 +8,7 @@
#include <functional>
#include "mojo/edk/system/awakable.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -7,7 +7,7 @@
#include <stdint.h>
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
namespace mojo {
namespace system {
......
......@@ -9,7 +9,7 @@
#include <vector>
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -22,7 +22,6 @@
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/edk/util/thread_checker.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -96,12 +96,13 @@ MojoHandle Core::AddDispatcher(Dispatcher* dispatcher) {
return handle_table_.AddDispatcher(dispatcher);
}
RefPtr<Dispatcher> Core::GetDispatcher(MojoHandle handle) {
MojoResult Core::GetDispatcher(MojoHandle handle,
RefPtr<Dispatcher>* dispatcher) {
if (handle == MOJO_HANDLE_INVALID)
return nullptr;
return MOJO_RESULT_INVALID_ARGUMENT;
MutexLocker locker(&handle_table_mutex_);
return RefPtr<Dispatcher>(handle_table_.GetDispatcher(handle));
return handle_table_.GetDispatcher(handle, dispatcher);
}
MojoResult Core::GetAndRemoveDispatcher(MojoHandle handle,
......@@ -116,14 +117,16 @@ MojoResult Core::GetAndRemoveDispatcher(MojoHandle handle,
MojoResult Core::AsyncWait(MojoHandle handle,
MojoHandleSignals signals,
const std::function<void(MojoResult)>& callback) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(handle));
DCHECK(dispatcher);
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
std::unique_ptr<AsyncWaiter> waiter(new AsyncWaiter(callback));
MojoResult rv = dispatcher->AddAwakable(waiter.get(), signals, 0, nullptr);
if (rv == MOJO_RESULT_OK)
result = dispatcher->AddAwakable(waiter.get(), signals, 0, nullptr);
if (result == MOJO_RESULT_OK)
ignore_result(waiter.release());
return rv;
return result;
}
MojoTimeTicks Core::GetTimeTicksNow() {
......@@ -156,11 +159,11 @@ MojoResult Core::Wait(MojoHandle handle,
UserPointer<MojoHandleSignalsState> signals_state) {
uint32_t unused = static_cast<uint32_t>(-1);
HandleSignalsState hss;
MojoResult rv = WaitManyInternal(&handle, &signals, 1, deadline, &unused,
signals_state.IsNull() ? nullptr : &hss);
if (rv != MOJO_RESULT_INVALID_ARGUMENT && !signals_state.IsNull())
MojoResult result = WaitManyInternal(&handle, &signals, 1, deadline, &unused,
signals_state.IsNull() ? nullptr : &hss);
if (result != MOJO_RESULT_INVALID_ARGUMENT && !signals_state.IsNull())
signals_state.Put(hss);
return rv;
return result;
}
MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles,
......@@ -178,26 +181,26 @@ MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles,
UserPointer<const MojoHandleSignals>::Reader signals_reader(signals,
num_handles);
uint32_t index = static_cast<uint32_t>(-1);
MojoResult rv;
MojoResult result;
if (signals_states.IsNull()) {
rv = WaitManyInternal(handles_reader.GetPointer(),
signals_reader.GetPointer(), num_handles, deadline,
&index, nullptr);
result = WaitManyInternal(handles_reader.GetPointer(),
signals_reader.GetPointer(), num_handles,
deadline, &index, nullptr);
} else {
UserPointer<MojoHandleSignalsState>::Writer signals_states_writer(
signals_states, num_handles);
// Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a
// subclass of |MojoHandleSignalsState| that doesn't add any data members.
rv = WaitManyInternal(handles_reader.GetPointer(),
signals_reader.GetPointer(), num_handles, deadline,
&index, reinterpret_cast<HandleSignalsState*>(
signals_states_writer.GetPointer()));
if (rv != MOJO_RESULT_INVALID_ARGUMENT)
result = WaitManyInternal(
handles_reader.GetPointer(), signals_reader.GetPointer(), num_handles,
deadline, &index, reinterpret_cast<HandleSignalsState*>(
signals_states_writer.GetPointer()));
if (result != MOJO_RESULT_INVALID_ARGUMENT)
signals_states_writer.Commit();
}
if (index != static_cast<uint32_t>(-1) && !result_index.IsNull())
result_index.Put(index);
return rv;
return result;
}
MojoResult Core::CreateMessagePipe(
......@@ -249,9 +252,10 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
UserPointer<const MojoHandle> handles,
uint32_t num_handles,
MojoWriteMessageFlags flags) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(message_pipe_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
// Easy case: not sending any handles.
if (num_handles == 0)
......@@ -289,8 +293,7 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
return result;
}
MojoResult rv =
dispatcher->WriteMessage(bytes, num_bytes, &transports, flags);
result = dispatcher->WriteMessage(bytes, num_bytes, &transports, flags);
// We need to release the dispatcher locks before we take the handle table
// lock.
......@@ -299,7 +302,7 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
{
MutexLocker locker(&handle_table_mutex_);
if (rv == MOJO_RESULT_OK) {
if (result == MOJO_RESULT_OK) {
handle_table_.RemoveBusyHandles(handles_reader.GetPointer(), num_handles);
} else {
handle_table_.RestoreBusyHandles(handles_reader.GetPointer(),
......@@ -307,7 +310,7 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
}
}
return rv;
return result;
}
MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
......@@ -316,23 +319,23 @@ MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
UserPointer<MojoHandle> handles,
UserPointer<uint32_t> num_handles,
MojoReadMessageFlags flags) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(message_pipe_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(message_pipe_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
uint32_t num_handles_value = num_handles.IsNull() ? 0 : num_handles.Get();
MojoResult rv;
if (num_handles_value == 0) {
// Easy case: won't receive any handles.
rv = dispatcher->ReadMessage(bytes, num_bytes, nullptr, &num_handles_value,
flags);
result = dispatcher->ReadMessage(bytes, num_bytes, nullptr,
&num_handles_value, flags);
} else {
DispatcherVector dispatchers;
rv = dispatcher->ReadMessage(bytes, num_bytes, &dispatchers,
&num_handles_value, flags);
result = dispatcher->ReadMessage(bytes, num_bytes, &dispatchers,
&num_handles_value, flags);
if (!dispatchers.empty()) {
DCHECK_EQ(rv, MOJO_RESULT_OK);
DCHECK_EQ(result, MOJO_RESULT_OK);
DCHECK(!num_handles.IsNull());
DCHECK_LE(dispatchers.size(), static_cast<size_t>(num_handles_value));
......@@ -354,15 +357,15 @@ MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
if (dispatchers[i])
dispatchers[i]->Close();
}
if (rv == MOJO_RESULT_OK)
rv = MOJO_RESULT_RESOURCE_EXHAUSTED;
if (result == MOJO_RESULT_OK)
result = MOJO_RESULT_RESOURCE_EXHAUSTED;
}
}
}
if (!num_handles.IsNull())
num_handles.Put(num_handles_value);
return rv;
return result;
}
MojoResult Core::CreateDataPipe(
......@@ -406,9 +409,10 @@ MojoResult Core::WriteData(MojoHandle data_pipe_producer_handle,
UserPointer<const void> elements,
UserPointer<uint32_t> num_bytes,
MojoWriteDataFlags flags) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_producer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(data_pipe_producer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
return dispatcher->WriteData(elements, num_bytes, flags);
}
......@@ -417,18 +421,20 @@ MojoResult Core::BeginWriteData(MojoHandle data_pipe_producer_handle,
UserPointer<void*> buffer,
UserPointer<uint32_t> buffer_num_bytes,
MojoWriteDataFlags flags) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_producer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(data_pipe_producer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
return dispatcher->BeginWriteData(buffer, buffer_num_bytes, flags);
}
MojoResult Core::EndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_written) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_producer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(data_pipe_producer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
return dispatcher->EndWriteData(num_bytes_written);
}
......@@ -437,9 +443,10 @@ MojoResult Core::ReadData(MojoHandle data_pipe_consumer_handle,
UserPointer<void> elements,
UserPointer<uint32_t> num_bytes,
MojoReadDataFlags flags) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_consumer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(data_pipe_consumer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
return dispatcher->ReadData(elements, num_bytes, flags);
}
......@@ -448,18 +455,20 @@ MojoResult Core::BeginReadData(MojoHandle data_pipe_consumer_handle,
UserPointer<const void*> buffer,
UserPointer<uint32_t> buffer_num_bytes,
MojoReadDataFlags flags) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_consumer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(data_pipe_consumer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
return dispatcher->BeginReadData(buffer, buffer_num_bytes, flags);
}
MojoResult Core::EndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_read) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(data_pipe_consumer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(data_pipe_consumer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
return dispatcher->EndReadData(num_bytes_read);
}
......@@ -496,14 +505,14 @@ MojoResult Core::DuplicateBufferHandle(
MojoHandle buffer_handle,
UserPointer<const MojoDuplicateBufferHandleOptions> options,
UserPointer<MojoHandle> new_buffer_handle) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(buffer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
// Don't verify |options| here; that's the dispatcher's job.
RefPtr<Dispatcher> new_dispatcher;
MojoResult result =
dispatcher->DuplicateBufferHandle(options, &new_dispatcher);
result = dispatcher->DuplicateBufferHandle(options, &new_dispatcher);
if (result != MOJO_RESULT_OK)
return result;
......@@ -521,9 +530,10 @@ MojoResult Core::DuplicateBufferHandle(
MojoResult Core::GetBufferInformation(MojoHandle buffer_handle,
UserPointer<MojoBufferInformation> info,
uint32_t info_num_bytes) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(buffer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
return dispatcher->GetBufferInformation(info, info_num_bytes);
}
......@@ -533,12 +543,13 @@ MojoResult Core::MapBuffer(MojoHandle buffer_handle,
uint64_t num_bytes,
UserPointer<void*> buffer,
MojoMapBufferFlags flags) {
RefPtr<Dispatcher> dispatcher(GetDispatcher(buffer_handle));
if (!dispatcher)
return MOJO_RESULT_INVALID_ARGUMENT;
RefPtr<Dispatcher> dispatcher;
MojoResult result = GetDispatcher(buffer_handle, &dispatcher);
if (result != MOJO_RESULT_OK)
return result;
std::unique_ptr<PlatformSharedBufferMapping> mapping;
MojoResult result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping);
result = dispatcher->MapBuffer(offset, num_bytes, flags, &mapping);
if (result != MOJO_RESULT_OK)
return result;
......@@ -575,13 +586,23 @@ MojoResult Core::WaitManyInternal(const MojoHandle* handles,
DispatcherVector dispatchers;
dispatchers.reserve(num_handles);
for (uint32_t i = 0; i < num_handles; i++) {
RefPtr<Dispatcher> dispatcher = GetDispatcher(handles[i]);
if (!dispatcher) {
*result_index = i;
return MOJO_RESULT_INVALID_ARGUMENT;
{
MutexLocker locker(&handle_table_mutex_);
for (uint32_t i = 0; i < num_handles; i++) {
if (handles[i] == MOJO_HANDLE_INVALID) {
*result_index = i;
return MOJO_RESULT_INVALID_ARGUMENT;
}
RefPtr<Dispatcher> dispatcher;
MojoResult result = handle_table_.GetDispatcher(handles[i], &dispatcher);
if (result != MOJO_RESULT_OK) {
*result_index = i;
return result;
}
dispatchers.push_back(std::move(dispatcher));
}
dispatchers.push_back(dispatcher);
}
// TODO(vtl): Should make the waiter live (permanently) in TLS.
......@@ -589,21 +610,21 @@ MojoResult Core::WaitManyInternal(const MojoHandle* handles,
waiter.Init();
uint32_t i;
MojoResult rv = MOJO_RESULT_OK;
MojoResult result = MOJO_RESULT_OK;
for (i = 0; i < num_handles; i++) {
rv = dispatchers[i]->AddAwakable(
result = dispatchers[i]->AddAwakable(
&waiter, signals[i], i, signals_states ? &signals_states[i] : nullptr);
if (rv != MOJO_RESULT_OK) {
if (result != MOJO_RESULT_OK) {
*result_index = i;
break;
}
}
uint32_t num_added = i;
if (rv == MOJO_RESULT_ALREADY_EXISTS)
rv = MOJO_RESULT_OK; // The i-th one is already "triggered".
else if (rv == MOJO_RESULT_OK)
rv = waiter.Wait(deadline, result_index);
if (result == MOJO_RESULT_ALREADY_EXISTS)
result = MOJO_RESULT_OK; // The i-th one is already "triggered".
else if (result == MOJO_RESULT_OK)
result = waiter.Wait(deadline, result_index);
// Make sure no other dispatchers try to wake |waiter| for the current
// |Wait()|/|WaitMany()| call. (Only after doing this can |waiter| be
......@@ -617,7 +638,7 @@ MojoResult Core::WaitManyInternal(const MojoHandle* handles,
signals_states[i] = dispatchers[i]->GetHandleSignalsState();
}
return rv;
return result;
}
} // namespace system
......
......@@ -17,8 +17,10 @@
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......@@ -48,16 +50,16 @@ class Core {
// |MOJO_HANDLE_INVALID| on failure, namely if the handle table is full.
MojoHandle AddDispatcher(Dispatcher* dispatcher);
// Looks up the dispatcher for the given handle. Returns null if the handle is
// invalid.
util::RefPtr<Dispatcher> GetDispatcher(MojoHandle handle);
// Looks up the dispatcher for the given handle. On success, gets the
// dispatcher for a given handle. On failure, returns an appropriate result
// and leaves |dispatcher| alone), namely |MOJO_RESULT_INVALID_ARGUMENT| if
// the handle is invalid or |MOJO_RESULT_BUSY| if the handle is marked as
// busy.
MojoResult GetDispatcher(MojoHandle handle,
util::RefPtr<Dispatcher>* dispatcher);
// Like |GetDispatcher()|, but also removes the handle from the handle table.
// On success, gets the dispatcher for a given handle (which should not be
// |MOJO_HANDLE_INVALID|) and removes it. (On failure, returns an appropriate
// result (and leaves |dispatcher| alone), namely
// |MOJO_RESULT_INVALID_ARGUMENT| if there's no dispatcher for the given
// handle or |MOJO_RESULT_BUSY| if the handle is marked as busy.)
// Like |GetDispatcher()|, but on success also removes the handle from the
// handle table.
MojoResult GetAndRemoveDispatcher(MojoHandle handle,
util::RefPtr<Dispatcher>* dispatcher);
......@@ -81,10 +83,17 @@ class Core {
// of these methods is to look at the header files defining the corresponding
// API functions, referenced below.
// These methods correspond to the API functions defined in
// "mojo/public/c/system/functions.h":
// This method corresponds to the API function defined in
// "mojo/public/c/system/time.h":
MojoTimeTicks GetTimeTicksNow();
// This method corresponds to the API function defined in
// "mojo/public/c/system/handle.h":
MojoResult Close(MojoHandle handle);
// These methods correspond to the API functions defined in
// "mojo/public/c/system/wait.h":
MojoResult Wait(MojoHandle handle,
MojoHandleSignals signals,
MojoDeadline deadline,
......
......@@ -9,7 +9,7 @@
#include "mojo/edk/util/mutex.h"
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/cpp/system/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -18,7 +18,8 @@
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -17,7 +17,7 @@
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/macros.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
namespace mojo {
namespace system {
......
......@@ -21,8 +21,9 @@
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -5,7 +5,7 @@
#ifndef MOJO_EDK_SYSTEM_HANDLE_SIGNALS_STATE_H_
#define MOJO_EDK_SYSTEM_HANDLE_SIGNALS_STATE_H_
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
namespace mojo {
namespace system {
......
......@@ -34,13 +34,19 @@ HandleTable::~HandleTable() {
// the singleton |Core|, which lives forever), except in tests.
}
Dispatcher* HandleTable::GetDispatcher(MojoHandle handle) {
MojoResult HandleTable::GetDispatcher(MojoHandle handle,
RefPtr<Dispatcher>* dispatcher) {
DCHECK_NE(handle, MOJO_HANDLE_INVALID);
DCHECK(dispatcher);
HandleToEntryMap::iterator it = handle_to_entry_map_.find(handle);
if (it == handle_to_entry_map_.end())
return nullptr;
return it->second.dispatcher.get();
return MOJO_RESULT_INVALID_ARGUMENT;
if (it->second.busy)
return MOJO_RESULT_BUSY;
*dispatcher = it->second.dispatcher;
return MOJO_RESULT_OK;
}
MojoResult HandleTable::GetAndRemoveDispatcher(MojoHandle handle,
......
......@@ -10,7 +10,8 @@
#include <vector>
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......@@ -41,19 +42,16 @@ class HandleTable {
HandleTable();
~HandleTable();
// Gets the dispatcher for a given handle (which should not be
// |MOJO_HANDLE_INVALID|). Returns null if there's no dispatcher for the given
// handle.
// WARNING: For efficiency, this returns a dumb pointer. If you're going to
// use the result outside |Core|'s lock, you MUST take a reference (e.g., by
// storing the result inside a |util::RefPtr|).
Dispatcher* GetDispatcher(MojoHandle handle);
// On success, gets the dispatcher for a given handle (which should not be
// |MOJO_HANDLE_INVALID|) and removes it. (On failure, returns an appropriate
// result (and leaves |dispatcher| alone), namely
// |MOJO_RESULT_INVALID_ARGUMENT| if there's no dispatcher for the given
// handle or |MOJO_RESULT_BUSY| if the handle is marked as busy.)
// |MOJO_HANDLE_INVALID|). On failure, returns an appropriate result (and
// leaves |dispatcher| alone), namely |MOJO_RESULT_INVALID_ARGUMENT| if
// there's no dispatcher for the given handle or |MOJO_RESULT_BUSY| if the
// handle is marked as busy.
MojoResult GetDispatcher(MojoHandle handle,
util::RefPtr<Dispatcher>* dispatcher);
// Like |GetDispatcher()|, but on success also removes the handle from the
// handle table.
MojoResult GetAndRemoveDispatcher(MojoHandle handle,
util::RefPtr<Dispatcher>* dispatcher);
......
......@@ -11,7 +11,7 @@
#include <unordered_map>
#include <vector>
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -21,8 +21,9 @@
#include "mojo/edk/util/mutex.h"
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -13,8 +13,9 @@
#include "mojo/edk/system/dispatcher.h"
#include "mojo/edk/system/memory.h"
#include "mojo/edk/system/message_in_transit.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/message_pipe.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -18,7 +18,6 @@
#include "base/logging.h"
#include "mojo/edk/system/memory.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -7,9 +7,6 @@
#ifndef MOJO_EDK_SYSTEM_TEST_PERF_LOG_H_
#define MOJO_EDK_SYSTEM_TEST_PERF_LOG_H_
//#include "mojo/public/c/system/types.h"
//#include "mojo/public/cpp/system/macros.h"
namespace mojo {
namespace system {
namespace test {
......
......@@ -7,7 +7,7 @@
#ifndef MOJO_EDK_SYSTEM_TEST_TIMEOUTS_H_
#define MOJO_EDK_SYSTEM_TEST_TIMEOUTS_H_
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/time.h"
namespace mojo {
namespace system {
......
......@@ -11,7 +11,8 @@
#include "mojo/edk/util/cond_var.h"
#include "mojo/edk/util/mutex.h"
#include "mojo/edk/util/thread_annotations.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -12,7 +12,9 @@
#include "mojo/edk/system/test/simple_test_thread.h"
#include "mojo/edk/system/waiter.h"
#include "mojo/edk/util/ref_ptr.h"
#include "mojo/public/c/system/types.h"
#include "mojo/public/c/system/handle.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
......
......@@ -5,11 +5,12 @@
#ifndef MOJO_MESSAGE_PUMP_HANDLE_WATCHER_H_
#define MOJO_MESSAGE_PUMP_HANDLE_WATCHER_H_
#include "base/basictypes.h"
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/cpp/system/handle.h"
namespace base {
class Thread;
......
......@@ -15,7 +15,7 @@
#include "base/threading/thread.h"
#include "mojo/message_pump/message_pump_mojo.h"
#include "mojo/message_pump/time_helper.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "mojo/public/cpp/test_support/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
......
......@@ -13,6 +13,8 @@
#include "base/time/time.h"
#include "mojo/message_pump/message_pump_mojo_handler.h"
#include "mojo/message_pump/time_helper.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "mojo/public/cpp/system/wait.h"
namespace mojo {
namespace common {
......
......@@ -15,7 +15,9 @@
#include "base/observer_list.h"
#include "base/synchronization/lock.h"
#include "base/time/time.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/c/system/time.h"
#include "mojo/public/cpp/system/handle.h"
namespace mojo {
namespace common {
......
......@@ -5,7 +5,8 @@
#ifndef MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_HANDLER_H_
#define MOJO_MESSAGE_PUMP_MESSAGE_PUMP_MOJO_HANDLER_H_
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/c/system/result.h"
#include "mojo/public/cpp/system/handle.h"
namespace mojo {
namespace common {
......
......@@ -7,7 +7,7 @@
#include "base/message_loop/message_loop_test.h"
#include "base/run_loop.h"
#include "mojo/message_pump/message_pump_mojo_handler.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
......
......@@ -18,7 +18,7 @@ interface AuthenticationService {
SelectAccount(bool return_last_selected) => (string? username, string? error);
// Requests an oauth2 token for the given Google account with the given
// scopes. In case of error, username will be null and error will contain a
// scopes. In case of error, token will be null and error will contain a
// description of the error.
GetOAuth2Token(string username, array<string> scopes) =>
(string? token, string? error);
......@@ -27,4 +27,22 @@ interface AuthenticationService {
// token is refused by a server component before requesting a new token to
// clear the token from any cache.
ClearOAuth2Token(string token);
// Requests an oauth2 device code response for the given set of scopes. In
// case of error, all response parameters other than error, namely
// verifcation_url, device_code and user_code will be null and error will
// contain a description of the error. To provision FNL like systems with
// Google account credentials, invoke GetOAuth2DeviceCode() method followed by
// AddAccount() instead of using SelectAccount(), which only works for
// Android.
GetOAuth2DeviceCode(array<string> scopes) => (string? verification_url,
string? device_code,
string? user_code,
string? error);
// Exchanges an oauth2 device code to a refresh token for the granted user,
// and stores it locally in a secure storage location on FNL. For future
// GetOAuth2Token requests, a new access token is minted from this refresh
// token and returned to the calling mojo app.
AddAccount(string device_code) => (string? username, string? error);
};
......@@ -14,6 +14,7 @@
#include "mojo/public/cpp/bindings/lib/message_builder.h"
#include "mojo/public/cpp/system/macros.h"
#include "mojo/public/cpp/system/message_pipe.h"
#include "mojo/public/cpp/system/time.h"
#include "mojo/services/log/interfaces/entry.mojom.h"
#include "mojo/services/log/interfaces/log.mojom.h"
......
......@@ -6,7 +6,7 @@
module mojo.media;
import "mojo/services/media/common/interfaces/media_common.mojom";
import "mojo/services/media/common/interfaces/media_pipe.mojom";
import "mojo/services/media/common/interfaces/media_transport.mojom";
import "mojo/services/media/common/interfaces/media_types.mojom";
import "mojo/services/media/common/interfaces/rate_control.mojom";
......@@ -48,7 +48,7 @@ interface AudioTrack {
Describe() => (AudioTrackDescriptor descriptor);
// Set the configuration, receive a pipe to send data to in return.
Configure(AudioTrackConfiguration configuration, MediaPipe& pipe);
Configure(AudioTrackConfiguration configuration, MediaConsumer& pipe);
// Request the rate control interface for this AudioTrack
GetRateControl(RateControl& rate_control);
......
......@@ -6,7 +6,7 @@
#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/services/media/common/cpp/circular_buffer_media_pipe_adapter.h"
#include "mojo/services/media/common/interfaces/media_common.mojom.h"
#include "mojo/services/media/common/interfaces/media_pipe.mojom.h"
#include "mojo/services/media/common/interfaces/media_transport.mojom.h"
namespace mojo {
namespace media {
......@@ -26,20 +26,20 @@ CircularBufferMediaPipeAdapter::MappedPacket::~MappedPacket() {
CircularBufferMediaPipeAdapter::PacketState::PacketState(
uint64_t post_consume_rd,
uint32_t seq_num,
const MediaPipe::SendPacketCallback& cbk)
const MediaConsumer::SendPacketCallback& cbk)
: post_consume_rd_(post_consume_rd),
seq_num_(seq_num),
cbk_(cbk) {}
CircularBufferMediaPipeAdapter::PacketState::~PacketState() { }
CircularBufferMediaPipeAdapter::CircularBufferMediaPipeAdapter(
MediaPipePtr pipe)
MediaConsumerPtr pipe)
: pipe_(pipe.Pass())
, thiz_(new CircularBufferMediaPipeAdapter*(this)) {
MOJO_DCHECK(pipe_);
MOJO_DCHECK(RunLoop::current());
pipe_flush_cbk_ = MediaPipe::FlushCallback(
pipe_flush_cbk_ = MediaConsumer::FlushCallback(
[this] () {
HandleFlush();
});
......@@ -117,7 +117,7 @@ void CircularBufferMediaPipeAdapter::Init(uint64_t size) {
// TODO(johngro) : We should not have to send the buffer size, it should be an
// intrinsic property of the buffer itself and be query-able via the handle.
pipe_->SetBuffer(duplicated_handle.Pass(), buffer_size_);
pipe_->SetBuffer(duplicated_handle.Pass(), buffer_size_, []() {});
}
void CircularBufferMediaPipeAdapter::SetSignalCallback(SignalCbk cbk) {
......@@ -244,7 +244,7 @@ MediaResult CircularBufferMediaPipeAdapter::CreateMediaPacket(
MediaResult CircularBufferMediaPipeAdapter::SendMediaPacket(
MappedPacket* packet,
const MediaPipe::SendPacketCallback& cbk) {
const MediaConsumer::SendPacketCallback& cbk) {
MOJO_DCHECK(packet && !packet->packet_.is_null());
if (!packet || packet->packet_.is_null()) {
return MediaResult::INVALID_ARGUMENT;
......@@ -297,7 +297,7 @@ MediaResult CircularBufferMediaPipeAdapter::SendMediaPacket(
pipe_->SendPacket(
packet->packet_.Pass(),
[this, seq_num](MediaPipe::SendResult result) {
[this, seq_num](MediaConsumer::SendResult result) {
HandleSendPacket(seq_num, result);
});
......@@ -346,8 +346,8 @@ MediaResult CircularBufferMediaPipeAdapter::Flush() {
void CircularBufferMediaPipeAdapter::HandleSendPacket(
uint32_t seq_num,
MediaPipe::SendResult result) {
MediaPipe::SendPacketCallback cbk;
MediaConsumer::SendResult result) {
MediaConsumer::SendPacketCallback cbk;
do {
// There should be at least one element in the in-flight queue, and the
......
......@@ -13,13 +13,13 @@
#include "mojo/public/cpp/bindings/callback.h"
#include "mojo/public/cpp/environment/logging.h"
#include "mojo/services/media/common/interfaces/media_common.mojom.h"
#include "mojo/services/media/common/interfaces/media_pipe.mojom.h"
#include "mojo/services/media/common/interfaces/media_transport.mojom.h"
namespace mojo {
namespace media {
// A class to help producers of media with the bookkeeping involved in using the
// shared buffer provided by a MediaPipe mojo interface in a circular buffer
// shared buffer provided by a MediaConsumer mojo interface in a circular buffer
// fashion.
//
class CircularBufferMediaPipeAdapter {
......@@ -73,14 +73,14 @@ class CircularBufferMediaPipeAdapter {
/**
* Constructor
*
* Create an adapter which will take ownership of the provided MediaPipe
* Create an adapter which will take ownership of the provided MediaConsumer
* interface and assist in the process of generating MediaPackets and
* marshalling them to the other side of the MediaPipe.
* marshalling them to the other side of the MediaConsumer.
*
* @param pipe A pointer to the MediaPipe interface which will be used as the
* target for MediaPackets.
* @param pipe A pointer to the MediaConsumer interface which will be used as
* the target for MediaPackets.
*/
explicit CircularBufferMediaPipeAdapter(MediaPipePtr pipe);
explicit CircularBufferMediaPipeAdapter(MediaConsumerPtr pipe);
/**
* Destructor
......@@ -91,7 +91,7 @@ class CircularBufferMediaPipeAdapter {
* Init
*
* Allocate a shared memory buffer of the specified size and begin the process
* of marshalling it to the other side of the MediaPipe.
* of marshalling it to the other side of the MediaConsumer.
*
* @param size The size in bytes of the shared memory buffer to allocate.
*/
......@@ -189,8 +189,8 @@ class CircularBufferMediaPipeAdapter {
*/
MediaResult SendMediaPacket(
MappedPacket* packet,
const MediaPipe::SendPacketCallback& cbk =
MediaPipe::SendPacketCallback());
const MediaConsumer::SendPacketCallback& cbk =
MediaConsumer::SendPacketCallback());
/**
* Cancel a packet previously created using CreateMediaPacket.
......@@ -220,16 +220,16 @@ class CircularBufferMediaPipeAdapter {
struct PacketState {
PacketState(uint64_t post_consume_rd,
uint32_t seq_num,
const MediaPipe::SendPacketCallback& cbk);
const MediaConsumer::SendPacketCallback& cbk);
~PacketState();
uint64_t post_consume_rd_;
uint32_t seq_num_;
MediaPipe::SendPacketCallback cbk_;
MediaConsumer::SendPacketCallback cbk_;
};
using PacketStateQueue = std::deque<PacketState>;
void HandleSendPacket(uint32_t seq_num, MediaPipe::SendResult result);
void HandleSendPacket(uint32_t seq_num, MediaConsumer::SendResult result);
void HandleFlush();
void HandleSignalCallback();
......@@ -246,9 +246,9 @@ class CircularBufferMediaPipeAdapter {
}
// Pipe interface callbacks
MediaPipePtr pipe_;
MediaPipe::FlushCallback pipe_flush_cbk_;
Closure signalled_callback_;
MediaConsumerPtr pipe_;
MediaConsumer::FlushCallback pipe_flush_cbk_;
Closure signalled_callback_;
// A small helper which lets us nerf callbacks we may have directly scheduled
// on the main run loop which may be in flight as we get destroyed.
......
......@@ -10,7 +10,6 @@ mojom("interfaces") {
"media_clock.mojom",
"media_common.mojom",
"media_metadata.mojom",
"media_pipe.mojom",
"media_state.mojom",
"media_transport.mojom",
"media_types.mojom",
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[DartPackage="mojo_services"]
module mojo.media;
import "mojo/services/media/common/interfaces/media_common.mojom";
// MediaPacketRegion
//
// A small structure used to keep track of a portion of a shared buffer used by
// a MediaPacket to hold its payload.
struct MediaPacketRegion {
uint64 offset;
uint64 length;
};
// MediaPacket
//
// A structure which hold the definition of an atomic unit of media which may be
// sent across a media pipe. MediaPackets consist of the metadata for the unit
// of media, as well as the set of offset/lengths in the pipe's shared buffer
// which define the payload of the packet itself.
struct MediaPacket {
const int64 kNoTimestamp = 0x7fffffffffffffff;
// Presentation Time Stamp. Time at which the media should be presented,
// according to the media timeline.
int64 pts = kNoTimestamp;
// Duration represented by the packet.
uint64 duration;
// Indicates whether this is the last packet in the stream.
bool end_of_stream;
// Bookkeeping to determine where this MediaPacket's payload exists in its
// MediaPipe's shared buffer.
//
// For simple cases, only the payload field is used. It provides the offset
// into the shared buffer for the payload, as well as its length. In more
// complicated cases (circular buffer, arbitrary scatter-gather), additional
// regions may be described in the extra_payload array. Logically, the
// payload is the concatination of the payload region, followed by the extra
// payload regions, from index 0 to index N-1.
//
// TODO(johngro): Depending on what happens with mojo struct marshalling,
// consider merging payload and extra_payload into just a single array. The
// intention was to not need any extra allocations if there way only a single
// payload region, but right now we always need to allocate an array, even if
// it is zero length. If this is not going to change, then we should just
// merge these two fields.
MediaPacketRegion payload;
array<MediaPacketRegion>? extra_payload;
// TODO(johngro): do we need to describe the MediaType of this payload, or is
// its type implicit based on the channel over which it is being pushed?
// TODO(johngro): how do we attach per-packet media specific metadata to this
// packet?
};
// MediaPipe
//
// An interface exposed by consumers of media which provides the means for
// producers to send media to consumers. A pipe logically consists of a shared
// memory region, and an ordered queue of MediaPackets. Users obtain access to
// the shared buffer via the GetState method. They may then send packet to the
// other side of the pipe using the SendPacket method and be informed about when
// the media has been consumed via the SendPacket callback they provide.
// Finally, the pipeline may be flushed using the Flush method.
interface MediaPipe {
const uint64 kMaxBufferLen = 0x3FFFFFFFFFFFFFFF;
// An enumeration used to indicate the ultimate fate of packets sent across
// the pipe using the SendPacket method.
enum SendResult {
CONSUMED, // Media was completely consumed.
FLUSHED, // Some or all of the media was flushed before being consumed.
};
// Sets the shared buffer in which sent Packet payloads will be located.
SetBuffer(handle<shared_buffer> buffer, uint64 size);
// Place a media packet into the pipeline to be consumed. When the consumer
// is finished with the packet, it will invoke the supplied callback to
// indicate that the region of the shared buffer indicated by the MediaPacket
// object is now available for new data. In addition, a SendResult will be
// providid indicating whether or not the packet was consumed or flushed.
SendPacket(MediaPacket packet) => (SendResult result);
// Flush the pipe, discarding all queued packets in order (from front to back)
// as we go. When the flush operation is complete, the provided callback will
// be invoked to indicate that the consumer end of the pipe has finished
// flushing and that the pipeline is now empty.
Flush() => ();
};
......@@ -6,9 +6,62 @@
module mojo.media;
import "mojo/services/media/common/interfaces/media_common.mojom";
import "mojo/services/media/common/interfaces/media_pipe.mojom";
import "mojo/services/media/common/interfaces/media_types.mojom";
// MediaPacketRegion
//
// A small structure used to keep track of a portion of a shared buffer used by
// a MediaPacket to hold its payload.
struct MediaPacketRegion {
uint64 offset;
uint64 length;
};
// MediaPacket
//
// A structure which hold the definition of an atomic unit of media which may be
// sent across a media pipe. MediaPackets consist of the metadata for the unit
// of media, as well as the set of offset/lengths in the pipe's shared buffer
// which define the payload of the packet itself.
struct MediaPacket {
const int64 kNoTimestamp = 0x7fffffffffffffff;
// Presentation Time Stamp. Time at which the media should be presented,
// according to the media timeline.
int64 pts = kNoTimestamp;
// Duration represented by the packet.
uint64 duration;
// Indicates whether this is the last packet in the stream.
bool end_of_stream;
// Bookkeeping to determine where this MediaPacket's payload exists in its
// MediaPipe's shared buffer.
//
// For simple cases, only the payload field is used. It provides the offset
// into the shared buffer for the payload, as well as its length. In more
// complicated cases (circular buffer, arbitrary scatter-gather), additional
// regions may be described in the extra_payload array. Logically, the
// payload is the concatination of the payload region, followed by the extra
// payload regions, from index 0 to index N-1.
//
// TODO(johngro): Depending on what happens with mojo struct marshalling,
// consider merging payload and extra_payload into just a single array. The
// intention was to not need any extra allocations if there way only a single
// payload region, but right now we always need to allocate an array, even if
// it is zero length. If this is not going to change, then we should just
// merge these two fields.
MediaPacketRegion payload;
array<MediaPacketRegion>? extra_payload;
// TODO(johngro): do we need to describe the MediaType of this payload, or is
// its type implicit based on the channel over which it is being pushed?
// TODO(johngro): how do we attach per-packet media specific metadata to this
// packet?
};
// Models a stream producer. A MediaProducer allows a client to connect the
// producer to a MediaConsumer so packets flow from the producer to the
// consumer. Clients who want to receive packets directly from the producer
......@@ -59,12 +112,25 @@ interface MediaPullModeProducer {
// producer and consumer. The producer then calls PushPacket on the consumer to
// deliver packets.
interface MediaConsumer {
const uint64 kMaxBufferLen = 0x3FFFFFFFFFFFFFFF;
// An enumeration used to indicate the ultimate fate of packets sent across
// the pipe using the SendPacket method.
enum SendResult {
CONSUMED, // Media was completely consumed.
FLUSHED, // Some or all of the media was flushed before being consumed.
};
// Sets the shared buffer in which packet payload will be located.
SetBuffer(handle<shared_buffer> buffer, uint64 size) => ();
// Pushes a packet to the consumer. The callback signals that the consumer
// Sends a packet to the consumer. The callback signals that the consumer
// is done with the packet buffer region.
PushPacket(MediaPacket packet) => ();
SendPacket(MediaPacket packet) => (SendResult result);
// Primes the stream. The callback signals that the prime operation is
// complete.
Prime() => ();
// Flushes the stream. The callback signals that the flush operation is
// complete.
......
......@@ -9,6 +9,7 @@ import "mojo/services/media/common/interfaces/media_types.mojom";
import "mojo/services/media/control/interfaces/media_player.mojom";
import "mojo/services/media/control/interfaces/media_sink.mojom";
import "mojo/services/media/control/interfaces/media_source.mojom";
import "mojo/services/media/core/interfaces/media_type_converter.mojom";
// Exposed by the factory service to create media-related agents.
[ServiceName="mojo::media::MediaFactory"]
......@@ -31,4 +32,7 @@ interface MediaFactory {
// convert the indicated media type to a type compatible with the
// destination.
CreateSink(string destination_url, MediaType media_type, MediaSink& sink);
// Creates a decoder.
CreateDecoder(MediaType input_media_type, MediaTypeConverter& decoder);
};
......@@ -17,6 +17,11 @@ interface MediaPlayer {
// Pauses playback.
Pause();
// Seeks to the specified position, specified in nanoseconds.
// TODO(dalesat): Consider adding relative vs remote flag.
// TODO(dalesat): Consider adding parameters regarding desired precision.
Seek(int64 position);
// Gets the status. To get the status immediately, call GetStatus(0). To
// get updates thereafter, pass the version sent in the previous callback.
GetStatus(uint64 version_last_seen) =>
......
......@@ -40,8 +40,14 @@ interface MediaSource {
// Prepares the source.
Prepare() => ();
// Flushes the source.
// Primes the source and downstream components.
Prime() => ();
// Flushes the source and downstream components.
Flush() => ();
// Seeks to the specified position, specified in nanoseconds.
Seek(int64 position) => ();
};
// Describes a media stream produced by a source.
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/module_args/mojo.gni")
import("$mojo_sdk_root/mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"media_type_converter.mojom",
]
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[DartPackage="mojo_services"]
module mojo.media;
import "mojo/services/media/common/interfaces/media_transport.mojom";
import "mojo/services/media/common/interfaces/media_types.mojom";
// Performs a type conversion on a media stream.
interface MediaTypeConverter {
// Gets the converter’s output type.
GetOutputType() => (MediaType output_type);
// Gets the consumer.
GetConsumer(MediaConsumer& consumer);
// Gets the producer.
GetProducer(MediaProducer& producer);
};
......@@ -30,6 +30,7 @@ mojo_services = [
"//mojo/services/media/audio/interfaces",
"//mojo/services/media/common/interfaces",
"//mojo/services/media/control/interfaces",
"//mojo/services/media/core/interfaces",
"//mojo/services/native_support/interfaces",
"//mojo/services/native_viewport/interfaces",
"//mojo/services/navigation/interfaces",
......
......@@ -18,6 +18,10 @@ std::ostream& operator<<(std::ostream& os,
return os << "{value=" << value.value << "}";
}
std::ostream& operator<<(std::ostream& os, const mojo::ui::ViewInfo& value) {
return os << "{scene_token=" << value.scene_token << "}";
}
std::ostream& operator<<(std::ostream& os,
const mojo::ui::BoxConstraints& value) {
return os << "{min_width=" << value.min_width
......@@ -34,8 +38,7 @@ std::ostream& operator<<(std::ostream& os,
std::ostream& operator<<(std::ostream& os,
const mojo::ui::ViewLayoutInfo& value) {
return os << "{size=" << value.size << ", scene_token=" << value.scene_token
<< "}";
return os << "{size=" << value.size << "}";
}
std::ostream& operator<<(std::ostream& os,
......
......@@ -21,6 +21,8 @@ std::ostream& operator<<(std::ostream& os, const mojo::ui::ViewToken& value);
std::ostream& operator<<(std::ostream& os,
const mojo::ui::ViewTreeToken& value);
std::ostream& operator<<(std::ostream& os, const mojo::ui::ViewInfo& value);
std::ostream& operator<<(std::ostream& os,
const mojo::ui::BoxConstraints& value);
std::ostream& operator<<(std::ostream& os,
......
......@@ -9,8 +9,11 @@ mojom("interfaces") {
sources = [
"layouts.mojom",
"view_associates.mojom",
"view_containers.mojom",
"view_manager.mojom",
"view_provider.mojom",
"view_token.mojom",
"view_tree_token.mojom",
"view_trees.mojom",
"views.mojom",
]
......
......@@ -6,7 +6,6 @@
module mojo.ui;
import "mojo/services/geometry/interfaces/geometry.mojom";
import "mojo/services/gfx/composition/interfaces/scene_token.mojom";
// Box constraints for layout.
//
......@@ -64,10 +63,8 @@ struct ViewLayoutParams {
};
// Layout information for a view.
// TODO(jeffbrown): Delete this while redesigning layout protocol.
struct ViewLayoutInfo {
// The view's scene token for composition by the parent.
mojo.gfx.composition.SceneToken scene_token;
// The actual size of the view in device pixels.
mojo.Size size;
};
......
......@@ -6,9 +6,10 @@
module mojo.ui;
import "mojo/public/interfaces/application/service_provider.mojom";
import "mojo/services/gfx/composition/interfaces/hit_tests.mojom";
import "mojo/services/gfx/composition/interfaces/scene_token.mojom";
import "mojo/services/ui/views/interfaces/views.mojom";
import "mojo/services/ui/views/interfaces/view_trees.mojom";
import "mojo/services/ui/views/interfaces/view_token.mojom";
import "mojo/services/ui/views/interfaces/view_tree_token.mojom";
// View associates are trusted components that are attached to a view manager
// instance with the purpose of offering additional services to views and
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[DartPackage="mojo_services"]
module mojo.ui;
import "mojo/services/gfx/composition/interfaces/scene_token.mojom";
import "mojo/services/ui/views/interfaces/layouts.mojom";
import "mojo/services/ui/views/interfaces/view_token.mojom";
// A view container is an interface exposed by |View| and |ViewTree| to
// manage their child views. Although |View| may have any number of children,
// a |ViewTree| can have at most one (its root view).
//
// EMBEDDING
//
// The following steps are required to embed another view as a child:
//
// 1. Obtain the |ViewOwner| belonging to the view you would like to embed.
// The means for doing this is not specified by the view system.
// You might create another view of your own to embed or connect to
// another application using a mechanism such as |ViewProvider| (or
// any suitable agreed-upon protocol) to create the view to embed.
//
// 2. Call |AddChild()| to add the view you would like to embed and assign
// it a unique key.
//
// 3. Call |LayoutChild()| to provide layout parameters for the new child
// using the key that was provided.
//
// 4. After obtaining the layout result from the child, publish an
// update to your |Scene| which includes a reference to the child's own
// scene using the |SceneToken| included in the layout result.
//
// 5. Watch for the child becoming unavailable, as reported by
// |OnChildUnavailable()|, which indicates that the child is no longer
// in a usable state (perhaps the application which provided it has
// stopped). When this happens, you are still responsible for calling
// |RemoveChild()| to remove the child and discard any state that your
// view has associated with it.
//
// LAYOUT
//
// TODO(jeffbrown): Elaborate this once the layout protocol has been
// redesigned.
interface ViewContainer {
// Sets the view container listener, or null to remove.
SetListener(ViewContainerListener? listener);
// Adds the view referenced by |child_view_owner| as a child and assigns
// it the provided |child_key| to identify it among its children.
// The container may remove the child later by passing the same |child_key|
// to |RemoveChild()|.
//
// This method takes ownership of the view.
//
// It is important for the container to choose locally unique values for
// |child_key| to ensure that each child can be distinguished even as
// more children are added or removed. We recommend using a simple
// counter which is incremented on each (re-)addition.
//
// If the child becomes unavailable at any time prior to being removed
// then an |OnChildUnavailable()| message will be sent.
//
// If |child_view_owner| refers to a view which is already unavailable or
// if adding the view would create a cycle in the view tree then the
// call proceeds as if it succeeded but an |OnChildUnavailable()| message
// will be sent.
//
// If |child_view_owner| refers to a view which already has a container or is
// the root of a view tree then an |OnChildUnavailable()| message will
// be sent to its old container or root and the the view will be
// (re-)added to its new container as usual. This special case also
// applies when the specified view is already a child of this view, in which
// case the behavior is similar to the view having been transferred to
// some other container and then back again.
//
// Note that an unavailable child will remain in its container's list of
// children until its container explicitly calls |RemoveChild()| to remove
// it.
//
// It is an error to add a view whose |child_key| already appears
// in the view's list of children; the connection will be closed.
//
// It is an error to add more than one child to a |ViewTree|'s container;
// it can only have at most one child (its root).
AddChild(uint32 child_key, ViewOwner child_view_owner);
// Removes the view referenced by |child_key| from the view's
// list of children.
//
// If |transferred_view_owner| is not null, associates it with the
// previously added child to allow it to be transferred elsewhere or
// closes the |transferred_view_owner| message pipe if there was none.
//
// It is an error to remove a view whose |child_key| does not appear
// in the container's list of children; the connection will be closed.
RemoveChild(uint32 child_key, ViewOwner&? transferred_view_owner);
// Sets the layout parameters of the child view referenced by |child_key|
// and retrieves its layout information.
//
// The returned |info| is null if this layout request was canceled either
// because it has been superceded by a subsequently issued layout request
// or because the child has become unavailable.
//
// It is an error to specify a |child_key| that does not appear in
// the parent's list of children; the connection will be closed.
//
// It is an error to specify malformed |child_layout_params| such
// as invalid size constraints; the connection will be closed.
LayoutChild(uint32 child_key, mojo.ui.ViewLayoutParams child_layout_params)
=> (mojo.ui.ViewLayoutInfo? info);
};
// An interface clients may implement to receive events from a view container.
interface ViewContainerListener {
// Called when a child view is attached along with embedding information.
//
// This method will be called at most once after the child is added.
//
// The implementation should invoke the callback once the event has
// been handled.
OnChildAttached(uint32 child_key, ViewInfo child_view_info) => ();
// Called when a child view has become unavailable.
//
// A child may become unavailable for many reasons such being unregistered
// by its application, abnormal termination of its application, or
// cycles being introduced in the view tree.
//
// To complete removal of an unavailable child, this view component must
// call RemoveChild() on its view with |child_key|.
//
// The implementation should invoke the callback once the event has
// been handled.
OnChildUnavailable(uint32 child_key) => ();
};
// Provides embedding information about a view for use by its container.
//
// This information is valid until the container removes the view.
struct ViewInfo {
// The scene which represents the contents of the embedded view to be
// included in its container's view.
//
// This scene is created by the view manager as a wrapper for the actual
// scene generated by the embedded view. It will be destroyed when the
// container removes the view.
mojo.gfx.composition.SceneToken scene_token;
};
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[DartPackage="mojo_services"]
module mojo.ui;
// A view token is an opaque transferable reference to a view.
//
// The ViewManager provides each view with a unique view token when
// it is registered. The token can subsequently be passed to other
// applications and may be used to add the view as a child of some
// other view or to set it as the root of a view tree.
//
// View tokens should be kept secret and should only be shared with
// the view's intended container.
//
// TODO(jeffbrown): This implementation is a temporary placeholder until
// we extend Mojo to provide a way to create tokens which cannot be forged.
struct ViewToken {
uint32 value;
};
// A view owner provides access to the view's token and keeps the
// view alive. When the view owner is closed, the view will be
// unregistered from the view manager.
//
// This interface is only intended to be implemented by the view manager
// to obtain the desired ownership semantics.
interface ViewOwner {
// Gets the |ViewToken| associated with the view.
GetToken() => (ViewToken token);
};
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
[DartPackage="mojo_services"]
module mojo.ui;
// A view tree token is an opaque transferable reference to a view tree.
//
// The ViewManager provides each view tree with a unique view tree token when
// it is registered. The token can subsequently be passed to other
// applications and used as a way to refer to the tree.
//
// View tree tokens should be kept secret and should only be shared with
// trusted services.
//
// TODO(jeffbrown): This implementation is a temporary placeholder until
// we extend Mojo to provide a way to create tokens which cannot be forged.
struct ViewTreeToken {
uint32 value;
};
......@@ -7,23 +7,8 @@ module mojo.ui;
import "mojo/public/interfaces/application/service_provider.mojom";
import "mojo/services/gfx/composition/interfaces/renderers.mojom";
import "mojo/services/ui/views/interfaces/layouts.mojom";
import "mojo/services/ui/views/interfaces/views.mojom";
// A view tree token is an opaque transferable reference to a view tree.
//
// The ViewManager provides each view tree with a unique view tree token when
// it is registered. The token can subsequently be passed to other
// applications and used as a way to refer to the tree.
//
// View tree tokens should be kept secret and should only be shared with
// trusted services.
//
// TODO(jeffbrown): This implementation is a temporary placeholder until
// we extend Mojo to provide a way to create tokens which cannot be forged.
struct ViewTreeToken {
uint32 value;
};
import "mojo/services/ui/views/interfaces/view_containers.mojom";
import "mojo/services/ui/views/interfaces/view_tree_token.mojom";
// A view tree is a top-level container for a hierarchy of views.
// Each view is intended to operate independently from others and will
......@@ -44,10 +29,11 @@ struct ViewTreeToken {
//
// To destroy a view tree, simply close the |ViewTree| message pipe.
//
// LAYOUT
// SETTING A ROOT VIEW
//
// Use |GetContainer()| to obtain an interface for manipulating the root view.
//
// TODO(jeffbrown): Elaborate this once the layout protocol has been
// redesigned.
// See |mojo.ui.ViewContainer| for more information.
//
// GETTING SERVICES
//
......@@ -86,53 +72,8 @@ interface ViewTree {
// new layout due to a change in the view tree's layout information.
RequestLayout();
// Sets the root of the view tree and assigns it the provided |root_key|
// to distinguish it from any other roots this view tree has had.
//
// It is a good idea to provide a distinct |root_key| each time a new root
// is set so that callbacks related to the root can be clearly distinguished
// across these changes.
//
// If |root_view_owner| refers to a view which is already unavailable
// then the call proceeds as if it succeeded but an OnChildUnavailable()
// message will be sent.
//
// If |root_view_owner| refers to a view which already has a parent or is
// the root of a view tree then an OnChildUnavailable() or OnRootUnavailable()
// message will be sent to its old parent or root and the the view will be
// used as the root of the new view tree as usual. This special case also
// applies when the specified view is already the root of this view tree, in
// which case the behavior is similar to the view having been transferred to
// some other view tree and then back again.
//
// It is an error to call this function if the root has already been set;
// the connection will be closed.
SetRoot(uint32 root_key, mojo.ui.ViewOwner root_view_owner);
// Removes the root of the view tree.
//
// If |transferred_view_owner| is not null, associates it with the previously
// configured view or closes the |transferred_view_owner| message pipe
// if there was none.
//
// It is an error to call this function if the root was not previously set;
// the connection will be closed.
ClearRoot(mojo.ui.ViewOwner&? transferred_view_owner);
// Sets the layout parameters of the root of the view tree and retrieves
// its layout information.
//
// The returned |info| is null if this layout request was canceled either
// because it has been superceded by a subsequently issued layout request
// or because the root has become unavailable.
//
// It is an error to call this function if the view tree does not currently
// have a root; the connection will be closed.
//
// It is an error to specify malformed |root_layout_params| such
// as invalid size constraints; the connection will be closed.
LayoutRoot(mojo.ui.ViewLayoutParams root_layout_params) =>
(mojo.ui.ViewLayoutInfo? info);
// Gets an interface for managing the view tree's root.
GetContainer(ViewContainer& container);
};
// An interface clients may implement to receive events from a view tree.
......@@ -153,16 +94,6 @@ interface ViewTreeListener {
// been handled and the view tree is ready to be shown in its new aspect.
OnLayout() => ();
// Called when the root view has become unavailable.
//
// The root may become unavailable for many reasons such being unregistered
// by its application, abnormal termination of its application, or
// being reparented into a different view tree.
//
// The implementation should invoke the callback once the event has
// been handled.
OnRootUnavailable(uint32 root_key) => ();
// Called when the tree's renderer connection closed unexpectedly.
//
// The implementation should invoke the callback once the event has
......
......@@ -8,33 +8,8 @@ module mojo.ui;
import "mojo/public/interfaces/application/service_provider.mojom";
import "mojo/services/gfx/composition/interfaces/scenes.mojom";
import "mojo/services/ui/views/interfaces/layouts.mojom";
// A view token is an opaque transferable reference to a view.
//
// The ViewManager provides each view with a unique view token when
// it is registered. The token can subsequently be passed to other
// applications and may be used to add the view as a child of some
// other view or to set it as the root of a view tree.
//
// View tokens should be kept secret and should only be shared with
// the view's intended container.
//
// TODO(jeffbrown): This implementation is a temporary placeholder until
// we extend Mojo to provide a way to create tokens which cannot be forged.
struct ViewToken {
uint32 value;
};
// A view owner provides access to the view's token and keeps the
// view alive. When the view owner is closed, the view will be
// unregistered from the view manager.
//
// This interface is only intended to be implemented by the view manager
// to obtain the desired ownership semantics.
interface ViewOwner {
// Gets the |ViewToken| associated with the view.
GetToken() => (ViewToken token);
};
import "mojo/services/ui/views/interfaces/view_containers.mojom";
import "mojo/services/ui/views/interfaces/view_token.mojom";
// A view is a graphical user interface component which is responsible
// for drawing and supporting user interactions in the area of the screen
......@@ -63,37 +38,11 @@ interface ViewOwner {
//
// See |mojo.gfx.compositor.Scene| for more information.
//
// EMBEDDING
// ADDING CHILD VIEWS
//
// The following steps are required to embed another view into your own:
// Use |GetContainer()| to obtain an interface for manipulating child views.
//
// 1. Obtain the |ViewOwner| belonging to the view you would like to embed.
// The means for doing this is not specified by the view system.
// You might create another view of your own to embed or connect to
// another application using a mechanism such as |ViewProvider| (or
// any suitable agreed-upon protocol) to create the view to embed.
//
// 2. Call |AddChild()| to add the view you would like to embed and assign
// it a unique key.
//
// 3. Call |LayoutChild()| to provide layout parameters for the new child
// using the key that was provided.
//
// 4. After obtaining the layout result from the child, publish an
// update to your |Scene| which includes a reference to the child's own
// scene using the |SceneToken| included in the layout result.
//
// 5. Watch for the child becoming unavailable, as reported by
// |OnChildUnavailable()|, which indicates that the child is no longer
// in a usable state (perhaps the application which provided it has
// stopped). When this happens, you are still responsible for calling
// |RemoveChild()| to remove the child and discard any state that your
// view has associated with it.
//
// LAYOUT
//
// TODO(jeffbrown): Elaborate this once the layout protocol has been
// redesigned.
// See |mojo.ui.ViewContainer| for more information.
//
// GETTING SERVICES
//
......@@ -135,67 +84,8 @@ interface View {
// new layout due to a change in the view's layout information.
RequestLayout();
// Adds the view referenced by |child_view_owner| as a child and assigns
// it the provided |child_key| to identify it among its children.
// The parent may remove the child later by passing the same |child_key|
// to RemoveChild().
//
// This method takes ownership of the view.
//
// It is important for the parent to choose locally unique values for
// |child_key| to ensure that each child can be distinguished even as
// more children are added or removed. We recommend using a simple
// counter which is incremented on each (re-)addition.
//
// If the child becomes unavailable at any time prior to being removed
// then an OnChildUnavailable() message will be sent.
//
// If |child_view_owner| refers to a view which is already unavailable or
// if adding the view would create a cycle in the view tree then the
// call proceeds as if it succeeded but an OnChildUnavailable() message
// will be sent.
//
// If |child_view_owner| refers to a view which already has a parent or is
// the root of a view tree then an OnChildUnavailable() or OnRootUnavailable()
// message will be sent to its old parent or root and the the view will be
// (re-)added to its new parent as usual. This special case also applies
// when the specified view is already a child of this view, in which
// case the behavior is similar to the view having been transferred to
// some other parent and then back again.
//
// Note that an unavailable child will remain in its parent's list of
// children until its parent explicitly calls RemoveChild() to remove
// it.
//
// It is an error to add a view whose |child_key| already appears
// in the view's list of children; the connection will be closed.
AddChild(uint32 child_key, mojo.ui.ViewOwner child_view_owner);
// Removes the view referenced by |child_key| from the view's
// list of children.
//
// If |transferred_view_owner| is not null, associates it with the
// previously added child to allow it to be transferred elsewhere or
// closes the |transferred_view_owner| message pipe if there was none.
//
// It is an error to remove a view whose |child_key| does not appear
// in the parent's list of children; the connection will be closed.
RemoveChild(uint32 child_key, mojo.ui.ViewOwner&? transferred_view_owner);
// Sets the layout parameters of the child view referenced by |child_key|
// and retrieves its layout information.
//
// The returned |info| is null if this layout request was canceled either
// because it has been superceded by a subsequently issued layout request
// or because the child has become unavailable.
//
// It is an error to specify a |child_key| that does not appear in
// the parent's list of children; the connection will be closed.
//
// It is an error to specify malformed |child_layout_params| such
// as invalid size constraints; the connection will be closed.
LayoutChild(uint32 child_key, mojo.ui.ViewLayoutParams child_layout_params)
=> (mojo.ui.ViewLayoutInfo? info);
// Gets an interface for managing the view's children.
GetContainer(ViewContainer& container);
};
// An interface clients may implement to receive events from a view.
......@@ -242,17 +132,4 @@ interface ViewListener {
// exceeds the requested constraints; the view's connection will be closed.
OnLayout(mojo.ui.ViewLayoutParams layout_params,
array<uint32> children_needing_layout) => (mojo.ui.ViewLayoutResult result);
// Called when a child view has become unavailable.
//
// A child may become unavailable for many reasons such being unregistered
// by its application, abnormal termination of its application, or
// cycles being introduced in the view tree.
//
// To complete removal of an unavailable child, this view component must
// call RemoveChild() on its view with |child_key|.
//
// The implementation should invoke the callback once the event has
// been handled.
OnChildUnavailable(uint32 child_key) => ();
};
......@@ -4,6 +4,6 @@ author: Flutter Authors <flutter-dev@googlegroups.com>
description: Mojom interfaces associated with Flutter
homepage: http://flutter.io
dependencies:
mojo_sdk: 0.2.19
mojo_sdk: 0.2.20
environment:
sdk: '>=1.8.0 <2.0.0'
......@@ -113,11 +113,6 @@ void ViewImpl::OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params,
callback.Run(info.Pass());
}
void ViewImpl::OnChildUnavailable(uint32_t child_key,
const OnChildUnavailableCallback& callback) {
callback.Run();
}
void ViewImpl::OnEvent(mojo::EventPtr event, const OnEventCallback& callback) {
DCHECK(event);
bool consumed = false;
......
......@@ -41,8 +41,6 @@ class ViewImpl : public mojo::ui::ViewListener,
void OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params,
mojo::Array<uint32_t> children_needing_layout,
const OnLayoutCallback& callback) override;
void OnChildUnavailable(uint32_t child_key,
const OnChildUnavailableCallback& callback) override;
// mojo::ui::InputListener
void OnEvent(mojo::EventPtr event, const OnEventCallback& callback) override;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册