summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthakis <thakis@chromium.org>2014-11-14 16:04:25 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-15 00:04:49 +0000
commit671db43a735bd2297225b9d74129402e66fdc549 (patch)
treeeeeb2735f56d964bcdd6a6bf8aa206d41a744b6c
parent3ec1799a199d75eda8bfe2040252df4e05e10735 (diff)
downloadchromium_src-671db43a735bd2297225b9d74129402e66fdc549.zip
chromium_src-671db43a735bd2297225b9d74129402e66fdc549.tar.gz
chromium_src-671db43a735bd2297225b9d74129402e66fdc549.tar.bz2
Revert of Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 (patchset #3 id:40001 of https://codereview.chromium.org/728553002/)
Reason for revert: Breaks incremental builds, crbug.com/433524 Original issue's description: > Update mojo sdk to rev afb4440fd5a10cba980878c326180b7ad7960480 > > TBR=jam@chromium.org > > Committed: https://crrev.com/184f354ddeff66784515ddbbee9c46355cadab6a > Cr-Commit-Position: refs/heads/master@{#304114} TBR=jam@chromium.org,jamesr@chromium.org NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/728043002 Cr-Commit-Position: refs/heads/master@{#304305}
-rw-r--r--build/all.gyp12
-rw-r--r--content/browser/webui/web_ui_mojo_browsertest.cc4
-rw-r--r--device/battery/battery_monitor_impl.cc14
-rw-r--r--device/battery/battery_monitor_impl.h18
-rw-r--r--media/mojo/services/mojo_demuxer_stream_impl.cc2
-rw-r--r--media/mojo/services/mojo_demuxer_stream_impl.h3
-rw-r--r--media/mojo/services/mojo_renderer_impl.cc12
-rw-r--r--mojo/BUILD.gn2
-rw-r--r--mojo/edk/embedder/BUILD.gn66
-rw-r--r--mojo/edk/embedder/channel_init.cc11
-rw-r--r--mojo/edk/embedder/channel_init.h2
-rw-r--r--mojo/edk/embedder/configuration.h68
-rw-r--r--mojo/edk/embedder/embedder.cc64
-rw-r--r--mojo/edk/embedder/embedder.h31
-rw-r--r--mojo/edk/embedder/embedder_internal.h25
-rw-r--r--mojo/edk/embedder/embedder_unittest.cc233
-rw-r--r--mojo/edk/embedder/platform_channel_pair_posix.cc12
-rw-r--r--mojo/edk/embedder/platform_channel_pair_posix_unittest.cc24
-rw-r--r--mojo/edk/embedder/platform_channel_pair_win.cc14
-rw-r--r--mojo/edk/embedder/platform_channel_utils_posix.h22
-rw-r--r--mojo/edk/embedder/platform_handle_utils.h5
-rw-r--r--mojo/edk/embedder/platform_handle_utils_win.cc8
-rw-r--r--mojo/edk/embedder/simple_platform_shared_buffer_posix.cc9
-rw-r--r--mojo/edk/embedder/simple_platform_shared_buffer_win.cc17
-rw-r--r--mojo/edk/embedder/test_embedder.cc13
-rw-r--r--mojo/edk/js/BUILD.gn19
-rw-r--r--mojo/edk/js/DEPS1
-rw-r--r--mojo/edk/js/core.cc130
-rw-r--r--mojo/edk/js/core.h6
-rw-r--r--mojo/edk/js/drain_data.h6
-rw-r--r--mojo/edk/js/handle.cc18
-rw-r--r--mojo/edk/js/handle.h12
-rw-r--r--mojo/edk/js/handle_close_observer.h6
-rw-r--r--mojo/edk/js/mojo_runner_delegate.cc78
-rw-r--r--mojo/edk/js/mojo_runner_delegate.h33
-rw-r--r--mojo/edk/js/support.h6
-rw-r--r--mojo/edk/js/test/BUILD.gn39
-rw-r--r--mojo/edk/js/test/hexdump.js34
-rw-r--r--mojo/edk/js/test/run_js_integration_tests.cc57
-rw-r--r--mojo/edk/js/tests/BUILD.gn21
-rw-r--r--mojo/edk/js/tests/DEPS7
-rw-r--r--mojo/edk/js/tests/connection_tests.js261
-rw-r--r--mojo/edk/js/tests/js_to_cpp.mojom53
-rw-r--r--mojo/edk/js/tests/js_to_cpp_tests.cc418
-rw-r--r--mojo/edk/js/tests/js_to_cpp_tests.js221
-rw-r--r--mojo/edk/js/tests/run_js_tests.cc (renamed from mojo/edk/js/test/run_js_tests.cc)2
-rw-r--r--mojo/edk/js/tests/sample_service_tests.js168
-rw-r--r--mojo/edk/js/threading.cc47
-rw-r--r--mojo/edk/js/threading.h25
-rw-r--r--mojo/edk/js/waiting_callback.h6
-rw-r--r--mojo/edk/mojo_edk.gyp318
-rw-r--r--mojo/edk/mojo_edk_tests.gyp278
-rw-r--r--mojo/edk/system/BUILD.gn65
-rw-r--r--mojo/edk/system/channel.cc25
-rw-r--r--mojo/edk/system/channel.h11
-rw-r--r--mojo/edk/system/channel_endpoint.cc3
-rw-r--r--mojo/edk/system/channel_info.cc8
-rw-r--r--mojo/edk/system/channel_info.h2
-rw-r--r--mojo/edk/system/channel_manager.cc62
-rw-r--r--mojo/edk/system/channel_manager.h74
-rw-r--r--mojo/edk/system/channel_unittest.cc15
-rw-r--r--mojo/edk/system/configuration.cc26
-rw-r--r--mojo/edk/system/configuration.h31
-rw-r--r--mojo/edk/system/constants.h48
-rw-r--r--mojo/edk/system/core.cc48
-rw-r--r--mojo/edk/system/core_test_base.cc4
-rw-r--r--mojo/edk/system/core_unittest.cc867
-rw-r--r--mojo/edk/system/data_pipe.cc43
-rw-r--r--mojo/edk/system/data_pipe.h13
-rw-r--r--mojo/edk/system/data_pipe_consumer_dispatcher.cc7
-rw-r--r--mojo/edk/system/data_pipe_unittest.cc16
-rw-r--r--mojo/edk/system/dispatcher.cc19
-rw-r--r--mojo/edk/system/dispatcher.h2
-rw-r--r--mojo/edk/system/dispatcher_unittest.cc113
-rw-r--r--mojo/edk/system/entrypoints.cc (renamed from mojo/edk/embedder/entrypoints.cc)80
-rw-r--r--mojo/edk/system/entrypoints.h24
-rw-r--r--mojo/edk/system/handle_table.cc37
-rw-r--r--mojo/edk/system/local_data_pipe.cc5
-rw-r--r--mojo/edk/system/local_data_pipe.h11
-rw-r--r--mojo/edk/system/local_data_pipe_unittest.cc669
-rw-r--r--mojo/edk/system/mapping_table.cc5
-rw-r--r--mojo/edk/system/memory.cc18
-rw-r--r--mojo/edk/system/memory.h4
-rw-r--r--mojo/edk/system/message_in_transit.cc42
-rw-r--r--mojo/edk/system/message_pipe.cc25
-rw-r--r--mojo/edk/system/message_pipe_dispatcher.cc21
-rw-r--r--mojo/edk/system/message_pipe_dispatcher_unittest.cc141
-rw-r--r--mojo/edk/system/message_pipe_perftest.cc36
-rw-r--r--mojo/edk/system/message_pipe_test_utils.cc11
-rw-r--r--mojo/edk/system/message_pipe_unittest.cc258
-rw-r--r--mojo/edk/system/multiprocess_message_pipe_unittest.cc115
-rw-r--r--mojo/edk/system/options_validation.h1
-rw-r--r--mojo/edk/system/raw_channel.cc38
-rw-r--r--mojo/edk/system/raw_channel.h1
-rw-r--r--mojo/edk/system/raw_channel_posix.cc30
-rw-r--r--mojo/edk/system/raw_channel_unittest.cc20
-rw-r--r--mojo/edk/system/raw_channel_win.cc38
-rw-r--r--mojo/edk/system/remote_message_pipe_unittest.cc441
-rw-r--r--mojo/edk/system/run_all_unittests.cc3
-rw-r--r--mojo/edk/system/shared_buffer_dispatcher.cc8
-rw-r--r--mojo/edk/system/shared_buffer_dispatcher_unittest.cc100
-rw-r--r--mojo/edk/system/simple_dispatcher_unittest.cc136
-rw-r--r--mojo/edk/system/test_utils.h3
-rw-r--r--mojo/edk/system/transport_data.cc40
-rw-r--r--mojo/edk/system/transport_data.h4
-rw-r--r--mojo/edk/system/waiter_test_utils.cc4
-rw-r--r--mojo/edk/test/BUILD.gn2
-rw-r--r--mojo/edk/test/multiprocess_test_helper.cc4
-rw-r--r--mojo/edk/test/multiprocess_test_helper.h3
-rw-r--r--mojo/edk/test/run_all_unittests.cc3
-rw-r--r--mojo/edk/test/test_support_impl.cc3
-rw-r--r--mojo/edk/test/test_utils_win.cc39
-rw-r--r--mojo/mojo.gyp2
-rw-r--r--mojo/mojo_base.gyp10
-rw-r--r--mojo/public/VERSION2
-rw-r--r--mojo/public/cpp/application/BUILD.gn8
-rw-r--r--mojo/public/cpp/application/lib/DEPS8
-rw-r--r--mojo/public/cpp/application/lib/application_test_main.cc7
-rw-r--r--mojo/public/cpp/bindings/BUILD.gn2
-rw-r--r--mojo/public/cpp/bindings/binding.h136
-rw-r--r--mojo/public/cpp/bindings/interface_impl.h86
-rw-r--r--mojo/public/cpp/bindings/lib/interface_impl_internal.h128
-rw-r--r--mojo/public/cpp/bindings/strong_binding.h88
-rw-r--r--mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc168
-rw-r--r--mojo/public/cpp/bindings/tests/validation_unittest.cc2
-rw-r--r--mojo/public/cpp/utility/tests/BUILD.gn10
-rw-r--r--mojo/public/dart/BUILD.gn46
-rw-r--r--mojo/public/dart/DEPS4
-rw-r--r--mojo/public/dart/README14
-rw-r--r--mojo/public/dart/core.dart19
-rw-r--r--mojo/public/dart/mojo_init.dart16
-rw-r--r--mojo/public/dart/src/buffer.dart107
-rw-r--r--mojo/public/dart/src/data_pipe.dart191
-rw-r--r--mojo/public/dart/src/handle.dart68
-rw-r--r--mojo/public/dart/src/message_pipe.dart155
-rw-r--r--mojo/public/dart/src/mojo_dart_core.cc659
-rw-r--r--mojo/public/dart/src/types.dart116
-rw-r--r--mojo/public/go/system/impl/mojo_types.go1
-rw-r--r--mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java10
-rw-r--r--mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java18
-rw-r--r--mojo/public/java/bindings/src/org/chromium/mojo/bindings/ServiceMessage.java2
-rw-r--r--mojo/public/java/system/src/org/chromium/mojo/system/DataPipe.java15
-rw-r--r--mojo/public/js/core.js1
-rw-r--r--mojo/public/js/core_unittests.js25
-rw-r--r--mojo/public/js/threading.js21
-rw-r--r--mojo/public/mojo_public.gyp61
-rw-r--r--mojo/public/python/mojo/bindings/descriptor.py2
-rw-r--r--mojo/public/python/mojo/bindings/messaging.py4
-rw-r--r--mojo/public/python/mojo/bindings/serialization.py4
-rw-r--r--mojo/public/python/mojo/c_core.pxd1
-rw-r--r--mojo/public/python/mojo/system.pyx1
-rw-r--r--mojo/public/tools/bindings/mojom_bindings_generator.gypi63
-rw-r--r--mojo/public/tools/bindings/mojom_bindings_generator_explicit.gypi69
-rw-r--r--mojo/public/tools/bindings/mojom_bindings_generator_variables.gypi67
-rwxr-xr-xmojo/public/tools/bindings/mojom_list_outputs.py34
-rw-r--r--mojo/services/public/cpp/view_manager/BUILD.gn2
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view.cc4
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc5
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc5
-rw-r--r--mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h5
-rw-r--r--mojo/services/public/cpp/view_manager/view_tracker.cc41
-rw-r--r--mojo/services/public/cpp/view_manager/view_tracker.h47
-rw-r--r--mojo/services/public/interfaces/accessibility/BUILD.gn15
-rw-r--r--mojo/services/public/interfaces/accessibility/accessibility.mojom35
-rw-r--r--mojo/services/public/interfaces/network/cookie_store.mojom4
-rw-r--r--mojo/services/public/interfaces/network/network_service.mojom4
-rw-r--r--mojo/services/public/interfaces/network/url_loader.mojom16
-rw-r--r--mojo/services/public/interfaces/view_manager/view_manager.mojom2
-rw-r--r--mojo/services/public/interfaces/window_manager/window_manager.mojom2
-rw-r--r--mojo/services/public/js/mojo.js169
-rw-r--r--ui/keyboard/webui/vk_mojo_handler.cc11
-rw-r--r--ui/keyboard/webui/vk_mojo_handler.h10
-rw-r--r--ui/keyboard/webui/vk_webui_controller.cc3
173 files changed, 3433 insertions, 6284 deletions
diff --git a/build/all.gyp b/build/all.gyp
index 9e3b257..a11ee7a 100644
--- a/build/all.gyp
+++ b/build/all.gyp
@@ -42,13 +42,13 @@
# NOTE: This list of targets is present because
# mojo_base.gyp:mojo_base cannot be built on iOS, as
# javascript-related targets cause v8 to be built.
- '../mojo/edk/mojo_edk_tests.gyp:mojo_public_bindings_unittests',
- '../mojo/edk/mojo_edk_tests.gyp:mojo_public_environment_unittests',
- '../mojo/edk/mojo_edk_tests.gyp:mojo_public_system_perftests',
- '../mojo/edk/mojo_edk_tests.gyp:mojo_public_system_unittests',
- '../mojo/edk/mojo_edk_tests.gyp:mojo_public_utility_unittests',
+ '../mojo/edk/mojo_edk.gyp:mojo_public_bindings_unittests',
+ '../mojo/edk/mojo_edk.gyp:mojo_public_environment_unittests',
+ '../mojo/edk/mojo_edk.gyp:mojo_public_system_perftests',
+ '../mojo/edk/mojo_edk.gyp:mojo_public_system_unittests',
+ '../mojo/edk/mojo_edk.gyp:mojo_public_utility_unittests',
'../mojo/edk/mojo_edk.gyp:mojo_system_impl',
- '../mojo/edk/mojo_edk_tests.gyp:mojo_system_unittests',
+ '../mojo/edk/mojo_edk.gyp:mojo_system_unittests',
'../mojo/mojo_base.gyp:mojo_common_lib',
'../mojo/mojo_base.gyp:mojo_common_unittests',
'../mojo/public/mojo_public.gyp:mojo_cpp_bindings',
diff --git a/content/browser/webui/web_ui_mojo_browsertest.cc b/content/browser/webui/web_ui_mojo_browsertest.cc
index d967230..9830f1d 100644
--- a/content/browser/webui/web_ui_mojo_browsertest.cc
+++ b/content/browser/webui/web_ui_mojo_browsertest.cc
@@ -82,6 +82,9 @@ class PingBrowserTargetImpl : public BrowserTargetImpl {
~PingBrowserTargetImpl() override {}
+ // mojo::InterfaceImpl<BrowserTarget> overrides:
+ void OnConnectionEstablished() override { client()->Ping(); }
+
// Quit the RunLoop when called.
void PingResponse() override {
got_message = true;
@@ -131,7 +134,6 @@ class PingTestWebUIController : public TestWebUIController {
void CreateHandler(mojo::InterfaceRequest<BrowserTarget> request) {
browser_target_.reset(mojo::WeakBindToRequest(
new PingBrowserTargetImpl(run_loop_), &request));
- browser_target_->client()->Ping();
}
private:
diff --git a/device/battery/battery_monitor_impl.cc b/device/battery/battery_monitor_impl.cc
index dc07b62..3cbf57d 100644
--- a/device/battery/battery_monitor_impl.cc
+++ b/device/battery/battery_monitor_impl.cc
@@ -11,26 +11,24 @@ namespace device {
// static
void BatteryMonitorImpl::Create(
mojo::InterfaceRequest<BatteryMonitor> request) {
- new BatteryMonitorImpl(request.Pass());
+ BindToRequest(new BatteryMonitorImpl(), &request);
}
-BatteryMonitorImpl::BatteryMonitorImpl(
- mojo::InterfaceRequest<BatteryMonitor> request)
- : binding_(this, request.Pass()),
- subscription_(BatteryStatusService::GetInstance()->AddCallback(
- base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this)))) {
+BatteryMonitorImpl::BatteryMonitorImpl() {
}
BatteryMonitorImpl::~BatteryMonitorImpl() {
}
-void BatteryMonitorImpl::RegisterSubscription() {
+void BatteryMonitorImpl::OnConnectionEstablished() {
+ subscription_ = BatteryStatusService::GetInstance()->AddCallback(
+ base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this)));
}
void BatteryMonitorImpl::DidChange(const BatteryStatus& battery_status) {
BatteryStatusPtr status(BatteryStatus::New());
*status = battery_status;
- binding_.client()->DidChange(status.Pass());
+ client()->DidChange(status.Pass());
}
} // namespace device
diff --git a/device/battery/battery_monitor_impl.h b/device/battery/battery_monitor_impl.h
index 7916b0d..5c64843 100644
--- a/device/battery/battery_monitor_impl.h
+++ b/device/battery/battery_monitor_impl.h
@@ -2,33 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef DEVICE_BATTERY_BATTERY_MONITOR_IMPL_H_
-#define DEVICE_BATTERY_BATTERY_MONITOR_IMPL_H_
-
#include "base/memory/scoped_ptr.h"
#include "device/battery/battery_export.h"
#include "device/battery/battery_monitor.mojom.h"
#include "device/battery/battery_status_service.h"
-#include "mojo/public/cpp/bindings/strong_binding.h"
+
+#ifndef DEVICE_BATTERY_BATTERY_MONITOR_IMPL_H_
+#define DEVICE_BATTERY_BATTERY_MONITOR_IMPL_H_
namespace device {
-class BatteryMonitorImpl : public BatteryMonitor {
+class BatteryMonitorImpl : public mojo::InterfaceImpl<BatteryMonitor> {
public:
DEVICE_BATTERY_EXPORT static void Create(
mojo::InterfaceRequest<BatteryMonitor> request);
private:
- explicit BatteryMonitorImpl(mojo::InterfaceRequest<BatteryMonitor> request);
+ BatteryMonitorImpl();
~BatteryMonitorImpl() override;
- void RegisterSubscription();
+ // mojo::InterfaceImpl<..> methods:
+ void OnConnectionEstablished() override;
+
void DidChange(const BatteryStatus& battery_status);
- mojo::StrongBinding<BatteryMonitor> binding_;
scoped_ptr<BatteryStatusService::BatteryUpdateSubscription> subscription_;
-
- DISALLOW_COPY_AND_ASSIGN(BatteryMonitorImpl);
};
} // namespace device
diff --git a/media/mojo/services/mojo_demuxer_stream_impl.cc b/media/mojo/services/mojo_demuxer_stream_impl.cc
index e891436..861ba2d 100644
--- a/media/mojo/services/mojo_demuxer_stream_impl.cc
+++ b/media/mojo/services/mojo_demuxer_stream_impl.cc
@@ -51,7 +51,7 @@ void MojoDemuxerStreamImpl::OnBufferReady(
mojo::MediaDecoderBuffer::From(buffer));
}
-void MojoDemuxerStreamImpl::DidConnect() {
+void MojoDemuxerStreamImpl::OnConnectionEstablished() {
// This is called when our DemuxerStreamClient has connected itself and is
// ready to receive messages. Send an initial config and notify it that
// we are now ready for business.
diff --git a/media/mojo/services/mojo_demuxer_stream_impl.h b/media/mojo/services/mojo_demuxer_stream_impl.h
index 53a6dc3..46333e4 100644
--- a/media/mojo/services/mojo_demuxer_stream_impl.h
+++ b/media/mojo/services/mojo_demuxer_stream_impl.h
@@ -28,7 +28,8 @@ class MojoDemuxerStreamImpl : public mojo::InterfaceImpl<mojo::DemuxerStream> {
mojo::MediaDecoderBufferPtr)>& callback)
override;
- void DidConnect();
+ // mojo::InterfaceImpl overrides.
+ void OnConnectionEstablished() override;
private:
// |callback| is the callback that was passed to the initiating Read()
diff --git a/media/mojo/services/mojo_renderer_impl.cc b/media/mojo/services/mojo_renderer_impl.cc
index 0a6abe6..f93bfe1 100644
--- a/media/mojo/services/mojo_renderer_impl.cc
+++ b/media/mojo/services/mojo_renderer_impl.cc
@@ -63,16 +63,12 @@ void MojoRendererImpl::Initialize(
demuxer_stream_provider_->GetStream(DemuxerStream::VIDEO);
mojo::DemuxerStreamPtr audio_stream;
- if (audio) {
- mojo::BindToProxy(new MojoDemuxerStreamImpl(audio), &audio_stream)
- ->DidConnect();
- }
+ if (audio)
+ mojo::BindToProxy(new MojoDemuxerStreamImpl(audio), &audio_stream);
mojo::DemuxerStreamPtr video_stream;
- if (video) {
- mojo::BindToProxy(new MojoDemuxerStreamImpl(video), &video_stream)
- ->DidConnect();
- }
+ if (video)
+ mojo::BindToProxy(new MojoDemuxerStreamImpl(video), &video_stream);
remote_audio_renderer_->Initialize(
audio_stream.Pass(),
diff --git a/mojo/BUILD.gn b/mojo/BUILD.gn
index 3a287f0..d9ec502 100644
--- a/mojo/BUILD.gn
+++ b/mojo/BUILD.gn
@@ -26,7 +26,7 @@ group("tests") {
deps = [
"//mojo/common:mojo_common_unittests",
"//mojo/converters/surfaces/tests:mojo_surfaces_lib_unittests",
- "//mojo/edk/js/test:js_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",
diff --git a/mojo/edk/embedder/BUILD.gn b/mojo/edk/embedder/BUILD.gn
index 3bd9df0..50e93b0 100644
--- a/mojo/edk/embedder/BUILD.gn
+++ b/mojo/edk/embedder/BUILD.gn
@@ -3,26 +3,11 @@
# found in the LICENSE file.
source_set("embedder") {
- # This isn't really a standalone target; it must be linked into the
+ # This isn't really a standalone target, it must be linked into the
# mojo_system_impl component.
visibility = [ "//mojo/edk/system" ]
- sources = [
- "channel_info_forward.h",
- "channel_init.cc",
- "channel_init.h",
- "configuration.h",
- "embedder.cc",
- "embedder.h",
- "embedder_internal.h",
- "entrypoints.cc",
- # Test-only code:
- # TODO(vtl): It's a little unfortunate that these end up in the same
- # component as non-test-only code. In the static build, this code should
- # hopefully be dead-stripped.
- "test_embedder.cc",
- "test_embedder.h",
- ]
+ deps = [ "//base", ]
defines = [
"MOJO_SYSTEM_IMPL_IMPLEMENTATION",
@@ -31,23 +16,12 @@ source_set("embedder") {
configs += [ "//mojo/edk/system:system_config" ]
- public_deps = [
- ":platform",
- "//mojo/public/cpp/system",
- ]
-
- deps = [ "//base" ]
-}
-
-source_set("platform") {
- # This isn't really a standalone target; it must be linked into the
- # mojo_system_impl component.
- visibility = [
- ":embedder",
- "//mojo/edk/system",
- ]
-
sources = [
+ "channel_info_forward.h",
+ "channel_init.cc",
+ "channel_init.h",
+ "embedder.cc",
+ "embedder.h",
"platform_channel_pair.cc",
"platform_channel_pair.h",
"platform_channel_pair_posix.cc",
@@ -69,30 +43,30 @@ source_set("platform") {
"simple_platform_shared_buffer_win.cc",
"simple_platform_support.cc",
"simple_platform_support.h",
+ # Test-only code:
+ # TODO(vtl): It's a little unfortunate that these end up in the same
+ # component as non-test-only code. In the static build, this code should
+ # hopefully be dead-stripped.
+ "test_embedder.cc",
+ "test_embedder.h",
]
-
- defines = [ "MOJO_SYSTEM_IMPL_IMPLEMENTATION" ]
-
- configs += [ "//mojo/edk/system:system_config" ]
-
- deps = [ "//base" ]
}
source_set("embedder_unittests") {
testonly = true
visibility = [ "//mojo/edk/system:mojo_system_unittests" ]
-
- sources = [
- "embedder_unittest.cc",
- "platform_channel_pair_posix_unittest.cc",
- "simple_platform_shared_buffer_unittest.cc",
- ]
+ testonly = true
deps = [
"//base",
- "//base/test:test_support",
"//mojo/edk/test:test_support",
"//mojo/edk/system",
"//testing/gtest",
]
+
+ sources = [
+ "embedder_unittest.cc",
+ "platform_channel_pair_posix_unittest.cc",
+ "simple_platform_shared_buffer_unittest.cc",
+ ]
}
diff --git a/mojo/edk/embedder/channel_init.cc b/mojo/edk/embedder/channel_init.cc
index 0e7a7b6..9ea984b 100644
--- a/mojo/edk/embedder/channel_init.cc
+++ b/mojo/edk/embedder/channel_init.cc
@@ -25,11 +25,12 @@ ScopedMessagePipeHandle ChannelInit::Init(
DCHECK(!io_thread_task_runner_.get()); // Should only init once.
io_thread_task_runner_ = io_thread_task_runner;
ScopedMessagePipeHandle message_pipe =
- CreateChannel(
- ScopedPlatformHandle(PlatformHandle(file)), io_thread_task_runner,
- base::Bind(&ChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(),
- io_thread_task_runner),
- base::MessageLoop::current()->message_loop_proxy()).Pass();
+ CreateChannel(ScopedPlatformHandle(PlatformHandle(file)),
+ io_thread_task_runner,
+ base::Bind(&ChannelInit::OnCreatedChannel,
+ weak_factory_.GetWeakPtr(),
+ io_thread_task_runner),
+ base::MessageLoop::current()->message_loop_proxy()).Pass();
return message_pipe.Pass();
}
diff --git a/mojo/edk/embedder/channel_init.h b/mojo/edk/embedder/channel_init.h
index 59b6694..ce191b4 100644
--- a/mojo/edk/embedder/channel_init.h
+++ b/mojo/edk/embedder/channel_init.h
@@ -10,7 +10,7 @@
#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/message_pipe.h"
+#include "mojo/public/cpp/system/core.h"
namespace base {
class MessageLoopProxy;
diff --git a/mojo/edk/embedder/configuration.h b/mojo/edk/embedder/configuration.h
deleted file mode 100644
index 0f99e1f..0000000
--- a/mojo/edk/embedder/configuration.h
+++ /dev/null
@@ -1,68 +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.
-
-#ifndef MOJO_EDK_EMBEDDER_CONFIGURATION_H_
-#define MOJO_EDK_EMBEDDER_CONFIGURATION_H_
-
-#include <stddef.h>
-
-namespace mojo {
-namespace embedder {
-
-// A set of constants that the Mojo system internally uses. These values should
-// be consistent across all processes on the same system.
-//
-// In general, there should be no need to change these values from their
-// defaults. However, if you do change them, you must do so before
-// initialization.
-struct Configuration {
- // Maximum number of open (Mojo) handles. The default is 1,000,000.
- //
- // TODO(vtl): This doesn't count "live" handles, some of which may live in
- // messages.
- size_t max_handle_table_size;
-
- // Maximum number of active memory mappings. The default is 1,000,000.
- size_t max_mapping_table_sze;
-
- // Upper limit of |MojoWaitMany()|'s |num_handles|. The default is 1,000,000.
- // Must be same as or smaller than |max_handle_table_size|.
- size_t max_wait_many_num_handles;
-
- // Maximum data size of messages sent over message pipes, in bytes. The
- // default is 4MB.
- size_t max_message_num_bytes;
-
- // Maximum number of handles that can be attached to messages sent over
- // message pipes. The default is 10,000.
- size_t max_message_num_handles;
-
- // Maximum capacity of a data pipe, in bytes. The default is 256MB. This value
- // must fit into a |uint32_t|. WARNING: If you bump it closer to 2^32, you
- // must audit all the code to check that we don't overflow (2^31 would
- // definitely be risky; up to 2^30 is probably okay).
- size_t max_data_pipe_capacity_bytes;
-
- // Default data pipe capacity, if not specified explicitly in the creation
- // options. The default is 1MB.
- size_t default_data_pipe_capacity_bytes;
-
- // Alignment for the "start" of the data buffer used by data pipes. (The
- // alignment of elements will depend on this and the element size.) The
- // default is 16 bytes.
- size_t data_pipe_buffer_alignment_bytes;
-
- // Maximum size of a single shared memory segment, in bytes. The default is
- // 1GB.
- //
- // TODO(vtl): Set this hard limit appropriately (e.g., higher on 64-bit).
- // (This will also entail some auditing to make sure I'm not messing up my
- // checks anywhere.)
- size_t max_shared_memory_num_bytes;
-};
-
-} // namespace embedder
-} // namespace mojo
-
-#endif // MOJO_EDK_EMBEDDER_CONFIGURATION_H_
diff --git a/mojo/edk/embedder/embedder.cc b/mojo/edk/embedder/embedder.cc
index 7b0dd39..ca2169a 100644
--- a/mojo/edk/embedder/embedder.cc
+++ b/mojo/edk/embedder/embedder.cc
@@ -9,13 +9,12 @@
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop_proxy.h"
-#include "mojo/edk/embedder/embedder_internal.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/configuration.h"
#include "mojo/edk/system/core.h"
+#include "mojo/edk/system/entrypoints.h"
#include "mojo/edk/system/message_pipe_dispatcher.h"
#include "mojo/edk/system/platform_handle_dispatcher.h"
#include "mojo/edk/system/raw_channel.h"
@@ -27,13 +26,14 @@ namespace {
// Helper for |CreateChannel...()|. (Note: May return null for some failures.)
scoped_refptr<system::Channel> MakeChannel(
+ system::Core* core,
ScopedPlatformHandle platform_handle,
scoped_refptr<system::ChannelEndpoint> channel_endpoint) {
DCHECK(platform_handle.is_valid());
// Create and initialize a |system::Channel|.
scoped_refptr<system::Channel> channel =
- new system::Channel(internal::g_core->platform_support());
+ new system::Channel(core->platform_support());
if (!channel->Init(system::RawChannel::Create(platform_handle.Pass()))) {
// This is very unusual (e.g., maybe |platform_handle| was invalid or we
// reached some system resource limit).
@@ -49,12 +49,14 @@ scoped_refptr<system::Channel> MakeChannel(
}
void CreateChannelHelper(
+ system::Core* core,
ScopedPlatformHandle platform_handle,
scoped_ptr<ChannelInfo> channel_info,
scoped_refptr<system::ChannelEndpoint> channel_endpoint,
DidCreateChannelCallback callback,
scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
- channel_info->channel = MakeChannel(platform_handle.Pass(), channel_endpoint);
+ channel_info->channel =
+ MakeChannel(core, platform_handle.Pass(), channel_endpoint);
// Hand the channel back to the embedder.
if (callback_thread_task_runner.get()) {
@@ -67,21 +69,8 @@ void CreateChannelHelper(
} // namespace
-namespace internal {
-
-// Declared in embedder_internal.h.
-system::Core* g_core = nullptr;
-
-} // namespace internal
-
void Init(scoped_ptr<PlatformSupport> platform_support) {
- // TODO(vtl): Uncomment after fixing Python bindings tests. crbug.com/432670
- // DCHECK(!internal::g_core);
- internal::g_core = new system::Core(platform_support.Pass());
-}
-
-Configuration* GetConfiguration() {
- return system::GetMutableConfiguration();
+ system::entrypoints::SetCore(new system::Core(platform_support.Pass()));
}
// TODO(vtl): Write tests for this.
@@ -95,13 +84,14 @@ ScopedMessagePipeHandle CreateChannelOnIOThread(
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint);
- DCHECK(internal::g_core);
+ system::Core* core = system::entrypoints::GetCore();
+ DCHECK(core);
ScopedMessagePipeHandle rv(
- MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));
+ MessagePipeHandle(core->AddDispatcher(dispatcher)));
- *channel_info =
- new ChannelInfo(MakeChannel(platform_handle.Pass(), channel_endpoint),
- base::MessageLoopProxy::current());
+ *channel_info = new ChannelInfo(
+ MakeChannel(core, platform_handle.Pass(), channel_endpoint),
+ base::MessageLoopProxy::current());
return rv.Pass();
}
@@ -119,20 +109,24 @@ ScopedMessagePipeHandle CreateChannel(
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint);
- DCHECK(internal::g_core);
+ system::Core* core = system::entrypoints::GetCore();
+ DCHECK(core);
ScopedMessagePipeHandle rv(
- MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));
+ MessagePipeHandle(core->AddDispatcher(dispatcher)));
scoped_ptr<ChannelInfo> channel_info(new ChannelInfo());
// 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,
- base::Bind(&CreateChannelHelper, base::Passed(&platform_handle),
- base::Passed(&channel_info), channel_endpoint, callback,
- callback_thread_task_runner));
+ io_thread_task_runner->PostTask(FROM_HERE,
+ base::Bind(&CreateChannelHelper,
+ base::Unretained(core),
+ base::Passed(&platform_handle),
+ base::Passed(&channel_info),
+ channel_endpoint,
+ callback,
+ callback_thread_task_runner));
} else {
(callback_thread_task_runner.get() ? callback_thread_task_runner
: io_thread_task_runner)
@@ -181,8 +175,9 @@ MojoResult CreatePlatformHandleWrapper(
scoped_refptr<system::Dispatcher> dispatcher(
new system::PlatformHandleDispatcher(platform_handle.Pass()));
- DCHECK(internal::g_core);
- MojoHandle h = internal::g_core->AddDispatcher(dispatcher);
+ system::Core* core = system::entrypoints::GetCore();
+ DCHECK(core);
+ MojoHandle h = core->AddDispatcher(dispatcher);
if (h == MOJO_HANDLE_INVALID) {
LOG(ERROR) << "Handle table full";
dispatcher->Close();
@@ -197,9 +192,10 @@ MojoResult PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
ScopedPlatformHandle* platform_handle) {
DCHECK(platform_handle);
- DCHECK(internal::g_core);
+ system::Core* core = system::entrypoints::GetCore();
+ DCHECK(core);
scoped_refptr<system::Dispatcher> dispatcher(
- internal::g_core->GetDispatcher(platform_handle_wrapper_handle));
+ core->GetDispatcher(platform_handle_wrapper_handle));
if (!dispatcher.get())
return MOJO_RESULT_INVALID_ARGUMENT;
diff --git a/mojo/edk/embedder/embedder.h b/mojo/edk/embedder/embedder.h
index 11a352c..85bc5832 100644
--- a/mojo/edk/embedder/embedder.h
+++ b/mojo/edk/embedder/embedder.h
@@ -12,23 +12,16 @@
#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/message_pipe.h"
+#include "mojo/public/cpp/system/core.h"
namespace mojo {
namespace embedder {
-struct Configuration;
class PlatformSupport;
-// Must be called first, or just after setting configuration parameters,
-// to initialize the (global, singleton) system.
+// Must be called first to initialize the (global, singleton) system.
MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support);
-// Returns the global configuration. In general there should be no need to
-// change the configuration, but if you do so this must be done before calling
-// |Init()|.
-MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration();
-
// A "channel" is a connection on top of an OS "pipe", on top of which Mojo
// message pipes (etc.) can be multiplexed. It must "live" on some I/O thread.
//
@@ -71,8 +64,8 @@ MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration();
// |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);
+ CreateChannelOnIOThread(ScopedPlatformHandle platform_handle,
+ ChannelInfo** channel_info);
typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback;
// Creates a channel asynchronously; may be called from any thread.
@@ -85,10 +78,10 @@ typedef base::Callback<void(ChannelInfo*)> DidCreateChannelCallback;
// it will be called using |io_thread_task_runner|. Returns a handle to the
// bootstrap message pipe.
MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle
-CreateChannel(ScopedPlatformHandle platform_handle,
- scoped_refptr<base::TaskRunner> io_thread_task_runner,
- DidCreateChannelCallback callback,
- scoped_refptr<base::TaskRunner> callback_thread_task_runner);
+ CreateChannel(ScopedPlatformHandle platform_handle,
+ scoped_refptr<base::TaskRunner> io_thread_task_runner,
+ DidCreateChannelCallback callback,
+ scoped_refptr<base::TaskRunner> callback_thread_task_runner);
// Destroys a channel that was created using either |CreateChannelOnIOThread()|
// or |CreateChannel()|; must only be called from the I/O thread. |channel_info|
@@ -113,14 +106,14 @@ MOJO_SYSTEM_IMPL_EXPORT void WillDestroyChannelSoon(ChannelInfo* channel_info);
// failure, which is different from what you'd expect from a Mojo API, but it
// makes for a more convenient embedder API.
MOJO_SYSTEM_IMPL_EXPORT MojoResult
-CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle,
- MojoHandle* platform_handle_wrapper_handle);
+ CreatePlatformHandleWrapper(ScopedPlatformHandle platform_handle,
+ MojoHandle* platform_handle_wrapper_handle);
// Retrieves the |PlatformHandle| that was wrapped into a |MojoHandle| (using
// |CreatePlatformHandleWrapper()| above). Note that the |MojoHandle| must still
// be closed separately.
MOJO_SYSTEM_IMPL_EXPORT MojoResult
-PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
- ScopedPlatformHandle* platform_handle);
+ PassWrappedPlatformHandle(MojoHandle platform_handle_wrapper_handle,
+ ScopedPlatformHandle* platform_handle);
} // namespace embedder
} // namespace mojo
diff --git a/mojo/edk/embedder/embedder_internal.h b/mojo/edk/embedder/embedder_internal.h
deleted file mode 100644
index b8919b0..0000000
--- a/mojo/edk/embedder/embedder_internal.h
+++ /dev/null
@@ -1,25 +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.
-
-#ifndef MOJO_EDK_EMBEDDER_EMBEDDER_INTERNAL_H_
-#define MOJO_EDK_EMBEDDER_EMBEDDER_INTERNAL_H_
-
-namespace mojo {
-
-namespace system {
-class Core;
-} // namespace system
-
-namespace embedder {
-namespace internal {
-
-// Instance of |Core| used by the system functions (|Mojo...()|).
-extern system::Core* g_core;
-
-} // namespace internal
-} // namepace embedder
-
-} // namespace mojo
-
-#endif // MOJO_EDK_EMBEDDER_EMBEDDER_INTERNAL_H_
diff --git a/mojo/edk/embedder/embedder_unittest.cc b/mojo/edk/embedder/embedder_unittest.cc
index 78423d2..5c4d0d8 100644
--- a/mojo/edk/embedder/embedder_unittest.cc
+++ b/mojo/edk/embedder/embedder_unittest.cc
@@ -39,7 +39,8 @@ class ScopedTestChannel {
did_create_channel_event_(true, false),
channel_info_(nullptr) {
bootstrap_message_pipe_ =
- CreateChannel(platform_handle.Pass(), io_thread_task_runner_,
+ CreateChannel(platform_handle.Pass(),
+ io_thread_task_runner_,
base::Bind(&ScopedTestChannel::DidCreateChannel,
base::Unretained(this)),
nullptr)
@@ -52,7 +53,8 @@ class ScopedTestChannel {
// the I/O thread must be alive and pumping messages.)
~ScopedTestChannel() {
system::test::PostTaskAndWait(
- io_thread_task_runner_, FROM_HERE,
+ io_thread_task_runner_,
+ FROM_HERE,
base::Bind(&ScopedTestChannel::DestroyChannel, base::Unretained(this)));
}
@@ -128,18 +130,27 @@ TEST_F(EmbedderTest, ChannelsBasic) {
// We can write to a message pipe handle immediately.
const char kHello[] = "hello";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(server_mp, kHello,
- static_cast<uint32_t>(sizeof(kHello)), nullptr,
- 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ MojoWriteMessage(server_mp,
+ kHello,
+ static_cast<uint32_t>(sizeof(kHello)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Now wait for the other side to become readable.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(
+ client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
char buffer[1000] = {};
uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr,
+ MojoReadMessage(client_mp,
+ buffer,
+ &num_bytes,
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), num_bytes);
EXPECT_STREQ(kHello, buffer);
@@ -178,28 +189,40 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) {
// Write a message to |h0| (attaching nothing).
const char kHello[] = "hello";
- EXPECT_EQ(
- MOJO_RESULT_OK,
- MojoWriteMessage(h0, kHello, static_cast<uint32_t>(sizeof(kHello)),
- nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoWriteMessage(h0,
+ kHello,
+ static_cast<uint32_t>(sizeof(kHello)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Write one message to |server_mp|, attaching |h1|.
const char kWorld[] = "world!!!";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(server_mp, kWorld,
- static_cast<uint32_t>(sizeof(kWorld)), &h1, 1,
+ MojoWriteMessage(server_mp,
+ kWorld,
+ static_cast<uint32_t>(sizeof(kWorld)),
+ &h1,
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
h1 = MOJO_HANDLE_INVALID;
// Write another message to |h0|.
const char kFoo[] = "foo";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(h0, kFoo, static_cast<uint32_t>(sizeof(kFoo)),
- nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ MojoWriteMessage(h0,
+ kFoo,
+ static_cast<uint32_t>(sizeof(kFoo)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Wait for |client_mp| to become readable.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(
+ client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
// Read a message from |client_mp|.
char buffer[1000] = {};
@@ -207,8 +230,12 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) {
MojoHandle handles[10] = {};
uint32_t num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(client_mp, buffer, &num_bytes, handles,
- &num_handles, MOJO_READ_MESSAGE_FLAG_NONE));
+ MojoReadMessage(client_mp,
+ buffer,
+ &num_bytes,
+ handles,
+ &num_handles,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kWorld), num_bytes);
EXPECT_STREQ(kWorld, buffer);
EXPECT_EQ(1u, num_handles);
@@ -216,8 +243,9 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) {
h1 = handles[0];
// Wait for |h1| to become readable.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
// Read a message from |h1|.
memset(buffer, 0, sizeof(buffer));
@@ -225,41 +253,58 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) {
memset(handles, 0, sizeof(handles));
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(h1, buffer, &num_bytes, handles, &num_handles,
+ MojoReadMessage(h1,
+ buffer,
+ &num_bytes,
+ handles,
+ &num_handles,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), num_bytes);
EXPECT_STREQ(kHello, buffer);
EXPECT_EQ(0u, num_handles);
// Wait for |h1| to become readable (again).
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(h1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
// Read the second message from |h1|.
memset(buffer, 0, sizeof(buffer));
num_bytes = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(h1, buffer, &num_bytes, nullptr, nullptr,
+ MojoReadMessage(h1,
+ buffer,
+ &num_bytes,
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kFoo), num_bytes);
EXPECT_STREQ(kFoo, buffer);
// Write a message to |h1|.
const char kBarBaz[] = "barbaz";
- EXPECT_EQ(
- MOJO_RESULT_OK,
- MojoWriteMessage(h1, kBarBaz, static_cast<uint32_t>(sizeof(kBarBaz)),
- nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoWriteMessage(h1,
+ kBarBaz,
+ static_cast<uint32_t>(sizeof(kBarBaz)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Wait for |h0| to become readable.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(h0, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
// Read a message from |h0|.
memset(buffer, 0, sizeof(buffer));
num_bytes = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(h0, buffer, &num_bytes, nullptr, nullptr,
+ MojoReadMessage(h0,
+ buffer,
+ &num_bytes,
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kBarBaz), num_bytes);
EXPECT_STREQ(kBarBaz, buffer);
@@ -309,20 +354,29 @@ TEST_F(EmbedderTest, MultiprocessChannels) {
// 1. Write a message to |server_mp| (attaching nothing).
const char kHello[] = "hello";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(server_mp, kHello,
- static_cast<uint32_t>(sizeof(kHello)), nullptr,
- 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ MojoWriteMessage(server_mp,
+ kHello,
+ static_cast<uint32_t>(sizeof(kHello)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// TODO(vtl): If the scope were ended immediately here (maybe after closing
// |server_mp|), we die with a fatal error in |Channel::HandleLocalError()|.
// 2. Read a message from |server_mp|.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(server_mp, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(
+ server_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
char buffer[1000] = {};
uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(server_mp, buffer, &num_bytes, nullptr, nullptr,
+ MojoReadMessage(server_mp,
+ buffer,
+ &num_bytes,
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
const char kWorld[] = "world!";
EXPECT_EQ(sizeof(kWorld), num_bytes);
@@ -335,29 +389,41 @@ TEST_F(EmbedderTest, MultiprocessChannels) {
// 3. Write something to |mp0|.
const char kFoo[] = "FOO";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(mp0, kFoo, static_cast<uint32_t>(sizeof(kFoo)),
- nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ MojoWriteMessage(mp0,
+ kFoo,
+ static_cast<uint32_t>(sizeof(kFoo)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// 4. Write a message to |server_mp|, attaching |mp1|.
const char kBar[] = "Bar";
- EXPECT_EQ(
- MOJO_RESULT_OK,
- MojoWriteMessage(server_mp, kBar, static_cast<uint32_t>(sizeof(kBar)),
- &mp1, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ MojoWriteMessage(server_mp,
+ kBar,
+ static_cast<uint32_t>(sizeof(kBar)),
+ &mp1,
+ 1,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
mp1 = MOJO_HANDLE_INVALID;
// 5. Close |server_mp|.
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(server_mp));
// 9. Read a message from |mp0|, which should have |mp2| attached.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(mp0, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
memset(buffer, 0, sizeof(buffer));
num_bytes = static_cast<uint32_t>(sizeof(buffer));
MojoHandle mp2 = MOJO_HANDLE_INVALID;
uint32_t num_handles = 1;
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(mp0, buffer, &num_bytes, &mp2, &num_handles,
+ MojoReadMessage(mp0,
+ buffer,
+ &num_bytes,
+ &mp2,
+ &num_handles,
MOJO_READ_MESSAGE_FLAG_NONE));
const char kQuux[] = "quux";
EXPECT_EQ(sizeof(kQuux), num_bytes);
@@ -366,12 +432,17 @@ TEST_F(EmbedderTest, MultiprocessChannels) {
EXPECT_NE(mp2, MOJO_HANDLE_INVALID);
// 7. Read a message from |mp2|.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(mp2, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
memset(buffer, 0, sizeof(buffer));
num_bytes = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(mp2, buffer, &num_bytes, nullptr, nullptr,
+ MojoReadMessage(mp2,
+ buffer,
+ &num_bytes,
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
const char kBaz[] = "baz";
EXPECT_EQ(sizeof(kBaz), num_bytes);
@@ -411,12 +482,18 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
CHECK(client_channel.channel_info() != nullptr);
// 1. Read the first message from |client_mp|.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(
+ client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
char buffer[1000] = {};
uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(client_mp, buffer, &num_bytes, nullptr, nullptr,
+ MojoReadMessage(client_mp,
+ buffer,
+ &num_bytes,
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
const char kHello[] = "hello";
EXPECT_EQ(sizeof(kHello), num_bytes);
@@ -425,13 +502,18 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
// 2. Write a message to |client_mp| (attaching nothing).
const char kWorld[] = "world!";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(client_mp, kWorld,
- static_cast<uint32_t>(sizeof(kWorld)), nullptr,
- 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ MojoWriteMessage(client_mp,
+ kWorld,
+ static_cast<uint32_t>(sizeof(kWorld)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// 4. Read a message from |client_mp|, which should have |mp1| attached.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(client_mp, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(
+ client_mp, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
// TODO(vtl): If the scope were to end here (and |client_mp| closed), we'd
// die (again due to |Channel::HandleLocalError()|).
memset(buffer, 0, sizeof(buffer));
@@ -439,7 +521,11 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
MojoHandle mp1 = MOJO_HANDLE_INVALID;
uint32_t num_handles = 1;
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(client_mp, buffer, &num_bytes, &mp1, &num_handles,
+ MojoReadMessage(client_mp,
+ buffer,
+ &num_bytes,
+ &mp1,
+ &num_handles,
MOJO_READ_MESSAGE_FLAG_NONE));
const char kBar[] = "Bar";
EXPECT_EQ(sizeof(kBar), num_bytes);
@@ -460,8 +546,12 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
// 7. Write a message to |mp3|.
const char kBaz[] = "baz";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(mp3, kBaz, static_cast<uint32_t>(sizeof(kBaz)),
- nullptr, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ MojoWriteMessage(mp3,
+ kBaz,
+ static_cast<uint32_t>(sizeof(kBaz)),
+ nullptr,
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// 8. Close |mp3|.
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(mp3));
@@ -469,17 +559,26 @@ MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessChannelsClient) {
// 9. Write a message to |mp1|, attaching |mp2|.
const char kQuux[] = "quux";
EXPECT_EQ(MOJO_RESULT_OK,
- MojoWriteMessage(mp1, kQuux, static_cast<uint32_t>(sizeof(kQuux)),
- &mp2, 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ MojoWriteMessage(mp1,
+ kQuux,
+ static_cast<uint32_t>(sizeof(kQuux)),
+ &mp2,
+ 1,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
mp2 = MOJO_HANDLE_INVALID;
// 3. Read a message from |mp1|.
- EXPECT_EQ(MOJO_RESULT_OK, MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ MojoWait(mp1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
memset(buffer, 0, sizeof(buffer));
num_bytes = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- MojoReadMessage(mp1, buffer, &num_bytes, nullptr, nullptr,
+ MojoReadMessage(mp1,
+ buffer,
+ &num_bytes,
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
const char kFoo[] = "FOO";
EXPECT_EQ(sizeof(kFoo), num_bytes);
diff --git a/mojo/edk/embedder/platform_channel_pair_posix.cc b/mojo/edk/embedder/platform_channel_pair_posix.cc
index 2242cce..f9886b5 100644
--- a/mojo/edk/embedder/platform_channel_pair_posix.cc
+++ b/mojo/edk/embedder/platform_channel_pair_posix.cc
@@ -46,10 +46,14 @@ PlatformChannelPair::PlatformChannelPair() {
// fail with |EPIPE| instead). On Linux, we have to use |send...()| with
// |MSG_NOSIGNAL| -- which is not supported on Mac -- instead.
int no_sigpipe = 1;
- PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe,
- sizeof(no_sigpipe)) == 0);
- PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe,
- sizeof(no_sigpipe)) == 0);
+ PCHECK(
+ setsockopt(
+ fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, sizeof(no_sigpipe)) ==
+ 0);
+ PCHECK(
+ setsockopt(
+ fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, sizeof(no_sigpipe)) ==
+ 0);
#endif // defined(OS_MACOSX)
server_handle_.reset(PlatformHandle(fds[0]));
diff --git a/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc b/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc
index c3b1ef1..926bbc5 100644
--- a/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc
+++ b/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc
@@ -112,15 +112,15 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveData) {
std::string send_string(1 << i, 'A' + i);
EXPECT_EQ(static_cast<ssize_t>(send_string.size()),
- PlatformChannelWrite(server_handle.get(), send_string.data(),
- send_string.size()));
+ PlatformChannelWrite(
+ server_handle.get(), send_string.data(), send_string.size()));
WaitReadable(client_handle.get());
char buf[10000] = {};
std::deque<PlatformHandle> received_handles;
- ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf,
- sizeof(buf), &received_handles);
+ ssize_t result = PlatformChannelRecvmsg(
+ client_handle.get(), buf, sizeof(buf), &received_handles);
EXPECT_EQ(static_cast<ssize_t>(send_string.size()), result);
EXPECT_EQ(send_string, std::string(buf, static_cast<size_t>(result)));
EXPECT_TRUE(received_handles.empty());
@@ -155,7 +155,9 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) {
struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)};
// We assume that the |sendmsg()| actually sends all the data.
EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
- PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1,
+ PlatformChannelSendmsgWithHandles(server_handle.get(),
+ &iov,
+ 1,
&platform_handles[0],
platform_handles.size()));
@@ -165,8 +167,8 @@ TEST_F(PlatformChannelPairPosixTest, SendReceiveFDs) {
std::deque<PlatformHandle> received_handles;
// We assume that the |recvmsg()| actually reads all the data.
EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
- PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf),
- &received_handles));
+ PlatformChannelRecvmsg(
+ client_handle.get(), buf, sizeof(buf), &received_handles));
EXPECT_STREQ(kHello, buf);
EXPECT_EQ(i, received_handles.size());
@@ -212,7 +214,9 @@ TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) {
struct iovec iov = {const_cast<char*>(kHello), sizeof(kHello)};
// We assume that the |sendmsg()| actually sends all the data.
EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
- PlatformChannelSendmsgWithHandles(server_handle.get(), &iov, 1,
+ PlatformChannelSendmsgWithHandles(server_handle.get(),
+ &iov,
+ 1,
&platform_handles[0],
platform_handles.size()));
}
@@ -226,8 +230,8 @@ TEST_F(PlatformChannelPairPosixTest, AppendReceivedFDs) {
char buf[100] = {};
// We assume that the |recvmsg()| actually reads all the data.
EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
- PlatformChannelRecvmsg(client_handle.get(), buf, sizeof(buf),
- &received_handles));
+ PlatformChannelRecvmsg(
+ client_handle.get(), buf, sizeof(buf), &received_handles));
EXPECT_STREQ(kHello, buf);
ASSERT_EQ(2u, received_handles.size());
EXPECT_FALSE(received_handles[0].is_valid());
diff --git a/mojo/edk/embedder/platform_channel_pair_win.cc b/mojo/edk/embedder/platform_channel_pair_win.cc
index 25306a6..4804eed 100644
--- a/mojo/edk/embedder/platform_channel_pair_win.cc
+++ b/mojo/edk/embedder/platform_channel_pair_win.cc
@@ -23,7 +23,8 @@ namespace {
std::wstring GeneratePipeName() {
return base::StringPrintf(L"\\\\.\\pipe\\mojo.%u.%u.%I64u",
- GetCurrentProcessId(), GetCurrentThreadId(),
+ GetCurrentProcessId(),
+ GetCurrentThreadId(),
base::RandUint64());
}
@@ -36,7 +37,9 @@ PlatformChannelPair::PlatformChannelPair() {
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE;
const DWORD kPipeMode = PIPE_TYPE_BYTE | PIPE_READMODE_BYTE;
server_handle_.reset(PlatformHandle(
- CreateNamedPipeW(pipe_name.c_str(), kOpenMode, kPipeMode,
+ CreateNamedPipeW(pipe_name.c_str(),
+ kOpenMode,
+ kPipeMode,
1, // Max instances.
4096, // Out buffer size.
4096, // In buffer size.
@@ -53,9 +56,12 @@ PlatformChannelPair::PlatformChannelPair() {
SECURITY_ATTRIBUTES security_attributes = {
sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE};
client_handle_.reset(
- PlatformHandle(CreateFileW(pipe_name.c_str(), kDesiredAccess,
+ PlatformHandle(CreateFileW(pipe_name.c_str(),
+ kDesiredAccess,
0, // No sharing.
- &security_attributes, OPEN_EXISTING, kFlags,
+ &security_attributes,
+ OPEN_EXISTING,
+ kFlags,
nullptr))); // No template file.
PCHECK(client_handle_.is_valid());
diff --git a/mojo/edk/embedder/platform_channel_utils_posix.h b/mojo/edk/embedder/platform_channel_utils_posix.h
index 34efcad..87176fb 100644
--- a/mojo/edk/embedder/platform_channel_utils_posix.h
+++ b/mojo/edk/embedder/platform_channel_utils_posix.h
@@ -30,9 +30,9 @@ const size_t kPlatformChannelMaxNumHandles = 7;
// never raise |SIGPIPE|. (Note: On Mac, the suppression of |SIGPIPE| is set up
// by |PlatformChannelPair|.)
MOJO_SYSTEM_IMPL_EXPORT ssize_t
-PlatformChannelWrite(PlatformHandle h, const void* bytes, size_t num_bytes);
+ PlatformChannelWrite(PlatformHandle h, const void* bytes, size_t num_bytes);
MOJO_SYSTEM_IMPL_EXPORT ssize_t
-PlatformChannelWritev(PlatformHandle h, struct iovec* iov, size_t num_iov);
+ PlatformChannelWritev(PlatformHandle h, struct iovec* iov, size_t num_iov);
// Writes data, and the given set of |PlatformHandle|s (i.e., file descriptors)
// over the Unix domain socket given by |h| (e.g., created using
@@ -43,11 +43,11 @@ PlatformChannelWritev(PlatformHandle h, struct iovec* iov, size_t num_iov);
// specified by |iov|). (The handles are not closed, regardless of success or
// failure.)
MOJO_SYSTEM_IMPL_EXPORT ssize_t
-PlatformChannelSendmsgWithHandles(PlatformHandle h,
- struct iovec* iov,
- size_t num_iov,
- PlatformHandle* platform_handles,
- size_t num_platform_handles);
+ PlatformChannelSendmsgWithHandles(PlatformHandle h,
+ struct iovec* iov,
+ size_t num_iov,
+ PlatformHandle* platform_handles,
+ size_t num_platform_handles);
// TODO(vtl): Remove this once I've switched things over to
// |PlatformChannelSendmsgWithHandles()|.
@@ -65,10 +65,10 @@ MOJO_SYSTEM_IMPL_EXPORT bool PlatformChannelSendHandles(PlatformHandle h,
// (in the control message) to |PlatformHandle|s (and append them to
// |platform_handles|). (This also handles |EINTR|.)
MOJO_SYSTEM_IMPL_EXPORT ssize_t
-PlatformChannelRecvmsg(PlatformHandle h,
- void* buf,
- size_t num_bytes,
- std::deque<PlatformHandle>* platform_handles);
+ PlatformChannelRecvmsg(PlatformHandle h,
+ void* buf,
+ size_t num_bytes,
+ std::deque<PlatformHandle>* platform_handles);
} // namespace embedder
} // namespace mojo
diff --git a/mojo/edk/embedder/platform_handle_utils.h b/mojo/edk/embedder/platform_handle_utils.h
index b3d7a79..f594e21 100644
--- a/mojo/edk/embedder/platform_handle_utils.h
+++ b/mojo/edk/embedder/platform_handle_utils.h
@@ -18,14 +18,15 @@ MOJO_SYSTEM_IMPL_EXPORT inline void CloseAllPlatformHandles(
PlatformHandleContainer* platform_handles) {
for (typename PlatformHandleContainer::iterator it =
platform_handles->begin();
- it != platform_handles->end(); ++it)
+ it != platform_handles->end();
+ ++it)
it->CloseIfNecessary();
}
// Duplicates the given |PlatformHandle| (which must be valid). (Returns an
// invalid |ScopedPlatformHandle| on failure.)
MOJO_SYSTEM_IMPL_EXPORT ScopedPlatformHandle
-DuplicatePlatformHandle(PlatformHandle platform_handle);
+ DuplicatePlatformHandle(PlatformHandle platform_handle);
} // namespace embedder
} // namespace mojo
diff --git a/mojo/edk/embedder/platform_handle_utils_win.cc b/mojo/edk/embedder/platform_handle_utils_win.cc
index 43d1331..12745d0 100644
--- a/mojo/edk/embedder/platform_handle_utils_win.cc
+++ b/mojo/edk/embedder/platform_handle_utils_win.cc
@@ -15,8 +15,12 @@ ScopedPlatformHandle DuplicatePlatformHandle(PlatformHandle platform_handle) {
DCHECK(platform_handle.is_valid());
HANDLE new_handle;
- if (!DuplicateHandle(GetCurrentProcess(), platform_handle.handle,
- GetCurrentProcess(), &new_handle, 0, TRUE,
+ if (!DuplicateHandle(GetCurrentProcess(),
+ platform_handle.handle,
+ GetCurrentProcess(),
+ &new_handle,
+ 0,
+ TRUE,
DUPLICATE_SAME_ACCESS))
return ScopedPlatformHandle();
DCHECK_NE(new_handle, INVALID_HANDLE_VALUE);
diff --git a/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc b/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc
index 8dfcf44..ebb55ee 100644
--- a/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc
+++ b/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc
@@ -127,9 +127,12 @@ scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::MapImpl(
DCHECK_LE(static_cast<uint64_t>(real_offset),
static_cast<uint64_t>(std::numeric_limits<off_t>::max()));
- void* real_base =
- mmap(nullptr, real_length, PROT_READ | PROT_WRITE, MAP_SHARED,
- handle_.get().fd, static_cast<off_t>(real_offset));
+ void* real_base = mmap(nullptr,
+ real_length,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ handle_.get().fd,
+ static_cast<off_t>(real_offset));
// |mmap()| should return |MAP_FAILED| (a.k.a. -1) on error. But it shouldn't
// return null either.
if (real_base == MAP_FAILED || !real_base) {
diff --git a/mojo/edk/embedder/simple_platform_shared_buffer_win.cc b/mojo/edk/embedder/simple_platform_shared_buffer_win.cc
index 0737465..fd3de83 100644
--- a/mojo/edk/embedder/simple_platform_shared_buffer_win.cc
+++ b/mojo/edk/embedder/simple_platform_shared_buffer_win.cc
@@ -33,9 +33,12 @@ bool SimplePlatformSharedBuffer::Init() {
// TODO(vtl): Unlike |base::SharedMemory|, we don't round up the size (to a
// multiple of 64 KB). This may cause problems with NaCl. Cross this bridge
// when we get there. crbug.com/210609
- handle_.reset(PlatformHandle(
- CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0,
- static_cast<DWORD>(num_bytes_), nullptr)));
+ handle_.reset(PlatformHandle(CreateFileMapping(INVALID_HANDLE_VALUE,
+ nullptr,
+ PAGE_READWRITE,
+ 0,
+ static_cast<DWORD>(num_bytes_),
+ nullptr)));
if (!handle_.is_valid()) {
PLOG(ERROR) << "CreateFileMapping";
return false;
@@ -65,9 +68,11 @@ scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::MapImpl(
DCHECK_LE(static_cast<uint64_t>(real_offset),
static_cast<uint64_t>(std::numeric_limits<DWORD>::max()));
- void* real_base =
- MapViewOfFile(handle_.get().handle, FILE_MAP_READ | FILE_MAP_WRITE, 0,
- static_cast<DWORD>(real_offset), real_length);
+ void* real_base = MapViewOfFile(handle_.get().handle,
+ FILE_MAP_READ | FILE_MAP_WRITE,
+ 0,
+ static_cast<DWORD>(real_offset),
+ real_length);
if (!real_base) {
PLOG(ERROR) << "MapViewOfFile";
return nullptr;
diff --git a/mojo/edk/embedder/test_embedder.cc b/mojo/edk/embedder/test_embedder.cc
index 1eca9c826..95d3be6 100644
--- a/mojo/edk/embedder/test_embedder.cc
+++ b/mojo/edk/embedder/test_embedder.cc
@@ -8,9 +8,9 @@
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "mojo/edk/embedder/embedder.h"
-#include "mojo/edk/embedder/embedder_internal.h"
#include "mojo/edk/embedder/simple_platform_support.h"
#include "mojo/edk/system/core.h"
+#include "mojo/edk/system/entrypoints.h"
#include "mojo/edk/system/handle_table.h"
namespace mojo {
@@ -18,17 +18,18 @@ namespace mojo {
namespace system {
namespace internal {
-bool ShutdownCheckNoLeaks(Core* core) {
+bool ShutdownCheckNoLeaks(Core* core_impl) {
// No point in taking the lock.
const HandleTable::HandleToEntryMap& handle_to_entry_map =
- core->handle_table_.handle_to_entry_map_;
+ core_impl->handle_table_.handle_to_entry_map_;
if (handle_to_entry_map.empty())
return true;
for (HandleTable::HandleToEntryMap::const_iterator it =
handle_to_entry_map.begin();
- it != handle_to_entry_map.end(); ++it) {
+ it != handle_to_entry_map.end();
+ ++it) {
LOG(ERROR) << "Mojo embedder shutdown: Leaking handle " << (*it).first;
}
return false;
@@ -45,9 +46,9 @@ void InitWithSimplePlatformSupport() {
}
bool Shutdown() {
- system::Core* core = internal::g_core;
+ system::Core* core = system::entrypoints::GetCore();
CHECK(core);
- internal::g_core = nullptr;
+ system::entrypoints::SetCore(nullptr);
bool rv = system::internal::ShutdownCheckNoLeaks(core);
delete core;
diff --git a/mojo/edk/js/BUILD.gn b/mojo/edk/js/BUILD.gn
index e652b80..b8d60ec 100644
--- a/mojo/edk/js/BUILD.gn
+++ b/mojo/edk/js/BUILD.gn
@@ -11,12 +11,8 @@ source_set("js") {
"handle.cc",
"handle.h",
"handle_close_observer.h",
- "mojo_runner_delegate.cc",
- "mojo_runner_delegate.h",
"support.cc",
"support.h",
- "threading.cc",
- "threading.h",
"waiting_callback.cc",
"waiting_callback.h",
]
@@ -26,24 +22,15 @@ source_set("js") {
"//gin",
"//v8",
]
-
- deps = [
- "//mojo/public/cpp/environment",
- "//mojo/public/cpp/system",
- ]
}
source_set("js_unittests") {
testonly = true
- sources = [
- "handle_unittest.cc",
- ]
-
deps = [
- "//mojo/edk/js",
"//mojo/edk/test:test_support",
- "//mojo/public/cpp/system",
- "//testing/gtest",
]
+ sources = [
+ "handle_unittest.cc",
+ ]
}
diff --git a/mojo/edk/js/DEPS b/mojo/edk/js/DEPS
index c350edf..d974b68 100644
--- a/mojo/edk/js/DEPS
+++ b/mojo/edk/js/DEPS
@@ -1,5 +1,4 @@
include_rules = [
- "+base",
"+gin",
"+v8",
]
diff --git a/mojo/edk/js/core.cc b/mojo/edk/js/core.cc
index 232f0e3..91a746c 100644
--- a/mojo/edk/js/core.cc
+++ b/mojo/edk/js/core.cc
@@ -247,73 +247,69 @@ v8::Local<v8::Value> Core::GetModule(v8::Isolate* isolate) {
&g_wrapper_info);
if (templ.IsEmpty()) {
- templ =
- gin::ObjectTemplateBuilder(isolate)
- // TODO(mpcomplete): Should these just be methods on the JS Handle
- // object?
- .SetMethod("close", CloseHandle)
- .SetMethod("wait", WaitHandle)
- .SetMethod("waitMany", WaitMany)
- .SetMethod("createMessagePipe", CreateMessagePipe)
- .SetMethod("writeMessage", WriteMessage)
- .SetMethod("readMessage", ReadMessage)
- .SetMethod("createDataPipe", CreateDataPipe)
- .SetMethod("writeData", WriteData)
- .SetMethod("readData", ReadData)
- .SetMethod("drainData", DoDrainData)
-
- .SetValue("RESULT_OK", MOJO_RESULT_OK)
- .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
- .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN)
- .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT)
- .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED)
- .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND)
- .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS)
- .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED)
- .SetValue("RESULT_RESOURCE_EXHAUSTED",
- MOJO_RESULT_RESOURCE_EXHAUSTED)
- .SetValue("RESULT_FAILED_PRECONDITION",
- MOJO_RESULT_FAILED_PRECONDITION)
- .SetValue("RESULT_ABORTED", MOJO_RESULT_ABORTED)
- .SetValue("RESULT_OUT_OF_RANGE", MOJO_RESULT_OUT_OF_RANGE)
- .SetValue("RESULT_UNIMPLEMENTED", MOJO_RESULT_UNIMPLEMENTED)
- .SetValue("RESULT_INTERNAL", MOJO_RESULT_INTERNAL)
- .SetValue("RESULT_UNAVAILABLE", MOJO_RESULT_UNAVAILABLE)
- .SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS)
- .SetValue("RESULT_BUSY", MOJO_RESULT_BUSY)
- .SetValue("RESULT_SHOULD_WAIT", MOJO_RESULT_SHOULD_WAIT)
-
- .SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE)
-
- .SetValue("HANDLE_SIGNAL_NONE", MOJO_HANDLE_SIGNAL_NONE)
- .SetValue("HANDLE_SIGNAL_READABLE", MOJO_HANDLE_SIGNAL_READABLE)
- .SetValue("HANDLE_SIGNAL_WRITABLE", MOJO_HANDLE_SIGNAL_WRITABLE)
-
- .SetValue("CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE",
- MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE)
-
- .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE)
-
- .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE)
- .SetValue("READ_MESSAGE_FLAG_MAY_DISCARD",
- MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)
-
- .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_NONE",
- MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE)
- .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD",
- MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD)
-
- .SetValue("WRITE_DATA_FLAG_NONE", MOJO_WRITE_DATA_FLAG_NONE)
- .SetValue("WRITE_DATA_FLAG_ALL_OR_NONE",
- MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)
-
- .SetValue("READ_DATA_FLAG_NONE", MOJO_READ_DATA_FLAG_NONE)
- .SetValue("READ_DATA_FLAG_ALL_OR_NONE",
- MOJO_READ_DATA_FLAG_ALL_OR_NONE)
- .SetValue("READ_DATA_FLAG_DISCARD", MOJO_READ_DATA_FLAG_DISCARD)
- .SetValue("READ_DATA_FLAG_QUERY", MOJO_READ_DATA_FLAG_QUERY)
- .SetValue("READ_DATA_FLAG_PEEK", MOJO_READ_DATA_FLAG_PEEK)
- .Build();
+ templ = gin::ObjectTemplateBuilder(isolate)
+ // TODO(mpcomplete): Should these just be methods on the JS Handle
+ // object?
+ .SetMethod("close", CloseHandle)
+ .SetMethod("wait", WaitHandle)
+ .SetMethod("waitMany", WaitMany)
+ .SetMethod("createMessagePipe", CreateMessagePipe)
+ .SetMethod("writeMessage", WriteMessage)
+ .SetMethod("readMessage", ReadMessage)
+ .SetMethod("createDataPipe", CreateDataPipe)
+ .SetMethod("writeData", WriteData)
+ .SetMethod("readData", ReadData)
+ .SetMethod("drainData", DoDrainData)
+
+ .SetValue("RESULT_OK", MOJO_RESULT_OK)
+ .SetValue("RESULT_CANCELLED", MOJO_RESULT_CANCELLED)
+ .SetValue("RESULT_UNKNOWN", MOJO_RESULT_UNKNOWN)
+ .SetValue("RESULT_INVALID_ARGUMENT", MOJO_RESULT_INVALID_ARGUMENT)
+ .SetValue("RESULT_DEADLINE_EXCEEDED", MOJO_RESULT_DEADLINE_EXCEEDED)
+ .SetValue("RESULT_NOT_FOUND", MOJO_RESULT_NOT_FOUND)
+ .SetValue("RESULT_ALREADY_EXISTS", MOJO_RESULT_ALREADY_EXISTS)
+ .SetValue("RESULT_PERMISSION_DENIED", MOJO_RESULT_PERMISSION_DENIED)
+ .SetValue("RESULT_RESOURCE_EXHAUSTED", MOJO_RESULT_RESOURCE_EXHAUSTED)
+ .SetValue("RESULT_FAILED_PRECONDITION", MOJO_RESULT_FAILED_PRECONDITION)
+ .SetValue("RESULT_ABORTED", MOJO_RESULT_ABORTED)
+ .SetValue("RESULT_OUT_OF_RANGE", MOJO_RESULT_OUT_OF_RANGE)
+ .SetValue("RESULT_UNIMPLEMENTED", MOJO_RESULT_UNIMPLEMENTED)
+ .SetValue("RESULT_INTERNAL", MOJO_RESULT_INTERNAL)
+ .SetValue("RESULT_UNAVAILABLE", MOJO_RESULT_UNAVAILABLE)
+ .SetValue("RESULT_DATA_LOSS", MOJO_RESULT_DATA_LOSS)
+ .SetValue("RESULT_BUSY", MOJO_RESULT_BUSY)
+ .SetValue("RESULT_SHOULD_WAIT", MOJO_RESULT_SHOULD_WAIT)
+
+ .SetValue("DEADLINE_INDEFINITE", MOJO_DEADLINE_INDEFINITE)
+
+ .SetValue("HANDLE_SIGNAL_NONE", MOJO_HANDLE_SIGNAL_NONE)
+ .SetValue("HANDLE_SIGNAL_READABLE", MOJO_HANDLE_SIGNAL_READABLE)
+ .SetValue("HANDLE_SIGNAL_WRITABLE", MOJO_HANDLE_SIGNAL_WRITABLE)
+
+ .SetValue("CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE",
+ MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE)
+
+ .SetValue("WRITE_MESSAGE_FLAG_NONE", MOJO_WRITE_MESSAGE_FLAG_NONE)
+
+ .SetValue("READ_MESSAGE_FLAG_NONE", MOJO_READ_MESSAGE_FLAG_NONE)
+ .SetValue("READ_MESSAGE_FLAG_MAY_DISCARD",
+ MOJO_READ_MESSAGE_FLAG_MAY_DISCARD)
+
+ .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_NONE",
+ MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE)
+ .SetValue("CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD",
+ MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD)
+
+ .SetValue("WRITE_DATA_FLAG_NONE", MOJO_WRITE_DATA_FLAG_NONE)
+ .SetValue("WRITE_DATA_FLAG_ALL_OR_NONE",
+ MOJO_WRITE_DATA_FLAG_ALL_OR_NONE)
+
+ .SetValue("READ_DATA_FLAG_NONE", MOJO_READ_DATA_FLAG_NONE)
+ .SetValue("READ_DATA_FLAG_ALL_OR_NONE",
+ MOJO_READ_DATA_FLAG_ALL_OR_NONE)
+ .SetValue("READ_DATA_FLAG_DISCARD", MOJO_READ_DATA_FLAG_DISCARD)
+ .SetValue("READ_DATA_FLAG_QUERY", MOJO_READ_DATA_FLAG_QUERY)
+ .Build();
data->SetObjectTemplate(&g_wrapper_info, templ);
}
diff --git a/mojo/edk/js/core.h b/mojo/edk/js/core.h
index 445fb00..bde327c 100644
--- a/mojo/edk/js/core.h
+++ b/mojo/edk/js/core.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_EDK_JS_CORE_H_
-#define MOJO_EDK_JS_CORE_H_
+#ifndef MOJO_BINDINGS_JS_CORE_H_
+#define MOJO_BINDINGS_JS_CORE_H_
#include "v8/include/v8.h"
@@ -19,4 +19,4 @@ class Core {
} // namespace js
} // namespace mojo
-#endif // MOJO_EDK_JS_CORE_H_
+#endif // MOJO_BINDINGS_JS_CORE_H_
diff --git a/mojo/edk/js/drain_data.h b/mojo/edk/js/drain_data.h
index 48f1de2..27d8f52 100644
--- a/mojo/edk/js/drain_data.h
+++ b/mojo/edk/js/drain_data.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_EDK_JS_DRAIN_DATA_H_
-#define MOJO_EDK_JS_DRAIN_DATA_H_
+#ifndef MOJO_BINDINGS_JS_DRAIN_DATA_H_
+#define MOJO_BINDINGS_JS_DRAIN_DATA_H_
#include "base/memory/scoped_vector.h"
#include "gin/runner.h"
@@ -61,4 +61,4 @@ class DrainData {
} // namespace js
} // namespace mojo
-#endif // MOJO_EDK_JS_DRAIN_DATA_H_
+#endif // MOJO_BINDINGS_JS_DRAIN_DATA_H_
diff --git a/mojo/edk/js/handle.cc b/mojo/edk/js/handle.cc
index de8f338..ae3415f 100644
--- a/mojo/edk/js/handle.cc
+++ b/mojo/edk/js/handle.cc
@@ -4,6 +4,7 @@
#include "mojo/edk/js/handle.h"
+#include <sstream>
#include "mojo/edk/js/handle_close_observer.h"
namespace mojo {
@@ -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();
diff --git a/mojo/edk/js/handle.h b/mojo/edk/js/handle.h
index 200b322..e363b7c 100644
--- a/mojo/edk/js/handle.h
+++ b/mojo/edk/js/handle.h
@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_EDK_JS_HANDLE_H_
-#define MOJO_EDK_JS_HANDLE_H_
+#ifndef MOJO_BINDINGS_JS_HANDLE_H_
+#define MOJO_BINDINGS_JS_HANDLE_H_
#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();
@@ -95,4 +101,4 @@ struct Converter<gin::Handle<mojo::js::HandleWrapper> > {
} // namespace gin
-#endif // MOJO_EDK_JS_HANDLE_H_
+#endif // MOJO_BINDINGS_JS_HANDLE_H_
diff --git a/mojo/edk/js/handle_close_observer.h b/mojo/edk/js/handle_close_observer.h
index 3e537fd..8f19466 100644
--- a/mojo/edk/js/handle_close_observer.h
+++ b/mojo/edk/js/handle_close_observer.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_EDK_JS_HANDLE_CLOSE_OBSERVER_H_
-#define MOJO_EDK_JS_HANDLE_CLOSE_OBSERVER_H_
+#ifndef MOJO_BINDINGS_JS_HANDLE_CLOSE_OBSERVER_H_
+#define MOJO_BINDINGS_JS_HANDLE_CLOSE_OBSERVER_H_
namespace mojo {
namespace js {
@@ -19,4 +19,4 @@ class HandleCloseObserver {
} // namespace js
} // namespace mojo
-#endif // MOJO_EDK_JS_HANDLE_CLOSE_OBSERVER_H_
+#endif // MOJO_BINDINGS_JS_HANDLE_CLOSE_OBSERVER_H_
diff --git a/mojo/edk/js/mojo_runner_delegate.cc b/mojo/edk/js/mojo_runner_delegate.cc
deleted file mode 100644
index 152b12c..0000000
--- a/mojo/edk/js/mojo_runner_delegate.cc
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2013 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/js/mojo_runner_delegate.h"
-
-#include "base/bind.h"
-#include "base/path_service.h"
-#include "gin/converter.h"
-#include "gin/modules/console.h"
-#include "gin/modules/module_registry.h"
-#include "gin/modules/timer.h"
-#include "gin/try_catch.h"
-#include "mojo/edk/js/core.h"
-#include "mojo/edk/js/handle.h"
-#include "mojo/edk/js/support.h"
-#include "mojo/edk/js/threading.h"
-
-namespace mojo {
-namespace js {
-
-namespace {
-
-// TODO(abarth): Rather than loading these modules from the file system, we
-// should load them from the network via Mojo IPC.
-std::vector<base::FilePath> GetModuleSearchPaths() {
- std::vector<base::FilePath> search_paths(2);
- PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]);
- PathService::Get(base::DIR_EXE, &search_paths[1]);
- search_paths[1] = search_paths[1].AppendASCII("gen");
- return search_paths;
-}
-
-void StartCallback(base::WeakPtr<gin::Runner> runner,
- MojoHandle pipe,
- v8::Handle<v8::Value> module) {
- v8::Isolate* isolate = runner->GetContextHolder()->isolate();
- v8::Handle<v8::Function> start;
- CHECK(gin::ConvertFromV8(isolate, module, &start));
-
- v8::Handle<v8::Value> args[] = {
- gin::ConvertToV8(isolate, Handle(pipe)) };
- runner->Call(start, runner->global(), 1, args);
-}
-
-} // namespace
-
-MojoRunnerDelegate::MojoRunnerDelegate()
- : ModuleRunnerDelegate(GetModuleSearchPaths()) {
- AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
- AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
- AddBuiltinModule(js::Core::kModuleName, js::Core::GetModule);
- AddBuiltinModule(js::Support::kModuleName, js::Support::GetModule);
- AddBuiltinModule(js::Threading::kModuleName, js::Threading::GetModule);
-}
-
-MojoRunnerDelegate::~MojoRunnerDelegate() {
-}
-
-void MojoRunnerDelegate::Start(gin::Runner* runner,
- MojoHandle pipe,
- const std::string& module) {
- gin::Runner::Scope scope(runner);
- gin::ModuleRegistry* registry =
- gin::ModuleRegistry::From(runner->GetContextHolder()->context());
- registry->LoadModule(runner->GetContextHolder()->isolate(), module,
- base::Bind(StartCallback, runner->GetWeakPtr(), pipe));
- AttemptToLoadMoreModules(runner);
-}
-
-void MojoRunnerDelegate::UnhandledException(gin::ShellRunner* runner,
- gin::TryCatch& try_catch) {
- gin::ModuleRunnerDelegate::UnhandledException(runner, try_catch);
- LOG(ERROR) << try_catch.GetStackTrace();
-}
-
-} // namespace js
-} // namespace mojo
diff --git a/mojo/edk/js/mojo_runner_delegate.h b/mojo/edk/js/mojo_runner_delegate.h
deleted file mode 100644
index 423eefb..0000000
--- a/mojo/edk/js/mojo_runner_delegate.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2013 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_JS_MOJO_RUNNER_DELEGATE_H_
-#define MOJO_EDK_JS_MOJO_RUNNER_DELEGATE_H_
-
-#include "base/macros.h"
-#include "gin/modules/module_runner_delegate.h"
-#include "mojo/public/c/system/core.h"
-
-namespace mojo {
-namespace js {
-
-class MojoRunnerDelegate : public gin::ModuleRunnerDelegate {
- public:
- MojoRunnerDelegate();
- ~MojoRunnerDelegate() override;
-
- void Start(gin::Runner* runner, MojoHandle pipe, const std::string& module);
-
- private:
- // From ModuleRunnerDelegate:
- void UnhandledException(gin::ShellRunner* runner,
- gin::TryCatch& try_catch) override;
-
- DISALLOW_COPY_AND_ASSIGN(MojoRunnerDelegate);
-};
-
-} // namespace js
-} // namespace mojo
-
-#endif // MOJO_EDK_JS_MOJO_RUNNER_DELEGATE_H_
diff --git a/mojo/edk/js/support.h b/mojo/edk/js/support.h
index b49dd23..0f6eb07c 100644
--- a/mojo/edk/js/support.h
+++ b/mojo/edk/js/support.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_EDK_JS_SUPPORT_H_
-#define MOJO_EDK_JS_SUPPORT_H_
+#ifndef MOJO_BINDINGS_JS_SUPPORT_H_
+#define MOJO_BINDINGS_JS_SUPPORT_H_
#include "v8/include/v8.h"
@@ -19,4 +19,4 @@ class Support {
} // namespace js
} // namespace mojo
-#endif // MOJO_EDK_JS_SUPPORT_H_
+#endif // MOJO_BINDINGS_JS_SUPPORT_H_
diff --git a/mojo/edk/js/test/BUILD.gn b/mojo/edk/js/test/BUILD.gn
deleted file mode 100644
index e63704b..0000000
--- a/mojo/edk/js/test/BUILD.gn
+++ /dev/null
@@ -1,39 +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.
-
-test("js_unittests") {
- deps = [
- "//base",
- "//gin:gin_test",
- "//mojo/edk/js",
- "//mojo/edk/js:js_unittests",
- "//mojo/edk/test:run_all_unittests",
- "//mojo/edk/test:test_support",
- "//mojo/public/cpp/environment",
- "//mojo/public/cpp/system",
- "//mojo/public/cpp/utility",
- "//mojo/environment:chromium",
- "//mojo/public/interfaces/bindings/tests:test_interfaces",
- ]
-
- sources = [ "run_js_tests.cc" ]
-}
-
-test("js_integration_tests") {
- deps = [
- "//base",
- "//gin:gin_test",
- "//mojo/edk/js",
- "//mojo/edk/js/tests:js_to_cpp_tests",
- "//mojo/edk/test:run_all_unittests",
- "//mojo/edk/test:test_support",
- "//mojo/public/cpp/bindings",
- "//mojo/environment:chromium",
- "//mojo/public/interfaces/bindings/tests:test_interfaces",
- ]
-
- sources = [
- "run_js_integration_tests.cc"
- ]
-}
diff --git a/mojo/edk/js/test/hexdump.js b/mojo/edk/js/test/hexdump.js
deleted file mode 100644
index b36c47f..0000000
--- a/mojo/edk/js/test/hexdump.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2013 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.
-
-define(function() {
- function hexify(value, length) {
- var hex = value.toString(16);
- while (hex.length < length)
- hex = "0" + hex;
- return hex;
- }
-
- function dumpArray(bytes) {
- var dumped = "";
- for (var i = 0; i < bytes.length; ++i) {
- dumped += hexify(bytes[i], 2);
-
- if (i % 16 == 15) {
- dumped += "\n";
- continue;
- }
-
- if (i % 2 == 1)
- dumped += " ";
- if (i % 8 == 7)
- dumped += " ";
- }
- return dumped;
- }
-
- var exports = {};
- exports.dumpArray = dumpArray;
- return exports;
-});
diff --git a/mojo/edk/js/test/run_js_integration_tests.cc b/mojo/edk/js/test/run_js_integration_tests.cc
deleted file mode 100644
index 1a6f1d6..0000000
--- a/mojo/edk/js/test/run_js_integration_tests.cc
+++ /dev/null
@@ -1,57 +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 "base/files/file_path.h"
-#include "base/path_service.h"
-#include "gin/modules/console.h"
-#include "gin/modules/module_registry.h"
-#include "gin/modules/timer.h"
-#include "gin/test/file_runner.h"
-#include "gin/test/gtest.h"
-#include "mojo/edk/js/core.h"
-#include "mojo/edk/js/support.h"
-#include "mojo/edk/js/threading.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace js {
-namespace {
-
-class TestRunnerDelegate : public gin::FileRunnerDelegate {
- public:
- TestRunnerDelegate() {
- AddBuiltinModule(gin::Console::kModuleName, gin::Console::GetModule);
- AddBuiltinModule(Core::kModuleName, Core::GetModule);
- AddBuiltinModule(gin::TimerModule::kName, gin::TimerModule::GetModule);
- AddBuiltinModule(Threading::kModuleName, Threading::GetModule);
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(TestRunnerDelegate);
-};
-
-void RunTest(std::string test, bool addSupportModule) {
- base::FilePath path;
- PathService::Get(base::DIR_SOURCE_ROOT, &path);
- path = path.AppendASCII("mojo")
- .AppendASCII("edk")
- .AppendASCII("js")
- .AppendASCII("tests")
- .AppendASCII(test);
- TestRunnerDelegate delegate;
- if (addSupportModule)
- delegate.AddBuiltinModule(Support::kModuleName, Support::GetModule);
- gin::RunTestFromFile(path, &delegate, true);
-}
-
-TEST(JSTest, connection) {
- RunTest("connection_tests.js", false);
-}
-
-TEST(JSTest, sample_service) {
- RunTest("sample_service_tests.js", true);
-}
-
-} // namespace
-} // namespace js
-} // namespace mojo
diff --git a/mojo/edk/js/tests/BUILD.gn b/mojo/edk/js/tests/BUILD.gn
index c61ba37..1555328 100644
--- a/mojo/edk/js/tests/BUILD.gn
+++ b/mojo/edk/js/tests/BUILD.gn
@@ -2,26 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-import("//mojo/public/tools/bindings/mojom.gni")
-
-source_set("js_to_cpp_tests") {
- testonly = true
-
+test("js_unittests") {
deps = [
- ":js_to_cpp_bindings",
"//gin:gin_test",
"//mojo/edk/js",
+ "//mojo/edk/js:js_unittests",
+ "//mojo/edk/test:run_all_unittests",
"//mojo/edk/test:test_support",
- "//mojo/public/cpp/bindings",
- "//mojo/public/cpp/system",
+ "//mojo/public/cpp/environment:standalone",
+ "//mojo/public/cpp/utility",
"//mojo/public/interfaces/bindings/tests:test_interfaces",
]
- sources = [
- "js_to_cpp_tests.cc",
- ]
-}
-
-mojom("js_to_cpp_bindings") {
- sources = [ "js_to_cpp.mojom" ]
+ sources = [ "run_js_tests.cc" ]
}
diff --git a/mojo/edk/js/tests/DEPS b/mojo/edk/js/tests/DEPS
new file mode 100644
index 0000000..190ee62
--- /dev/null
+++ b/mojo/edk/js/tests/DEPS
@@ -0,0 +1,7 @@
+include_rules = [
+ "+base",
+ "+gin",
+ "+v8",
+ "+mojo/edk/js/core.h",
+ "+mojo/edk/js/support.h",
+]
diff --git a/mojo/edk/js/tests/connection_tests.js b/mojo/edk/js/tests/connection_tests.js
deleted file mode 100644
index 6649dfe..0000000
--- a/mojo/edk/js/tests/connection_tests.js
+++ /dev/null
@@ -1,261 +0,0 @@
-// Copyright 2013 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.
-
-// Mock out the support module to avoid depending on the message loop.
-define("mojo/public/js/support", ["timer"], function(timer) {
- var waitingCallbacks = [];
-
- function WaitCookie(id) {
- this.id = id;
- }
-
- function asyncWait(handle, flags, callback) {
- var id = waitingCallbacks.length;
- waitingCallbacks.push(callback);
- return new WaitCookie(id);
- }
-
- function cancelWait(cookie) {
- waitingCallbacks[cookie.id] = null;
- }
-
- function numberOfWaitingCallbacks() {
- var count = 0;
- for (var i = 0; i < waitingCallbacks.length; ++i) {
- if (waitingCallbacks[i])
- ++count;
- }
- return count;
- }
-
- function pumpOnce(result) {
- var callbacks = waitingCallbacks;
- waitingCallbacks = [];
- for (var i = 0; i < callbacks.length; ++i) {
- if (callbacks[i])
- callbacks[i](result);
- }
- }
-
- // Queue up a pumpOnce call to execute after the stack unwinds. Use
- // this to trigger a pump after all Promises are executed.
- function queuePump(result) {
- timer.createOneShot(0, pumpOnce.bind(undefined, result));
- }
-
- var exports = {};
- exports.asyncWait = asyncWait;
- exports.cancelWait = cancelWait;
- exports.numberOfWaitingCallbacks = numberOfWaitingCallbacks;
- exports.pumpOnce = pumpOnce;
- exports.queuePump = queuePump;
- return exports;
-});
-
-define([
- "gin/test/expect",
- "mojo/public/js/support",
- "mojo/public/js/core",
- "mojo/public/js/connection",
- "mojo/public/interfaces/bindings/tests/sample_interfaces.mojom",
- "mojo/public/interfaces/bindings/tests/sample_service.mojom",
- "mojo/public/js/threading",
- "gc",
-], function(expect,
- mockSupport,
- core,
- connection,
- sample_interfaces,
- sample_service,
- threading,
- gc) {
- testClientServer();
- testWriteToClosedPipe();
- testRequestResponse().then(function() {
- this.result = "PASS";
- gc.collectGarbage(); // should not crash
- threading.quit();
- }.bind(this)).catch(function(e) {
- this.result = "FAIL: " + (e.stack || e);
- threading.quit();
- }.bind(this));
-
- function testClientServer() {
- var receivedFrobinate = false;
- var receivedDidFrobinate = false;
-
- // ServiceImpl ------------------------------------------------------------
-
- function ServiceImpl(peer) {
- this.peer = peer;
- }
-
- ServiceImpl.prototype = Object.create(
- sample_service.Service.stubClass.prototype);
-
- ServiceImpl.prototype.frobinate = function(foo, baz, port) {
- receivedFrobinate = true;
-
- expect(foo.name).toBe("Example name");
- expect(baz).toBeTruthy();
- expect(core.close(port)).toBe(core.RESULT_OK);
-
- this.peer.didFrobinate(42);
- };
-
- // ServiceClientImpl ------------------------------------------------------
-
- function ServiceClientImpl(peer) {
- this.peer = peer;
- }
-
- ServiceClientImpl.prototype =
- Object.create(sample_service.ServiceClient.stubClass.prototype);
-
- ServiceClientImpl.prototype.didFrobinate = function(result) {
- receivedDidFrobinate = true;
-
- expect(result).toBe(42);
- };
-
- var pipe = core.createMessagePipe();
- var anotherPipe = core.createMessagePipe();
- var sourcePipe = core.createMessagePipe();
-
- var connection0 = new connection.Connection(
- pipe.handle0, ServiceImpl, sample_service.ServiceClient.proxyClass);
-
- var connection1 = new connection.Connection(
- pipe.handle1, ServiceClientImpl, sample_service.Service.proxyClass);
-
- var foo = new sample_service.Foo();
- foo.bar = new sample_service.Bar();
- foo.name = "Example name";
- foo.source = sourcePipe.handle0;
- connection1.remote.frobinate(foo, true, anotherPipe.handle0);
-
- mockSupport.pumpOnce(core.RESULT_OK);
-
- expect(receivedFrobinate).toBeTruthy();
- expect(receivedDidFrobinate).toBeTruthy();
-
- connection0.close();
- connection1.close();
-
- expect(mockSupport.numberOfWaitingCallbacks()).toBe(0);
-
- // sourcePipe.handle0 was closed automatically when sent over IPC.
- expect(core.close(sourcePipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
- // sourcePipe.handle1 hasn't been closed yet.
- expect(core.close(sourcePipe.handle1)).toBe(core.RESULT_OK);
-
- // anotherPipe.handle0 was closed automatically when sent over IPC.
- expect(core.close(anotherPipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
- // anotherPipe.handle1 hasn't been closed yet.
- expect(core.close(anotherPipe.handle1)).toBe(core.RESULT_OK);
-
- // The Connection object is responsible for closing these handles.
- expect(core.close(pipe.handle0)).toBe(core.RESULT_INVALID_ARGUMENT);
- expect(core.close(pipe.handle1)).toBe(core.RESULT_INVALID_ARGUMENT);
- }
-
- function testWriteToClosedPipe() {
- var pipe = core.createMessagePipe();
-
- var connection1 = new connection.Connection(
- pipe.handle1, function() {}, sample_service.Service.proxyClass);
-
- // Close the other end of the pipe.
- core.close(pipe.handle0);
-
- // Not observed yet because we haven't pumped events yet.
- expect(connection1.encounteredError()).toBeFalsy();
-
- var foo = new sample_service.Foo();
- foo.bar = new sample_service.Bar();
- // TODO(darin): crbug.com/357043: pass null in place of |foo| here.
- connection1.remote.frobinate(foo, true, null);
-
- // Write failures are not reported.
- expect(connection1.encounteredError()).toBeFalsy();
-
- // Pump events, and then we should start observing the closed pipe.
- mockSupport.pumpOnce(core.RESULT_OK);
-
- expect(connection1.encounteredError()).toBeTruthy();
-
- connection1.close();
- }
-
- function testRequestResponse() {
-
- // ProviderImpl ------------------------------------------------------------
-
- function ProviderImpl(peer) {
- this.peer = peer;
- }
-
- ProviderImpl.prototype =
- Object.create(sample_interfaces.Provider.stubClass.prototype);
-
- ProviderImpl.prototype.echoString = function(a) {
- mockSupport.queuePump(core.RESULT_OK);
- return Promise.resolve({a: a});
- };
-
- ProviderImpl.prototype.echoStrings = function(a, b) {
- mockSupport.queuePump(core.RESULT_OK);
- return Promise.resolve({a: a, b: b});
- };
-
- // ProviderClientImpl ------------------------------------------------------
-
- function ProviderClientImpl(peer) {
- this.peer = peer;
- }
-
- ProviderClientImpl.prototype =
- Object.create(sample_interfaces.ProviderClient.stubClass.prototype);
-
- var pipe = core.createMessagePipe();
-
- var connection0 = new connection.Connection(
- pipe.handle0,
- ProviderImpl,
- sample_interfaces.ProviderClient.proxyClass);
-
- var connection1 = new connection.Connection(
- pipe.handle1,
- ProviderClientImpl,
- sample_interfaces.Provider.proxyClass);
-
- var origReadMessage = core.readMessage;
- // echoString
- mockSupport.queuePump(core.RESULT_OK);
- return connection1.remote.echoString("hello").then(function(response) {
- expect(response.a).toBe("hello");
- }).then(function() {
- // echoStrings
- mockSupport.queuePump(core.RESULT_OK);
- return connection1.remote.echoStrings("hello", "world");
- }).then(function(response) {
- expect(response.a).toBe("hello");
- expect(response.b).toBe("world");
- }).then(function() {
- // Mock a read failure, expect it to fail.
- core.readMessage = function() {
- return { result: core.RESULT_UNKNOWN };
- };
- mockSupport.queuePump(core.RESULT_OK);
- return connection1.remote.echoString("goodbye");
- }).then(function() {
- throw Error("Expected echoString to fail.");
- }, function(error) {
- expect(error.message).toBe("Connection error: " + core.RESULT_UNKNOWN);
-
- // Clean up.
- core.readMessage = origReadMessage;
- });
- }
-});
diff --git a/mojo/edk/js/tests/js_to_cpp.mojom b/mojo/edk/js/tests/js_to_cpp.mojom
deleted file mode 100644
index 69f67b6..0000000
--- a/mojo/edk/js/tests/js_to_cpp.mojom
+++ /dev/null
@@ -1,53 +0,0 @@
-module js_to_cpp;
-
-// This struct encompasses all of the basic types, so that they
-// may be sent from C++ to JS and back for validation.
-struct EchoArgs {
- int64 si64;
- int32 si32;
- int16 si16;
- int8 si8;
- uint64 ui64;
- uint32 ui32;
- uint16 ui16;
- uint8 ui8;
- float float_val;
- float float_inf;
- float float_nan;
- double double_val;
- double double_inf;
- double double_nan;
- string? name;
- array<string>? string_array;
- handle<message_pipe>? message_handle;
- handle<data_pipe_consumer>? data_handle;
-};
-
-struct EchoArgsList {
- EchoArgsList? next;
- EchoArgs? item;
-};
-
-// Note: For messages which control test flow, pick numbers that are unlikely
-// to be hit as a result of our deliberate corruption of response messages.
-interface CppSide {
- // Sent for all tests to notify that the JS side is now ready.
- StartTest@88888888();
-
- // Indicates end for echo, bit-flip, and back-pointer tests.
- TestFinished@99999999();
-
- // Responses from specific tests.
- PingResponse();
- EchoResponse(EchoArgsList list);
- BitFlipResponse(EchoArgsList arg);
- BackPointerResponse(EchoArgsList arg);
-};
-
-[Client=CppSide]
-interface JsSide {
- Ping();
- Echo(int32 numIterations, EchoArgs arg);
- BitFlip(EchoArgs arg);
- BackPointer(EchoArgs arg);
-};
diff --git a/mojo/edk/js/tests/js_to_cpp_tests.cc b/mojo/edk/js/tests/js_to_cpp_tests.cc
deleted file mode 100644
index 1da70c2..0000000
--- a/mojo/edk/js/tests/js_to_cpp_tests.cc
+++ /dev/null
@@ -1,418 +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 "base/at_exit.h"
-#include "base/files/file_path.h"
-#include "base/files/file_util.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/strings/utf_string_conversions.h"
-#include "gin/array_buffer.h"
-#include "gin/public/isolate_holder.h"
-#include "mojo/edk/js/mojo_runner_delegate.h"
-#include "mojo/edk/js/tests/js_to_cpp.mojom.h"
-#include "mojo/edk/test/test_utils.h"
-#include "mojo/public/cpp/system/core.h"
-#include "mojo/public/cpp/system/macros.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace js {
-
-// Global value updated by some checks to prevent compilers from optimizing
-// reads out of existence.
-uint32 g_waste_accumulator = 0;
-
-namespace {
-
-// Negative numbers with different values in each byte, the last of
-// which can survive promotion to double and back.
-const int8 kExpectedInt8Value = -65;
-const int16 kExpectedInt16Value = -16961;
-const int32 kExpectedInt32Value = -1145258561;
-const int64 kExpectedInt64Value = -77263311946305LL;
-
-// Positive numbers with different values in each byte, the last of
-// which can survive promotion to double and back.
-const uint8 kExpectedUInt8Value = 65;
-const uint16 kExpectedUInt16Value = 16961;
-const uint32 kExpectedUInt32Value = 1145258561;
-const uint64 kExpectedUInt64Value = 77263311946305LL;
-
-// Double/float values, including special case constants.
-const double kExpectedDoubleVal = 3.14159265358979323846;
-const double kExpectedDoubleInf = std::numeric_limits<double>::infinity();
-const double kExpectedDoubleNan = std::numeric_limits<double>::quiet_NaN();
-const float kExpectedFloatVal = static_cast<float>(kExpectedDoubleVal);
-const float kExpectedFloatInf = std::numeric_limits<float>::infinity();
-const float kExpectedFloatNan = std::numeric_limits<float>::quiet_NaN();
-
-// NaN has the property that it is not equal to itself.
-#define EXPECT_NAN(x) EXPECT_NE(x, x)
-
-void CheckDataPipe(MojoHandle data_pipe_handle) {
- unsigned char buffer[100];
- uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
- MojoResult result = MojoReadData(
- data_pipe_handle, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE);
- EXPECT_EQ(MOJO_RESULT_OK, result);
- EXPECT_EQ(64u, buffer_size);
- for (int i = 0; i < 64; ++i) {
- EXPECT_EQ(i, buffer[i]);
- }
-}
-
-void CheckMessagePipe(MojoHandle message_pipe_handle) {
- unsigned char buffer[100];
- uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
- MojoResult result = MojoReadMessage(
- message_pipe_handle, buffer, &buffer_size, 0, 0, 0);
- EXPECT_EQ(MOJO_RESULT_OK, result);
- EXPECT_EQ(64u, buffer_size);
- for (int i = 0; i < 64; ++i) {
- EXPECT_EQ(255 - i, buffer[i]);
- }
-}
-
-js_to_cpp::EchoArgsPtr BuildSampleEchoArgs() {
- js_to_cpp::EchoArgsPtr args(js_to_cpp::EchoArgs::New());
- args->si64 = kExpectedInt64Value;
- args->si32 = kExpectedInt32Value;
- args->si16 = kExpectedInt16Value;
- args->si8 = kExpectedInt8Value;
- args->ui64 = kExpectedUInt64Value;
- args->ui32 = kExpectedUInt32Value;
- args->ui16 = kExpectedUInt16Value;
- args->ui8 = kExpectedUInt8Value;
- args->float_val = kExpectedFloatVal;
- args->float_inf = kExpectedFloatInf;
- args->float_nan = kExpectedFloatNan;
- args->double_val = kExpectedDoubleVal;
- args->double_inf = kExpectedDoubleInf;
- args->double_nan = kExpectedDoubleNan;
- args->name = "coming";
- Array<String> string_array(3);
- string_array[0] = "one";
- string_array[1] = "two";
- string_array[2] = "three";
- args->string_array = string_array.Pass();
- return args.Pass();
-}
-
-void CheckSampleEchoArgs(const js_to_cpp::EchoArgs& arg) {
- EXPECT_EQ(kExpectedInt64Value, arg.si64);
- EXPECT_EQ(kExpectedInt32Value, arg.si32);
- EXPECT_EQ(kExpectedInt16Value, arg.si16);
- EXPECT_EQ(kExpectedInt8Value, arg.si8);
- EXPECT_EQ(kExpectedUInt64Value, arg.ui64);
- EXPECT_EQ(kExpectedUInt32Value, arg.ui32);
- EXPECT_EQ(kExpectedUInt16Value, arg.ui16);
- EXPECT_EQ(kExpectedUInt8Value, arg.ui8);
- EXPECT_EQ(kExpectedFloatVal, arg.float_val);
- EXPECT_EQ(kExpectedFloatInf, arg.float_inf);
- EXPECT_NAN(arg.float_nan);
- EXPECT_EQ(kExpectedDoubleVal, arg.double_val);
- EXPECT_EQ(kExpectedDoubleInf, arg.double_inf);
- EXPECT_NAN(arg.double_nan);
- EXPECT_EQ(std::string("coming"), arg.name.get());
- EXPECT_EQ(std::string("one"), arg.string_array[0].get());
- EXPECT_EQ(std::string("two"), arg.string_array[1].get());
- EXPECT_EQ(std::string("three"), arg.string_array[2].get());
- CheckDataPipe(arg.data_handle.get().value());
- CheckMessagePipe(arg.message_handle.get().value());
-}
-
-void CheckSampleEchoArgsList(const js_to_cpp::EchoArgsListPtr& list) {
- if (list.is_null())
- return;
- CheckSampleEchoArgs(*list->item);
- CheckSampleEchoArgsList(list->next);
-}
-
-// More forgiving checks are needed in the face of potentially corrupt
-// messages. The values don't matter so long as all accesses are within
-// bounds.
-void CheckCorruptedString(const String& arg) {
- if (arg.is_null())
- return;
- for (size_t i = 0; i < arg.size(); ++i)
- g_waste_accumulator += arg[i];
-}
-
-void CheckCorruptedStringArray(const Array<String>& string_array) {
- if (string_array.is_null())
- return;
- for (size_t i = 0; i < string_array.size(); ++i)
- CheckCorruptedString(string_array[i]);
-}
-
-void CheckCorruptedDataPipe(MojoHandle data_pipe_handle) {
- unsigned char buffer[100];
- uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
- MojoResult result = MojoReadData(
- data_pipe_handle, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE);
- if (result != MOJO_RESULT_OK)
- return;
- for (uint32_t i = 0; i < buffer_size; ++i)
- g_waste_accumulator += buffer[i];
-}
-
-void CheckCorruptedMessagePipe(MojoHandle message_pipe_handle) {
- unsigned char buffer[100];
- uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
- MojoResult result = MojoReadMessage(
- message_pipe_handle, buffer, &buffer_size, 0, 0, 0);
- if (result != MOJO_RESULT_OK)
- return;
- for (uint32_t i = 0; i < buffer_size; ++i)
- g_waste_accumulator += buffer[i];
-}
-
-void CheckCorruptedEchoArgs(const js_to_cpp::EchoArgsPtr& arg) {
- if (arg.is_null())
- return;
- CheckCorruptedString(arg->name);
- CheckCorruptedStringArray(arg->string_array);
- if (arg->data_handle.is_valid())
- CheckCorruptedDataPipe(arg->data_handle.get().value());
- if (arg->message_handle.is_valid())
- CheckCorruptedMessagePipe(arg->message_handle.get().value());
-}
-
-void CheckCorruptedEchoArgsList(const js_to_cpp::EchoArgsListPtr& list) {
- if (list.is_null())
- return;
- CheckCorruptedEchoArgs(list->item);
- CheckCorruptedEchoArgsList(list->next);
-}
-
-// Base Provider implementation class. It's expected that tests subclass and
-// override the appropriate Provider functions. When test is done quit the
-// run_loop().
-class CppSideConnection : public js_to_cpp::CppSide {
- public:
- CppSideConnection() :
- run_loop_(NULL),
- js_side_(NULL),
- mishandled_messages_(0) {
- }
- ~CppSideConnection() override {}
-
- void set_run_loop(base::RunLoop* run_loop) { run_loop_ = run_loop; }
- base::RunLoop* run_loop() { return run_loop_; }
-
- void set_js_side(js_to_cpp::JsSide* js_side) { js_side_ = js_side; }
- js_to_cpp::JsSide* js_side() { return js_side_; }
-
- // js_to_cpp::CppSide:
- void StartTest() override { NOTREACHED(); }
-
- void TestFinished() override { NOTREACHED(); }
-
- void PingResponse() override { mishandled_messages_ += 1; }
-
- void EchoResponse(js_to_cpp::EchoArgsListPtr list) override {
- mishandled_messages_ += 1;
- }
-
- void BitFlipResponse(js_to_cpp::EchoArgsListPtr list) override {
- mishandled_messages_ += 1;
- }
-
- void BackPointerResponse(js_to_cpp::EchoArgsListPtr list) override {
- mishandled_messages_ += 1;
- }
-
- protected:
- base::RunLoop* run_loop_;
- js_to_cpp::JsSide* js_side_;
- int mishandled_messages_;
-
- private:
- DISALLOW_COPY_AND_ASSIGN(CppSideConnection);
-};
-
-// Trivial test to verify a message sent from JS is received.
-class PingCppSideConnection : public CppSideConnection {
- public:
- PingCppSideConnection() : got_message_(false) {}
- ~PingCppSideConnection() override {}
-
- // js_to_cpp::CppSide:
- void StartTest() override { js_side_->Ping(); }
-
- void PingResponse() override {
- got_message_ = true;
- run_loop()->Quit();
- }
-
- bool DidSucceed() {
- return got_message_ && !mishandled_messages_;
- }
-
- private:
- bool got_message_;
- DISALLOW_COPY_AND_ASSIGN(PingCppSideConnection);
-};
-
-// Test that parameters are passed with correct values.
-class EchoCppSideConnection : public CppSideConnection {
- public:
- EchoCppSideConnection() :
- message_count_(0),
- termination_seen_(false) {
- }
- ~EchoCppSideConnection() override {}
-
- // js_to_cpp::CppSide:
- void StartTest() override {
- js_side_->Echo(kExpectedMessageCount, BuildSampleEchoArgs());
- }
-
- void EchoResponse(js_to_cpp::EchoArgsListPtr list) override {
- const js_to_cpp::EchoArgsPtr& special_arg = list->item;
- message_count_ += 1;
- EXPECT_EQ(-1, special_arg->si64);
- EXPECT_EQ(-1, special_arg->si32);
- EXPECT_EQ(-1, special_arg->si16);
- EXPECT_EQ(-1, special_arg->si8);
- EXPECT_EQ(std::string("going"), special_arg->name.To<std::string>());
- CheckSampleEchoArgsList(list->next);
- }
-
- void TestFinished() override {
- termination_seen_ = true;
- run_loop()->Quit();
- }
-
- bool DidSucceed() {
- return termination_seen_ &&
- !mishandled_messages_ &&
- message_count_ == kExpectedMessageCount;
- }
-
- private:
- static const int kExpectedMessageCount = 10;
- int message_count_;
- bool termination_seen_;
- DISALLOW_COPY_AND_ASSIGN(EchoCppSideConnection);
-};
-
-// Test that corrupted messages don't wreak havoc.
-class BitFlipCppSideConnection : public CppSideConnection {
- public:
- BitFlipCppSideConnection() : termination_seen_(false) {}
- ~BitFlipCppSideConnection() override {}
-
- // js_to_cpp::CppSide:
- void StartTest() override { js_side_->BitFlip(BuildSampleEchoArgs()); }
-
- void BitFlipResponse(js_to_cpp::EchoArgsListPtr list) override {
- CheckCorruptedEchoArgsList(list);
- }
-
- void TestFinished() override {
- termination_seen_ = true;
- run_loop()->Quit();
- }
-
- bool DidSucceed() {
- return termination_seen_;
- }
-
- private:
- bool termination_seen_;
- DISALLOW_COPY_AND_ASSIGN(BitFlipCppSideConnection);
-};
-
-// Test that severely random messages don't wreak havoc.
-class BackPointerCppSideConnection : public CppSideConnection {
- public:
- BackPointerCppSideConnection() : termination_seen_(false) {}
- ~BackPointerCppSideConnection() override {}
-
- // js_to_cpp::CppSide:
- void StartTest() override { js_side_->BackPointer(BuildSampleEchoArgs()); }
-
- void BackPointerResponse(js_to_cpp::EchoArgsListPtr list) override {
- CheckCorruptedEchoArgsList(list);
- }
-
- void TestFinished() override {
- termination_seen_ = true;
- run_loop()->Quit();
- }
-
- bool DidSucceed() {
- return termination_seen_;
- }
-
- private:
- bool termination_seen_;
- DISALLOW_COPY_AND_ASSIGN(BackPointerCppSideConnection);
-};
-
-} // namespace
-
-class JsToCppTest : public testing::Test {
- public:
- JsToCppTest() {}
-
- void RunTest(const std::string& test, CppSideConnection* cpp_side) {
- cpp_side->set_run_loop(&run_loop_);
-
- MessagePipe pipe;
- js_to_cpp::JsSidePtr js_side =
- MakeProxy<js_to_cpp::JsSide>(pipe.handle0.Pass());
- js_side.set_client(cpp_side);
-
- js_side.internal_state()->router_for_testing()->EnableTestingMode();
-
- cpp_side->set_js_side(js_side.get());
-
- gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
- gin::ArrayBufferAllocator::SharedInstance());
- gin::IsolateHolder instance;
- MojoRunnerDelegate delegate;
- gin::ShellRunner runner(&delegate, instance.isolate());
- delegate.Start(&runner, pipe.handle1.release().value(), test);
-
- run_loop_.Run();
- }
-
- private:
- base::ShadowingAtExitManager at_exit_;
- base::MessageLoop loop;
- base::RunLoop run_loop_;
-
- DISALLOW_COPY_AND_ASSIGN(JsToCppTest);
-};
-
-TEST_F(JsToCppTest, Ping) {
- PingCppSideConnection cpp_side_connection;
- RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
- EXPECT_TRUE(cpp_side_connection.DidSucceed());
-}
-
-TEST_F(JsToCppTest, Echo) {
- EchoCppSideConnection cpp_side_connection;
- RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
- EXPECT_TRUE(cpp_side_connection.DidSucceed());
-}
-
-TEST_F(JsToCppTest, BitFlip) {
- BitFlipCppSideConnection cpp_side_connection;
- RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
- EXPECT_TRUE(cpp_side_connection.DidSucceed());
-}
-
-TEST_F(JsToCppTest, BackPointer) {
- BackPointerCppSideConnection cpp_side_connection;
- RunTest("mojo/edk/js/tests/js_to_cpp_tests", &cpp_side_connection);
- EXPECT_TRUE(cpp_side_connection.DidSucceed());
-}
-
-} // namespace js
-} // namespace mojo
diff --git a/mojo/edk/js/tests/js_to_cpp_tests.js b/mojo/edk/js/tests/js_to_cpp_tests.js
deleted file mode 100644
index c32f0af..0000000
--- a/mojo/edk/js/tests/js_to_cpp_tests.js
+++ /dev/null
@@ -1,221 +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.
-
-define('mojo/edk/js/tests/js_to_cpp_tests', [
- 'console',
- 'mojo/edk/js/tests/js_to_cpp.mojom',
- 'mojo/public/js/connection',
- 'mojo/public/js/connector',
- 'mojo/public/js/core',
-], function (console, jsToCpp, connection, connector, core) {
- var retainedConnection;
- var sampleData;
- var sampleMessage;
- var BAD_VALUE = 13;
- var DATA_PIPE_PARAMS = {
- flags: core.CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
- elementNumBytes: 1,
- capacityNumBytes: 64
- };
-
- function JsSideConnection(cppSide) {
- this.cppSide_ = cppSide;
- cppSide.startTest();
- }
-
- JsSideConnection.prototype =
- Object.create(jsToCpp.JsSide.stubClass.prototype);
-
- JsSideConnection.prototype.ping = function (arg) {
- this.cppSide_.pingResponse();
- };
-
- JsSideConnection.prototype.echo = function (numIterations, arg) {
- var dataPipe1;
- var dataPipe2;
- var i;
- var messagePipe1;
- var messagePipe2;
- var specialArg;
-
- // Ensure expected negative values are negative.
- if (arg.si64 > 0)
- arg.si64 = BAD_VALUE;
-
- if (arg.si32 > 0)
- arg.si32 = BAD_VALUE;
-
- if (arg.si16 > 0)
- arg.si16 = BAD_VALUE;
-
- if (arg.si8 > 0)
- arg.si8 = BAD_VALUE;
-
- for (i = 0; i < numIterations; ++i) {
- dataPipe1 = core.createDataPipe(DATA_PIPE_PARAMS);
- dataPipe2 = core.createDataPipe(DATA_PIPE_PARAMS);
- messagePipe1 = core.createMessagePipe();
- messagePipe2 = core.createMessagePipe();
-
- arg.data_handle = dataPipe1.consumerHandle;
- arg.message_handle = messagePipe1.handle1;
-
- specialArg = new jsToCpp.EchoArgs();
- specialArg.si64 = -1;
- specialArg.si32 = -1;
- specialArg.si16 = -1;
- specialArg.si8 = -1;
- specialArg.name = 'going';
- specialArg.data_handle = dataPipe2.consumerHandle;
- specialArg.message_handle = messagePipe2.handle1;
-
- writeDataPipe(dataPipe1, sampleData);
- writeDataPipe(dataPipe2, sampleData);
- writeMessagePipe(messagePipe1, sampleMessage);
- writeMessagePipe(messagePipe2, sampleMessage);
-
- this.cppSide_.echoResponse(createEchoArgsList(specialArg, arg));
-
- core.close(dataPipe1.producerHandle);
- core.close(dataPipe2.producerHandle);
- core.close(messagePipe1.handle0);
- core.close(messagePipe2.handle0);
- }
- this.cppSide_.testFinished();
- };
-
- JsSideConnection.prototype.bitFlip = function (arg) {
- var iteration = 0;
- var dataPipe;
- var messagePipe;
- var proto = connector.Connector.prototype;
- var stopSignalled = false;
-
- proto.realAccept = proto.accept;
- proto.accept = function (message) {
- var offset = iteration / 8;
- var mask;
- var value;
- if (offset < message.buffer.arrayBuffer.byteLength) {
- mask = 1 << (iteration % 8);
- value = message.buffer.getUint8(offset) ^ mask;
- message.buffer.setUint8(offset, value);
- return this.realAccept(message);
- }
- stopSignalled = true;
- return false;
- };
-
- while (!stopSignalled) {
- dataPipe = core.createDataPipe(DATA_PIPE_PARAMS);
- messagePipe = core.createMessagePipe();
- writeDataPipe(dataPipe, sampleData);
- writeMessagePipe(messagePipe, sampleMessage);
- arg.data_handle = dataPipe.consumerHandle;
- arg.message_handle = messagePipe.handle1;
-
- this.cppSide_.bitFlipResponse(createEchoArgsList(arg));
-
- core.close(dataPipe.producerHandle);
- core.close(messagePipe.handle0);
- iteration += 1;
- }
-
- proto.accept = proto.realAccept;
- proto.realAccept = null;
- this.cppSide_.testFinished();
- };
-
- JsSideConnection.prototype.backPointer = function (arg) {
- var iteration = 0;
- var dataPipe;
- var messagePipe;
- var proto = connector.Connector.prototype;
- var stopSignalled = false;
-
- proto.realAccept = proto.accept;
- proto.accept = function (message) {
- var delta = 8 * (1 + iteration % 32);
- var offset = 8 * ((iteration / 32) | 0);
- if (offset < message.buffer.arrayBuffer.byteLength - 4) {
- message.buffer.dataView.setUint32(offset, 0x100000000 - delta, true);
- message.buffer.dataView.setUint32(offset + 4, 0xffffffff, true);
- return this.realAccept(message);
- }
- stopSignalled = true;
- return false;
- };
-
- while (!stopSignalled) {
- dataPipe = core.createDataPipe(DATA_PIPE_PARAMS);
- messagePipe = core.createMessagePipe();
- writeDataPipe(dataPipe, sampleData);
- writeMessagePipe(messagePipe, sampleMessage);
- arg.data_handle = dataPipe.consumerHandle;
- arg.message_handle = messagePipe.handle1;
-
- this.cppSide_.backPointerResponse(createEchoArgsList(arg));
-
- core.close(dataPipe.producerHandle);
- core.close(messagePipe.handle0);
- iteration += 1;
- }
-
- proto.accept = proto.realAccept;
- proto.realAccept = null;
- this.cppSide_.testFinished();
- };
-
- function writeDataPipe(pipe, data) {
- var writeResult = core.writeData(
- pipe.producerHandle, data, core.WRITE_DATA_FLAG_ALL_OR_NONE);
-
- if (writeResult.result != core.RESULT_OK) {
- console.log('ERROR: Data pipe write result was ' + writeResult.result);
- return false;
- }
- if (writeResult.numBytes != data.length) {
- console.log('ERROR: Data pipe write length was ' + writeResult.numBytes);
- return false;
- }
- return true;
- }
-
- function writeMessagePipe(pipe, arrayBuffer) {
- var result = core.writeMessage(pipe.handle0, arrayBuffer, [], 0);
- if (result != core.RESULT_OK) {
- console.log('ERROR: Message pipe write result was ' + result);
- return false;
- }
- return true;
- }
-
- function createEchoArgsListElement(item, next) {
- var list = new jsToCpp.EchoArgsList();
- list.item = item;
- list.next = next;
- return list;
- }
-
- function createEchoArgsList() {
- var genuineArray = Array.prototype.slice.call(arguments);
- return genuineArray.reduceRight(function (previous, current) {
- return createEchoArgsListElement(current, previous);
- }, null);
- }
-
- return function(handle) {
- var i;
- sampleData = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes);
- for (i = 0; i < sampleData.length; ++i) {
- sampleData[i] = i;
- }
- sampleMessage = new Uint8Array(DATA_PIPE_PARAMS.capacityNumBytes);
- for (i = 0; i < sampleMessage.length; ++i) {
- sampleMessage[i] = 255 - i;
- }
- retainedConnection = new connection.Connection(handle, JsSideConnection,
- jsToCpp.CppSide.proxyClass);
- };
-});
diff --git a/mojo/edk/js/test/run_js_tests.cc b/mojo/edk/js/tests/run_js_tests.cc
index b574902..4246f8e 100644
--- a/mojo/edk/js/test/run_js_tests.cc
+++ b/mojo/edk/js/tests/run_js_tests.cc
@@ -6,6 +6,7 @@
#include "base/path_service.h"
#include "gin/modules/console.h"
#include "gin/modules/module_registry.h"
+#include "gin/modules/timer.h"
#include "gin/test/file_runner.h"
#include "gin/test/gtest.h"
#include "mojo/edk/js/core.h"
@@ -30,6 +31,7 @@ class TestRunnerDelegate : public gin::FileRunnerDelegate {
};
void RunTest(std::string test, bool run_until_idle) {
+ Environment env;
base::FilePath path;
PathService::Get(base::DIR_SOURCE_ROOT, &path);
path = path.AppendASCII("mojo")
diff --git a/mojo/edk/js/tests/sample_service_tests.js b/mojo/edk/js/tests/sample_service_tests.js
deleted file mode 100644
index ca4f8e6..0000000
--- a/mojo/edk/js/tests/sample_service_tests.js
+++ /dev/null
@@ -1,168 +0,0 @@
-// Copyright 2013 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.
-
-define([
- "console",
- "mojo/edk/js/test/hexdump",
- "gin/test/expect",
- "mojo/public/interfaces/bindings/tests/sample_service.mojom",
- "mojo/public/interfaces/bindings/tests/sample_import.mojom",
- "mojo/public/interfaces/bindings/tests/sample_import2.mojom",
- ], function(console, hexdump, expect, sample, imported, imported2) {
-
- var global = this;
-
- // Set this variable to true to print the binary message in hex.
- var dumpMessageAsHex = false;
-
- function makeFoo() {
- var bar = new sample.Bar();
- bar.alpha = 20;
- bar.beta = 40;
- bar.gamma = 60;
- bar.type = sample.Bar.Type.VERTICAL;
-
- var extra_bars = new Array(3);
- for (var i = 0; i < extra_bars.length; ++i) {
- var base = i * 100;
- var type = i % 2 ?
- sample.Bar.Type.VERTICAL : sample.Bar.Type.HORIZONTAL;
- extra_bars[i] = new sample.Bar();
- extra_bars[i].alpha = base;
- extra_bars[i].beta = base + 20;
- extra_bars[i].gamma = base + 40;
- extra_bars[i].type = type;
- }
-
- var data = new Array(10);
- for (var i = 0; i < data.length; ++i) {
- data[i] = data.length - i;
- }
-
- var source = 0xFFFF; // Invent a dummy handle.
-
- var foo = new sample.Foo();
- foo.name = "foopy";
- foo.x = 1;
- foo.y = 2;
- foo.a = false;
- foo.b = true;
- foo.c = false;
- foo.bar = bar;
- foo.extra_bars = extra_bars;
- foo.data = data;
- foo.source = source;
- return foo;
- }
-
- // Check that the given |Foo| is identical to the one made by |MakeFoo()|.
- function checkFoo(foo) {
- expect(foo.name).toBe("foopy");
- expect(foo.x).toBe(1);
- expect(foo.y).toBe(2);
- expect(foo.a).toBeFalsy();
- expect(foo.b).toBeTruthy();
- expect(foo.c).toBeFalsy();
- expect(foo.bar.alpha).toBe(20);
- expect(foo.bar.beta).toBe(40);
- expect(foo.bar.gamma).toBe(60);
- expect(foo.bar.type).toBe(sample.Bar.Type.VERTICAL);
-
- expect(foo.extra_bars.length).toBe(3);
- for (var i = 0; i < foo.extra_bars.length; ++i) {
- var base = i * 100;
- var type = i % 2 ?
- sample.Bar.Type.VERTICAL : sample.Bar.Type.HORIZONTAL;
- expect(foo.extra_bars[i].alpha).toBe(base);
- expect(foo.extra_bars[i].beta).toBe(base + 20);
- expect(foo.extra_bars[i].gamma).toBe(base + 40);
- expect(foo.extra_bars[i].type).toBe(type);
- }
-
- expect(foo.data.length).toBe(10);
- for (var i = 0; i < foo.data.length; ++i)
- expect(foo.data[i]).toBe(foo.data.length - i);
-
- expect(foo.source).toBe(0xFFFF);
- }
-
- // Check that values are set to the defaults if we don't override them.
- function checkDefaultValues() {
- var bar = new sample.Bar();
- expect(bar.alpha).toBe(255);
- expect(bar.type).toBe(sample.Bar.Type.VERTICAL);
-
- var foo = new sample.Foo();
- expect(foo.name).toBe("Fooby");
- expect(foo.a).toBeTruthy();
- expect(foo.data).toBeNull();
-
- var defaults = new sample.DefaultsTest();
- expect(defaults.a0).toBe(-12);
- expect(defaults.a1).toBe(sample.kTwelve);
- expect(defaults.a2).toBe(1234);
- expect(defaults.a3).toBe(34567);
- expect(defaults.a4).toBe(123456);
- expect(defaults.a5).toBe(3456789012);
- expect(defaults.a6).toBe(-111111111111);
- // JS doesn't have a 64 bit integer type so this is just checking that the
- // expected and actual values have the same closest double value.
- expect(defaults.a7).toBe(9999999999999999999);
- expect(defaults.a8).toBe(0x12345);
- expect(defaults.a9).toBe(-0x12345);
- expect(defaults.a10).toBe(1234);
- expect(defaults.a11).toBe(true);
- expect(defaults.a12).toBe(false);
- expect(defaults.a13).toBe(123.25);
- expect(defaults.a14).toBe(1234567890.123);
- expect(defaults.a15).toBe(1E10);
- expect(defaults.a16).toBe(-1.2E+20);
- expect(defaults.a17).toBe(1.23E-20);
- expect(defaults.a20).toBe(sample.Bar.Type.BOTH);
- expect(defaults.a21).toBeNull();
- expect(defaults.a22).toBeTruthy();
- expect(defaults.a22.shape).toBe(imported.Shape.RECTANGLE);
- expect(defaults.a22.color).toBe(imported2.Color.BLACK);
- expect(defaults.a21).toBeNull();
- expect(defaults.a23).toBe(0xFFFFFFFFFFFFFFFF);
- expect(defaults.a24).toBe(0x123456789);
- expect(defaults.a25).toBe(-0x123456789);
- }
-
- function ServiceImpl() {
- }
-
- ServiceImpl.prototype = Object.create(sample.Service.stubClass.prototype);
-
- ServiceImpl.prototype.frobinate = function(foo, baz, port) {
- checkFoo(foo);
- expect(baz).toBe(sample.Service.BazOptions.EXTRA);
- expect(port).toBe(10);
- global.result = "PASS";
- };
-
- function SimpleMessageReceiver() {
- }
-
- SimpleMessageReceiver.prototype.accept = function(message) {
- if (dumpMessageAsHex) {
- var uint8Array = new Uint8Array(message.buffer.arrayBuffer);
- console.log(hexdump.dumpArray(uint8Array));
- }
- // Imagine some IPC happened here.
- var serviceImpl = new ServiceImpl();
- serviceImpl.accept(message);
- };
-
- var receiver = new SimpleMessageReceiver();
- var serviceProxy = new sample.Service.proxyClass(receiver);
-
- checkDefaultValues();
-
- var foo = makeFoo();
- checkFoo(foo);
-
- var port = 10;
- serviceProxy.frobinate(foo, sample.Service.BazOptions.EXTRA, port);
-});
diff --git a/mojo/edk/js/threading.cc b/mojo/edk/js/threading.cc
deleted file mode 100644
index b571e3e..0000000
--- a/mojo/edk/js/threading.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2013 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/js/threading.h"
-
-#include "base/message_loop/message_loop.h"
-#include "gin/object_template_builder.h"
-#include "gin/per_isolate_data.h"
-#include "mojo/edk/js/handle.h"
-
-namespace mojo {
-namespace js {
-
-namespace {
-
-void Quit() {
- base::MessageLoop::current()->QuitNow();
-}
-
-gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin };
-
-} // namespace
-
-const char Threading::kModuleName[] = "mojo/public/js/threading";
-
-v8::Local<v8::Value> Threading::GetModule(v8::Isolate* isolate) {
- gin::PerIsolateData* data = gin::PerIsolateData::From(isolate);
- v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate(
- &g_wrapper_info);
-
- if (templ.IsEmpty()) {
- templ = gin::ObjectTemplateBuilder(isolate)
- .SetMethod("quit", Quit)
- .Build();
-
- data->SetObjectTemplate(&g_wrapper_info, templ);
- }
-
- return templ->NewInstance();
-}
-
-Threading::Threading() {
-}
-
-} // namespace js
-} // namespace mojo
diff --git a/mojo/edk/js/threading.h b/mojo/edk/js/threading.h
deleted file mode 100644
index 7cf0d53..0000000
--- a/mojo/edk/js/threading.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2013 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_JS_THREADING_H_
-#define MOJO_EDK_JS_THREADING_H_
-
-#include "gin/public/wrapper_info.h"
-#include "v8/include/v8.h"
-
-namespace mojo {
-namespace js {
-
-class Threading {
- public:
- static const char kModuleName[];
- static v8::Local<v8::Value> GetModule(v8::Isolate* isolate);
- private:
- Threading();
-};
-
-} // namespace js
-} // namespace mojo
-
-#endif // MOJO_EDK_JS_THREADING_H_
diff --git a/mojo/edk/js/waiting_callback.h b/mojo/edk/js/waiting_callback.h
index 6b2ccc7..fdffde5 100644
--- a/mojo/edk/js/waiting_callback.h
+++ b/mojo/edk/js/waiting_callback.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef MOJO_EDK_JS_WAITING_CALLBACK_H_
-#define MOJO_EDK_JS_WAITING_CALLBACK_H_
+#ifndef MOJO_BINDINGS_JS_WAITING_CALLBACK_H_
+#define MOJO_BINDINGS_JS_WAITING_CALLBACK_H_
#include "gin/handle.h"
#include "gin/runner.h"
@@ -60,4 +60,4 @@ class WaitingCallback : public gin::Wrappable<WaitingCallback>,
} // namespace js
} // namespace mojo
-#endif // MOJO_EDK_JS_WAITING_CALLBACK_H_
+#endif // MOJO_BINDINGS_JS_WAITING_CALLBACK_H_
diff --git a/mojo/edk/mojo_edk.gyp b/mojo/edk/mojo_edk.gyp
index 05bde04..e826893 100644
--- a/mojo/edk/mojo_edk.gyp
+++ b/mojo/edk/mojo_edk.gyp
@@ -2,12 +2,196 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+# Essential components (and their tests) that are needed to build
+# Chrome should be here. Other components that are useful only in
+# Mojo land like mojo_shell should be in mojo.gyp.
{
'includes': [
'../mojo_variables.gypi',
],
'targets': [
{
+ 'target_name': 'mojo_edk',
+ 'type': 'none',
+ 'dependencies': [
+ # NOTE: If adding a new dependency here, please consider whether it
+ # should also be added to the list of Mojo-related dependencies of
+ # build/all.gyp:All on iOS, as All cannot depend on the mojo_base
+ # target on iOS due to the presence of the js targets, which cause v8
+ # to be built.
+ 'mojo_message_pipe_perftests',
+ 'mojo_public_application_unittests',
+ 'mojo_public_bindings_unittests',
+ 'mojo_public_environment_unittests',
+ 'mojo_public_system_perftests',
+ 'mojo_public_system_unittests',
+ 'mojo_public_utility_unittests',
+ 'mojo_system_impl',
+ 'mojo_system_unittests',
+ 'mojo_js_unittests',
+ ],
+ },
+ {
+ 'target_name': 'mojo_none',
+ 'type': 'none',
+ },
+ {
+ # GN version: //mojo/edk/test:run_all_unittests
+ 'target_name': 'mojo_run_all_unittests',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ '../../base/base.gyp:test_support_base',
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_system_impl',
+ 'mojo_test_support_impl',
+ '../public/mojo_public.gyp:mojo_test_support',
+ ],
+ 'sources': [
+ 'test/run_all_unittests.cc',
+ ],
+ },
+ {
+ # GN version: //mojo/edk/test:run_all_perftests
+ 'target_name': 'mojo_run_all_perftests',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../../base/base.gyp:test_support_base',
+ 'mojo_system_impl',
+ 'mojo_test_support_impl',
+ '../public/mojo_public.gyp:mojo_test_support',
+ ],
+ 'sources': [
+ 'test/run_all_perftests.cc',
+ ],
+ },
+ # TODO(vtl): Reorganize the mojo_public_*_unittests.
+ {
+ # GN version: //mojo/public/cpp/bindings/tests:mojo_public_bindings_unittests
+ 'target_name': 'mojo_public_bindings_unittests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_run_all_unittests',
+ '../public/mojo_public.gyp:mojo_cpp_bindings',
+ '../public/mojo_public.gyp:mojo_environment_standalone',
+ '../public/mojo_public.gyp:mojo_public_bindings_test_utils',
+ '../public/mojo_public.gyp:mojo_public_test_interfaces',
+ '../public/mojo_public.gyp:mojo_public_test_utils',
+ '../public/mojo_public.gyp:mojo_utility',
+ ],
+ 'sources': [
+ '../public/cpp/bindings/tests/array_unittest.cc',
+ '../public/cpp/bindings/tests/bounds_checker_unittest.cc',
+ '../public/cpp/bindings/tests/buffer_unittest.cc',
+ '../public/cpp/bindings/tests/connector_unittest.cc',
+ '../public/cpp/bindings/tests/container_test_util.cc',
+ '../public/cpp/bindings/tests/equals_unittest.cc',
+ '../public/cpp/bindings/tests/handle_passing_unittest.cc',
+ '../public/cpp/bindings/tests/interface_ptr_unittest.cc',
+ '../public/cpp/bindings/tests/map_unittest.cc',
+ '../public/cpp/bindings/tests/request_response_unittest.cc',
+ '../public/cpp/bindings/tests/router_unittest.cc',
+ '../public/cpp/bindings/tests/sample_service_unittest.cc',
+ '../public/cpp/bindings/tests/serialization_warning_unittest.cc',
+ '../public/cpp/bindings/tests/string_unittest.cc',
+ '../public/cpp/bindings/tests/struct_unittest.cc',
+ '../public/cpp/bindings/tests/type_conversion_unittest.cc',
+ '../public/cpp/bindings/tests/validation_unittest.cc',
+ ],
+ },
+ {
+ # GN version: //mojo/public/cpp/environment/tests:mojo_public_environment_unittests
+ 'target_name': 'mojo_public_environment_unittests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_run_all_unittests',
+ '../public/mojo_public.gyp:mojo_environment_standalone',
+ '../public/mojo_public.gyp:mojo_public_test_utils',
+ '../public/mojo_public.gyp:mojo_utility',
+ ],
+ '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',
+ ],
+ },
+ {
+ # GN version: //mojo/public/cpp/application/tests:mojo_public_application_unittests
+ 'target_name': 'mojo_public_application_unittests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_run_all_unittests',
+ '../public/mojo_public.gyp:mojo_application_standalone',
+ '../public/mojo_public.gyp:mojo_utility',
+ '../public/mojo_public.gyp:mojo_environment_standalone',
+ ],
+ 'sources': [
+ '../public/cpp/application/tests/service_registry_unittest.cc',
+ ],
+ },
+ {
+ # GN version: //mojo/public/cpp/application/tests:mojo_public_system_unittests
+ 'target_name': 'mojo_public_system_unittests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_run_all_unittests',
+ '../public/mojo_public.gyp:mojo_public_test_utils',
+ ],
+ 'include_dirs': [ '../..' ],
+ 'sources': [
+ '<@(mojo_public_system_unittest_sources)',
+ ],
+ },
+ {
+ # GN version: //mojo/public/cpp/application/tests:mojo_public_utility_unittests
+ 'target_name': 'mojo_public_utility_unittests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_run_all_unittests',
+ '../public/mojo_public.gyp:mojo_public_test_utils',
+ '../public/mojo_public.gyp:mojo_utility',
+ ],
+ 'include_dirs': [ '../..' ],
+ 'sources': [
+ '../public/cpp/utility/tests/mutex_unittest.cc',
+ '../public/cpp/utility/tests/run_loop_unittest.cc',
+ '../public/cpp/utility/tests/thread_unittest.cc',
+ ],
+ 'conditions': [
+ # See crbug.com/342893:
+ ['OS=="win"', {
+ 'sources!': [
+ '../public/cpp/utility/tests/mutex_unittest.cc',
+ '../public/cpp/utility/tests/thread_unittest.cc',
+ ],
+ }],
+ ],
+ },
+ {
+ # GN version: //mojo/public/c/system/tests:perftests
+ 'target_name': 'mojo_public_system_perftests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_run_all_perftests',
+ '../public/mojo_public.gyp:mojo_public_test_utils',
+ '../public/mojo_public.gyp:mojo_utility',
+ ],
+ 'sources': [
+ '../public/c/system/tests/core_perftest.cc',
+ ],
+ },
+
+ {
# GN version: //mojo/edk/system
'target_name': 'mojo_system_impl',
'type': '<(component)',
@@ -21,14 +205,11 @@
'MOJO_USE_SYSTEM_IMPL',
],
'sources': [
- 'embedder/configuration.h',
'embedder/channel_info_forward.h',
'embedder/channel_init.cc',
'embedder/channel_init.h',
'embedder/embedder.cc',
'embedder/embedder.h',
- 'embedder/embedder_internal.h',
- 'embedder/entrypoints.cc',
'embedder/platform_channel_pair.cc',
'embedder/platform_channel_pair.h',
'embedder/platform_channel_pair_posix.cc',
@@ -58,10 +239,7 @@
'system/channel_endpoint_id.h',
'system/channel_info.cc',
'system/channel_info.h',
- 'system/channel_manager.cc',
- 'system/channel_manager.h',
- 'system/configuration.cc',
- 'system/configuration.h',
+ 'system/constants.h',
'system/core.cc',
'system/core.h',
'system/data_pipe.cc',
@@ -72,6 +250,7 @@
'system/data_pipe_producer_dispatcher.h',
'system/dispatcher.cc',
'system/dispatcher.h',
+ 'system/entrypoints.cc',
'system/handle_signals_state.h',
'system/handle_table.cc',
'system/handle_table.h',
@@ -125,6 +304,77 @@
}
},
{
+ # GN version: //mojo/edk/system:mojo_system_unittests
+ 'target_name': 'mojo_system_unittests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_common_test_support',
+ 'mojo_system_impl',
+ ],
+ 'sources': [
+ 'embedder/embedder_unittest.cc',
+ 'embedder/platform_channel_pair_posix_unittest.cc',
+ 'embedder/simple_platform_shared_buffer_unittest.cc',
+ 'system/channel_endpoint_id_unittest.cc',
+ 'system/channel_unittest.cc',
+ 'system/core_unittest.cc',
+ 'system/core_test_base.cc',
+ 'system/core_test_base.h',
+ 'system/data_pipe_unittest.cc',
+ 'system/dispatcher_unittest.cc',
+ 'system/local_data_pipe_unittest.cc',
+ 'system/memory_unittest.cc',
+ 'system/message_pipe_dispatcher_unittest.cc',
+ 'system/message_pipe_test_utils.h',
+ 'system/message_pipe_test_utils.cc',
+ 'system/message_pipe_unittest.cc',
+ 'system/multiprocess_message_pipe_unittest.cc',
+ 'system/options_validation_unittest.cc',
+ 'system/platform_handle_dispatcher_unittest.cc',
+ 'system/raw_channel_unittest.cc',
+ 'system/remote_message_pipe_unittest.cc',
+ 'system/run_all_unittests.cc',
+ 'system/shared_buffer_dispatcher_unittest.cc',
+ 'system/simple_dispatcher_unittest.cc',
+ 'system/test_utils.cc',
+ 'system/test_utils.h',
+ 'system/waiter_list_unittest.cc',
+ 'system/waiter_test_utils.cc',
+ 'system/waiter_test_utils.h',
+ 'system/waiter_unittest.cc',
+ ],
+ 'conditions': [
+ ['OS=="ios"', {
+ 'sources!': [
+ 'embedder/embedder_unittest.cc',
+ 'system/multiprocess_message_pipe_unittest.cc',
+ ],
+ }],
+ ],
+ },
+ {
+ # GN version: //mojo/edk/system:mojo_message_pipe_perftests
+ 'target_name': 'mojo_message_pipe_perftests',
+ 'type': 'executable',
+ 'dependencies': [
+ '../../base/base.gyp:base',
+ '../../base/base.gyp:test_support_base',
+ '../../base/base.gyp:test_support_perf',
+ '../../testing/gtest.gyp:gtest',
+ 'mojo_common_test_support',
+ 'mojo_system_impl',
+ ],
+ 'sources': [
+ 'system/message_pipe_perftest.cc',
+ 'system/message_pipe_test_utils.h',
+ 'system/message_pipe_test_utils.cc',
+ 'system/test_utils.cc',
+ 'system/test_utils.h',
+ ],
+ },
+ {
# GN version: //mojo/edk/js
'target_name': 'mojo_js_lib',
'type': 'static_library',
@@ -146,18 +396,32 @@
'js/handle.cc',
'js/handle.h',
'js/handle_close_observer.h',
- 'js/mojo_runner_delegate.cc',
- 'js/mojo_runner_delegate.h',
'js/support.cc',
'js/support.h',
- 'js/threading.cc',
- 'js/threading.h',
'js/waiting_callback.cc',
'js/waiting_callback.h',
],
},
{
- # GN version: //mojo/edk/test:test_support_impl
+ # 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',
'type': 'static_library',
'dependencies': [
@@ -193,35 +457,5 @@
}],
],
},
- {
- # GN version: //mojo/edk/test:run_all_unittests
- 'target_name': 'mojo_run_all_unittests',
- 'type': 'static_library',
- 'dependencies': [
- '../../base/base.gyp:base',
- '../../base/base.gyp:test_support_base',
- '../../testing/gtest.gyp:gtest',
- 'mojo_system_impl',
- 'mojo_test_support_impl',
- '../public/mojo_public.gyp:mojo_test_support',
- ],
- 'sources': [
- 'test/run_all_unittests.cc',
- ],
- },
- {
- # GN version: //mojo/edk/test:run_all_perftests
- 'target_name': 'mojo_run_all_perftests',
- 'type': 'static_library',
- 'dependencies': [
- '../../base/base.gyp:test_support_base',
- 'mojo_edk.gyp:mojo_system_impl',
- 'mojo_test_support_impl',
- '../public/mojo_public.gyp:mojo_test_support',
- ],
- 'sources': [
- 'test/run_all_perftests.cc',
- ],
- },
],
}
diff --git a/mojo/edk/mojo_edk_tests.gyp b/mojo/edk/mojo_edk_tests.gyp
deleted file mode 100644
index 943cad3..0000000
--- a/mojo/edk/mojo_edk_tests.gyp
+++ /dev/null
@@ -1,278 +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.
-
-{
- 'includes': [
- '../mojo_variables.gypi',
- ],
- 'targets': [
- {
- 'target_name': 'mojo_edk_tests',
- 'type': 'none',
- 'dependencies': [
- # NOTE: If adding a new dependency here, please consider whether it
- # should also be added to the list of Mojo-related dependencies of
- # build/all.gyp:All on iOS, as All cannot depend on the mojo_base
- # target on iOS due to the presence of the js targets, which cause v8
- # to be built.
- 'mojo_message_pipe_perftests',
- 'mojo_public_application_unittests',
- 'mojo_public_bindings_unittests',
- 'mojo_public_environment_unittests',
- 'mojo_public_system_perftests',
- 'mojo_public_system_unittests',
- 'mojo_public_utility_unittests',
- 'mojo_system_unittests',
- 'mojo_js_unittests',
- 'mojo_js_integration_tests',
- ],
- },
- # TODO(vtl): Reorganize the mojo_public_*_unittests.
- {
- # GN version: //mojo/public/cpp/bindings/tests:mojo_public_bindings_unittests
- 'target_name': 'mojo_public_bindings_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_run_all_unittests',
- '../public/mojo_public.gyp:mojo_cpp_bindings',
- '../public/mojo_public.gyp:mojo_environment_standalone',
- '../public/mojo_public.gyp:mojo_public_bindings_test_utils',
- '../public/mojo_public.gyp:mojo_public_test_interfaces',
- '../public/mojo_public.gyp:mojo_public_test_utils',
- '../public/mojo_public.gyp:mojo_utility',
- ],
- 'sources': [
- '../public/cpp/bindings/tests/array_unittest.cc',
- '../public/cpp/bindings/tests/bounds_checker_unittest.cc',
- '../public/cpp/bindings/tests/buffer_unittest.cc',
- '../public/cpp/bindings/tests/connector_unittest.cc',
- '../public/cpp/bindings/tests/container_test_util.cc',
- '../public/cpp/bindings/tests/equals_unittest.cc',
- '../public/cpp/bindings/tests/handle_passing_unittest.cc',
- '../public/cpp/bindings/tests/interface_ptr_unittest.cc',
- '../public/cpp/bindings/tests/map_unittest.cc',
- '../public/cpp/bindings/tests/request_response_unittest.cc',
- '../public/cpp/bindings/tests/router_unittest.cc',
- '../public/cpp/bindings/tests/sample_service_unittest.cc',
- '../public/cpp/bindings/tests/serialization_warning_unittest.cc',
- '../public/cpp/bindings/tests/string_unittest.cc',
- '../public/cpp/bindings/tests/struct_unittest.cc',
- '../public/cpp/bindings/tests/type_conversion_unittest.cc',
- '../public/cpp/bindings/tests/validation_unittest.cc',
- ],
- },
- {
- # GN version: //mojo/public/cpp/environment/tests:mojo_public_environment_unittests
- 'target_name': 'mojo_public_environment_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_run_all_unittests',
- '../public/mojo_public.gyp:mojo_environment_standalone',
- '../public/mojo_public.gyp:mojo_public_test_utils',
- '../public/mojo_public.gyp:mojo_utility',
- ],
- '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',
- ],
- },
- {
- # GN version: //mojo/public/cpp/application/tests:mojo_public_application_unittests
- 'target_name': 'mojo_public_application_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../base/base.gyp:base',
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_run_all_unittests',
- '../public/mojo_public.gyp:mojo_application_standalone',
- '../public/mojo_public.gyp:mojo_utility',
- '../public/mojo_public.gyp:mojo_environment_standalone',
- ],
- 'sources': [
- '../public/cpp/application/tests/service_registry_unittest.cc',
- ],
- },
- {
- # GN version: //mojo/public/cpp/system/tests:mojo_public_system_unittests
- # and //mojo/public/c/system/tests
- 'target_name': 'mojo_public_system_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_run_all_unittests',
- '../public/mojo_public.gyp:mojo_public_test_utils',
- ],
- 'include_dirs': [ '../..' ],
- 'sources': [
- '<@(mojo_public_system_unittest_sources)',
- ],
- },
- {
- # GN version: //mojo/public/cpp/application/tests:mojo_public_utility_unittests
- 'target_name': 'mojo_public_utility_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_run_all_unittests',
- '../public/mojo_public.gyp:mojo_public_test_utils',
- '../public/mojo_public.gyp:mojo_utility',
- ],
- 'include_dirs': [ '../..' ],
- 'sources': [
- '../public/cpp/utility/tests/mutex_unittest.cc',
- '../public/cpp/utility/tests/run_loop_unittest.cc',
- '../public/cpp/utility/tests/thread_unittest.cc',
- ],
- 'conditions': [
- # See crbug.com/342893:
- ['OS=="win"', {
- 'sources!': [
- '../public/cpp/utility/tests/mutex_unittest.cc',
- '../public/cpp/utility/tests/thread_unittest.cc',
- ],
- }],
- ],
- },
- {
- # GN version: //mojo/public/c/system/tests:perftests
- 'target_name': 'mojo_public_system_perftests',
- 'type': 'executable',
- 'dependencies': [
- '../../base/base.gyp:base',
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_run_all_perftests',
- '../public/mojo_public.gyp:mojo_public_test_utils',
- '../public/mojo_public.gyp:mojo_utility',
- ],
- 'sources': [
- '../public/c/system/tests/core_perftest.cc',
- ],
- },
- {
- # GN version: //mojo/edk/system:mojo_system_unittests
- 'target_name': 'mojo_system_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../base/base.gyp:base',
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_common_test_support',
- 'mojo_edk.gyp:mojo_system_impl',
- ],
- 'sources': [
- 'embedder/embedder_unittest.cc',
- 'embedder/platform_channel_pair_posix_unittest.cc',
- 'embedder/simple_platform_shared_buffer_unittest.cc',
- 'system/channel_endpoint_id_unittest.cc',
- 'system/channel_unittest.cc',
- 'system/core_unittest.cc',
- 'system/core_test_base.cc',
- 'system/core_test_base.h',
- 'system/data_pipe_unittest.cc',
- 'system/dispatcher_unittest.cc',
- 'system/local_data_pipe_unittest.cc',
- 'system/memory_unittest.cc',
- 'system/message_pipe_dispatcher_unittest.cc',
- 'system/message_pipe_test_utils.h',
- 'system/message_pipe_test_utils.cc',
- 'system/message_pipe_unittest.cc',
- 'system/multiprocess_message_pipe_unittest.cc',
- 'system/options_validation_unittest.cc',
- 'system/platform_handle_dispatcher_unittest.cc',
- 'system/raw_channel_unittest.cc',
- 'system/remote_message_pipe_unittest.cc',
- 'system/run_all_unittests.cc',
- 'system/shared_buffer_dispatcher_unittest.cc',
- 'system/simple_dispatcher_unittest.cc',
- 'system/test_utils.cc',
- 'system/test_utils.h',
- 'system/waiter_list_unittest.cc',
- 'system/waiter_test_utils.cc',
- 'system/waiter_test_utils.h',
- 'system/waiter_unittest.cc',
- 'test/multiprocess_test_helper_unittest.cc',
- ],
- 'conditions': [
- ['OS=="ios"', {
- 'sources!': [
- 'embedder/embedder_unittest.cc',
- 'system/multiprocess_message_pipe_unittest.cc',
- 'test/multiprocess_test_helper_unittest.cc',
- ],
- }],
- ],
- },
- {
- # GN version: //mojo/edk/system:mojo_message_pipe_perftests
- 'target_name': 'mojo_message_pipe_perftests',
- 'type': 'executable',
- 'dependencies': [
- '../../base/base.gyp:base',
- '../../base/base.gyp:test_support_base',
- '../../base/base.gyp:test_support_perf',
- '../../testing/gtest.gyp:gtest',
- 'mojo_edk.gyp:mojo_common_test_support',
- 'mojo_edk.gyp:mojo_system_impl',
- ],
- 'sources': [
- 'system/message_pipe_perftest.cc',
- 'system/message_pipe_test_utils.h',
- 'system/message_pipe_test_utils.cc',
- 'system/test_utils.cc',
- 'system/test_utils.h',
- ],
- },
- {
- # GN version: //mojo/edk/js/test:js_unittests
- 'target_name': 'mojo_js_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../../gin/gin.gyp:gin_test',
- 'mojo_edk.gyp:mojo_common_test_support',
- 'mojo_edk.gyp:mojo_run_all_unittests',
- 'mojo_edk.gyp: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/test/run_js_tests.cc',
- ],
- },
- {
- # GN version: //mojo/edk/js/test:js_integration_tests
- 'target_name': 'mojo_js_integration_tests',
- 'type': 'executable',
- 'dependencies': [
- '../../base/base.gyp:base',
- '../../gin/gin.gyp:gin_test',
- '../public/mojo_public.gyp:mojo_environment_standalone',
- '../public/mojo_public.gyp:mojo_public_test_interfaces',
- '../public/mojo_public.gyp:mojo_utility',
- 'mojo_edk.gyp:mojo_js_lib',
- 'mojo_edk.gyp:mojo_run_all_unittests',
- 'mojo_js_to_cpp_bindings',
- ],
- 'sources': [
- 'js/test/run_js_integration_tests.cc',
- 'js/tests/js_to_cpp_tests',
- ],
- },
- {
- 'target_name': 'mojo_js_to_cpp_bindings',
- 'type': 'none',
- 'variables': {
- 'mojom_files': [
- 'js/tests/js_to_cpp.mojom',
- ],
- },
- 'includes': [ '../public/tools/bindings/mojom_bindings_generator_explicit.gypi' ],
- },
- ],
-}
diff --git a/mojo/edk/system/BUILD.gn b/mojo/edk/system/BUILD.gn
index d0bfda7..791a192 100644
--- a/mojo/edk/system/BUILD.gn
+++ b/mojo/edk/system/BUILD.gn
@@ -12,6 +12,19 @@ config("system_config") {
component("system") {
output_name = "mojo_system_impl"
+ deps = [
+ "//base",
+ "//base/third_party/dynamic_annotations",
+ "//mojo/edk/embedder",
+ ]
+
+ defines = [
+ "MOJO_SYSTEM_IMPL_IMPLEMENTATION",
+ "MOJO_SYSTEM_IMPLEMENTATION",
+ ]
+
+ all_dependent_configs = [ ":system_config" ]
+
sources = [
"channel.cc",
"channel.h",
@@ -21,10 +34,7 @@ component("system") {
"channel_endpoint_id.h",
"channel_info.cc",
"channel_info.h",
- "channel_manager.cc",
- "channel_manager.h",
- "configuration.cc",
- "configuration.h",
+ "constants.h",
"core.cc",
"core.h",
"data_pipe.cc",
@@ -35,6 +45,7 @@ component("system") {
"data_pipe_producer_dispatcher.h",
"dispatcher.cc",
"dispatcher.h",
+ "entrypoints.cc",
"handle_signals_state.h",
"handle_table.cc",
"handle_table.h",
@@ -76,30 +87,18 @@ component("system") {
"waiter_list.cc",
"waiter_list.h",
]
+}
- defines = [
- "MOJO_SYSTEM_IMPL_IMPLEMENTATION",
- "MOJO_SYSTEM_IMPLEMENTATION",
- ]
-
- all_dependent_configs = [ ":system_config" ]
-
- public_deps = [
- "//mojo/edk/embedder",
- "//mojo/edk/embedder:platform",
- "//mojo/public/c/system",
- ]
-
+# GYP version: mojo/edk/mojo_edk.gyp:mojo_system_unittests
+test("mojo_system_unittests") {
deps = [
+ ":system",
"//base",
- "//base/third_party/dynamic_annotations",
+ "//mojo/edk/embedder:embedder_unittests",
+ "//mojo/edk/test:test_support",
+ "//testing/gtest",
]
- allow_circular_includes_from = [ "//mojo/edk/embedder" ]
-}
-
-# GYP version: mojo/edk/mojo_edk.gyp:mojo_system_unittests
-test("mojo_system_unittests") {
sources = [
"../test/multiprocess_test_helper_unittest.cc",
"channel_endpoint_id_unittest.cc",
@@ -123,7 +122,6 @@ test("mojo_system_unittests") {
"run_all_unittests.cc",
"shared_buffer_dispatcher_unittest.cc",
"simple_dispatcher_unittest.cc",
- # TODO(vtl): Factor test_utils.* into their own source set.
"test_utils.cc",
"test_utils.h",
"waiter_list_unittest.cc",
@@ -131,21 +129,19 @@ test("mojo_system_unittests") {
"waiter_test_utils.h",
"waiter_unittest.cc",
]
+}
+# GYP version: mojo/edk/mojo_edk.gyp:mojo_message_pipe_perftests
+test("mojo_message_pipe_perftests") {
deps = [
":system",
"//base",
"//base/test:test_support",
- "//mojo/edk/embedder:embedder_unittests",
+ "//base/test:test_support_perf",
"//mojo/edk/test:test_support",
"//testing/gtest",
]
- allow_circular_includes_from = [ "//mojo/edk/embedder:embedder_unittests" ]
-}
-
-# GYP version: mojo/edk/mojo_edk.gyp:mojo_message_pipe_perftests
-test("mojo_message_pipe_perftests") {
sources = [
"message_pipe_perftest.cc",
"message_pipe_test_utils.h",
@@ -153,13 +149,4 @@ test("mojo_message_pipe_perftests") {
"test_utils.cc",
"test_utils.h",
]
-
- deps = [
- ":system",
- "//base",
- "//base/test:test_support",
- "//base/test:test_support_perf",
- "//mojo/edk/test:test_support",
- "//testing/gtest",
- ]
}
diff --git a/mojo/edk/system/channel.cc b/mojo/edk/system/channel.cc
index 0205312..b63aaeb 100644
--- a/mojo/edk/system/channel.cc
+++ b/mojo/edk/system/channel.cc
@@ -20,8 +20,7 @@ namespace system {
Channel::Channel(embedder::PlatformSupport* platform_support)
: platform_support_(platform_support),
is_running_(false),
- is_shutting_down_(false),
- channel_manager_(nullptr) {
+ is_shutting_down_(false) {
}
bool Channel::Init(scoped_ptr<RawChannel> raw_channel) {
@@ -42,15 +41,6 @@ bool Channel::Init(scoped_ptr<RawChannel> raw_channel) {
return true;
}
-void Channel::SetChannelManager(ChannelManager* channel_manager) {
- DCHECK(channel_manager);
-
- base::AutoLock locker(lock_);
- DCHECK(!is_shutting_down_);
- DCHECK(!channel_manager_);
- channel_manager_ = channel_manager;
-}
-
void Channel::Shutdown() {
DCHECK(creation_thread_checker_.CalledOnValidThread());
@@ -72,7 +62,8 @@ void Channel::Shutdown() {
size_t num_live = 0;
size_t num_zombies = 0;
for (IdToEndpointMap::iterator it = to_destroy.begin();
- it != to_destroy.end(); ++it) {
+ it != to_destroy.end();
+ ++it) {
if (it->second.get()) {
num_live++;
it->second->OnDisconnect();
@@ -89,7 +80,6 @@ void Channel::Shutdown() {
void Channel::WillShutdownSoon() {
base::AutoLock locker(lock_);
is_shutting_down_ = true;
- channel_manager_ = nullptr;
}
// Note: |endpoint| being a |scoped_refptr| makes this function safe, since it
@@ -130,7 +120,8 @@ ChannelEndpointId Channel::AttachAndRunEndpoint(
if (!is_bootstrap) {
if (!SendControlMessage(
- MessageInTransit::kSubtypeChannelAttachAndRunEndpoint, local_id,
+ MessageInTransit::kSubtypeChannelAttachAndRunEndpoint,
+ local_id,
remote_id)) {
HandleLocalError(base::StringPrintf(
"Failed to send message to run remote message pipe endpoint (local "
@@ -194,7 +185,8 @@ void Channel::DetachEndpoint(ChannelEndpoint* endpoint,
}
if (!SendControlMessage(
- MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpoint, local_id,
+ MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpoint,
+ local_id,
remote_id)) {
HandleLocalError(base::StringPrintf(
"Failed to send message to remove remote message pipe endpoint (local "
@@ -467,7 +459,8 @@ bool Channel::OnRemoveMessagePipeEndpoint(ChannelEndpointId local_id,
if (!SendControlMessage(
MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpointAck,
- local_id, remote_id)) {
+ local_id,
+ remote_id)) {
HandleLocalError(base::StringPrintf(
"Failed to send message to remove remote message pipe endpoint ack "
"(local ID %u, remote ID %u)",
diff --git a/mojo/edk/system/channel.h b/mojo/edk/system/channel.h
index 715d1f2..6697965 100644
--- a/mojo/edk/system/channel.h
+++ b/mojo/edk/system/channel.h
@@ -32,7 +32,6 @@ class PlatformSupport;
namespace system {
class ChannelEndpoint;
-class ChannelManager;
// This class is mostly thread-safe. It must be created on an I/O thread.
// |Init()| must be called on that same thread before it becomes thread-safe (in
@@ -62,11 +61,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel
// failure, no other methods should be called (including |Shutdown()|).
bool Init(scoped_ptr<RawChannel> raw_channel);
- // Sets the channel manager associated with this channel. This should be set
- // at most once and only called before |WillShutdownSoon()| (and
- // |Shutdown()|).
- void SetChannelManager(ChannelManager* channel_manager);
-
// This must be called on the creation thread before destruction (which can
// happen on any thread).
void Shutdown();
@@ -75,8 +69,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel
// thread, unlike |Shutdown()|). Warnings will be issued if, e.g., messages
// are written after this is called; other warnings may be suppressed. (This
// may be called multiple times, or not at all.)
- //
- // If set, the channel manager associated with this channel will be reset.
void WillShutdownSoon();
// Attaches the given endpoint to this channel and runs it. |is_bootstrap|
@@ -183,9 +175,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel
// Set when |WillShutdownSoon()| is called.
bool is_shutting_down_;
- // Has a reference to us.
- ChannelManager* channel_manager_;
-
typedef base::hash_map<ChannelEndpointId, scoped_refptr<ChannelEndpoint>>
IdToEndpointMap;
// Map from local IDs to endpoints. If the endpoint is null, this means that
diff --git a/mojo/edk/system/channel_endpoint.cc b/mojo/edk/system/channel_endpoint.cc
index dd7cd5b..8b64643 100644
--- a/mojo/edk/system/channel_endpoint.cc
+++ b/mojo/edk/system/channel_endpoint.cc
@@ -109,7 +109,8 @@ bool ChannelEndpoint::OnReadMessage(
DCHECK(message_view.transport_data_buffer());
message->SetDispatchers(TransportData::DeserializeDispatchers(
message_view.transport_data_buffer(),
- message_view.transport_data_buffer_size(), platform_handles.Pass(),
+ message_view.transport_data_buffer_size(),
+ platform_handles.Pass(),
channel_));
}
diff --git a/mojo/edk/system/channel_info.cc b/mojo/edk/system/channel_info.cc
index 6d23215..efc5f04 100644
--- a/mojo/edk/system/channel_info.cc
+++ b/mojo/edk/system/channel_info.cc
@@ -4,8 +4,6 @@
#include "mojo/edk/system/channel_info.h"
-#include <algorithm>
-
namespace mojo {
namespace system {
@@ -21,11 +19,5 @@ ChannelInfo::ChannelInfo(
ChannelInfo::~ChannelInfo() {
}
-void ChannelInfo::Swap(ChannelInfo* other) {
- // Note: Swapping avoids refcount churn.
- std::swap(channel, other->channel);
- std::swap(channel_thread_task_runner, other->channel_thread_task_runner);
-}
-
} // namespace system
} // namespace mojo
diff --git a/mojo/edk/system/channel_info.h b/mojo/edk/system/channel_info.h
index 5167cca..bd84e16 100644
--- a/mojo/edk/system/channel_info.h
+++ b/mojo/edk/system/channel_info.h
@@ -19,8 +19,6 @@ struct MOJO_SYSTEM_IMPL_EXPORT ChannelInfo {
scoped_refptr<base::TaskRunner> channel_thread_task_runner);
~ChannelInfo();
- void Swap(ChannelInfo* other);
-
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.
diff --git a/mojo/edk/system/channel_manager.cc b/mojo/edk/system/channel_manager.cc
deleted file mode 100644
index e673299..0000000
--- a/mojo/edk/system/channel_manager.cc
+++ /dev/null
@@ -1,62 +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/edk/system/channel_manager.h"
-
-#include "base/bind.h"
-#include "base/location.h"
-
-namespace mojo {
-namespace system {
-
-namespace {
-
-void ShutdownChannelHelper(const ChannelInfo& channel_info) {
- channel_info.channel->WillShutdownSoon();
- channel_info.channel_thread_task_runner->PostTask(
- FROM_HERE, base::Bind(&Channel::Shutdown, channel_info.channel));
-}
-
-} // namespace
-
-ChannelManager::ChannelManager() {
-}
-
-ChannelManager::~ChannelManager() {
- // No need to take the lock.
- for (const auto& map_elem : channel_infos_)
- ShutdownChannelHelper(map_elem.second);
-}
-
-ChannelId ChannelManager::AddChannel(
- scoped_refptr<Channel> channel,
- scoped_refptr<base::TaskRunner> channel_thread_task_runner) {
- ChannelId channel_id = GetChannelId(channel.get());
-
- {
- base::AutoLock locker(lock_);
- DCHECK(channel_infos_.find(channel_id) == channel_infos_.end());
- channel_infos_[channel_id] =
- ChannelInfo(channel, channel_thread_task_runner);
- }
- channel->SetChannelManager(this);
-
- return channel_id;
-}
-
-void ChannelManager::ShutdownChannel(ChannelId channel_id) {
- ChannelInfo channel_info;
- {
- base::AutoLock locker(lock_);
-
- auto it = channel_infos_.find(channel_id);
- DCHECK(it != channel_infos_.end());
- channel_info.Swap(&it->second);
- channel_infos_.erase(it);
- }
- ShutdownChannelHelper(channel_info);
-}
-
-} // namespace system
-} // namespace mojo
diff --git a/mojo/edk/system/channel_manager.h b/mojo/edk/system/channel_manager.h
deleted file mode 100644
index 244f8ad..0000000
--- a/mojo/edk/system/channel_manager.h
+++ /dev/null
@@ -1,74 +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.
-
-#ifndef MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_
-#define MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_
-
-#include <stdint.h>
-
-#include "base/containers/hash_tables.h"
-#include "base/macros.h"
-#include "base/memory/ref_counted.h"
-#include "base/synchronization/lock.h"
-#include "base/task_runner.h"
-#include "mojo/edk/system/channel.h"
-#include "mojo/edk/system/channel_info.h"
-
-namespace mojo {
-namespace system {
-
-// IDs for |Channel|s managed by a |ChannelManager|. (IDs should be thought of
-// as specific to a given |ChannelManager|.) 0 is never a valid ID.
-//
-// Note: We currently just use the pointer of the |Channel| casted to a
-// |uintptr_t|, but we reserve the right to change this.
-typedef uintptr_t ChannelId;
-
-// This class manages and "owns" |Channel|s (which typically connect to other
-// processes) for a given process. This class is thread-safe.
-class MOJO_SYSTEM_IMPL_EXPORT ChannelManager {
- public:
- ChannelManager();
- ~ChannelManager();
-
- // Gets the ID for a given channel.
- //
- // Note: This is currently a static method and thus may be called under
- // |lock_|. If this is ever made non-static (i.e., made specific to a given
- // |ChannelManager|), those call sites may have to changed.
- static ChannelId GetChannelId(const Channel* channel) {
- return reinterpret_cast<ChannelId>(channel);
- }
-
- // Adds |channel| to the set of |Channel|s managed by this |ChannelManager|;
- // |channel_thread_task_runner| should be the task runner for |channel|'s
- // creation (a.k.a. I/O) thread.
- //
- // |channel| should either already be initialized or at least already have a
- // task posted to |channel_thread_task_runner| to initialize it. It should not
- // be managed by any |ChannelManager| yet.
- //
- // Returns the ID for the added channel.
- ChannelId AddChannel(
- scoped_refptr<Channel> channel,
- scoped_refptr<base::TaskRunner> channel_thread_task_runner);
-
- // Shuts down the channel specified by the given ID. It is up to the caller to
- // guarantee that this is only called once per channel (that was added using
- // |AddChannel()|).
- void ShutdownChannel(ChannelId channel_id);
-
- private:
- // Note: |Channel| methods should not be called under |lock_|.
- base::Lock lock_; // Protects the members below.
-
- base::hash_map<ChannelId, ChannelInfo> channel_infos_;
-
- DISALLOW_COPY_AND_ASSIGN(ChannelManager);
-};
-
-} // namespace system
-} // namespace mojo
-
-#endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_
diff --git a/mojo/edk/system/channel_unittest.cc b/mojo/edk/system/channel_unittest.cc
index 68b1315..f6cf896 100644
--- a/mojo/edk/system/channel_unittest.cc
+++ b/mojo/edk/system/channel_unittest.cc
@@ -104,8 +104,9 @@ TEST_F(ChannelTest, InitShutdown) {
EXPECT_EQ(TRISTATE_TRUE, init_result());
io_thread()->PostTaskAndWait(
- FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
- base::Unretained(this)));
+ FROM_HERE,
+ base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
+ base::Unretained(this)));
// Okay to destroy |Channel| on not-the-I/O-thread.
EXPECT_TRUE(channel()->HasOneRef());
@@ -202,8 +203,9 @@ TEST_F(ChannelTest, CloseBeforeRun) {
channel()->AttachAndRunEndpoint(channel_endpoint, true);
io_thread()->PostTaskAndWait(
- FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
- base::Unretained(this)));
+ FROM_HERE,
+ base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
+ base::Unretained(this)));
EXPECT_TRUE(channel()->HasOneRef());
}
@@ -271,8 +273,9 @@ TEST_F(ChannelTest, WaitAfterAttachRunAndShutdown) {
channel()->AttachAndRunEndpoint(channel_endpoint, true);
io_thread()->PostTaskAndWait(
- FROM_HERE, base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
- base::Unretained(this)));
+ FROM_HERE,
+ base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
+ base::Unretained(this)));
Waiter waiter;
waiter.Init();
diff --git a/mojo/edk/system/configuration.cc b/mojo/edk/system/configuration.cc
deleted file mode 100644
index 4756c99..0000000
--- a/mojo/edk/system/configuration.cc
+++ /dev/null
@@ -1,26 +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/edk/system/configuration.h"
-
-namespace mojo {
-namespace system {
-namespace internal {
-
-// These default values should be synced with the documentation in
-// mojo/edk/embedder/configuration.h.
-embedder::Configuration g_configuration = {
- 1000000, // max_handle_table_size
- 1000000, // max_mapping_table_sze
- 1000000, // max_wait_many_num_handles
- 4 * 1024 * 1024, // max_message_num_bytes
- 10000, // max_message_num_handles
- 256 * 1024 * 1024, // max_data_pipe_capacity_bytes
- 1024 * 1024, // default_data_pipe_capacity_bytes
- 16, // data_pipe_buffer_alignment_bytes
- 1024 * 1024 * 1024}; // max_shared_memory_num_bytes
-
-} // namespace internal
-} // namespace system
-} // namespace mojo
diff --git a/mojo/edk/system/configuration.h b/mojo/edk/system/configuration.h
deleted file mode 100644
index 007277a..0000000
--- a/mojo/edk/system/configuration.h
+++ /dev/null
@@ -1,31 +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.
-
-#ifndef MOJO_EDK_SYSTEM_CONFIGURATION_H_
-#define MOJO_EDK_SYSTEM_CONFIGURATION_H_
-
-#include "mojo/edk/embedder/configuration.h"
-#include "mojo/edk/system/system_impl_export.h"
-
-namespace mojo {
-namespace system {
-
-namespace internal {
-MOJO_SYSTEM_IMPL_EXPORT extern embedder::Configuration g_configuration;
-} // namespace internal
-
-MOJO_SYSTEM_IMPL_EXPORT inline const embedder::Configuration&
-GetConfiguration() {
- return internal::g_configuration;
-}
-
-MOJO_SYSTEM_IMPL_EXPORT inline embedder::Configuration*
-GetMutableConfiguration() {
- return &internal::g_configuration;
-}
-
-} // namespace system
-} // namespace mojo
-
-#endif // MOJO_EDK_SYSTEM_CONFIGURATION_H_
diff --git a/mojo/edk/system/constants.h b/mojo/edk/system/constants.h
new file mode 100644
index 0000000..23f35d8
--- /dev/null
+++ b/mojo/edk/system/constants.h
@@ -0,0 +1,48 @@
+// Copyright 2013 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_CONSTANTS_H_
+#define MOJO_EDK_SYSTEM_CONSTANTS_H_
+
+#include <stddef.h>
+
+namespace mojo {
+namespace system {
+
+// Maximum number of open (Mojo) handles.
+// TODO(vtl): This doesn't count "live" handles, some of which may live in
+// messages.
+const size_t kMaxHandleTableSize = 1000000;
+
+// Maximum number of active memory mappings.
+const size_t kMaxMappingTableSize = 1000000;
+
+const size_t kMaxWaitManyNumHandles = kMaxHandleTableSize;
+
+const size_t kMaxMessageNumBytes = 4 * 1024 * 1024;
+
+const size_t kMaxMessageNumHandles = 10000;
+
+// Maximum capacity of a data pipe, in bytes. This value must fit into a
+// |uint32_t|.
+// WARNING: If you bump it closer to 2^32, you must audit all the code to check
+// that we don't overflow (2^31 would definitely be risky; up to 2^30 is
+// probably okay).
+const size_t kMaxDataPipeCapacityBytes = 256 * 1024 * 1024; // 256 MB.
+
+const size_t kDefaultDataPipeCapacityBytes = 1024 * 1024; // 1 MB.
+
+// Alignment for the "start" of the data buffer used by data pipes. (The
+// alignment of elements will depend on this and the element size.)
+const size_t kDataPipeBufferAlignmentBytes = 16;
+
+// TODO(vtl): Set this hard limit appropriately (e.g., higher on 64-bit). (This
+// will also entail some auditing to make sure I'm not messing up my checks
+// anywhere.)
+const size_t kMaxSharedMemoryNumBytes = 1024 * 1024 * 1024; // 1 GB.
+
+} // namespace system
+} // namespace mojo
+
+#endif // MOJO_EDK_SYSTEM_CONSTANTS_H_
diff --git a/mojo/edk/system/core.cc b/mojo/edk/system/core.cc
index 27d33b2..c67a626 100644
--- a/mojo/edk/system/core.cc
+++ b/mojo/edk/system/core.cc
@@ -10,7 +10,7 @@
#include "base/time/time.h"
#include "mojo/edk/embedder/platform_shared_buffer.h"
#include "mojo/edk/embedder/platform_support.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/data_pipe.h"
#include "mojo/edk/system/data_pipe_consumer_dispatcher.h"
#include "mojo/edk/system/data_pipe_producer_dispatcher.h"
@@ -126,7 +126,11 @@ MojoResult Core::Wait(MojoHandle handle,
UserPointer<MojoHandleSignalsState> signals_state) {
uint32_t unused = static_cast<uint32_t>(-1);
HandleSignalsState hss;
- MojoResult rv = WaitManyInternal(&handle, &signals, 1, deadline, &unused,
+ MojoResult rv = WaitManyInternal(&handle,
+ &signals,
+ 1,
+ deadline,
+ &unused,
signals_state.IsNull() ? nullptr : &hss);
if (rv != MOJO_RESULT_INVALID_ARGUMENT && !signals_state.IsNull())
signals_state.Put(hss);
@@ -141,7 +145,7 @@ MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles,
UserPointer<MojoHandleSignalsState> signals_states) {
if (num_handles < 1)
return MOJO_RESULT_INVALID_ARGUMENT;
- if (num_handles > GetConfiguration().max_wait_many_num_handles)
+ if (num_handles > kMaxWaitManyNumHandles)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
UserPointer<const MojoHandle>::Reader handles_reader(handles, num_handles);
@@ -151,17 +155,23 @@ MojoResult Core::WaitMany(UserPointer<const MojoHandle> handles,
MojoResult rv;
if (signals_states.IsNull()) {
rv = WaitManyInternal(handles_reader.GetPointer(),
- signals_reader.GetPointer(), num_handles, deadline,
- &index, nullptr);
+ signals_reader.GetPointer(),
+ num_handles,
+ deadline,
+ &index,
+ nullptr);
} else {
UserPointer<MojoHandleSignalsState>::Writer signals_states_writer(
signals_states, num_handles);
// Note: The |reinterpret_cast| is safe, since |HandleSignalsState| is a
// subclass of |MojoHandleSignalsState| that doesn't add any data members.
rv = WaitManyInternal(handles_reader.GetPointer(),
- signals_reader.GetPointer(), num_handles, deadline,
- &index, reinterpret_cast<HandleSignalsState*>(
- signals_states_writer.GetPointer()));
+ signals_reader.GetPointer(),
+ num_handles,
+ deadline,
+ &index,
+ reinterpret_cast<HandleSignalsState*>(
+ signals_states_writer.GetPointer()));
if (rv != MOJO_RESULT_INVALID_ARGUMENT)
signals_states_writer.Commit();
}
@@ -236,7 +246,7 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
// validity, even for dispatchers that don't support |WriteMessage()| and will
// simply return failure unconditionally. It also breaks the usual
// left-to-right verification order of arguments.)
- if (num_handles > GetConfiguration().max_message_num_handles)
+ if (num_handles > kMaxMessageNumHandles)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
UserPointer<const MojoHandle>::Reader handles_reader(handles, num_handles);
@@ -253,9 +263,11 @@ MojoResult Core::WriteMessage(MojoHandle message_pipe_handle,
// handles from the handle table.
{
base::AutoLock locker(handle_table_lock_);
- MojoResult result = handle_table_.MarkBusyAndStartTransport(
- message_pipe_handle, handles_reader.GetPointer(), num_handles,
- &transports);
+ MojoResult result =
+ handle_table_.MarkBusyAndStartTransport(message_pipe_handle,
+ handles_reader.GetPointer(),
+ num_handles,
+ &transports);
if (result != MOJO_RESULT_OK)
return result;
}
@@ -296,12 +308,12 @@ MojoResult Core::ReadMessage(MojoHandle message_pipe_handle,
MojoResult rv;
if (num_handles_value == 0) {
// Easy case: won't receive any handles.
- rv = dispatcher->ReadMessage(bytes, num_bytes, nullptr, &num_handles_value,
- flags);
+ rv = dispatcher->ReadMessage(
+ bytes, num_bytes, nullptr, &num_handles_value, flags);
} else {
DispatcherVector dispatchers;
- rv = dispatcher->ReadMessage(bytes, num_bytes, &dispatchers,
- &num_handles_value, flags);
+ rv = dispatcher->ReadMessage(
+ bytes, num_bytes, &dispatchers, &num_handles_value, flags);
if (!dispatchers.empty()) {
DCHECK_EQ(rv, MOJO_RESULT_OK);
DCHECK(!num_handles.IsNull());
@@ -454,8 +466,8 @@ MojoResult Core::CreateSharedBuffer(
return result;
scoped_refptr<SharedBufferDispatcher> dispatcher;
- result = SharedBufferDispatcher::Create(platform_support(), validated_options,
- num_bytes, &dispatcher);
+ result = SharedBufferDispatcher::Create(
+ platform_support(), validated_options, num_bytes, &dispatcher);
if (result != MOJO_RESULT_OK) {
DCHECK(!dispatcher.get());
return result;
diff --git a/mojo/edk/system/core_test_base.cc b/mojo/edk/system/core_test_base.cc
index ea06c29..d1a1a24 100644
--- a/mojo/edk/system/core_test_base.cc
+++ b/mojo/edk/system/core_test_base.cc
@@ -10,7 +10,7 @@
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "mojo/edk/embedder/simple_platform_support.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/core.h"
#include "mojo/edk/system/dispatcher.h"
#include "mojo/edk/system/memory.h"
@@ -50,7 +50,7 @@ class MockDispatcher : public Dispatcher {
info_->IncrementWriteMessageCallCount();
lock().AssertAcquired();
- if (num_bytes > GetConfiguration().max_message_num_bytes)
+ if (num_bytes > kMaxMessageNumBytes)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
if (transports)
diff --git a/mojo/edk/system/core_unittest.cc b/mojo/edk/system/core_unittest.cc
index 96780f7..e6607df 100644
--- a/mojo/edk/system/core_unittest.cc
+++ b/mojo/edk/system/core_unittest.cc
@@ -42,34 +42,45 @@ TEST_F(CoreTest, Basic) {
EXPECT_EQ(0u, info.GetWriteMessageCallCount());
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h, NullUserPointer(), 0, NullUserPointer(), 0,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ NullUserPointer(),
+ 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, info.GetWriteMessageCallCount());
EXPECT_EQ(0u, info.GetReadMessageCallCount());
uint32_t num_bytes = 0;
- EXPECT_EQ(
- MOJO_RESULT_OK,
- core()->ReadMessage(h, NullUserPointer(), MakeUserPointer(&num_bytes),
- NullUserPointer(), NullUserPointer(),
- MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->ReadMessage(h,
+ NullUserPointer(),
+ MakeUserPointer(&num_bytes),
+ NullUserPointer(),
+ NullUserPointer(),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, info.GetReadMessageCallCount());
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(h, NullUserPointer(), NullUserPointer(),
- NullUserPointer(), NullUserPointer(),
+ core()->ReadMessage(h,
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(2u, info.GetReadMessageCallCount());
EXPECT_EQ(0u, info.GetWriteDataCallCount());
- EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
- core()->WriteData(h, NullUserPointer(), NullUserPointer(),
- MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_UNIMPLEMENTED,
+ core()->WriteData(
+ h, NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(1u, info.GetWriteDataCallCount());
EXPECT_EQ(0u, info.GetBeginWriteDataCallCount());
- EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
- core()->BeginWriteData(h, NullUserPointer(), NullUserPointer(),
- MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_UNIMPLEMENTED,
+ core()->BeginWriteData(
+ h, NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(1u, info.GetBeginWriteDataCallCount());
EXPECT_EQ(0u, info.GetEndWriteDataCallCount());
@@ -77,15 +88,17 @@ TEST_F(CoreTest, Basic) {
EXPECT_EQ(1u, info.GetEndWriteDataCallCount());
EXPECT_EQ(0u, info.GetReadDataCallCount());
- EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
- core()->ReadData(h, NullUserPointer(), NullUserPointer(),
- MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_UNIMPLEMENTED,
+ core()->ReadData(
+ h, NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(1u, info.GetReadDataCallCount());
EXPECT_EQ(0u, info.GetBeginReadDataCallCount());
- EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
- core()->BeginReadData(h, NullUserPointer(), NullUserPointer(),
- MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_UNIMPLEMENTED,
+ core()->BeginReadData(
+ h, NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(1u, info.GetBeginReadDataCallCount());
EXPECT_EQ(0u, info.GetEndReadDataCallCount());
@@ -94,7 +107,9 @@ TEST_F(CoreTest, Basic) {
EXPECT_EQ(0u, info.GetAddWaiterCallCount());
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE,
+ core()->Wait(h,
+ ~MOJO_HANDLE_SIGNAL_NONE,
+ MOJO_DEADLINE_INDEFINITE,
NullUserPointer()));
EXPECT_EQ(1u, info.GetAddWaiterCallCount());
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
@@ -102,7 +117,9 @@ TEST_F(CoreTest, Basic) {
EXPECT_EQ(2u, info.GetAddWaiterCallCount());
MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE,
+ core()->Wait(h,
+ ~MOJO_HANDLE_SIGNAL_NONE,
+ MOJO_DEADLINE_INDEFINITE,
MakeUserPointer(&hss)));
EXPECT_EQ(3u, info.GetAddWaiterCallCount());
EXPECT_EQ(0u, hss.satisfied_signals);
@@ -113,43 +130,51 @@ TEST_F(CoreTest, Basic) {
EXPECT_EQ(4u, info.GetAddWaiterCallCount());
hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- core()->Wait(h, ~MOJO_HANDLE_SIGNAL_NONE, 10 * 1000,
- MakeUserPointer(&hss)));
+ core()->Wait(
+ h, ~MOJO_HANDLE_SIGNAL_NONE, 10 * 1000, MakeUserPointer(&hss)));
EXPECT_EQ(5u, info.GetAddWaiterCallCount());
EXPECT_EQ(0u, hss.satisfied_signals);
EXPECT_EQ(0u, hss.satisfiable_signals);
MojoHandleSignals handle_signals = ~MOJO_HANDLE_SIGNAL_NONE;
- EXPECT_EQ(
- MOJO_RESULT_FAILED_PRECONDITION,
- core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- NullUserPointer()));
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core()->WaitMany(MakeUserPointer(&h),
+ MakeUserPointer(&handle_signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ NullUserPointer()));
EXPECT_EQ(6u, info.GetAddWaiterCallCount());
uint32_t result_index = static_cast<uint32_t>(-1);
- EXPECT_EQ(
- MOJO_RESULT_FAILED_PRECONDITION,
- core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index),
- NullUserPointer()));
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core()->WaitMany(MakeUserPointer(&h),
+ MakeUserPointer(&handle_signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&result_index),
+ NullUserPointer()));
EXPECT_EQ(7u, info.GetAddWaiterCallCount());
EXPECT_EQ(0u, result_index);
hss = kFullMojoHandleSignalsState;
- EXPECT_EQ(
- MOJO_RESULT_FAILED_PRECONDITION,
- core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- MakeUserPointer(&hss)));
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core()->WaitMany(MakeUserPointer(&h),
+ MakeUserPointer(&handle_signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ MakeUserPointer(&hss)));
EXPECT_EQ(8u, info.GetAddWaiterCallCount());
EXPECT_EQ(0u, hss.satisfied_signals);
EXPECT_EQ(0u, hss.satisfiable_signals);
result_index = static_cast<uint32_t>(-1);
hss = kFullMojoHandleSignalsState;
- EXPECT_EQ(
- MOJO_RESULT_FAILED_PRECONDITION,
- core()->WaitMany(MakeUserPointer(&h), MakeUserPointer(&handle_signals), 1,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index),
- MakeUserPointer(&hss)));
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core()->WaitMany(MakeUserPointer(&h),
+ MakeUserPointer(&handle_signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&result_index),
+ MakeUserPointer(&hss)));
EXPECT_EQ(9u, info.GetAddWaiterCallCount());
EXPECT_EQ(0u, result_index);
EXPECT_EQ(0u, hss.satisfied_signals);
@@ -186,16 +211,22 @@ TEST_F(CoreTest, InvalidArguments) {
// |Wait()|:
{
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->Wait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer()));
+ core()->Wait(MOJO_HANDLE_INVALID,
+ ~MOJO_HANDLE_SIGNAL_NONE,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer()));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->Wait(10, ~MOJO_HANDLE_SIGNAL_NONE,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer()));
+ core()->Wait(10,
+ ~MOJO_HANDLE_SIGNAL_NONE,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer()));
MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->Wait(MOJO_HANDLE_INVALID, ~MOJO_HANDLE_SIGNAL_NONE,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&hss)));
+ core()->Wait(MOJO_HANDLE_INVALID,
+ ~MOJO_HANDLE_SIGNAL_NONE,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&hss)));
// On invalid argument, it shouldn't modify the handle signals state.
EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
hss.satisfied_signals);
@@ -203,8 +234,10 @@ TEST_F(CoreTest, InvalidArguments) {
hss.satisfiable_signals);
hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->Wait(10, ~MOJO_HANDLE_SIGNAL_NONE,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&hss)));
+ core()->Wait(10,
+ ~MOJO_HANDLE_SIGNAL_NONE,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&hss)));
// On invalid argument, it shouldn't modify the handle signals state.
EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
hss.satisfied_signals);
@@ -217,14 +250,19 @@ TEST_F(CoreTest, InvalidArguments) {
MojoHandle handles[2] = {MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID};
MojoHandleSignals signals[2] = {~MOJO_HANDLE_SIGNAL_NONE,
~MOJO_HANDLE_SIGNAL_NONE};
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 0,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- NullUserPointer()));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(NullUserPointer(), MakeUserPointer(signals), 0,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
+ core()->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ 0,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ NullUserPointer()));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->WaitMany(NullUserPointer(),
+ MakeUserPointer(signals),
+ 0,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
NullUserPointer()));
// If |num_handles| is invalid, it should leave |result_index| and
// |signals_states| alone.
@@ -232,7 +270,9 @@ TEST_F(CoreTest, InvalidArguments) {
uint32_t result_index = 123;
MojoHandleSignalsState hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(NullUserPointer(), MakeUserPointer(signals), 0,
+ core()->WaitMany(NullUserPointer(),
+ MakeUserPointer(signals),
+ 0,
MOJO_DEADLINE_INDEFINITE,
MakeUserPointer(&result_index),
MakeUserPointer(&hss)));
@@ -243,23 +283,30 @@ TEST_F(CoreTest, InvalidArguments) {
hss.satisfiable_signals);
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(MakeUserPointer(handles), NullUserPointer(), 0,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
+ core()->WaitMany(MakeUserPointer(handles),
+ NullUserPointer(),
+ 0,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ NullUserPointer()));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
NullUserPointer()));
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 1,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- NullUserPointer()));
// But if a handle is bad, then it should set |result_index| but still leave
// |signals_states| alone.
result_index = static_cast<uint32_t>(-1);
hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(
- MakeUserPointer(handles), MakeUserPointer(signals), 1,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index),
- MakeUserPointer(&hss)));
+ core()->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&result_index),
+ MakeUserPointer(&hss)));
EXPECT_EQ(0u, result_index);
EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
hss.satisfied_signals);
@@ -272,10 +319,12 @@ TEST_F(CoreTest, InvalidArguments) {
result_index = static_cast<uint32_t>(-1);
hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- core()->WaitMany(
- MakeUserPointer(handles), MakeUserPointer(signals), 1,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index),
- MakeUserPointer(&hss)));
+ core()->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&result_index),
+ MakeUserPointer(&hss)));
EXPECT_EQ(0u, result_index);
EXPECT_EQ(0u, hss.satisfied_signals);
EXPECT_EQ(0u, hss.satisfiable_signals);
@@ -284,27 +333,33 @@ TEST_F(CoreTest, InvalidArguments) {
result_index = static_cast<uint32_t>(-1);
hss = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(
- MakeUserPointer(handles), MakeUserPointer(signals), 2,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index),
- MakeUserPointer(&hss)));
+ core()->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ 2,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&result_index),
+ MakeUserPointer(&hss)));
EXPECT_EQ(1u, result_index);
EXPECT_EQ(kFullMojoHandleSignalsState.satisfied_signals,
hss.satisfied_signals);
EXPECT_EQ(kFullMojoHandleSignalsState.satisfiable_signals,
hss.satisfiable_signals);
handles[1] = handles[0] + 1; // Invalid handle.
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 2,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- NullUserPointer()));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ 2,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ NullUserPointer()));
handles[1] = CreateMockHandle(&info[1]);
- EXPECT_EQ(
- MOJO_RESULT_FAILED_PRECONDITION,
- core()->WaitMany(MakeUserPointer(handles), MakeUserPointer(signals), 2,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- NullUserPointer()));
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core()->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ 2,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ NullUserPointer()));
// TODO(vtl): Test one where we get "failed precondition" only for the
// second handle (and the first one is valid to wait on).
@@ -321,8 +376,11 @@ TEST_F(CoreTest, InvalidArguments) {
// |num_handles|.
{
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->WriteMessage(MOJO_HANDLE_INVALID, NullUserPointer(), 0,
- NullUserPointer(), 0,
+ core()->WriteMessage(MOJO_HANDLE_INVALID,
+ NullUserPointer(),
+ 0,
+ NullUserPointer(),
+ 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
MockHandleInfo info;
@@ -334,41 +392,55 @@ TEST_F(CoreTest, InvalidArguments) {
// Note: This may return either |MOJO_RESULT_INVALID_ARGUMENT| or
// |MOJO_RESULT_RESOURCE_EXHAUSTED|, depending on whether it's plausible or
// not.
- EXPECT_NE(
- MOJO_RESULT_OK,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- std::numeric_limits<uint32_t>::max(),
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_NE(MOJO_RESULT_OK,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ std::numeric_limits<uint32_t>::max(),
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(0u, info.GetWriteMessageCallCount());
// Huge handle count (plausibly big).
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
core()->WriteMessage(
- h, NullUserPointer(), 0, MakeUserPointer(handles),
+ h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
std::numeric_limits<uint32_t>::max() / sizeof(handles[0]),
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(0u, info.GetWriteMessageCallCount());
// Invalid handle in |handles|.
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ 1,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(0u, info.GetWriteMessageCallCount());
// Two invalid handles in |handles|.
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- 2, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ 2,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(0u, info.GetWriteMessageCallCount());
// Can't send a handle over itself.
handles[0] = h;
- EXPECT_EQ(
- MOJO_RESULT_BUSY,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_BUSY,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ 1,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(0u, info.GetWriteMessageCallCount());
MockHandleInfo info2;
@@ -376,33 +448,45 @@ TEST_F(CoreTest, InvalidArguments) {
// This is "okay", but |MockDispatcher| doesn't implement it.
handles[0] = h2;
- EXPECT_EQ(
- MOJO_RESULT_UNIMPLEMENTED,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- 1, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ 1,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, info.GetWriteMessageCallCount());
// One of the |handles| is still invalid.
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- 2, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ 2,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, info.GetWriteMessageCallCount());
// One of the |handles| is the same as |handle|.
handles[1] = h;
- EXPECT_EQ(
- MOJO_RESULT_BUSY,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- 2, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_BUSY,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ 2,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, info.GetWriteMessageCallCount());
// Can't send a handle twice in the same message.
handles[1] = h2;
- EXPECT_EQ(
- MOJO_RESULT_BUSY,
- core()->WriteMessage(h, NullUserPointer(), 0, MakeUserPointer(handles),
- 2, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_BUSY,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ MakeUserPointer(handles),
+ 2,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, info.GetWriteMessageCallCount());
// Note: Since we never successfully sent anything with it, |h2| should
@@ -416,11 +500,13 @@ TEST_F(CoreTest, InvalidArguments) {
// Only check arguments checked by |Core|, namely |handle|, |handles|, and
// |num_handles|.
{
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- core()->ReadMessage(MOJO_HANDLE_INVALID, NullUserPointer(),
- NullUserPointer(), NullUserPointer(),
- NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ core()->ReadMessage(MOJO_HANDLE_INVALID,
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
+ MOJO_READ_MESSAGE_FLAG_NONE));
MockHandleInfo info;
MojoHandle h = CreateMockHandle(&info);
@@ -428,9 +514,12 @@ TEST_F(CoreTest, InvalidArguments) {
// Okay.
uint32_t handle_count = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h, NullUserPointer(), NullUserPointer(), NullUserPointer(),
- MakeUserPointer(&handle_count), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h,
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
+ MakeUserPointer(&handle_count),
+ MOJO_READ_MESSAGE_FLAG_NONE));
// Checked by |Core|, shouldn't go through to the dispatcher.
EXPECT_EQ(1u, info.GetReadMessageCallCount());
@@ -451,16 +540,20 @@ TEST_F(CoreTest, InvalidArgumentsDeath) {
{
MojoHandle handle = MOJO_HANDLE_INVALID;
MojoHandleSignals signals = ~MOJO_HANDLE_SIGNAL_NONE;
- EXPECT_DEATH_IF_SUPPORTED(
- core()->WaitMany(NullUserPointer(), MakeUserPointer(&signals), 1,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- NullUserPointer()),
- kMemoryCheckFailedRegex);
- EXPECT_DEATH_IF_SUPPORTED(
- core()->WaitMany(MakeUserPointer(&handle), NullUserPointer(), 1,
- MOJO_DEADLINE_INDEFINITE, NullUserPointer(),
- NullUserPointer()),
- kMemoryCheckFailedRegex);
+ EXPECT_DEATH_IF_SUPPORTED(core()->WaitMany(NullUserPointer(),
+ MakeUserPointer(&signals),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ NullUserPointer()),
+ kMemoryCheckFailedRegex);
+ EXPECT_DEATH_IF_SUPPORTED(core()->WaitMany(MakeUserPointer(&handle),
+ NullUserPointer(),
+ 1,
+ MOJO_DEADLINE_INDEFINITE,
+ NullUserPointer(),
+ NullUserPointer()),
+ kMemoryCheckFailedRegex);
// TODO(vtl): |result_index| and |signals_states| are optional. Test them
// with non-null invalid pointers?
}
@@ -469,16 +562,16 @@ TEST_F(CoreTest, InvalidArgumentsDeath) {
{
MojoHandle h;
EXPECT_DEATH_IF_SUPPORTED(
- core()->CreateMessagePipe(NullUserPointer(), NullUserPointer(),
- NullUserPointer()),
+ core()->CreateMessagePipe(
+ NullUserPointer(), NullUserPointer(), NullUserPointer()),
kMemoryCheckFailedRegex);
EXPECT_DEATH_IF_SUPPORTED(
- core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h),
- NullUserPointer()),
+ core()->CreateMessagePipe(
+ NullUserPointer(), MakeUserPointer(&h), NullUserPointer()),
kMemoryCheckFailedRegex);
EXPECT_DEATH_IF_SUPPORTED(
- core()->CreateMessagePipe(NullUserPointer(), NullUserPointer(),
- MakeUserPointer(&h)),
+ core()->CreateMessagePipe(
+ NullUserPointer(), NullUserPointer(), MakeUserPointer(&h)),
kMemoryCheckFailedRegex);
}
@@ -491,7 +584,11 @@ TEST_F(CoreTest, InvalidArgumentsDeath) {
// Null |handles| with nonzero |num_handles|.
EXPECT_DEATH_IF_SUPPORTED(
- core()->WriteMessage(h, NullUserPointer(), 0, NullUserPointer(), 1,
+ core()->WriteMessage(h,
+ NullUserPointer(),
+ 0,
+ NullUserPointer(),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE),
kMemoryCheckFailedRegex);
@@ -507,8 +604,11 @@ TEST_F(CoreTest, InvalidArgumentsDeath) {
uint32_t handle_count = 1;
EXPECT_DEATH_IF_SUPPORTED(
- core()->ReadMessage(h, NullUserPointer(), NullUserPointer(),
- NullUserPointer(), MakeUserPointer(&handle_count),
+ core()->ReadMessage(h,
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
+ MakeUserPointer(&handle_count),
MOJO_READ_MESSAGE_FLAG_NONE),
kMemoryCheckFailedRegex);
@@ -525,9 +625,10 @@ TEST_F(CoreTest, MessagePipe) {
MojoHandleSignalsState hss[2];
uint32_t result_index;
- EXPECT_EQ(MOJO_RESULT_OK,
- core()->CreateMessagePipe(NullUserPointer(), MakeUserPointer(&h[0]),
- MakeUserPointer(&h[1])));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ core()->CreateMessagePipe(
+ NullUserPointer(), MakeUserPointer(&h[0]), MakeUserPointer(&h[1])));
// Should get two distinct, valid handles.
EXPECT_NE(h[0], MOJO_HANDLE_INVALID);
EXPECT_NE(h[1], MOJO_HANDLE_INVALID);
@@ -539,10 +640,13 @@ TEST_F(CoreTest, MessagePipe) {
result_index = static_cast<uint32_t>(-1);
hss[0] = kEmptyMojoHandleSignalsState;
hss[1] = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(
- MOJO_RESULT_DEADLINE_EXCEEDED,
- core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2, 0,
- MakeUserPointer(&result_index), MakeUserPointer(hss)));
+ EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
+ core()->WaitMany(MakeUserPointer(h),
+ MakeUserPointer(signals),
+ 2,
+ 0,
+ MakeUserPointer(&result_index),
+ MakeUserPointer(hss)));
EXPECT_EQ(static_cast<uint32_t>(-1), result_index);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
@@ -554,25 +658,33 @@ TEST_F(CoreTest, MessagePipe) {
// Try to read anyway.
char buffer[1] = {'a'};
uint32_t buffer_size = 1;
- EXPECT_EQ(
- MOJO_RESULT_SHOULD_WAIT,
- core()->ReadMessage(h[0], UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), NullUserPointer(),
- NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
+ core()->ReadMessage(h[0],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ NullUserPointer(),
+ NullUserPointer(),
+ MOJO_READ_MESSAGE_FLAG_NONE));
// Check that it left its inputs alone.
EXPECT_EQ('a', buffer[0]);
EXPECT_EQ(1u, buffer_size);
// Both should be writable.
hss[0] = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(h[0], MOJO_HANDLE_SIGNAL_WRITABLE,
- 1000000000, MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(h[0],
+ MOJO_HANDLE_SIGNAL_WRITABLE,
+ 1000000000,
+ MakeUserPointer(&hss[0])));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss[0].satisfiable_signals);
hss[0] = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(h[1], MOJO_HANDLE_SIGNAL_WRITABLE,
- 1000000000, MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(h[1],
+ MOJO_HANDLE_SIGNAL_WRITABLE,
+ 1000000000,
+ MakeUserPointer(&hss[0])));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss[0].satisfiable_signals);
@@ -583,11 +695,13 @@ TEST_F(CoreTest, MessagePipe) {
result_index = static_cast<uint32_t>(-1);
hss[0] = kEmptyMojoHandleSignalsState;
hss[1] = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(
- MOJO_RESULT_OK,
- core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index),
- MakeUserPointer(hss)));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->WaitMany(MakeUserPointer(h),
+ MakeUserPointer(signals),
+ 2,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&result_index),
+ MakeUserPointer(hss)));
EXPECT_EQ(1u, result_index);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
@@ -598,10 +712,13 @@ TEST_F(CoreTest, MessagePipe) {
// Write to |h[1]|.
buffer[0] = 'b';
- EXPECT_EQ(
- MOJO_RESULT_OK,
- core()->WriteMessage(h[1], UserPointer<const void>(buffer), 1,
- NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->WriteMessage(h[1],
+ UserPointer<const void>(buffer),
+ 1,
+ NullUserPointer(),
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Check that |h[0]| is now readable.
signals[0] = MOJO_HANDLE_SIGNAL_READABLE;
@@ -609,11 +726,13 @@ TEST_F(CoreTest, MessagePipe) {
result_index = static_cast<uint32_t>(-1);
hss[0] = kEmptyMojoHandleSignalsState;
hss[1] = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(
- MOJO_RESULT_OK,
- core()->WaitMany(MakeUserPointer(h), MakeUserPointer(signals), 2,
- MOJO_DEADLINE_INDEFINITE, MakeUserPointer(&result_index),
- MakeUserPointer(hss)));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->WaitMany(MakeUserPointer(h),
+ MakeUserPointer(signals),
+ 2,
+ MOJO_DEADLINE_INDEFINITE,
+ MakeUserPointer(&result_index),
+ MakeUserPointer(hss)));
EXPECT_EQ(0u, result_index);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss[0].satisfied_signals);
@@ -626,38 +745,46 @@ TEST_F(CoreTest, MessagePipe) {
// Read from |h[0]|.
// First, get only the size.
buffer_size = 0;
- EXPECT_EQ(
- MOJO_RESULT_RESOURCE_EXHAUSTED,
- core()->ReadMessage(h[0], NullUserPointer(),
- MakeUserPointer(&buffer_size), NullUserPointer(),
- NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
+ core()->ReadMessage(h[0],
+ NullUserPointer(),
+ MakeUserPointer(&buffer_size),
+ NullUserPointer(),
+ NullUserPointer(),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(1u, buffer_size);
// Then actually read it.
buffer[0] = 'c';
buffer_size = 1;
- EXPECT_EQ(
- MOJO_RESULT_OK,
- core()->ReadMessage(h[0], UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), NullUserPointer(),
- NullUserPointer(), MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->ReadMessage(h[0],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ NullUserPointer(),
+ NullUserPointer(),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ('b', buffer[0]);
EXPECT_EQ(1u, buffer_size);
// |h[0]| should no longer be readable.
hss[0] = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED,
- core()->Wait(h[0], MOJO_HANDLE_SIGNAL_READABLE, 0,
- MakeUserPointer(&hss[0])));
+ EXPECT_EQ(
+ MOJO_RESULT_DEADLINE_EXCEEDED,
+ core()->Wait(
+ h[0], MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss[0])));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss[0].satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss[0].satisfiable_signals);
// Write to |h[0]|.
buffer[0] = 'd';
- EXPECT_EQ(
- MOJO_RESULT_OK,
- core()->WriteMessage(h[0], UserPointer<const void>(buffer), 1,
- NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->WriteMessage(h[0],
+ UserPointer<const void>(buffer),
+ 1,
+ NullUserPointer(),
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Close |h[0]|.
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[0]));
@@ -665,38 +792,51 @@ TEST_F(CoreTest, MessagePipe) {
// Check that |h[1]| is no longer writable (and will never be).
hss[0] = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- core()->Wait(h[1], MOJO_HANDLE_SIGNAL_WRITABLE, 1000000000,
+ core()->Wait(h[1],
+ MOJO_HANDLE_SIGNAL_WRITABLE,
+ 1000000000,
MakeUserPointer(&hss[0])));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfiable_signals);
// Check that |h[1]| is still readable (for the moment).
hss[0] = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(h[1], MOJO_HANDLE_SIGNAL_READABLE,
- 1000000000, MakeUserPointer(&hss[0])));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->Wait(h[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
+ MakeUserPointer(&hss[0])));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss[0].satisfiable_signals);
// Discard a message from |h[1]|.
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
- core()->ReadMessage(h[1], NullUserPointer(), NullUserPointer(),
- NullUserPointer(), NullUserPointer(),
+ core()->ReadMessage(h[1],
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
+ NullUserPointer(),
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
// |h[1]| is no longer readable (and will never be).
hss[0] = kFullMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- core()->Wait(h[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss[0])));
EXPECT_EQ(0u, hss[0].satisfied_signals);
EXPECT_EQ(0u, hss[0].satisfiable_signals);
// Try writing to |h[1]|.
buffer[0] = 'e';
- EXPECT_EQ(
- MOJO_RESULT_FAILED_PRECONDITION,
- core()->WriteMessage(h[1], UserPointer<const void>(buffer), 1,
- NullUserPointer(), 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
+ core()->WriteMessage(h[1],
+ UserPointer<const void>(buffer),
+ 1,
+ NullUserPointer(),
+ 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, core()->Close(h[1]));
}
@@ -723,12 +863,17 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
// Make sure that |h_passing[]| work properly.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
- kHelloSize, NullUserPointer(), 0,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ NullUserPointer(),
+ 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_passing[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -737,10 +882,12 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_passing[1], UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_passing[1],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kHelloSize, num_bytes);
EXPECT_STREQ(kHello, buffer);
EXPECT_EQ(0u, num_handles);
@@ -748,12 +895,18 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
// Make sure that you can't pass either of the message pipe's handles over
// itself.
EXPECT_EQ(MOJO_RESULT_BUSY,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
- kHelloSize, MakeUserPointer(&h_passing[0]), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ MakeUserPointer(&h_passing[0]),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
- kHelloSize, MakeUserPointer(&h_passing[1]), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ MakeUserPointer(&h_passing[1]),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
MojoHandle h_passed[2];
@@ -764,12 +917,17 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
// Make sure that |h_passed[]| work properly.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passed[0], UserPointer<const void>(kHello),
- kHelloSize, NullUserPointer(), 0,
+ core()->WriteMessage(h_passed[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ NullUserPointer(),
+ 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_passed[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_passed[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -778,22 +936,29 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_passed[1], UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_passed[1],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kHelloSize, num_bytes);
EXPECT_STREQ(kHello, buffer);
EXPECT_EQ(0u, num_handles);
// Send |h_passed[1]| from |h_passing[0]| to |h_passing[1]|.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld),
- kWorldSize, MakeUserPointer(&h_passed[1]), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kWorld),
+ kWorldSize,
+ MakeUserPointer(&h_passed[1]),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_passing[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -802,10 +967,12 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_passing[1], UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_passing[1],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kWorldSize, num_bytes);
EXPECT_STREQ(kWorld, buffer);
EXPECT_EQ(1u, num_handles);
@@ -824,12 +991,17 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
// Write to |h_passed[0]|. Should receive on |h_received|.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passed[0], UserPointer<const void>(kHello),
- kHelloSize, NullUserPointer(), 0,
+ core()->WriteMessage(h_passed[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ NullUserPointer(),
+ 0,
MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_received,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -838,10 +1010,12 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) {
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_received, UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_received,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kHelloSize, num_bytes);
EXPECT_STREQ(kHello, buffer);
EXPECT_EQ(0u, num_handles);
@@ -857,8 +1031,8 @@ TEST_F(CoreTest, DataPipe) {
MojoHandleSignalsState hss;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->CreateDataPipe(NullUserPointer(), MakeUserPointer(&ph),
- MakeUserPointer(&ch)));
+ core()->CreateDataPipe(
+ NullUserPointer(), MakeUserPointer(&ph), MakeUserPointer(&ch)));
// Should get two distinct, valid handles.
EXPECT_NE(ph, MOJO_HANDLE_INVALID);
EXPECT_NE(ch, MOJO_HANDLE_INVALID);
@@ -872,8 +1046,9 @@ TEST_F(CoreTest, DataPipe) {
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals);
hss = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(ph, MOJO_HANDLE_SIGNAL_WRITABLE, 0,
- MakeUserPointer(&hss)));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ core()->Wait(ph, MOJO_HANDLE_SIGNAL_WRITABLE, 0, MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfiable_signals);
@@ -895,15 +1070,17 @@ TEST_F(CoreTest, DataPipe) {
char elements[2] = {'A', 'B'};
uint32_t num_bytes = 2u;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteData(ph, UserPointer<const void>(elements),
+ core()->WriteData(ph,
+ UserPointer<const void>(elements),
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(2u, num_bytes);
// Consumer should now be readable.
hss = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0,
- MakeUserPointer(&hss)));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE, 0, MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
@@ -913,7 +1090,9 @@ TEST_F(CoreTest, DataPipe) {
num_bytes = 1u;
EXPECT_EQ(MOJO_RESULT_OK,
core()->ReadData(
- ch, UserPointer<void>(elements), MakeUserPointer(&num_bytes),
+ 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]);
@@ -922,9 +1101,11 @@ TEST_F(CoreTest, DataPipe) {
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));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ core()->ReadData(ch,
+ UserPointer<void>(elements),
+ MakeUserPointer(&num_bytes),
+ MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ('A', elements[0]);
EXPECT_EQ(-1, elements[1]);
@@ -932,7 +1113,8 @@ TEST_F(CoreTest, DataPipe) {
void* write_ptr = nullptr;
num_bytes = 0u;
ASSERT_EQ(MOJO_RESULT_OK,
- core()->BeginWriteData(ph, MakeUserPointer(&write_ptr),
+ core()->BeginWriteData(ph,
+ MakeUserPointer(&write_ptr),
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_NONE));
// We count on the default options providing a decent buffer size.
@@ -942,7 +1124,8 @@ TEST_F(CoreTest, DataPipe) {
elements[0] = 'X';
num_bytes = 1u;
EXPECT_EQ(MOJO_RESULT_BUSY,
- core()->WriteData(ph, UserPointer<const void>(elements),
+ core()->WriteData(ph,
+ UserPointer<const void>(elements),
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_NONE));
@@ -955,51 +1138,63 @@ TEST_F(CoreTest, DataPipe) {
// Query how much data we have.
num_bytes = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes),
+ core()->ReadData(ch,
+ NullUserPointer(),
+ MakeUserPointer(&num_bytes),
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(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,
core()->ReadData(
- ch, NullUserPointer(), MakeUserPointer(&num_bytes),
+ ch,
+ NullUserPointer(),
+ 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));
+ 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,
core()->ReadData(
- ch, NullUserPointer(), MakeUserPointer(&num_bytes),
+ ch,
+ NullUserPointer(),
+ MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_DISCARD | MOJO_READ_DATA_FLAG_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),
+ 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),
+ core()->BeginReadData(ch,
+ MakeUserPointer(&read_ptr),
MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
// Note: Count on still being able to do the contiguous read here.
@@ -1008,7 +1203,9 @@ TEST_F(CoreTest, DataPipe) {
// Discarding right now should fail.
num_bytes = 1;
EXPECT_EQ(MOJO_RESULT_BUSY,
- core()->ReadData(ch, NullUserPointer(), MakeUserPointer(&num_bytes),
+ core()->ReadData(ch,
+ NullUserPointer(),
+ MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_DISCARD));
// Actually check our data and end the two-phase read.
@@ -1061,17 +1258,22 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
MojoHandle ph, ch;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->CreateDataPipe(NullUserPointer(), MakeUserPointer(&ph),
- MakeUserPointer(&ch)));
+ core()->CreateDataPipe(
+ NullUserPointer(), MakeUserPointer(&ph), MakeUserPointer(&ch)));
// Send |ch| from |h_passing[0]| to |h_passing[1]|.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
- kHelloSize, MakeUserPointer(&ch), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ MakeUserPointer(&ch),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_passing[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -1080,10 +1282,12 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_passing[1], UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_passing[1],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kHelloSize, num_bytes);
EXPECT_STREQ(kHello, buffer);
EXPECT_EQ(1u, num_handles);
@@ -1103,18 +1307,22 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
// Write to |ph|. Should receive on |ch_received|.
num_bytes = kWorldSize;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteData(ph, UserPointer<const void>(kWorld),
+ core()->WriteData(ph,
+ UserPointer<const void>(kWorld),
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(ch_received,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
num_bytes = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadData(ch_received, UserPointer<void>(buffer),
+ core()->ReadData(ch_received,
+ UserPointer<void>(buffer),
MakeUserPointer(&num_bytes),
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kWorldSize, num_bytes);
@@ -1122,12 +1330,17 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
// Now pass |ph| in the same direction.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld),
- kWorldSize, MakeUserPointer(&ph), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kWorld),
+ kWorldSize,
+ MakeUserPointer(&ph),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_passing[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -1136,10 +1349,12 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_passing[1], UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_passing[1],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kWorldSize, num_bytes);
EXPECT_STREQ(kWorld, buffer);
EXPECT_EQ(1u, num_handles);
@@ -1159,18 +1374,22 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
// Write to |ph_received|. Should receive on |ch_received|.
num_bytes = kHelloSize;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteData(ph_received, UserPointer<const void>(kHello),
+ core()->WriteData(ph_received,
+ UserPointer<const void>(kHello),
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE));
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(ch_received, MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(ch_received,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
num_bytes = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadData(ch_received, UserPointer<void>(buffer),
+ core()->ReadData(ch_received,
+ UserPointer<void>(buffer),
MakeUserPointer(&num_bytes),
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kHelloSize, num_bytes);
@@ -1185,31 +1404,42 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
void* write_ptr = nullptr;
num_bytes = 0;
ASSERT_EQ(MOJO_RESULT_OK,
- core()->BeginWriteData(ph, MakeUserPointer(&write_ptr),
+ core()->BeginWriteData(ph,
+ MakeUserPointer(&write_ptr),
MakeUserPointer(&num_bytes),
MOJO_WRITE_DATA_FLAG_NONE));
ASSERT_GE(num_bytes, 1u);
EXPECT_EQ(MOJO_RESULT_BUSY,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
- kHelloSize, MakeUserPointer(&ph), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ MakeUserPointer(&ph),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// But |ch| can, even if |ph| is in a two-phase write.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
- kHelloSize, MakeUserPointer(&ch), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ MakeUserPointer(&ch),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
ch = MOJO_HANDLE_INVALID;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_passing[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
NullUserPointer()));
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_passing[1], UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_passing[1],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kHelloSize, num_bytes);
EXPECT_STREQ(kHello, buffer);
EXPECT_EQ(1u, num_handles);
@@ -1222,8 +1452,10 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
// Wait for |ch| to be readable.
hss = kEmptyMojoHandleSignalsState;
- EXPECT_EQ(MOJO_RESULT_OK, core()->Wait(ch, MOJO_HANDLE_SIGNAL_READABLE,
- 1000000000, MakeUserPointer(&hss)));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ core()->Wait(
+ ch, MOJO_HANDLE_SIGNAL_READABLE, 1000000000, MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
@@ -1231,23 +1463,32 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
const void* read_ptr = nullptr;
num_bytes = 1;
ASSERT_EQ(MOJO_RESULT_OK,
- core()->BeginReadData(ch, MakeUserPointer(&read_ptr),
+ core()->BeginReadData(ch,
+ MakeUserPointer(&read_ptr),
MakeUserPointer(&num_bytes),
MOJO_READ_DATA_FLAG_ALL_OR_NONE));
EXPECT_EQ(MOJO_RESULT_BUSY,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kHello),
- kHelloSize, MakeUserPointer(&ch), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kHello),
+ kHelloSize,
+ MakeUserPointer(&ch),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// But |ph| can, even if |ch| is in a two-phase read.
EXPECT_EQ(MOJO_RESULT_OK,
- core()->WriteMessage(h_passing[0], UserPointer<const void>(kWorld),
- kWorldSize, MakeUserPointer(&ph), 1,
+ core()->WriteMessage(h_passing[0],
+ UserPointer<const void>(kWorld),
+ kWorldSize,
+ MakeUserPointer(&ph),
+ 1,
MOJO_WRITE_MESSAGE_FLAG_NONE));
ph = MOJO_HANDLE_INVALID;
hss = kEmptyMojoHandleSignalsState;
EXPECT_EQ(MOJO_RESULT_OK,
- core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000,
+ core()->Wait(h_passing[1],
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 1000000000,
MakeUserPointer(&hss)));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -1256,10 +1497,12 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) {
num_bytes = kBufferSize;
num_handles = arraysize(handles);
EXPECT_EQ(MOJO_RESULT_OK,
- core()->ReadMessage(
- h_passing[1], UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), MakeUserPointer(handles),
- MakeUserPointer(&num_handles), MOJO_READ_MESSAGE_FLAG_NONE));
+ core()->ReadMessage(h_passing[1],
+ UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(&num_handles),
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kWorldSize, num_bytes);
EXPECT_STREQ(kWorld, buffer);
EXPECT_EQ(1u, num_handles);
diff --git a/mojo/edk/system/data_pipe.cc b/mojo/edk/system/data_pipe.cc
index cbacb89..e9525bc 100644
--- a/mojo/edk/system/data_pipe.cc
+++ b/mojo/edk/system/data_pipe.cc
@@ -10,7 +10,7 @@
#include <limits>
#include "base/logging.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/memory.h"
#include "mojo/edk/system/options_validation.h"
#include "mojo/edk/system/waiter_list.h"
@@ -19,15 +19,11 @@ namespace mojo {
namespace system {
// static
-MojoCreateDataPipeOptions DataPipe::GetDefaultCreateOptions() {
- MojoCreateDataPipeOptions result = {
- static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)),
- MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
- 1u,
- static_cast<uint32_t>(
- GetConfiguration().default_data_pipe_capacity_bytes)};
- return result;
-}
+const MojoCreateDataPipeOptions DataPipe::kDefaultCreateOptions = {
+ static_cast<uint32_t>(sizeof(MojoCreateDataPipeOptions)),
+ MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE,
+ 1u,
+ static_cast<uint32_t>(kDefaultDataPipeCapacityBytes)};
// static
MojoResult DataPipe::ValidateCreateOptions(
@@ -36,7 +32,7 @@ MojoResult DataPipe::ValidateCreateOptions(
const MojoCreateDataPipeOptionsFlags kKnownFlags =
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD;
- *out_options = GetDefaultCreateOptions();
+ *out_options = kDefaultCreateOptions;
if (in_options.IsNull())
return MOJO_RESULT_OK;
@@ -52,31 +48,28 @@ MojoResult DataPipe::ValidateCreateOptions(
// Checks for fields beyond |flags|:
- if (!OPTIONS_STRUCT_HAS_MEMBER(MojoCreateDataPipeOptions, element_num_bytes,
- reader))
+ if (!OPTIONS_STRUCT_HAS_MEMBER(
+ MojoCreateDataPipeOptions, element_num_bytes, reader))
return MOJO_RESULT_OK;
if (reader.options().element_num_bytes == 0)
return MOJO_RESULT_INVALID_ARGUMENT;
out_options->element_num_bytes = reader.options().element_num_bytes;
- if (!OPTIONS_STRUCT_HAS_MEMBER(MojoCreateDataPipeOptions, capacity_num_bytes,
- reader) ||
+ if (!OPTIONS_STRUCT_HAS_MEMBER(
+ MojoCreateDataPipeOptions, capacity_num_bytes, reader) ||
reader.options().capacity_num_bytes == 0) {
// Round the default capacity down to a multiple of the element size (but at
// least one element).
- size_t default_data_pipe_capacity_bytes =
- GetConfiguration().default_data_pipe_capacity_bytes;
out_options->capacity_num_bytes =
- std::max(static_cast<uint32_t>(default_data_pipe_capacity_bytes -
- (default_data_pipe_capacity_bytes %
+ std::max(static_cast<uint32_t>(kDefaultDataPipeCapacityBytes -
+ (kDefaultDataPipeCapacityBytes %
out_options->element_num_bytes)),
out_options->element_num_bytes);
return MOJO_RESULT_OK;
}
if (reader.options().capacity_num_bytes % out_options->element_num_bytes != 0)
return MOJO_RESULT_INVALID_ARGUMENT;
- if (reader.options().capacity_num_bytes >
- GetConfiguration().max_data_pipe_capacity_bytes)
+ if (reader.options().capacity_num_bytes > kMaxDataPipeCapacityBytes)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
out_options->capacity_num_bytes = reader.options().capacity_num_bytes;
@@ -155,8 +148,8 @@ MojoResult DataPipe::ProducerBeginWriteData(
return MOJO_RESULT_INVALID_ARGUMENT;
}
- MojoResult rv = ProducerBeginWriteDataImplNoLock(buffer, buffer_num_bytes,
- min_num_bytes_to_write);
+ MojoResult rv = ProducerBeginWriteDataImplNoLock(
+ buffer, buffer_num_bytes, min_num_bytes_to_write);
if (rv != MOJO_RESULT_OK)
return rv;
// Note: No need to awake producer waiters, even though we're going from
@@ -352,8 +345,8 @@ MojoResult DataPipe::ConsumerBeginReadData(
return MOJO_RESULT_INVALID_ARGUMENT;
}
- MojoResult rv = ConsumerBeginReadDataImplNoLock(buffer, buffer_num_bytes,
- min_num_bytes_to_read);
+ MojoResult rv = ConsumerBeginReadDataImplNoLock(
+ buffer, buffer_num_bytes, min_num_bytes_to_read);
if (rv != MOJO_RESULT_OK)
return rv;
DCHECK(consumer_in_two_phase_read_no_lock());
diff --git a/mojo/edk/system/data_pipe.h b/mojo/edk/system/data_pipe.h
index 767d405..d4afdda 100644
--- a/mojo/edk/system/data_pipe.h
+++ b/mojo/edk/system/data_pipe.h
@@ -35,7 +35,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe
// The default options for |MojoCreateDataPipe()|. (Real uses should obtain
// this via |ValidateCreateOptions()| with a null |in_options|; this is
// exposed directly for testing convenience.)
- static MojoCreateDataPipeOptions GetDefaultCreateOptions();
+ static const MojoCreateDataPipeOptions kDefaultCreateOptions;
// Validates and/or sets default options for |MojoCreateDataPipeOptions|. If
// non-null, |in_options| must point to a struct of at least
@@ -117,11 +117,12 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe
virtual void ConsumerCloseImplNoLock() = 0;
// |*num_bytes| will be a nonzero multiple of |element_num_bytes_|.
- virtual MojoResult ConsumerReadDataImplNoLock(UserPointer<void> elements,
- UserPointer<uint32_t> num_bytes,
- uint32_t max_num_bytes_to_read,
- uint32_t min_num_bytes_to_read,
- bool peek) = 0;
+ virtual MojoResult ConsumerReadDataImplNoLock(
+ UserPointer<void> elements,
+ UserPointer<uint32_t> num_bytes,
+ uint32_t max_num_bytes_to_read,
+ 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,
diff --git a/mojo/edk/system/data_pipe_consumer_dispatcher.cc b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
index 3c14f35..fa103c3 100644
--- a/mojo/edk/system/data_pipe_consumer_dispatcher.cc
+++ b/mojo/edk/system/data_pipe_consumer_dispatcher.cc
@@ -77,7 +77,9 @@ 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));
}
@@ -89,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_PEEK))
+ (flags & MOJO_READ_DATA_FLAG_QUERY) ||
+ (flags & MOJO_READ_DATA_FLAG_PEEK))
return MOJO_RESULT_INVALID_ARGUMENT;
return data_pipe_->ConsumerBeginReadData(
diff --git a/mojo/edk/system/data_pipe_unittest.cc b/mojo/edk/system/data_pipe_unittest.cc
index ad02222..8d2e4eb 100644
--- a/mojo/edk/system/data_pipe_unittest.cc
+++ b/mojo/edk/system/data_pipe_unittest.cc
@@ -9,7 +9,7 @@
#include <limits>
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace mojo {
@@ -28,8 +28,9 @@ void RevalidateCreateOptions(
// Nothing to check for flags.
EXPECT_GT(validated_options.element_num_bytes, 0u);
EXPECT_GT(validated_options.capacity_num_bytes, 0u);
- EXPECT_EQ(0u, validated_options.capacity_num_bytes %
- validated_options.element_num_bytes);
+ EXPECT_EQ(0u,
+ validated_options.capacity_num_bytes %
+ validated_options.element_num_bytes);
MojoCreateDataPipeOptions revalidated_options = {};
EXPECT_EQ(MOJO_RESULT_OK,
@@ -47,10 +48,10 @@ void RevalidateCreateOptions(
// checks done by |RevalidateCreateOptions()|.)
void CheckDefaultCapacity(const MojoCreateDataPipeOptions& validated_options) {
EXPECT_LE(validated_options.capacity_num_bytes,
- GetConfiguration().default_data_pipe_capacity_bytes);
+ kDefaultDataPipeCapacityBytes);
EXPECT_GT(validated_options.capacity_num_bytes +
validated_options.element_num_bytes,
- GetConfiguration().default_data_pipe_capacity_bytes);
+ kDefaultDataPipeCapacityBytes);
}
// Tests valid inputs to |ValidateCreateOptions()|.
@@ -58,8 +59,9 @@ TEST(DataPipeTest, ValidateCreateOptionsValid) {
// Default options.
{
MojoCreateDataPipeOptions validated_options = {};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- NullUserPointer(), &validated_options));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(NullUserPointer(), &validated_options));
RevalidateCreateOptions(validated_options);
CheckDefaultCapacity(validated_options);
}
diff --git a/mojo/edk/system/dispatcher.cc b/mojo/edk/system/dispatcher.cc
index c58da9f..5607125 100644
--- a/mojo/edk/system/dispatcher.cc
+++ b/mojo/edk/system/dispatcher.cc
@@ -5,7 +5,7 @@
#include "mojo/edk/system/dispatcher.h"
#include "base/logging.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/message_pipe_dispatcher.h"
#include "mojo/edk/system/platform_handle_dispatcher.h"
#include "mojo/edk/system/shared_buffer_dispatcher.h"
@@ -58,8 +58,8 @@ bool Dispatcher::TransportDataAccess::EndSerializeAndClose(
size_t* actual_size,
embedder::PlatformHandleVector* platform_handles) {
DCHECK(dispatcher);
- return dispatcher->EndSerializeAndClose(channel, destination, actual_size,
- platform_handles);
+ return dispatcher->EndSerializeAndClose(
+ channel, destination, actual_size, platform_handles);
}
// static
@@ -107,9 +107,8 @@ MojoResult Dispatcher::WriteMessage(
uint32_t num_bytes,
std::vector<DispatcherTransport>* transports,
MojoWriteMessageFlags flags) {
- DCHECK(!transports ||
- (transports->size() > 0 &&
- transports->size() < GetConfiguration().max_message_num_handles));
+ DCHECK(!transports || (transports->size() > 0 &&
+ transports->size() < kMaxMessageNumHandles));
base::AutoLock locker(lock_);
if (is_closed_)
@@ -130,8 +129,8 @@ MojoResult Dispatcher::ReadMessage(UserPointer<void> bytes,
if (is_closed_)
return MOJO_RESULT_INVALID_ARGUMENT;
- return ReadMessageImplNoLock(bytes, num_bytes, dispatchers, num_dispatchers,
- flags);
+ return ReadMessageImplNoLock(
+ bytes, num_bytes, dispatchers, num_dispatchers, flags);
}
MojoResult Dispatcher::WriteData(UserPointer<const void> elements,
@@ -474,8 +473,8 @@ bool Dispatcher::EndSerializeAndClose(
base::AutoLock locker(lock_);
#endif
- return EndSerializeAndCloseImplNoLock(channel, destination, actual_size,
- platform_handles);
+ return EndSerializeAndCloseImplNoLock(
+ channel, destination, actual_size, platform_handles);
}
// DispatcherTransport ---------------------------------------------------------
diff --git a/mojo/edk/system/dispatcher.h b/mojo/edk/system/dispatcher.h
index d4db54b..8d3edd4 100644
--- a/mojo/edk/system/dispatcher.h
+++ b/mojo/edk/system/dispatcher.h
@@ -48,7 +48,7 @@ namespace test {
// Test helper. We need to declare it here so we can friend it.
MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport
-DispatcherTryStartTransport(Dispatcher* dispatcher);
+ DispatcherTryStartTransport(Dispatcher* dispatcher);
} // namespace test
diff --git a/mojo/edk/system/dispatcher_unittest.cc b/mojo/edk/system/dispatcher_unittest.cc
index 0b15436..b5a05d4 100644
--- a/mojo/edk/system/dispatcher_unittest.cc
+++ b/mojo/edk/system/dispatcher_unittest.cc
@@ -44,24 +44,31 @@ TEST(DispatcherTest, Basic) {
EXPECT_EQ(Dispatcher::kTypeUnknown, d->GetType());
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->WriteMessage(NullUserPointer(), 0, nullptr,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ d->WriteMessage(
+ NullUserPointer(), 0, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->ReadMessage(NullUserPointer(), NullUserPointer(), nullptr,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->WriteData(NullUserPointer(), NullUserPointer(),
- MOJO_WRITE_DATA_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->BeginWriteData(NullUserPointer(), NullUserPointer(),
- MOJO_WRITE_DATA_FLAG_NONE));
+ d->ReadMessage(NullUserPointer(),
+ NullUserPointer(),
+ nullptr,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->WriteData(
+ NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->BeginWriteData(
+ NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->ReadData(NullUserPointer(), NullUserPointer(),
- MOJO_READ_DATA_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->BeginReadData(NullUserPointer(), NullUserPointer(),
- MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->ReadData(
+ NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->BeginReadData(
+ NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0));
Waiter w;
w.Init();
@@ -83,24 +90,31 @@ TEST(DispatcherTest, Basic) {
EXPECT_EQ(MOJO_RESULT_OK, d->Close());
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->WriteMessage(NullUserPointer(), 0, nullptr,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->ReadMessage(NullUserPointer(), NullUserPointer(), nullptr,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ d->WriteMessage(
+ NullUserPointer(), 0, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->WriteData(NullUserPointer(), NullUserPointer(),
- MOJO_WRITE_DATA_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->BeginWriteData(NullUserPointer(), NullUserPointer(),
- MOJO_WRITE_DATA_FLAG_NONE));
+ d->ReadMessage(NullUserPointer(),
+ NullUserPointer(),
+ nullptr,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->WriteData(
+ NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->BeginWriteData(
+ NullUserPointer(), NullUserPointer(), MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndWriteData(0));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->ReadData(NullUserPointer(), NullUserPointer(),
- MOJO_READ_DATA_FLAG_NONE));
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- d->BeginReadData(NullUserPointer(), NullUserPointer(),
- MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->ReadData(
+ NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ d->BeginReadData(
+ NullUserPointer(), NullUserPointer(), MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, d->EndReadData(0));
hss = HandleSignalsState();
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
@@ -158,40 +172,45 @@ class ThreadSafetyStressThread : public base::SimpleThread {
break;
}
case WRITE_MESSAGE:
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- dispatcher_->WriteMessage(NullUserPointer(), 0, nullptr,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ dispatcher_->WriteMessage(
+ NullUserPointer(), 0, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
break;
case READ_MESSAGE:
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- dispatcher_->ReadMessage(NullUserPointer(), NullUserPointer(),
- nullptr, nullptr,
+ dispatcher_->ReadMessage(NullUserPointer(),
+ NullUserPointer(),
+ nullptr,
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
break;
case WRITE_DATA:
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- dispatcher_->WriteData(NullUserPointer(), NullUserPointer(),
+ dispatcher_->WriteData(NullUserPointer(),
+ NullUserPointer(),
MOJO_WRITE_DATA_FLAG_NONE));
break;
case BEGIN_WRITE_DATA:
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- dispatcher_->BeginWriteData(NullUserPointer(), NullUserPointer(),
- MOJO_WRITE_DATA_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ dispatcher_->BeginWriteData(NullUserPointer(),
+ NullUserPointer(),
+ MOJO_WRITE_DATA_FLAG_NONE));
break;
case END_WRITE_DATA:
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndWriteData(0));
break;
case READ_DATA:
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- dispatcher_->ReadData(NullUserPointer(), NullUserPointer(),
+ dispatcher_->ReadData(NullUserPointer(),
+ NullUserPointer(),
MOJO_READ_DATA_FLAG_NONE));
break;
case BEGIN_READ_DATA:
- EXPECT_EQ(
- MOJO_RESULT_INVALID_ARGUMENT,
- dispatcher_->BeginReadData(NullUserPointer(), NullUserPointer(),
- MOJO_READ_DATA_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
+ dispatcher_->BeginReadData(NullUserPointer(),
+ NullUserPointer(),
+ MOJO_READ_DATA_FLAG_NONE));
break;
case END_READ_DATA:
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dispatcher_->EndReadData(0));
diff --git a/mojo/edk/embedder/entrypoints.cc b/mojo/edk/system/entrypoints.cc
index 7b2e53f..7ec5bb4 100644
--- a/mojo/edk/embedder/entrypoints.cc
+++ b/mojo/edk/system/entrypoints.cc
@@ -2,16 +2,35 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/edk/embedder/embedder_internal.h"
+#include "mojo/edk/system/entrypoints.h"
+
+#include "base/logging.h"
#include "mojo/edk/system/core.h"
#include "mojo/public/c/system/buffer.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/functions.h"
#include "mojo/public/c/system/message_pipe.h"
-using mojo::embedder::internal::g_core;
+static mojo::system::Core* g_core = nullptr;
+
using mojo::system::MakeUserPointer;
+namespace mojo {
+namespace system {
+namespace entrypoints {
+
+void SetCore(Core* core) {
+ g_core = core;
+}
+
+Core* GetCore() {
+ return g_core;
+}
+
+} // namespace entrypoints
+} // namepace system
+} // namespace mojo
+
// Definitions of the system functions.
extern "C" {
MojoTimeTicks MojoGetTimeTicksNow() {
@@ -25,8 +44,8 @@ MojoResult MojoClose(MojoHandle handle) {
MojoResult MojoWait(MojoHandle handle,
MojoHandleSignals signals,
MojoDeadline deadline) {
- return g_core->Wait(handle, signals, deadline,
- mojo::system::NullUserPointer());
+ return g_core->Wait(
+ handle, signals, deadline, mojo::system::NullUserPointer());
}
MojoResult MojoWaitMany(const MojoHandle* handles,
@@ -34,9 +53,12 @@ MojoResult MojoWaitMany(const MojoHandle* handles,
uint32_t num_handles,
MojoDeadline deadline) {
uint32_t result_index = static_cast<uint32_t>(-1);
- MojoResult result = g_core->WaitMany(
- MakeUserPointer(handles), MakeUserPointer(signals), num_handles, deadline,
- MakeUserPointer(&result_index), mojo::system::NullUserPointer());
+ MojoResult result = g_core->WaitMany(MakeUserPointer(handles),
+ MakeUserPointer(signals),
+ num_handles,
+ deadline,
+ MakeUserPointer(&result_index),
+ mojo::system::NullUserPointer());
return (result == MOJO_RESULT_OK) ? static_cast<MojoResult>(result_index)
: result;
}
@@ -55,8 +77,11 @@ MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
const MojoHandle* handles,
uint32_t num_handles,
MojoWriteMessageFlags flags) {
- return g_core->WriteMessage(message_pipe_handle, MakeUserPointer(bytes),
- num_bytes, MakeUserPointer(handles), num_handles,
+ return g_core->WriteMessage(message_pipe_handle,
+ MakeUserPointer(bytes),
+ num_bytes,
+ MakeUserPointer(handles),
+ num_handles,
flags);
}
@@ -66,9 +91,12 @@ MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
MojoHandle* handles,
uint32_t* num_handles,
MojoReadMessageFlags flags) {
- return g_core->ReadMessage(
- message_pipe_handle, MakeUserPointer(bytes), MakeUserPointer(num_bytes),
- MakeUserPointer(handles), MakeUserPointer(num_handles), flags);
+ return g_core->ReadMessage(message_pipe_handle,
+ MakeUserPointer(bytes),
+ MakeUserPointer(num_bytes),
+ MakeUserPointer(handles),
+ MakeUserPointer(num_handles),
+ flags);
}
MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options,
@@ -83,8 +111,10 @@ MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_elements,
MojoWriteDataFlags flags) {
- return g_core->WriteData(data_pipe_producer_handle, MakeUserPointer(elements),
- MakeUserPointer(num_elements), flags);
+ return g_core->WriteData(data_pipe_producer_handle,
+ MakeUserPointer(elements),
+ MakeUserPointer(num_elements),
+ flags);
}
MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
@@ -93,7 +123,8 @@ MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
MojoWriteDataFlags flags) {
return g_core->BeginWriteData(data_pipe_producer_handle,
MakeUserPointer(buffer),
- MakeUserPointer(buffer_num_elements), flags);
+ MakeUserPointer(buffer_num_elements),
+ flags);
}
MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle,
@@ -105,8 +136,10 @@ MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
void* elements,
uint32_t* num_elements,
MojoReadDataFlags flags) {
- return g_core->ReadData(data_pipe_consumer_handle, MakeUserPointer(elements),
- MakeUserPointer(num_elements), flags);
+ return g_core->ReadData(data_pipe_consumer_handle,
+ MakeUserPointer(elements),
+ MakeUserPointer(num_elements),
+ flags);
}
MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
@@ -115,7 +148,8 @@ MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
MojoReadDataFlags flags) {
return g_core->BeginReadData(data_pipe_consumer_handle,
MakeUserPointer(buffer),
- MakeUserPointer(buffer_num_elements), flags);
+ MakeUserPointer(buffer_num_elements),
+ flags);
}
MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle,
@@ -127,7 +161,8 @@ MojoResult MojoCreateSharedBuffer(
const struct MojoCreateSharedBufferOptions* options,
uint64_t num_bytes,
MojoHandle* shared_buffer_handle) {
- return g_core->CreateSharedBuffer(MakeUserPointer(options), num_bytes,
+ return g_core->CreateSharedBuffer(MakeUserPointer(options),
+ num_bytes,
MakeUserPointer(shared_buffer_handle));
}
@@ -135,7 +170,8 @@ MojoResult MojoDuplicateBufferHandle(
MojoHandle buffer_handle,
const struct MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle) {
- return g_core->DuplicateBufferHandle(buffer_handle, MakeUserPointer(options),
+ return g_core->DuplicateBufferHandle(buffer_handle,
+ MakeUserPointer(options),
MakeUserPointer(new_buffer_handle));
}
@@ -144,8 +180,8 @@ MojoResult MojoMapBuffer(MojoHandle buffer_handle,
uint64_t num_bytes,
void** buffer,
MojoMapBufferFlags flags) {
- return g_core->MapBuffer(buffer_handle, offset, num_bytes,
- MakeUserPointer(buffer), flags);
+ return g_core->MapBuffer(
+ buffer_handle, offset, num_bytes, MakeUserPointer(buffer), flags);
}
MojoResult MojoUnmapBuffer(void* buffer) {
diff --git a/mojo/edk/system/entrypoints.h b/mojo/edk/system/entrypoints.h
new file mode 100644
index 0000000..46c41b4
--- /dev/null
+++ b/mojo/edk/system/entrypoints.h
@@ -0,0 +1,24 @@
+// 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_ENTRYPOINTS_H_
+#define MOJO_EDK_SYSTEM_ENTRYPOINTS_H_
+
+namespace mojo {
+namespace system {
+
+class Core;
+
+namespace entrypoints {
+
+// Sets the instance of Core to be used by system functions.
+void SetCore(Core* core);
+// Gets the instance of Core to be used by system functions.
+Core* GetCore();
+
+} // namespace entrypoints
+} // namepace system
+} // namespace mojo
+
+#endif // MOJO_EDK_SYSTEM_ENTRYPOINTS_H_
diff --git a/mojo/edk/system/handle_table.cc b/mojo/edk/system/handle_table.cc
index 05d5260..9c01230 100644
--- a/mojo/edk/system/handle_table.cc
+++ b/mojo/edk/system/handle_table.cc
@@ -4,10 +4,9 @@
#include "mojo/edk/system/handle_table.h"
-#include <limits>
#include "base/logging.h"
#include "base/macros.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/dispatcher.h"
namespace mojo {
@@ -60,7 +59,7 @@ MojoResult HandleTable::GetAndRemoveDispatcher(
MojoHandle HandleTable::AddDispatcher(
const scoped_refptr<Dispatcher>& dispatcher) {
- if (handle_to_entry_map_.size() >= GetConfiguration().max_handle_table_size)
+ if (handle_to_entry_map_.size() >= kMaxHandleTableSize)
return MOJO_HANDLE_INVALID;
return AddDispatcherNoSizeCheck(dispatcher);
}
@@ -68,8 +67,7 @@ MojoHandle HandleTable::AddDispatcher(
std::pair<MojoHandle, MojoHandle> HandleTable::AddDispatcherPair(
const scoped_refptr<Dispatcher>& dispatcher0,
const scoped_refptr<Dispatcher>& dispatcher1) {
- if (handle_to_entry_map_.size() + 1 >=
- GetConfiguration().max_handle_table_size)
+ if (handle_to_entry_map_.size() + 1 >= kMaxHandleTableSize)
return std::make_pair(MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID);
return std::make_pair(AddDispatcherNoSizeCheck(dispatcher0),
AddDispatcherNoSizeCheck(dispatcher1));
@@ -77,17 +75,17 @@ std::pair<MojoHandle, MojoHandle> HandleTable::AddDispatcherPair(
bool HandleTable::AddDispatcherVector(const DispatcherVector& dispatchers,
MojoHandle* handles) {
- size_t max_message_num_handles = GetConfiguration().max_message_num_handles;
- size_t max_handle_table_size = GetConfiguration().max_handle_table_size;
-
- DCHECK_LE(dispatchers.size(), max_message_num_handles);
+ DCHECK_LE(dispatchers.size(), kMaxMessageNumHandles);
DCHECK(handles);
- DCHECK_LT(
- static_cast<uint64_t>(max_handle_table_size) + max_message_num_handles,
- std::numeric_limits<size_t>::max())
- << "Addition may overflow";
-
- if (handle_to_entry_map_.size() + dispatchers.size() > max_handle_table_size)
+ // TODO(vtl): |std::numeric_limits<size_t>::max()| isn't a compile-time
+ // expression in C++03.
+ static_assert(
+ static_cast<uint64_t>(kMaxHandleTableSize) + kMaxMessageNumHandles <
+ (sizeof(size_t) == 8 ? kuint64max
+ : static_cast<uint64_t>(kuint32max)),
+ "Addition may overflow");
+
+ if (handle_to_entry_map_.size() + dispatchers.size() > kMaxHandleTableSize)
return false;
for (size_t i = 0; i < dispatchers.size(); i++) {
@@ -108,7 +106,7 @@ MojoResult HandleTable::MarkBusyAndStartTransport(
std::vector<DispatcherTransport>* transports) {
DCHECK_NE(disallowed_handle, MOJO_HANDLE_INVALID);
DCHECK(handles);
- DCHECK_LE(num_handles, GetConfiguration().max_message_num_handles);
+ DCHECK_LE(num_handles, kMaxMessageNumHandles);
DCHECK(transports);
DCHECK_EQ(transports->size(), num_handles);
@@ -189,8 +187,7 @@ MojoResult HandleTable::MarkBusyAndStartTransport(
MojoHandle HandleTable::AddDispatcherNoSizeCheck(
const scoped_refptr<Dispatcher>& dispatcher) {
DCHECK(dispatcher.get());
- DCHECK_LT(handle_to_entry_map_.size(),
- GetConfiguration().max_handle_table_size);
+ DCHECK_LT(handle_to_entry_map_.size(), kMaxHandleTableSize);
DCHECK_NE(next_handle_, MOJO_HANDLE_INVALID);
// TODO(vtl): Maybe we want to do something different/smarter. (Or maybe try
@@ -215,7 +212,7 @@ MojoHandle HandleTable::AddDispatcherNoSizeCheck(
void HandleTable::RemoveBusyHandles(const MojoHandle* handles,
uint32_t num_handles) {
DCHECK(handles);
- DCHECK_LE(num_handles, GetConfiguration().max_message_num_handles);
+ DCHECK_LE(num_handles, kMaxMessageNumHandles);
for (uint32_t i = 0; i < num_handles; i++) {
HandleToEntryMap::iterator it = handle_to_entry_map_.find(handles[i]);
@@ -229,7 +226,7 @@ void HandleTable::RemoveBusyHandles(const MojoHandle* handles,
void HandleTable::RestoreBusyHandles(const MojoHandle* handles,
uint32_t num_handles) {
DCHECK(handles);
- DCHECK_LE(num_handles, GetConfiguration().max_message_num_handles);
+ DCHECK_LE(num_handles, kMaxMessageNumHandles);
for (uint32_t i = 0; i < num_handles; i++) {
HandleToEntryMap::iterator it = handle_to_entry_map_.find(handles[i]);
diff --git a/mojo/edk/system/local_data_pipe.cc b/mojo/edk/system/local_data_pipe.cc
index 177b238..fdfaf28 100644
--- a/mojo/edk/system/local_data_pipe.cc
+++ b/mojo/edk/system/local_data_pipe.cc
@@ -15,7 +15,7 @@
#include <algorithm>
#include "base/logging.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
namespace mojo {
namespace system {
@@ -301,8 +301,7 @@ void LocalDataPipe::EnsureBufferNoLock() {
if (buffer_)
return;
buffer_.reset(static_cast<char*>(
- base::AlignedAlloc(capacity_num_bytes(),
- GetConfiguration().data_pipe_buffer_alignment_bytes)));
+ base::AlignedAlloc(capacity_num_bytes(), kDataPipeBufferAlignmentBytes)));
}
void LocalDataPipe::DestroyBufferNoLock() {
diff --git a/mojo/edk/system/local_data_pipe.h b/mojo/edk/system/local_data_pipe.h
index abe3a46..c98cb7e 100644
--- a/mojo/edk/system/local_data_pipe.h
+++ b/mojo/edk/system/local_data_pipe.h
@@ -44,11 +44,12 @@ class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipe : public DataPipe {
uint32_t num_bytes_written) override;
HandleSignalsState ProducerGetHandleSignalsStateImplNoLock() const override;
void ConsumerCloseImplNoLock() override;
- MojoResult ConsumerReadDataImplNoLock(UserPointer<void> elements,
- UserPointer<uint32_t> num_bytes,
- uint32_t max_num_bytes_to_read,
- uint32_t min_num_bytes_to_read,
- bool peek) override;
+ MojoResult ConsumerReadDataImplNoLock(
+ UserPointer<void> elements,
+ UserPointer<uint32_t> num_bytes,
+ uint32_t max_num_bytes_to_read,
+ uint32_t min_num_bytes_to_read,
+ bool peek) override;
MojoResult ConsumerDiscardDataImplNoLock(
UserPointer<uint32_t> num_bytes,
uint32_t max_num_bytes_to_discard,
diff --git a/mojo/edk/system/local_data_pipe_unittest.cc b/mojo/edk/system/local_data_pipe_unittest.cc
index 9ba6b21..e8bc716 100644
--- a/mojo/edk/system/local_data_pipe_unittest.cc
+++ b/mojo/edk/system/local_data_pipe_unittest.cc
@@ -25,8 +25,9 @@ TEST(LocalDataPipeTest, Creation) {
{
// Get default options.
MojoCreateDataPipeOptions default_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- NullUserPointer(), &default_options));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(NullUserPointer(), &default_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(default_options));
dp->ProducerClose();
dp->ConsumerClose();
@@ -104,8 +105,9 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
@@ -114,9 +116,12 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
// Try reading; nothing there yet.
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, false));
+ EXPECT_EQ(
+ MOJO_RESULT_SHOULD_WAIT,
+ dp->ConsumerReadData(UserPointer<void>(elements),
+ MakeUserPointer(&num_bytes),
+ false,
+ false));
// Query; nothing there yet.
num_bytes = 0;
@@ -130,9 +135,12 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
// Read with invalid |num_bytes|.
num_bytes = sizeof(elements[0]) + 1;
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- dp->ConsumerReadData(UserPointer<void>(elements),
- MakeUserPointer(&num_bytes), false, false));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ dp->ConsumerReadData(UserPointer<void>(elements),
+ MakeUserPointer(&num_bytes),
+ false,
+ false));
// Write two elements.
elements[0] = 123;
@@ -140,7 +148,8 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
// It should have written everything (even without "all or none").
EXPECT_EQ(2u * sizeof(elements[0]), num_bytes);
@@ -153,9 +162,12 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
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, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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]);
@@ -169,9 +181,12 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
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(
+ 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]);
@@ -185,9 +200,12 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
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, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OUT_OF_RANGE,
+ dp->ConsumerReadData(UserPointer<void>(elements),
+ MakeUserPointer(&num_bytes),
+ true,
+ false));
EXPECT_EQ(-1, elements[0]);
EXPECT_EQ(-1, elements[1]);
@@ -195,9 +213,12 @@ TEST(LocalDataPipeTest, SimpleReadWrite) {
elements[0] = -1;
elements[1] = -1;
num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerReadData(UserPointer<void>(elements),
- MakeUserPointer(&num_bytes), false, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerReadData(UserPointer<void>(elements),
+ MakeUserPointer(&num_bytes),
+ false,
+ false));
EXPECT_EQ(456, elements[0]);
EXPECT_EQ(-1, elements[1]);
@@ -224,8 +245,9 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
2 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
Waiter waiter;
@@ -253,7 +275,8 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), true));
+ MakeUserPointer(&num_bytes),
+ true));
EXPECT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes);
// Adding a waiter should now succeed.
@@ -272,9 +295,12 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
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(
+ 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]);
@@ -301,9 +327,12 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
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, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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]);
@@ -320,14 +349,15 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
void* buffer = nullptr;
num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0]));
EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&buffer),
- MakeUserPointer(&num_bytes), false));
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&buffer), MakeUserPointer(&num_bytes), false));
EXPECT_TRUE(buffer);
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
static_cast<int32_t*>(buffer)[0] = 789;
- EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(static_cast<uint32_t>(
- 1u * sizeof(elements[0]))));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dp->ProducerEndWriteData(
+ static_cast<uint32_t>(1u * sizeof(elements[0]))));
// Add a waiter.
waiter.Init();
@@ -338,9 +368,10 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
// Read one element, using a two-phase read.
const void* read_buffer = nullptr;
num_bytes = 0u;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_buffer), MakeUserPointer(&num_bytes), false));
EXPECT_TRUE(read_buffer);
// Since we only read one element (after having written three in all), the
// two-phase read should only allow us to read one. This checks an
@@ -364,7 +395,8 @@ TEST(LocalDataPipeTest, BasicProducerWaiting) {
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
// Add a waiter.
@@ -395,8 +427,9 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
{
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
@@ -416,8 +449,8 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
// Not yet readable.
waiter.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 34,
- nullptr));
+ dp->ConsumerAddWaiter(
+ &waiter, MOJO_HANDLE_SIGNAL_READABLE, 34, nullptr));
EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, nullptr));
hss = HandleSignalsState();
dp->ConsumerRemoveWaiter(&waiter, &hss);
@@ -429,7 +462,8 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
uint32_t num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), true));
+ MakeUserPointer(&num_bytes),
+ true));
// Should already be readable.
waiter.Init();
@@ -459,9 +493,12 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
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(
+ 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]);
@@ -479,9 +516,12 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
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, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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]);
@@ -489,8 +529,8 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
// Adding a waiter should now succeed.
waiter.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 90,
- nullptr));
+ dp->ConsumerAddWaiter(
+ &waiter, MOJO_HANDLE_SIGNAL_READABLE, 90, nullptr));
// Write one element.
elements[0] = 789;
@@ -498,7 +538,8 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
num_bytes = static_cast<uint32_t>(1u * sizeof(elements[0]));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), true));
+ MakeUserPointer(&num_bytes),
+ true));
// Waiting should now succeed.
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(1000, &context));
@@ -524,9 +565,12 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
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, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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]);
@@ -557,15 +601,16 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
// Request room for three (but we'll only write two).
uint32_t num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0]));
EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&buffer),
- MakeUserPointer(&num_bytes), true));
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&buffer), MakeUserPointer(&num_bytes), true));
EXPECT_TRUE(buffer);
EXPECT_GE(num_bytes, static_cast<uint32_t>(3u * sizeof(elements[0])));
elements = static_cast<int32_t*>(buffer);
elements[0] = 123;
elements[1] = 456;
- EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(static_cast<uint32_t>(
- 2u * sizeof(elements[0]))));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dp->ProducerEndWriteData(
+ static_cast<uint32_t>(2u * sizeof(elements[0]))));
// Should already be readable.
waiter.Init();
@@ -580,15 +625,17 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
// Request two in all-or-none mode, but only read one.
const void* read_buffer = nullptr;
num_bytes = static_cast<uint32_t>(2u * sizeof(elements[0]));
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_buffer), MakeUserPointer(&num_bytes), true));
EXPECT_TRUE(read_buffer);
EXPECT_EQ(static_cast<uint32_t>(2u * sizeof(elements[0])), num_bytes);
const int32_t* read_elements = static_cast<const int32_t*>(read_buffer);
EXPECT_EQ(123, read_elements[0]);
- EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(static_cast<uint32_t>(
- 1u * sizeof(elements[0]))));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dp->ConsumerEndReadData(
+ static_cast<uint32_t>(1u * sizeof(elements[0]))));
// Should still be readable.
waiter.Init();
@@ -603,21 +650,23 @@ TEST(LocalDataPipeTest, BasicConsumerWaiting) {
// Request three, but not in all-or-none mode.
read_buffer = nullptr;
num_bytes = static_cast<uint32_t>(3u * sizeof(elements[0]));
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_buffer), MakeUserPointer(&num_bytes), false));
EXPECT_TRUE(read_buffer);
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(elements[0])), num_bytes);
read_elements = static_cast<const int32_t*>(read_buffer);
EXPECT_EQ(456, read_elements[0]);
- EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(static_cast<uint32_t>(
- 1u * sizeof(elements[0]))));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dp->ConsumerEndReadData(
+ static_cast<uint32_t>(1u * sizeof(elements[0]))));
// Adding a waiter should now succeed.
waiter.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dp->ConsumerAddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 56,
- nullptr));
+ dp->ConsumerAddWaiter(
+ &waiter, MOJO_HANDLE_SIGNAL_READABLE, 56, nullptr));
// Close the producer.
dp->ProducerClose();
@@ -643,8 +692,9 @@ TEST(LocalDataPipeTest, BasicTwoPhaseWaiting) {
1000 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
Waiter waiter;
@@ -661,9 +711,10 @@ TEST(LocalDataPipeTest, BasicTwoPhaseWaiting) {
uint32_t num_bytes = static_cast<uint32_t>(1u * sizeof(int32_t));
void* write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_TRUE(write_ptr);
EXPECT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(int32_t)));
@@ -690,8 +741,9 @@ TEST(LocalDataPipeTest, BasicTwoPhaseWaiting) {
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfiable_signals);
static_cast<int32_t*>(write_ptr)[0] = 123;
- EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(
- static_cast<uint32_t>(1u * sizeof(int32_t))));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerEndWriteData(static_cast<uint32_t>(1u * sizeof(int32_t))));
// It should be writable again.
waiter.Init();
@@ -715,9 +767,10 @@ TEST(LocalDataPipeTest, BasicTwoPhaseWaiting) {
// middle of it.
num_bytes = static_cast<uint32_t>(1u * sizeof(int32_t));
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_TRUE(write_ptr);
EXPECT_GE(num_bytes, static_cast<uint32_t>(1u * sizeof(int32_t)));
@@ -736,9 +789,10 @@ TEST(LocalDataPipeTest, BasicTwoPhaseWaiting) {
// Start a two-phase read.
num_bytes = static_cast<uint32_t>(1u * sizeof(int32_t));
const void* read_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_TRUE(read_ptr);
EXPECT_EQ(static_cast<uint32_t>(1u * sizeof(int32_t)), num_bytes);
@@ -787,8 +841,9 @@ TEST(LocalDataPipeTest, BasicMayDiscardWaiting) {
1 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
Waiter waiter;
@@ -818,7 +873,8 @@ TEST(LocalDataPipeTest, BasicMayDiscardWaiting) {
int32_t element = 123;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(&element),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(static_cast<uint32_t>(sizeof(int32_t)), num_bytes);
// Still writable (even though it's full).
@@ -844,7 +900,8 @@ TEST(LocalDataPipeTest, BasicMayDiscardWaiting) {
element = 456;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(&element),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(static_cast<uint32_t>(sizeof(int32_t)), num_bytes);
// Still writable.
@@ -868,9 +925,12 @@ TEST(LocalDataPipeTest, BasicMayDiscardWaiting) {
// Read that element.
num_bytes = static_cast<uint32_t>(sizeof(int32_t));
element = 0;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerReadData(UserPointer<void>(&element),
- MakeUserPointer(&num_bytes), false, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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);
@@ -911,8 +971,9 @@ TEST(LocalDataPipeTest, MayDiscard) {
10 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
@@ -923,9 +984,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
Seq(0, arraysize(buffer), buffer);
// Try writing more than capacity. (This test relies on the implementation
// enforcing the capacity strictly.)
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(10u * sizeof(int32_t), num_bytes);
// Read half of what we wrote.
@@ -933,7 +995,9 @@ TEST(LocalDataPipeTest, MayDiscard) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), false, false));
+ 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));
@@ -945,9 +1009,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
// Write a bit more than the space that's available.
num_bytes = 8u * sizeof(int32_t);
Seq(100, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(8u * sizeof(int32_t), num_bytes);
// Internally, a circular buffer would now look like:
// 100, 101, 102, 103, 104, 105, 106, 107, 8, 9
@@ -957,7 +1022,9 @@ TEST(LocalDataPipeTest, MayDiscard) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), false, false));
+ 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,9 +1039,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
// Write one integer.
num_bytes = 1u * sizeof(int32_t);
Seq(200, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(1u * sizeof(int32_t), num_bytes);
// Internally, a circular buffer would now look like:
// -, -, -, 103, 104, 105, 106, 107, 200, -
@@ -982,9 +1050,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
// Write five more.
num_bytes = 5u * sizeof(int32_t);
Seq(300, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
// Internally, a circular buffer would now look like:
// 301, 302, 303, 304, 104, 105, 106, 107, 200, 300
@@ -994,7 +1063,9 @@ TEST(LocalDataPipeTest, MayDiscard) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), false, false));
+ MakeUserPointer(&num_bytes),
+ false,
+ false));
EXPECT_EQ(10u * sizeof(int32_t), num_bytes);
memset(expected_buffer, 0xab, sizeof(expected_buffer));
expected_buffer[0] = 104;
@@ -1016,9 +1087,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
num_bytes = 0u;
void* write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_TRUE(write_ptr);
EXPECT_EQ(6u * sizeof(int32_t), num_bytes);
Seq(400, 6, static_cast<int32_t*>(write_ptr));
@@ -1030,9 +1102,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
// mode.
num_bytes = 6u * sizeof(int32_t);
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(4u * sizeof(int32_t), num_bytes);
static_cast<int32_t*>(write_ptr)[0] = 500;
EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(1u * sizeof(int32_t)));
@@ -1042,17 +1115,19 @@ TEST(LocalDataPipeTest, MayDiscard) {
// Requesting a 10-element buffer in all-or-none mode fails at this point.
num_bytes = 10u * sizeof(int32_t);
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OUT_OF_RANGE,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), true));
// But requesting, say, a 5-element (up to 9, really) buffer should be okay.
// It will discard two elements.
num_bytes = 5u * sizeof(int32_t);
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
// Only write 4 elements though.
Seq(600, 4, static_cast<int32_t*>(write_ptr));
@@ -1064,9 +1139,10 @@ TEST(LocalDataPipeTest, MayDiscard) {
// the internal buffer.
num_bytes = 5u * sizeof(int32_t);
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
// Only write 3 elements though.
Seq(700, 3, static_cast<int32_t*>(write_ptr));
@@ -1079,7 +1155,9 @@ TEST(LocalDataPipeTest, MayDiscard) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), false, false));
+ MakeUserPointer(&num_bytes),
+ false,
+ false));
EXPECT_EQ(8u * sizeof(int32_t), num_bytes);
memset(expected_buffer, 0xab, sizeof(expected_buffer));
expected_buffer[0] = 500;
@@ -1104,8 +1182,9 @@ TEST(LocalDataPipeTest, AllOrNone) {
10 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
@@ -1113,9 +1192,10 @@ TEST(LocalDataPipeTest, AllOrNone) {
uint32_t num_bytes = 20u * sizeof(int32_t);
int32_t buffer[100];
Seq(0, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OUT_OF_RANGE,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
// Should still be empty.
num_bytes = ~0u;
@@ -1125,9 +1205,10 @@ TEST(LocalDataPipeTest, AllOrNone) {
// Write some data.
num_bytes = 5u * sizeof(int32_t);
Seq(100, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
// Half full.
@@ -1138,16 +1219,19 @@ TEST(LocalDataPipeTest, AllOrNone) {
// Too much.
num_bytes = 6u * sizeof(int32_t);
Seq(200, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OUT_OF_RANGE,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
// Try reading too much.
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, false));
+ 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)));
@@ -1160,17 +1244,19 @@ TEST(LocalDataPipeTest, AllOrNone) {
// Just a little.
num_bytes = 2u * sizeof(int32_t);
Seq(300, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(2u * sizeof(int32_t), num_bytes);
// Just right.
num_bytes = 3u * sizeof(int32_t);
Seq(400, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(3u * sizeof(int32_t), num_bytes);
// Exactly full.
@@ -1183,7 +1269,9 @@ TEST(LocalDataPipeTest, AllOrNone) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), true, false));
+ 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);
@@ -1194,7 +1282,9 @@ TEST(LocalDataPipeTest, AllOrNone) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), true, false));
+ MakeUserPointer(&num_bytes),
+ true,
+ false));
memset(expected_buffer, 0xab, sizeof(expected_buffer));
EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
@@ -1222,7 +1312,9 @@ TEST(LocalDataPipeTest, AllOrNone) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), true, false));
+ MakeUserPointer(&num_bytes),
+ true,
+ false));
memset(expected_buffer, 0xab, sizeof(expected_buffer));
EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
@@ -1236,7 +1328,9 @@ TEST(LocalDataPipeTest, AllOrNone) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), true, false));
+ 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);
@@ -1264,8 +1358,9 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
10 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
@@ -1273,24 +1368,27 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
uint32_t num_bytes = 20u * sizeof(int32_t);
int32_t buffer[100];
Seq(0, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OUT_OF_RANGE,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
// Write some stuff.
num_bytes = 5u * sizeof(int32_t);
Seq(100, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(5u * sizeof(int32_t), num_bytes);
// Write lots of stuff (discarding all but "104").
num_bytes = 9u * sizeof(int32_t);
Seq(200, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(9u * sizeof(int32_t), num_bytes);
// Read one.
@@ -1298,7 +1396,9 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), true, false));
+ 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));
@@ -1310,7 +1410,9 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), true, false));
+ MakeUserPointer(&num_bytes),
+ true,
+ false));
memset(expected_buffer, 0xab, sizeof(expected_buffer));
EXPECT_EQ(0, memcmp(buffer, expected_buffer, sizeof(buffer)));
@@ -1332,9 +1434,10 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
// Write as much as possible.
num_bytes = 10u * sizeof(int32_t);
Seq(300, arraysize(buffer), buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(10u * sizeof(int32_t), num_bytes);
// Read everything.
@@ -1342,7 +1445,9 @@ TEST(LocalDataPipeTest, AllOrNoneMayDiscard) {
memset(buffer, 0xab, sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), true, false));
+ 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);
@@ -1363,40 +1468,44 @@ TEST(LocalDataPipeTest, TwoPhaseAllOrNone) {
10 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
// Try writing way too much (two-phase).
uint32_t num_bytes = 20u * sizeof(int32_t);
void* write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OUT_OF_RANGE,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), true));
// Try writing an amount which isn't a multiple of the element size
// (two-phase).
static_assert(sizeof(int32_t) > 1u, "Wow! int32_t's have size 1");
num_bytes = 1u;
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_INVALID_ARGUMENT,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), true));
// Try reading way too much (two-phase).
num_bytes = 20u * sizeof(int32_t);
const void* read_ptr = nullptr;
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), true));
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true));
// Write half (two-phase).
num_bytes = 5u * sizeof(int32_t);
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), true));
// May provide more space than requested.
EXPECT_GE(num_bytes, 5u * sizeof(int32_t));
EXPECT_TRUE(write_ptr);
@@ -1408,15 +1517,15 @@ TEST(LocalDataPipeTest, TwoPhaseAllOrNone) {
num_bytes = 1u;
read_ptr = nullptr;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), true));
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true));
// Read one (two-phase).
num_bytes = 1u * sizeof(int32_t);
read_ptr = nullptr;
EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), true));
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true));
EXPECT_GE(num_bytes, 1u * sizeof(int32_t));
EXPECT_EQ(0, static_cast<const int32_t*>(read_ptr)[0]);
EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(1u * sizeof(int32_t)));
@@ -1430,17 +1539,19 @@ TEST(LocalDataPipeTest, TwoPhaseAllOrNone) {
// two-phase write of six now.
num_bytes = 6u * sizeof(int32_t);
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OUT_OF_RANGE,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), true));
// Write six elements (simple), filling the buffer.
num_bytes = 6u * sizeof(int32_t);
int32_t buffer[100];
Seq(100, 6, buffer);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerWriteData(UserPointer<const void>(buffer),
- MakeUserPointer(&num_bytes), true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerWriteData(
+ UserPointer<const void>(buffer), MakeUserPointer(&num_bytes), true));
EXPECT_EQ(6u * sizeof(int32_t), num_bytes);
// We have ten.
@@ -1452,8 +1563,8 @@ TEST(LocalDataPipeTest, TwoPhaseAllOrNone) {
num_bytes = 10u * sizeof(int32_t);
read_ptr = nullptr;
EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), true));
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true));
// Close the producer.
dp->ProducerClose();
@@ -1462,8 +1573,8 @@ TEST(LocalDataPipeTest, TwoPhaseAllOrNone) {
num_bytes = 9u * sizeof(int32_t);
read_ptr = nullptr;
EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), true));
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true));
EXPECT_GE(num_bytes, 9u * sizeof(int32_t));
EXPECT_EQ(1, static_cast<const int32_t*>(read_ptr)[0]);
EXPECT_EQ(2, static_cast<const int32_t*>(read_ptr)[1]);
@@ -1480,8 +1591,8 @@ TEST(LocalDataPipeTest, TwoPhaseAllOrNone) {
num_bytes = 2u * sizeof(int32_t);
read_ptr = nullptr;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), true));
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true));
dp->ConsumerClose();
}
@@ -1502,8 +1613,9 @@ TEST(LocalDataPipeTest, WrapAround) {
100u // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
// This test won't be valid if |ValidateCreateOptions()| decides to give the
// pipe more space.
ASSERT_EQ(100u, validated_options.capacity_num_bytes);
@@ -1514,15 +1626,19 @@ TEST(LocalDataPipeTest, WrapAround) {
uint32_t num_bytes = 20u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(&test_data[0]),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(20u, num_bytes);
// Read 10 bytes.
unsigned char read_buffer[1000] = {0};
num_bytes = 10u;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerReadData(UserPointer<void>(read_buffer),
- MakeUserPointer(&num_bytes), false, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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));
@@ -1533,7 +1649,8 @@ TEST(LocalDataPipeTest, WrapAround) {
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(write_buffer_ptr);
EXPECT_EQ(80u, num_bytes);
EXPECT_EQ(MOJO_RESULT_OK, dp->ProducerEndWriteData(0u));
@@ -1543,7 +1660,8 @@ TEST(LocalDataPipeTest, WrapAround) {
num_bytes = 200u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(&test_data[20]),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(90u, num_bytes);
// Check that a two-phase read can now only read (at most) 90 bytes. (This
@@ -1553,7 +1671,8 @@ TEST(LocalDataPipeTest, WrapAround) {
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(read_buffer_ptr);
EXPECT_EQ(90u, num_bytes);
EXPECT_EQ(MOJO_RESULT_OK, dp->ConsumerEndReadData(0u));
@@ -1563,9 +1682,12 @@ TEST(LocalDataPipeTest, WrapAround) {
num_bytes =
static_cast<uint32_t>(arraysize(read_buffer) * sizeof(read_buffer[0]));
memset(read_buffer, 0, num_bytes);
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerReadData(UserPointer<void>(read_buffer),
- MakeUserPointer(&num_bytes), false, false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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));
@@ -1586,8 +1708,9 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
1000u // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
// Close producer first, then consumer.
{
@@ -1597,14 +1720,16 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
uint32_t num_bytes = kTestDataSize;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(kTestData),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(kTestDataSize, num_bytes);
// Write it again, so we'll have something left over.
num_bytes = kTestDataSize;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(kTestData),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(kTestDataSize, num_bytes);
// Start two-phase write.
@@ -1612,7 +1737,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(write_buffer_ptr);
EXPECT_GT(num_bytes, 0u);
@@ -1621,7 +1747,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(read_buffer_ptr);
EXPECT_EQ(2u * kTestDataSize, num_bytes);
@@ -1637,7 +1764,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(read_buffer_ptr);
EXPECT_EQ(kTestDataSize, num_bytes);
@@ -1653,7 +1781,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
uint32_t num_bytes = kTestDataSize;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(kTestData),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(kTestDataSize, num_bytes);
// Start two-phase write.
@@ -1661,7 +1790,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(write_buffer_ptr);
ASSERT_GT(num_bytes, kTestDataSize);
@@ -1670,7 +1800,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(read_buffer_ptr);
EXPECT_EQ(kTestDataSize, num_bytes);
@@ -1688,14 +1819,16 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
num_bytes = kTestDataSize;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
dp->ProducerWriteData(UserPointer<const void>(kTestData),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
// As will trying to start another two-phase write.
write_buffer_ptr = nullptr;
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
dp->ProducerClose();
}
@@ -1710,7 +1843,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
uint32_t num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerBeginWriteData(MakeUserPointer(&write_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_TRUE(write_buffer_ptr);
ASSERT_GT(num_bytes, kTestDataSize);
@@ -1726,7 +1860,8 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
uint32_t num_bytes = kTestDataSize;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(kTestData),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(kTestDataSize, num_bytes);
// Close the producer.
@@ -1735,33 +1870,43 @@ TEST(LocalDataPipeTest, CloseWriteRead) {
// 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, true));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ 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(
+ 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));
// A second read should fail.
num_bytes = static_cast<uint32_t>(sizeof(buffer));
- EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- dp->ConsumerReadData(UserPointer<void>(buffer),
- MakeUserPointer(&num_bytes), false, false));
+ EXPECT_EQ(
+ MOJO_RESULT_FAILED_PRECONDITION,
+ dp->ConsumerReadData(UserPointer<void>(buffer),
+ MakeUserPointer(&num_bytes),
+ false,
+ false));
// A two-phase read should also fail.
const void* read_buffer_ptr = nullptr;
num_bytes = 0u;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
dp->ConsumerBeginReadData(MakeUserPointer(&read_buffer_ptr),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
// Ditto for discard.
num_bytes = 10u;
@@ -1780,8 +1925,9 @@ TEST(LocalDataPipeTest, TwoPhaseMoreInvalidArguments) {
10 * sizeof(int32_t) // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
@@ -1802,9 +1948,10 @@ TEST(LocalDataPipeTest, TwoPhaseMoreInvalidArguments) {
// Try ending a two-phase write with an invalid amount (too much).
num_bytes = 0u;
void* write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
dp->ProducerEndWriteData(num_bytes +
static_cast<uint32_t>(sizeof(int32_t))));
@@ -1821,9 +1968,10 @@ TEST(LocalDataPipeTest, TwoPhaseMoreInvalidArguments) {
// element size).
num_bytes = 0u;
write_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ProducerBeginWriteData(MakeUserPointer(&write_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ProducerBeginWriteData(
+ MakeUserPointer(&write_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_GE(num_bytes, 1u);
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dp->ProducerEndWriteData(1u));
@@ -1840,7 +1988,8 @@ TEST(LocalDataPipeTest, TwoPhaseMoreInvalidArguments) {
num_bytes = 1u * sizeof(int32_t);
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(&element),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
// One element available.
num_bytes = 0u;
@@ -1859,9 +2008,10 @@ TEST(LocalDataPipeTest, TwoPhaseMoreInvalidArguments) {
// Try ending a two-phase read with an invalid amount (too much).
num_bytes = 0u;
const void* read_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
dp->ConsumerEndReadData(num_bytes +
static_cast<uint32_t>(sizeof(int32_t))));
@@ -1875,9 +2025,10 @@ TEST(LocalDataPipeTest, TwoPhaseMoreInvalidArguments) {
// element size).
num_bytes = 0u;
read_ptr = nullptr;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(1u * sizeof(int32_t), num_bytes);
EXPECT_EQ(123, static_cast<const int32_t*>(read_ptr)[0]);
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, dp->ConsumerEndReadData(1u));
@@ -1906,8 +2057,9 @@ TEST(LocalDataPipeTest, DISABLED_MayDiscardTwoPhaseConsistent) {
2 // |capacity_num_bytes|.
};
MojoCreateDataPipeOptions validated_options = {0};
- EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(
- MakeUserPointer(&options), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ DataPipe::ValidateCreateOptions(MakeUserPointer(&options),
+ &validated_options));
scoped_refptr<LocalDataPipe> dp(new LocalDataPipe(validated_options));
@@ -1916,15 +2068,17 @@ TEST(LocalDataPipeTest, DISABLED_MayDiscardTwoPhaseConsistent) {
uint32_t num_bytes = 2u;
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
EXPECT_EQ(2u, num_bytes);
// Begin reading.
const void* read_ptr = nullptr;
num_bytes = 2u;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(2u, num_bytes);
EXPECT_EQ('a', static_cast<const char*>(read_ptr)[0]);
EXPECT_EQ('b', static_cast<const char*>(read_ptr)[1]);
@@ -1940,7 +2094,8 @@ TEST(LocalDataPipeTest, DISABLED_MayDiscardTwoPhaseConsistent) {
// this through reveals the significant consequence.
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
// Check that our read buffer hasn't changed underneath us.
EXPECT_EQ('a', static_cast<const char*>(read_ptr)[0]);
@@ -1952,14 +2107,16 @@ TEST(LocalDataPipeTest, DISABLED_MayDiscardTwoPhaseConsistent) {
// Now writing should succeed.
EXPECT_EQ(MOJO_RESULT_OK,
dp->ProducerWriteData(UserPointer<const void>(elements),
- MakeUserPointer(&num_bytes), false));
+ MakeUserPointer(&num_bytes),
+ false));
// And if we read, we should get the new values.
read_ptr = nullptr;
num_bytes = 2u;
- EXPECT_EQ(MOJO_RESULT_OK,
- dp->ConsumerBeginReadData(MakeUserPointer(&read_ptr),
- MakeUserPointer(&num_bytes), false));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dp->ConsumerBeginReadData(
+ MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), false));
EXPECT_EQ(2u, num_bytes);
EXPECT_EQ('x', static_cast<const char*>(read_ptr)[0]);
EXPECT_EQ('y', static_cast<const char*>(read_ptr)[1]);
diff --git a/mojo/edk/system/mapping_table.cc b/mojo/edk/system/mapping_table.cc
index 693e8d7..0a28a1d 100644
--- a/mojo/edk/system/mapping_table.cc
+++ b/mojo/edk/system/mapping_table.cc
@@ -6,7 +6,7 @@
#include "base/logging.h"
#include "mojo/edk/embedder/platform_shared_buffer.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
namespace mojo {
namespace system {
@@ -23,8 +23,7 @@ MojoResult MappingTable::AddMapping(
scoped_ptr<embedder::PlatformSharedBufferMapping> mapping) {
DCHECK(mapping);
- if (address_to_mapping_map_.size() >=
- GetConfiguration().max_mapping_table_sze)
+ if (address_to_mapping_map_.size() >= kMaxMappingTableSize)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
uintptr_t address = reinterpret_cast<uintptr_t>(mapping->GetBase());
diff --git a/mojo/edk/system/memory.cc b/mojo/edk/system/memory.cc
index 0e3d9a9..1d7f792 100644
--- a/mojo/edk/system/memory.cc
+++ b/mojo/edk/system/memory.cc
@@ -40,20 +40,20 @@ template void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointer<8, 8>(const void*);
template <size_t size, size_t alignment>
void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithCount(const void* pointer, size_t count) {
+ CheckUserPointerWithCount(const void* pointer, size_t count) {
CHECK_LE(count, std::numeric_limits<size_t>::max() / size);
CHECK(count == 0 || (pointer && IsAligned<alignment>(pointer)));
}
// Explicitly instantiate the sizes we need. Add instantiations as needed.
template void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithCount<1, 1>(const void*, size_t);
+ CheckUserPointerWithCount<1, 1>(const void*, size_t);
template void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithCount<4, 4>(const void*, size_t);
+ CheckUserPointerWithCount<4, 4>(const void*, size_t);
template void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithCount<8, 4>(const void*, size_t);
+ CheckUserPointerWithCount<8, 4>(const void*, size_t);
template void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithCount<8, 8>(const void*, size_t);
+ CheckUserPointerWithCount<8, 8>(const void*, size_t);
template <size_t alignment>
void CheckUserPointerWithSize(const void* pointer, size_t size) {
@@ -65,9 +65,9 @@ void CheckUserPointerWithSize(const void* pointer, size_t size) {
// Explicitly instantiate the sizes we need. Add instantiations as needed.
template void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithSize<1>(const void*, size_t);
+ CheckUserPointerWithSize<1>(const void*, size_t);
template void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithSize<4>(const void*, size_t);
+ CheckUserPointerWithSize<4>(const void*, size_t);
// Whereas the other |Check...()| functions are usually used with integral typs
// or arrays of integral types, this one is used with Options structs for which
// alignment has been explicitly been specified (using |MOJO_ALIGNAS()|), which
@@ -75,13 +75,13 @@ CheckUserPointerWithSize<4>(const void*, size_t);
#if defined(COMPILER_MSVC) && defined(ARCH_CPU_32_BITS)
template <>
void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithSize<8>(const void* pointer, size_t size) {
+ CheckUserPointerWithSize<8>(const void* pointer, size_t size) {
CHECK(size == 0 ||
(!!pointer && reinterpret_cast<uintptr_t>(pointer) % 8 == 0));
}
#else
template void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithSize<8>(const void*, size_t);
+ CheckUserPointerWithSize<8>(const void*, size_t);
#endif
} // namespace internal
diff --git a/mojo/edk/system/memory.h b/mojo/edk/system/memory.h
index 96cf219..7b5b724 100644
--- a/mojo/edk/system/memory.h
+++ b/mojo/edk/system/memory.h
@@ -53,13 +53,13 @@ void MOJO_SYSTEM_IMPL_EXPORT CheckUserPointer(const void* pointer);
// a buffer of |count| elements of the given size and alignment (both in bytes).
template <size_t size, size_t alignment>
void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithCount(const void* pointer, size_t count);
+ CheckUserPointerWithCount(const void* pointer, size_t count);
// Checks (insofar as appropriate/possible) that |pointer| is a valid pointer to
// a buffer of the given size and alignment (both in bytes).
template <size_t alignment>
void MOJO_SYSTEM_IMPL_EXPORT
-CheckUserPointerWithSize(const void* pointer, size_t size);
+ CheckUserPointerWithSize(const void* pointer, size_t size);
} // namespace internal
diff --git a/mojo/edk/system/message_in_transit.cc b/mojo/edk/system/message_in_transit.cc
index 0f2ff5e..95a7d23 100644
--- a/mojo/edk/system/message_in_transit.cc
+++ b/mojo/edk/system/message_in_transit.cc
@@ -8,7 +8,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/transport_data.h"
namespace mojo {
@@ -38,13 +38,23 @@ struct MessageInTransit::PrivateStructForCompileAsserts {
// The size of |Header| must be a multiple of the alignment.
static_assert(sizeof(Header) % kMessageAlignment == 0,
"sizeof(MessageInTransit::Header) invalid");
+ // Avoid dangerous situations, but making sure that the size of the "header" +
+ // the size of the data fits into a 31-bit number.
+ static_assert(static_cast<uint64_t>(sizeof(Header)) + kMaxMessageNumBytes <=
+ 0x7fffffffULL,
+ "kMaxMessageNumBytes too big");
+
+ // We assume (to avoid extra rounding code) that the maximum message (data)
+ // size is a multiple of the alignment.
+ static_assert(kMaxMessageNumBytes % kMessageAlignment == 0,
+ "kMessageAlignment not a multiple of alignment");
};
MessageInTransit::View::View(size_t message_size, const void* buffer)
: buffer_(buffer) {
size_t next_message_size = 0;
- DCHECK(MessageInTransit::GetNextMessageSize(buffer_, message_size,
- &next_message_size));
+ DCHECK(MessageInTransit::GetNextMessageSize(
+ buffer_, message_size, &next_message_size));
DCHECK_EQ(message_size, next_message_size);
// This should be equivalent.
DCHECK_EQ(message_size, total_size());
@@ -52,29 +62,18 @@ MessageInTransit::View::View(size_t message_size, const void* buffer)
bool MessageInTransit::View::IsValid(size_t serialized_platform_handle_size,
const char** error_message) const {
- size_t max_message_num_bytes = GetConfiguration().max_message_num_bytes;
- // Avoid dangerous situations, but making sure that the size of the "header" +
- // the size of the data fits into a 31-bit number.
- DCHECK_LE(static_cast<uint64_t>(sizeof(Header)) + max_message_num_bytes,
- 0x7fffffffULL)
- << "GetConfiguration().max_message_num_bytes too big";
-
- // We assume (to avoid extra rounding code) that the maximum message (data)
- // size is a multiple of the alignment.
- DCHECK_EQ(max_message_num_bytes % kMessageAlignment, 0U)
- << "GetConfiguration().max_message_num_bytes not a multiple of alignment";
-
// Note: This also implies a check on the |main_buffer_size()|, which is just
// |RoundUpMessageAlignment(sizeof(Header) + num_bytes())|.
- if (num_bytes() > max_message_num_bytes) {
+ if (num_bytes() > kMaxMessageNumBytes) {
*error_message = "Message data payload too large";
return false;
}
if (transport_data_buffer_size() > 0) {
- const char* e = TransportData::ValidateBuffer(
- serialized_platform_handle_size, transport_data_buffer(),
- transport_data_buffer_size());
+ const char* e =
+ TransportData::ValidateBuffer(serialized_platform_handle_size,
+ transport_data_buffer(),
+ transport_data_buffer_size());
if (e) {
*error_message = e;
return false;
@@ -94,7 +93,8 @@ MessageInTransit::MessageInTransit(Type type,
ConstructorHelper(type, subtype, num_bytes);
if (bytes) {
memcpy(MessageInTransit::bytes(), bytes, num_bytes);
- memset(static_cast<char*>(MessageInTransit::bytes()) + num_bytes, 0,
+ memset(static_cast<char*>(MessageInTransit::bytes()) + num_bytes,
+ 0,
main_buffer_size_ - sizeof(Header) - num_bytes);
} else {
memset(MessageInTransit::bytes(), 0, main_buffer_size_ - sizeof(Header));
@@ -195,7 +195,7 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
void MessageInTransit::ConstructorHelper(Type type,
Subtype subtype,
uint32_t num_bytes) {
- DCHECK_LE(num_bytes, GetConfiguration().max_message_num_bytes);
+ DCHECK_LE(num_bytes, kMaxMessageNumBytes);
// |total_size| is updated below, from the other values.
header()->type = type;
diff --git a/mojo/edk/system/message_pipe.cc b/mojo/edk/system/message_pipe.cc
index ce529ed..e215730 100644
--- a/mojo/edk/system/message_pipe.cc
+++ b/mojo/edk/system/message_pipe.cc
@@ -100,7 +100,9 @@ MojoResult MessagePipe::WriteMessage(
GetPeerPort(port),
make_scoped_ptr(new MessageInTransit(
MessageInTransit::kTypeMessagePipeEndpoint,
- MessageInTransit::kSubtypeMessagePipeEndpointData, num_bytes, bytes)),
+ MessageInTransit::kSubtypeMessagePipeEndpointData,
+ num_bytes,
+ bytes)),
transports);
}
@@ -115,8 +117,8 @@ MojoResult MessagePipe::ReadMessage(unsigned port,
base::AutoLock locker(lock_);
DCHECK(endpoints_[port]);
- return endpoints_[port]->ReadMessage(bytes, num_bytes, dispatchers,
- num_dispatchers, flags);
+ return endpoints_[port]->ReadMessage(
+ bytes, num_bytes, dispatchers, num_dispatchers, flags);
}
HandleSignalsState MessagePipe::GetHandleSignalsState(unsigned port) const {
@@ -163,8 +165,10 @@ scoped_refptr<ChannelEndpoint> MessagePipe::ConvertLocalToProxy(unsigned port) {
// send the already-queued messages.
if (!endpoints_[GetPeerPort(port)]) {
scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint(
- nullptr, 0, static_cast<LocalMessagePipeEndpoint*>(
- endpoints_[port].get())->message_queue()));
+ nullptr,
+ 0,
+ static_cast<LocalMessagePipeEndpoint*>(endpoints_[port].get())
+ ->message_queue()));
endpoints_[port]->Close();
endpoints_[port].reset();
return channel_endpoint;
@@ -173,15 +177,18 @@ scoped_refptr<ChannelEndpoint> MessagePipe::ConvertLocalToProxy(unsigned port) {
// TODO(vtl): Allowing this case is a temporary hack. It'll set up a
// |MessagePipe| with two proxy endpoints, which will then act as a proxy
// (rather than trying to connect the two ends directly).
- DLOG_IF(WARNING, endpoints_[GetPeerPort(port)]->GetType() !=
- MessagePipeEndpoint::kTypeLocal)
+ DLOG_IF(WARNING,
+ endpoints_[GetPeerPort(port)]->GetType() !=
+ MessagePipeEndpoint::kTypeLocal)
<< "Direct message pipe passing across multiple channels not yet "
"implemented; will proxy";
scoped_ptr<MessagePipeEndpoint> old_endpoint(endpoints_[port].Pass());
scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint(
- this, port, static_cast<LocalMessagePipeEndpoint*>(old_endpoint.get())
- ->message_queue()));
+ this,
+ port,
+ static_cast<LocalMessagePipeEndpoint*>(old_endpoint.get())
+ ->message_queue()));
endpoints_[port].reset(new ProxyMessagePipeEndpoint(channel_endpoint.get()));
old_endpoint->Close();
diff --git a/mojo/edk/system/message_pipe_dispatcher.cc b/mojo/edk/system/message_pipe_dispatcher.cc
index 826cf26..7db16e8 100644
--- a/mojo/edk/system/message_pipe_dispatcher.cc
+++ b/mojo/edk/system/message_pipe_dispatcher.cc
@@ -8,7 +8,7 @@
#include "mojo/edk/system/channel.h"
#include "mojo/edk/system/channel_endpoint.h"
#include "mojo/edk/system/channel_endpoint_id.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/local_message_pipe_endpoint.h"
#include "mojo/edk/system/memory.h"
#include "mojo/edk/system/message_pipe.h"
@@ -173,17 +173,16 @@ MojoResult MessagePipeDispatcher::WriteMessageImplNoLock(
uint32_t num_bytes,
std::vector<DispatcherTransport>* transports,
MojoWriteMessageFlags flags) {
- DCHECK(!transports ||
- (transports->size() > 0 &&
- transports->size() <= GetConfiguration().max_message_num_handles));
+ DCHECK(!transports || (transports->size() > 0 &&
+ transports->size() <= kMaxMessageNumHandles));
lock().AssertAcquired();
- if (num_bytes > GetConfiguration().max_message_num_bytes)
+ if (num_bytes > kMaxMessageNumBytes)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
- return message_pipe_->WriteMessage(port_, bytes, num_bytes, transports,
- flags);
+ return message_pipe_->WriteMessage(
+ port_, bytes, num_bytes, transports, flags);
}
MojoResult MessagePipeDispatcher::ReadMessageImplNoLock(
@@ -193,8 +192,8 @@ MojoResult MessagePipeDispatcher::ReadMessageImplNoLock(
uint32_t* num_dispatchers,
MojoReadMessageFlags flags) {
lock().AssertAcquired();
- return message_pipe_->ReadMessage(port_, bytes, num_bytes, dispatchers,
- num_dispatchers, flags);
+ return message_pipe_->ReadMessage(
+ port_, bytes, num_bytes, dispatchers, num_dispatchers, flags);
}
HandleSignalsState MessagePipeDispatcher::GetHandleSignalsStateImplNoLock()
@@ -209,8 +208,8 @@ MojoResult MessagePipeDispatcher::AddWaiterImplNoLock(
uint32_t context,
HandleSignalsState* signals_state) {
lock().AssertAcquired();
- return message_pipe_->AddWaiter(port_, waiter, signals, context,
- signals_state);
+ return message_pipe_->AddWaiter(
+ port_, waiter, signals, context, signals_state);
}
void MessagePipeDispatcher::RemoveWaiterImplNoLock(
diff --git a/mojo/edk/system/message_pipe_dispatcher_unittest.cc b/mojo/edk/system/message_pipe_dispatcher_unittest.cc
index 8076a99..ae651fa 100644
--- a/mojo/edk/system/message_pipe_dispatcher_unittest.cc
+++ b/mojo/edk/system/message_pipe_dispatcher_unittest.cc
@@ -68,8 +68,10 @@ TEST(MessagePipeDispatcherTest, Basic) {
d0->AddWaiter(&w, MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr));
buffer[0] = 123456789;
EXPECT_EQ(MOJO_RESULT_OK,
- d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ d1->WriteMessage(UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
stopwatch.Start();
EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context));
EXPECT_EQ(1u, context);
@@ -97,7 +99,9 @@ TEST(MessagePipeDispatcherTest, Basic) {
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
d0->ReadMessage(UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kBufferSize, buffer_size);
EXPECT_EQ(123456789, buffer[0]);
@@ -153,7 +157,8 @@ TEST(MessagePipeDispatcherTest, InvalidParams) {
// Huge buffer size.
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
d0->WriteMessage(UserPointer<const void>(buffer),
- std::numeric_limits<uint32_t>::max(), nullptr,
+ std::numeric_limits<uint32_t>::max(),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
@@ -181,21 +186,26 @@ TEST(MessagePipeDispatcherTest, InvalidParamsDeath) {
// |WriteMessage|:
// Null buffer with nonzero buffer size.
- EXPECT_DEATH_IF_SUPPORTED(d0->WriteMessage(NullUserPointer(), 1, nullptr,
- MOJO_WRITE_MESSAGE_FLAG_NONE),
- kMemoryCheckFailedRegex);
+ EXPECT_DEATH_IF_SUPPORTED(
+ d0->WriteMessage(
+ NullUserPointer(), 1, nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE),
+ kMemoryCheckFailedRegex);
// |ReadMessage|:
// Null buffer with nonzero buffer size.
// First write something so that we actually have something to read.
EXPECT_EQ(MOJO_RESULT_OK,
- d1->WriteMessage(UserPointer<const void>("x"), 1, nullptr,
+ d1->WriteMessage(UserPointer<const void>("x"),
+ 1,
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
uint32_t buffer_size = 1;
- EXPECT_DEATH_IF_SUPPORTED(
- d0->ReadMessage(NullUserPointer(), MakeUserPointer(&buffer_size), 0,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE),
- kMemoryCheckFailedRegex);
+ EXPECT_DEATH_IF_SUPPORTED(d0->ReadMessage(NullUserPointer(),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE),
+ kMemoryCheckFailedRegex);
EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
EXPECT_EQ(MOJO_RESULT_OK, d1->Close());
@@ -224,12 +234,16 @@ TEST(MessagePipeDispatcherTest, BasicClosed) {
// Write (twice) to |d1|.
buffer[0] = 123456789;
EXPECT_EQ(MOJO_RESULT_OK,
- d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ d1->WriteMessage(UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
buffer[0] = 234567890;
EXPECT_EQ(MOJO_RESULT_OK,
- d1->WriteMessage(UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ d1->WriteMessage(UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Try waiting for readable on |d0|; should fail (already satisfied).
w.Init();
@@ -246,7 +260,9 @@ TEST(MessagePipeDispatcherTest, BasicClosed) {
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
d1->ReadMessage(UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
// Close |d1|.
@@ -265,7 +281,9 @@ TEST(MessagePipeDispatcherTest, BasicClosed) {
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
d0->ReadMessage(UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kBufferSize, buffer_size);
EXPECT_EQ(123456789, buffer[0]);
@@ -283,7 +301,9 @@ TEST(MessagePipeDispatcherTest, BasicClosed) {
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
d0->ReadMessage(UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kBufferSize, buffer_size);
EXPECT_EQ(234567890, buffer[0]);
@@ -310,14 +330,18 @@ TEST(MessagePipeDispatcherTest, BasicClosed) {
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
d0->ReadMessage(UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
// Try writing to |d0|; should fail (other end closed).
buffer[0] = 345678901;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- d0->WriteMessage(UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ d0->WriteMessage(UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, d0->Close());
}
@@ -354,17 +378,24 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) {
// Wait for readable on |d1|, which will become readable after some time.
{
- test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 1, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d1,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 1,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
// Wake it up by writing to |d0|.
buffer[0] = 123456789;
EXPECT_EQ(MOJO_RESULT_OK,
- d0->WriteMessage(UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ d0->WriteMessage(UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
} // Joins the thread.
elapsed = stopwatch.Elapsed();
EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout());
@@ -379,9 +410,14 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) {
// Now |d1| is already readable. Try waiting for it again.
{
- test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 2, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d1,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 2,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
} // Joins the thread.
@@ -398,7 +434,9 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) {
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
d1->ReadMessage(UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kBufferSize, buffer_size);
EXPECT_EQ(123456789, buffer[0]);
@@ -406,9 +444,14 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) {
// Wait for readable on |d1| and close |d0| after some time, which should
// cancel that wait.
{
- test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 3, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d1,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 3,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
@@ -440,9 +483,14 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) {
// Wait for readable on |d1| and close |d1| after some time, which should
// cancel that wait.
{
- test::WaiterThread thread(d1, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 4, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d1,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 4,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
@@ -498,15 +546,18 @@ class WriterThread : public base::SimpleThread {
base::RandInt(1, static_cast<int>(kMaxMessageSize)));
EXPECT_EQ(MOJO_RESULT_OK,
write_dispatcher_->WriteMessage(UserPointer<const void>(buffer),
- bytes_to_write, nullptr,
+ bytes_to_write,
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
*bytes_written_ += bytes_to_write;
}
// Write one last "quit" message.
- EXPECT_EQ(MOJO_RESULT_OK, write_dispatcher_->WriteMessage(
- UserPointer<const void>("quit"), 4, nullptr,
- MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ write_dispatcher_->WriteMessage(UserPointer<const void>("quit"),
+ 4,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
}
const scoped_refptr<Dispatcher> write_dispatcher_;
@@ -561,9 +612,11 @@ class ReaderThread : public base::SimpleThread {
// Clear the buffer so that we can check the result.
memset(buffer, 0, sizeof(buffer));
uint32_t buffer_size = static_cast<uint32_t>(sizeof(buffer));
- result = read_dispatcher_->ReadMessage(
- UserPointer<void>(buffer), MakeUserPointer(&buffer_size), 0, nullptr,
- MOJO_READ_MESSAGE_FLAG_NONE);
+ result = read_dispatcher_->ReadMessage(UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE);
EXPECT_TRUE(result == MOJO_RESULT_OK || result == MOJO_RESULT_SHOULD_WAIT)
<< "result: " << result;
// We're racing with others to read, so maybe we failed.
diff --git a/mojo/edk/system/message_pipe_perftest.cc b/mojo/edk/system/message_pipe_perftest.cc
index 9f1ac5d..9861e0b 100644
--- a/mojo/edk/system/message_pipe_perftest.cc
+++ b/mojo/edk/system/message_pipe_perftest.cc
@@ -47,23 +47,31 @@ class MultiprocessMessagePipePerfTest
protected:
void WriteWaitThenRead(scoped_refptr<MessagePipe> mp) {
- CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(payload_.data()),
- static_cast<uint32_t>(payload_.size()), nullptr,
+ CHECK_EQ(mp->WriteMessage(0,
+ UserPointer<const void>(payload_.data()),
+ static_cast<uint32_t>(payload_.size()),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
HandleSignalsState hss;
CHECK_EQ(test::WaitIfNecessary(mp, MOJO_HANDLE_SIGNAL_READABLE, &hss),
MOJO_RESULT_OK);
uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer_.size());
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer_[0]),
- MakeUserPointer(&read_buffer_size), nullptr,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE),
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer_[0]),
+ MakeUserPointer(&read_buffer_size),
+ nullptr,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
CHECK_EQ(read_buffer_size, static_cast<uint32_t>(payload_.size()));
}
void SendQuitMessage(scoped_refptr<MessagePipe> mp) {
- CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(""), 0, nullptr,
+ CHECK_EQ(mp->WriteMessage(0,
+ UserPointer<const void>(""),
+ 0,
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
}
@@ -73,7 +81,8 @@ class MultiprocessMessagePipePerfTest
WriteWaitThenRead(mp);
std::string test_name =
- base::StringPrintf("IPC_Perf_%dx_%u", message_count_,
+ base::StringPrintf("IPC_Perf_%dx_%u",
+ message_count_,
static_cast<unsigned>(message_size_));
base::PerfTimeLogger logger(test_name.c_str());
@@ -118,8 +127,11 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) {
}
uint32_t read_size = static_cast<uint32_t>(buffer.size());
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&buffer[0]),
- MakeUserPointer(&read_size), nullptr, nullptr,
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&buffer[0]),
+ MakeUserPointer(&read_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
@@ -127,8 +139,10 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) {
if (0 == read_size)
break;
- CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(&buffer[0]),
- static_cast<uint32_t>(read_size), nullptr,
+ CHECK_EQ(mp->WriteMessage(0,
+ UserPointer<const void>(&buffer[0]),
+ static_cast<uint32_t>(read_size),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
}
diff --git a/mojo/edk/system/message_pipe_test_utils.cc b/mojo/edk/system/message_pipe_test_utils.cc
index e5df26d..8f217ca 100644
--- a/mojo/edk/system/message_pipe_test_utils.cc
+++ b/mojo/edk/system/message_pipe_test_utils.cc
@@ -46,8 +46,10 @@ void ChannelThread::Start(embedder::ScopedPlatformHandle platform_handle,
test_io_thread_.Start();
test_io_thread_.PostTaskAndWait(
FROM_HERE,
- base::Bind(&ChannelThread::InitChannelOnIOThread, base::Unretained(this),
- base::Passed(&platform_handle), channel_endpoint));
+ base::Bind(&ChannelThread::InitChannelOnIOThread,
+ base::Unretained(this),
+ base::Passed(&platform_handle),
+ channel_endpoint));
}
void ChannelThread::Stop() {
@@ -59,8 +61,9 @@ void ChannelThread::Stop() {
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20));
test_io_thread_.PostTaskAndWait(
- FROM_HERE, base::Bind(&ChannelThread::ShutdownChannelOnIOThread,
- base::Unretained(this)));
+ FROM_HERE,
+ base::Bind(&ChannelThread::ShutdownChannelOnIOThread,
+ base::Unretained(this)));
}
test_io_thread_.Stop();
}
diff --git a/mojo/edk/system/message_pipe_unittest.cc b/mojo/edk/system/message_pipe_unittest.cc
index 030084b..dbffb4c 100644
--- a/mojo/edk/system/message_pipe_unittest.cc
+++ b/mojo/edk/system/message_pipe_unittest.cc
@@ -39,8 +39,11 @@ TEST(MessagePipeTest, Basic) {
buffer[1] = 456;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kBufferSize, buffer_size);
EXPECT_EQ(123, buffer[0]);
@@ -51,16 +54,21 @@ TEST(MessagePipeTest, Basic) {
buffer[1] = 456;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
// Write from port 1 (to port 0).
buffer[0] = 789012345;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(1, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(1,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Read from port 0.
@@ -68,8 +76,11 @@ TEST(MessagePipeTest, Basic) {
buffer[1] = 456;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
EXPECT_EQ(789012345, buffer[0]);
@@ -78,30 +89,41 @@ TEST(MessagePipeTest, Basic) {
// Read again from port 0 -- it should be empty.
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
// Write two messages from port 0 (to port 1).
buffer[0] = 123456789;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(0,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
buffer[0] = 234567890;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(0,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Read from port 1 with buffer size 0 (should get the size of next message).
// Also test that giving a null buffer is okay when the buffer size is 0.
buffer_size = 0;
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
- mp->ReadMessage(1, NullUserPointer(), MakeUserPointer(&buffer_size),
- 0, nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ mp->ReadMessage(1,
+ NullUserPointer(),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
// Read from port 1 with buffer size 1 (too small; should get the size of next
@@ -110,8 +132,11 @@ TEST(MessagePipeTest, Basic) {
buffer[1] = 456;
buffer_size = 1;
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
EXPECT_EQ(123, buffer[0]);
@@ -122,8 +147,11 @@ TEST(MessagePipeTest, Basic) {
buffer[1] = 456;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
EXPECT_EQ(123456789, buffer[0]);
@@ -134,8 +162,11 @@ TEST(MessagePipeTest, Basic) {
buffer[1] = 456;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
EXPECT_EQ(234567890, buffer[0]);
@@ -144,16 +175,21 @@ TEST(MessagePipeTest, Basic) {
// Read again from port 1 -- it should be empty.
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
// Write from port 0 (to port 1).
buffer[0] = 345678901;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(0,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Close port 0.
@@ -163,8 +199,10 @@ TEST(MessagePipeTest, Basic) {
buffer[0] = 456789012;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- mp->WriteMessage(1, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(1,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Read from port 1; should still get message (even though port 0 was closed).
@@ -172,8 +210,11 @@ TEST(MessagePipeTest, Basic) {
buffer[1] = 456;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
EXPECT_EQ(345678901, buffer[0]);
@@ -182,8 +223,11 @@ TEST(MessagePipeTest, Basic) {
// Read again from port 1 -- it should be empty (and port 0 is closed).
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
mp->Close(1);
@@ -200,15 +244,22 @@ TEST(MessagePipeTest, CloseWithQueuedIncomingMessages) {
for (int32_t i = 0; i < 5; i++) {
buffer[0] = i;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(1, UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ mp->WriteMessage(1,
+ UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
}
// Port 0 shouldn't be empty.
buffer_size = 0;
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
- mp->ReadMessage(0, NullUserPointer(), MakeUserPointer(&buffer_size),
- 0, nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ mp->ReadMessage(0,
+ NullUserPointer(),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(kBufferSize, buffer_size);
// Close port 0 first, which should have outstanding (incoming) messages.
@@ -227,30 +278,41 @@ TEST(MessagePipeTest, DiscardMode) {
buffer[0] = 789012345;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(1, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(1,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Read/discard from port 0 (no buffer); get size.
buffer_size = 0;
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
- mp->ReadMessage(0, NullUserPointer(), MakeUserPointer(&buffer_size),
- 0, nullptr, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
+ mp->ReadMessage(0,
+ NullUserPointer(),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
// Read again from port 0 -- it should be empty.
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
// Write from port 1 (to port 0).
buffer[0] = 890123456;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(1, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(1,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Read from port 0 (buffer big enough).
@@ -258,8 +320,11 @@ TEST(MessagePipeTest, DiscardMode) {
buffer[1] = 456;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
EXPECT_EQ(890123456, buffer[0]);
@@ -268,52 +333,72 @@ TEST(MessagePipeTest, DiscardMode) {
// Read again from port 0 -- it should be empty.
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
// Write from port 1 (to port 0).
buffer[0] = 901234567;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(1, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(1,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Read/discard from port 0 (buffer too small); get size.
buffer_size = 1;
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
EXPECT_EQ(static_cast<uint32_t>(sizeof(buffer[0])), buffer_size);
// Read again from port 0 -- it should be empty.
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
// Write from port 1 (to port 0).
buffer[0] = 123456789;
buffer[1] = 0;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(1, UserPointer<const void>(buffer),
- static_cast<uint32_t>(sizeof(buffer[0])), nullptr,
+ mp->WriteMessage(1,
+ UserPointer<const void>(buffer),
+ static_cast<uint32_t>(sizeof(buffer[0])),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Discard from port 0.
buffer_size = 1;
EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
- mp->ReadMessage(0, NullUserPointer(), NullUserPointer(), 0, nullptr,
+ mp->ReadMessage(0,
+ NullUserPointer(),
+ NullUserPointer(),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
// Read again from port 0 -- it should be empty.
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD));
mp->Close(0);
@@ -339,10 +424,13 @@ TEST(MessagePipeTest, BasicWaiting) {
hss.satisfiable_signals);
waiter.Init();
hss = HandleSignalsState();
- EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
- mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE |
- MOJO_HANDLE_SIGNAL_WRITABLE,
- 0, &hss));
+ EXPECT_EQ(
+ MOJO_RESULT_ALREADY_EXISTS,
+ mp->AddWaiter(0,
+ &waiter,
+ MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
+ 0,
+ &hss));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfiable_signals);
@@ -361,8 +449,11 @@ TEST(MessagePipeTest, BasicWaiting) {
// Write from port 0 (to port 1), to make port 1 readable.
buffer[0] = 123456789;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ mp->WriteMessage(0,
+ UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Port 1 should already be readable now.
waiter.Init();
@@ -375,10 +466,13 @@ TEST(MessagePipeTest, BasicWaiting) {
hss.satisfiable_signals);
waiter.Init();
hss = HandleSignalsState();
- EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS,
- mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE |
- MOJO_HANDLE_SIGNAL_WRITABLE,
- 0, &hss));
+ EXPECT_EQ(
+ MOJO_RESULT_ALREADY_EXISTS,
+ mp->AddWaiter(1,
+ &waiter,
+ MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
+ 0,
+ &hss));
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
@@ -416,8 +510,11 @@ TEST(MessagePipeTest, BasicWaiting) {
buffer[0] = 0;
buffer_size = kBufferSize;
EXPECT_EQ(MOJO_RESULT_OK,
- mp->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), 0, nullptr,
+ mp->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ 0,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(123456789, buffer[0]);
@@ -446,15 +543,18 @@ TEST(MessagePipeTest, ThreadedWaiting) {
thread.waiter()->Init();
ASSERT_EQ(MOJO_RESULT_OK,
- mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1,
- nullptr));
+ mp->AddWaiter(
+ 1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 1, nullptr));
thread.Start();
buffer[0] = 123456789;
// Write from port 0 (to port 1), which should wake up the waiter.
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(buffer), kBufferSize,
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ mp->WriteMessage(0,
+ UserPointer<const void>(buffer),
+ kBufferSize,
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
HandleSignalsState hss;
mp->RemoveWaiter(1, thread.waiter(), &hss);
@@ -477,8 +577,8 @@ TEST(MessagePipeTest, ThreadedWaiting) {
thread.waiter()->Init();
ASSERT_EQ(MOJO_RESULT_OK,
- mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 2,
- nullptr));
+ mp->AddWaiter(
+ 1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 2, nullptr));
thread.Start();
// Close port 1 first -- this should result in the waiter being cancelled.
@@ -500,8 +600,8 @@ TEST(MessagePipeTest, ThreadedWaiting) {
thread.waiter()->Init();
ASSERT_EQ(MOJO_RESULT_OK,
- mp->AddWaiter(1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3,
- nullptr));
+ mp->AddWaiter(
+ 1, thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr));
thread.Start();
// Close port 0 first -- this should wake the waiter up, since port 1 will
diff --git a/mojo/edk/system/multiprocess_message_pipe_unittest.cc b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
index ab2e75c..2f22d67 100644
--- a/mojo/edk/system/multiprocess_message_pipe_unittest.cc
+++ b/mojo/edk/system/multiprocess_message_pipe_unittest.cc
@@ -72,9 +72,12 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
std::string read_buffer(1000, '\0');
uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
- MakeUserPointer(&read_buffer_size), nullptr,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE),
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer[0]),
+ MakeUserPointer(&read_buffer_size),
+ nullptr,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
read_buffer.resize(read_buffer_size);
VLOG(2) << "Child got: " << read_buffer;
@@ -85,9 +88,11 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(EchoEcho) {
}
std::string write_buffer = read_buffer + read_buffer;
- CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(write_buffer.data()),
+ CHECK_EQ(mp->WriteMessage(0,
+ UserPointer<const void>(write_buffer.data()),
static_cast<uint32_t>(write_buffer.size()),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
}
@@ -105,8 +110,10 @@ TEST_F(MultiprocessMessagePipeTest, Basic) {
std::string hello("hello");
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(hello.data()),
- static_cast<uint32_t>(hello.size()), nullptr,
+ mp->WriteMessage(0,
+ UserPointer<const void>(hello.data()),
+ static_cast<uint32_t>(hello.size()),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
HandleSignalsState hss;
@@ -120,8 +127,11 @@ TEST_F(MultiprocessMessagePipeTest, Basic) {
std::string read_buffer(1000, '\0');
uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
- MakeUserPointer(&read_buffer_size), nullptr, nullptr,
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer[0]),
+ MakeUserPointer(&read_buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
read_buffer.resize(read_buffer_size);
@@ -147,16 +157,20 @@ TEST_F(MultiprocessMessagePipeTest, QueueMessages) {
for (size_t i = 0; i < kNumMessages; i++) {
std::string write_buffer(i, 'A' + (i % 26));
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(write_buffer.data()),
+ mp->WriteMessage(0,
+ UserPointer<const void>(write_buffer.data()),
static_cast<uint32_t>(write_buffer.size()),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
}
const std::string quitquitquit("quitquitquit");
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(quitquitquit.data()),
+ mp->WriteMessage(0,
+ UserPointer<const void>(quitquitquit.data()),
static_cast<uint32_t>(quitquitquit.size()),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
for (size_t i = 0; i < kNumMessages; i++) {
HandleSignalsState hss;
@@ -170,9 +184,12 @@ TEST_F(MultiprocessMessagePipeTest, QueueMessages) {
std::string read_buffer(kNumMessages * 2, '\0');
uint32_t read_buffer_size = static_cast<uint32_t>(read_buffer.size());
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
- MakeUserPointer(&read_buffer_size), nullptr,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE),
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer[0]),
+ MakeUserPointer(&read_buffer_size),
+ nullptr,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
read_buffer.resize(read_buffer_size);
@@ -219,9 +236,12 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
DispatcherVector dispatchers;
uint32_t num_dispatchers = 10; // Maximum number to receive.
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
- MakeUserPointer(&num_bytes), &dispatchers,
- &num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE),
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer[0]),
+ MakeUserPointer(&num_bytes),
+ &dispatchers,
+ &num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
read_buffer.resize(num_bytes);
CHECK_EQ(read_buffer, std::string("go 1"));
@@ -249,8 +269,10 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
// And send a message to signal that we've written stuff.
const std::string go2("go 2");
- CHECK_EQ(mp->WriteMessage(0, UserPointer<const void>(&go2[0]),
- static_cast<uint32_t>(go2.size()), nullptr,
+ CHECK_EQ(mp->WriteMessage(0,
+ UserPointer<const void>(&go2[0]),
+ static_cast<uint32_t>(go2.size()),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
@@ -265,8 +287,11 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckSharedBuffer) {
read_buffer = std::string(100, '\0');
num_bytes = static_cast<uint32_t>(read_buffer.size());
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
- MakeUserPointer(&num_bytes), nullptr, nullptr,
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer[0]),
+ MakeUserPointer(&num_bytes),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
read_buffer.resize(num_bytes);
@@ -297,10 +322,12 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
// Make a shared buffer.
scoped_refptr<SharedBufferDispatcher> dispatcher;
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
- platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions,
- 100, &dispatcher));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 100,
+ &dispatcher));
ASSERT_TRUE(dispatcher.get());
// Make a mapping.
@@ -320,8 +347,10 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(&go1[0]),
- static_cast<uint32_t>(go1.size()), &transports,
+ mp->WriteMessage(0,
+ UserPointer<const void>(&go1[0]),
+ static_cast<uint32_t>(go1.size()),
+ &transports,
MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
@@ -338,8 +367,11 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
std::string read_buffer(100, '\0');
uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
EXPECT_EQ(MOJO_RESULT_OK,
- mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
- MakeUserPointer(&num_bytes), nullptr, nullptr,
+ mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer[0]),
+ MakeUserPointer(&num_bytes),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
read_buffer.resize(num_bytes);
EXPECT_EQ(std::string("go 2"), read_buffer);
@@ -356,8 +388,10 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_SharedBufferPassing) {
// And send a message to signal that we've written stuff.
const std::string go3("go 3");
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(&go3[0]),
- static_cast<uint32_t>(go3.size()), nullptr,
+ mp->WriteMessage(0,
+ UserPointer<const void>(&go3[0]),
+ static_cast<uint32_t>(go3.size()),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
// Wait for |mp| to become readable, which should fail.
@@ -394,9 +428,12 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(CheckPlatformHandleFile) {
uint32_t num_bytes = static_cast<uint32_t>(read_buffer.size());
DispatcherVector dispatchers;
uint32_t num_dispatchers = 10; // Maximum number to receive.
- CHECK_EQ(mp->ReadMessage(0, UserPointer<void>(&read_buffer[0]),
- MakeUserPointer(&num_bytes), &dispatchers,
- &num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE),
+ CHECK_EQ(mp->ReadMessage(0,
+ UserPointer<void>(&read_buffer[0]),
+ MakeUserPointer(&num_bytes),
+ &dispatchers,
+ &num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE),
MOJO_RESULT_OK);
mp->Close(0);
@@ -459,8 +496,10 @@ TEST_F(MultiprocessMessagePipeTest, MAYBE_PlatformHandlePassing) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
EXPECT_EQ(MOJO_RESULT_OK,
- mp->WriteMessage(0, UserPointer<const void>(&hello[0]),
- static_cast<uint32_t>(hello.size()), &transports,
+ mp->WriteMessage(0,
+ UserPointer<const void>(&hello[0]),
+ static_cast<uint32_t>(hello.size()),
+ &transports,
MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
diff --git a/mojo/edk/system/options_validation.h b/mojo/edk/system/options_validation.h
index 9724e38..4772508 100644
--- a/mojo/edk/system/options_validation.h
+++ b/mojo/edk/system/options_validation.h
@@ -18,6 +18,7 @@
#include "base/logging.h"
#include "base/macros.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/memory.h"
#include "mojo/edk/system/system_impl_export.h"
#include "mojo/public/c/system/types.h"
diff --git a/mojo/edk/system/raw_channel.cc b/mojo/edk/system/raw_channel.cc
index 4331166..0bfe104 100644
--- a/mojo/edk/system/raw_channel.cc
+++ b/mojo/edk/system/raw_channel.cc
@@ -133,8 +133,9 @@ void RawChannel::WriteBuffer::GetBuffers(std::vector<Buffer>* buffers) const {
// attached.
// Write from both buffers.
- DCHECK_EQ(bytes_to_write, message->main_buffer_size() - data_offset_ +
- transport_data_buffer_size);
+ DCHECK_EQ(
+ bytes_to_write,
+ message->main_buffer_size() - data_offset_ + transport_data_buffer_size);
Buffer buffer1 = {
static_cast<const char*>(message->main_buffer()) + data_offset_,
message->main_buffer_size() - data_offset_};
@@ -194,9 +195,11 @@ bool RawChannel::Init(Delegate* delegate) {
if (io_result != IO_PENDING) {
// This will notify the delegate about the read failure. Although we're on
// the I/O thread, don't call it in the nested context.
- message_loop_for_io_->PostTask(
- FROM_HERE, base::Bind(&RawChannel::OnReadCompleted,
- weak_ptr_factory_.GetWeakPtr(), io_result, 0));
+ message_loop_for_io_->PostTask(FROM_HERE,
+ base::Bind(&RawChannel::OnReadCompleted,
+ weak_ptr_factory_.GetWeakPtr(),
+ io_result,
+ 0));
}
// ScheduleRead() failure is treated as a read failure (by notifying the
@@ -243,15 +246,15 @@ bool RawChannel::WriteMessage(scoped_ptr<MessageInTransit> message) {
if (io_result == IO_PENDING)
return true;
- bool result = OnWriteCompletedNoLock(io_result, platform_handles_written,
- bytes_written);
+ bool result = OnWriteCompletedNoLock(
+ io_result, platform_handles_written, bytes_written);
if (!result) {
// Even if we're on the I/O thread, don't call |OnError()| in the nested
// context.
- message_loop_for_io_->PostTask(
- FROM_HERE,
- base::Bind(&RawChannel::CallOnError, weak_ptr_factory_.GetWeakPtr(),
- Delegate::ERROR_WRITE));
+ message_loop_for_io_->PostTask(FROM_HERE,
+ base::Bind(&RawChannel::CallOnError,
+ weak_ptr_factory_.GetWeakPtr(),
+ Delegate::ERROR_WRITE));
}
return result;
@@ -309,7 +312,8 @@ void RawChannel::OnReadCompleted(IOResult io_result, size_t bytes_read) {
// TODO(vtl): Validate that |message_size| is sane.
while (remaining_bytes > 0 && MessageInTransit::GetNextMessageSize(
&read_buffer_->buffer_[read_buffer_start],
- remaining_bytes, &message_size) &&
+ remaining_bytes,
+ &message_size) &&
remaining_bytes >= message_size) {
MessageInTransit::View message_view(
message_size, &read_buffer_->buffer_[read_buffer_start]);
@@ -337,7 +341,8 @@ void RawChannel::OnReadCompleted(IOResult io_result, size_t bytes_read) {
size_t num_platform_handles;
const void* platform_handle_table;
TransportData::GetPlatformHandleTable(
- message_view.transport_data_buffer(), &num_platform_handles,
+ message_view.transport_data_buffer(),
+ &num_platform_handles,
&platform_handle_table);
if (num_platform_handles > 0) {
@@ -378,7 +383,8 @@ void RawChannel::OnReadCompleted(IOResult io_result, size_t bytes_read) {
read_buffer_->num_valid_bytes_ = remaining_bytes;
if (read_buffer_->num_valid_bytes_ > 0) {
memmove(&read_buffer_->buffer_[0],
- &read_buffer_->buffer_[read_buffer_start], remaining_bytes);
+ &read_buffer_->buffer_[read_buffer_start],
+ remaining_bytes);
}
read_buffer_start = 0;
}
@@ -427,8 +433,8 @@ void RawChannel::OnWriteCompleted(IOResult io_result,
return;
}
- did_fail = !OnWriteCompletedNoLock(io_result, platform_handles_written,
- bytes_written);
+ did_fail = !OnWriteCompletedNoLock(
+ io_result, platform_handles_written, bytes_written);
}
if (did_fail)
diff --git a/mojo/edk/system/raw_channel.h b/mojo/edk/system/raw_channel.h
index 62e13ff..1a077ef 100644
--- a/mojo/edk/system/raw_channel.h
+++ b/mojo/edk/system/raw_channel.h
@@ -14,6 +14,7 @@
#include "base/synchronization/lock.h"
#include "mojo/edk/embedder/platform_handle_vector.h"
#include "mojo/edk/embedder/scoped_platform_handle.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/message_in_transit.h"
#include "mojo/edk/system/system_impl_export.h"
diff --git a/mojo/edk/system/raw_channel_posix.cc b/mojo/edk/system/raw_channel_posix.cc
index 71ec02f..45d93e86 100644
--- a/mojo/edk/system/raw_channel_posix.cc
+++ b/mojo/edk/system/raw_channel_posix.cc
@@ -135,7 +135,8 @@ void RawChannelPosix::EnqueueMessageNoLock(
i += embedder::kPlatformChannelMaxNumHandles) {
scoped_ptr<MessageInTransit> fd_message(new MessageInTransit(
MessageInTransit::kTypeRawChannel,
- MessageInTransit::kSubtypeRawChannelPosixExtraPlatformHandles, 0,
+ MessageInTransit::kSubtypeRawChannelPosixExtraPlatformHandles,
+ 0,
nullptr));
embedder::ScopedPlatformHandleVectorPtr fds(
new embedder::PlatformHandleVector(
@@ -252,8 +253,8 @@ RawChannel::IOResult RawChannelPosix::WriteNoLock(
DCHECK(!buffers.empty());
if (buffers.size() == 1) {
- write_result = embedder::PlatformChannelWrite(fd_.get(), buffers[0].addr,
- buffers[0].size);
+ write_result = embedder::PlatformChannelWrite(
+ fd_.get(), buffers[0].addr, buffers[0].size);
} else {
const size_t kMaxBufferCount = 10;
iovec iov[kMaxBufferCount];
@@ -301,8 +302,11 @@ RawChannel::IOResult RawChannelPosix::ScheduleWriteNoLock() {
}
if (message_loop_for_io()->WatchFileDescriptor(
- fd_.get().fd, false, base::MessageLoopForIO::WATCH_WRITE,
- write_watcher_.get(), this)) {
+ fd_.get().fd,
+ false,
+ base::MessageLoopForIO::WATCH_WRITE,
+ write_watcher_.get(),
+ this)) {
pending_write_ = true;
return IO_PENDING;
}
@@ -319,8 +323,11 @@ bool RawChannelPosix::OnInit() {
write_watcher_.reset(new base::MessageLoopForIO::FileDescriptorWatcher());
if (!message_loop_for_io()->WatchFileDescriptor(
- fd_.get().fd, true, base::MessageLoopForIO::WATCH_READ,
- read_watcher_.get(), this)) {
+ fd_.get().fd,
+ true,
+ base::MessageLoopForIO::WATCH_READ,
+ read_watcher_.get(),
+ this)) {
// TODO(vtl): I'm not sure |WatchFileDescriptor()| actually fails cleanly
// (in the sense of returning the message loop's state to what it was before
// it was called).
@@ -414,7 +421,7 @@ RawChannel::IOResult RawChannelPosix::ReadImpl(size_t* bytes_read) {
// then received the message data plus the first set of handles for the next
// message in the subsequent |recvmsg()|.)
if (read_platform_handles_.size() >
- (TransportData::GetMaxPlatformHandles() +
+ (TransportData::kMaxPlatformHandles +
embedder::kPlatformChannelMaxNumHandles)) {
LOG(ERROR) << "Received too many platform handles";
embedder::CloseAllPlatformHandles(&read_platform_handles_);
@@ -448,8 +455,11 @@ void RawChannelPosix::WaitToWrite() {
DCHECK(write_watcher_);
if (!message_loop_for_io()->WatchFileDescriptor(
- fd_.get().fd, false, base::MessageLoopForIO::WATCH_WRITE,
- write_watcher_.get(), this)) {
+ fd_.get().fd,
+ false,
+ base::MessageLoopForIO::WATCH_WRITE,
+ write_watcher_.get(),
+ this)) {
{
base::AutoLock locker(write_lock());
diff --git a/mojo/edk/system/raw_channel_unittest.cc b/mojo/edk/system/raw_channel_unittest.cc
index 7717f49..9ee937d 100644
--- a/mojo/edk/system/raw_channel_unittest.cc
+++ b/mojo/edk/system/raw_channel_unittest.cc
@@ -41,7 +41,8 @@ scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) {
return make_scoped_ptr(
new MessageInTransit(MessageInTransit::kTypeMessagePipeEndpoint,
MessageInTransit::kSubtypeMessagePipeEndpointData,
- num_bytes, bytes.empty() ? nullptr : &bytes[0]));
+ num_bytes,
+ bytes.empty() ? nullptr : &bytes[0]));
}
bool CheckMessageData(const void* bytes, uint32_t num_bytes) {
@@ -62,8 +63,8 @@ bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle,
scoped_ptr<MessageInTransit> message(MakeTestMessage(num_bytes));
size_t write_size = 0;
- mojo::test::BlockingWrite(handle, message->main_buffer(),
- message->main_buffer_size(), &write_size);
+ mojo::test::BlockingWrite(
+ handle, message->main_buffer(), message->main_buffer_size(), &write_size);
return write_size == message->main_buffer_size();
}
@@ -134,8 +135,8 @@ class TestMessageReaderAndChecker {
for (size_t i = 0; i < kMessageReaderMaxPollIterations;) {
size_t read_size = 0;
- CHECK(mojo::test::NonBlockingRead(handle_, buffer, sizeof(buffer),
- &read_size));
+ CHECK(mojo::test::NonBlockingRead(
+ handle_, buffer, sizeof(buffer), &read_size));
// Append newly-read data to |bytes_|.
bytes_.insert(bytes_.end(), buffer, buffer + read_size);
@@ -143,7 +144,8 @@ class TestMessageReaderAndChecker {
// If we have the header....
size_t message_size;
if (MessageInTransit::GetNextMessageSize(
- bytes_.empty() ? nullptr : &bytes_[0], bytes_.size(),
+ bytes_.empty() ? nullptr : &bytes_[0],
+ bytes_.size(),
&message_size)) {
// If we've read the whole message....
if (bytes_.size() >= message_size) {
@@ -376,14 +378,16 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) {
WriteOnlyRawChannelDelegate writer_delegate;
scoped_ptr<RawChannel> writer_rc(RawChannel::Create(handles[0].Pass()));
io_thread()->PostTaskAndWait(FROM_HERE,
- base::Bind(&InitOnIOThread, writer_rc.get(),
+ base::Bind(&InitOnIOThread,
+ writer_rc.get(),
base::Unretained(&writer_delegate)));
ReadCountdownRawChannelDelegate reader_delegate(kNumWriterThreads *
kNumWriteMessagesPerThread);
scoped_ptr<RawChannel> reader_rc(RawChannel::Create(handles[1].Pass()));
io_thread()->PostTaskAndWait(FROM_HERE,
- base::Bind(&InitOnIOThread, reader_rc.get(),
+ base::Bind(&InitOnIOThread,
+ reader_rc.get(),
base::Unretained(&reader_delegate)));
{
diff --git a/mojo/edk/system/raw_channel_win.cc b/mojo/edk/system/raw_channel_win.cc
index 27b9ccf..98380a9 100644
--- a/mojo/edk/system/raw_channel_win.cc
+++ b/mojo/edk/system/raw_channel_win.cc
@@ -371,9 +371,11 @@ RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) {
size_t bytes_to_read = 0;
read_buffer()->GetBuffer(&buffer, &bytes_to_read);
- BOOL result =
- ReadFile(io_handler_->handle(), buffer, static_cast<DWORD>(bytes_to_read),
- nullptr, &io_handler_->read_context()->overlapped);
+ BOOL result = ReadFile(io_handler_->handle(),
+ buffer,
+ static_cast<DWORD>(bytes_to_read),
+ nullptr,
+ &io_handler_->read_context()->overlapped);
if (!result) {
DWORD error = GetLastError();
if (error == ERROR_BROKEN_PIPE)
@@ -386,9 +388,11 @@ RawChannel::IOResult RawChannelWin::Read(size_t* bytes_read) {
if (result && skip_completion_port_on_success_) {
DWORD bytes_read_dword = 0;
- BOOL get_size_result = GetOverlappedResult(
- io_handler_->handle(), &io_handler_->read_context()->overlapped,
- &bytes_read_dword, FALSE);
+ BOOL get_size_result =
+ GetOverlappedResult(io_handler_->handle(),
+ &io_handler_->read_context()->overlapped,
+ &bytes_read_dword,
+ FALSE);
DPCHECK(get_size_result);
*bytes_read = bytes_read_dword;
return IO_SUCCEEDED;
@@ -422,10 +426,12 @@ RawChannel::IOResult RawChannelWin::ScheduleRead() {
// |io_handler_| won't go away before the task is run, so it is safe to use
// |base::Unretained()|.
message_loop_for_io()->PostTask(
- FROM_HERE, base::Bind(&RawChannelIOHandler::OnIOCompleted,
- base::Unretained(io_handler_),
- base::Unretained(io_handler_->read_context()),
- static_cast<DWORD>(bytes_read), ERROR_SUCCESS));
+ FROM_HERE,
+ base::Bind(&RawChannelIOHandler::OnIOCompleted,
+ base::Unretained(io_handler_),
+ base::Unretained(io_handler_->read_context()),
+ static_cast<DWORD>(bytes_read),
+ ERROR_SUCCESS));
return IO_PENDING;
}
@@ -459,10 +465,11 @@ RawChannel::IOResult RawChannelWin::WriteNoLock(
// TODO(yzshen): Handle multi-segment writes more efficiently.
DWORD bytes_written_dword = 0;
- BOOL result =
- WriteFile(io_handler_->handle(), buffers[0].addr,
- static_cast<DWORD>(buffers[0].size), &bytes_written_dword,
- &io_handler_->write_context_no_lock()->overlapped);
+ BOOL result = WriteFile(io_handler_->handle(),
+ buffers[0].addr,
+ static_cast<DWORD>(buffers[0].size),
+ &bytes_written_dword,
+ &io_handler_->write_context_no_lock()->overlapped);
if (!result) {
DWORD error = GetLastError();
if (error == ERROR_BROKEN_PIPE)
@@ -514,7 +521,8 @@ RawChannel::IOResult RawChannelWin::ScheduleWriteNoLock() {
base::Bind(&RawChannelIOHandler::OnIOCompleted,
base::Unretained(io_handler_),
base::Unretained(io_handler_->write_context_no_lock()),
- static_cast<DWORD>(bytes_written), ERROR_SUCCESS));
+ static_cast<DWORD>(bytes_written),
+ ERROR_SUCCESS));
return IO_PENDING;
}
diff --git a/mojo/edk/system/remote_message_pipe_unittest.cc b/mojo/edk/system/remote_message_pipe_unittest.cc
index e3a320e..d3a95df 100644
--- a/mojo/edk/system/remote_message_pipe_unittest.cc
+++ b/mojo/edk/system/remote_message_pipe_unittest.cc
@@ -48,14 +48,16 @@ class RemoteMessagePipeTest : public testing::Test {
void SetUp() override {
io_thread_.PostTaskAndWait(
- FROM_HERE, base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread,
- base::Unretained(this)));
+ FROM_HERE,
+ base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread,
+ base::Unretained(this)));
}
void TearDown() override {
io_thread_.PostTaskAndWait(
- FROM_HERE, base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread,
- base::Unretained(this)));
+ FROM_HERE,
+ base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread,
+ base::Unretained(this)));
}
protected:
@@ -67,7 +69,9 @@ class RemoteMessagePipeTest : public testing::Test {
io_thread_.PostTaskAndWait(
FROM_HERE,
base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointsOnIOThread,
- base::Unretained(this), ep0, ep1));
+ base::Unretained(this),
+ ep0,
+ ep1));
}
// This bootstraps |ep| on |channels_[channel_index]|. It assumes/requires
@@ -78,7 +82,9 @@ class RemoteMessagePipeTest : public testing::Test {
io_thread_.PostTask(
FROM_HERE,
base::Bind(&RemoteMessagePipeTest::BootstrapChannelEndpointOnIOThread,
- base::Unretained(this), channel_index, ep));
+ base::Unretained(this),
+ channel_index,
+ ep));
}
void RestoreInitialState() {
@@ -192,10 +198,12 @@ TEST_F(RemoteMessagePipeTest, Basic) {
mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
// Write to MP 0, port 0.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Wait.
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
@@ -209,8 +217,11 @@ TEST_F(RemoteMessagePipeTest, Basic) {
// Read from MP 1, port 1.
EXPECT_EQ(MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp1->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
EXPECT_STREQ(kHello, buffer);
@@ -222,10 +233,12 @@ TEST_F(RemoteMessagePipeTest, Basic) {
MOJO_RESULT_OK,
mp0->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr));
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->WriteMessage(1,
+ UserPointer<const void>(kWorld),
+ sizeof(kWorld),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
EXPECT_EQ(456u, context);
@@ -238,8 +251,11 @@ TEST_F(RemoteMessagePipeTest, Basic) {
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- mp0->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp0->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size));
EXPECT_STREQ(kWorld, buffer);
@@ -304,8 +320,10 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
EXPECT_EQ(MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(&remote_id),
- sizeof(remote_id), nullptr,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(&remote_id),
+ sizeof(remote_id),
+ nullptr,
MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
@@ -320,8 +338,11 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
ChannelEndpointId received_id;
buffer_size = static_cast<uint32_t>(sizeof(received_id));
EXPECT_EQ(MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(&received_id),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp1->ReadMessage(1,
+ UserPointer<void>(&received_id),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(received_id), static_cast<size_t>(buffer_size));
EXPECT_EQ(remote_id, received_id);
@@ -338,10 +359,12 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
MOJO_RESULT_OK,
mp3->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp2->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp2->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
EXPECT_EQ(789u, context);
@@ -355,25 +378,37 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
// Make sure there's nothing on MP 0, port 0 or MP 1, port 1 or MP 2, port 0.
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp0->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp0->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp1->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp1->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp2->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp2->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
// Read from MP 3, port 1.
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- mp3->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp3->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
EXPECT_STREQ(kHello, buffer);
@@ -385,10 +420,12 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
MOJO_RESULT_OK,
mp1->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, nullptr));
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kWorld),
+ sizeof(kWorld),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
EXPECT_EQ(123u, context);
@@ -402,24 +439,36 @@ TEST_F(RemoteMessagePipeTest, Multiplex) {
// Make sure there's nothing on the other ports.
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp0->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp0->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp2->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp2->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
- mp3->ReadMessage(0, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp3->ReadMessage(0,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp1->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(buffer_size));
EXPECT_STREQ(kWorld, buffer);
@@ -446,10 +495,12 @@ TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
// Write to MP 0, port 0.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Close MP 0, port 0 before it's even been attached to the channel and run.
mp0->Close(0);
@@ -482,8 +533,11 @@ TEST_F(RemoteMessagePipeTest, CloseBeforeAttachAndRun) {
// Read from MP 1, port 1.
EXPECT_EQ(MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp1->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
EXPECT_STREQ(kHello, buffer);
@@ -508,10 +562,12 @@ TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) {
scoped_refptr<MessagePipe> mp0(MessagePipe::CreateLocalProxy(&ep0));
// Write to MP 0, port 0.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
BootstrapChannelEndpointNoWait(0, ep0);
@@ -544,8 +600,11 @@ TEST_F(RemoteMessagePipeTest, CloseBeforeConnect) {
// Read from MP 1, port 1.
EXPECT_EQ(MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(buffer),
- MakeUserPointer(&buffer_size), nullptr, nullptr,
+ mp1->ReadMessage(1,
+ UserPointer<void>(buffer),
+ MakeUserPointer(&buffer_size),
+ nullptr,
+ nullptr,
MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(buffer_size));
EXPECT_STREQ(kHello, buffer);
@@ -587,10 +646,12 @@ TEST_F(RemoteMessagePipeTest, HandlePassing) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ &transports,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
// |dispatcher| should have been closed. This is |DCHECK()|ed when the
@@ -614,11 +675,13 @@ TEST_F(RemoteMessagePipeTest, HandlePassing) {
uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
DispatcherVector read_dispatchers;
uint32_t read_num_dispatchers = 10; // Maximum to get.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), &read_dispatchers,
- &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->ReadMessage(1,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ &read_dispatchers,
+ &read_num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
EXPECT_EQ(1u, read_dispatchers.size());
@@ -632,14 +695,16 @@ TEST_F(RemoteMessagePipeTest, HandlePassing) {
// Add the waiter now, before it becomes readable to avoid a race.
waiter.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 456,
- nullptr));
+ dispatcher->AddWaiter(
+ &waiter, MOJO_HANDLE_SIGNAL_READABLE, 456, nullptr));
// Write to "local_mp", port 1.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ local_mp->WriteMessage(1,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// TODO(vtl): FIXME -- We (racily) crash if I close |dispatcher| immediately
// here. (We don't crash if I sleep and then close.)
@@ -659,21 +724,25 @@ TEST_F(RemoteMessagePipeTest, HandlePassing) {
read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dispatcher->ReadMessage(UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), 0,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ MakeUserPointer(&read_buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
// Prepare to wait on "local_mp", port 1.
waiter.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
- nullptr));
+ local_mp->AddWaiter(
+ 1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
// Write to the dispatcher.
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage(
- UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dispatcher->WriteMessage(UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Wait.
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
@@ -689,9 +758,12 @@ TEST_F(RemoteMessagePipeTest, HandlePassing) {
memset(read_buffer, 0, sizeof(read_buffer));
read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- local_mp->ReadMessage(1, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), nullptr,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ local_mp->ReadMessage(1,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ nullptr,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
@@ -724,20 +796,24 @@ TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) {
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfiable_signals);
// Write to the other end (|local_mp|, port 1), and then close it.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ local_mp->WriteMessage(1,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = local_mp->GetHandleSignalsState(0);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfiable_signals);
// Then the second message....
- EXPECT_EQ(
- MOJO_RESULT_OK,
- local_mp->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ local_mp->WriteMessage(1,
+ UserPointer<const void>(kWorld),
+ sizeof(kWorld),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
hss = local_mp->GetHandleSignalsState(0);
EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE,
hss.satisfied_signals);
@@ -767,10 +843,12 @@ TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ &transports,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
// |dispatcher| should have been closed. This is |DCHECK()|ed when the
@@ -794,11 +872,13 @@ TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) {
uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
DispatcherVector read_dispatchers;
uint32_t read_num_dispatchers = 10; // Maximum to get.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), &read_dispatchers,
- &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->ReadMessage(1,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ &read_dispatchers,
+ &read_num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
EXPECT_EQ(1u, read_dispatchers.size());
@@ -818,8 +898,10 @@ TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) {
read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dispatcher->ReadMessage(UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), 0,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ MakeUserPointer(&read_buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
// It should still be readable.
@@ -831,8 +913,10 @@ TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) {
read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dispatcher->ReadMessage(UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), 0,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ MakeUserPointer(&read_buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kWorld, read_buffer);
// Now it should no longer be readable.
@@ -866,16 +950,19 @@ TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) {
// We'll try to pass this dispatcher.
scoped_refptr<SharedBufferDispatcher> dispatcher;
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
- platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions,
- 100, &dispatcher));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 100,
+ &dispatcher));
ASSERT_TRUE(dispatcher.get());
// Make a mapping.
scoped_ptr<embedder::PlatformSharedBufferMapping> mapping0;
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
- 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping0));
ASSERT_TRUE(mapping0);
ASSERT_TRUE(mapping0->GetBase());
ASSERT_EQ(100u, mapping0->GetLength());
@@ -898,10 +985,12 @@ TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ &transports,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
// |dispatcher| should have been closed. This is |DCHECK()|ed when the
@@ -925,11 +1014,13 @@ TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) {
uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
DispatcherVector read_dispatchers;
uint32_t read_num_dispatchers = 10; // Maximum to get.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), &read_dispatchers,
- &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->ReadMessage(1,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ &read_dispatchers,
+ &read_num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
EXPECT_EQ(1u, read_dispatchers.size());
@@ -942,8 +1033,9 @@ TEST_F(RemoteMessagePipeTest, MAYBE_SharedBufferPassing) {
// Make another mapping.
scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1;
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
- 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
ASSERT_TRUE(mapping1);
ASSERT_TRUE(mapping1->GetBase());
ASSERT_EQ(100u, mapping1->GetLength());
@@ -1018,10 +1110,12 @@ TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kWorld), sizeof(kWorld),
- &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kWorld),
+ sizeof(kWorld),
+ &transports,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
// |dispatcher| should have been closed. This is |DCHECK()|ed when the
@@ -1045,11 +1139,13 @@ TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) {
uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
DispatcherVector read_dispatchers;
uint32_t read_num_dispatchers = 10; // Maximum to get.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), &read_dispatchers,
- &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->ReadMessage(1,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ &read_dispatchers,
+ &read_num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kWorld, read_buffer);
EXPECT_EQ(1u, read_dispatchers.size());
@@ -1156,10 +1252,12 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->WriteMessage(0, UserPointer<const void>(kHello), sizeof(kHello),
- &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->WriteMessage(0,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ &transports,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
// |dispatcher| should have been closed. This is |DCHECK()|ed when the
@@ -1183,11 +1281,13 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
DispatcherVector read_dispatchers;
uint32_t read_num_dispatchers = 10; // Maximum to get.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp1->ReadMessage(1, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), &read_dispatchers,
- &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->ReadMessage(1,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ &read_dispatchers,
+ &read_num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
EXPECT_EQ(1u, read_dispatchers.size());
@@ -1216,10 +1316,12 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
std::vector<DispatcherTransport> transports;
transports.push_back(transport);
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp1->WriteMessage(1, UserPointer<const void>(kWorld), sizeof(kWorld),
- &transports, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp1->WriteMessage(1,
+ UserPointer<const void>(kWorld),
+ sizeof(kWorld),
+ &transports,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
transport.End();
// |dispatcher| should have been closed. This is |DCHECK()|ed when the
@@ -1241,11 +1343,13 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
// Read from MP 0, port 0.
read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
read_num_dispatchers = 10; // Maximum to get.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- mp0->ReadMessage(0, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), &read_dispatchers,
- &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ mp0->ReadMessage(0,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ &read_dispatchers,
+ &read_num_dispatchers,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kWorld), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kWorld, read_buffer);
EXPECT_EQ(1u, read_dispatchers.size());
@@ -1260,14 +1364,16 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
// Add the waiter now, before it becomes readable to avoid a race.
waiter.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- dispatcher->AddWaiter(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
- nullptr));
+ dispatcher->AddWaiter(
+ &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
// Write to "local_mp", port 1.
- EXPECT_EQ(
- MOJO_RESULT_OK,
- local_mp->WriteMessage(1, UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ local_mp->WriteMessage(1,
+ UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Wait for the dispatcher to become readable.
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
@@ -1284,21 +1390,25 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
EXPECT_EQ(MOJO_RESULT_OK,
dispatcher->ReadMessage(UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), 0,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ MakeUserPointer(&read_buffer_size),
+ 0,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
// Prepare to wait on "local_mp", port 1.
waiter.Init();
ASSERT_EQ(MOJO_RESULT_OK,
- local_mp->AddWaiter(1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789,
- nullptr));
+ local_mp->AddWaiter(
+ 1, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 789, nullptr));
// Write to the dispatcher.
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher->WriteMessage(
- UserPointer<const void>(kHello), sizeof(kHello),
- nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dispatcher->WriteMessage(UserPointer<const void>(kHello),
+ sizeof(kHello),
+ nullptr,
+ MOJO_WRITE_MESSAGE_FLAG_NONE));
// Wait.
EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(MOJO_DEADLINE_INDEFINITE, &context));
@@ -1314,9 +1424,12 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) {
memset(read_buffer, 0, sizeof(read_buffer));
read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer));
EXPECT_EQ(MOJO_RESULT_OK,
- local_mp->ReadMessage(1, UserPointer<void>(read_buffer),
- MakeUserPointer(&read_buffer_size), nullptr,
- nullptr, MOJO_READ_MESSAGE_FLAG_NONE));
+ local_mp->ReadMessage(1,
+ UserPointer<void>(read_buffer),
+ MakeUserPointer(&read_buffer_size),
+ nullptr,
+ nullptr,
+ MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(sizeof(kHello), static_cast<size_t>(read_buffer_size));
EXPECT_STREQ(kHello, read_buffer);
diff --git a/mojo/edk/system/run_all_unittests.cc b/mojo/edk/system/run_all_unittests.cc
index 3ea1682..2855e96 100644
--- a/mojo/edk/system/run_all_unittests.cc
+++ b/mojo/edk/system/run_all_unittests.cc
@@ -15,6 +15,7 @@ int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
- argc, argv,
+ argc,
+ argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
diff --git a/mojo/edk/system/shared_buffer_dispatcher.cc b/mojo/edk/system/shared_buffer_dispatcher.cc
index 38ac390..7e345d9 100644
--- a/mojo/edk/system/shared_buffer_dispatcher.cc
+++ b/mojo/edk/system/shared_buffer_dispatcher.cc
@@ -10,7 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "mojo/edk/embedder/platform_support.h"
#include "mojo/edk/system/channel.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/memory.h"
#include "mojo/edk/system/options_validation.h"
#include "mojo/public/c/system/macros.h"
@@ -69,7 +69,7 @@ MojoResult SharedBufferDispatcher::Create(
scoped_refptr<SharedBufferDispatcher>* result) {
if (!num_bytes)
return MOJO_RESULT_INVALID_ARGUMENT;
- if (num_bytes > GetConfiguration().max_shared_memory_num_bytes)
+ if (num_bytes > kMaxSharedMemoryNumBytes)
return MOJO_RESULT_RESOURCE_EXHAUSTED;
scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer(
@@ -163,8 +163,8 @@ MojoResult SharedBufferDispatcher::ValidateDuplicateOptions(
if (!reader.is_valid())
return MOJO_RESULT_INVALID_ARGUMENT;
- if (!OPTIONS_STRUCT_HAS_MEMBER(MojoDuplicateBufferHandleOptions, flags,
- reader))
+ if (!OPTIONS_STRUCT_HAS_MEMBER(
+ MojoDuplicateBufferHandleOptions, flags, reader))
return MOJO_RESULT_OK;
if ((reader.options().flags & ~kKnownFlags))
return MOJO_RESULT_UNIMPLEMENTED;
diff --git a/mojo/edk/system/shared_buffer_dispatcher_unittest.cc b/mojo/edk/system/shared_buffer_dispatcher_unittest.cc
index 5866089..a80f71d 100644
--- a/mojo/edk/system/shared_buffer_dispatcher_unittest.cc
+++ b/mojo/edk/system/shared_buffer_dispatcher_unittest.cc
@@ -58,8 +58,9 @@ TEST_F(SharedBufferDispatcherTest, ValidateCreateOptionsValid) {
// Default options.
{
MojoCreateSharedBufferOptions validated_options = {};
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::ValidateCreateOptions(
- NullUserPointer(), &validated_options));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::ValidateCreateOptions(
+ NullUserPointer(), &validated_options));
RevalidateCreateOptions(validated_options);
}
@@ -114,17 +115,20 @@ TEST_F(SharedBufferDispatcherTest, ValidateCreateOptionsInvalid) {
TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) {
scoped_refptr<SharedBufferDispatcher> dispatcher;
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
- platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions,
- 100, &dispatcher));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 100,
+ &dispatcher));
ASSERT_TRUE(dispatcher.get());
EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType());
// Make a couple of mappings.
scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1;
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
- 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
ASSERT_TRUE(mapping1);
ASSERT_TRUE(mapping1->GetBase());
EXPECT_EQ(100u, mapping1->GetLength());
@@ -132,8 +136,9 @@ TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) {
static_cast<char*>(mapping1->GetBase())[50] = 'x';
scoped_ptr<embedder::PlatformSharedBufferMapping> mapping2;
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher->MapBuffer(
- 50, 50, MOJO_MAP_BUFFER_FLAG_NONE, &mapping2));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher->MapBuffer(50, 50, MOJO_MAP_BUFFER_FLAG_NONE, &mapping2));
ASSERT_TRUE(mapping2);
ASSERT_TRUE(mapping2->GetBase());
EXPECT_EQ(50u, mapping2->GetLength());
@@ -149,30 +154,35 @@ TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) {
TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) {
scoped_refptr<SharedBufferDispatcher> dispatcher1;
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
- platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions,
- 100, &dispatcher1));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 100,
+ &dispatcher1));
// Map and write something.
scoped_ptr<embedder::PlatformSharedBufferMapping> mapping;
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->MapBuffer(
- 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher1->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
static_cast<char*>(mapping->GetBase())[0] = 'x';
mapping.reset();
// Duplicate |dispatcher1| and then close it.
scoped_refptr<Dispatcher> dispatcher2;
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle(
- NullUserPointer(), &dispatcher2));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher1->DuplicateBufferHandle(NullUserPointer(), &dispatcher2));
ASSERT_TRUE(dispatcher2.get());
EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType());
EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
// Map |dispatcher2| and read something.
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->MapBuffer(
- 0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
+ EXPECT_EQ(
+ MOJO_RESULT_OK,
+ dispatcher2->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]);
EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
@@ -180,10 +190,12 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandle) {
TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
scoped_refptr<SharedBufferDispatcher> dispatcher1;
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
- platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions,
- 100, &dispatcher1));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 100,
+ &dispatcher1));
MojoDuplicateBufferHandleOptions options[] = {
{sizeof(MojoDuplicateBufferHandleOptions),
@@ -191,8 +203,9 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
{sizeof(MojoDuplicateBufferHandleOptionsFlags), ~0u}};
for (size_t i = 0; i < arraysize(options); i++) {
scoped_refptr<Dispatcher> dispatcher2;
- EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle(
- MakeUserPointer(&options[i]), &dispatcher2));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options[i]),
+ &dispatcher2));
ASSERT_TRUE(dispatcher2.get());
EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType());
EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
@@ -203,10 +216,12 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) {
TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) {
scoped_refptr<SharedBufferDispatcher> dispatcher1;
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
- platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions,
- 100, &dispatcher1));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 100,
+ &dispatcher1));
// Invalid |struct_size|.
{
@@ -236,27 +251,32 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) {
TEST_F(SharedBufferDispatcherTest, CreateInvalidNumBytes) {
// Size too big.
scoped_refptr<SharedBufferDispatcher> dispatcher;
- EXPECT_EQ(
- MOJO_RESULT_RESOURCE_EXHAUSTED,
- SharedBufferDispatcher::Create(
- platform_support(), SharedBufferDispatcher::kDefaultCreateOptions,
- std::numeric_limits<uint64_t>::max(), &dispatcher));
+ EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ std::numeric_limits<uint64_t>::max(),
+ &dispatcher));
EXPECT_FALSE(dispatcher.get());
// Zero size.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
SharedBufferDispatcher::Create(
platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions, 0, &dispatcher));
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 0,
+ &dispatcher));
EXPECT_FALSE(dispatcher.get());
}
TEST_F(SharedBufferDispatcherTest, MapBufferInvalidArguments) {
scoped_refptr<SharedBufferDispatcher> dispatcher;
- EXPECT_EQ(MOJO_RESULT_OK, SharedBufferDispatcher::Create(
- platform_support(),
- SharedBufferDispatcher::kDefaultCreateOptions,
- 100, &dispatcher));
+ EXPECT_EQ(MOJO_RESULT_OK,
+ SharedBufferDispatcher::Create(
+ platform_support(),
+ SharedBufferDispatcher::kDefaultCreateOptions,
+ 100,
+ &dispatcher));
scoped_ptr<embedder::PlatformSharedBufferMapping> mapping;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
diff --git a/mojo/edk/system/simple_dispatcher_unittest.cc b/mojo/edk/system/simple_dispatcher_unittest.cc
index f23ff68..502e34b 100644
--- a/mojo/edk/system/simple_dispatcher_unittest.cc
+++ b/mojo/edk/system/simple_dispatcher_unittest.cc
@@ -343,9 +343,14 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) {
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
{
d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE);
- test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 1, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 1,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
} // Joins the thread.
@@ -363,9 +368,14 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) {
{
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
{
- test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 2, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 2,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
@@ -387,9 +397,14 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) {
{
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
{
- test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 3, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 3,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
@@ -409,9 +424,14 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) {
// Wait for readable and dispatcher gets closed.
{
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
- test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
- MOJO_DEADLINE_INDEFINITE, 4, &did_wait, &result,
- &context, &hss);
+ test::WaiterThread thread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ 4,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
@@ -430,9 +450,14 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) {
{
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
{
- test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE,
- 2 * test::EpsilonTimeout().InMicroseconds(), 5,
- &did_wait, &result, &context, &hss);
+ test::WaiterThread thread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 2 * test::EpsilonTimeout().InMicroseconds(),
+ 5,
+ &did_wait,
+ &result,
+ &context,
+ &hss);
stopwatch.Start();
thread.Start();
base::PlatformThread::Sleep(1 * test::EpsilonTimeout());
@@ -471,9 +496,14 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) {
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
ScopedVector<test::WaiterThread> threads;
for (uint32_t i = 0; i < kNumWaiters; i++) {
- threads.push_back(new test::WaiterThread(
- d, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, i,
- &did_wait[i], &result[i], &context[i], &hss[i]));
+ threads.push_back(new test::WaiterThread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ i,
+ &did_wait[i],
+ &result[i],
+ &context[i],
+ &hss[i]));
threads.back()->Start();
}
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
@@ -494,15 +524,25 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) {
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
ScopedVector<test::WaiterThread> threads;
for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
- threads.push_back(new test::WaiterThread(
- d, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, i,
- &did_wait[i], &result[i], &context[i], &hss[i]));
+ threads.push_back(new test::WaiterThread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ i,
+ &did_wait[i],
+ &result[i],
+ &context[i],
+ &hss[i]));
threads.back()->Start();
}
for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
- threads.push_back(new test::WaiterThread(
- d, MOJO_HANDLE_SIGNAL_WRITABLE, MOJO_DEADLINE_INDEFINITE, i,
- &did_wait[i], &result[i], &context[i], &hss[i]));
+ threads.push_back(new test::WaiterThread(d,
+ MOJO_HANDLE_SIGNAL_WRITABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ i,
+ &did_wait[i],
+ &result[i],
+ &context[i],
+ &hss[i]));
threads.back()->Start();
}
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
@@ -531,15 +571,25 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) {
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
ScopedVector<test::WaiterThread> threads;
for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
- threads.push_back(new test::WaiterThread(
- d, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE, i,
- &did_wait[i], &result[i], &context[i], &hss[i]));
+ threads.push_back(new test::WaiterThread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ i,
+ &did_wait[i],
+ &result[i],
+ &context[i],
+ &hss[i]));
threads.back()->Start();
}
for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
- threads.push_back(new test::WaiterThread(
- d, MOJO_HANDLE_SIGNAL_WRITABLE, MOJO_DEADLINE_INDEFINITE, i,
- &did_wait[i], &result[i], &context[i], &hss[i]));
+ threads.push_back(new test::WaiterThread(d,
+ MOJO_HANDLE_SIGNAL_WRITABLE,
+ MOJO_DEADLINE_INDEFINITE,
+ i,
+ &did_wait[i],
+ &result[i],
+ &context[i],
+ &hss[i]));
threads.back()->Start();
}
base::PlatformThread::Sleep(1 * test::EpsilonTimeout());
@@ -569,17 +619,27 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) {
scoped_refptr<MockSimpleDispatcher> d(new MockSimpleDispatcher());
ScopedVector<test::WaiterThread> threads;
for (uint32_t i = 0; i < kNumWaiters / 2; i++) {
- threads.push_back(new test::WaiterThread(
- d, MOJO_HANDLE_SIGNAL_READABLE,
- 3 * test::EpsilonTimeout().InMicroseconds(), i, &did_wait[i],
- &result[i], &context[i], &hss[i]));
+ threads.push_back(
+ new test::WaiterThread(d,
+ MOJO_HANDLE_SIGNAL_READABLE,
+ 3 * test::EpsilonTimeout().InMicroseconds(),
+ i,
+ &did_wait[i],
+ &result[i],
+ &context[i],
+ &hss[i]));
threads.back()->Start();
}
for (uint32_t i = kNumWaiters / 2; i < kNumWaiters; i++) {
- threads.push_back(new test::WaiterThread(
- d, MOJO_HANDLE_SIGNAL_WRITABLE,
- 1 * test::EpsilonTimeout().InMicroseconds(), i, &did_wait[i],
- &result[i], &context[i], &hss[i]));
+ threads.push_back(
+ new test::WaiterThread(d,
+ MOJO_HANDLE_SIGNAL_WRITABLE,
+ 1 * test::EpsilonTimeout().InMicroseconds(),
+ i,
+ &did_wait[i],
+ &result[i],
+ &context[i],
+ &hss[i]));
threads.back()->Start();
}
base::PlatformThread::Sleep(2 * test::EpsilonTimeout());
diff --git a/mojo/edk/system/test_utils.h b/mojo/edk/system/test_utils.h
index b8dee66..3ab1907 100644
--- a/mojo/edk/system/test_utils.h
+++ b/mojo/edk/system/test_utils.h
@@ -5,7 +5,10 @@
#ifndef MOJO_EDK_SYSTEM_TEST_UTILS_H_
#define MOJO_EDK_SYSTEM_TEST_UTILS_H_
+#include <stdint.h>
+
#include "base/callback_forward.h"
+#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/task_runner.h"
diff --git a/mojo/edk/system/transport_data.cc b/mojo/edk/system/transport_data.cc
index 300b731..774b744 100644
--- a/mojo/edk/system/transport_data.cc
+++ b/mojo/edk/system/transport_data.cc
@@ -9,7 +9,7 @@
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "mojo/edk/system/channel.h"
-#include "mojo/edk/system/configuration.h"
+#include "mojo/edk/system/constants.h"
#include "mojo/edk/system/message_in_transit.h"
namespace mojo {
@@ -32,20 +32,19 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
TransportData::kMaxSerializedDispatcherPlatformHandles;
// static
-size_t TransportData::GetMaxBufferSize() {
- // In additional to the header, for each attached (Mojo) handle there'll be a
- // handle table entry and serialized dispatcher data.
- return sizeof(Header) +
- GetConfiguration().max_message_num_handles *
- (sizeof(HandleTableEntry) + kMaxSerializedDispatcherSize) +
- GetMaxPlatformHandles() * kMaxSizePerPlatformHandle;
-}
+const size_t TransportData::kMaxPlatformHandles =
+ kMaxMessageNumHandles * kMaxSerializedDispatcherPlatformHandles;
+// In additional to the header, for each attached (Mojo) handle there'll be a
+// handle table entry and serialized dispatcher data.
+// Note: This definition must follow the one for |kMaxPlatformHandles|;
+// otherwise, we get a static initializer with gcc (but not clang).
// static
-size_t TransportData::GetMaxPlatformHandles() {
- return GetConfiguration().max_message_num_handles *
- kMaxSerializedDispatcherPlatformHandles;
-}
+const size_t TransportData::kMaxBufferSize =
+ sizeof(Header) +
+ kMaxMessageNumHandles *
+ (sizeof(HandleTableEntry) + kMaxSerializedDispatcherSize) +
+ kMaxPlatformHandles * kMaxSizePerPlatformHandle;
struct TransportData::PrivateStructForCompileAsserts {
static_assert(sizeof(Header) % MessageInTransit::kMessageAlignment == 0,
@@ -91,11 +90,11 @@ TransportData::TransportData(scoped_ptr<DispatcherVector> dispatchers,
DCHECK_LE(max_size, kMaxSerializedDispatcherSize);
estimated_size += MessageInTransit::RoundUpMessageAlignment(max_size);
- DCHECK_LE(estimated_size, GetMaxBufferSize());
+ DCHECK_LE(estimated_size, kMaxBufferSize);
DCHECK_LE(max_platform_handles, kMaxSerializedDispatcherPlatformHandles);
estimated_num_platform_handles += max_platform_handles;
- DCHECK_LE(estimated_num_platform_handles, GetMaxPlatformHandles());
+ DCHECK_LE(estimated_num_platform_handles, kMaxPlatformHandles);
#if DCHECK_IS_ON
all_max_sizes[i] = max_size;
@@ -110,7 +109,7 @@ TransportData::TransportData(scoped_ptr<DispatcherVector> dispatchers,
DCHECK_LE(size_per_platform_handle, kMaxSizePerPlatformHandle);
estimated_size += estimated_num_platform_handles * size_per_platform_handle;
estimated_size = MessageInTransit::RoundUpMessageAlignment(estimated_size);
- DCHECK_LE(estimated_size, GetMaxBufferSize());
+ DCHECK_LE(estimated_size, kMaxBufferSize);
}
buffer_.reset(static_cast<char*>(
@@ -149,7 +148,10 @@ TransportData::TransportData(scoped_ptr<DispatcherVector> dispatchers,
void* destination = buffer_.get() + current_offset;
size_t actual_size = 0;
if (Dispatcher::TransportDataAccess::EndSerializeAndClose(
- dispatcher, channel, destination, &actual_size,
+ dispatcher,
+ channel,
+ destination,
+ &actual_size,
platform_handles_.get())) {
handle_table[i].type = static_cast<int32_t>(dispatcher->GetType());
handle_table[i].offset = static_cast<uint32_t>(current_offset);
@@ -214,7 +216,7 @@ const char* TransportData::ValidateBuffer(
// Always make sure that the buffer size is sane; if it's not, someone's
// messing with us.
- if (buffer_size < sizeof(Header) || buffer_size > GetMaxBufferSize() ||
+ if (buffer_size < sizeof(Header) || buffer_size > kMaxBufferSize ||
buffer_size % MessageInTransit::kMessageAlignment != 0)
return "Invalid message secondary buffer size";
@@ -231,7 +233,7 @@ const char* TransportData::ValidateBuffer(
#endif
// Sanity-check |num_handles| (before multiplying it against anything).
- if (num_handles > GetConfiguration().max_message_num_handles)
+ if (num_handles > kMaxMessageNumHandles)
return "Message handle payload too large";
if (buffer_size < sizeof(Header) + num_handles * sizeof(HandleTableEntry))
diff --git a/mojo/edk/system/transport_data.h b/mojo/edk/system/transport_data.h
index d54ad2a..395bc73 100644
--- a/mojo/edk/system/transport_data.h
+++ b/mojo/edk/system/transport_data.h
@@ -84,10 +84,10 @@ class MOJO_SYSTEM_IMPL_EXPORT TransportData {
static const size_t kMaxSerializedDispatcherPlatformHandles = 2;
// The maximum possible size of a valid transport data buffer.
- static size_t GetMaxBufferSize();
+ static const size_t kMaxBufferSize;
// The maximum total number of platform handles that may be attached.
- static size_t GetMaxPlatformHandles();
+ static const size_t kMaxPlatformHandles;
TransportData(scoped_ptr<DispatcherVector> dispatchers, Channel* channel);
diff --git a/mojo/edk/system/waiter_test_utils.cc b/mojo/edk/system/waiter_test_utils.cc
index 39cb14e..06a4033 100644
--- a/mojo/edk/system/waiter_test_utils.cc
+++ b/mojo/edk/system/waiter_test_utils.cc
@@ -55,8 +55,8 @@ WaiterThread::~WaiterThread() {
void WaiterThread::Run() {
waiter_.Init();
- *result_out_ = dispatcher_->AddWaiter(&waiter_, handle_signals_, context_,
- signals_state_out_);
+ *result_out_ = dispatcher_->AddWaiter(
+ &waiter_, handle_signals_, context_, signals_state_out_);
if (*result_out_ != MOJO_RESULT_OK)
return;
diff --git a/mojo/edk/test/BUILD.gn b/mojo/edk/test/BUILD.gn
index 38a631b..e5d53b5 100644
--- a/mojo/edk/test/BUILD.gn
+++ b/mojo/edk/test/BUILD.gn
@@ -56,8 +56,6 @@ source_set("test_support_impl") {
testonly = true
deps = [
"//base",
- "//base/test:test_support",
- "//mojo/public/c/test_support",
]
sources = [
diff --git a/mojo/edk/test/multiprocess_test_helper.cc b/mojo/edk/test/multiprocess_test_helper.cc
index 30aa0be..02367d6 100644
--- a/mojo/edk/test/multiprocess_test_helper.cc
+++ b/mojo/edk/test/multiprocess_test_helper.cc
@@ -60,8 +60,8 @@ int MultiprocessTestHelper::WaitForChildShutdown() {
CHECK_NE(test_child_handle_, base::kNullProcessHandle);
int rv = -1;
- CHECK(base::WaitForExitCodeWithTimeout(test_child_handle_, &rv,
- TestTimeouts::action_timeout()));
+ CHECK(base::WaitForExitCodeWithTimeout(
+ test_child_handle_, &rv, TestTimeouts::action_timeout()));
base::CloseProcessHandle(test_child_handle_);
test_child_handle_ = base::kNullProcessHandle;
return rv;
diff --git a/mojo/edk/test/multiprocess_test_helper.h b/mojo/edk/test/multiprocess_test_helper.h
index d131460..6b2713f 100644
--- a/mojo/edk/test/multiprocess_test_helper.h
+++ b/mojo/edk/test/multiprocess_test_helper.h
@@ -7,7 +7,8 @@
#include <string>
-#include "base/macros.h"
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
#include "base/process/process_handle.h"
#include "base/test/multiprocess_test.h"
#include "base/test/test_timeouts.h"
diff --git a/mojo/edk/test/run_all_unittests.cc b/mojo/edk/test/run_all_unittests.cc
index 166a73e..c66ea50 100644
--- a/mojo/edk/test/run_all_unittests.cc
+++ b/mojo/edk/test/run_all_unittests.cc
@@ -21,6 +21,7 @@ int main(int argc, char** argv) {
mojo::test::TestSupport::Init(new mojo::test::TestSupportImpl());
return base::LaunchUnitTests(
- argc, argv,
+ argc,
+ argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
diff --git a/mojo/edk/test/test_support_impl.cc b/mojo/edk/test/test_support_impl.cc
index fae3a8f..2a86331 100644
--- a/mojo/edk/test/test_support_impl.cc
+++ b/mojo/edk/test/test_support_impl.cc
@@ -56,7 +56,8 @@ FILE* TestSupportImpl::OpenSourceRootRelativeFile(const char* relative_path) {
char** TestSupportImpl::EnumerateSourceRootRelativeDirectory(
const char* relative_path) {
std::vector<std::string> names;
- base::FileEnumerator e(ResolveSourceRootRelativePath(relative_path), false,
+ base::FileEnumerator e(ResolveSourceRootRelativePath(relative_path),
+ false,
base::FileEnumerator::FILES);
for (base::FilePath name = e.Next(); !name.empty(); name = e.Next())
names.push_back(name.BaseName().AsUTF8Unsafe());
diff --git a/mojo/edk/test/test_utils_win.cc b/mojo/edk/test/test_utils_win.cc
index 2387945..5d5b942 100644
--- a/mojo/edk/test/test_utils_win.cc
+++ b/mojo/edk/test/test_utils_win.cc
@@ -23,11 +23,14 @@ bool BlockingWrite(const embedder::PlatformHandle& handle,
OVERLAPPED overlapped = {0};
DWORD bytes_written_dword = 0;
- if (!WriteFile(handle.handle, buffer, static_cast<DWORD>(bytes_to_write),
- &bytes_written_dword, &overlapped)) {
+ if (!WriteFile(handle.handle,
+ buffer,
+ static_cast<DWORD>(bytes_to_write),
+ &bytes_written_dword,
+ &overlapped)) {
if (GetLastError() != ERROR_IO_PENDING ||
- !GetOverlappedResult(handle.handle, &overlapped, &bytes_written_dword,
- TRUE)) {
+ !GetOverlappedResult(
+ handle.handle, &overlapped, &bytes_written_dword, TRUE)) {
return false;
}
}
@@ -43,11 +46,14 @@ bool BlockingRead(const embedder::PlatformHandle& handle,
OVERLAPPED overlapped = {0};
DWORD bytes_read_dword = 0;
- if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size),
- &bytes_read_dword, &overlapped)) {
+ if (!ReadFile(handle.handle,
+ buffer,
+ static_cast<DWORD>(buffer_size),
+ &bytes_read_dword,
+ &overlapped)) {
if (GetLastError() != ERROR_IO_PENDING ||
- !GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword,
- TRUE)) {
+ !GetOverlappedResult(
+ handle.handle, &overlapped, &bytes_read_dword, TRUE)) {
return false;
}
}
@@ -63,15 +69,18 @@ bool NonBlockingRead(const embedder::PlatformHandle& handle,
OVERLAPPED overlapped = {0};
DWORD bytes_read_dword = 0;
- if (!ReadFile(handle.handle, buffer, static_cast<DWORD>(buffer_size),
- &bytes_read_dword, &overlapped)) {
+ if (!ReadFile(handle.handle,
+ buffer,
+ static_cast<DWORD>(buffer_size),
+ &bytes_read_dword,
+ &overlapped)) {
if (GetLastError() != ERROR_IO_PENDING)
return false;
CancelIo(handle.handle);
- if (!GetOverlappedResult(handle.handle, &overlapped, &bytes_read_dword,
- TRUE)) {
+ if (!GetOverlappedResult(
+ handle.handle, &overlapped, &bytes_read_dword, TRUE)) {
*bytes_read = 0;
return true;
}
@@ -88,7 +97,11 @@ embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp) {
PCHECK(DuplicateHandle(
GetCurrentProcess(),
reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(fp.get()))),
- GetCurrentProcess(), &rv, 0, TRUE, DUPLICATE_SAME_ACCESS))
+ GetCurrentProcess(),
+ &rv,
+ 0,
+ TRUE,
+ DUPLICATE_SAME_ACCESS))
<< "DuplicateHandle";
return embedder::ScopedPlatformHandle(embedder::PlatformHandle(rv));
}
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index 7771da7..cba70c9 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -12,7 +12,7 @@
'target_name': 'mojo',
'type': 'none',
'dependencies': [
- 'edk/mojo_edk_tests.gyp:mojo_edk_tests',
+ 'edk/mojo_edk.gyp:mojo_edk',
'mojo_base.gyp:mojo_base',
'mojo_geometry_converters.gyp:mojo_geometry_lib',
'mojo_input_events_converters.gyp:mojo_input_events_lib',
diff --git a/mojo/mojo_base.gyp b/mojo/mojo_base.gyp
index bab8c0e..96305df 100644
--- a/mojo/mojo_base.gyp
+++ b/mojo/mojo_base.gyp
@@ -71,11 +71,9 @@
'type': 'executable',
'dependencies': [
'../base/base.gyp:base',
- '../base/base.gyp:test_support_base',
'../base/base.gyp:base_message_loop_tests',
'../testing/gtest.gyp:gtest',
'../url/url.gyp:url_lib',
- 'edk/mojo_edk.gyp:mojo_system_impl',
'edk/mojo_edk.gyp:mojo_common_test_support',
'edk/mojo_edk.gyp:mojo_run_all_unittests',
'mojo_common_lib',
@@ -87,6 +85,14 @@
'common/common_type_converters_unittest.cc',
'common/handle_watcher_unittest.cc',
'common/message_pump_mojo_unittest.cc',
+ 'edk/test/multiprocess_test_helper_unittest.cc',
+ ],
+ 'conditions': [
+ ['OS=="ios"', {
+ 'sources!': [
+ 'edk/test/multiprocess_test_helper_unittest.cc',
+ ],
+ }],
],
},
{
diff --git a/mojo/public/VERSION b/mojo/public/VERSION
index f700f55..1156739 100644
--- a/mojo/public/VERSION
+++ b/mojo/public/VERSION
@@ -1 +1 @@
-afb4440fd5a10cba980878c326180b7ad7960480 \ No newline at end of file
+04a510fb37db10642e156957f9b2c11c2f6442ac \ No newline at end of file
diff --git a/mojo/public/cpp/application/BUILD.gn b/mojo/public/cpp/application/BUILD.gn
index ad46086..1eacdc6 100644
--- a/mojo/public/cpp/application/BUILD.gn
+++ b/mojo/public/cpp/application/BUILD.gn
@@ -64,13 +64,11 @@ source_set("test_support") {
source_set("test_support_standalone") {
testonly = true
- sources = [ "lib/application_test_main.cc" ]
-
- public_deps = [ ":test_support" ]
+ sources = [ "lib/application_test_main.cc", ]
+ public_deps = [ ":test_support", ]
deps = [
- ":application",
"//mojo/public/cpp/environment:standalone",
+ "//mojo/public/cpp/application",
"//mojo/public/cpp/system",
- "//mojo/public/cpp/utility",
]
}
diff --git a/mojo/public/cpp/application/lib/DEPS b/mojo/public/cpp/application/lib/DEPS
index a04ed0f..a49df6a 100644
--- a/mojo/public/cpp/application/lib/DEPS
+++ b/mojo/public/cpp/application/lib/DEPS
@@ -1,3 +1,5 @@
-include_rules = [
- "+mojo/public/cpp/utility",
-]
+specific_include_rules = {
+ r"application_runner\.cc": [
+ "+mojo/public/cpp/utility",
+ ],
+}
diff --git a/mojo/public/cpp/application/lib/application_test_main.cc b/mojo/public/cpp/application/lib/application_test_main.cc
index 6cdfb0d..9b76dad1 100644
--- a/mojo/public/cpp/application/lib/application_test_main.cc
+++ b/mojo/public/cpp/application/lib/application_test_main.cc
@@ -6,18 +6,16 @@
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/application_test_base.h"
-#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/environment/logging.h"
#include "mojo/public/cpp/system/message_pipe.h"
-#include "mojo/public/cpp/utility/run_loop.h"
MojoResult MojoMain(MojoHandle shell_handle) {
// An Environment instance is needed to construct run loops.
mojo::Environment environment;
{
- // This loop is used for init, and then destroyed before running tests.
- mojo::RunLoop run_loop;
+ // This RunLoop is used for init, and then destroyed before running tests.
+ mojo::Environment::InstantiateDefaultRunLoop();
// Construct an ApplicationImpl just for the GTEST commandline arguments.
// GTEST command line arguments are supported amid application arguments:
@@ -40,6 +38,7 @@ MojoResult MojoMain(MojoHandle shell_handle) {
testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
mojo::test::SetShellHandle(app.UnbindShell());
+ mojo::Environment::DestroyDefaultRunLoop();
}
int result = RUN_ALL_TESTS();
diff --git a/mojo/public/cpp/bindings/BUILD.gn b/mojo/public/cpp/bindings/BUILD.gn
index 143ab83..86ccae0 100644
--- a/mojo/public/cpp/bindings/BUILD.gn
+++ b/mojo/public/cpp/bindings/BUILD.gn
@@ -5,14 +5,12 @@
source_set("bindings") {
sources = [
"array.h",
- "binding.h",
"error_handler.h",
"interface_ptr.h",
"map.h",
"message.h",
"message_filter.h",
"no_interface.h",
- "strong_binding.h",
"string.h",
"struct_ptr.h",
"type_converter.h",
diff --git a/mojo/public/cpp/bindings/binding.h b/mojo/public/cpp/bindings/binding.h
deleted file mode 100644
index 2c4c9ce..0000000
--- a/mojo/public/cpp/bindings/binding.h
+++ /dev/null
@@ -1,136 +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.
-
-#ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
-#define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
-
-#include "mojo/public/c/environment/async_waiter.h"
-#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/interface_ptr.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
-#include "mojo/public/cpp/bindings/lib/filter_chain.h"
-#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
-#include "mojo/public/cpp/bindings/lib/router.h"
-#include "mojo/public/cpp/environment/logging.h"
-#include "mojo/public/cpp/system/core.h"
-
-namespace mojo {
-
-// This binds an interface implementation a pipe. Deleting the binding closes
-// the pipe.
-//
-// Example:
-//
-// #include "foo.mojom.h"
-//
-// class FooImpl : public Foo {
-// public:
-// explicit FooImpl(ScopedMessagePipeHandle handle)
-// : binding_(this, handle.Pass()) {}
-//
-// // Foo implementation here.
-//
-// private:
-// Binding<Foo> binding_;
-// };
-//
-template <typename Interface>
-class Binding : public ErrorHandler {
- public:
- using Client = typename Interface::Client;
-
- explicit Binding(Interface* impl) : impl_(impl) { stub_.set_sink(impl_); }
-
- Binding(Interface* impl,
- ScopedMessagePipeHandle handle,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
- : Binding(impl) {
- Bind(handle.Pass(), waiter);
- }
-
- Binding(Interface* impl,
- InterfacePtr<Interface>* ptr,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
- : Binding(impl) {
- Bind(ptr, waiter);
- }
-
- Binding(Interface* impl,
- InterfaceRequest<Interface> request,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
- : Binding(impl) {
- Bind(request.PassMessagePipe(), waiter);
- }
-
- ~Binding() override {
- delete proxy_;
- if (internal_router_) {
- internal_router_->set_error_handler(nullptr);
- delete internal_router_;
- }
- }
-
- void Bind(
- ScopedMessagePipeHandle handle,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- internal::FilterChain filters;
- filters.Append<internal::MessageHeaderValidator>();
- filters.Append<typename Interface::RequestValidator_>();
- filters.Append<typename Client::ResponseValidator_>();
-
- internal_router_ =
- new internal::Router(handle.Pass(), filters.Pass(), waiter);
- internal_router_->set_incoming_receiver(&stub_);
- internal_router_->set_error_handler(this);
-
- proxy_ = new typename Client::Proxy_(internal_router_);
- }
-
- void Bind(
- InterfacePtr<Interface>* ptr,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- MessagePipe pipe;
- ptr->Bind(pipe.handle0.Pass(), waiter);
- Bind(pipe.handle1.Pass(), waiter);
- }
-
- void Bind(
- InterfaceRequest<Interface> request,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- Bind(request.PassMessagePipe(), waiter);
- }
-
- bool WaitForIncomingMethodCall() {
- MOJO_DCHECK(internal_router_);
- return internal_router_->WaitForIncomingMessage();
- }
-
- void set_error_handler(ErrorHandler* error_handler) {
- error_handler_ = error_handler;
- }
-
- // ErrorHandler implementation
- void OnConnectionError() override {
- if (error_handler_)
- error_handler_->OnConnectionError();
- }
-
- Interface* impl() { return impl_; }
- Client* client() { return proxy_; }
- // Exposed for testing, should not generally be used.
- internal::Router* internal_router() { return internal_router_; }
-
- private:
- internal::Router* internal_router_ = nullptr;
- typename Client::Proxy_* proxy_ = nullptr;
- typename Interface::Stub_ stub_;
- Interface* impl_;
- ErrorHandler* error_handler_ = nullptr;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(Binding);
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
diff --git a/mojo/public/cpp/bindings/interface_impl.h b/mojo/public/cpp/bindings/interface_impl.h
index 0917103..da1055d 100644
--- a/mojo/public/cpp/bindings/interface_impl.h
+++ b/mojo/public/cpp/bindings/interface_impl.h
@@ -5,41 +5,40 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_
#define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_IMPL_H_
-#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/interface_request.h"
+#include "mojo/public/cpp/bindings/lib/interface_impl_internal.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/macros.h"
namespace mojo {
-// DEPRECATED! Please use mojo::Binding instead of InterfaceImpl<> in new code.
-//
// InterfaceImpl<..> is designed to be the base class of an interface
// implementation. It may be bound to a pipe or a proxy, see BindToPipe and
// BindToProxy.
template <typename Interface>
-class InterfaceImpl : public Interface, public ErrorHandler {
+class InterfaceImpl : public internal::InterfaceImplBase<Interface> {
public:
- using ImplementedInterface = Interface;
- using Client = typename Interface::Client;
+ typedef typename Interface::Client Client;
+ typedef Interface ImplementedInterface;
- InterfaceImpl() : binding_(this), error_handler_impl_(this) {
- binding_.set_error_handler(&error_handler_impl_);
- }
+ InterfaceImpl() : internal_state_(this) {}
virtual ~InterfaceImpl() {}
- void BindToHandle(
- ScopedMessagePipeHandle handle,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- binding_.Bind(handle.Pass(), waiter);
- }
+ // Returns a proxy to the client interface. This is null upon construction,
+ // and becomes non-null after OnClientConnected. NOTE: It remains non-null
+ // until this instance is deleted.
+ Client* client() { return internal_state_.client(); }
+ // Blocks the current thread for the first incoming method call, i.e., either
+ // a call to a method or a client callback method. Returns |true| if a method
+ // has been called, |false| in case of error. It must only be called on a
+ // bound object.
bool WaitForIncomingMethodCall() {
- return binding_.WaitForIncomingMethodCall();
+ return internal_state_.WaitForIncomingMethodCall();
}
- Client* client() { return binding_.client(); }
- internal::Router* internal_router() { return binding_.internal_router(); }
+ // Called when the client has connected to this instance.
+ virtual void OnConnectionEstablished() {}
// Called when the client is no longer connected to this instance. NOTE: The
// client() method continues to return a non-null pointer after this method
@@ -47,42 +46,13 @@ class InterfaceImpl : public Interface, public ErrorHandler {
// will be silently ignored.
virtual void OnConnectionError() {}
- void set_delete_on_error(bool delete_on_error) {
- error_handler_impl_.set_delete_on_error(delete_on_error);
+ // DO NOT USE. Exposed only for internal use and for testing.
+ internal::InterfaceImplState<Interface>* internal_state() {
+ return &internal_state_;
}
private:
- class ErrorHandlerImpl : public ErrorHandler {
- public:
- explicit ErrorHandlerImpl(InterfaceImpl* impl) : impl_(impl) {}
- ~ErrorHandlerImpl() override {}
-
- // ErrorHandler implementation:
- void OnConnectionError() override {
- // If the the instance is not bound to the pipe, the instance might choose
- // to delete the binding in the OnConnectionError handler, which would in
- // turn delete |this|. Save the error behavior before invoking the error
- // handler so we can correctly decide what to do.
- bool delete_on_error = delete_on_error_;
- impl_->OnConnectionError();
- if (delete_on_error)
- delete impl_;
- }
-
- void set_delete_on_error(bool delete_on_error) {
- delete_on_error_ = delete_on_error;
- }
-
- private:
- InterfaceImpl* impl_;
- bool delete_on_error_ = false;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(ErrorHandlerImpl);
- };
-
- Binding<Interface> binding_;
- ErrorHandlerImpl error_handler_impl_;
-
+ internal::InterfaceImplState<Interface> internal_state_;
MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImpl);
};
@@ -97,13 +67,14 @@ class InterfaceImpl : public Interface, public ErrorHandler {
// called on the current thread, and if the current thread exits, then the end
// point of the pipe will be closed and the error handler's OnConnectionError
// method will be called.
+//
+// Before returning, the instance's OnConnectionEstablished method is called.
template <typename Impl>
Impl* BindToPipe(
Impl* instance,
ScopedMessagePipeHandle handle,
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- instance->set_delete_on_error(true);
- instance->BindToHandle(handle.Pass(), waiter);
+ instance->internal_state()->Bind(handle.Pass(), true, waiter);
return instance;
}
@@ -113,7 +84,7 @@ Impl* WeakBindToPipe(
Impl* instance,
ScopedMessagePipeHandle handle,
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- instance->BindToHandle(handle.Pass(), waiter);
+ instance->internal_state()->Bind(handle.Pass(), false, waiter);
return instance;
}
@@ -126,13 +97,14 @@ Impl* WeakBindToPipe(
// The instance is also bound to the current thread. Its methods will only be
// called on the current thread, and if the current thread exits, then it will
// also be deleted, and along with it, its end point of the pipe will be closed.
+//
+// Before returning, the instance's OnConnectionEstablished method is called.
template <typename Impl, typename Interface>
Impl* BindToProxy(
Impl* instance,
InterfacePtr<Interface>* ptr,
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- instance->set_delete_on_error(true);
- WeakBindToProxy(instance, ptr, waiter);
+ instance->internal_state()->BindProxy(ptr, true, waiter);
return instance;
}
@@ -142,9 +114,7 @@ Impl* WeakBindToProxy(
Impl* instance,
InterfacePtr<Interface>* ptr,
const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
- MessagePipe pipe;
- ptr->Bind(pipe.handle0.Pass(), waiter);
- instance->BindToHandle(pipe.handle1.Pass(), waiter);
+ instance->internal_state()->BindProxy(ptr, false, waiter);
return instance;
}
diff --git a/mojo/public/cpp/bindings/lib/interface_impl_internal.h b/mojo/public/cpp/bindings/lib/interface_impl_internal.h
new file mode 100644
index 0000000..492b182
--- /dev/null
+++ b/mojo/public/cpp/bindings/lib/interface_impl_internal.h
@@ -0,0 +1,128 @@
+// 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_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
+#define MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
+
+#include "mojo/public/cpp/bindings/error_handler.h"
+#include "mojo/public/cpp/bindings/interface_ptr.h"
+#include "mojo/public/cpp/bindings/lib/filter_chain.h"
+#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
+#include "mojo/public/cpp/environment/environment.h"
+#include "mojo/public/cpp/environment/logging.h"
+#include "mojo/public/cpp/system/macros.h"
+
+namespace mojo {
+namespace internal {
+
+template <typename Interface>
+class InterfaceImplBase : public Interface {
+ public:
+ virtual ~InterfaceImplBase() {}
+ virtual void OnConnectionEstablished() = 0;
+ virtual void OnConnectionError() = 0;
+};
+
+template <typename Interface>
+class InterfaceImplState : public ErrorHandler {
+ public:
+ typedef typename Interface::Client Client;
+
+ explicit InterfaceImplState(InterfaceImplBase<Interface>* instance)
+ : router_(nullptr),
+ proxy_(nullptr),
+ instance_bound_to_pipe_(false)
+#ifndef NDEBUG
+ ,
+ deleting_instance_due_to_error_(false)
+#endif
+ {
+ MOJO_DCHECK(instance);
+ stub_.set_sink(instance);
+ }
+
+ virtual ~InterfaceImplState() {
+#ifndef NDEBUG
+ MOJO_DCHECK(!instance_bound_to_pipe_ || deleting_instance_due_to_error_);
+#endif
+ delete proxy_;
+ if (router_) {
+ router_->set_error_handler(nullptr);
+ delete router_;
+ }
+ }
+
+ void BindProxy(
+ InterfacePtr<Interface>* ptr,
+ bool instance_bound_to_pipe,
+ const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()) {
+ MessagePipe pipe;
+ ptr->Bind(pipe.handle0.Pass(), waiter);
+ Bind(pipe.handle1.Pass(), instance_bound_to_pipe, waiter);
+ }
+
+ void Bind(ScopedMessagePipeHandle handle,
+ bool instance_bound_to_pipe,
+ const MojoAsyncWaiter* waiter) {
+ MOJO_CHECK(!router_);
+
+ FilterChain filters;
+ filters.Append<MessageHeaderValidator>();
+ filters.Append<typename Interface::RequestValidator_>();
+ filters.Append<typename Interface::Client::ResponseValidator_>();
+
+ router_ = new Router(handle.Pass(), filters.Pass(), waiter);
+ router_->set_incoming_receiver(&stub_);
+ router_->set_error_handler(this);
+
+ proxy_ = new typename Client::Proxy_(router_);
+
+ instance_bound_to_pipe_ = instance_bound_to_pipe;
+
+ instance()->OnConnectionEstablished();
+ }
+
+ bool WaitForIncomingMethodCall() {
+ MOJO_DCHECK(router_);
+ return router_->WaitForIncomingMessage();
+ }
+
+ Router* router() { return router_; }
+ Client* client() { return proxy_; }
+
+ private:
+ InterfaceImplBase<Interface>* instance() {
+ return static_cast<InterfaceImplBase<Interface>*>(stub_.sink());
+ }
+
+ virtual void OnConnectionError() override {
+ // If the the instance is not bound to the pipe, the instance might choose
+ // to delete itself in the OnConnectionError handler, which would in turn
+ // delete this. Save the error behavior before invoking the error handler
+ // so we can correctly decide what to do.
+ bool bound = instance_bound_to_pipe_;
+ instance()->OnConnectionError();
+ if (!bound)
+ return;
+#ifndef NDEBUG
+ deleting_instance_due_to_error_ = true;
+#endif
+ delete instance();
+ }
+
+ Router* router_;
+ typename Client::Proxy_* proxy_;
+ typename Interface::Stub_ stub_;
+ bool instance_bound_to_pipe_;
+#ifndef NDEBUG
+ bool deleting_instance_due_to_error_;
+#endif
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(InterfaceImplState);
+};
+
+} // namespace internal
+} // namespace mojo
+
+#endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_INTERFACE_IMPL_INTERNAL_H_
diff --git a/mojo/public/cpp/bindings/strong_binding.h b/mojo/public/cpp/bindings/strong_binding.h
deleted file mode 100644
index 73966ff..0000000
--- a/mojo/public/cpp/bindings/strong_binding.h
+++ /dev/null
@@ -1,88 +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.
-
-#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_
-#define MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_
-
-#include "mojo/public/c/environment/async_waiter.h"
-#include "mojo/public/cpp/bindings/binding.h"
-#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/interface_ptr.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
-#include "mojo/public/cpp/bindings/lib/filter_chain.h"
-#include "mojo/public/cpp/bindings/lib/message_header_validator.h"
-#include "mojo/public/cpp/bindings/lib/router.h"
-#include "mojo/public/cpp/system/core.h"
-
-namespace mojo {
-
-// This connects an interface implementation strongly to a pipe. When a
-// connection error is detected the implementation is deleted. Deleting the
-// connector also closes the pipe.
-//
-// Example of an implementation that is always bound strongly to a pipe
-//
-// class StronglyBound : public Foo {
-// public:
-// explicit StronglyBound(ScopedMessagePipeHandle handle)
-// : binding_(this, handle.Pass()) {}
-//
-// // Foo implementation here
-//
-// private:
-// StrongBinding<Foo> binding_;
-// };
-//
-template <typename Interface>
-class StrongBinding : public ErrorHandler {
- public:
- explicit StrongBinding(Interface* impl) : binding_(impl) {
- binding_.set_error_handler(this);
- }
-
- StrongBinding(
- Interface* impl,
- ScopedMessagePipeHandle handle,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
- : StrongBinding(impl) {
- binding_.Bind(handle.Pass(), waiter);
- }
-
- StrongBinding(
- Interface* impl,
- InterfaceRequest<Interface> request,
- const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter())
- : StrongBinding(impl) {
- binding_.Bind(request.Pass(), waiter);
- }
-
- ~StrongBinding() override {}
-
- bool WaitForIncomingMethodCall() {
- return binding_.WaitForIncomingMethodCall();
- }
-
- void set_error_handler(ErrorHandler* error_handler) {
- error_handler_ = error_handler;
- }
-
- typename Interface::Client* client() { return binding_.client(); }
- // Exposed for testing, should not generally be used.
- internal::Router* internal_router() { return binding_.internal_router(); }
-
- // ErrorHandler implementation
- void OnConnectionError() override {
- if (error_handler_)
- error_handler_->OnConnectionError();
- delete binding_.impl();
- }
-
- private:
- ErrorHandler* error_handler_ = nullptr;
- Binding<Interface> binding_;
-};
-
-} // namespace mojo
-
-#endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_BINDING_H_
diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
index 91ce84b..0cd5646 100644
--- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
@@ -2,9 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/error_handler.h"
-#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h"
@@ -31,7 +29,9 @@ class MathCalculatorImpl : public InterfaceImpl<math::Calculator> {
public:
~MathCalculatorImpl() override {}
- MathCalculatorImpl() : total_(0.0) {}
+ MathCalculatorImpl() : total_(0.0), got_connection_(false) {}
+
+ void OnConnectionEstablished() override { got_connection_ = true; }
void Clear() override { client()->Output(total_); }
@@ -45,8 +45,11 @@ class MathCalculatorImpl : public InterfaceImpl<math::Calculator> {
client()->Output(total_);
}
+ bool got_connection() const { return got_connection_; }
+
private:
double total_;
+ bool got_connection_;
};
class MathCalculatorUIImpl : public math::CalculatorUI {
@@ -120,7 +123,12 @@ class ReentrantServiceImpl : public InterfaceImpl<sample::Service> {
public:
~ReentrantServiceImpl() override {}
- ReentrantServiceImpl() : call_depth_(0), max_call_depth_(0) {}
+ ReentrantServiceImpl()
+ : got_connection_(false), call_depth_(0), max_call_depth_(0) {}
+
+ void OnConnectionEstablished() override { got_connection_ = true; }
+
+ bool got_connection() const { return got_connection_; }
int max_call_depth() { return max_call_depth_; }
@@ -137,6 +145,7 @@ class ReentrantServiceImpl : public InterfaceImpl<sample::Service> {
void GetPort(mojo::InterfaceRequest<sample::Port> port) override {}
private:
+ bool got_connection_;
int call_depth_;
int max_call_depth_;
};
@@ -154,7 +163,8 @@ class InterfacePtrTest : public testing::Test {
TEST_F(InterfacePtrTest, EndToEnd) {
math::CalculatorPtr calc;
- BindToProxy(new MathCalculatorImpl(), &calc);
+ MathCalculatorImpl* impl = BindToProxy(new MathCalculatorImpl(), &calc);
+ EXPECT_TRUE(impl->got_connection());
// Suppose this is instantiated in a process that has pipe1_.
MathCalculatorUIImpl calculator_ui(calc.Pass());
@@ -170,6 +180,7 @@ TEST_F(InterfacePtrTest, EndToEnd) {
TEST_F(InterfacePtrTest, EndToEnd_Synchronous) {
math::CalculatorPtr calc;
MathCalculatorImpl* impl = BindToProxy(new MathCalculatorImpl(), &calc);
+ EXPECT_TRUE(impl->got_connection());
// Suppose this is instantiated in a process that has pipe1_.
MathCalculatorUIImpl calculator_ui(calc.Pass());
@@ -241,7 +252,7 @@ TEST_F(InterfacePtrTest, EncounteredError) {
EXPECT_FALSE(calculator_ui.encountered_error());
// Close the server.
- server->internal_router()->CloseMessagePipe();
+ server->internal_state()->router()->CloseMessagePipe();
// The state change isn't picked up locally yet.
EXPECT_FALSE(calculator_ui.encountered_error());
@@ -270,7 +281,7 @@ TEST_F(InterfacePtrTest, EncounteredErrorCallback) {
EXPECT_FALSE(calculator_ui.encountered_error());
// Close the server.
- server->internal_router()->CloseMessagePipe();
+ server->internal_state()->router()->CloseMessagePipe();
// The state change isn't picked up locally yet.
EXPECT_FALSE(calculator_ui.encountered_error());
@@ -326,6 +337,7 @@ TEST_F(InterfacePtrTest, NestedDestroyInterfacePtrOnClientMethod) {
TEST_F(InterfacePtrTest, ReentrantWaitForIncomingMethodCall) {
sample::ServicePtr proxy;
ReentrantServiceImpl* impl = BindToProxy(new ReentrantServiceImpl(), &proxy);
+ EXPECT_TRUE(impl->got_connection());
proxy->Frobinate(sample::FooPtr(),
sample::Service::BAZ_OPTIONS_REGULAR,
@@ -339,148 +351,6 @@ TEST_F(InterfacePtrTest, ReentrantWaitForIncomingMethodCall) {
EXPECT_EQ(2, impl->max_call_depth());
}
-class StrongMathCalculatorImpl : public math::Calculator, public ErrorHandler {
- public:
- StrongMathCalculatorImpl(ScopedMessagePipeHandle handle,
- bool* error_received,
- bool* destroyed)
- : error_received_(error_received),
- destroyed_(destroyed),
- binding_(this, handle.Pass()) {
- binding_.set_error_handler(this);
- }
- ~StrongMathCalculatorImpl() override { *destroyed_ = true; }
-
- // math::Calculator implementation.
- void Clear() override { binding_.client()->Output(total_); }
-
- void Add(double value) override {
- total_ += value;
- binding_.client()->Output(total_);
- }
-
- void Multiply(double value) override {
- total_ *= value;
- binding_.client()->Output(total_);
- }
-
- // ErrorHandler implementation.
- void OnConnectionError() override { *error_received_ = true; }
-
- private:
- double total_ = 0.0;
- bool* error_received_;
- bool* destroyed_;
-
- StrongBinding<math::Calculator> binding_;
-};
-
-TEST(StrongConnectorTest, Math) {
- Environment env;
- RunLoop loop;
-
- bool error_received = false;
- bool destroyed = false;
- MessagePipe pipe;
- new StrongMathCalculatorImpl(pipe.handle0.Pass(), &error_received,
- &destroyed);
-
- math::CalculatorPtr calc;
- calc.Bind(pipe.handle1.Pass());
-
- {
- // Suppose this is instantiated in a process that has the other end of the
- // message pipe.
- MathCalculatorUIImpl calculator_ui(calc.Pass());
-
- calculator_ui.Add(2.0);
- calculator_ui.Multiply(5.0);
-
- loop.RunUntilIdle();
-
- EXPECT_EQ(10.0, calculator_ui.GetOutput());
- EXPECT_FALSE(error_received);
- EXPECT_FALSE(destroyed);
- }
- // Destroying calculator_ui should close the pipe and generate an error on the
- // other
- // end which will destroy the instance since it is strongly bound.
-
- loop.RunUntilIdle();
- EXPECT_TRUE(error_received);
- EXPECT_TRUE(destroyed);
-}
-
-class WeakMathCalculatorImpl : public math::Calculator, public ErrorHandler {
- public:
- WeakMathCalculatorImpl(ScopedMessagePipeHandle handle,
- bool* error_received,
- bool* destroyed)
- : error_received_(error_received),
- destroyed_(destroyed),
- binding_(this, handle.Pass()) {
- binding_.set_error_handler(this);
- }
- ~WeakMathCalculatorImpl() override { *destroyed_ = true; }
-
- void Clear() override { binding_.client()->Output(total_); }
-
- void Add(double value) override {
- total_ += value;
- binding_.client()->Output(total_);
- }
-
- void Multiply(double value) override {
- total_ *= value;
- binding_.client()->Output(total_);
- }
-
- // ErrorHandler implementation.
- void OnConnectionError() override { *error_received_ = true; }
-
- private:
- double total_ = 0.0;
- bool* error_received_;
- bool* destroyed_;
-
- Binding<math::Calculator> binding_;
-};
-
-TEST(WeakConnectorTest, Math) {
- Environment env;
- RunLoop loop;
-
- bool error_received = false;
- bool destroyed = false;
- MessagePipe pipe;
- WeakMathCalculatorImpl impl(pipe.handle0.Pass(), &error_received, &destroyed);
-
- math::CalculatorPtr calc;
- calc.Bind(pipe.handle1.Pass());
-
- {
- // Suppose this is instantiated in a process that has the other end of the
- // message pipe.
- MathCalculatorUIImpl calculator_ui(calc.Pass());
-
- calculator_ui.Add(2.0);
- calculator_ui.Multiply(5.0);
-
- loop.RunUntilIdle();
-
- EXPECT_EQ(10.0, calculator_ui.GetOutput());
- EXPECT_FALSE(error_received);
- EXPECT_FALSE(destroyed);
- // Destroying calculator_ui should close the pipe and generate an error on
- // the other
- // end which will destroy the instance since it is strongly bound.
- }
-
- loop.RunUntilIdle();
- EXPECT_TRUE(error_received);
- EXPECT_FALSE(destroyed);
-}
-
} // namespace
} // namespace test
} // namespace mojo
diff --git a/mojo/public/cpp/bindings/tests/validation_unittest.cc b/mojo/public/cpp/bindings/tests/validation_unittest.cc
index 6507f21..c7edf19e 100644
--- a/mojo/public/cpp/bindings/tests/validation_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/validation_unittest.cc
@@ -409,7 +409,7 @@ TEST_F(ValidationIntegrationTest, InterfaceImpl) {
// |interface1_impl| will delete itself when the pipe is closed.
IntegrationTestInterface1Impl* interface1_impl =
BindToPipe(new IntegrationTestInterface1Impl(), testee_endpoint().Pass());
- interface1_impl->internal_router()->EnableTestingMode();
+ interface1_impl->internal_state()->router()->EnableTestingMode();
RunValidationTests("integration_", test_message_receiver());
}
diff --git a/mojo/public/cpp/utility/tests/BUILD.gn b/mojo/public/cpp/utility/tests/BUILD.gn
index 67419d4..dd1d154 100644
--- a/mojo/public/cpp/utility/tests/BUILD.gn
+++ b/mojo/public/cpp/utility/tests/BUILD.gn
@@ -13,14 +13,8 @@ test("mojo_public_utility_unittests") {
]
sources = [
+ "mutex_unittest.cc",
"run_loop_unittest.cc",
+ "thread_unittest.cc",
]
-
- # crbug.com/342893
- if (!is_win) {
- sources += [
- "mutex_unittest.cc",
- "thread_unittest.cc",
- ]
- }
}
diff --git a/mojo/public/dart/BUILD.gn b/mojo/public/dart/BUILD.gn
index c2e8f6a..83c5a25 100644
--- a/mojo/public/dart/BUILD.gn
+++ b/mojo/public/dart/BUILD.gn
@@ -3,62 +3,16 @@
# found in the LICENSE file.
group("dart") {
- testonly = true
deps = [
- ":core",
":bindings",
]
}
-group("core") {
- deps = [
- ":mojo_dart_core",
- ":copy_core_library",
- ]
-}
-
-
-shared_library("mojo_dart_core") {
- defines = ["DART_SHARED_LIB"]
- sources = [
- "src/mojo_dart_core.cc",
- ]
- deps = [
- "//mojo/public/c/environment",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/public/cpp/environment:standalone",
- "//mojo/public/cpp/system",
- "//mojo/public/cpp/utility",
- "//mojo/public/cpp/bindings:callback",
- ]
-}
-
-
-copy("copy_core_library") {
- sources = [
- "$root_out_dir/libmojo_dart_core.so",
- ]
- outputs = [
- "$root_out_dir/gen/mojo/public/dart/src/libmojo_dart_core.so"
- ]
- deps =[
- ":mojo_dart_core"
- ]
-}
-
-
copy("bindings") {
sources = [
"bindings.dart",
- "core.dart",
- "mojo_init.dart",
- "src/buffer.dart",
"src/codec.dart",
- "src/data_pipe.dart",
- "src/handle.dart",
- "src/message_pipe.dart",
- "src/types.dart",
]
outputs = [
"{{source_gen_dir}}/{{source_file_part}}"
diff --git a/mojo/public/dart/DEPS b/mojo/public/dart/DEPS
deleted file mode 100644
index 53d0007..0000000
--- a/mojo/public/dart/DEPS
+++ /dev/null
@@ -1,4 +0,0 @@
-include_rules = [
- "+dart",
- "+base",
-] \ No newline at end of file
diff --git a/mojo/public/dart/README b/mojo/public/dart/README
index 5ff7ee3..aadb348 100644
--- a/mojo/public/dart/README
+++ b/mojo/public/dart/README
@@ -39,17 +39,3 @@ e.g. out/ReleaseX64/dart-sdk/bin to your path.
4.) Run Dart tests.
$ ./mojob.sh --release darttest
-
-
-These are instructions for adding a Dart VM source checkout to your client.
-
-1. Edit your .gclient file.
-
- Replace "DEPS" with "DEPS.dart"
-
-2. Run:
-
- $ gclient sync
-
- You should now have a directory //src/dart
-
diff --git a/mojo/public/dart/core.dart b/mojo/public/dart/core.dart
deleted file mode 100644
index 5159440..0000000
--- a/mojo/public/dart/core.dart
+++ /dev/null
@@ -1,19 +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.
-
-library core;
-
-import 'dart:async';
-import 'dart:core';
-import 'dart:isolate';
-import 'dart:typed_data';
-import 'dart-ext:src/mojo_dart_core';
-
-part 'src/buffer.dart';
-part 'src/data_pipe.dart';
-part 'src/handle.dart';
-part 'src/message_pipe.dart';
-part 'src/types.dart';
-
-void mojoSystemThunksSet(int thunks) native "MojoSystemThunks_Set";
diff --git a/mojo/public/dart/mojo_init.dart b/mojo/public/dart/mojo_init.dart
deleted file mode 100644
index c622f5f..0000000
--- a/mojo/public/dart/mojo_init.dart
+++ /dev/null
@@ -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.
-
-library mojo_init;
-
-import 'core.dart' as core;
-import 'dart-ext:src/mojo_dart_init';
-
-void _init() native "MojoLibrary_Init";
-void _mojoSystemThunksMake(Function fn) native "MojoSystemThunks_Make";
-
-void mojoInit() {
- _init();
- _mojoSystemThunksMake(core.mojoSystemThunksSet);
-}
diff --git a/mojo/public/dart/src/buffer.dart b/mojo/public/dart/src/buffer.dart
deleted file mode 100644
index a00838e..0000000
--- a/mojo/public/dart/src/buffer.dart
+++ /dev/null
@@ -1,107 +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.
-
-part of core;
-
-class _MojoSharedBufferNatives {
- static List Create(int num_bytes, int flags)
- native "MojoSharedBuffer_Create";
-
- static List Duplicate(int buffer_handle, int flags)
- native "MojoSharedBuffer_Duplicate";
-
- static List Map(int buffer_handle, int offset, int num_bytes, int flags)
- native "MojoSharedBuffer_Map";
-
- static int Unmap(ByteData buffer)
- native "MojoSharedBuffer_Unmap";
-}
-
-
-class MojoSharedBuffer {
- static const int CREATE_FLAG_NONE = 0;
- static const int DUPLICATE_FLAG_NONE = 0;
- static const int MAP_FLAG_NONE = 0;
-
- RawMojoHandle handle;
- MojoResult status;
- ByteData mapping;
-
- MojoSharedBuffer._() {
- handle = null;
- status = MojoResult.OK;
- mapping = null;
- }
-
- factory MojoSharedBuffer(int num_bytes, [int flags = 0]) {
- List result = _MojoSharedBufferNatives.Create(num_bytes, flags);
- if (result == null) {
- return null;
- }
- assert((result is List) && (result.length == 2));
- var r = new MojoResult(result[0]);
- if (!r.isOk) {
- return null;
- }
-
- MojoSharedBuffer buf = new MojoSharedBuffer._();
- buf.status = r;
- buf.handle = new RawMojoHandle(result[1]);
- buf.mapping = null;
- return buf;
- }
-
- factory MojoSharedBuffer.duplicate(MojoSharedBuffer msb, [int flags = 0]) {
- List result = _MojoSharedBufferNatives.Duplicate(msb.handle.h, flags);
- if (result == null) {
- return null;
- }
- assert((result is List) && (result.length == 2));
- var r = new MojoResult(result[0]);
- if(!r.isOk) {
- return null;
- }
-
- MojoSharedBuffer dupe = new MojoSharedBuffer._();
- dupe.status = r;
- dupe.handle = new RawMojoHandle(result[1]);
- dupe.mapping = msb.mapping;
- return dupe;
- }
-
- MojoResult close() {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
- MojoResult r = handle.close();
- status = r;
- mapping = null;
- return status;
- }
-
- MojoResult map(int offset, int num_bytes, [int flags = 0]) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
- List result = _MojoSharedBufferNatives.Map(
- handle.h, offset, num_bytes, flags);
- if (result == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
- assert((result is List) && (result.length == 2));
- status = new MojoResult(result[0]);
- mapping = result[1];
- return status;
- }
-
- MojoResult unmap() {
- int r = _MojoSharedBufferNatives.Unmap(mapping);
- status = new MojoResult(r);
- mapping = null;
- return status;
- }
-}
diff --git a/mojo/public/dart/src/data_pipe.dart b/mojo/public/dart/src/data_pipe.dart
deleted file mode 100644
index 665285d..0000000
--- a/mojo/public/dart/src/data_pipe.dart
+++ /dev/null
@@ -1,191 +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.
-
-part of core;
-
-
-class _MojoDataPipeNatives {
- static List MojoCreateDataPipe(
- int element_bytes, int capacity_bytes, int flags)
- native "MojoDataPipe_Create";
-
- static List MojoWriteData(int handle, ByteData data, int num_bytes, int flags)
- native "MojoDataPipe_WriteData";
-
- static List MojoBeginWriteData(int handle, int buffer_bytes, int flags)
- native "MojoDataPipe_BeginWriteData";
-
- static int MojoEndWriteData(int handle, int bytes_written)
- native "MojoDataPipe_EndWriteData";
-
- static List MojoReadData(int handle, ByteData data, int num_bytes, int flags)
- native "MojoDataPipe_ReadData";
-
- static List MojoBeginReadData(int handle, int buffer_bytes, int flags)
- native "MojoDataPipe_BeginReadData";
-
- static int MojoEndReadData(int handle, int bytes_read)
- native "MojoDataPipe_EndReadData";
-}
-
-
-class MojoDataPipeProducer {
- static const int FLAG_NONE = 0;
- static const int FLAG_ALL_OR_NONE = 1 << 0;
-
- RawMojoHandle handle;
- MojoResult status;
- final int element_bytes;
-
- MojoDataPipeProducer(this.handle,
- this.status,
- this.element_bytes);
-
- int write(ByteData data, [int num_bytes = -1, int flags = 0]) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
-
- int data_num_bytes = (num_bytes == -1) ? data.lengthInBytes : num_bytes;
- List result = _MojoDataPipeNatives.MojoWriteData(
- handle.h, data, data_num_bytes, flags);
- if (result == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
-
- assert((result is List) && (result.length == 2));
- status = new MojoResult(result[0]);
- return result[1];
- }
-
- ByteData beginWrite(int buffer_bytes, [int flags = 0]) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return null;
- }
-
- List result = _MojoDataPipeNatives.MojoBeginWriteData(
- handle.h, buffer_bytes, flags);
- if (result == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return null;
- }
-
- assert((result is List) && (result.length == 2));
- status = new MojoResult(result[0]);
- return result[1];
- }
-
- MojoResult endWrite(int bytes_written) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
- int result = _MojoDataPipeNatives.MojoEndWriteData(handle.h, bytes_written);
- status = new MojoResult(result);
- return status;
- }
-}
-
-
-class MojoDataPipeConsumer {
- static const int FLAG_NONE = 0;
- static const int FLAG_ALL_OR_NONE = 1 << 0;
- static const int FLAG_MAY_DISCARD = 1 << 1;
- static const int FLAG_QUERY = 1 << 2;
-
- RawMojoHandle handle;
- MojoResult status;
- final int element_bytes;
-
- MojoDataPipeConsumer(this.handle,
- this.status,
- this.element_bytes);
-
- int read(ByteData data, [int num_bytes = -1, int flags = 0]) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
-
- int data_num_bytes = (num_bytes == -1) ? data.lengthInBytes : num_bytes;
- List result = _MojoDataPipeNatives.MojoReadData(
- handle.h, data, data_num_bytes, flags);
- if (result == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
- assert((result is List) && (result.length == 2));
- status = new MojoResult(result[0]);
- return result[1];
- }
-
- ByteData beginRead(int buffer_bytes, [int flags = 0]) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return null;
- }
-
- List result = _MojoDataPipeNatives.MojoBeginReadData(
- handle.h, buffer_bytes, flags);
- if (result == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return null;
- }
-
- assert((result is List) && (result.length == 2));
- status = new MojoResult(result[0]);
- return result[1];
- }
-
- MojoResult endRead(int bytes_read) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
- int result = _MojoDataPipeNatives.MojoEndReadData(handle.h, bytes_read);
- status = new MojoResult(result);
- return status;
- }
-}
-
-
-class MojoDataPipe {
- static const int FLAG_NONE = 0;
- static const int FLAG_MAY_DISCARD = 1 << 0;
- static const int DEFAULT_ELEMENT_SIZE = 1;
- static const int DEFAULT_CAPACITY = 0;
-
- MojoDataPipeProducer producer;
- MojoDataPipeConsumer consumer;
- MojoResult status;
-
- MojoDataPipe._internal() {
- producer = null;
- consumer = null;
- status = MojoResult.OK;
- }
-
- factory MojoDataPipe([int element_bytes = DEFAULT_ELEMENT_SIZE,
- int capacity_bytes = DEFAULT_CAPACITY,
- int flags = FLAG_NONE]) {
- List result = _MojoDataPipeNatives.MojoCreateDataPipe(
- element_bytes, capacity_bytes, flags);
- if (result == null) {
- return null;
- }
- assert((result is List) && (result.length == 3));
- RawMojoHandle producer_handle = new RawMojoHandle(result[1]);
- RawMojoHandle consumer_handle = new RawMojoHandle(result[2]);
- MojoDataPipe pipe = new MojoDataPipe._internal();
- pipe.producer = new MojoDataPipeProducer(
- producer_handle, new MojoResult(result[0]), element_bytes);
- pipe.consumer = new MojoDataPipeConsumer(
- consumer_handle, new MojoResult(result[0]), element_bytes);
- pipe.status = new MojoResult(result[0]);
- return pipe;
- }
-}
diff --git a/mojo/public/dart/src/handle.dart b/mojo/public/dart/src/handle.dart
deleted file mode 100644
index 08a23ae..0000000
--- a/mojo/public/dart/src/handle.dart
+++ /dev/null
@@ -1,68 +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.
-
-part of core;
-
-
-class _MojoHandleNatives {
- static int close(int handle) native "MojoHandle_Close";
- static int wait(int handle, int signals, int deadline)
- native "MojoHandle_Wait";
- static int waitMany(
- List handles, List signals, int num_handles, int deadline)
- native "MojoHandle_WaitMany";
-}
-
-
-class RawMojoHandle {
- static const int INVALID = 0;
- static const int DEADLINE_INDEFINITE = -1;
-
- RawMojoHandle(this.h);
-
- MojoResult close() {
- int result = _MojoHandleNatives.close(h);
- h = INVALID;
- return new MojoResult(result);
- }
-
- MojoResult wait(int signals, int deadline) {
- int result = _MojoHandleNatives.wait(h, signals, deadline);
- return new MojoResult(result);
- }
-
- bool _ready(int signal) {
- MojoResult res = wait(signal, 0);
- switch (res) {
- case MojoResult.OK:
- return true;
- case MojoResult.DEADLINE_EXCEEDED:
- case MojoResult.CANCELLED:
- case MojoResult.INVALID_ARGUMENT:
- case MojoResult.FAILED_PRECONDITION:
- return false;
- default:
- // Should be unreachable.
- throw new Exception("Unreachable");
- }
- }
-
- bool readyRead() => _ready(MojoHandleSignals.READABLE);
- bool readyWrite() => _ready(MojoHandleSignals.WRITABLE);
-
- static MojoResult waitMany(List<int> handles,
- List<int> signals,
- int deadline) {
- if (handles.length != signals.length) {
- return MojoResult.INVALID_ARGUMENT;
- }
- int result = _MojoHandleNatives.waitMany(
- handles, signals, handles.length, deadline);
- return new MojoResult(result);
- }
-
- static bool isValid(RawMojoHandle h) => (h.h != INVALID);
-
- int h;
-}
diff --git a/mojo/public/dart/src/message_pipe.dart b/mojo/public/dart/src/message_pipe.dart
deleted file mode 100644
index 81d9f28..0000000
--- a/mojo/public/dart/src/message_pipe.dart
+++ /dev/null
@@ -1,155 +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.
-
-part of core;
-
-
-class _MojoMessagePipeNatives {
- static List MojoCreateMessagePipe(int flags)
- native "MojoMessagePipe_Create";
-
- static int MojoWriteMessage(
- int handle, ByteData data, int num_bytes, List<int> handles, int flags)
- native "MojoMessagePipe_Write";
-
- static List MojoReadMessage(
- int handle, ByteData data, int num_bytes, List<int> handles, int flags)
- native "MojoMessagePipe_Read";
-}
-
-
-class MojoMessagePipeReadResult {
- final MojoResult status;
- final int bytesRead;
- final int handlesRead;
-
- MojoMessagePipeReadResult(this.status, this.bytesRead, this.handlesRead);
- MojoMessagePipeReadResult.fromList(List<int> resultList)
- : this(new MojoResult(resultList[0]), resultList[1], resultList[2]);
-}
-
-
-class MojoMessagePipeEndpoint {
- static const int WRITE_FLAG_NONE = 0;
- static const int READ_FLAG_NONE = 0;
- static const int READ_FLAG_MAY_DISCARD = 0;
-
- RawMojoHandle handle;
- MojoResult status;
-
- MojoMessagePipeEndpoint(this.handle);
-
- MojoResult write(ByteData data,
- [int num_bytes = -1,
- List<RawMojoHandle> handles = null,
- int flags = 0]) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
-
- // If num_bytes has the default value, use the full length of the data.
- int data_num_bytes = (num_bytes == -1) ? data.lengthInBytes : num_bytes;
- if (data_num_bytes > data.lengthInBytes) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
-
- // handles may be null, otherwise convert to ints.
- List<int> mojo_handles =
- (handles != null) ? handles.map((h) => h.h).toList() : null;
-
- // Do the call.
- int result = _MojoMessagePipeNatives.MojoWriteMessage(
- handle.h, data, data_num_bytes, mojo_handles, flags);
-
- status = new MojoResult(result);
- return status;
- }
-
-
- MojoMessagePipeReadResult read(ByteData data,
- [int num_bytes = -1,
- List<RawMojoHandle> handles = null,
- int flags = 0]) {
- if (handle == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return null;
- }
-
- // If num_bytes has the default value, use the full length of the data.
- int data_num_bytes;
- if (data == null) {
- data_num_bytes = 0;
- } else {
- data_num_bytes = (num_bytes == -1) ? data.lengthInBytes : num_bytes;
- }
- if (data_num_bytes > data.lengthInBytes) {
- status = MojoResult.INVALID_ARGUMENT;
- return status;
- }
-
- // handles may be null, otherwise make an int list for the handles.
- List<int> mojo_handles;
- if (handles == null) {
- mojo_handles = null;
- } else {
- mojo_handles = new List<int>(handles.length);
- }
-
- // Do the call.
- List result = _MojoMessagePipeNatives.MojoReadMessage(
- handle.h, data, data_num_bytes, mojo_handles, flags);
-
- if (result == null) {
- status = MojoResult.INVALID_ARGUMENT;
- return null;
- }
-
- assert((result is List) && (result.length == 3));
- var readResult = new MojoMessagePipeReadResult.fromList(result);
-
- // Copy out the handles that were read.
- if (handles != null) {
- for (var i = 0; i < readResult.handlesRead; i++) {
- handles[i].h = mojo_handles[i];
- }
- }
-
- status = readResult.status;
- return readResult;
- }
-
- MojoMessagePipeReadResult query() => read(null);
-}
-
-
-class MojoMessagePipe {
- static const int FLAG_NONE = 0;
-
- List<MojoMessagePipeEndpoint> endpoints;
- MojoResult status;
-
- MojoMessagePipe._() {
- endpoints = null;
- status = MojoResult.OK;
- }
-
- factory MojoMessagePipe([int flags = FLAG_NONE]) {
- List result = _MojoMessagePipeNatives.MojoCreateMessagePipe(flags);
- if (result == null) {
- return null;
- }
- assert((result is List) && (result.length == 3));
-
- RawMojoHandle end1 = new RawMojoHandle(result[1]);
- RawMojoHandle end2 = new RawMojoHandle(result[2]);
- MojoMessagePipe pipe = new MojoMessagePipe._();
- pipe.endpoints = new List(2);
- pipe.endpoints[0] = new MojoMessagePipeEndpoint(end1);
- pipe.endpoints[1] = new MojoMessagePipeEndpoint(end2);
- pipe.status = new MojoResult(result[0]);
- return pipe;
- }
-}
diff --git a/mojo/public/dart/src/mojo_dart_core.cc b/mojo/public/dart/src/mojo_dart_core.cc
deleted file mode 100644
index 7cb50d8..0000000
--- a/mojo/public/dart/src/mojo_dart_core.cc
+++ /dev/null
@@ -1,659 +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 <stdio.h>
-#include <string.h>
-
-#include "base/memory/scoped_ptr.h"
-#include "dart/runtime/include/dart_api.h"
-#include "mojo/public/c/system/core.h"
-#include "mojo/public/platform/native/system_thunks.h"
-
-
-static Dart_NativeFunction ResolveName(
- Dart_Handle name, int argc, bool* auto_setup_scope);
-
-
-DART_EXPORT Dart_Handle mojo_dart_core_Init(Dart_Handle parent_library) {
- if (Dart_IsError(parent_library)) {
- return parent_library;
- }
-
- Dart_Handle result_code = Dart_SetNativeResolver(
- parent_library, ResolveName, NULL);
- if (Dart_IsError(result_code)) {
- return result_code;
- }
-
- return Dart_Null();
-}
-
-
-static Dart_Handle HandleError(Dart_Handle handle) {
- if (Dart_IsError(handle)) {
- Dart_PropagateError(handle);
- }
- return handle;
-}
-
-
-static void SetNullReturn(Dart_NativeArguments arguments) {
- Dart_SetReturnValue(arguments, Dart_Null());
-}
-
-
-static void SetInvalidArgumentReturn(Dart_NativeArguments arguments) {
- Dart_SetIntegerReturnValue(
- arguments, static_cast<int64_t>(MOJO_RESULT_INVALID_ARGUMENT));
-}
-
-
-#define CHECK_INTEGER_ARGUMENT(args, num, result, failure) \
- { \
- Dart_Handle __status; \
- __status = Dart_GetNativeIntegerArgument(args, num, result); \
- if (Dart_IsError(__status)) { \
- Set##failure##Return(arguments); \
- return; \
- } \
- } \
-
-
-extern "C" {
- extern size_t MojoSetSystemThunks(const MojoSystemThunks* system_thunks);
-}
-
-
-static void MojoSystemThunks_Set(Dart_NativeArguments arguments) {
- int64_t thunks_addr = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &thunks_addr, Null);
-
- MojoSystemThunks* thunks = reinterpret_cast<MojoSystemThunks*>(thunks_addr);
- MojoSetSystemThunks(thunks);
-
- Dart_SetReturnValue(arguments, Dart_Null());
-}
-
-
-static void MojoHandle_Close(Dart_NativeArguments arguments) {
- int64_t handle;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument);
-
- MojoResult res = MojoClose(static_cast<MojoHandle>(handle));
-
- Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res));
-}
-
-
-static void MojoHandle_Wait(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- int64_t signals = 0;
- int64_t deadline = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &signals, InvalidArgument);
- CHECK_INTEGER_ARGUMENT(arguments, 2, &deadline, InvalidArgument);
-
- MojoResult r = MojoWait(static_cast<MojoHandle>(handle),
- static_cast<MojoHandleSignals>(signals),
- static_cast<MojoDeadline>(deadline));
-
- Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(r));
-}
-
-
-static void MojoHandle_WaitMany(Dart_NativeArguments arguments) {
- int64_t num_handles = 0;
- int64_t deadline = 0;
- Dart_Handle handles = Dart_GetNativeArgument(arguments, 0);
- Dart_Handle signals = Dart_GetNativeArgument(arguments, 1);
- CHECK_INTEGER_ARGUMENT(arguments, 2, &num_handles, InvalidArgument);
- CHECK_INTEGER_ARGUMENT(arguments, 3, &deadline, InvalidArgument);
-
- if (!Dart_IsList(handles) || !Dart_IsList(signals)) {
- SetInvalidArgumentReturn(arguments);
- return;
- }
-
- intptr_t handles_len = 0;
- intptr_t signals_len = 0;
- Dart_ListLength(handles, &handles_len);
- Dart_ListLength(signals, &signals_len);
- if ((handles_len != num_handles) || (signals_len != num_handles)) {
- SetInvalidArgumentReturn(arguments);
- return;
- }
-
- scoped_ptr<MojoHandle[]> mojo_handles(new MojoHandle[num_handles]);
- scoped_ptr<MojoHandleSignals[]> mojo_signals(
- new MojoHandleSignals[num_handles]);
-
- for (int i = 0; i < num_handles; i++) {
- Dart_Handle dart_handle = Dart_ListGetAt(handles, i);
- Dart_Handle dart_signal = Dart_ListGetAt(signals, i);
- if (!Dart_IsInteger(dart_handle) || !Dart_IsInteger(dart_signal)) {
- SetInvalidArgumentReturn(arguments);
- return;
- }
- int64_t mojo_handle = 0;
- int64_t mojo_signal = 0;
- Dart_IntegerToInt64(dart_handle, &mojo_handle);
- Dart_IntegerToInt64(dart_signal, &mojo_signal);
- mojo_handles[i] = static_cast<MojoHandle>(mojo_handle);
- mojo_signals[i] = static_cast<MojoHandleSignals>(mojo_signal);
- }
-
- MojoResult res = MojoWaitMany(mojo_handles.get(), mojo_signals.get(),
- static_cast<uint32_t>(num_handles),
- static_cast<MojoDeadline>(deadline));
- Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res));
-}
-
-
-static void MojoSharedBuffer_Create(Dart_NativeArguments arguments) {
- int64_t num_bytes = 0;
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &num_bytes, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &flags, Null);
-
- MojoCreateSharedBufferOptions options;
- options.struct_size = sizeof(MojoCreateSharedBufferOptions);
- options.flags = static_cast<MojoCreateSharedBufferOptionsFlags>(flags);
-
- MojoHandle out = MOJO_HANDLE_INVALID;;
- MojoResult res = MojoCreateSharedBuffer(
- &options, static_cast<int32_t>(num_bytes), &out);
-
- Dart_Handle list = Dart_NewList(2);
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, Dart_NewInteger(out));
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoSharedBuffer_Duplicate(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &flags, Null);
-
- MojoDuplicateBufferHandleOptions options;
- options.struct_size = sizeof(MojoDuplicateBufferHandleOptions);
- options.flags = static_cast<MojoDuplicateBufferHandleOptionsFlags>(flags);
-
- MojoHandle out = MOJO_HANDLE_INVALID;;
- MojoResult res = MojoDuplicateBufferHandle(
- static_cast<MojoHandle>(handle), &options, &out);
-
- Dart_Handle list = Dart_NewList(2);
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, Dart_NewInteger(out));
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoSharedBuffer_Map(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- int64_t offset = 0;
- int64_t num_bytes = 0;
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &offset, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 2, &num_bytes, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 3, &flags, Null);
-
- void* out;
- MojoResult res = MojoMapBuffer(static_cast<MojoHandle>(handle),
- offset,
- num_bytes,
- &out,
- static_cast<MojoMapBufferFlags>(flags));
-
- Dart_Handle list = Dart_NewList(2);
- Dart_Handle typed_data;
- if (res == MOJO_RESULT_OK) {
- typed_data = Dart_NewExternalTypedData(
- Dart_TypedData_kByteData, out, num_bytes);
- } else {
- typed_data = Dart_Null();
- }
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, typed_data);
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoSharedBuffer_Unmap(Dart_NativeArguments arguments) {
- Dart_Handle typed_data = Dart_GetNativeArgument(arguments, 0);
- if (!Dart_IsTypedData(typed_data)) {
- SetInvalidArgumentReturn(arguments);
- return;
- }
-
- Dart_TypedData_Type typ;
- void *data;
- intptr_t len;
- Dart_TypedDataAcquireData(typed_data, &typ, &data, &len);
- MojoResult res = MojoUnmapBuffer(data);
- Dart_TypedDataReleaseData(typed_data);
-
- Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res));
-}
-
-
-static void MojoDataPipe_Create(Dart_NativeArguments arguments) {
- int64_t element_bytes = 0;
- int64_t capacity_bytes = 0;
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &element_bytes, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &capacity_bytes, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 2, &flags, Null);
-
- MojoCreateDataPipeOptions options;
- options.struct_size = sizeof(MojoCreateDataPipeOptions);
- options.flags = static_cast<MojoCreateDataPipeOptionsFlags>(flags);
- options.element_num_bytes = static_cast<uint32_t>(element_bytes);
- options.capacity_num_bytes = static_cast<uint32_t>(capacity_bytes);
-
- MojoHandle producer = MOJO_HANDLE_INVALID;
- MojoHandle consumer = MOJO_HANDLE_INVALID;
- MojoResult res = MojoCreateDataPipe(&options, &producer, &consumer);
-
- Dart_Handle list = Dart_NewList(3);
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, Dart_NewInteger(producer));
- Dart_ListSetAt(list, 2, Dart_NewInteger(consumer));
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoDataPipe_WriteData(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, Null);
-
- Dart_Handle typed_data = Dart_GetNativeArgument(arguments, 1);
- if (!Dart_IsTypedData(typed_data)) {
- SetNullReturn(arguments);
- return;
- }
-
- int64_t num_bytes = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 2, &num_bytes, Null);
-
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 3, &flags, Null);
-
- Dart_TypedData_Type type;
- void* data;
- intptr_t data_length;
- Dart_TypedDataAcquireData(typed_data, &type, &data, &data_length);
- uint32_t length = static_cast<uint32_t>(num_bytes);
- MojoResult res = MojoWriteData(
- static_cast<MojoHandle>(handle),
- data,
- &length,
- static_cast<MojoWriteDataFlags>(flags));
- Dart_TypedDataReleaseData(typed_data);
-
- Dart_Handle list = Dart_NewList(2);
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, Dart_NewInteger(length));
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoDataPipe_BeginWriteData(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- int64_t buffer_bytes = 0;
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &buffer_bytes, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 2, &flags, Null);
-
- void* buffer;
- uint32_t size = static_cast<uint32_t>(buffer_bytes);
- MojoResult res = MojoBeginWriteData(
- static_cast<MojoHandle>(handle),
- &buffer,
- &size,
- static_cast<MojoWriteDataFlags>(flags));
-
- Dart_Handle list = Dart_NewList(2);
- Dart_Handle typed_data;
- if (res == MOJO_RESULT_OK) {
- typed_data = Dart_NewExternalTypedData(
- Dart_TypedData_kByteData, buffer, size);
- } else {
- typed_data = Dart_Null();
- }
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, typed_data);
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoDataPipe_EndWriteData(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- int64_t num_bytes_written = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &num_bytes_written, InvalidArgument);
-
- MojoResult res = MojoEndWriteData(
- static_cast<MojoHandle>(handle),
- static_cast<uint32_t>(num_bytes_written));
-
- Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res));
-}
-
-
-static void MojoDataPipe_ReadData(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, Null);
-
- Dart_Handle typed_data = Dart_GetNativeArgument(arguments, 1);
- if (!Dart_IsTypedData(typed_data) && !Dart_IsNull(typed_data)) {
- SetNullReturn(arguments);
- return;
- }
-
- int64_t num_bytes = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 2, &num_bytes, Null);
-
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 3, &flags, Null);
-
- Dart_TypedData_Type typ;
- void* data = NULL;
- intptr_t bdlen = 0;
- if (!Dart_IsNull(typed_data)) {
- Dart_TypedDataAcquireData(typed_data, &typ, &data, &bdlen);
- }
- uint32_t len = static_cast<uint32_t>(num_bytes);
- MojoResult res = MojoReadData(
- static_cast<MojoHandle>(handle),
- data,
- &len,
- static_cast<MojoReadDataFlags>(flags));
- if (!Dart_IsNull(typed_data)) {
- Dart_TypedDataReleaseData(typed_data);
- }
-
- Dart_Handle list = Dart_NewList(2);
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, Dart_NewInteger(len));
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoDataPipe_BeginReadData(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- int64_t buffer_bytes = 0;
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &buffer_bytes, Null);
- CHECK_INTEGER_ARGUMENT(arguments, 2, &flags, Null);
-
- void* buffer;
- uint32_t size = static_cast<uint32_t>(buffer_bytes);
- MojoResult res = MojoBeginReadData(
- static_cast<MojoHandle>(handle),
- const_cast<const void**>(&buffer),
- &size,
- static_cast<MojoWriteDataFlags>(flags));
-
- Dart_Handle list = Dart_NewList(2);
- Dart_Handle typed_data;
- if (res == MOJO_RESULT_OK) {
- typed_data = Dart_NewExternalTypedData(
- Dart_TypedData_kByteData, buffer, size);
- } else {
- typed_data = Dart_Null();
- }
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, typed_data);
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoDataPipe_EndReadData(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- int64_t num_bytes_read = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument);
- CHECK_INTEGER_ARGUMENT(arguments, 1, &num_bytes_read, InvalidArgument);
-
- MojoResult res = MojoEndReadData(
- static_cast<MojoHandle>(handle),
- static_cast<uint32_t>(num_bytes_read));
-
- Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res));
-}
-
-
-static void MojoMessagePipe_Create(Dart_NativeArguments arguments) {
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &flags, Null);
-
- MojoCreateMessagePipeOptions options;
- options.struct_size = sizeof(MojoCreateMessagePipeOptions);
- options.flags = static_cast<MojoCreateMessagePipeOptionsFlags>(flags);
-
- MojoHandle end1 = MOJO_HANDLE_INVALID;
- MojoHandle end2 = MOJO_HANDLE_INVALID;
- MojoResult res = MojoCreateMessagePipe(&options, &end1, &end2);
-
- Dart_Handle list = Dart_NewList(3);
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, Dart_NewInteger(end1));
- Dart_ListSetAt(list, 2, Dart_NewInteger(end2));
- Dart_SetReturnValue(arguments, list);
-}
-
-
-static void MojoMessagePipe_Write(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, InvalidArgument);
-
- Dart_Handle typed_data = Dart_GetNativeArgument(arguments, 1);
- if (!Dart_IsTypedData(typed_data) && !Dart_IsNull(typed_data)) {
- SetInvalidArgumentReturn(arguments);
- return;
- }
-
- int64_t num_bytes = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 2, &num_bytes, InvalidArgument);
-
- Dart_Handle handles = Dart_GetNativeArgument(arguments, 3);
- if (!Dart_IsList(handles) && !Dart_IsNull(handles)) {
- SetInvalidArgumentReturn(arguments);
- return;
- }
-
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 4, &flags, InvalidArgument);
-
- // Grab the data if there is any.
- Dart_TypedData_Type typ;
- void* bytes = NULL;
- intptr_t bdlen = 0;
- if (!Dart_IsNull(typed_data)) {
- Dart_TypedDataAcquireData(typed_data, &typ, &bytes, &bdlen);
- }
-
- // Grab the handles if there are any.
- scoped_ptr<MojoHandle[]> mojo_handles;
- intptr_t handles_len = 0;
- if (!Dart_IsNull(handles)) {
- Dart_ListLength(handles, &handles_len);
- mojo_handles.reset(new MojoHandle[handles_len]);
- for (int i = 0; i < handles_len; i++) {
- Dart_Handle dart_handle = Dart_ListGetAt(handles, i);
- if (!Dart_IsInteger(dart_handle)) {
- SetInvalidArgumentReturn(arguments);
- return;
- }
- int64_t mojo_handle = 0;
- Dart_IntegerToInt64(dart_handle, &mojo_handle);
- mojo_handles[i] = static_cast<MojoHandle>(mojo_handle);
- }
- }
-
- MojoResult res = MojoWriteMessage(
- static_cast<MojoHandle>(handle),
- const_cast<const void*>(bytes),
- static_cast<uint32_t>(num_bytes),
- mojo_handles.get(),
- static_cast<uint32_t>(handles_len),
- static_cast<MojoWriteMessageFlags>(flags));
-
- // Release the data.
- if (!Dart_IsNull(typed_data)) {
- Dart_TypedDataReleaseData(typed_data);
- }
-
- Dart_SetIntegerReturnValue(arguments, static_cast<int64_t>(res));
-}
-
-
-static void MojoMessagePipe_Read(Dart_NativeArguments arguments) {
- int64_t handle = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 0, &handle, Null);
-
- Dart_Handle typed_data = Dart_GetNativeArgument(arguments, 1);
- if (!Dart_IsTypedData(typed_data) && !Dart_IsNull(typed_data)) {
- SetNullReturn(arguments);
- return;
- }
-
- int64_t num_bytes = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 2, &num_bytes, Null);
-
- Dart_Handle handles = Dart_GetNativeArgument(arguments, 3);
- if (!Dart_IsList(handles) && !Dart_IsNull(handles)) {
- SetNullReturn(arguments);
- return;
- }
-
- int64_t flags = 0;
- CHECK_INTEGER_ARGUMENT(arguments, 4, &flags, Null);
-
- // Grab the data if there is any.
- Dart_TypedData_Type typ;
- void* bytes = NULL;
- intptr_t byte_data_len = 0;
- if (!Dart_IsNull(typed_data)) {
- Dart_TypedDataAcquireData(typed_data, &typ, &bytes, &byte_data_len);
- }
- uint32_t blen = static_cast<uint32_t>(num_bytes);
-
- // Grab the handles if there are any.
- scoped_ptr<MojoHandle[]> mojo_handles;
- intptr_t handles_len = 0;
- if (!Dart_IsNull(handles)) {
- Dart_ListLength(handles, &handles_len);
- mojo_handles.reset(new MojoHandle[handles_len]);
- }
- uint32_t hlen = static_cast<uint32_t>(handles_len);
-
- MojoResult res = MojoReadMessage(
- static_cast<MojoHandle>(handle),
- bytes,
- &blen,
- mojo_handles.get(),
- &hlen,
- static_cast<MojoReadMessageFlags>(flags));
-
- // Release the data.
- if (!Dart_IsNull(typed_data)) {
- Dart_TypedDataReleaseData(typed_data);
- }
-
- if (!Dart_IsNull(handles)) {
- for (int i = 0; i < handles_len; i++) {
- Dart_ListSetAt(handles, i, Dart_NewInteger(mojo_handles[i]));
- }
- }
-
- Dart_Handle list = Dart_NewList(3);
- Dart_ListSetAt(list, 0, Dart_NewInteger(res));
- Dart_ListSetAt(list, 1, Dart_NewInteger(blen));
- Dart_ListSetAt(list, 2, Dart_NewInteger(hlen));
- Dart_SetReturnValue(arguments, list);
-}
-
-
-#define SCOPE_FUNCTIONS(V) \
- V(MojoSharedBuffer_Create) \
- V(MojoSharedBuffer_Duplicate) \
- V(MojoSharedBuffer_Map) \
- V(MojoSharedBuffer_Unmap) \
- V(MojoDataPipe_Create) \
- V(MojoDataPipe_WriteData) \
- V(MojoDataPipe_BeginWriteData) \
- V(MojoDataPipe_ReadData) \
- V(MojoDataPipe_BeginReadData) \
- V(MojoDataPipe_EndReadData) \
- V(MojoMessagePipe_Create) \
- V(MojoMessagePipe_Write) \
- V(MojoMessagePipe_Read) \
-
-#define NOSCOPE_FUNCTIONS(V) \
- V(MojoSystemThunks_Set) \
- V(MojoHandle_Close) \
- V(MojoHandle_Wait) \
- V(MojoHandle_WaitMany) \
- V(MojoDataPipe_EndWriteData) \
-
-#define FUNCTION_STRING_MAP(name) {#name, name},
-
-struct FunctionLookup {
- const char* name;
- Dart_NativeFunction function;
-};
-
-FunctionLookup function_list[] = {
- SCOPE_FUNCTIONS(FUNCTION_STRING_MAP)
- {NULL, NULL}
-};
-
-FunctionLookup no_scope_function_list[] = {
- NOSCOPE_FUNCTIONS(FUNCTION_STRING_MAP)
- {NULL, NULL}
-};
-
-#undef FUNCTION_STRING_MAP
-
-
-Dart_NativeFunction ResolveName(Dart_Handle name,
- int argc,
- bool* auto_setup_scope) {
- if (!Dart_IsString(name)) {
- return NULL;
- }
- Dart_NativeFunction result = NULL;
- if (auto_setup_scope == NULL) {
- return NULL;
- }
-
- Dart_EnterScope();
- const char* cname;
- HandleError(Dart_StringToCString(name, &cname));
-
- for (int i=0; function_list[i].name != NULL; ++i) {
- if (strcmp(function_list[i].name, cname) == 0) {
- *auto_setup_scope = true;
- Dart_ExitScope();
- return function_list[i].function;
- }
- }
-
- for (int i=0; no_scope_function_list[i].name != NULL; ++i) {
- if (strcmp(no_scope_function_list[i].name, cname) == 0) {
- *auto_setup_scope = false;
- result = no_scope_function_list[i].function;
- break;
- }
- }
-
- Dart_ExitScope();
- return result;
-}
diff --git a/mojo/public/dart/src/types.dart b/mojo/public/dart/src/types.dart
deleted file mode 100644
index 658e477..0000000
--- a/mojo/public/dart/src/types.dart
+++ /dev/null
@@ -1,116 +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.
-
-
-part of core;
-
-
-class MojoResult {
- static const int kOk = 0;
- static const int kCancelled = -1;
- static const int kUnknown = -2;
- static const int kInvalidArgument = -3;
- static const int kDeadlineExceeded = -4;
- static const int kNotFound = -5;
- static const int kAlreadyExists = -6;
- static const int kPermissionDenied = -7;
- static const int kResourceExhausted = -8;
- static const int kFailedPrecondition = -9;
- static const int kAborted = -10;
- static const int kOutOfRange = -11;
- static const int kUnimplemented = -12;
- static const int kInternal = -13;
- static const int kUnavailable = -14;
- static const int kDataLoss = -15;
- static const int kBusy = -16;
- static const int kShouldWait = -17;
-
- static const OK = const MojoResult._(kOk);
- static const CANCELLED = const MojoResult._(kCancelled);
- static const UNKNOWN = const MojoResult._(kUnknown);
- static const INVALID_ARGUMENT = const MojoResult._(kInvalidArgument);
- static const DEADLINE_EXCEEDED = const MojoResult._(kDeadlineExceeded);
- static const NOT_FOUND = const MojoResult._(kNotFound);
- static const ALREADY_EXISTS = const MojoResult._(kAlreadyExists);
- static const PERMISSION_DENIED = const MojoResult._(kPermissionDenied);
- static const RESOURCE_EXHAUSTED = const MojoResult._(kResourceExhausted);
- static const FAILED_PRECONDITION = const MojoResult._(kFailedPrecondition);
- static const ABORTED = const MojoResult._(kAborted);
- static const OUT_OF_RANGE = const MojoResult._(kOutOfRange);
- static const UNIMPLEMENTED = const MojoResult._(kUnimplemented);
- static const INTERNAL = const MojoResult._(kInternal);
- static const UNAVAILABLE = const MojoResult._(kUnavailable);
- static const DATA_LOSS = const MojoResult._(kDataLoss);
- static const BUSY = const MojoResult._(kBusy);
- static const SHOULD_WAIT = const MojoResult._(kShouldWait);
-
- final int value;
-
- const MojoResult._(this.value);
-
- factory MojoResult(int value) {
- switch (value) {
- case kOk: return OK;
- case kCancelled: return CANCELLED;
- case kUnknown: return UNKNOWN;
- case kInvalidArgument: return INVALID_ARGUMENT;
- case kDeadlineExceeded: return DEADLINE_EXCEEDED;
- case kNotFound: return NOT_FOUND;
- case kAlreadyExists: return ALREADY_EXISTS;
- case kPermissionDenied: return PERMISSION_DENIED;
- case kResourceExhausted: return RESOURCE_EXHAUSTED;
- case kFailedPrecondition: return FAILED_PRECONDITION;
- case kAborted: return ABORTED;
- case kOutOfRange: return OUT_OF_RANGE;
- case kUnimplemented: return UNIMPLEMENTED;
- case kInternal: return INTERNAL;
- case kUnavailable: return UNAVAILABLE;
- case kDataLoss: return DATA_LOSS;
- case kBusy: return BUSY;
- case kShouldWait: return SHOULD_WAIT;
- default: return null;
- }
- }
-
- bool get isOk => (this == OK);
- bool get isCancelled => (this == CANCELLED);
- bool get isUnknown => (this == UNKNOWN);
- bool get isInvalidArgument => (this == INVALID_ARGUMENT);
- bool get isDeadlineExceeded => (this == DEADLINE_EXCEEDED);
- bool get isNotFound => (this == NOT_FOUND);
- bool get isAlreadExists => (this == ALREADY_EXISTS);
- bool get isPermissionDenied => (this == PERMISSION_DENIED);
- bool get isResourceExhausted => (this == RESOURCE_EXHAUSTED);
- bool get isFailedPrecondition => (this == FAILED_PRECONDITION);
- bool get isAborted => (this == ABORTED);
- bool get isOutOfRange => (this == OUT_OF_RANGE);
- bool get isUnimplemented => (this == UNIMPLEMENTED);
- bool get isInternal => (this == INTERNAL);
- bool get isUnavailable => (this == UNAVAILABLE);
- bool get isDataLoss => (this == DATA_LOSS);
- bool get isBusy => (this == BUSY);
- bool get isShouldWait => (this == SHOULD_WAIT);
-}
-
-
-class MojoHandleSignals {
- static const int NONE = 0;
- static const int READABLE = 1 << 0;
- static const int WRITABLE = 1 << 1;
- static const int READWRITE = READABLE | WRITABLE;
-
- static bool isReadable(int mask) => (mask & READABLE) == READABLE;
- static bool isWritable(int mask) => (mask & WRITABLE) == WRITABLE;
- static bool isReadWrite(int mask) => (mask & READWRITE) == READWRITE;
- static int toggleWrite(int mask) =>
- isWritable(mask) ? (mask & ~WRITABLE) : (mask | WRITABLE);
-}
-
-
-class MojoHandleSignalsState {
- const MojoHandleSignalsState(this.satisfied_signals,
- this.satisfiable_signals);
- final int satisfied_signals;
- final int satisfiable_signals;
-}
diff --git a/mojo/public/go/system/impl/mojo_types.go b/mojo/public/go/system/impl/mojo_types.go
index 01d518e..9156a45 100644
--- a/mojo/public/go/system/impl/mojo_types.go
+++ b/mojo/public/go/system/impl/mojo_types.go
@@ -66,7 +66,6 @@ const (
MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0
MOJO_READ_DATA_FLAG_DISCARD = 1 << 1
MOJO_READ_DATA_FLAG_QUERY = 1 << 2
- MOJO_READ_DATA_FLAG_PEEK = 1 << 3
MOJO_WRITE_DATA_FLAG_NONE MojoWriteDataFlags = 0
MOJO_WRITE_DATA_FLAG_ALL_OR_NONE MojoWriteDataFlags = 1 << 0
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java
index b95b6dd..80ed9d1 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Decoder.java
@@ -108,7 +108,7 @@ public class Decoder {
private Decoder(Message message, Validator validator, int baseOffset) {
mMessage = message;
- mMessage.getData().order(ByteOrder.LITTLE_ENDIAN);
+ mMessage.getData().order(ByteOrder.nativeOrder());
mBaseOffset = baseOffset;
mValidator = validator;
}
@@ -615,8 +615,8 @@ public class Decoder {
}
if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH
&& dataHeader.numFields != expectedLength) {
- throw new DeserializationException("Incorrect array length. Expected: "
- + expectedLength + ", but got: " + dataHeader.numFields + ".");
+ throw new DeserializationException("Incorrect array length. Expected: " +
+ expectedLength + ", but got: " + dataHeader.numFields + ".");
}
return dataHeader;
}
@@ -631,8 +631,8 @@ public class Decoder {
}
if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH
&& dataHeader.numFields != expectedLength) {
- throw new DeserializationException("Incorrect array length. Expected: "
- + expectedLength + ", but got: " + dataHeader.numFields + ".");
+ throw new DeserializationException("Incorrect array length. Expected: " +
+ expectedLength + ", but got: " + dataHeader.numFields + ".");
}
return dataHeader;
}
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java
index 75cddc9..ef04f6d 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/Encoder.java
@@ -59,7 +59,7 @@ public class Encoder {
this.core = core;
byteBuffer = ByteBuffer.allocateDirect(
bufferSize > 0 ? bufferSize : INITIAL_BUFFER_SIZE);
- byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
+ byteBuffer.order(ByteOrder.nativeOrder());
dataEnd = 0;
}
@@ -226,8 +226,8 @@ public class Encoder {
encodeNullPointer(offset, nullable);
return;
}
- final int arrayNullability = nullable
- ? BindingsHelper.ARRAY_NULLABLE : BindingsHelper.NOTHING_NULLABLE;
+ final int arrayNullability = nullable ?
+ BindingsHelper.ARRAY_NULLABLE : BindingsHelper.NOTHING_NULLABLE;
encode(v.getBytes(Charset.forName("utf8")), offset, arrayNullability,
BindingsHelper.UNSPECIFIED_ARRAY_LENGTH);
}
@@ -303,8 +303,8 @@ public class Encoder {
encodeNullPointer(offset, BindingsHelper.isArrayNullable(arrayNullability));
return;
}
- if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH
- && expectedLength != v.length) {
+ if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH &&
+ expectedLength != v.length) {
throw new SerializationException("Trying to encode a fixed array of incorrect length.");
}
byte[] bytes = new byte[(v.length + 7) / BindingsHelper.ALIGNMENT];
@@ -327,8 +327,8 @@ public class Encoder {
encodeNullPointer(offset, BindingsHelper.isArrayNullable(arrayNullability));
return;
}
- if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH
- && expectedLength != v.length) {
+ if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH &&
+ expectedLength != v.length) {
throw new SerializationException("Trying to encode a fixed array of incorrect length.");
}
encodeByteArray(v, v.length, offset);
@@ -473,8 +473,8 @@ public class Encoder {
private Encoder encoderForArray(
int elementSizeInByte, int length, int offset, int expectedLength) {
- if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH
- && expectedLength != length) {
+ if (expectedLength != BindingsHelper.UNSPECIFIED_ARRAY_LENGTH &&
+ expectedLength != length) {
throw new SerializationException("Trying to encode a fixed array of incorrect length.");
}
return encoderForArrayByTotalSize(length * elementSizeInByte, length, offset);
diff --git a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ServiceMessage.java b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ServiceMessage.java
index 313dc6a..ac62bf6 100644
--- a/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ServiceMessage.java
+++ b/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ServiceMessage.java
@@ -57,7 +57,7 @@ public class ServiceMessage extends Message {
if (mPayload == null) {
ByteBuffer truncatedBuffer =
((ByteBuffer) getData().position(getHeader().getSize())).slice();
- truncatedBuffer.order(ByteOrder.LITTLE_ENDIAN);
+ truncatedBuffer.order(ByteOrder.nativeOrder());
mPayload = new Message(truncatedBuffer, getHandles());
}
return mPayload;
diff --git a/mojo/public/java/system/src/org/chromium/mojo/system/DataPipe.java b/mojo/public/java/system/src/org/chromium/mojo/system/DataPipe.java
index a5b77ae..4cd74e1 100644
--- a/mojo/public/java/system/src/org/chromium/mojo/system/DataPipe.java
+++ b/mojo/public/java/system/src/org/chromium/mojo/system/DataPipe.java
@@ -161,7 +161,6 @@ public interface DataPipe {
private static final int FLAG_NONE = 0;
private static final int FLAG_ALL_OR_NONE = 1 << 0;
private static final int FLAG_QUERY = 1 << 2;
- private static final int FLAG_PEEK = 1 << 3;
/**
* Immutable flag with not bit set.
@@ -190,7 +189,7 @@ public interface DataPipe {
/**
* Change the query bit of this flag. If set query the number of elements available to read.
- * Mutually exclusive with |discard| and |allOrNone| is ignored if this flag is set.
+ * Mutually exclusive with |dicard| and |allOrNone| is ignored if this flag is set.
*
* @param query the new value of the query bit.
* @return this.
@@ -200,18 +199,6 @@ public interface DataPipe {
}
/**
- * Change the peek bit of this flag. If set, read the requested number of elements, and
- * leave those elements in the pipe. A later read will return the same data.
- * Mutually exclusive with |discard| and |query|.
- *
- * @param peek the new value of the peek bit.
- * @return this.
- */
- public ReadFlags peek(boolean peek) {
- return setFlag(FLAG_PEEK, peek);
- }
-
- /**
* @return a flag with no bit set.
*/
public static ReadFlags none() {
diff --git a/mojo/public/js/core.js b/mojo/public/js/core.js
index 9dcb20f..8727833 100644
--- a/mojo/public/js/core.js
+++ b/mojo/public/js/core.js
@@ -111,7 +111,6 @@ var READ_DATA_FLAG_NONE;
var READ_DATA_FLAG_ALL_OR_NONE;
var READ_DATA_FLAG_DISCARD;
var READ_DATA_FLAG_QUERY;
-var READ_DATA_FLAG_PEEK;
/**
* Closes the given |handle|. See MojoClose for more info.
diff --git a/mojo/public/js/core_unittests.js b/mojo/public/js/core_unittests.js
index eaeaa4f..34cd4c0 100644
--- a/mojo/public/js/core_unittests.js
+++ b/mojo/public/js/core_unittests.js
@@ -15,6 +15,7 @@ define([
runWithDataPipe(testReadAndWriteDataPipe);
runWithDataPipeWithOptions(testNop);
runWithDataPipeWithOptions(testReadAndWriteDataPipe);
+ testHandleToString();
gc.collectGarbage(); // should not crash
this.result = "PASS";
@@ -104,16 +105,6 @@ define([
expect(write.result).toBe(core.RESULT_OK);
expect(write.numBytes).toBe(42);
- var peeked = core.readData(
- pipe.consumerHandle,
- core.READ_DATA_FLAG_PEEK | core.READ_DATA_FLAG_ALL_OR_NONE);
- expect(peeked.result).toBe(core.RESULT_OK);
- expect(peeked.buffer.byteLength).toBe(42);
-
- var peeked_memory = new Uint8Array(peeked.buffer);
- for (var i = 0; i < peeked_memory.length; ++i)
- expect(peeked_memory[i]).toBe((i * i) & 0xFF);
-
var read = core.readData(
pipe.consumerHandle, core.READ_DATA_FLAG_ALL_OR_NONE);
@@ -125,4 +116,18 @@ define([
expect(memory[i]).toBe((i * i) & 0xFF);
}
+ function testHandleToString() {
+ var pipe = core.createDataPipe();
+ expect(pipe.consumerHandle.toString).toBeDefined();
+
+ var openHandleRE = /^\[mojo\:\:Handle \d+\]$/ // e.g. "[mojo::Handle 123]"
+ var openHandleString = pipe.consumerHandle.toString();
+ expect(openHandleString.match(openHandleRE)[0]).toEqual(openHandleString);
+
+ expect(core.close(pipe.producerHandle)).toBe(core.RESULT_OK);
+ expect(core.close(pipe.consumerHandle)).toBe(core.RESULT_OK);
+
+ expect(pipe.consumerHandle.toString()).toEqual("[mojo::Handle null]");
+ }
+
});
diff --git a/mojo/public/js/threading.js b/mojo/public/js/threading.js
deleted file mode 100644
index cfe5037..0000000
--- a/mojo/public/js/threading.js
+++ /dev/null
@@ -1,21 +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.
-
-// Module "mojo/public/js/threading"
-//
-// Note: This file is for documentation purposes only. The code here is not
-// actually executed. The real module is implemented natively in Mojo.
-//
-// This module provides a way for a Mojo application implemented in JS
-// to exit by quitting the current message loop. This module is not
-// intended to be used by Mojo JS application started by the JS
-// content handler.
-
-while (1);
-
-/**
- * Quits the current message loop, esssentially:
- * base::MessageLoop::current()->QuitNow();
-*/
-function quit() { [native code] }
diff --git a/mojo/public/mojo_public.gyp b/mojo/public/mojo_public.gyp
index 1e62097..46f22f7 100644
--- a/mojo/public/mojo_public.gyp
+++ b/mojo/public/mojo_public.gyp
@@ -70,7 +70,6 @@
],
'sources': [
'cpp/bindings/array.h',
- 'cpp/bindings/binding.h',
'cpp/bindings/callback.h',
'cpp/bindings/error_handler.h',
'cpp/bindings/interface_impl.h',
@@ -80,7 +79,6 @@
'cpp/bindings/message_filter.h',
'cpp/bindings/no_interface.h',
'cpp/bindings/string.h',
- 'cpp/bindings/strong_binding.h',
'cpp/bindings/type_converter.h',
'cpp/bindings/lib/array_internal.h',
'cpp/bindings/lib/array_internal.cc',
@@ -98,6 +96,7 @@
'cpp/bindings/lib/filter_chain.h',
'cpp/bindings/lib/fixed_buffer.cc',
'cpp/bindings/lib/fixed_buffer.h',
+ 'cpp/bindings/lib/interface_impl_internal.h',
'cpp/bindings/lib/interface_ptr_internal.h',
'cpp/bindings/lib/map_data_internal.h',
'cpp/bindings/lib/map_internal.h',
@@ -124,7 +123,7 @@
],
},
{
- # GN version: //mojo/public/js
+ # GN version: //mojo/public/js/bindings
'target_name': 'mojo_js_bindings',
'type': 'static_library',
'include_dirs': [
@@ -189,23 +188,16 @@
],
},
{
- 'target_name': 'mojo_application_bindings_mojom',
- 'type': 'none',
- 'variables': {
- 'mojom_files': [
- 'interfaces/application/application.mojom',
- 'interfaces/application/service_provider.mojom',
- 'interfaces/application/shell.mojom',
- ],
- },
- 'includes': [ 'tools/bindings/mojom_bindings_generator_explicit.gypi' ],
- },
- {
# GN version: //mojo/public/interfaces/application:application
'target_name': 'mojo_application_bindings',
'type': 'static_library',
+ 'sources': [
+ 'interfaces/application/application.mojom',
+ 'interfaces/application/service_provider.mojom',
+ 'interfaces/application/shell.mojom',
+ ],
+ 'includes': [ 'tools/bindings/mojom_bindings_generator.gypi' ],
'dependencies': [
- 'mojo_application_bindings_mojom',
'mojo_cpp_bindings',
],
'export_dependent_settings': [
@@ -321,35 +313,28 @@
],
},
{
- 'target_name': 'mojo_public_test_interfaces_mojom',
- 'type': 'none',
- 'variables': {
- 'mojom_files': [
- 'interfaces/bindings/tests/math_calculator.mojom',
- 'interfaces/bindings/tests/no_module.mojom',
- 'interfaces/bindings/tests/rect.mojom',
- 'interfaces/bindings/tests/regression_tests.mojom',
- 'interfaces/bindings/tests/sample_factory.mojom',
- 'interfaces/bindings/tests/sample_import.mojom',
- 'interfaces/bindings/tests/sample_import2.mojom',
- 'interfaces/bindings/tests/sample_interfaces.mojom',
- 'interfaces/bindings/tests/sample_service.mojom',
- 'interfaces/bindings/tests/serialization_test_structs.mojom',
- 'interfaces/bindings/tests/test_structs.mojom',
- 'interfaces/bindings/tests/validation_test_interfaces.mojom',
- ],
- },
- 'includes': [ 'tools/bindings/mojom_bindings_generator_explicit.gypi' ],
- },
- {
# GN version: //mojo/public/interfaces/bindings/tests:test_interfaces
'target_name': 'mojo_public_test_interfaces',
'type': 'static_library',
+ 'sources': [
+ 'interfaces/bindings/tests/math_calculator.mojom',
+ 'interfaces/bindings/tests/no_module.mojom',
+ 'interfaces/bindings/tests/rect.mojom',
+ 'interfaces/bindings/tests/regression_tests.mojom',
+ 'interfaces/bindings/tests/sample_factory.mojom',
+ 'interfaces/bindings/tests/sample_import.mojom',
+ 'interfaces/bindings/tests/sample_import2.mojom',
+ 'interfaces/bindings/tests/sample_interfaces.mojom',
+ 'interfaces/bindings/tests/sample_service.mojom',
+ 'interfaces/bindings/tests/serialization_test_structs.mojom',
+ 'interfaces/bindings/tests/test_structs.mojom',
+ 'interfaces/bindings/tests/validation_test_interfaces.mojom',
+ ],
+ 'includes': [ 'tools/bindings/mojom_bindings_generator.gypi' ],
'export_dependent_settings': [
'mojo_cpp_bindings',
],
'dependencies': [
- 'mojo_public_test_interfaces_mojom',
'mojo_cpp_bindings',
],
},
diff --git a/mojo/public/python/mojo/bindings/descriptor.py b/mojo/public/python/mojo/bindings/descriptor.py
index f190d2b..f566d47 100644
--- a/mojo/public/python/mojo/bindings/descriptor.py
+++ b/mojo/public/python/mojo/bindings/descriptor.py
@@ -41,7 +41,7 @@ class SerializableType(Type):
def __init__(self, typecode):
Type.__init__(self)
self.typecode = typecode
- self.byte_size = struct.calcsize('<%s' % self.GetTypeCode())
+ self.byte_size = struct.calcsize('=%s' % self.GetTypeCode())
def GetTypeCode(self):
"""
diff --git a/mojo/public/python/mojo/bindings/messaging.py b/mojo/public/python/mojo/bindings/messaging.py
index bba3c01..f9061fb 100644
--- a/mojo/public/python/mojo/bindings/messaging.py
+++ b/mojo/public/python/mojo/bindings/messaging.py
@@ -31,9 +31,9 @@ class MessageHeader(object):
"""The header of a mojo message."""
_SIMPLE_MESSAGE_NUM_FIELDS = 2
- _SIMPLE_MESSAGE_STRUCT = struct.Struct("<IIII")
+ _SIMPLE_MESSAGE_STRUCT = struct.Struct("=IIII")
- _REQUEST_ID_STRUCT = struct.Struct("<Q")
+ _REQUEST_ID_STRUCT = struct.Struct("=Q")
_REQUEST_ID_OFFSET = _SIMPLE_MESSAGE_STRUCT.size
_MESSAGE_WITH_REQUEST_ID_NUM_FIELDS = 3
diff --git a/mojo/public/python/mojo/bindings/serialization.py b/mojo/public/python/mojo/bindings/serialization.py
index 2c0478f..9a4b6a9 100644
--- a/mojo/public/python/mojo/bindings/serialization.py
+++ b/mojo/public/python/mojo/bindings/serialization.py
@@ -8,7 +8,7 @@ import struct
# Format of a header for a struct or an array.
-HEADER_STRUCT = struct.Struct("<II")
+HEADER_STRUCT = struct.Struct("=II")
class SerializationException(Exception):
@@ -110,7 +110,7 @@ def _FilterGroups(groups, version):
def _GetStruct(groups):
index = 0
- codes = [ '<' ]
+ codes = [ '=' ]
for group in groups:
code = group.GetTypeCode()
size = group.GetByteSize()
diff --git a/mojo/public/python/mojo/c_core.pxd b/mojo/public/python/mojo/c_core.pxd
index 1526dfe..80b8487d 100644
--- a/mojo/public/python/mojo/c_core.pxd
+++ b/mojo/public/python/mojo/c_core.pxd
@@ -126,7 +126,6 @@ cdef extern from "mojo/public/c/system/core.h" nogil:
const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE
const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD
const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY
- const MojoReadDataFlags MOJO_READ_DATA_FLAG_PEEK
MojoResult MojoCreateDataPipe(
const MojoCreateDataPipeOptions* options,
diff --git a/mojo/public/python/mojo/system.pyx b/mojo/public/python/mojo/system.pyx
index 4507d4d..8285261 100644
--- a/mojo/public/python/mojo/system.pyx
+++ b/mojo/public/python/mojo/system.pyx
@@ -62,7 +62,6 @@ READ_DATA_FLAG_NONE = c_core.MOJO_READ_DATA_FLAG_NONE
READ_DATA_FLAG_ALL_OR_NONE = c_core.MOJO_READ_DATA_FLAG_ALL_OR_NONE
READ_DATA_FLAG_DISCARD = c_core.MOJO_READ_DATA_FLAG_DISCARD
READ_DATA_FLAG_QUERY = c_core.MOJO_READ_DATA_FLAG_QUERY
-READ_DATA_FLAG_PEEK = c_core.MOJO_READ_DATA_FLAG_PEEK
MAP_BUFFER_FLAG_NONE = c_core.MOJO_MAP_BUFFER_FLAG_NONE
def GetTimeTicksNow():
diff --git a/mojo/public/tools/bindings/mojom_bindings_generator.gypi b/mojo/public/tools/bindings/mojom_bindings_generator.gypi
index e8843bb..02c2813 100644
--- a/mojo/public/tools/bindings/mojom_bindings_generator.gypi
+++ b/mojo/public/tools/bindings/mojom_bindings_generator.gypi
@@ -3,23 +3,76 @@
# found in the LICENSE file.
{
- 'includes': [
- 'mojom_bindings_generator_variables.gypi',
- ],
'rules': [
{
'rule_name': '<(_target_name)_mojom_bindings_generator',
'extension': 'mojom',
'variables': {
'mojom_base_output_dir':
- '<!(python <(DEPTH)/build/inverse_depth.py <(DEPTH))',
+ '<!(python <(DEPTH)/build/inverse_depth.py <(DEPTH))',
+ 'mojom_bindings_generator':
+ '<(DEPTH)/mojo/public/tools/bindings/mojom_bindings_generator.py',
'java_out_dir': '<(PRODUCT_DIR)/java_mojo/<(_target_name)/src',
'mojom_import_args%': [
'-I<(DEPTH)'
],
},
'inputs': [
- '<@(mojom_bindings_generator_sources)',
+ '<(mojom_bindings_generator)',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/enum_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_macros.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_request_validator_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_response_validator_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/params_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/constant_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/constants.java.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/enum_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/enum.java.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/header.java.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/interface.java.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/interface_internal.java.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/struct.java.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/enum_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/module_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/module.sky.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/python_templates/module_macros.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/python_templates/module.py.tmpl',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_cpp_generator.py',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_java_generator.py',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_js_generator.py',
+ '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_python_generator.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/__init__.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/error.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/__init__.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/data.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/generator.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/module.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/pack.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/template_expander.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/__init__.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/ast.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/parser.py',
+ '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/translate.py',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/<(mojom_base_output_dir)/<(RULE_INPUT_DIRNAME)/<(RULE_INPUT_ROOT).mojom.cc',
diff --git a/mojo/public/tools/bindings/mojom_bindings_generator_explicit.gypi b/mojo/public/tools/bindings/mojom_bindings_generator_explicit.gypi
deleted file mode 100644
index 68348fb..0000000
--- a/mojo/public/tools/bindings/mojom_bindings_generator_explicit.gypi
+++ /dev/null
@@ -1,69 +0,0 @@
-# Copyright 2013 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.
-
-{
- 'includes': [
- 'mojom_bindings_generator_variables.gypi',
- ],
- 'variables': {
- 'mojom_base_output_dir':
- '<!(python <(DEPTH)/build/inverse_depth.py <(DEPTH))',
- 'mojom_generated_outputs': [
- '<!@(python <(DEPTH)/mojo/public/tools/bindings/mojom_list_outputs.py --basedir <(mojom_base_output_dir) <@(mojom_files))',
- ],
- },
- 'actions': [
- {
- 'action_name': '<(_target_name)_mojom_bindings_generator',
- 'variables': {
- 'java_out_dir': '<(PRODUCT_DIR)/java_mojo/<(_target_name)/src',
- 'mojom_import_args%': [
- '-I<(DEPTH)'
- ],
- },
- 'inputs': [
- '<@(mojom_bindings_generator_sources)',
- '<@(mojom_files)',
- ],
- 'outputs': [
- '<@(mojom_generated_outputs)',
- ],
- 'action': [
- 'python', '<@(mojom_bindings_generator)',
- '<@(mojom_files)',
- '--use_chromium_bundled_pylibs',
- '-d', '<(DEPTH)',
- '<@(mojom_import_args)',
- '-o', '<(SHARED_INTERMEDIATE_DIR)',
- '--java_output_directory=<(java_out_dir)',
- ],
- 'message': 'Generating Mojo bindings from <@(mojom_files)',
- 'process_outputs_as_sources': 1,
- }
- ],
- 'direct_dependent_settings': {
- 'sources': [
- '<@(mojom_generated_outputs)',
- ],
- # Include paths needed to compile the generated sources into a library.
- 'include_dirs': [
- '<(DEPTH)',
- '<(SHARED_INTERMEDIATE_DIR)',
- ],
- 'direct_dependent_settings': {
- # Include paths needed to find the generated header files and their
- # transitive dependancies when using the library.
- 'include_dirs': [
- '<(DEPTH)',
- '<(SHARED_INTERMEDIATE_DIR)',
- ],
- 'variables': {
- 'generated_src_dirs': [
- '<(PRODUCT_DIR)/java_mojo/<(_target_name)/src',
- ],
- },
- }
- },
- 'hard_dependency': 1,
-}
diff --git a/mojo/public/tools/bindings/mojom_bindings_generator_variables.gypi b/mojo/public/tools/bindings/mojom_bindings_generator_variables.gypi
deleted file mode 100644
index b4b53e6..0000000
--- a/mojo/public/tools/bindings/mojom_bindings_generator_variables.gypi
+++ /dev/null
@@ -1,67 +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.
-
-{
- 'variables': {
- 'mojom_bindings_generator':
- '<(DEPTH)/mojo/public/tools/bindings/mojom_bindings_generator.py',
- 'mojom_bindings_generator_sources': [
- '<(mojom_bindings_generator)',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/enum_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_macros.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_proxy_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_request_validator_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_response_validator_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/interface_stub_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/module.cc.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/module-internal.h.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/params_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/struct_serialization_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/constant_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/constants.java.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/enum_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/enum.java.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/header.java.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/interface_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/interface.java.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/interface_internal.java.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/struct_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/java_templates/struct.java.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/enum_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/module_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/module.sky.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/python_templates/module_macros.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/python_templates/module.py.tmpl',
- '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_cpp_generator.py',
- '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_java_generator.py',
- '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_js_generator.py',
- '<(DEPTH)/mojo/public/tools/bindings/generators/mojom_python_generator.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/__init__.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/error.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/__init__.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/data.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/generator.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/module.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/pack.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/generate/template_expander.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/__init__.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/ast.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/lexer.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/parser.py',
- '<(DEPTH)/mojo/public/tools/bindings/pylib/mojom/parse/translate.py',
- ]
- }
-} \ No newline at end of file
diff --git a/mojo/public/tools/bindings/mojom_list_outputs.py b/mojo/public/tools/bindings/mojom_list_outputs.py
deleted file mode 100755
index 8ac94e8..0000000
--- a/mojo/public/tools/bindings/mojom_list_outputs.py
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env python
-# Copyright 2014 The Chromium Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-import argparse
-import os.path
-import sys
-
-def main():
- parser = argparse.ArgumentParser(
- description="GYP helper script for mapping mojoms => generated outputs.")
- parser.add_argument("--basedir", required=True)
- parser.add_argument("mojom", nargs="*")
-
- args = parser.parse_args()
-
- for mojom in args.mojom:
- full = os.path.join("<(SHARED_INTERMEDIATE_DIR)", args.basedir, mojom)
- base, ext = os.path.splitext(full)
- assert ext == ".mojom", mojom
- # Fix filename escaping issues on Windows.
- base = base.replace("\\", "/")
- print base + ".mojom.cc"
- print base + ".mojom.h"
- print base + ".mojom-internal.h"
- print base + ".mojom.js"
- print base + ".mojom.html"
- print base + "_mojom.py"
-
- return 0
-
-if __name__ == "__main__":
- sys.exit(main())
diff --git a/mojo/services/public/cpp/view_manager/BUILD.gn b/mojo/services/public/cpp/view_manager/BUILD.gn
index 22381a3..173abf1 100644
--- a/mojo/services/public/cpp/view_manager/BUILD.gn
+++ b/mojo/services/public/cpp/view_manager/BUILD.gn
@@ -19,8 +19,6 @@ source_set("view_manager") {
"view_manager_context.h",
"view_manager_delegate.h",
"view_observer.h",
- "view_tracker.cc",
- "view_tracker.h",
"window_manager_delegate.h",
]
diff --git a/mojo/services/public/cpp/view_manager/lib/view.cc b/mojo/services/public/cpp/view_manager/lib/view.cc
index b371000..84a0455 100644
--- a/mojo/services/public/cpp/view_manager/lib/view.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view.cc
@@ -311,10 +311,6 @@ void View::Reorder(View* relative, OrderDirection direction) {
}
bool View::Contains(View* child) const {
- if (!child)
- return false;
- if (child == this)
- return true;
if (manager_)
CHECK_EQ(ViewPrivate(child).view_manager(), manager_);
for (View* p = child->parent(); p; p = p->parent()) {
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc
index 84fa87d..91bc265 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_factory.cc
@@ -27,7 +27,6 @@ ViewManagerClientFactory::WeakBindViewManagerToPipe(
scoped_ptr<ViewManagerClientImpl> client(
new ViewManagerClientImpl(delegate, shell));
WeakBindToPipe(client.get(), handle.Pass());
- client->OnConnectionEstablished();
return client.Pass();
}
@@ -35,9 +34,7 @@ ViewManagerClientFactory::WeakBindViewManagerToPipe(
void ViewManagerClientFactory::Create(
ApplicationConnection* connection,
InterfaceRequest<ViewManagerClient> request) {
- ViewManagerClientImpl* impl =
- BindToRequest(new ViewManagerClientImpl(delegate_, shell_), &request);
- impl->OnConnectionEstablished();
+ BindToRequest(new ViewManagerClientImpl(delegate_, shell_), &request);
}
} // namespace mojo
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
index cc04f04..860beb5 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.cc
@@ -199,9 +199,8 @@ void ViewManagerClientImpl::Embed(
Id view_id,
ServiceProviderPtr service_provider) {
DCHECK(connected_);
- service_->Embed(url, view_id,
- MakeRequest<ServiceProvider>(service_provider.PassMessagePipe()),
- ActionCompletedCallback());
+ service_->Embed(url, view_id, service_provider.Pass(),
+ ActionCompletedCallback());
}
void ViewManagerClientImpl::AddView(View* view) {
diff --git a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
index 47f08cd..f40e3a8 100644
--- a/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
+++ b/mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h
@@ -73,8 +73,6 @@ class ViewManagerClientImpl : public ViewManager,
void AddView(View* view);
void RemoveView(Id view_id);
- void OnConnectionEstablished();
-
private:
friend class RootObserver;
@@ -85,6 +83,9 @@ class ViewManagerClientImpl : public ViewManager,
const std::vector<View*>& GetRoots() const override;
View* GetViewById(Id id) override;
+ // Overridden from InterfaceImpl:
+ void OnConnectionEstablished() override;
+
// Overridden from ViewManagerClient:
void OnEmbed(ConnectionSpecificId connection_id,
const String& creator_url,
diff --git a/mojo/services/public/cpp/view_manager/view_tracker.cc b/mojo/services/public/cpp/view_manager/view_tracker.cc
deleted file mode 100644
index 453d6f9..0000000
--- a/mojo/services/public/cpp/view_manager/view_tracker.cc
+++ /dev/null
@@ -1,41 +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/services/public/cpp/view_manager/view_tracker.h"
-
-namespace mojo {
-
-ViewTracker::ViewTracker() {
-}
-
-ViewTracker::~ViewTracker() {
- for (Views::iterator i = views_.begin(); i != views_.end(); ++i)
- (*i)->RemoveObserver(this);
-}
-
-void ViewTracker::Add(View* view) {
- if (views_.count(view))
- return;
-
- view->AddObserver(this);
- views_.insert(view);
-}
-
-void ViewTracker::Remove(View* view) {
- if (views_.count(view)) {
- views_.erase(view);
- view->RemoveObserver(this);
- }
-}
-
-bool ViewTracker::Contains(View* view) {
- return views_.count(view) > 0;
-}
-
-void ViewTracker::OnViewDestroying(View* view) {
- DCHECK_GT(views_.count(view), 0u);
- Remove(view);
-}
-
-} // namespace mojo
diff --git a/mojo/services/public/cpp/view_manager/view_tracker.h b/mojo/services/public/cpp/view_manager/view_tracker.h
deleted file mode 100644
index 71a218a..0000000
--- a/mojo/services/public/cpp/view_manager/view_tracker.h
+++ /dev/null
@@ -1,47 +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.
-
-#ifndef MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TRACKER_H_
-#define MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TRACKER_H_
-
-#include <set>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-
-namespace mojo {
-
-class ViewTracker : public ViewObserver {
- public:
- using Views = std::set<View*>;
-
- ViewTracker();
- ~ViewTracker() override;
-
- // Returns the set of views being observed.
- const std::set<View*>& views() const { return views_; }
-
- // Adds |view| to the set of Views being tracked.
- void Add(View* view);
-
- // Removes |view| from the set of views being tracked.
- void Remove(View* view);
-
- // Returns true if |view| was previously added and has not been removed or
- // deleted.
- bool Contains(View* view);
-
- // ViewObserver overrides:
- virtual void OnViewDestroying(View* view) override;
-
- private:
- Views views_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewTracker);
-};
-
-} // namespace mojo
-
-#endif // MOJO_SERVICES_PUBLIC_CPP_VIEW_MANAGER_VIEW_TRACKER_H_
diff --git a/mojo/services/public/interfaces/accessibility/BUILD.gn b/mojo/services/public/interfaces/accessibility/BUILD.gn
deleted file mode 100644
index 64b570b..0000000
--- a/mojo/services/public/interfaces/accessibility/BUILD.gn
+++ /dev/null
@@ -1,15 +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.
-
-import("//mojo/public/tools/bindings/mojom.gni")
-
-mojom("accessibility") {
- sources = [
- "accessibility.mojom",
- ]
-
- deps = [
- "//mojo/services/public/interfaces/geometry",
- ]
-}
diff --git a/mojo/services/public/interfaces/accessibility/accessibility.mojom b/mojo/services/public/interfaces/accessibility/accessibility.mojom
deleted file mode 100644
index abc97c3..0000000
--- a/mojo/services/public/interfaces/accessibility/accessibility.mojom
+++ /dev/null
@@ -1,35 +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.
-
-module mojo;
-
-import "mojo/services/public/interfaces/geometry/geometry.mojom";
-
-interface AxProvider {
- GetTree() => (array<AxNode> nodes);
-};
-
-struct AxNode {
- // Must be non-zero.
- uint32 id;
-
- // Can be zero if the node has no parent or next sibling.
- uint32 parent_id;
- uint32 next_sibling_id;
-
- mojo.Rect bounds;
-
- // At most one of the below will be present.
- // TODO(aa): These should become a union.
- AxLink? link;
- AxText? text;
-};
-
-struct AxLink {
- string url;
-};
-
-struct AxText {
- string content;
-};
diff --git a/mojo/services/public/interfaces/network/cookie_store.mojom b/mojo/services/public/interfaces/network/cookie_store.mojom
index 92a4241..6f2da5e 100644
--- a/mojo/services/public/interfaces/network/cookie_store.mojom
+++ b/mojo/services/public/interfaces/network/cookie_store.mojom
@@ -5,6 +5,6 @@
module mojo;
interface CookieStore {
- Get(string url) => (string cookies);
- Set(string url, string cookie) => (bool success);
+ Get(string? url) => (string? cookies);
+ Set(string? url, string? cookie) => (bool success);
};
diff --git a/mojo/services/public/interfaces/network/network_service.mojom b/mojo/services/public/interfaces/network/network_service.mojom
index e79dfb5..e3e4070 100644
--- a/mojo/services/public/interfaces/network/network_service.mojom
+++ b/mojo/services/public/interfaces/network/network_service.mojom
@@ -17,9 +17,9 @@ import "mojo/services/public/interfaces/network/web_socket.mojom";
// high-level origin-build requests like WebSockets and HTTP, and the other for
// non-origin-bound low-level stuff like DNS, UDP, and TCP.
interface NetworkService {
- CreateURLLoader(URLLoader& loader);
+ CreateURLLoader(URLLoader&? loader);
- GetCookieStore(CookieStore& cookie_store);
+ GetCookieStore(CookieStore&? cookie_store);
CreateWebSocket(WebSocket& socket);
diff --git a/mojo/services/public/interfaces/network/url_loader.mojom b/mojo/services/public/interfaces/network/url_loader.mojom
index c1d2bd3..b258fc4 100644
--- a/mojo/services/public/interfaces/network/url_loader.mojom
+++ b/mojo/services/public/interfaces/network/url_loader.mojom
@@ -8,17 +8,17 @@ import "mojo/services/public/interfaces/network/network_error.mojom";
struct URLRequest {
// The URL to load.
- string url;
+ string? url;
// The HTTP method if applicable.
- string method = "GET";
+ string? method = "GET";
// Additional HTTP request headers.
- array<string>? headers;
+ array<string?>? headers;
// The payload for the request body, represented as a concatenation of data
// streams. For HTTP requests, the method must be set to "POST" or "PUT".
- array<handle<data_pipe_consumer>>? body;
+ array<handle<data_pipe_consumer>?>? body;
// The number of bytes to be read from |body|. A Content-Length header of
// this value will be sent. Set to -1 if length is unknown, which will cause
@@ -59,7 +59,7 @@ struct URLResponse {
string? status_line;
// The HTTP response headers.
- array<string>? headers;
+ array<string?>? headers;
// The MIME type of the response body.
string? mime_type;
@@ -92,13 +92,13 @@ interface URLLoader {
// Loads the given |request|, asynchronously producing |response|. Consult
// |response| to determine if the request resulted in an error, was
// redirected, or has a response body to be consumed.
- Start(URLRequest request) => (URLResponse response);
+ Start(URLRequest? request) => (URLResponse? response);
// If the request passed to |Start| had |auto_follow_redirects| set to false,
// then upon receiving an URLResponse with a non-NULL |redirect_url| field,
// |FollowRedirect| may be called to load the URL indicated by the redirect.
- FollowRedirect() => (URLResponse response);
+ FollowRedirect() => (URLResponse? response);
// Query status about the URLLoader.
- QueryStatus() => (URLLoaderStatus status);
+ QueryStatus() => (URLLoaderStatus? status);
};
diff --git a/mojo/services/public/interfaces/view_manager/view_manager.mojom b/mojo/services/public/interfaces/view_manager/view_manager.mojom
index 25e1f06..2a1a178 100644
--- a/mojo/services/public/interfaces/view_manager/view_manager.mojom
+++ b/mojo/services/public/interfaces/view_manager/view_manager.mojom
@@ -130,7 +130,7 @@ interface ViewManagerService {
// any services it provided are not broken and continue to be valid.
Embed(string url,
uint32 view_id,
- ServiceProvider&? service_provider) => (bool success);
+ ServiceProvider? service_provider) => (bool success);
};
// Changes to views are not sent to the connection that originated the
diff --git a/mojo/services/public/interfaces/window_manager/window_manager.mojom b/mojo/services/public/interfaces/window_manager/window_manager.mojom
index 8fe6f21..6d108f9 100644
--- a/mojo/services/public/interfaces/window_manager/window_manager.mojom
+++ b/mojo/services/public/interfaces/window_manager/window_manager.mojom
@@ -10,7 +10,7 @@ import "mojo/services/public/interfaces/input_events/input_events.mojom";
[Client=WindowManagerClient]
interface WindowManager {
// Requests the WindowManager to embed the app for |url| at an appropriate
- // View. See ViewMangerService::Embed() for details on |service_provider|.
+ // View. See ViewManger::Embed() for details on |service_provider|.
Embed(string url, ServiceProvider&? service_provider);
SetCapture(uint32 view_id) => (bool success);
diff --git a/mojo/services/public/js/mojo.js b/mojo/services/public/js/mojo.js
deleted file mode 100644
index ad0ed0c..0000000
--- a/mojo/services/public/js/mojo.js
+++ /dev/null
@@ -1,169 +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.
-
-define("mojo/services/public/js/mojo", [
- "mojo/public/interfaces/application/service_provider.mojom",
- "mojo/public/js/connection",
- "mojo/public/js/core",
- "services/js/bridge",
-], function(service, connection, core, bridge) {
-
- function Shell() {
- this.applications_ = new Map();
- }
-
- Shell.prototype.connectToApplication = function(url) {
- var application = this.applications_.get(url);
- if (application)
- return application;
- application = new ServiceProvider(bridge.connectToApplication(url));
- this.applications_.set(url, application);
- return application;
- };
-
- Shell.prototype.connectToService = function (url, service, client) {
- return this.connectToApplication(url).connectToService(service, client);
- };
-
- Shell.prototype.close = function() {
- shell().applications_.forEach(function(application, url) {
- application.close();
- });
- shell().applications_.clear();
- };
-
- var shellValue = null;
-
- function shell() {
- if (!shellValue)
- shellValue = new Shell();
- return shellValue;
- }
-
- var requestorValue = null;
-
- function requestor() {
- if (!requestorValue) {
- var handle = bridge.requestorMessagePipeHandle();
- requestorValue = handle && new ServiceProvider(handle);
- }
- return requestorValue;
- }
-
- function connectToServiceImpl(serviceName, serviceHandle) {
- var provider = this.providers_.get(serviceName);
- if (!provider) {
- this.pendingRequests_.set(serviceName, serviceHandle);
- return;
- }
-
- var serviceConnection = new connection.Connection(
- serviceHandle,
- provider.service.delegatingStubClass,
- provider.service.client && provider.service.client.proxyClass);
-
- serviceConnection.local.connection$ = serviceConnection;
- serviceConnection.local.delegate$ =
- new provider.factory(serviceConnection.remote);
-
- provider.connections.push(serviceConnection);
- }
-
- function ServiceProvider(messagePipeHandle) {
- // TODO(hansmuller): if messagePipeHandle is null, throw an exception.
- this.connections_ = new Map();
- this.providers_ = new Map();
- this.pendingRequests_ = new Map();
- this.connection_ = null;
- this.handle_ = messagePipeHandle;
- this.connection_ = new connection.Connection(
- this.handle_,
- service.ServiceProvider.client.delegatingStubClass,
- service.ServiceProvider.proxyClass);
- this.connection_.local.delegate$ = {
- connectToService: connectToServiceImpl.bind(this)
- };
- }
-
- ServiceProvider.prototype.provideService = function(service, factory) {
- // TODO(hansmuller): if !factory, remove provider and close its connections.
- // TODO(hansmuller): if this.connection_ is null, throw an error.
- var provider = {
- service: service,
- factory: factory,
- connections: [],
- };
- this.providers_.set(service.name, provider);
-
- if (this.pendingRequests_.has(service.name)) {
- connectToServiceImpl(service.name, pendingRequests_.get(service.name));
- pendingRequests_.delete(service.name);
- }
-
- return this;
- };
-
- ServiceProvider.prototype.connectToService = function(service, client) {
- // TODO(hansmuler): if service.name isn't defined, throw an error.
- // TODO(hansmuller): if this.connection_ is null, throw an error.
- var serviceConnection = this.connections_.get(service.name);
- if (serviceConnection)
- return serviceConnection.remote;
-
- var pipe = core.createMessagePipe();
- this.connection_.remote.connectToService(service.name, pipe.handle1);
- var clientClass = client && service.client.delegatingStubClass;
- var serviceConnection =
- new connection.Connection(pipe.handle0, clientClass, service.proxyClass);
- if (serviceConnection.local)
- serviceConnection.local.delegate$ = client;
-
- this.connections_.set(service.name, serviceConnection);
- return serviceConnection.remote;
- };
-
- ServiceProvider.prototype.close = function() {
- if (!this.connection_)
- return;
-
- try {
- // Outgoing connections
- this.connections_.forEach(function(connection, serviceName) {
- connection.close();
- });
- // Incoming connections
- this.providers_.forEach(function(provider, serviceName) {
- provider.connections.forEach(function(connection) {
- connection.close();
- });
- });
- this.connection_.close();
- } finally {
- this.connections_ = null;
- this.providers_ = null;
- this.pendingRequests_ = null;
- this.connection_ = null;
- this.handle_ = null;
-
- shell().applications_.forEach(function(application, url) {
- if (application === this)
- shell().applications_.delete(url);
- }, this);
- }
- };
-
- function quit() {
- if (requestorValue)
- requestor().close();
- if (shellValue)
- shell().close();
- bridge.quit();
- }
-
- var exports = {};
- exports.requestor = requestor;
- exports.shell = shell;
- exports.quit = quit;
- return exports;
-});
diff --git a/ui/keyboard/webui/vk_mojo_handler.cc b/ui/keyboard/webui/vk_mojo_handler.cc
index 5efe763..48e6dcc 100644
--- a/ui/keyboard/webui/vk_mojo_handler.cc
+++ b/ui/keyboard/webui/vk_mojo_handler.cc
@@ -14,11 +14,8 @@
namespace keyboard {
-VKMojoHandler::VKMojoHandler(
- mojo::InterfaceRequest<KeyboardUIHandlerMojo> request)
- : binding_(this, request.Pass()) {
+VKMojoHandler::VKMojoHandler() {
GetInputMethod()->AddObserver(this);
- OnTextInputStateChanged(GetInputMethod()->GetTextInputClient());
}
VKMojoHandler::~VKMojoHandler() {
@@ -29,6 +26,10 @@ ui::InputMethod* VKMojoHandler::GetInputMethod() {
return KeyboardController::GetInstance()->proxy()->GetInputMethod();
}
+void VKMojoHandler::OnConnectionEstablished() {
+ OnTextInputStateChanged(GetInputMethod()->GetTextInputClient());
+}
+
void VKMojoHandler::SendKeyEvent(const mojo::String& event_type,
int32_t char_value,
int32_t key_code,
@@ -106,7 +107,7 @@ void VKMojoHandler::OnTextInputStateChanged(
type_name = "text";
break;
}
- binding_.client()->OnTextInputTypeChanged(type_name);
+ client()->OnTextInputTypeChanged(type_name);
}
void VKMojoHandler::OnInputMethodDestroyed(
diff --git a/ui/keyboard/webui/vk_mojo_handler.h b/ui/keyboard/webui/vk_mojo_handler.h
index 8d69d15..5a25abd 100644
--- a/ui/keyboard/webui/vk_mojo_handler.h
+++ b/ui/keyboard/webui/vk_mojo_handler.h
@@ -6,21 +6,23 @@
#define UI_KEYBOARD_WEBUI_VK_MOJO_HANDLER_H_
#include "base/macros.h"
-#include "mojo/public/cpp/bindings/binding.h"
#include "ui/base/ime/input_method_observer.h"
#include "ui/keyboard/webui/keyboard.mojom.h"
namespace keyboard {
-class VKMojoHandler : public KeyboardUIHandlerMojo,
+class VKMojoHandler : public mojo::InterfaceImpl<KeyboardUIHandlerMojo>,
public ui::InputMethodObserver {
public:
- explicit VKMojoHandler(mojo::InterfaceRequest<KeyboardUIHandlerMojo> request);
+ VKMojoHandler();
~VKMojoHandler() override;
private:
ui::InputMethod* GetInputMethod();
+ // mojo::InterfaceImpl<>:
+ void OnConnectionEstablished() override;
+
// KeyboardUIHandlerMojo:
void SendKeyEvent(const mojo::String& event_type,
int32_t char_value,
@@ -38,8 +40,6 @@ class VKMojoHandler : public KeyboardUIHandlerMojo,
void OnInputMethodDestroyed(const ui::InputMethod* input_method) override;
void OnShowImeIfNeeded() override;
- mojo::Binding<KeyboardUIHandlerMojo> binding_;
-
DISALLOW_COPY_AND_ASSIGN(VKMojoHandler);
};
diff --git a/ui/keyboard/webui/vk_webui_controller.cc b/ui/keyboard/webui/vk_webui_controller.cc
index 5fd04ce..2e0138b 100644
--- a/ui/keyboard/webui/vk_webui_controller.cc
+++ b/ui/keyboard/webui/vk_webui_controller.cc
@@ -68,7 +68,8 @@ void VKWebUIController::RenderViewCreated(content::RenderViewHost* host) {
void VKWebUIController::CreateAndStoreUIHandler(
mojo::InterfaceRequest<KeyboardUIHandlerMojo> request) {
- ui_handler_ = make_scoped_ptr(new VKMojoHandler(request.Pass()));
+ ui_handler_ = scoped_ptr<VKMojoHandler>(
+ mojo::WeakBindToRequest(new VKMojoHandler(), &request));
}
////////////////////////////////////////////////////////////////////////////////