Update mojo sdk to rev 04a510fb37db10642e156957f9b2c11c2f6442ac
This updates the mojo sdk and updates chromium code to match. The most significant change is updating references to the mojo JS bindings code, which reshuffled. This part was reviewed separately by hansmuller@ in https://codereview.chromium.org/693343003/. This also updates ipc/mojo to reflect changes in ChannelInfo. R=morrita@chromium.org for ipc/mojo R=jam@chromium.org for top-level approval of the rest Review URL: https://codereview.chromium.org/703273002 Cr-Commit-Position: refs/heads/master@{#303149}
This commit is contained in:
chrome/browser
content
extensions
ipc/mojo
mojo
BUILD.gn
bindings
js
tests
edk
PRESUBMIT.py
mojo.gypmojo_base.gypembedder
js
BUILD.gnDEPScore.cccore.hdrain_data.ccdrain_data.hhandle.cchandle.hhandle_close_observer.hhandle_unittest.ccsupport.ccsupport.h
mojo_edk.gyptests
waiting_callback.ccwaiting_callback.hsystem
public
BUILD.gnVERSION
c
cpp
dart
js
BUILD.gn
mojo.gnimojo_public.gypbindings
buffer.jscodec.jscodec_unittests.jsconnection.jsconnector.jsconstants.ccconstants.hcore.jscore_unittests.jsrouter.jsstruct_unittests.jssupport.jstest
unicode.jsvalidation_unittests.jsvalidator.jspython
mojo
sky
tools
bindings
generators
services
public
cpp
network
view_manager
interfaces
view_manager
ui/keyboard
@ -189,7 +189,7 @@ static_library("browser") {
|
||||
"//mojo/edk/system",
|
||||
"//mojo/environment:chromium",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/js/bindings",
|
||||
"//mojo/public/js",
|
||||
"//net:extras",
|
||||
"//net:net_with_v8",
|
||||
"//storage/browser",
|
||||
|
@ -17,7 +17,7 @@
|
||||
* are available, the Javascript formats them and displays them.
|
||||
*/
|
||||
define('main', [
|
||||
'mojo/public/js/bindings/connection',
|
||||
'mojo/public/js/connection',
|
||||
'chrome/browser/ui/webui/omnibox/omnibox.mojom',
|
||||
'content/public/renderer/service_provider',
|
||||
], function(connector, browser, serviceProvider) {
|
||||
|
@ -32,9 +32,9 @@ include_rules = [
|
||||
|
||||
"+dbus",
|
||||
"+gpu",
|
||||
"+mojo/bindings/js",
|
||||
"+mojo/common",
|
||||
"+mojo/edk/embedder",
|
||||
"+mojo/edk/js",
|
||||
"+mojo/edk/test",
|
||||
"+mojo/public",
|
||||
"+net",
|
||||
|
@ -100,7 +100,7 @@ source_set("browser") {
|
||||
"//content/public/common:mojo_bindings",
|
||||
"//mojo/public/cpp/bindings",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//mojo/public/js/bindings",
|
||||
"//mojo/public/js",
|
||||
"//net:http_server",
|
||||
"//storage/browser",
|
||||
"//storage/common",
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/grit/content_resources.h"
|
||||
#include "content/public/common/content_client.h"
|
||||
#include "mojo/public/js/bindings/constants.h"
|
||||
#include "mojo/public/js/constants.h"
|
||||
#include "ui/base/webui/jstemplate_builder.h"
|
||||
#include "ui/base/webui/web_ui_util.h"
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "mojo/edk/test/test_utils.h"
|
||||
#include "mojo/public/cpp/bindings/interface_impl.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/public/js/bindings/constants.h"
|
||||
#include "mojo/public/js/constants.h"
|
||||
|
||||
namespace content {
|
||||
namespace {
|
||||
|
@ -18,6 +18,7 @@ source_set("child") {
|
||||
deps = [
|
||||
"//base",
|
||||
"//components/tracing",
|
||||
"//mojo/common",
|
||||
"//mojo/environment:chromium",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//skia",
|
||||
|
@ -7,6 +7,7 @@
|
||||
'../base/base.gyp:base',
|
||||
'../components/tracing.gyp:tracing',
|
||||
'../mojo/mojo_base.gyp:mojo_environment_chromium',
|
||||
'../mojo/mojo_base.gyp:mojo_common_lib',
|
||||
'../mojo/public/mojo_public.gyp:mojo_application_bindings',
|
||||
'../skia/skia.gyp:skia',
|
||||
'../ui/base/ui_base.gyp:ui_base',
|
||||
|
@ -16,8 +16,8 @@
|
||||
'../jingle/jingle.gyp:jingle_glue',
|
||||
'../media/blink/media_blink.gyp:media_blink',
|
||||
'../media/media.gyp:media',
|
||||
'../mojo/edk/mojo_edk.gyp:mojo_js_lib',
|
||||
'../mojo/mojo_base.gyp:mojo_environment_chromium',
|
||||
'../mojo/mojo_base.gyp:mojo_js_bindings_lib',
|
||||
'../mojo/public/mojo_public.gyp:mojo_application_bindings',
|
||||
'../net/net.gyp:net',
|
||||
'../skia/skia.gyp:skia',
|
||||
|
@ -38,13 +38,13 @@
|
||||
<include name="IDR_UTILITY_SANDBOX_PROFILE" file="utility/utility.sb" type="BINDATA" />
|
||||
</if>
|
||||
<if expr="not is_ios">
|
||||
<include name="IDR_MOJO_BUFFER_JS" file="../mojo/public/js/bindings/buffer.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CODEC_JS" file="../mojo/public/js/bindings/codec.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CONNECTION_JS" file="../mojo/public/js/bindings/connection.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CONNECTOR_JS" file="../mojo/public/js/bindings/connector.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_ROUTER_JS" file="../mojo/public/js/bindings/router.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_UNICODE_JS" file="../mojo/public/js/bindings/unicode.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_VALIDATOR_JS" file="../mojo/public/js/bindings/validator.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_BUFFER_JS" file="../mojo/public/js/buffer.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CODEC_JS" file="../mojo/public/js/codec.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CONNECTION_JS" file="../mojo/public/js/connection.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_CONNECTOR_JS" file="../mojo/public/js/connector.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_ROUTER_JS" file="../mojo/public/js/router.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_UNICODE_JS" file="../mojo/public/js/unicode.js" flattenhtml="true" type="BINDATA" />
|
||||
<include name="IDR_MOJO_VALIDATOR_JS" file="../mojo/public/js/validator.js" flattenhtml="true" type="BINDATA" />
|
||||
</if>
|
||||
</includes>
|
||||
</release>
|
||||
|
@ -39,9 +39,9 @@ source_set("renderer") {
|
||||
"//jingle:jingle_glue",
|
||||
"//media",
|
||||
"//media/blink",
|
||||
"//mojo/bindings/js",
|
||||
"//mojo/edk/js",
|
||||
"//mojo/environment:chromium",
|
||||
"//mojo/public/js/bindings",
|
||||
"//mojo/public/js",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//net",
|
||||
"//skia",
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
#include "content/common/mojo/service_registry_impl.h"
|
||||
#include "content/public/common/service_registry.h"
|
||||
#include "mojo/bindings/js/handle.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
|
||||
namespace content {
|
||||
|
||||
|
@ -101,8 +101,8 @@
|
||||
#include "media/blink/webmediaplayer_impl.h"
|
||||
#include "media/blink/webmediaplayer_params.h"
|
||||
#include "media/filters/gpu_video_accelerator_factories.h"
|
||||
#include "mojo/bindings/js/core.h"
|
||||
#include "mojo/bindings/js/support.h"
|
||||
#include "mojo/edk/js/core.h"
|
||||
#include "mojo/edk/js/support.h"
|
||||
#include "net/base/data_url.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
|
||||
|
@ -3,7 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
define('main', [
|
||||
'mojo/public/js/bindings/connection',
|
||||
'mojo/public/js/connection',
|
||||
'content/test/data/web_ui_test_mojo_bindings.mojom',
|
||||
'content/public/renderer/service_provider',
|
||||
], function (connection, bindings, serviceProvider) {
|
||||
|
@ -266,7 +266,7 @@ test("extensions_unittests") {
|
||||
"//extensions/common",
|
||||
"//extensions/renderer",
|
||||
"//extensions/strings",
|
||||
"//mojo/bindings/js",
|
||||
"//mojo/edk/js",
|
||||
"//mojo/edk/system",
|
||||
"//mojo/environment:chromium",
|
||||
"//mojo/public/cpp/bindings",
|
||||
|
@ -1130,9 +1130,9 @@
|
||||
'../device/bluetooth/bluetooth.gyp:device_bluetooth_mocks',
|
||||
'../device/serial/serial.gyp:device_serial',
|
||||
'../device/serial/serial.gyp:device_serial_test_util',
|
||||
'../mojo/edk/mojo_edk.gyp:mojo_js_lib',
|
||||
'../mojo/edk/mojo_edk.gyp:mojo_system_impl',
|
||||
'../mojo/mojo_base.gyp:mojo_environment_chromium',
|
||||
'../mojo/mojo_base.gyp:mojo_js_bindings_lib',
|
||||
'../mojo/public/mojo_public.gyp:mojo_cpp_bindings',
|
||||
'../testing/gmock.gyp:gmock',
|
||||
'../testing/gtest.gyp:gtest',
|
||||
|
@ -167,7 +167,7 @@ source_set("renderer") {
|
||||
"//content:resources",
|
||||
"//extensions:extensions_resources",
|
||||
"//gin",
|
||||
"//mojo/bindings/js",
|
||||
"//mojo/edk/js",
|
||||
"//skia",
|
||||
"//third_party/WebKit/public:blink",
|
||||
]
|
||||
|
@ -2,7 +2,7 @@ include_rules = [
|
||||
"+content/public/renderer",
|
||||
|
||||
"+gin",
|
||||
"+mojo/bindings/js",
|
||||
"+mojo/edk/js",
|
||||
|
||||
"+third_party/skia/include/core",
|
||||
|
||||
|
@ -12,9 +12,9 @@
|
||||
#include "extensions/renderer/process_info_native_handler.h"
|
||||
#include "gin/converter.h"
|
||||
#include "gin/dictionary.h"
|
||||
#include "mojo/bindings/js/core.h"
|
||||
#include "mojo/bindings/js/handle.h"
|
||||
#include "mojo/bindings/js/support.h"
|
||||
#include "mojo/edk/js/core.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
#include "mojo/edk/js/support.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "gin/modules/module_registry.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "gin/wrappable.h"
|
||||
#include "mojo/bindings/js/handle.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
#include "mojo/public/cpp/bindings/interface_request.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
||||
|
@ -80,7 +80,7 @@
|
||||
#include "extensions/renderer/utils_native_handler.h"
|
||||
#include "extensions/renderer/v8_context_native_handler.h"
|
||||
#include "grit/extensions_renderer_resources.h"
|
||||
#include "mojo/public/js/bindings/constants.h"
|
||||
#include "mojo/public/js/constants.h"
|
||||
#include "third_party/WebKit/public/platform/WebString.h"
|
||||
#include "third_party/WebKit/public/platform/WebURLRequest.h"
|
||||
#include "third_party/WebKit/public/web/WebCustomElement.h"
|
||||
|
@ -3,7 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
define('async_waiter', [
|
||||
'mojo/public/js/bindings/support',
|
||||
'mojo/public/js/support',
|
||||
], function(supportModule) {
|
||||
/**
|
||||
* @module async_waiter
|
||||
|
@ -5,8 +5,8 @@
|
||||
define('data_receiver', [
|
||||
'device/serial/data_stream.mojom',
|
||||
'device/serial/data_stream_serialization.mojom',
|
||||
'mojo/public/js/bindings/core',
|
||||
'mojo/public/js/bindings/router',
|
||||
'mojo/public/js/core',
|
||||
'mojo/public/js/router',
|
||||
], function(dataStream, serialization, core, router) {
|
||||
/**
|
||||
* @module data_receiver
|
||||
@ -135,7 +135,7 @@ define('data_receiver', [
|
||||
pendingData,
|
||||
paused) {
|
||||
/**
|
||||
* The [Router]{@link module:mojo/public/js/bindings/router.Router} for the
|
||||
* The [Router]{@link module:mojo/public/js/router.Router} for the
|
||||
* connection to the DataSource.
|
||||
* @private
|
||||
*/
|
||||
|
@ -5,8 +5,8 @@
|
||||
define('data_sender', [
|
||||
'device/serial/data_stream.mojom',
|
||||
'device/serial/data_stream_serialization.mojom',
|
||||
'mojo/public/js/bindings/core',
|
||||
'mojo/public/js/bindings/router',
|
||||
'mojo/public/js/core',
|
||||
'mojo/public/js/router',
|
||||
], function(dataStreamMojom, serialization, core, routerModule) {
|
||||
/**
|
||||
* @module data_sender
|
||||
@ -221,7 +221,7 @@ define('data_sender', [
|
||||
*/
|
||||
this.shutDown_ = false;
|
||||
/**
|
||||
* The [Router]{@link module:mojo/public/js/bindings/router.Router} for the
|
||||
* The [Router]{@link module:mojo/public/js/router.Router} for the
|
||||
* connection to the DataSink.
|
||||
* @private
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@
|
||||
define('keep_alive', [
|
||||
'content/public/renderer/service_provider',
|
||||
'extensions/common/mojo/keep_alive.mojom',
|
||||
'mojo/public/js/bindings/core',
|
||||
'mojo/public/js/core',
|
||||
], function(serviceProvider, mojom, core) {
|
||||
|
||||
/**
|
||||
|
@ -8,8 +8,8 @@ define('serial_service', [
|
||||
'data_sender',
|
||||
'device/serial/serial.mojom',
|
||||
'device/serial/serial_serialization.mojom',
|
||||
'mojo/public/js/bindings/core',
|
||||
'mojo/public/js/bindings/router',
|
||||
'mojo/public/js/core',
|
||||
'mojo/public/js/router',
|
||||
], function(serviceProvider,
|
||||
dataReceiver,
|
||||
dataSender,
|
||||
|
@ -36,8 +36,8 @@ unittestBindings.exportTests([
|
||||
},
|
||||
function testMojoModulesAreAvailable() {
|
||||
Promise.all([
|
||||
requireAsync('mojo/public/js/bindings/connection'),
|
||||
requireAsync('mojo/public/js/bindings/core'),
|
||||
requireAsync('mojo/public/js/connection'),
|
||||
requireAsync('mojo/public/js/core'),
|
||||
requireAsync('content/public/renderer/service_provider'),
|
||||
]).then(test.callback(function(modules) {
|
||||
var connection = modules[0];
|
||||
|
@ -15,14 +15,9 @@
|
||||
#include "ipc/ipc_export.h"
|
||||
#include "ipc/mojo/ipc_message_pipe_reader.h"
|
||||
#include "ipc/mojo/ipc_mojo_bootstrap.h"
|
||||
#include "mojo/edk/embedder/channel_info_forward.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace embedder {
|
||||
struct ChannelInfo;
|
||||
}
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
namespace internal {
|
||||
|
@ -12,12 +12,6 @@
|
||||
#include "ipc/mojo/ipc_message_pipe_reader.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace embedder {
|
||||
struct ChannelInfo;
|
||||
}
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
class ChannelMojo;
|
||||
|
@ -24,9 +24,9 @@ group("mojo") {
|
||||
group("tests") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"//mojo/bindings/js/tests:mojo_js_unittests",
|
||||
"//mojo/common:mojo_common_unittests",
|
||||
"//mojo/converters/surfaces/tests:mojo_surfaces_lib_unittests",
|
||||
"//mojo/edk/js/tests:js_unittests",
|
||||
"//mojo/edk/system:mojo_message_pipe_perftests",
|
||||
"//mojo/edk/system:mojo_system_unittests",
|
||||
"//mojo/public/c/system/tests:perftests",
|
||||
|
@ -1,7 +0,0 @@
|
||||
include_rules = [
|
||||
"+base",
|
||||
"+gin",
|
||||
"+v8",
|
||||
"+mojo/bindings/js/core.h",
|
||||
"+mojo/bindings/js/support.h",
|
||||
]
|
@ -1,16 +0,0 @@
|
||||
# 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.
|
||||
|
||||
"""Presubmit script for mojo/edk.
|
||||
|
||||
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
||||
for more details about the presubmit API built into depot_tools.
|
||||
"""
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
results = []
|
||||
results += input_api.canned_checks.CheckChangeHasOnlyOneEol(input_api,
|
||||
output_api)
|
||||
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
|
||||
return results
|
@ -17,6 +17,7 @@ source_set("embedder") {
|
||||
configs += [ "//mojo/edk/system:system_config" ]
|
||||
|
||||
sources = [
|
||||
"channel_info_forward.h",
|
||||
"channel_init.cc",
|
||||
"channel_init.h",
|
||||
"embedder.cc",
|
||||
|
31
mojo/edk/embedder/channel_info_forward.h
Normal file
31
mojo/edk/embedder/channel_info_forward.h
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
// This file simply (forward) declares |mojo::embedder::ChannelInfo|, which is
|
||||
// meant to be opaque to users of the embedder API.
|
||||
|
||||
#ifndef MOJO_EDK_EMBEDDER_CHANNEL_INFO_FORWARD_H_
|
||||
#define MOJO_EDK_EMBEDDER_CHANNEL_INFO_FORWARD_H_
|
||||
|
||||
namespace mojo {
|
||||
|
||||
// Forward declare |system::ChannelInfo|, so that we can typedef it to
|
||||
// |embedder::ChannelInfo|. Users of the embedder API shouldn't use this
|
||||
// directly; instead they should use |embedder::ChannelInfo|.
|
||||
namespace system {
|
||||
struct ChannelInfo;
|
||||
}
|
||||
|
||||
namespace embedder {
|
||||
|
||||
// This is an opaque type. The embedder API uses (returns and takes as
|
||||
// arguments) pointers to this type. (We don't simply use |void*|, so that
|
||||
// custom deleters and such can be used without additional wrappers.
|
||||
typedef system::ChannelInfo ChannelInfo;
|
||||
|
||||
} // namespace embedder
|
||||
|
||||
} // namespace mojo
|
||||
|
||||
#endif // MOJO_EDK_EMBEDDER_CHANNEL_INFO_FORWARD_H_
|
@ -8,6 +8,7 @@
|
||||
#include "base/files/file.h"
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "mojo/edk/embedder/channel_info_forward.h"
|
||||
#include "mojo/edk/system/system_impl_export.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
||||
@ -17,10 +18,6 @@ class TaskRunner;
|
||||
}
|
||||
|
||||
namespace mojo {
|
||||
namespace embedder {
|
||||
struct ChannelInfo;
|
||||
}
|
||||
|
||||
namespace embedder {
|
||||
|
||||
// |ChannelInit| handles creation (and destruction) of the Mojo channel. It is
|
||||
|
@ -8,9 +8,11 @@
|
||||
#include "base/location.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/message_loop/message_loop_proxy.h"
|
||||
#include "mojo/edk/embedder/platform_support.h"
|
||||
#include "mojo/edk/system/channel.h"
|
||||
#include "mojo/edk/system/channel_endpoint.h"
|
||||
#include "mojo/edk/system/channel_info.h"
|
||||
#include "mojo/edk/system/core.h"
|
||||
#include "mojo/edk/system/entrypoints.h"
|
||||
#include "mojo/edk/system/message_pipe_dispatcher.h"
|
||||
@ -20,20 +22,6 @@
|
||||
namespace mojo {
|
||||
namespace embedder {
|
||||
|
||||
// This is defined here (instead of a header file), since it's opaque to the
|
||||
// outside world. But we need to define it before our (internal-only) functions
|
||||
// that use it.
|
||||
struct ChannelInfo {
|
||||
ChannelInfo() {}
|
||||
~ChannelInfo() {}
|
||||
|
||||
scoped_refptr<system::Channel> channel;
|
||||
|
||||
// May be null, in which case |DestroyChannelOnIOThread()| must be used (from
|
||||
// the IO thread), instead of |DestroyChannel()|.
|
||||
scoped_refptr<base::TaskRunner> io_thread_task_runner;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
// Helper for |CreateChannel...()|. (Note: May return null for some failures.)
|
||||
@ -101,9 +89,9 @@ ScopedMessagePipeHandle CreateChannelOnIOThread(
|
||||
ScopedMessagePipeHandle rv(
|
||||
MessagePipeHandle(core->AddDispatcher(dispatcher)));
|
||||
|
||||
*channel_info = new ChannelInfo();
|
||||
(*channel_info)->channel =
|
||||
MakeChannel(core, platform_handle.Pass(), channel_endpoint);
|
||||
*channel_info = new ChannelInfo(
|
||||
MakeChannel(core, platform_handle.Pass(), channel_endpoint),
|
||||
base::MessageLoopProxy::current());
|
||||
|
||||
return rv.Pass();
|
||||
}
|
||||
@ -114,6 +102,8 @@ ScopedMessagePipeHandle CreateChannel(
|
||||
DidCreateChannelCallback callback,
|
||||
scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
|
||||
DCHECK(platform_handle.is_valid());
|
||||
DCHECK(io_thread_task_runner.get());
|
||||
DCHECK(!callback.is_null());
|
||||
|
||||
scoped_refptr<system::ChannelEndpoint> channel_endpoint;
|
||||
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
|
||||
@ -125,7 +115,8 @@ ScopedMessagePipeHandle CreateChannel(
|
||||
MessagePipeHandle(core->AddDispatcher(dispatcher)));
|
||||
|
||||
scoped_ptr<ChannelInfo> channel_info(new ChannelInfo());
|
||||
channel_info->io_thread_task_runner = io_thread_task_runner;
|
||||
// We'll have to set |channel_info->channel| on the I/O thread.
|
||||
channel_info->channel_thread_task_runner = io_thread_task_runner;
|
||||
|
||||
if (rv.is_valid()) {
|
||||
io_thread_task_runner->PostTask(FROM_HERE,
|
||||
@ -159,7 +150,7 @@ void DestroyChannelOnIOThread(ChannelInfo* channel_info) {
|
||||
// TODO(vtl): Write tests for this.
|
||||
void DestroyChannel(ChannelInfo* channel_info) {
|
||||
DCHECK(channel_info);
|
||||
DCHECK(channel_info->io_thread_task_runner.get());
|
||||
DCHECK(channel_info->channel_thread_task_runner.get());
|
||||
|
||||
if (!channel_info->channel.get()) {
|
||||
// Presumably, |Init()| on the channel failed.
|
||||
@ -167,7 +158,7 @@ void DestroyChannel(ChannelInfo* channel_info) {
|
||||
}
|
||||
|
||||
channel_info->channel->WillShutdownSoon();
|
||||
channel_info->io_thread_task_runner->PostTask(
|
||||
channel_info->channel_thread_task_runner->PostTask(
|
||||
FROM_HERE, base::Bind(&DestroyChannelOnIOThread, channel_info));
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "mojo/edk/embedder/channel_info_forward.h"
|
||||
#include "mojo/edk/embedder/scoped_platform_handle.h"
|
||||
#include "mojo/edk/system/system_impl_export.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
@ -53,19 +54,15 @@ MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support);
|
||||
// first synchronously and second asynchronously.
|
||||
//
|
||||
// The destruction functions are similarly synchronous and asynchronous,
|
||||
// respectively, and take the |ChannelInfo*| produced by the creation function.
|
||||
// (Note: One may call |DestroyChannelOnIOThread()| with the result of
|
||||
// |CreateChannel()|, but not |DestroyChannel()| with the result of
|
||||
// |CreateChannelOnIOThread()|.)
|
||||
// respectively, and take the |ChannelInfo*| produced by the creation functions.
|
||||
//
|
||||
// TODO(vtl): Figure out channel teardown.
|
||||
struct ChannelInfo;
|
||||
|
||||
// Creates a channel; must only be called from the I/O thread. |platform_handle|
|
||||
// should be a handle to a connected OS "pipe". Eventually (even on failure),
|
||||
// the "out" value |*channel_info| should be passed to
|
||||
// |DestroyChannelOnIOThread()| to tear down the channel. Returns a handle to
|
||||
// the bootstrap message pipe.
|
||||
// |DestroyChannelOnIOThread()| (or |DestoryChannel()|) to tear down the
|
||||
// channel. Returns a handle to the bootstrap message pipe.
|
||||
MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
|
||||
CreateChannelOnIOThread(ScopedPlatformHandle platform_handle,
|
||||
ChannelInfo** channel_info);
|
||||
@ -93,10 +90,9 @@ MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
|
||||
MOJO_SYSTEM_IMPL_EXPORT void DestroyChannelOnIOThread(
|
||||
ChannelInfo* channel_info);
|
||||
|
||||
// Destroys a channel (asynchronously) that was created using |CreateChannel()|
|
||||
// (note: NOT |CreateChannelOnIOThread()|); may be called from any thread.
|
||||
// |channel_info| should be the value provided to the callback to
|
||||
// |CreateChannel()|.
|
||||
// Destroys a channel (asynchronously) that was created using |CreateChannel()|;
|
||||
// may be called from any thread. |channel_info| should be the value provided to
|
||||
// the callback to |CreateChannel()|.
|
||||
MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel(ChannelInfo* channel_info);
|
||||
|
||||
// Inform the channel that it will soon be destroyed (doing so is optional).
|
||||
|
@ -2,7 +2,6 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# GYP version: mojo/mojo.gyp:mojo_js_bindings
|
||||
source_set("js") {
|
||||
sources = [
|
||||
"core.cc",
|
||||
@ -21,7 +20,17 @@ source_set("js") {
|
||||
public_deps = [
|
||||
"//base",
|
||||
"//gin",
|
||||
"//mojo/common",
|
||||
"//v8",
|
||||
]
|
||||
}
|
||||
|
||||
source_set("js_unittests") {
|
||||
testonly = true
|
||||
deps = [
|
||||
"//mojo/edk/test:test_support",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"handle_unittest.cc",
|
||||
]
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "mojo/bindings/js/core.h"
|
||||
#include "mojo/edk/js/core.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/logging.h"
|
||||
@ -16,8 +16,8 @@
|
||||
#include "gin/per_isolate_data.h"
|
||||
#include "gin/public/wrapper_info.h"
|
||||
#include "gin/wrappable.h"
|
||||
#include "mojo/bindings/js/drain_data.h"
|
||||
#include "mojo/bindings/js/handle.h"
|
||||
#include "mojo/edk/js/drain_data.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace js {
|
||||
@ -239,7 +239,7 @@ gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
|
||||
|
||||
} // namespace
|
||||
|
||||
const char Core::kModuleName[] = "mojo/public/js/bindings/core";
|
||||
const char Core::kModuleName[] = "mojo/public/js/core";
|
||||
|
||||
v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
|
||||
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "mojo/bindings/js/drain_data.h"
|
||||
#include "mojo/edk/js/drain_data.h"
|
||||
|
||||
#include "gin/array_buffer.h"
|
||||
#include "gin/converter.h"
|
@ -2,9 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "mojo/bindings/js/handle.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
|
||||
#include "mojo/bindings/js/handle_close_observer.h"
|
||||
#include <sstream>
|
||||
#include "mojo/edk/js/handle_close_observer.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace js {
|
||||
@ -19,6 +20,23 @@ HandleWrapper::~HandleWrapper() {
|
||||
NotifyCloseObservers();
|
||||
}
|
||||
|
||||
std::string HandleWrapper::ToString() {
|
||||
std::ostringstream oss;
|
||||
oss << "[mojo::Handle ";
|
||||
if (handle_.is_valid())
|
||||
oss << handle_.get().value();
|
||||
else
|
||||
oss << "null";
|
||||
oss << "]";
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
gin::ObjectTemplateBuilder HandleWrapper::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
return Wrappable<HandleWrapper>::GetObjectTemplateBuilder(isolate)
|
||||
.SetMethod("toString", &HandleWrapper::ToString);
|
||||
}
|
||||
|
||||
void HandleWrapper::Close() {
|
||||
NotifyCloseObservers();
|
||||
handle_.reset();
|
||||
@ -68,4 +86,16 @@ bool Converter<mojo::Handle>::FromV8(v8::Isolate* isolate,
|
||||
return true;
|
||||
}
|
||||
|
||||
v8::Handle<v8::Value> Converter<mojo::MessagePipeHandle>::ToV8(
|
||||
v8::Isolate* isolate, mojo::MessagePipeHandle val) {
|
||||
return Converter<mojo::Handle>::ToV8(isolate, val);
|
||||
}
|
||||
|
||||
bool Converter<mojo::MessagePipeHandle>::FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
mojo::MessagePipeHandle* out) {
|
||||
return Converter<mojo::Handle>::FromV8(isolate, val, out);
|
||||
}
|
||||
|
||||
|
||||
} // namespace gin
|
@ -8,6 +8,7 @@
|
||||
#include "base/observer_list.h"
|
||||
#include "gin/converter.h"
|
||||
#include "gin/handle.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "gin/wrappable.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
||||
@ -26,6 +27,11 @@ class HandleWrapper : public gin::Wrappable<HandleWrapper> {
|
||||
return gin::CreateHandle(isolate, new HandleWrapper(handle));
|
||||
}
|
||||
|
||||
std::string ToString();
|
||||
|
||||
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(v8::Isolate* isolate)
|
||||
override;
|
||||
|
||||
mojo::Handle get() const { return handle_.get(); }
|
||||
mojo::Handle release() { return handle_.release(); }
|
||||
void Close();
|
||||
@ -59,6 +65,15 @@ struct Converter<mojo::Handle> {
|
||||
mojo::Handle* out);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Converter<mojo::MessagePipeHandle> {
|
||||
static v8::Handle<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
mojo::MessagePipeHandle val);
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Handle<v8::Value> val,
|
||||
mojo::MessagePipeHandle* out);
|
||||
};
|
||||
|
||||
// We need to specialize the normal gin::Handle converter in order to handle
|
||||
// converting |null| to a wrapper for an empty mojo::Handle.
|
||||
template<>
|
90
mojo/edk/js/handle_unittest.cc
Normal file
90
mojo/edk/js/handle_unittest.cc
Normal file
@ -0,0 +1,90 @@
|
||||
// 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.
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
#include "mojo/edk/js/handle_close_observer.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace js {
|
||||
|
||||
class HandleWrapperTest : public testing::Test,
|
||||
public HandleCloseObserver {
|
||||
public:
|
||||
HandleWrapperTest() : closes_observed_(0) {}
|
||||
|
||||
void OnWillCloseHandle() override { closes_observed_++; }
|
||||
|
||||
protected:
|
||||
int closes_observed_;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(HandleWrapperTest);
|
||||
};
|
||||
|
||||
class TestHandleWrapper : public HandleWrapper {
|
||||
public:
|
||||
explicit TestHandleWrapper(MojoHandle handle) : HandleWrapper(handle) {}
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(TestHandleWrapper);
|
||||
};
|
||||
|
||||
// Test that calling Close() on a HandleWrapper for an invalid handle does not
|
||||
// notify observers.
|
||||
TEST_F(HandleWrapperTest, CloseWithInvalidHandle) {
|
||||
{
|
||||
TestHandleWrapper wrapper(MOJO_HANDLE_INVALID);
|
||||
wrapper.AddCloseObserver(this);
|
||||
ASSERT_EQ(0, closes_observed_);
|
||||
wrapper.Close();
|
||||
EXPECT_EQ(0, closes_observed_);
|
||||
}
|
||||
EXPECT_EQ(0, closes_observed_);
|
||||
}
|
||||
|
||||
// Test that destroying a HandleWrapper for an invalid handle does not notify
|
||||
// observers.
|
||||
TEST_F(HandleWrapperTest, DestroyWithInvalidHandle) {
|
||||
{
|
||||
TestHandleWrapper wrapper(MOJO_HANDLE_INVALID);
|
||||
wrapper.AddCloseObserver(this);
|
||||
ASSERT_EQ(0, closes_observed_);
|
||||
}
|
||||
EXPECT_EQ(0, closes_observed_);
|
||||
}
|
||||
|
||||
// Test that calling Close on a HandleWrapper for a valid handle notifies
|
||||
// observers once.
|
||||
TEST_F(HandleWrapperTest, CloseWithValidHandle) {
|
||||
{
|
||||
mojo::MessagePipe pipe;
|
||||
TestHandleWrapper wrapper(pipe.handle0.release().value());
|
||||
wrapper.AddCloseObserver(this);
|
||||
ASSERT_EQ(0, closes_observed_);
|
||||
wrapper.Close();
|
||||
EXPECT_EQ(1, closes_observed_);
|
||||
// Check that calling close again doesn't notify observers.
|
||||
wrapper.Close();
|
||||
EXPECT_EQ(1, closes_observed_);
|
||||
}
|
||||
// Check that destroying a closed HandleWrapper doesn't notify observers.
|
||||
EXPECT_EQ(1, closes_observed_);
|
||||
}
|
||||
|
||||
// Test that destroying a HandleWrapper for a valid handle notifies observers.
|
||||
TEST_F(HandleWrapperTest, DestroyWithValidHandle) {
|
||||
{
|
||||
mojo::MessagePipe pipe;
|
||||
TestHandleWrapper wrapper(pipe.handle0.release().value());
|
||||
wrapper.AddCloseObserver(this);
|
||||
ASSERT_EQ(0, closes_observed_);
|
||||
}
|
||||
EXPECT_EQ(1, closes_observed_);
|
||||
}
|
||||
|
||||
} // namespace js
|
||||
} // namespace mojo
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "mojo/bindings/js/support.h"
|
||||
#include "mojo/edk/js/support.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "gin/arguments.h"
|
||||
@ -12,8 +12,8 @@
|
||||
#include "gin/per_isolate_data.h"
|
||||
#include "gin/public/wrapper_info.h"
|
||||
#include "gin/wrappable.h"
|
||||
#include "mojo/bindings/js/handle.h"
|
||||
#include "mojo/bindings/js/waiting_callback.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
#include "mojo/edk/js/waiting_callback.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
||||
namespace mojo {
|
||||
@ -37,7 +37,7 @@ gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
|
||||
|
||||
} // namespace
|
||||
|
||||
const char Support::kModuleName[] = "mojo/public/js/bindings/support";
|
||||
const char Support::kModuleName[] = "mojo/public/js/support";
|
||||
|
||||
v8::Local<v8::Value> Support::GetModule(v8::Isolate* isolate) {
|
||||
gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
|
@ -2,11 +2,11 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
# GYP version: mojo/mojo_public_tests.gypi:mojo_js_unittests
|
||||
test("mojo_js_unittests") {
|
||||
test("js_unittests") {
|
||||
deps = [
|
||||
"//gin:gin_test",
|
||||
"//mojo/bindings/js",
|
||||
"//mojo/edk/js",
|
||||
"//mojo/edk/js:js_unittests",
|
||||
"//mojo/edk/test:run_all_unittests",
|
||||
"//mojo/edk/test:test_support",
|
||||
"//mojo/public/cpp/environment:standalone",
|
7
mojo/edk/js/tests/DEPS
Normal file
7
mojo/edk/js/tests/DEPS
Normal file
@ -0,0 +1,7 @@
|
||||
include_rules = [
|
||||
"+base",
|
||||
"+gin",
|
||||
"+v8",
|
||||
"+mojo/edk/js/core.h",
|
||||
"+mojo/edk/js/support.h",
|
||||
]
|
@ -9,8 +9,8 @@
|
||||
#include "gin/modules/timer.h"
|
||||
#include "gin/test/file_runner.h"
|
||||
#include "gin/test/gtest.h"
|
||||
#include "mojo/bindings/js/core.h"
|
||||
#include "mojo/bindings/js/support.h"
|
||||
#include "mojo/edk/js/core.h"
|
||||
#include "mojo/edk/js/support.h"
|
||||
#include "mojo/public/cpp/environment/environment.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -37,7 +37,6 @@ void RunTest(std::string test, bool run_until_idle) {
|
||||
path = path.AppendASCII("mojo")
|
||||
.AppendASCII("public")
|
||||
.AppendASCII("js")
|
||||
.AppendASCII("bindings")
|
||||
.AppendASCII(test);
|
||||
TestRunnerDelegate delegate;
|
||||
gin::RunTestFromFile(path, &delegate, run_until_idle);
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "mojo/bindings/js/waiting_callback.h"
|
||||
#include "mojo/edk/js/waiting_callback.h"
|
||||
|
||||
#include "gin/per_context_data.h"
|
||||
#include "mojo/public/cpp/environment/environment.h"
|
@ -8,8 +8,8 @@
|
||||
#include "gin/handle.h"
|
||||
#include "gin/runner.h"
|
||||
#include "gin/wrappable.h"
|
||||
#include "mojo/bindings/js/handle.h"
|
||||
#include "mojo/bindings/js/handle_close_observer.h"
|
||||
#include "mojo/edk/js/handle.h"
|
||||
#include "mojo/edk/js/handle_close_observer.h"
|
||||
#include "mojo/public/c/environment/async_waiter.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
|
@ -28,6 +28,7 @@
|
||||
'mojo_public_utility_unittests',
|
||||
'mojo_system_impl',
|
||||
'mojo_system_unittests',
|
||||
'mojo_js_unittests',
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -112,6 +113,7 @@
|
||||
],
|
||||
'include_dirs': [ '../..' ],
|
||||
'sources': [
|
||||
'../public/cpp/environment/tests/async_wait_unittest.cc',
|
||||
'../public/cpp/environment/tests/async_waiter_unittest.cc',
|
||||
'../public/cpp/environment/tests/logger_unittest.cc',
|
||||
'../public/cpp/environment/tests/logging_unittest.cc',
|
||||
@ -203,6 +205,7 @@
|
||||
'MOJO_USE_SYSTEM_IMPL',
|
||||
],
|
||||
'sources': [
|
||||
'embedder/channel_info_forward.h',
|
||||
'embedder/channel_init.cc',
|
||||
'embedder/channel_init.h',
|
||||
'embedder/embedder.cc',
|
||||
@ -234,6 +237,8 @@
|
||||
'system/channel_endpoint.h',
|
||||
'system/channel_endpoint_id.cc',
|
||||
'system/channel_endpoint_id.h',
|
||||
'system/channel_info.cc',
|
||||
'system/channel_info.h',
|
||||
'system/constants.h',
|
||||
'system/core.cc',
|
||||
'system/core.h',
|
||||
@ -369,6 +374,52 @@
|
||||
'system/test_utils.h',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/edk/js
|
||||
'target_name': 'mojo_js_lib',
|
||||
'type': 'static_library',
|
||||
'dependencies': [
|
||||
'../../base/base.gyp:base',
|
||||
'../../gin/gin.gyp:gin',
|
||||
'../../v8/tools/gyp/v8.gyp:v8',
|
||||
],
|
||||
'export_dependent_settings': [
|
||||
'../../base/base.gyp:base',
|
||||
'../../gin/gin.gyp:gin',
|
||||
],
|
||||
'sources': [
|
||||
# Sources list duplicated in GN build.
|
||||
'js/core.cc',
|
||||
'js/core.h',
|
||||
'js/drain_data.cc',
|
||||
'js/drain_data.h',
|
||||
'js/handle.cc',
|
||||
'js/handle.h',
|
||||
'js/handle_close_observer.h',
|
||||
'js/support.cc',
|
||||
'js/support.h',
|
||||
'js/waiting_callback.cc',
|
||||
'js/waiting_callback.h',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/edk/js:js_unittests
|
||||
'target_name': 'mojo_js_unittests',
|
||||
'type': 'executable',
|
||||
'dependencies': [
|
||||
'../../gin/gin.gyp:gin_test',
|
||||
'mojo_common_test_support',
|
||||
'mojo_run_all_unittests',
|
||||
'mojo_js_lib',
|
||||
'../public/mojo_public.gyp:mojo_environment_standalone',
|
||||
'../public/mojo_public.gyp:mojo_public_test_interfaces',
|
||||
'../public/mojo_public.gyp:mojo_utility',
|
||||
],
|
||||
'sources': [
|
||||
'js/handle_unittest.cc',
|
||||
'js/tests/run_js_tests.cc',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/common/test:test_support_impl
|
||||
'target_name': 'mojo_test_support_impl',
|
||||
|
@ -32,6 +32,8 @@ component("system") {
|
||||
"channel_endpoint.h",
|
||||
"channel_endpoint_id.cc",
|
||||
"channel_endpoint_id.h",
|
||||
"channel_info.cc",
|
||||
"channel_info.h",
|
||||
"constants.h",
|
||||
"core.cc",
|
||||
"core.h",
|
||||
|
23
mojo/edk/system/channel_info.cc
Normal file
23
mojo/edk/system/channel_info.cc
Normal file
@ -0,0 +1,23 @@
|
||||
// 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.
|
||||
|
||||
#include "mojo/edk/system/channel_info.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace system {
|
||||
|
||||
ChannelInfo::ChannelInfo() {
|
||||
}
|
||||
|
||||
ChannelInfo::ChannelInfo(
|
||||
scoped_refptr<Channel> channel,
|
||||
scoped_refptr<base::TaskRunner> channel_thread_task_runner)
|
||||
: channel(channel), channel_thread_task_runner(channel_thread_task_runner) {
|
||||
}
|
||||
|
||||
ChannelInfo::~ChannelInfo() {
|
||||
}
|
||||
|
||||
} // namespace system
|
||||
} // namespace mojo
|
31
mojo/edk/system/channel_info.h
Normal file
31
mojo/edk/system/channel_info.h
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
#ifndef MOJO_EDK_SYSTEM_CHANNEL_INFO_H_
|
||||
#define MOJO_EDK_SYSTEM_CHANNEL_INFO_H_
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "base/task_runner.h"
|
||||
#include "mojo/edk/system/channel.h"
|
||||
#include "mojo/edk/system/system_impl_export.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace system {
|
||||
|
||||
struct MOJO_SYSTEM_IMPL_EXPORT ChannelInfo {
|
||||
ChannelInfo();
|
||||
ChannelInfo(scoped_refptr<Channel> channel,
|
||||
scoped_refptr<base::TaskRunner> channel_thread_task_runner);
|
||||
~ChannelInfo();
|
||||
|
||||
scoped_refptr<Channel> channel;
|
||||
// The task runner for |channel|'s creation thread (a.k.a. its I/O thread), on
|
||||
// which it must, e.g., be shut down.
|
||||
scoped_refptr<base::TaskRunner> channel_thread_task_runner;
|
||||
};
|
||||
|
||||
} // namespace system
|
||||
} // namespace mojo
|
||||
|
||||
#endif // MOJO_EDK_SYSTEM_CHANNEL_INFO_H_
|
@ -1084,6 +1084,19 @@ TEST_F(CoreTest, DataPipe) {
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
|
||||
|
||||
// Peek one character.
|
||||
elements[0] = -1;
|
||||
elements[1] = -1;
|
||||
num_bytes = 1u;
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
core()->ReadData(
|
||||
ch,
|
||||
UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
MOJO_READ_DATA_FLAG_NONE | MOJO_READ_DATA_FLAG_PEEK));
|
||||
EXPECT_EQ('A', elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
|
||||
// Read one character.
|
||||
elements[0] = -1;
|
||||
elements[1] = -1;
|
||||
@ -1131,6 +1144,16 @@ TEST_F(CoreTest, DataPipe) {
|
||||
MOJO_READ_DATA_FLAG_QUERY));
|
||||
EXPECT_EQ(4u, num_bytes);
|
||||
|
||||
// Try to query with peek. Should fail.
|
||||
num_bytes = 0;
|
||||
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
|
||||
core()->ReadData(
|
||||
ch,
|
||||
NullUserPointer(),
|
||||
MakeUserPointer(&num_bytes),
|
||||
MOJO_READ_DATA_FLAG_QUERY | MOJO_READ_DATA_FLAG_PEEK));
|
||||
EXPECT_EQ(0u, num_bytes);
|
||||
|
||||
// Try to discard ten characters, in all-or-none mode. Should fail.
|
||||
num_bytes = 10;
|
||||
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
|
||||
@ -1140,6 +1163,15 @@ TEST_F(CoreTest, DataPipe) {
|
||||
MakeUserPointer(&num_bytes),
|
||||
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE));
|
||||
|
||||
// Try to discard two characters, in peek mode. Should fail.
|
||||
num_bytes = 2;
|
||||
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
|
||||
core()->ReadData(
|
||||
ch,
|
||||
NullUserPointer(),
|
||||
MakeUserPointer(&num_bytes),
|
||||
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_PEEK));
|
||||
|
||||
// Discard two characters.
|
||||
num_bytes = 2;
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
@ -1149,9 +1181,17 @@ TEST_F(CoreTest, DataPipe) {
|
||||
MakeUserPointer(&num_bytes),
|
||||
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_ALL_OR_NONE));
|
||||
|
||||
// Read the remaining two characters, in two-phase mode (all-or-none).
|
||||
// Try a two-phase read of the remaining two bytes with peek. Should fail.
|
||||
const void* read_ptr = nullptr;
|
||||
num_bytes = 2;
|
||||
ASSERT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
|
||||
core()->BeginReadData(ch,
|
||||
MakeUserPointer(&read_ptr),
|
||||
MakeUserPointer(&num_bytes),
|
||||
MOJO_READ_DATA_FLAG_PEEK));
|
||||
|
||||
// Read the remaining two characters, in two-phase mode (all-or-none).
|
||||
num_bytes = 2;
|
||||
ASSERT_EQ(MOJO_RESULT_OK,
|
||||
core()->BeginReadData(ch,
|
||||
MakeUserPointer(&read_ptr),
|
||||
|
@ -260,7 +260,8 @@ void DataPipe::ConsumerClose() {
|
||||
|
||||
MojoResult DataPipe::ConsumerReadData(UserPointer<void> elements,
|
||||
UserPointer<uint32_t> num_bytes,
|
||||
bool all_or_none) {
|
||||
bool all_or_none,
|
||||
bool peek) {
|
||||
base::AutoLock locker(lock_);
|
||||
DCHECK(has_local_consumer_no_lock());
|
||||
|
||||
@ -279,7 +280,7 @@ MojoResult DataPipe::ConsumerReadData(UserPointer<void> elements,
|
||||
HandleSignalsState old_producer_state =
|
||||
ProducerGetHandleSignalsStateImplNoLock();
|
||||
MojoResult rv = ConsumerReadDataImplNoLock(
|
||||
elements, num_bytes, max_num_bytes_to_read, min_num_bytes_to_read);
|
||||
elements, num_bytes, max_num_bytes_to_read, min_num_bytes_to_read, peek);
|
||||
HandleSignalsState new_producer_state =
|
||||
ProducerGetHandleSignalsStateImplNoLock();
|
||||
if (!new_producer_state.equals(old_producer_state))
|
||||
|
@ -73,7 +73,8 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe
|
||||
// a multiple of |element_num_bytes_|.
|
||||
MojoResult ConsumerReadData(UserPointer<void> elements,
|
||||
UserPointer<uint32_t> num_bytes,
|
||||
bool all_or_none);
|
||||
bool all_or_none,
|
||||
bool peek);
|
||||
MojoResult ConsumerDiscardData(UserPointer<uint32_t> num_bytes,
|
||||
bool all_or_none);
|
||||
MojoResult ConsumerQueryData(UserPointer<uint32_t> num_bytes);
|
||||
@ -120,7 +121,8 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe
|
||||
UserPointer<void> elements,
|
||||
UserPointer<uint32_t> num_bytes,
|
||||
uint32_t max_num_bytes_to_read,
|
||||
uint32_t min_num_bytes_to_read) = 0;
|
||||
uint32_t min_num_bytes_to_read,
|
||||
bool peek) = 0;
|
||||
virtual MojoResult ConsumerDiscardDataImplNoLock(
|
||||
UserPointer<uint32_t> num_bytes,
|
||||
uint32_t max_num_bytes_to_discard,
|
||||
|
@ -58,7 +58,8 @@ MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock(
|
||||
|
||||
if ((flags & MOJO_READ_DATA_FLAG_DISCARD)) {
|
||||
// These flags are mutally exclusive.
|
||||
if ((flags & MOJO_READ_DATA_FLAG_QUERY))
|
||||
if ((flags & MOJO_READ_DATA_FLAG_QUERY) ||
|
||||
(flags & MOJO_READ_DATA_FLAG_PEEK))
|
||||
return MOJO_RESULT_INVALID_ARGUMENT;
|
||||
DVLOG_IF(2, !elements.IsNull())
|
||||
<< "Discard mode: ignoring non-null |elements|";
|
||||
@ -67,6 +68,8 @@ MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock(
|
||||
}
|
||||
|
||||
if ((flags & MOJO_READ_DATA_FLAG_QUERY)) {
|
||||
if ((flags & MOJO_READ_DATA_FLAG_PEEK))
|
||||
return MOJO_RESULT_INVALID_ARGUMENT;
|
||||
DCHECK(!(flags & MOJO_READ_DATA_FLAG_DISCARD)); // Handled above.
|
||||
DVLOG_IF(2, !elements.IsNull())
|
||||
<< "Query mode: ignoring non-null |elements|";
|
||||
@ -74,7 +77,10 @@ MojoResult DataPipeConsumerDispatcher::ReadDataImplNoLock(
|
||||
}
|
||||
|
||||
return data_pipe_->ConsumerReadData(
|
||||
elements, num_bytes, (flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE));
|
||||
elements,
|
||||
num_bytes,
|
||||
!!(flags & MOJO_READ_DATA_FLAG_ALL_OR_NONE),
|
||||
!!(flags & MOJO_READ_DATA_FLAG_PEEK));
|
||||
}
|
||||
|
||||
MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock(
|
||||
@ -85,7 +91,8 @@ MojoResult DataPipeConsumerDispatcher::BeginReadDataImplNoLock(
|
||||
|
||||
// These flags may not be used in two-phase mode.
|
||||
if ((flags & MOJO_READ_DATA_FLAG_DISCARD) ||
|
||||
(flags & MOJO_READ_DATA_FLAG_QUERY))
|
||||
(flags & MOJO_READ_DATA_FLAG_QUERY) ||
|
||||
(flags & MOJO_READ_DATA_FLAG_PEEK))
|
||||
return MOJO_RESULT_INVALID_ARGUMENT;
|
||||
|
||||
return data_pipe_->ConsumerBeginReadData(
|
||||
|
@ -177,7 +177,8 @@ MojoResult LocalDataPipe::ConsumerReadDataImplNoLock(
|
||||
UserPointer<void> elements,
|
||||
UserPointer<uint32_t> num_bytes,
|
||||
uint32_t max_num_bytes_to_read,
|
||||
uint32_t min_num_bytes_to_read) {
|
||||
uint32_t min_num_bytes_to_read,
|
||||
bool peek) {
|
||||
DCHECK_EQ(max_num_bytes_to_read % element_num_bytes(), 0u);
|
||||
DCHECK_EQ(min_num_bytes_to_read % element_num_bytes(), 0u);
|
||||
DCHECK_GT(max_num_bytes_to_read, 0u);
|
||||
@ -207,7 +208,8 @@ MojoResult LocalDataPipe::ConsumerReadDataImplNoLock(
|
||||
.PutArray(buffer_.get(), num_bytes_to_read - num_bytes_to_read_first);
|
||||
}
|
||||
|
||||
MarkDataAsConsumedNoLock(num_bytes_to_read);
|
||||
if (!peek)
|
||||
MarkDataAsConsumedNoLock(num_bytes_to_read);
|
||||
num_bytes.Put(static_cast<uint32_t>(num_bytes_to_read));
|
||||
return MOJO_RESULT_OK;
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipe : public DataPipe {
|
||||
UserPointer<void> elements,
|
||||
UserPointer<uint32_t> num_bytes,
|
||||
uint32_t max_num_bytes_to_read,
|
||||
uint32_t min_num_bytes_to_read) override;
|
||||
uint32_t min_num_bytes_to_read,
|
||||
bool peek) override;
|
||||
MojoResult ConsumerDiscardDataImplNoLock(
|
||||
UserPointer<uint32_t> num_bytes,
|
||||
uint32_t max_num_bytes_to_discard,
|
||||
|
@ -118,8 +118,10 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
|
||||
num_bytes = static_cast<uint32_t>(arraysize(elements) * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_SHOULD_WAIT,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
|
||||
// Query; nothing there yet.
|
||||
num_bytes = 0;
|
||||
@ -135,8 +137,10 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
|
||||
num_bytes = sizeof(elements[0]) + 1;
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_INVALID_ARGUMENT,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
|
||||
// Write two elements.
|
||||
elements[0] = 123;
|
||||
@ -160,8 +164,10 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
|
||||
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(1u * sizeof(elements[0]), num_bytes);
|
||||
EXPECT_EQ(123, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
@ -171,14 +177,35 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
|
||||
EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes)));
|
||||
EXPECT_EQ(1 * sizeof(elements[0]), num_bytes);
|
||||
|
||||
// Peek one element.
|
||||
elements[0] = -1;
|
||||
elements[1] = -1;
|
||||
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
true));
|
||||
EXPECT_EQ(1u * sizeof(elements[0]), num_bytes);
|
||||
EXPECT_EQ(456, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
|
||||
// Query. Still has 1 element remaining.
|
||||
num_bytes = 0;
|
||||
EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerQueryData(MakeUserPointer(&num_bytes)));
|
||||
EXPECT_EQ(1 * sizeof(elements[0]), num_bytes);
|
||||
|
||||
// Try to read two elements, with "all or none".
|
||||
elements[0] = -1;
|
||||
elements[1] = -1;
|
||||
num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OUT_OF_RANGE,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
EXPECT_EQ(-1, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
|
||||
@ -188,8 +215,10 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
|
||||
num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(456, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
|
||||
@ -262,6 +291,32 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
|
||||
EXPECT_EQ(0u, hss.satisfied_signals);
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals);
|
||||
|
||||
// Peek one element.
|
||||
elements[0] = -1;
|
||||
elements[1] = -1;
|
||||
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
true));
|
||||
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
|
||||
EXPECT_EQ(123, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
|
||||
// Add a waiter.
|
||||
waiter.Init();
|
||||
ASSERT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ProducerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_WRITABLE, 56, nullptr));
|
||||
// And it still shouldn't be writable yet.
|
||||
EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr));
|
||||
hss = HandleSignalsState();
|
||||
dp->ProducerRemoveWaiter(&waiter, &hss);
|
||||
EXPECT_EQ(0u, hss.satisfied_signals);
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals);
|
||||
|
||||
// Do it again.
|
||||
waiter.Init();
|
||||
ASSERT_EQ(
|
||||
@ -274,8 +329,10 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
|
||||
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
|
||||
EXPECT_EQ(123, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
@ -432,14 +489,39 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
|
||||
|
||||
// Peek one element.
|
||||
elements[0] = -1;
|
||||
elements[1] = -1;
|
||||
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
true));
|
||||
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
|
||||
EXPECT_EQ(456, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
|
||||
// Should still be readable.
|
||||
waiter.Init();
|
||||
hss = HandleSignalsState();
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_ALREADY_EXISTS,
|
||||
dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 78, &hss));
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
|
||||
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
|
||||
|
||||
// Read one element.
|
||||
elements[0] = -1;
|
||||
elements[1] = -1;
|
||||
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
|
||||
EXPECT_EQ(456, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
@ -485,8 +567,10 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
|
||||
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(elements), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(elements),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
|
||||
EXPECT_EQ(789, elements[0]);
|
||||
EXPECT_EQ(-1, elements[1]);
|
||||
@ -843,8 +927,10 @@ TEST(LocalDataPipeTest, BasicMayDiscardWaiting) {
|
||||
element = 0;
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(&element), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(&element),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(static_cast<uint32_t>(sizeof(int32_t)), num_bytes);
|
||||
EXPECT_EQ(456, element);
|
||||
|
||||
@ -908,8 +994,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
|
||||
num_bytes = 5u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
|
||||
int32_t expected_buffer[100];
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
@ -933,8 +1021,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
|
||||
num_bytes = 5u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
expected_buffer[0] = 8;
|
||||
@ -972,8 +1062,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
|
||||
num_bytes = sizeof(buffer);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(10u * sizeof(int32_t), num_bytes);
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
expected_buffer[0] = 104;
|
||||
@ -1062,8 +1154,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
|
||||
num_bytes = sizeof(buffer);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(8u * sizeof(int32_t), num_bytes);
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
expected_buffer[0] = 500;
|
||||
@ -1134,8 +1228,10 @@ TEST(LocalDataPipeTest, AllOrNone) {
|
||||
num_bytes = 11u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
int32_t expected_buffer[100];
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
|
||||
@ -1172,8 +1268,10 @@ TEST(LocalDataPipeTest, AllOrNone) {
|
||||
num_bytes = 5u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
Seq(100, 5, expected_buffer);
|
||||
@ -1183,8 +1281,10 @@ TEST(LocalDataPipeTest, AllOrNone) {
|
||||
num_bytes = 6u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
|
||||
|
||||
@ -1211,8 +1311,10 @@ TEST(LocalDataPipeTest, AllOrNone) {
|
||||
num_bytes = 4u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
|
||||
|
||||
@ -1225,8 +1327,10 @@ TEST(LocalDataPipeTest, AllOrNone) {
|
||||
num_bytes = 2u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
EXPECT_EQ(2u * sizeof(int32_t), num_bytes);
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
Seq(400, 2, expected_buffer);
|
||||
@ -1291,8 +1395,10 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
|
||||
num_bytes = 1u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
EXPECT_EQ(1u * sizeof(int32_t), num_bytes);
|
||||
int32_t expected_buffer[100];
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
@ -1303,8 +1409,10 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
|
||||
num_bytes = 10u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
|
||||
|
||||
@ -1336,8 +1444,10 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
|
||||
num_bytes = 10u * sizeof(int32_t);
|
||||
memset(buffer, 0xab, sizeof(buffer));
|
||||
EXPECT_EQ(MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), true));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
true,
|
||||
false));
|
||||
memset(expected_buffer, 0xab, sizeof(expected_buffer));
|
||||
EXPECT_EQ(10u * sizeof(int32_t), num_bytes);
|
||||
Seq(300, 10, expected_buffer);
|
||||
@ -1525,8 +1635,10 @@ TEST(LocalDataPipeTest, WrapAround) {
|
||||
num_bytes = 10u;
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(read_buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(read_buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(10u, num_bytes);
|
||||
EXPECT_EQ(0, memcmp(read_buffer, &test_data[0], 10u));
|
||||
|
||||
@ -1572,8 +1684,10 @@ TEST(LocalDataPipeTest, WrapAround) {
|
||||
memset(read_buffer, 0, num_bytes);
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(read_buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(read_buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(100u, num_bytes);
|
||||
EXPECT_EQ(0, memcmp(read_buffer, &test_data[10], 100u));
|
||||
|
||||
@ -1753,13 +1867,27 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
|
||||
// Close the producer.
|
||||
dp->ProducerClose();
|
||||
|
||||
// Read that data.
|
||||
// Peek that data.
|
||||
char buffer[1000];
|
||||
num_bytes = static_cast<uint32_t>(sizeof(buffer));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
true));
|
||||
EXPECT_EQ(kTestDataSize, num_bytes);
|
||||
EXPECT_EQ(0, memcmp(buffer, kTestData, kTestDataSize));
|
||||
|
||||
// Read that data.
|
||||
memset(buffer, 0, 1000);
|
||||
num_bytes = static_cast<uint32_t>(sizeof(buffer));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_OK,
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
EXPECT_EQ(kTestDataSize, num_bytes);
|
||||
EXPECT_EQ(0, memcmp(buffer, kTestData, kTestDataSize));
|
||||
|
||||
@ -1767,8 +1895,10 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
|
||||
num_bytes = static_cast<uint32_t>(sizeof(buffer));
|
||||
EXPECT_EQ(
|
||||
MOJO_RESULT_FAILED_PRECONDITION,
|
||||
dp->ConsumerReadData(
|
||||
UserPointer<void>(buffer), MakeUserPointer(&num_bytes), false));
|
||||
dp->ConsumerReadData(UserPointer<void>(buffer),
|
||||
MakeUserPointer(&num_bytes),
|
||||
false,
|
||||
false));
|
||||
|
||||
// A two-phase read should also fail.
|
||||
const void* read_buffer_ptr = nullptr;
|
||||
|
@ -16,29 +16,11 @@
|
||||
'mojo_base.gyp:mojo_base',
|
||||
'mojo_geometry_converters.gyp:mojo_geometry_lib',
|
||||
'mojo_input_events_converters.gyp:mojo_input_events_lib',
|
||||
'mojo_js_unittests',
|
||||
'mojo_surface_converters.gyp:mojo_surfaces_lib',
|
||||
'mojo_surface_converters.gyp:mojo_surfaces_lib_unittests',
|
||||
'services/public/mojo_services_public.gyp:mojo_services_public',
|
||||
'public/mojo_public.gyp:mojo_public',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/bindings/js/tests:mojo_js_unittests
|
||||
'target_name': 'mojo_js_unittests',
|
||||
'type': 'executable',
|
||||
'dependencies': [
|
||||
'../gin/gin.gyp:gin_test',
|
||||
'edk/mojo_edk.gyp:mojo_common_test_support',
|
||||
'edk/mojo_edk.gyp:mojo_run_all_unittests',
|
||||
'mojo_base.gyp:mojo_js_bindings_lib',
|
||||
'public/mojo_public.gyp:mojo_environment_standalone',
|
||||
'public/mojo_public.gyp:mojo_public_test_interfaces',
|
||||
'public/mojo_public.gyp:mojo_utility',
|
||||
],
|
||||
'sources': [
|
||||
'bindings/js/tests/run_js_tests.cc',
|
||||
],
|
||||
},
|
||||
],
|
||||
]
|
||||
}
|
||||
|
@ -155,36 +155,6 @@
|
||||
'public/mojo_public.gyp:mojo_application_base',
|
||||
],
|
||||
},
|
||||
{
|
||||
# GN version: //mojo/bindings/js
|
||||
'target_name': 'mojo_js_bindings_lib',
|
||||
'type': 'static_library',
|
||||
'dependencies': [
|
||||
'../base/base.gyp:base',
|
||||
'../gin/gin.gyp:gin',
|
||||
'../v8/tools/gyp/v8.gyp:v8',
|
||||
'mojo_common_lib',
|
||||
],
|
||||
'export_dependent_settings': [
|
||||
'../base/base.gyp:base',
|
||||
'../gin/gin.gyp:gin',
|
||||
'mojo_common_lib',
|
||||
],
|
||||
'sources': [
|
||||
# Sources list duplicated in GN build.
|
||||
'bindings/js/core.cc',
|
||||
'bindings/js/core.h',
|
||||
'bindings/js/drain_data.cc',
|
||||
'bindings/js/drain_data.h',
|
||||
'bindings/js/handle.cc',
|
||||
'bindings/js/handle.h',
|
||||
'bindings/js/handle_close_observer.h',
|
||||
'bindings/js/support.cc',
|
||||
'bindings/js/support.h',
|
||||
'bindings/js/waiting_callback.cc',
|
||||
'bindings/js/waiting_callback.h',
|
||||
],
|
||||
},
|
||||
],
|
||||
'conditions': [
|
||||
['OS=="android"', {
|
||||
|
@ -2,6 +2,8 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//mojo/public/mojo.gni")
|
||||
|
||||
group("public") {
|
||||
# Meta-target, don't link into production code.
|
||||
testonly = true
|
||||
@ -22,6 +24,12 @@ group("public") {
|
||||
]
|
||||
}
|
||||
|
||||
if (mojo_use_dart) {
|
||||
deps += [
|
||||
"//mojo/public/dart",
|
||||
]
|
||||
}
|
||||
|
||||
if (is_android) {
|
||||
deps += [
|
||||
"//mojo/public/java:system",
|
||||
@ -38,7 +46,7 @@ group("sdk") {
|
||||
"//mojo/public/cpp/environment:standalone",
|
||||
"//mojo/public/cpp/utility",
|
||||
"//mojo/public/interfaces/application",
|
||||
"//mojo/public/js/bindings",
|
||||
"//mojo/public/js",
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
cfc99316100efdfa7d53d83f9e07f1d4d3765c21
|
||||
04a510fb37db10642e156957f9b2c11c2f6442ac
|
@ -1,16 +0,0 @@
|
||||
# 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.
|
||||
|
||||
"""Presubmit script for mojo/public/c.
|
||||
|
||||
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
||||
for more details about the presubmit API built into depot_tools.
|
||||
"""
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
results = []
|
||||
results += input_api.canned_checks.CheckChangeHasOnlyOneEol(input_api,
|
||||
output_api)
|
||||
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
|
||||
return results
|
@ -83,6 +83,9 @@ const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0;
|
||||
// read. For use with |MojoReadData()| only. Mutually exclusive with
|
||||
// |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_ALL_OR_NONE| is
|
||||
// ignored if this flag is set.
|
||||
// |MOJO_READ_DATA_FLAG_PEEK| - Read elements without removing them. For use
|
||||
// with |MojoReadData()| only. Mutually exclusive with
|
||||
// |MOJO_READ_DATA_FLAG_DISCARD| and |MOJO_READ_DATA_FLAG_QUERY|.
|
||||
|
||||
typedef uint32_t MojoReadDataFlags;
|
||||
|
||||
@ -91,11 +94,13 @@ const MojoReadDataFlags MOJO_READ_DATA_FLAG_NONE = 0;
|
||||
const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0;
|
||||
const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1;
|
||||
const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2;
|
||||
const MojoReadDataFlags MOJO_READ_DATA_FLAG_PEEK = 1 << 3;
|
||||
#else
|
||||
#define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags)0)
|
||||
#define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags)1 << 0)
|
||||
#define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags)1 << 1)
|
||||
#define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags)1 << 2)
|
||||
#define MOJO_READ_DATA_FLAG_PEEK ((MojoReadDataFlags)1 << 3)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -254,7 +259,9 @@ MOJO_SYSTEM_EXPORT MojoResult
|
||||
// must be a multiple of the data pipe's element size) bytes of data to
|
||||
// |elements| and set |*num_bytes| to the amount actually read. If flags has
|
||||
// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set, it will either read exactly
|
||||
// |*num_bytes| bytes of data or none.
|
||||
// |*num_bytes| bytes of data or none. Additionally, if flags has
|
||||
// |MOJO_READ_DATA_FLAG_PEEK| set, the data read will remain in the pipe and be
|
||||
// available to future reads.
|
||||
//
|
||||
// If flags has |MOJO_READ_DATA_FLAG_DISCARD| set, it discards up to
|
||||
// |*num_bytes| (which again be a multiple of the element size) bytes of data,
|
||||
@ -300,7 +307,8 @@ MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
|
||||
// |*buffer_num_bytes| will be at least as large as its input value, which must
|
||||
// also be a multiple of the element size (if |MOJO_READ_DATA_FLAG_ALL_OR_NONE|
|
||||
// is not set, the input value of |*buffer_num_bytes| is ignored). |flags| must
|
||||
// not have |MOJO_READ_DATA_FLAG_DISCARD| or |MOJO_READ_DATA_FLAG_QUERY| set.
|
||||
// not have |MOJO_READ_DATA_FLAG_DISCARD|, |MOJO_READ_DATA_FLAG_QUERY|, or
|
||||
// |MOJO_READ_DATA_FLAG_PEEK| set.
|
||||
//
|
||||
// During a two-phase read, |data_pipe_consumer_handle| is *not* readable.
|
||||
// E.g., if another thread tries to read from it, it will get
|
||||
|
@ -1,16 +0,0 @@
|
||||
# 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.
|
||||
|
||||
"""Presubmit script for mojo/public/cpp.
|
||||
|
||||
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
||||
for more details about the presubmit API built into depot_tools.
|
||||
"""
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
results = []
|
||||
results += input_api.canned_checks.CheckChangeHasOnlyOneEol(input_api,
|
||||
output_api)
|
||||
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
|
||||
return results
|
@ -45,8 +45,8 @@ void ApplicationTestBase::SetUp() {
|
||||
Environment::InstantiateDefaultRunLoop();
|
||||
|
||||
// New applications are constructed for each test to avoid persisting state.
|
||||
application_impl_ =
|
||||
new ApplicationImpl(GetApplicationDelegate(), PassShellHandle());
|
||||
application_impl_ = new ApplicationImpl(GetApplicationDelegate(),
|
||||
PassShellHandle());
|
||||
|
||||
// Fake application initialization with the given command line arguments.
|
||||
application_impl_->Initialize(args_.Clone());
|
||||
|
@ -19,7 +19,7 @@ MojoResult MojoMain(MojoHandle shell_handle) {
|
||||
|
||||
// Construct an ApplicationImpl just for the GTEST commandline arguments.
|
||||
// GTEST command line arguments are supported amid application arguments:
|
||||
// $ mojo_shell 'mojo:example_apptest arg1 --gtest_filter=foo arg2'
|
||||
// $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2'
|
||||
mojo::ApplicationDelegate dummy_application_delegate;
|
||||
mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
|
||||
MOJO_CHECK(app.WaitForInitialize());
|
||||
|
@ -4,17 +4,22 @@
|
||||
|
||||
source_set("environment") {
|
||||
sources = [
|
||||
"async_waiter.h",
|
||||
"logging.h",
|
||||
"environment.h",
|
||||
]
|
||||
|
||||
public_deps = [ "//mojo/public/c/environment" ]
|
||||
|
||||
deps = [ "//mojo/public/cpp/system" ]
|
||||
deps = [
|
||||
"//mojo/public/cpp/bindings:callback",
|
||||
"//mojo/public/cpp/system",
|
||||
]
|
||||
}
|
||||
|
||||
source_set("standalone") {
|
||||
sources = [
|
||||
"lib/async_waiter.cc",
|
||||
"lib/default_async_waiter.cc",
|
||||
"lib/default_async_waiter.h",
|
||||
"lib/default_logger.cc",
|
||||
|
3
mojo/public/cpp/environment/DEPS
Normal file
3
mojo/public/cpp/environment/DEPS
Normal file
@ -0,0 +1,3 @@
|
||||
include_rules = [
|
||||
"+mojo/public/cpp/bindings/callback.h",
|
||||
]
|
40
mojo/public/cpp/environment/async_waiter.h
Normal file
40
mojo/public/cpp/environment/async_waiter.h
Normal file
@ -0,0 +1,40 @@
|
||||
// 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.
|
||||
|
||||
#ifndef MOJO_PUBLIC_CPP_ENVIRONMENT_ASYNC_WAITER_H_
|
||||
#define MOJO_PUBLIC_CPP_ENVIRONMENT_ASYNC_WAITER_H_
|
||||
|
||||
#include "mojo/public/c/environment/async_waiter.h"
|
||||
#include "mojo/public/cpp/bindings/callback.h"
|
||||
#include "mojo/public/cpp/environment/environment.h"
|
||||
#include "mojo/public/cpp/system/handle.h"
|
||||
|
||||
namespace mojo {
|
||||
|
||||
// A class that waits until a handle is ready and calls |callback| with the
|
||||
// result. If the AsyncWaiter is deleted before the handle is ready, the wait is
|
||||
// cancelled and the callback will not be called.
|
||||
class AsyncWaiter {
|
||||
public:
|
||||
typedef mojo::Callback<void(MojoResult)> Callback;
|
||||
|
||||
AsyncWaiter(Handle handle,
|
||||
MojoHandleSignals signals,
|
||||
const Callback& callback);
|
||||
~AsyncWaiter();
|
||||
|
||||
private:
|
||||
static void WaitComplete(void* waiter, MojoResult result);
|
||||
void WaitCompleteInternal(MojoResult result);
|
||||
|
||||
const MojoAsyncWaiter* waiter_;
|
||||
MojoAsyncWaitID id_;
|
||||
const Callback callback_;
|
||||
|
||||
MOJO_DISALLOW_COPY_AND_ASSIGN(AsyncWaiter);
|
||||
};
|
||||
|
||||
} // namespace mojo
|
||||
|
||||
#endif // MOJO_PUBLIC_CPP_ENVIRONMENT_ASYNC_WAITER_H_
|
34
mojo/public/cpp/environment/lib/async_waiter.cc
Normal file
34
mojo/public/cpp/environment/lib/async_waiter.cc
Normal file
@ -0,0 +1,34 @@
|
||||
// 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.
|
||||
|
||||
#include "mojo/public/cpp/environment/async_waiter.h"
|
||||
|
||||
namespace mojo {
|
||||
|
||||
AsyncWaiter::AsyncWaiter(Handle handle,
|
||||
MojoHandleSignals signals,
|
||||
const Callback& callback)
|
||||
: waiter_(Environment::GetDefaultAsyncWaiter()),
|
||||
id_(0),
|
||||
callback_(callback) {
|
||||
id_ = waiter_->AsyncWait(handle.value(), signals, MOJO_DEADLINE_INDEFINITE,
|
||||
&AsyncWaiter::WaitComplete, this);
|
||||
}
|
||||
|
||||
AsyncWaiter::~AsyncWaiter() {
|
||||
if (id_)
|
||||
waiter_->CancelWait(id_);
|
||||
}
|
||||
|
||||
// static
|
||||
void AsyncWaiter::WaitComplete(void* waiter, MojoResult result) {
|
||||
static_cast<AsyncWaiter*>(waiter)->WaitCompleteInternal(result);
|
||||
}
|
||||
|
||||
void AsyncWaiter::WaitCompleteInternal(MojoResult result) {
|
||||
id_ = 0;
|
||||
callback_.Run(result);
|
||||
}
|
||||
|
||||
} // namespace mojo
|
@ -5,6 +5,7 @@
|
||||
# GYP version: mojo/mojo_base.gyp:mojo_public_environment_unittests
|
||||
test("mojo_public_environment_unittests") {
|
||||
sources = [
|
||||
"async_wait_unittest.cc",
|
||||
"async_waiter_unittest.cc",
|
||||
"logger_unittest.cc",
|
||||
"logging_unittest.cc",
|
||||
@ -13,6 +14,7 @@ test("mojo_public_environment_unittests") {
|
||||
deps = [
|
||||
"//mojo/edk/test:run_all_unittests",
|
||||
"//mojo/public/c/environment",
|
||||
"//mojo/public/cpp/bindings:callback",
|
||||
"//mojo/public/cpp/environment:standalone",
|
||||
"//mojo/public/cpp/system",
|
||||
"//mojo/public/cpp/test_support:test_utils",
|
||||
|
114
mojo/public/cpp/environment/tests/async_wait_unittest.cc
Normal file
114
mojo/public/cpp/environment/tests/async_wait_unittest.cc
Normal file
@ -0,0 +1,114 @@
|
||||
// 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.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "mojo/public/c/environment/async_waiter.h"
|
||||
#include "mojo/public/cpp/environment/environment.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
#include "mojo/public/cpp/system/macros.h"
|
||||
#include "mojo/public/cpp/test_support/test_utils.h"
|
||||
#include "mojo/public/cpp/utility/run_loop.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
namespace mojo {
|
||||
namespace {
|
||||
|
||||
class TestAsyncWaitCallback {
|
||||
public:
|
||||
TestAsyncWaitCallback() : result_count_(0), last_result_(MOJO_RESULT_OK) {}
|
||||
~TestAsyncWaitCallback() {}
|
||||
|
||||
int result_count() const { return result_count_; }
|
||||
|
||||
MojoResult last_result() const { return last_result_; }
|
||||
|
||||
// MojoAsyncWaitCallback:
|
||||
static void OnHandleReady(void* closure, MojoResult result) {
|
||||
TestAsyncWaitCallback* self = static_cast<TestAsyncWaitCallback*>(closure);
|
||||
self->result_count_++;
|
||||
self->last_result_ = result;
|
||||
}
|
||||
|
||||
private:
|
||||
int result_count_;
|
||||
MojoResult last_result_;
|
||||
|
||||
MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaitCallback);
|
||||
};
|
||||
|
||||
MojoAsyncWaitID CallAsyncWait(const Handle& handle,
|
||||
MojoHandleSignals signals,
|
||||
TestAsyncWaitCallback* callback) {
|
||||
return Environment::GetDefaultAsyncWaiter()->AsyncWait(
|
||||
handle.value(),
|
||||
signals,
|
||||
MOJO_DEADLINE_INDEFINITE,
|
||||
&TestAsyncWaitCallback::OnHandleReady,
|
||||
callback);
|
||||
}
|
||||
|
||||
void CallCancelWait(MojoAsyncWaitID wait_id) {
|
||||
Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id);
|
||||
}
|
||||
|
||||
class AsyncWaitTest : public testing::Test {
|
||||
public:
|
||||
AsyncWaitTest() {}
|
||||
|
||||
private:
|
||||
Environment environment_;
|
||||
RunLoop run_loop_;
|
||||
|
||||
MOJO_DISALLOW_COPY_AND_ASSIGN(AsyncWaitTest);
|
||||
};
|
||||
|
||||
// Verifies AsyncWaitCallback is notified when pipe is ready.
|
||||
TEST_F(AsyncWaitTest, CallbackNotified) {
|
||||
TestAsyncWaitCallback callback;
|
||||
MessagePipe test_pipe;
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
|
||||
|
||||
CallAsyncWait(
|
||||
test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback);
|
||||
RunLoop::current()->Run();
|
||||
EXPECT_EQ(1, callback.result_count());
|
||||
EXPECT_EQ(MOJO_RESULT_OK, callback.last_result());
|
||||
}
|
||||
|
||||
// Verifies 2 AsyncWaitCallbacks are notified when there pipes are ready.
|
||||
TEST_F(AsyncWaitTest, TwoCallbacksNotified) {
|
||||
TestAsyncWaitCallback callback1;
|
||||
TestAsyncWaitCallback callback2;
|
||||
MessagePipe test_pipe1;
|
||||
MessagePipe test_pipe2;
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe1.handle1.get(), std::string()));
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe2.handle1.get(), std::string()));
|
||||
|
||||
CallAsyncWait(
|
||||
test_pipe1.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback1);
|
||||
CallAsyncWait(
|
||||
test_pipe2.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback2);
|
||||
|
||||
RunLoop::current()->Run();
|
||||
EXPECT_EQ(1, callback1.result_count());
|
||||
EXPECT_EQ(MOJO_RESULT_OK, callback1.last_result());
|
||||
EXPECT_EQ(1, callback2.result_count());
|
||||
EXPECT_EQ(MOJO_RESULT_OK, callback2.last_result());
|
||||
}
|
||||
|
||||
// Verifies cancel works.
|
||||
TEST_F(AsyncWaitTest, CancelCallback) {
|
||||
TestAsyncWaitCallback callback;
|
||||
MessagePipe test_pipe;
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
|
||||
|
||||
CallCancelWait(CallAsyncWait(
|
||||
test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback));
|
||||
RunLoop::current()->Run();
|
||||
EXPECT_EQ(0, callback.result_count());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mojo
|
@ -2,12 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "mojo/public/c/environment/async_waiter.h"
|
||||
#include "mojo/public/cpp/environment/environment.h"
|
||||
#include "mojo/public/cpp/system/core.h"
|
||||
#include "mojo/public/cpp/system/macros.h"
|
||||
#include "mojo/public/cpp/bindings/callback.h"
|
||||
#include "mojo/public/cpp/environment/async_waiter.h"
|
||||
#include "mojo/public/cpp/test_support/test_utils.h"
|
||||
#include "mojo/public/cpp/utility/run_loop.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -24,11 +20,9 @@ class TestAsyncWaitCallback {
|
||||
|
||||
MojoResult last_result() const { return last_result_; }
|
||||
|
||||
// MojoAsyncWaitCallback:
|
||||
static void OnHandleReady(void* closure, MojoResult result) {
|
||||
TestAsyncWaitCallback* self = static_cast<TestAsyncWaitCallback*>(closure);
|
||||
self->result_count_++;
|
||||
self->last_result_ = result;
|
||||
void OnHandleReady(MojoResult result) {
|
||||
result_count_++;
|
||||
last_result_ = result;
|
||||
}
|
||||
|
||||
private:
|
||||
@ -38,20 +32,17 @@ class TestAsyncWaitCallback {
|
||||
MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaitCallback);
|
||||
};
|
||||
|
||||
MojoAsyncWaitID CallAsyncWait(const Handle& handle,
|
||||
MojoHandleSignals signals,
|
||||
TestAsyncWaitCallback* callback) {
|
||||
return Environment::GetDefaultAsyncWaiter()->AsyncWait(
|
||||
handle.value(),
|
||||
signals,
|
||||
MOJO_DEADLINE_INDEFINITE,
|
||||
&TestAsyncWaitCallback::OnHandleReady,
|
||||
callback);
|
||||
}
|
||||
// Manual code to create a callback since we don't have mojo::Bind yet.
|
||||
class ManualCallback {
|
||||
public:
|
||||
explicit ManualCallback(TestAsyncWaitCallback* callback)
|
||||
: callback_(callback) {}
|
||||
|
||||
void CallCancelWait(MojoAsyncWaitID wait_id) {
|
||||
Environment::GetDefaultAsyncWaiter()->CancelWait(wait_id);
|
||||
}
|
||||
void Run(MojoResult result) const { callback_->OnHandleReady(result); }
|
||||
|
||||
private:
|
||||
TestAsyncWaitCallback* callback_;
|
||||
};
|
||||
|
||||
class AsyncWaiterTest : public testing::Test {
|
||||
public:
|
||||
@ -70,8 +61,8 @@ TEST_F(AsyncWaiterTest, CallbackNotified) {
|
||||
MessagePipe test_pipe;
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
|
||||
|
||||
CallAsyncWait(
|
||||
test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback);
|
||||
AsyncWaiter waiter(test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE,
|
||||
ManualCallback(&callback));
|
||||
RunLoop::current()->Run();
|
||||
EXPECT_EQ(1, callback.result_count());
|
||||
EXPECT_EQ(MOJO_RESULT_OK, callback.last_result());
|
||||
@ -86,10 +77,10 @@ TEST_F(AsyncWaiterTest, TwoCallbacksNotified) {
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe1.handle1.get(), std::string()));
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe2.handle1.get(), std::string()));
|
||||
|
||||
CallAsyncWait(
|
||||
test_pipe1.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback1);
|
||||
CallAsyncWait(
|
||||
test_pipe2.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback2);
|
||||
AsyncWaiter waiter1(test_pipe1.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE,
|
||||
ManualCallback(&callback1));
|
||||
AsyncWaiter waiter2(test_pipe2.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE,
|
||||
ManualCallback(&callback2));
|
||||
|
||||
RunLoop::current()->Run();
|
||||
EXPECT_EQ(1, callback1.result_count());
|
||||
@ -104,8 +95,10 @@ TEST_F(AsyncWaiterTest, CancelCallback) {
|
||||
MessagePipe test_pipe;
|
||||
EXPECT_TRUE(test::WriteTextMessage(test_pipe.handle1.get(), std::string()));
|
||||
|
||||
CallCancelWait(CallAsyncWait(
|
||||
test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE, &callback));
|
||||
{
|
||||
AsyncWaiter waiter(test_pipe.handle0.get(), MOJO_HANDLE_SIGNAL_READABLE,
|
||||
ManualCallback(&callback));
|
||||
}
|
||||
RunLoop::current()->Run();
|
||||
EXPECT_EQ(0, callback.result_count());
|
||||
}
|
||||
|
20
mojo/public/dart/BUILD.gn
Normal file
20
mojo/public/dart/BUILD.gn
Normal file
@ -0,0 +1,20 @@
|
||||
# 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.
|
||||
|
||||
group("dart") {
|
||||
deps = [
|
||||
":bindings",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
copy("bindings") {
|
||||
sources = [
|
||||
"bindings.dart",
|
||||
"src/codec.dart",
|
||||
]
|
||||
outputs = [
|
||||
"{{source_gen_dir}}/{{source_file_part}}"
|
||||
]
|
||||
}
|
41
mojo/public/dart/README
Normal file
41
mojo/public/dart/README
Normal file
@ -0,0 +1,41 @@
|
||||
These are interim instructions for building and testing Dart's Mojo bindings.
|
||||
These instructions currently only work for Linux, and assume you already have a
|
||||
Mojo checkout.
|
||||
|
||||
1.) Install the Dart SDK.
|
||||
|
||||
- apt-get -
|
||||
|
||||
Follow instructions at: https://www.dartlang.org/tools/debian.html
|
||||
|
||||
- Debian package -
|
||||
|
||||
Download from:
|
||||
|
||||
$ wget https://storage.googleapis.com/dart-archive/channels/dev/release/latest/linux_packages/debian_wheezy/dart_1.8.0-dev.2.0-1_amd64.deb
|
||||
$ dpkg -i dart_1.8.0-dev.2.0-1_amd64.deb
|
||||
|
||||
- From source -
|
||||
|
||||
Follow instructions here: https://code.google.com/p/dart/wiki/Building
|
||||
|
||||
and build the "create_sdk" target.
|
||||
|
||||
With the first two options, dart is on your path and you are ready to go.
|
||||
When building from source, you must explicitly add
|
||||
e.g. out/ReleaseX64/dart-sdk/bin to your path.
|
||||
|
||||
|
||||
2.) Configure Mojo with Dart.
|
||||
|
||||
$ ./mojob.sh --release --with-dart gn
|
||||
|
||||
|
||||
3.) Build Mojo with Dart.
|
||||
|
||||
$ ./mojob.sh --release build
|
||||
|
||||
|
||||
4.) Run Dart tests.
|
||||
|
||||
$ ./mojob.sh --release darttest
|
13
mojo/public/dart/bindings.dart
Normal file
13
mojo/public/dart/bindings.dart
Normal file
@ -0,0 +1,13 @@
|
||||
// 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.
|
||||
|
||||
library bindings;
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:core';
|
||||
import 'dart:mirrors';
|
||||
import 'dart:typed_data';
|
||||
|
||||
part 'src/codec.dart';
|
745
mojo/public/dart/src/codec.dart
Normal file
745
mojo/public/dart/src/codec.dart
Normal file
@ -0,0 +1,745 @@
|
||||
// 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.
|
||||
|
||||
part of bindings;
|
||||
|
||||
const int kAlignment = 8;
|
||||
const int kArrayHeaderSize = 8;
|
||||
const int kStructHeaderSize = 8;
|
||||
const int kMessageHeaderSize = 16;
|
||||
const int kMessageWithRequestIDHeaderSize = 24;
|
||||
const int kMapStructPayloadSize = 16;
|
||||
const int kStructHeaderNumBytesOffset = 0;
|
||||
const int kStructHeaderNumFieldsOffset = 4;
|
||||
const int kEncodedInvalidHandleValue = 0xffffffff;
|
||||
const String kErrorUnsigned = "Passing negative value to unsigned encoder";
|
||||
|
||||
|
||||
int align(int size) => size + (kAlignment - (size % kAlignment)) % kAlignment;
|
||||
bool isAligned(offset) => (offset >= 0) && ((offset % kAlignment) == 0);
|
||||
|
||||
|
||||
Uint8List utf8OfString(String s) =>
|
||||
(new Uint8List.fromList((const Utf8Encoder()).convert(s)));
|
||||
|
||||
|
||||
String stringOfUtf8(Uint8List bytes) =>
|
||||
(const Utf8Decoder()).convert(bytes.toList());
|
||||
|
||||
|
||||
// Given an argument that is either a Type or an instance:
|
||||
// Invoke the static method "decode" of the Type, or the instance method
|
||||
// "decode" of the instance, on the MojoDecoder.
|
||||
Object _callDecode(Object typeOrInstance, MojoDecoder decoder) {
|
||||
if (typeOrInstance is Type) {
|
||||
return reflectClass(typeOrInstance).invoke(#decode, [decoder]).reflectee;
|
||||
} else {
|
||||
return typeOrInstance.decode(decoder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Given an argument that is either a Type or an instance:
|
||||
// Invoke the static method "encode" of the Type, or the instance method
|
||||
// "encode" of the instance, on the MojoEncoder and value to be encoded.
|
||||
void _callEncode(Object typeOrInstance, MojoEncoder encoder, Object val) {
|
||||
if (typeOrInstance is Type) {
|
||||
reflectClass(typeOrInstance).invoke(#encode, [encoder, val]);
|
||||
} else {
|
||||
typeOrInstance.encode(encoder, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Given an argument that is either a Type or an instance:
|
||||
// Invoke the static getter "encodedSize" of the Type, or the instance getter
|
||||
// "encodedSize" of the instance, and return the result.
|
||||
int getEncodedSize(Object typeOrInstance) {
|
||||
if (typeOrInstance is Type) {
|
||||
return reflectClass(typeOrInstance).getField(#encodedSize).reflectee;
|
||||
} else {
|
||||
return typeOrInstance.encodedSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MojoDecoder {
|
||||
ByteData buffer;
|
||||
List<int> handles;
|
||||
int base;
|
||||
int next;
|
||||
|
||||
MojoDecoder(this.buffer, this.handles, this.base) {
|
||||
next = base;
|
||||
}
|
||||
|
||||
void skip(int offset) {
|
||||
next += offset;
|
||||
}
|
||||
|
||||
int readInt8() {
|
||||
int result = buffer.getInt8(next);
|
||||
next += 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
int readUint8() {
|
||||
int result = buffer.getUint8(next);
|
||||
next += 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
int readInt16() {
|
||||
int result = buffer.getInt16(next, Endianness.LITTLE_ENDIAN);
|
||||
next += 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
int readUint16() {
|
||||
int result = buffer.getUint16(next, Endianness.LITTLE_ENDIAN);
|
||||
next += 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
int readInt32() {
|
||||
int result = buffer.getInt32(next, Endianness.LITTLE_ENDIAN);
|
||||
next += 4;
|
||||
return result;
|
||||
}
|
||||
|
||||
int readUint32() {
|
||||
int result = buffer.getUint32(next, Endianness.LITTLE_ENDIAN);
|
||||
next += 4;
|
||||
return result;
|
||||
}
|
||||
|
||||
int readInt64() {
|
||||
int result = buffer.getInt64(next, Endianness.LITTLE_ENDIAN);
|
||||
next += 8;
|
||||
return result;
|
||||
}
|
||||
|
||||
int readUint64() {
|
||||
int result = buffer.getUint64(next, Endianness.LITTLE_ENDIAN);
|
||||
next += 8;
|
||||
return result;
|
||||
}
|
||||
|
||||
double readFloat() {
|
||||
double result = buffer.getFloat32(next,Endianness.LITTLE_ENDIAN);
|
||||
next += 4;
|
||||
return result;
|
||||
}
|
||||
|
||||
double readDouble() {
|
||||
double result = buffer.getFloat64(next, Endianness.LITTLE_ENDIAN);
|
||||
next += 8;
|
||||
return result;
|
||||
}
|
||||
|
||||
int decodePointer() {
|
||||
int offsetPointer = next;
|
||||
int offset = readUint64();
|
||||
if (offset == 0) {
|
||||
return 0;
|
||||
}
|
||||
return offsetPointer + offset;
|
||||
}
|
||||
|
||||
MojoDecoder decodeAndCreateDecoder(int offset) {
|
||||
return new MojoDecoder(buffer, handles, offset);
|
||||
}
|
||||
|
||||
int decodeHandle() {
|
||||
return handles[readUint32()];
|
||||
}
|
||||
|
||||
String decodeString() {
|
||||
int numBytes = readUint32();
|
||||
int numElements = readUint32();
|
||||
int base = next;
|
||||
next += numElements;
|
||||
return stringOfUtf8(buffer.buffer.asUint8List(base, numElements));
|
||||
}
|
||||
|
||||
List decodeArray(Object type) {
|
||||
int numBytes = readUint32();
|
||||
int numElements = readUint32();
|
||||
if (type == PackedBool) {
|
||||
int b;
|
||||
List<bool> result = new List<bool>(numElements);
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
if ((i % 8) == 0) {
|
||||
b = readUint8();
|
||||
}
|
||||
result[i] = ((b & (1 << (i % 8)) != 0) ? true : false);
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
List result = new List(numElements);
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
result[i] = _callDecode(type, this);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Object decodeStruct(Object t) {
|
||||
return _callDecode(t, this);
|
||||
}
|
||||
|
||||
Object decodeStructPointer(Object t) {
|
||||
int pointer = decodePointer();
|
||||
if (pointer == 0) {
|
||||
return null;
|
||||
}
|
||||
return _callDecode(t, decodeAndCreateDecoder(pointer));
|
||||
}
|
||||
|
||||
List decodeArrayPointer(Object type) {
|
||||
int pointer = decodePointer();
|
||||
if (pointer == 0) {
|
||||
return null;
|
||||
}
|
||||
return decodeAndCreateDecoder(pointer).decodeArray(type);
|
||||
}
|
||||
|
||||
String decodeStringPointer() {
|
||||
int pointer = decodePointer();
|
||||
if (pointer == 0) {
|
||||
return null;
|
||||
}
|
||||
return decodeAndCreateDecoder(pointer).decodeString();
|
||||
}
|
||||
|
||||
Map decodeMap(Object keyType, Object valType) {
|
||||
skip(4); // number of bytes.
|
||||
skip(4); // number of fields.
|
||||
List keys = decodeArrayPointer(keyType);
|
||||
List values = decodeArrayPointer(valType);
|
||||
return new Map.fromIterables(keys, values);
|
||||
}
|
||||
|
||||
Map decodeMapPointer(Object keyType, Object valType) {
|
||||
int pointer = this.decodePointer();
|
||||
if (pointer == 0) {
|
||||
return null;
|
||||
}
|
||||
MojoDecoder decoder = decodeAndCreateDecoder(pointer);
|
||||
return decoder.decodeMap(keyType, valType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MojoEncoder {
|
||||
ByteData buffer;
|
||||
List<int> handles;
|
||||
int base;
|
||||
int next;
|
||||
int extent;
|
||||
|
||||
MojoEncoder(this.buffer, this.handles, this.base, this.extent) {
|
||||
next = base;
|
||||
}
|
||||
|
||||
void skip(int offset) {
|
||||
next += offset;
|
||||
}
|
||||
|
||||
void writeInt8(int val) {
|
||||
buffer.setInt8(next, val);
|
||||
next += 1;
|
||||
}
|
||||
|
||||
void writeUint8(int val) {
|
||||
if (val < 0) {
|
||||
throw new ArgumentError("$kErrorUnsigned: $val");
|
||||
}
|
||||
buffer.setUint8(next, val);
|
||||
next += 1;
|
||||
}
|
||||
|
||||
void writeInt16(int val) {
|
||||
buffer.setInt16(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 2;
|
||||
}
|
||||
|
||||
void writeUint16(int val) {
|
||||
if (val < 0) {
|
||||
throw new ArgumentError("$kErrorUnsigned: $val");
|
||||
}
|
||||
buffer.setUint16(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 2;
|
||||
}
|
||||
|
||||
void writeInt32(int val) {
|
||||
buffer.setInt32(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 4;
|
||||
}
|
||||
|
||||
void writeUint32(int val) {
|
||||
if (val < 0) {
|
||||
throw new ArgumentError("$kErrorUnsigned: $val");
|
||||
}
|
||||
buffer.setUint32(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 4;
|
||||
}
|
||||
|
||||
void writeInt64(int val) {
|
||||
buffer.setInt64(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 8;
|
||||
}
|
||||
|
||||
void writeUint64(int val) {
|
||||
if (val < 0) {
|
||||
throw new ArgumentError("$kErrorUnsigned: $val");
|
||||
}
|
||||
buffer.setUint64(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 8;
|
||||
}
|
||||
|
||||
void writeFloat(double val) {
|
||||
buffer.setFloat32(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 4;
|
||||
}
|
||||
|
||||
void writeDouble(double val) {
|
||||
buffer.setFloat64(next, val, Endianness.LITTLE_ENDIAN);
|
||||
next += 8;
|
||||
}
|
||||
|
||||
void encodePointer(int pointer) {
|
||||
if (pointer == null) {
|
||||
writeUint64(0);
|
||||
return;
|
||||
}
|
||||
int offset = pointer - next;
|
||||
writeUint64(offset);
|
||||
}
|
||||
|
||||
void grow(int new_size) {
|
||||
Uint8List new_buffer = new Uint8List(new_size);
|
||||
new_buffer.setRange(0, next, buffer.buffer.asUint8List());
|
||||
buffer = new_buffer.buffer.asByteData();
|
||||
}
|
||||
|
||||
int alloc(int size_request) {
|
||||
int pointer = extent;
|
||||
extent += size_request;
|
||||
if (extent > buffer.lengthInBytes) {
|
||||
int new_size = buffer.lengthInBytes + size_request;
|
||||
new_size += new_size ~/ 2;
|
||||
grow(new_size);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
|
||||
MojoEncoder createAndEncodeEncoder(int size) {
|
||||
int pointer = alloc(align(size));
|
||||
encodePointer(pointer);
|
||||
return new MojoEncoder(buffer, handles, pointer, extent);
|
||||
}
|
||||
|
||||
void encodeHandle(int handle) {
|
||||
handles.add(handle);
|
||||
writeUint32(handles.length - 1);
|
||||
}
|
||||
|
||||
void encodeString(String val) {
|
||||
Uint8List utf8string = utf8OfString(val);
|
||||
int numElements = utf8string.lengthInBytes;
|
||||
int numBytes = kArrayHeaderSize + numElements;
|
||||
writeUint32(numBytes);
|
||||
writeUint32(numElements);
|
||||
buffer.buffer.asUint8List().setRange(next, next + numElements, utf8string);
|
||||
next += numElements;
|
||||
}
|
||||
|
||||
void encodeArray(Object t, List val, [int numElements, int encodedSize]) {
|
||||
if (numElements == null) {
|
||||
numElements = val.length;
|
||||
}
|
||||
if (encodedSize == null) {
|
||||
encodedSize = kArrayHeaderSize + (getEncodedSize(t) * numElements);
|
||||
}
|
||||
|
||||
writeUint32(encodedSize);
|
||||
writeUint32(numElements);
|
||||
|
||||
if (t == PackedBool) {
|
||||
int b = 0;
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
if (val[i]) {
|
||||
b |= (1 << (i % 8));
|
||||
}
|
||||
if (((i % 8) == 7) || (i == (numElements - 1))) {
|
||||
Uint8.encode(this, b);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < numElements; i++) {
|
||||
_callEncode(t, this, val[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void encodeStruct(Object t, Object val) {
|
||||
_callEncode(t, this, val);
|
||||
}
|
||||
|
||||
void encodeStructPointer(Object t, Object val) {
|
||||
if (val == null) {
|
||||
encodePointer(val);
|
||||
return;
|
||||
}
|
||||
MojoEncoder encoder = createAndEncodeEncoder(getEncodedSize(t));
|
||||
_callEncode(t, encoder, val);
|
||||
extent = encoder.extent;
|
||||
buffer = encoder.buffer;
|
||||
}
|
||||
|
||||
void encodeArrayPointer(Object t, List val) {
|
||||
if (val == null) {
|
||||
encodePointer(val);
|
||||
return;
|
||||
}
|
||||
int numElements = val.length;
|
||||
int encodedSize = kArrayHeaderSize + ((t == PackedBool) ?
|
||||
(numElements / 8).ceil() : (getEncodedSize(t) * numElements));
|
||||
MojoEncoder encoder = createAndEncodeEncoder(encodedSize);
|
||||
encoder.encodeArray(t, val, numElements, encodedSize);
|
||||
extent = encoder.extent;
|
||||
buffer = encoder.buffer;
|
||||
}
|
||||
|
||||
void encodeStringPointer(String val) {
|
||||
if (val == null) {
|
||||
encodePointer(val);
|
||||
return;
|
||||
}
|
||||
int encodedSize = kArrayHeaderSize + utf8OfString(val).lengthInBytes;
|
||||
MojoEncoder encoder = createAndEncodeEncoder(encodedSize);
|
||||
encoder.encodeString(val);
|
||||
extent = encoder.extent;
|
||||
buffer = encoder.buffer;
|
||||
}
|
||||
|
||||
void encodeMap(Object keyType, Object valType, Map val) {
|
||||
List keys = val.keys;
|
||||
List vals = val.values;
|
||||
writeUint32(kStructHeaderSize + kMapStructPayloadSize);
|
||||
writeUint32(2);
|
||||
encodeArrayPointer(keyType, keys);
|
||||
encodeArrayPointer(valType, vals);
|
||||
}
|
||||
|
||||
void encodeMapPointer(Object keyTYpe, Object valType, Map val) {
|
||||
if (val == null) {
|
||||
encodePointer(val);
|
||||
return;
|
||||
}
|
||||
int encodedSize = kStructHeaderSize + kMapStructPayloadSize;
|
||||
MojoEncoder encoder = createAndEncodeEncoder(encodedSize);
|
||||
encoder.encodeMap(keyType, valType, val);
|
||||
extent = encoder.extent;
|
||||
buffer = encoder.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const int kMessageNameOffset = kStructHeaderSize;
|
||||
const int kMessageFlagsOffset = kMessageNameOffset + 4;
|
||||
const int kMessageRequestIDOffset = kMessageFlagsOffset + 4;
|
||||
const int kMessageExpectsResponse = 1 << 0;
|
||||
const int kMessageIsResponse = 1 << 1;
|
||||
|
||||
class Message {
|
||||
ByteData buffer;
|
||||
List<int> handles;
|
||||
|
||||
Message(this.buffer, this.handles);
|
||||
|
||||
int getHeaderNumBytes() => buffer.getUint32(kStructHeaderNumBytesOffset);
|
||||
int getHeaderNumFields() => buffer.getUint32(kStructHeaderNumFieldsOffset);
|
||||
int getName() => buffer.getUint32(kMessageNameOffset);
|
||||
int getFlags() => buffer.getUint32(kMessageFlagsOffset);
|
||||
bool isResponse() => (getFlags() & kMessageIsResponse) != 0;
|
||||
bool expectsResponse() => (getFlags() & kMessageExpectsResponse) != 0;
|
||||
|
||||
void setRequestID(int id) {
|
||||
buffer.setUint64(kMessageRequestIDOffset, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MessageBuilder {
|
||||
MojoEncoder encoder;
|
||||
List<int> handles;
|
||||
|
||||
MessageBuilder(int name, int payloadSize) {
|
||||
int numBytes = kMessageHeaderSize + payloadSize;
|
||||
var buffer = new ByteData(numBytes);
|
||||
handles = [];
|
||||
|
||||
encoder = new MojoEncoder(buffer, handles, 0, kMessageHeaderSize);
|
||||
encoder.writeUint32(kMessageHeaderSize);
|
||||
encoder.writeUint32(2); // num_fields;
|
||||
encoder.writeUint32(name);
|
||||
encoder.writeUint32(0); // flags.
|
||||
}
|
||||
|
||||
MojoEncoder createEncoder(int size) {
|
||||
encoder = new MojoEncoder(encoder.buffer,
|
||||
handles,
|
||||
encoder.next,
|
||||
encoder.next + size);
|
||||
return encoder;
|
||||
}
|
||||
|
||||
void encodeStruct(Object t, Object val) {
|
||||
encoder = createEncoder(getEncodedSize(t));
|
||||
_callEncode(t, encoder, val);
|
||||
}
|
||||
|
||||
ByteData _trimBuffer() {
|
||||
return new ByteData.view(encoder.buffer.buffer, 0, encoder.extent);
|
||||
}
|
||||
|
||||
Message finish() {
|
||||
Message message = new Message(_trimBuffer(), handles);
|
||||
encoder = null;
|
||||
handles = null;
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MessageWithRequestIDBuilder extends MessageBuilder {
|
||||
MessageWithRequestIDBuilder(
|
||||
int name, int payloadSize, int flags, int requestID) {
|
||||
int numBytes = kMessageWithRequestIDHeaderSize + payloadSize;
|
||||
buffer = new ByteData(numBytes);
|
||||
handles = [];
|
||||
base = 0;
|
||||
|
||||
encoder = createEncoder(0, kMessageWithRequestIDHeaderSize);
|
||||
encoder.writeUint32(kMessageWithRequestIDHeaderSize);
|
||||
encoder.writeUint32(3); // num_fields.
|
||||
encoder.writeUint32(name);
|
||||
encoder.writeUint32(flags);
|
||||
encoder.writeUint64(requestID);
|
||||
base = encoder.next;
|
||||
buffer = encoder.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MessageReader {
|
||||
MojoDecoder decoder;
|
||||
int payloadSize;
|
||||
int name;
|
||||
int flags;
|
||||
int requestID;
|
||||
|
||||
MessageReader(Message message) {
|
||||
decoder = new MojoDecoder(message.buffer, message.handles, 0);
|
||||
|
||||
int messageHeaderSize = decoder.readUint32();
|
||||
payloadSize = message.buffer.lengthInBytes - messageHeaderSize;
|
||||
|
||||
int num_fields = decoder.readUint32();
|
||||
name = decoder.readUint32();
|
||||
flags = decoder.readUint32();
|
||||
|
||||
if (num_fields >= 3) {
|
||||
requestID = decoder.readUint64();
|
||||
}
|
||||
decoder.skip(messageHeaderSize - decoder.next);
|
||||
}
|
||||
|
||||
Object decodeStruct(Object t) => _callDecode(t, decoder);
|
||||
}
|
||||
|
||||
|
||||
abstract class MojoType<T> {
|
||||
static const int encodedSize = 0;
|
||||
static T decode(MojoDecoder decoder) { return null }
|
||||
static void encode(MojoEncoder encoder, T val) {}
|
||||
}
|
||||
|
||||
|
||||
class PackedBool {}
|
||||
|
||||
|
||||
class Int8 implements MojoType<int> {
|
||||
static const int encodedSize = 1;
|
||||
static int decode(MojoDecoder decoder) => decoder.readInt8();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeInt8(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Uint8 implements MojoType<int> {
|
||||
static const int encodedSize = 1;
|
||||
static int decode(MojoDecoder decoder) => decoder.readUint8();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeUint8(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Int16 implements MojoType<int> {
|
||||
static const int encodedSize = 2;
|
||||
static int decode(MojoDecoder decoder) => decoder.readInt16();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeInt16(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Uint16 implements MojoType<int> {
|
||||
static const int encodedSize = 2;
|
||||
static int decode(MojoDecoder decoder) => decoder.readUint16();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeUint16(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Int32 implements MojoType<int> {
|
||||
static const int encodedSize = 4;
|
||||
static int decode(MojoDecoder decoder) => decoder.readInt32();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeInt32(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Uint32 implements MojoType<int> {
|
||||
static const int encodedSize = 4;
|
||||
static int decode(MojoDecoder decoder) => decoder.readUint32();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeUint32(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Int64 implements MojoType<int> {
|
||||
static const int encodedSize = 8;
|
||||
static int decode(MojoDecoder decoder) => decoder.readInt64();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeInt64(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Uint64 implements MojoType<int> {
|
||||
static const int encodedSize = 8;
|
||||
static int decode(MojoDecoder decoder) => decoder.readUint64();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.writeUint64(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MojoString implements MojoType<String> {
|
||||
static const int encodedSize = 8;
|
||||
static String decode(MojoDecoder decoder) => decoder.decodeStringPointer();
|
||||
static void encode(MojoEncoder encoder, String val) {
|
||||
encoder.encodeStringPointer(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NullableMojoString implements MojoType<String> {
|
||||
static const int encodedSize = MojoString.encodedSize;
|
||||
static var decode = MojoString.decode;
|
||||
static var encode = MojoString.encode;
|
||||
}
|
||||
|
||||
|
||||
class Float implements MojoType<double> {
|
||||
static const int encodedSize = 4;
|
||||
static double decode(MojoDecoder decoder) => decoder.readFloat();
|
||||
static void encode(MojoEncoder encoder, double val) {
|
||||
encoder.writeFloat(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Double implements MojoType<double> {
|
||||
static const int encodedSize = 8;
|
||||
static double decode(MojoDecoder decoder) => decoder.readDouble();
|
||||
static void encode(MojoEncoder encoder, double val) {
|
||||
encoder.writeDouble(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class PointerTo {
|
||||
Object val;
|
||||
|
||||
PointerTo(this.val);
|
||||
|
||||
int encodedSize = 8;
|
||||
Object decode(MojoDecoder decoder) {
|
||||
int pointer = decoder.decodePointer();
|
||||
if (pointer == 0) {
|
||||
return null;
|
||||
}
|
||||
return _callDecode(val, decoder.decodeAndCreateDecoder(pointer));
|
||||
}
|
||||
void encode(MojoEncoder encoder, Object val) {
|
||||
if (val == null) {
|
||||
encoder.encodePointer(val);
|
||||
return;
|
||||
}
|
||||
MojoEncoder obj_encoder =
|
||||
encoder.createAndEncodeEncoder(getEncodedSize(this.val));
|
||||
_callEncode(this.val, obj_encoder, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NullablePointerTo extends PointerTo {
|
||||
static const int encodedSize = PointerTo.encodedSize;
|
||||
}
|
||||
|
||||
|
||||
class ArrayOf {
|
||||
Object val;
|
||||
int length;
|
||||
|
||||
ArrayOf(this.val, [this.length = 0]);
|
||||
|
||||
int dimensions() => [length].addAll((val is ArrayOf) ? val.dimensions() : []);
|
||||
|
||||
int encodedSize = 8;
|
||||
List decode(MojoDecoder decoder) => decoder.decodeArrayPointer(val);
|
||||
void encode(MojoEncoder encoder, List val) {
|
||||
encoder.encodeArrayPointer(this.val, val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NullableArrayOf extends ArrayOf {
|
||||
static const int encodedSize = ArrayOf.encodedSize;
|
||||
}
|
||||
|
||||
|
||||
class Handle implements MojoType<int> {
|
||||
static const int encodedSize = 4;
|
||||
static int decode(MojoDecoder decoder) => decoder.decodeHandle();
|
||||
static void encode(MojoEncoder encoder, int val) {
|
||||
encoder.encodeHandle(val);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class NullableHandle implements MojoType<int> {
|
||||
static const int encodedSize = Handle.encodedSize;
|
||||
static const decode = Handle.decode;
|
||||
static const encode = Handle.encode;
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
source_set("bindings") {
|
||||
source_set("js") {
|
||||
sources = [
|
||||
"constants.cc",
|
||||
"constants.h",
|
@ -1,17 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#include "mojo/public/js/bindings/constants.h"
|
||||
|
||||
namespace mojo {
|
||||
|
||||
const char kBufferModuleName[] = "mojo/public/js/bindings/buffer";
|
||||
const char kCodecModuleName[] = "mojo/public/js/bindings/codec";
|
||||
const char kConnectionModuleName[] = "mojo/public/js/bindings/connection";
|
||||
const char kConnectorModuleName[] = "mojo/public/js/bindings/connector";
|
||||
const char kUnicodeModuleName[] = "mojo/public/js/bindings/unicode";
|
||||
const char kRouterModuleName[] = "mojo/public/js/bindings/router";
|
||||
const char kValidatorModuleName[] = "mojo/public/js/bindings/validator";
|
||||
|
||||
} // namespace mojo
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
define("mojo/public/js/bindings/buffer", function() {
|
||||
define("mojo/public/js/buffer", function() {
|
||||
|
||||
var kHostIsLittleEndian = (function () {
|
||||
var endianArrayBuffer = new ArrayBuffer(2);
|
@ -2,9 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
define("mojo/public/js/bindings/codec", [
|
||||
"mojo/public/js/bindings/unicode",
|
||||
"mojo/public/js/bindings/buffer",
|
||||
define("mojo/public/js/codec", [
|
||||
"mojo/public/js/unicode",
|
||||
"mojo/public/js/buffer",
|
||||
], function(unicode, buffer) {
|
||||
|
||||
var kErrorUnsigned = "Passing negative value to unsigned";
|
@ -4,7 +4,7 @@
|
||||
|
||||
define([
|
||||
"gin/test/expect",
|
||||
"mojo/public/js/bindings/codec",
|
||||
"mojo/public/js/codec",
|
||||
"mojo/public/interfaces/bindings/tests/rect.mojom",
|
||||
"mojo/public/interfaces/bindings/tests/sample_service.mojom",
|
||||
"mojo/public/interfaces/bindings/tests/test_structs.mojom",
|
@ -2,9 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
define("mojo/public/js/bindings/connection", [
|
||||
"mojo/public/js/bindings/connector",
|
||||
"mojo/public/js/bindings/router",
|
||||
define("mojo/public/js/connection", [
|
||||
"mojo/public/js/connector",
|
||||
"mojo/public/js/router",
|
||||
], function(connector, router) {
|
||||
|
||||
function Connection(
|
@ -2,11 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
define("mojo/public/js/bindings/connector", [
|
||||
"mojo/public/js/bindings/buffer",
|
||||
"mojo/public/js/bindings/codec",
|
||||
"mojo/public/js/bindings/core",
|
||||
"mojo/public/js/bindings/support",
|
||||
define("mojo/public/js/connector", [
|
||||
"mojo/public/js/buffer",
|
||||
"mojo/public/js/codec",
|
||||
"mojo/public/js/core",
|
||||
"mojo/public/js/support",
|
||||
], function(buffer, codec, core, support) {
|
||||
|
||||
function Connector(handle) {
|
||||
@ -86,6 +86,8 @@ define("mojo/public/js/bindings/connector", [
|
||||
for (;;) {
|
||||
var read = core.readMessage(this.handle_,
|
||||
core.READ_MESSAGE_FLAG_NONE);
|
||||
if (this.handle_ == null) // The connector has been closed.
|
||||
return;
|
||||
if (read.result == core.RESULT_SHOULD_WAIT) {
|
||||
this.waitToReadMore_();
|
||||
return;
|
17
mojo/public/js/constants.cc
Normal file
17
mojo/public/js/constants.cc
Normal file
@ -0,0 +1,17 @@
|
||||
// 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.
|
||||
|
||||
#include "mojo/public/js/constants.h"
|
||||
|
||||
namespace mojo {
|
||||
|
||||
const char kBufferModuleName[] = "mojo/public/js/buffer";
|
||||
const char kCodecModuleName[] = "mojo/public/js/codec";
|
||||
const char kConnectionModuleName[] = "mojo/public/js/connection";
|
||||
const char kConnectorModuleName[] = "mojo/public/js/connector";
|
||||
const char kUnicodeModuleName[] = "mojo/public/js/unicode";
|
||||
const char kRouterModuleName[] = "mojo/public/js/router";
|
||||
const char kValidatorModuleName[] = "mojo/public/js/validator";
|
||||
|
||||
} // namespace mojo
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Module "mojo/public/js/bindings/core"
|
||||
// Module "mojo/public/js/core"
|
||||
//
|
||||
// Note: This file is for documentation purposes only. The code here is not
|
||||
// actually executed. The real module is implemented natively in Mojo.
|
@ -4,7 +4,7 @@
|
||||
|
||||
define([
|
||||
"gin/test/expect",
|
||||
"mojo/public/js/bindings/core",
|
||||
"mojo/public/js/core",
|
||||
"gc",
|
||||
], function(expect, core, gc) {
|
||||
runWithMessagePipe(testNop);
|
@ -2,10 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
define("mojo/public/js/bindings/router", [
|
||||
"mojo/public/js/bindings/codec",
|
||||
"mojo/public/js/bindings/connector",
|
||||
"mojo/public/js/bindings/validator",
|
||||
define("mojo/public/js/router", [
|
||||
"mojo/public/js/codec",
|
||||
"mojo/public/js/connector",
|
||||
"mojo/public/js/validator",
|
||||
], function(codec, connector, validator) {
|
||||
|
||||
function Router(handle, connectorFactory) {
|
||||
@ -14,7 +14,7 @@ define("mojo/public/js/bindings/router", [
|
||||
this.connector_ = new connectorFactory(handle);
|
||||
this.incomingReceiver_ = null;
|
||||
this.nextRequestID_ = 0;
|
||||
this.responders_ = {};
|
||||
this.completers_ = new Map();
|
||||
this.payloadValidators_ = [];
|
||||
|
||||
this.connector_.setIncomingReceiver({
|
||||
@ -26,7 +26,7 @@ define("mojo/public/js/bindings/router", [
|
||||
}
|
||||
|
||||
Router.prototype.close = function() {
|
||||
this.responders_ = {}; // Drop any responders.
|
||||
this.completers_.clear(); // Drop any responders.
|
||||
this.connector_.close();
|
||||
};
|
||||
|
||||
@ -38,7 +38,7 @@ define("mojo/public/js/bindings/router", [
|
||||
// TODO(mpcomplete): no way to trasmit errors over a Connection.
|
||||
};
|
||||
|
||||
Router.prototype.acceptWithResponder = function(message, responder) {
|
||||
Router.prototype.acceptAndExpectResponse = function(message) {
|
||||
// Reserve 0 in case we want it to convey special meaning in the future.
|
||||
var requestID = this.nextRequestID_++;
|
||||
if (requestID == 0)
|
||||
@ -46,13 +46,15 @@ define("mojo/public/js/bindings/router", [
|
||||
|
||||
message.setRequestID(requestID);
|
||||
var result = this.connector_.accept(message);
|
||||
if (!result)
|
||||
return Promise.reject(Error("Connection error"));
|
||||
|
||||
this.responders_[requestID] = responder;
|
||||
|
||||
// TODO(mpcomplete): accept should return a Promise too, maybe?
|
||||
if (result)
|
||||
return Promise.resolve();
|
||||
return Promise.reject(Error("Connection error"));
|
||||
var completer = {};
|
||||
this.completers_.set(requestID, completer);
|
||||
return new Promise(function(resolve, reject) {
|
||||
completer.resolve = resolve;
|
||||
completer.reject = reject;
|
||||
});
|
||||
};
|
||||
|
||||
Router.prototype.setIncomingReceiver = function(receiver) {
|
||||
@ -92,9 +94,9 @@ define("mojo/public/js/bindings/router", [
|
||||
} else if (message.isResponse()) {
|
||||
var reader = new codec.MessageReader(message);
|
||||
var requestID = reader.requestID;
|
||||
var responder = this.responders_[requestID];
|
||||
delete this.responders_[requestID];
|
||||
responder.accept(message);
|
||||
var completer = this.completers_.get(requestID);
|
||||
this.completers_.delete(requestID);
|
||||
completer.resolve(message);
|
||||
} else {
|
||||
if (this.incomingReceiver_)
|
||||
this.incomingReceiver_.accept(message);
|
||||
@ -106,8 +108,9 @@ define("mojo/public/js/bindings/router", [
|
||||
}
|
||||
|
||||
Router.prototype.handleConnectionError_ = function(result) {
|
||||
for (var each in this.responders_)
|
||||
this.responders_[each].reject(result);
|
||||
this.completers_.forEach(function(value) {
|
||||
value.reject(result);
|
||||
});
|
||||
this.close();
|
||||
};
|
||||
|
@ -6,8 +6,8 @@ define([
|
||||
"gin/test/expect",
|
||||
"mojo/public/interfaces/bindings/tests/rect.mojom",
|
||||
"mojo/public/interfaces/bindings/tests/test_structs.mojom",
|
||||
"mojo/public/js/bindings/codec",
|
||||
"mojo/public/js/bindings/validator",
|
||||
"mojo/public/js/codec",
|
||||
"mojo/public/js/validator",
|
||||
], function(expect,
|
||||
rect,
|
||||
testStructs,
|
@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Module "mojo/public/js/bindings/support"
|
||||
// Module "mojo/public/js/support"
|
||||
//
|
||||
// Note: This file is for documentation purposes only. The code here is not
|
||||
// actually executed. The real module is implemented natively in Mojo.
|
@ -7,7 +7,7 @@
|
||||
// mojo/public/cpp/bindings/tests/validation_test_input_parser.h
|
||||
|
||||
define([
|
||||
"mojo/public/js/bindings/buffer"
|
||||
"mojo/public/js/buffer"
|
||||
], function(buffer) {
|
||||
|
||||
// Files and Lines represent the raw text from an input string
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user