diff --git a/components/view_manager/view_manager_client_apptest.cc b/components/view_manager/view_manager_client_apptest.cc index 2cdec887b151e6..960625e0370f6a 100644 --- a/components/view_manager/view_manager_client_apptest.cc +++ b/components/view_manager/view_manager_client_apptest.cc @@ -142,7 +142,6 @@ class ViewTracker : public ViewObserver { view_ = nullptr; } - int id_; View* view_; MOJO_DISALLOW_COPY_AND_ASSIGN(ViewTracker); diff --git a/components/view_manager/view_manager_service_impl.cc b/components/view_manager/view_manager_service_impl.cc index 1b5f9a644a4c76..16ddc8326d1bc5 100644 --- a/components/view_manager/view_manager_service_impl.cc +++ b/components/view_manager/view_manager_service_impl.cc @@ -200,7 +200,8 @@ bool ViewManagerServiceImpl::Embed(const ViewId& view_id, if (!client.get() || !CanEmbed(view_id)) return false; PrepareForEmbed(view_id); - ignore_result(connection_manager_->EmbedAtView(id_, view_id, client.Pass())); + ::ignore_result( + connection_manager_->EmbedAtView(id_, view_id, client.Pass())); return true; } diff --git a/content/browser/webui/web_ui_mojo_browsertest.cc b/content/browser/webui/web_ui_mojo_browsertest.cc index f41c6e2cff24e9..5ceb632a5d63f5 100644 --- a/content/browser/webui/web_ui_mojo_browsertest.cc +++ b/content/browser/webui/web_ui_mojo_browsertest.cc @@ -26,7 +26,7 @@ #include "content/public/test/content_browser_test_utils.h" #include "content/shell/browser/shell.h" #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" -#include "third_party/mojo/src/mojo/edk/test/test_utils.h" +#include "mojo/test/test_utils.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" #include "third_party/mojo/src/mojo/public/js/constants.h" diff --git a/content/content_tests.gypi b/content/content_tests.gypi index fd6a899a3ec5f3..5328282fb0b3a5 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -1397,6 +1397,7 @@ '../media/media.gyp:shared_memory_support', '../mojo/mojo_base.gyp:mojo_application_base', '../mojo/mojo_base.gyp:mojo_environment_chromium', + '../mojo/mojo_base.gyp:mojo_test_support', '../net/net.gyp:net_test_support', '../ppapi/ppapi_internal.gyp:ppapi_host', '../ppapi/ppapi_internal.gyp:ppapi_ipc', diff --git a/content/test/BUILD.gn b/content/test/BUILD.gn index 8114b7da37c9d2..c924395881b47b 100644 --- a/content/test/BUILD.gn +++ b/content/test/BUILD.gn @@ -290,6 +290,7 @@ if (!is_mac) { "//media:shared_memory_support", "//mojo/application/public/cpp:cpp_for_chromium", "//mojo/environment:chromium", + "//mojo/test:test_support", "//net:test_support", "//ppapi/host", "//ppapi/proxy", diff --git a/ipc/mojo/async_handle_waiter_unittest.cc b/ipc/mojo/async_handle_waiter_unittest.cc index 441b4ecd316c4c..46d4c7ef73937b 100644 --- a/ipc/mojo/async_handle_waiter_unittest.cc +++ b/ipc/mojo/async_handle_waiter_unittest.cc @@ -202,7 +202,7 @@ TEST_F(AsyncHandleWaiterTest, RestartWaitingWhileSignaled) { EXPECT_TRUE(handler.IsClosingHandled()); // |HandlerThatReenters::RestartAndClose| already closed it. - ignore_result(pipe_to_read_.release()); + ::ignore_result(pipe_to_read_.release()); } class AsyncHandleWaiterIOObserverTest : public testing::Test { diff --git a/mojo/mojo_base.gyp b/mojo/mojo_base.gyp index 1e3b1810f50eca..a12ab7931c7e2e 100644 --- a/mojo/mojo_base.gyp +++ b/mojo/mojo_base.gyp @@ -256,6 +256,19 @@ 'mojo_services.gyp:network_service_bindings_lib', ], }, + { + # GN version: //mojo/test:test_support + 'target_name': 'mojo_test_support', + 'type': 'static_library', + 'dependencies': [ + '../base/base.gyp:base', + ], + 'sources': [ + 'test/test_utils.h', + 'test/test_utils_posix.cc', + 'test/test_utils_win.cc', + ], + }, { # GN version: //mojo/application/public/cpp/tests 'target_name': 'mojo_public_application_unittests', diff --git a/mojo/test/BUILD.gn b/mojo/test/BUILD.gn new file mode 100644 index 00000000000000..05f54a4036b290 --- /dev/null +++ b/mojo/test/BUILD.gn @@ -0,0 +1,15 @@ +# Copyright 2015 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +source_set("test_support") { + sources = [ + "test_utils.h", + "test_utils_posix.cc", + "test_utils_win.cc", + ] + + public_deps = [ + "//base", + ] +} diff --git a/mojo/test/test_utils.h b/mojo/test/test_utils.h new file mode 100644 index 00000000000000..ffb4c28072fb5a --- /dev/null +++ b/mojo/test/test_utils.h @@ -0,0 +1,21 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MOJO_TEST_TEST_UTILS_H_ +#define MOJO_TEST_TEST_UTILS_H_ + +#include + +#include "base/files/file_path.h" + +namespace mojo { +namespace test { + +// Returns the path to the mojom js bindings file. +base::FilePath GetFilePathForJSResource(const std::string& path); + +} // namespace test +} // namespace mojo + +#endif // MOJO_TEST_TEST_UTILS_H_ diff --git a/mojo/test/test_utils_posix.cc b/mojo/test/test_utils_posix.cc new file mode 100644 index 00000000000000..5ac356f6501e2e --- /dev/null +++ b/mojo/test/test_utils_posix.cc @@ -0,0 +1,21 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/test/test_utils.h" + +#include "base/base_paths.h" +#include "base/path_service.h" + +namespace mojo { +namespace test { + +base::FilePath GetFilePathForJSResource(const std::string& path) { + std::string binding_path = "gen/" + path + ".js"; + base::FilePath exe_dir; + PathService::Get(base::DIR_EXE, &exe_dir); + return exe_dir.AppendASCII(binding_path); +} + +} // namespace test +} // namespace mojo diff --git a/mojo/test/test_utils_win.cc b/mojo/test/test_utils_win.cc new file mode 100644 index 00000000000000..e022c9a375592e --- /dev/null +++ b/mojo/test/test_utils_win.cc @@ -0,0 +1,22 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "mojo/test/test_utils.h" + +#include "base/base_paths.h" +#include "base/path_service.h" +#include "base/strings/string_util.h" +namespace mojo { +namespace test { + +base::FilePath GetFilePathForJSResource(const std::string& path) { + std::string binding_path = "gen/" + path + ".js"; + base::ReplaceChars(binding_path, "//", "\\", &binding_path); + base::FilePath exe_dir; + PathService::Get(base::DIR_EXE, &exe_dir); + return exe_dir.AppendASCII(binding_path); +} + +} // namespace test +} // namespace mojo diff --git a/third_party/mojo/mojom_bindings_generator_variables.gypi b/third_party/mojo/mojom_bindings_generator_variables.gypi index d1ea5fca65d69b..cc8f041d632eb7 100644 --- a/third_party/mojo/mojom_bindings_generator_variables.gypi +++ b/third_party/mojo/mojom_bindings_generator_variables.gypi @@ -41,6 +41,8 @@ '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/module_definition.tmpl', '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/module.amd.tmpl', '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl', + '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/union_definition.tmpl', + '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/validation_macros.tmpl', '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/python_templates/module_macros.tmpl', '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/python_templates/module.py.tmpl', '<(DEPTH)/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_cpp_generator.py', diff --git a/third_party/mojo/src/mojo/edk/embedder/BUILD.gn b/third_party/mojo/src/mojo/edk/embedder/BUILD.gn index 74fe45a77937e5..c3e0d538be9bc8 100644 --- a/third_party/mojo/src/mojo/edk/embedder/BUILD.gn +++ b/third_party/mojo/src/mojo/edk/embedder/BUILD.gn @@ -83,6 +83,8 @@ mojo_edk_source_set("platform") { mojo_edk_configs = [ "mojo/edk/system:system_config" ] + mojo_sdk_public_deps = [ "mojo/public/cpp/system" ] + deps = [ "//base", "//crypto", @@ -112,9 +114,7 @@ mojo_edk_source_set("delegates") { mojo_edk_configs = [ "mojo/edk/system:system_config" ] - deps = [ - "//base", - ] + mojo_sdk_public_deps = [ "mojo/public/cpp/system" ] } mojo_edk_source_set("embedder_unittests") { diff --git a/third_party/mojo/src/mojo/edk/embedder/embedder.cc b/third_party/mojo/src/mojo/edk/embedder/embedder.cc index 6cc75754517f0b..523b368d07e3f6 100644 --- a/third_party/mojo/src/mojo/edk/embedder/embedder.cc +++ b/third_party/mojo/src/mojo/edk/embedder/embedder.cc @@ -103,8 +103,8 @@ MojoResult CreatePlatformHandleWrapper( MojoHandle* platform_handle_wrapper_handle) { DCHECK(platform_handle_wrapper_handle); - scoped_refptr dispatcher( - new system::PlatformHandleDispatcher(platform_handle.Pass())); + scoped_refptr dispatcher = + system::PlatformHandleDispatcher::Create(platform_handle.Pass()); DCHECK(internal::g_core); MojoHandle h = internal::g_core->AddDispatcher(dispatcher); @@ -173,8 +173,8 @@ void ShutdownIPCSupport() { ScopedMessagePipeHandle ConnectToSlave( SlaveInfo slave_info, ScopedPlatformHandle platform_handle, - const DidConnectToSlaveCallback& callback, - scoped_refptr callback_thread_task_runner, + const base::Closure& did_connect_to_slave_callback, + scoped_refptr did_connect_to_slave_runner, std::string* platform_connection_id, ChannelInfo** channel_info) { DCHECK(platform_connection_id); @@ -187,8 +187,9 @@ ScopedMessagePipeHandle ConnectToSlave( system::ChannelId channel_id = system::kInvalidChannelId; scoped_refptr dispatcher = internal::g_ipc_support->ConnectToSlave( - connection_id, slave_info, platform_handle.Pass(), callback, - callback_thread_task_runner.Pass(), &channel_id); + connection_id, slave_info, platform_handle.Pass(), + did_connect_to_slave_callback, did_connect_to_slave_runner.Pass(), + &channel_id); *channel_info = new ChannelInfo(channel_id); ScopedMessagePipeHandle rv( @@ -201,8 +202,8 @@ ScopedMessagePipeHandle ConnectToSlave( ScopedMessagePipeHandle ConnectToMaster( const std::string& platform_connection_id, - const DidConnectToMasterCallback& callback, - scoped_refptr callback_thread_task_runner, + const base::Closure& did_connect_to_master_callback, + scoped_refptr did_connect_to_master_runner, ChannelInfo** channel_info) { DCHECK(channel_info); DCHECK(internal::g_ipc_support); @@ -215,8 +216,8 @@ ScopedMessagePipeHandle ConnectToMaster( system::ChannelId channel_id = system::kInvalidChannelId; scoped_refptr dispatcher = internal::g_ipc_support->ConnectToMaster( - connection_id, callback, callback_thread_task_runner.Pass(), - &channel_id); + connection_id, did_connect_to_master_callback, + did_connect_to_master_runner.Pass(), &channel_id); *channel_info = new ChannelInfo(channel_id); ScopedMessagePipeHandle rv( @@ -253,10 +254,10 @@ ScopedMessagePipeHandle CreateChannelOnIOThread( ScopedMessagePipeHandle CreateChannel( ScopedPlatformHandle platform_handle, - const DidCreateChannelCallback& callback, - scoped_refptr callback_thread_task_runner) { + const base::Callback& did_create_channel_callback, + scoped_refptr did_create_channel_runner) { DCHECK(platform_handle.is_valid()); - DCHECK(!callback.is_null()); + DCHECK(!did_create_channel_callback.is_null()); DCHECK(internal::g_ipc_support); system::ChannelManager* channel_manager = @@ -267,8 +268,9 @@ ScopedMessagePipeHandle CreateChannel( scoped_refptr dispatcher = channel_manager->CreateChannel( channel_id, platform_handle.Pass(), - base::Bind(callback, base::Unretained(channel_info.release())), - callback_thread_task_runner); + base::Bind(did_create_channel_callback, + base::Unretained(channel_info.release())), + did_create_channel_runner); ScopedMessagePipeHandle rv( MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher))); @@ -293,17 +295,18 @@ void DestroyChannelOnIOThread(ChannelInfo* channel_info) { // TODO(vtl): Write tests for this. void DestroyChannel( ChannelInfo* channel_info, - const DidDestroyChannelCallback& callback, - scoped_refptr callback_thread_task_runner) { + const base::Closure& did_destroy_channel_callback, + scoped_refptr did_destroy_channel_runner) { DCHECK(channel_info); DCHECK(channel_info->channel_id); - DCHECK(!callback.is_null()); + DCHECK(!did_destroy_channel_callback.is_null()); DCHECK(internal::g_ipc_support); system::ChannelManager* channel_manager = internal::g_ipc_support->channel_manager(); - channel_manager->ShutdownChannel(channel_info->channel_id, callback, - callback_thread_task_runner); + channel_manager->ShutdownChannel(channel_info->channel_id, + did_destroy_channel_callback, + did_destroy_channel_runner); delete channel_info; } diff --git a/third_party/mojo/src/mojo/edk/embedder/embedder.h b/third_party/mojo/src/mojo/edk/embedder/embedder.h index c4a4e51114324f..2514c7c72de224 100644 --- a/third_party/mojo/src/mojo/edk/embedder/embedder.h +++ b/third_party/mojo/src/mojo/edk/embedder/embedder.h @@ -123,19 +123,19 @@ MOJO_SYSTEM_IMPL_EXPORT void ShutdownIPCSupport(); // returns a handle), an ID string (returned in |*platform_connection_id|) that // must be passed to the slave (e.g., on the command line), and a // |ChannelInfo*| (in |*channel_info|) which should eventually be given to -// |DestroyChannel()|/|DestroyChannelOnIOThread()|, but only after |callback| -// has been run. +// |DestroyChannel()|/|DestroyChannelOnIOThread()|, but only after +// |did_connect_to_slave_callback| has been run. // -// |callback| will be run either using |callback_thread_task_runner| (if -// non-null) or on the I/O thread, once the |ChannelInfo*| is valid. +// |did_connect_to_slave_callback| will be run either using +// |did_connect_to_slave_runner| (if non-null) or on the I/O thread, once the +// |ChannelInfo*| is valid. // // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|. -using DidConnectToSlaveCallback = base::Closure; MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle ConnectToSlave(SlaveInfo slave_info, ScopedPlatformHandle platform_handle, - const DidConnectToSlaveCallback& callback, - scoped_refptr callback_thread_task_runner, + const base::Closure& did_connect_to_slave_callback, + scoped_refptr did_connect_to_slave_runner, std::string* platform_connection_id, ChannelInfo** channel_info); @@ -146,15 +146,14 @@ ConnectToSlave(SlaveInfo slave_info, // // See |ConnectToSlave()| for details. (Note that if this fails in any way, // e.g., if |platform_connection_id| is invalid, this will CHECK-fail and -// terminate the process.) |channel_info|, |callback|, and -// |callback_thread_task_runner| are as in |ConnectToSlave()|. +// terminate the process.) |channel_info|, |did_connect_to_master_callback|, and +// |did_connect_to_master_runner| are analagous to in |ConnectToSlave()|. // // TODO(vtl): The API is a little crazy with respect to the |ChannelInfo*|. -using DidConnectToMasterCallback = base::Closure; MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle ConnectToMaster(const std::string& platform_connection_id, - const DidConnectToMasterCallback& callback, - scoped_refptr callback_thread_task_runner, + const base::Closure& did_connect_to_master_callback, + scoped_refptr did_connect_to_master_runner, ChannelInfo** channel_info); // A "channel" is a connection on top of an OS "pipe", on top of which Mojo @@ -201,21 +200,20 @@ MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle CreateChannelOnIOThread(ScopedPlatformHandle platform_handle, ChannelInfo** channel_info); -using DidCreateChannelCallback = base::Callback; // Creates a channel asynchronously; may be called from any thread. // |platform_handle| should be a handle to a connected OS "pipe". -// |callback| should be the callback to call with the |ChannelInfo*|, which -// should eventually be passed to |DestroyChannel()| to tear down the channel; -// the callback will be called using |callback_thread_task_runner| if that is -// non-null, or otherwise it will be posted to the I/O thread. Returns a handle -// to the bootstrap message pipe. +// |did_create_channel_callback| should be the callback to call with the +// |ChannelInfo*|, which should eventually be passed to |DestroyChannel()| to +// tear down the channel; the callback will be called using +// |did_create_channel_runner| if that is non-null, or otherwise it will be +// posted to the I/O thread. Returns a handle to the bootstrap message pipe. // // Note: This should only be used to establish a channel with a process of type // |ProcessType::NONE|. This function may be removed in the future. -MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle -CreateChannel(ScopedPlatformHandle platform_handle, - const DidCreateChannelCallback& callback, - scoped_refptr callback_thread_task_runner); +MOJO_SYSTEM_IMPL_EXPORT ScopedMessagePipeHandle CreateChannel( + ScopedPlatformHandle platform_handle, + const base::Callback& did_create_channel_callback, + scoped_refptr did_create_channel_runner); // Destroys a channel that was created using |ConnectToMaster()|, // |ConnectToSlave()|, |CreateChannel()|, or |CreateChannelOnIOThread()|; must @@ -224,16 +222,15 @@ CreateChannel(ScopedPlatformHandle platform_handle, MOJO_SYSTEM_IMPL_EXPORT void DestroyChannelOnIOThread( ChannelInfo* channel_info); -using DidDestroyChannelCallback = base::Closure; // Like |DestroyChannelOnIOThread()|, but asynchronous and may be called from -// any thread. The callback will be called using |callback_thread_task_runner| +// any thread. The callback will be called using |did_destroy_channel_runner| // if that is non-null, or otherwise it will be called on the "channel thread". // The "channel thread" must remain alive and continue to process tasks until // the callback has been executed. MOJO_SYSTEM_IMPL_EXPORT void DestroyChannel( ChannelInfo* channel_info, - const DidDestroyChannelCallback& callback, - scoped_refptr callback_thread_task_runner); + const base::Closure& did_destroy_channel_callback, + scoped_refptr did_destroy_channel_runner); // Inform the channel that it will soon be destroyed (doing so is optional). // This may be called from any thread, but the caller must ensure that this is diff --git a/third_party/mojo/src/mojo/edk/embedder/embedder_unittest.cc b/third_party/mojo/src/mojo/edk/embedder/embedder_unittest.cc index 27192dee3d300a..0d1f3d92d0ea4f 100644 --- a/third_party/mojo/src/mojo/edk/embedder/embedder_unittest.cc +++ b/third_party/mojo/src/mojo/edk/embedder/embedder_unittest.cc @@ -10,7 +10,6 @@ #include "base/command_line.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/message_loop/message_loop.h" #include "base/synchronization/waitable_event.h" #include "base/test/test_io_thread.h" @@ -22,6 +21,7 @@ #include "mojo/edk/test/scoped_ipc_support.h" #include "mojo/public/c/system/core.h" #include "mojo/public/cpp/system/handle.h" +#include "mojo/public/cpp/system/macros.h" #include "mojo/public/cpp/system/message_pipe.h" #include "testing/gtest/include/gtest/gtest.h" @@ -106,7 +106,7 @@ class ScopedTestChannel { // Valid after channel creation completion until destruction. ChannelInfo* channel_info_; - DISALLOW_COPY_AND_ASSIGN(ScopedTestChannel); + MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedTestChannel); }; class EmbedderTest : public testing::Test { @@ -127,7 +127,7 @@ class EmbedderTest : public testing::Test { base::TestIOThread test_io_thread_; - DISALLOW_COPY_AND_ASSIGN(EmbedderTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(EmbedderTest); }; TEST_F(EmbedderTest, ChannelsBasic) { @@ -198,7 +198,7 @@ class TestAsyncWaiter { mutable base::Lock wait_result_lock_; MojoResult wait_result_; - DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestAsyncWaiter); }; void WriteHello(MessagePipeHandle pipe) { @@ -301,7 +301,7 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) { char buffer[1000] = {}; uint32_t num_bytes = static_cast(sizeof(buffer)); MojoHandle handles[10] = {}; - uint32_t num_handles = arraysize(handles); + uint32_t num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(client_mp, buffer, &num_bytes, handles, &num_handles, MOJO_READ_MESSAGE_FLAG_NONE)); @@ -321,7 +321,7 @@ TEST_F(EmbedderTest, ChannelsHandlePassing) { memset(buffer, 0, sizeof(buffer)); num_bytes = static_cast(sizeof(buffer)); memset(handles, 0, sizeof(handles)); - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, MojoReadMessage(h1, buffer, &num_bytes, handles, &num_handles, MOJO_READ_MESSAGE_FLAG_NONE)); diff --git a/third_party/mojo/src/mojo/edk/embedder/master_process_delegate.h b/third_party/mojo/src/mojo/edk/embedder/master_process_delegate.h index 8f3ab3c778b31a..031f3ba7bd2fd9 100644 --- a/third_party/mojo/src/mojo/edk/embedder/master_process_delegate.h +++ b/third_party/mojo/src/mojo/edk/embedder/master_process_delegate.h @@ -5,11 +5,10 @@ #ifndef MOJO_EDK_EMBEDDER_MASTER_PROCESS_DELEGATE_H_ #define MOJO_EDK_EMBEDDER_MASTER_PROCESS_DELEGATE_H_ -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "mojo/edk/embedder/process_delegate.h" #include "mojo/edk/embedder/slave_info.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace embedder { @@ -31,7 +30,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MasterProcessDelegate : public ProcessDelegate { ~MasterProcessDelegate() override {} private: - DISALLOW_COPY_AND_ASSIGN(MasterProcessDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(MasterProcessDelegate); }; inline ProcessType MasterProcessDelegate::GetType() const { diff --git a/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h b/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h index ff8aabd2e75c20..873df04437bda0 100644 --- a/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h +++ b/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h @@ -5,12 +5,12 @@ #ifndef MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ #define MOJO_EDK_EMBEDDER_PLATFORM_CHANNEL_PAIR_H_ -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/process/launch.h" #include "build/build_config.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace base { class CommandLine; @@ -85,7 +85,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformChannelPair { ScopedPlatformHandle server_handle_; ScopedPlatformHandle client_handle_; - DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); + MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPair); }; } // namespace embedder diff --git a/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc b/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc index 107406e20e8595..897929fee13d26 100644 --- a/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc +++ b/third_party/mojo/src/mojo/edk/embedder/platform_channel_pair_posix_unittest.cc @@ -20,12 +20,12 @@ #include "base/files/scoped_file.h" #include "base/files/scoped_temp_dir.h" #include "base/logging.h" -#include "base/macros.h" #include "mojo/edk/embedder/platform_channel_utils_posix.h" #include "mojo/edk/embedder/platform_handle.h" #include "mojo/edk/embedder/platform_handle_vector.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/test/test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -59,7 +59,7 @@ class PlatformChannelPairPosixTest : public testing::Test { private: struct sigaction old_action_; - DISALLOW_COPY_AND_ASSIGN(PlatformChannelPairPosixTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPairPosixTest); }; TEST_F(PlatformChannelPairPosixTest, NoSigPipe) { diff --git a/third_party/mojo/src/mojo/edk/embedder/platform_handle.cc b/third_party/mojo/src/mojo/edk/embedder/platform_handle.cc index 467571422857d5..04d4f08e37b727 100644 --- a/third_party/mojo/src/mojo/edk/embedder/platform_handle.cc +++ b/third_party/mojo/src/mojo/edk/embedder/platform_handle.cc @@ -13,7 +13,6 @@ #error "Platform not yet supported." #endif -#include "base/compiler_specific.h" #include "base/logging.h" namespace mojo { diff --git a/third_party/mojo/src/mojo/edk/embedder/platform_shared_buffer.h b/third_party/mojo/src/mojo/edk/embedder/platform_shared_buffer.h index 07f8b90b21b39a..61b372916aeca6 100644 --- a/third_party/mojo/src/mojo/edk/embedder/platform_shared_buffer.h +++ b/third_party/mojo/src/mojo/edk/embedder/platform_shared_buffer.h @@ -7,11 +7,11 @@ #include -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace embedder { @@ -70,7 +70,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBuffer virtual ~PlatformSharedBuffer() {} private: - DISALLOW_COPY_AND_ASSIGN(PlatformSharedBuffer); + MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformSharedBuffer); }; // An interface for a mapping of a |PlatformSharedBuffer| (compararable to a @@ -93,7 +93,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedBufferMapping { PlatformSharedBufferMapping() {} private: - DISALLOW_COPY_AND_ASSIGN(PlatformSharedBufferMapping); + MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformSharedBufferMapping); }; } // namespace embedder diff --git a/third_party/mojo/src/mojo/edk/embedder/platform_support.h b/third_party/mojo/src/mojo/edk/embedder/platform_support.h index 80ee81b8afc927..02186161082252 100644 --- a/third_party/mojo/src/mojo/edk/embedder/platform_support.h +++ b/third_party/mojo/src/mojo/edk/embedder/platform_support.h @@ -7,9 +7,9 @@ #include -#include "base/macros.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace embedder { @@ -34,7 +34,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSupport { PlatformSupport() {} private: - DISALLOW_COPY_AND_ASSIGN(PlatformSupport); + MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformSupport); }; } // namespace embedder diff --git a/third_party/mojo/src/mojo/edk/embedder/process_delegate.h b/third_party/mojo/src/mojo/edk/embedder/process_delegate.h index 325c5320cd504d..5c1406ddda941d 100644 --- a/third_party/mojo/src/mojo/edk/embedder/process_delegate.h +++ b/third_party/mojo/src/mojo/edk/embedder/process_delegate.h @@ -5,9 +5,9 @@ #ifndef MOJO_EDK_EMBEDDER_PROCESS_DELEGATE_H_ #define MOJO_EDK_EMBEDDER_PROCESS_DELEGATE_H_ -#include "base/macros.h" #include "mojo/edk/embedder/process_type.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace embedder { @@ -26,7 +26,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ProcessDelegate { virtual ~ProcessDelegate() {} private: - DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(ProcessDelegate); }; inline ProcessType ProcessDelegate::GetType() const { diff --git a/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h b/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h index 0ec99b87dc128f..aec44825667f6b 100644 --- a/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h +++ b/third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h @@ -5,10 +5,10 @@ #ifndef MOJO_EDK_EMBEDDER_SCOPED_PLATFORM_HANDLE_H_ #define MOJO_EDK_EMBEDDER_SCOPED_PLATFORM_HANDLE_H_ -#include "base/compiler_specific.h" #include "base/move.h" #include "mojo/edk/embedder/platform_handle.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/c/system/macros.h" namespace mojo { namespace embedder { @@ -39,7 +39,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ScopedPlatformHandle { other.handle_ = temp; } - PlatformHandle release() WARN_UNUSED_RESULT { + PlatformHandle release() MOJO_WARN_UNUSED_RESULT { PlatformHandle rv = handle_; handle_ = PlatformHandle(); return rv; diff --git a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer.h b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer.h index b4958b958ad45a..66b0c228ab7e23 100644 --- a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer.h +++ b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer.h @@ -7,15 +7,15 @@ #include -#include "base/macros.h" #include "mojo/edk/embedder/platform_shared_buffer.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace embedder { // A simple implementation of |PlatformSharedBuffer|. -class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBuffer +class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBuffer final : public PlatformSharedBuffer { public: // Creates a shared buffer of size |num_bytes| bytes (initially zero-filled). @@ -60,7 +60,7 @@ class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBuffer // hence does not need to be protected by a lock. ScopedPlatformHandle handle_; - DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBuffer); + MOJO_DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBuffer); }; // An implementation of |PlatformSharedBufferMapping|, produced by @@ -92,7 +92,7 @@ class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSharedBufferMapping void* const real_base_; const size_t real_length_; - DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBufferMapping); + MOJO_DISALLOW_COPY_AND_ASSIGN(SimplePlatformSharedBufferMapping); }; } // namespace embedder diff --git a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_android.cc b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_android.cc index 3517db37cba3ce..60219f91af9f8f 100644 --- a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_android.cc +++ b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_android.cc @@ -5,15 +5,13 @@ #include "mojo/edk/embedder/simple_platform_shared_buffer.h" #include -#include // For |mmap()|/|munmap()|. +#include // For |PROT_...|. #include // For |off_t|. -#include #include #include "base/files/scoped_file.h" #include "base/logging.h" -#include "base/macros.h" #include "mojo/edk/embedder/platform_handle.h" #include "third_party/ashmem/ashmem.h" diff --git a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc index a3d10ef9eba4db..4bae02e26d9566 100644 --- a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc +++ b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_posix.cc @@ -17,7 +17,6 @@ #include "base/files/file_util.h" #include "base/files/scoped_file.h" #include "base/logging.h" -#include "base/macros.h" #include "base/posix/eintr_wrapper.h" #include "base/sys_info.h" #include "base/threading/thread_restrictions.h" diff --git a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_unittest.cc b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_unittest.cc index 4644b7b63f1e74..cc66c7648978b7 100644 --- a/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_unittest.cc +++ b/third_party/mojo/src/mojo/edk/embedder/simple_platform_shared_buffer_unittest.cc @@ -6,9 +6,9 @@ #include -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -151,7 +151,7 @@ TEST(SimplePlatformSharedBufferTest, MappingsDistinct) { TEST(SimplePlatformSharedBufferTest, BufferZeroInitialized) { static const size_t kSizes[] = {10, 100, 1000, 10000, 100000}; - for (size_t i = 0; i < arraysize(kSizes); i++) { + for (size_t i = 0; i < MOJO_ARRAYSIZE(kSizes); i++) { scoped_refptr buffer( SimplePlatformSharedBuffer::Create(kSizes[i])); scoped_ptr mapping(buffer->Map(0, kSizes[i])); diff --git a/third_party/mojo/src/mojo/edk/embedder/simple_platform_support.h b/third_party/mojo/src/mojo/edk/embedder/simple_platform_support.h index 9be7dc058fe3e3..f06ae081eb90cf 100644 --- a/third_party/mojo/src/mojo/edk/embedder/simple_platform_support.h +++ b/third_party/mojo/src/mojo/edk/embedder/simple_platform_support.h @@ -5,9 +5,9 @@ #ifndef MOJO_EDK_EMBEDDER_SIMPLE_PLATFORM_SUPPORT_H_ #define MOJO_EDK_EMBEDDER_SIMPLE_PLATFORM_SUPPORT_H_ -#include "base/macros.h" #include "mojo/edk/embedder/platform_support.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace embedder { @@ -17,7 +17,8 @@ namespace embedder { // has no state, and different instances of |SimplePlatformSupport| are mutually // compatible (i.e., you don't need to use a single instance of it everywhere -- // you may simply create one whenever/wherever you need it). -class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSupport : public PlatformSupport { +class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSupport final + : public PlatformSupport { public: SimplePlatformSupport() {} ~SimplePlatformSupport() override {} @@ -29,7 +30,7 @@ class MOJO_SYSTEM_IMPL_EXPORT SimplePlatformSupport : public PlatformSupport { ScopedPlatformHandle platform_handle) override; private: - DISALLOW_COPY_AND_ASSIGN(SimplePlatformSupport); + MOJO_DISALLOW_COPY_AND_ASSIGN(SimplePlatformSupport); }; } // namespace embedder diff --git a/third_party/mojo/src/mojo/edk/embedder/slave_process_delegate.h b/third_party/mojo/src/mojo/edk/embedder/slave_process_delegate.h index d9592154161b66..cef5e0d3932679 100644 --- a/third_party/mojo/src/mojo/edk/embedder/slave_process_delegate.h +++ b/third_party/mojo/src/mojo/edk/embedder/slave_process_delegate.h @@ -5,10 +5,9 @@ #ifndef MOJO_EDK_EMBEDDER_SLAVE_PROCESS_DELEGATE_H_ #define MOJO_EDK_EMBEDDER_SLAVE_PROCESS_DELEGATE_H_ -#include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "mojo/edk/embedder/process_delegate.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace embedder { @@ -30,7 +29,7 @@ class MOJO_SYSTEM_IMPL_EXPORT SlaveProcessDelegate : public ProcessDelegate { ~SlaveProcessDelegate() override {} private: - DISALLOW_COPY_AND_ASSIGN(SlaveProcessDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(SlaveProcessDelegate); }; inline ProcessType SlaveProcessDelegate::GetType() const { diff --git a/third_party/mojo/src/mojo/edk/embedder/test_embedder.cc b/third_party/mojo/src/mojo/edk/embedder/test_embedder.cc index 36f1a5a78b2432..d7c0d40df6f82b 100644 --- a/third_party/mojo/src/mojo/edk/embedder/test_embedder.cc +++ b/third_party/mojo/src/mojo/edk/embedder/test_embedder.cc @@ -5,7 +5,6 @@ #include "mojo/edk/embedder/test_embedder.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/embedder/embedder.h" #include "mojo/edk/embedder/embedder_internal.h" diff --git a/third_party/mojo/src/mojo/edk/js/test/BUILD.gn b/third_party/mojo/src/mojo/edk/js/test/BUILD.gn index 326de6aa7e7a43..d5439121b39bb2 100644 --- a/third_party/mojo/src/mojo/edk/js/test/BUILD.gn +++ b/third_party/mojo/src/mojo/edk/js/test/BUILD.gn @@ -14,6 +14,7 @@ test("js_unittests") { "../../../public/cpp/system", "../../../public/cpp/utility", "../../../public/interfaces/bindings/tests:test_interfaces", + "../../../public/interfaces/bindings/tests:test_interfaces_experimental", "//base", "//gin:gin_test", "//mojo/environment:chromium", diff --git a/third_party/mojo/src/mojo/edk/js/test/run_js_tests.cc b/third_party/mojo/src/mojo/edk/js/test/run_js_tests.cc index b574902f69b4d8..b1155072f2b3a2 100644 --- a/third_party/mojo/src/mojo/edk/js/test/run_js_tests.cc +++ b/third_party/mojo/src/mojo/edk/js/test/run_js_tests.cc @@ -53,6 +53,10 @@ TEST(JSTest, struct) { RunTest("struct_unittests.js", true); } +TEST(JSTest, union) { + RunTest("union_unittests.js", true); +} + TEST(JSTest, validation) { RunTest("validation_unittests.js", true); } diff --git a/third_party/mojo/src/mojo/edk/js/tests/BUILD.gn b/third_party/mojo/src/mojo/edk/js/tests/BUILD.gn index c9711c768714a4..0d9b3be00b4a08 100644 --- a/third_party/mojo/src/mojo/edk/js/tests/BUILD.gn +++ b/third_party/mojo/src/mojo/edk/js/tests/BUILD.gn @@ -22,6 +22,7 @@ mojo_edk_source_set("js_to_cpp_tests") { "mojo/public/cpp/bindings", "mojo/public/cpp/system", "mojo/public/interfaces/bindings/tests:test_interfaces", + "mojo/public/interfaces/bindings/tests:test_interfaces_experimental", ] sources = [ diff --git a/third_party/mojo/src/mojo/edk/mojo_edk.gni b/third_party/mojo/src/mojo/edk/mojo_edk.gni index 1d1d992d420043..b90462de81bef8 100644 --- a/third_party/mojo/src/mojo/edk/mojo_edk.gni +++ b/third_party/mojo/src/mojo/edk/mojo_edk.gni @@ -18,7 +18,9 @@ import("../public/mojo_sdk.gni") # writing targets. template("mojo_edk_source_set") { mojo_sdk_source_set(target_name) { - restrict_external_deps = false + if (defined(invoker.public_deps) || defined(invoker.deps)) { + restrict_external_deps = false + } if (defined(invoker.visibility)) { visibility = invoker.visibility diff --git a/third_party/mojo/src/mojo/edk/system/BUILD.gn b/third_party/mojo/src/mojo/edk/system/BUILD.gn index f0ad7c48247f39..95ee992e1484fb 100644 --- a/third_party/mojo/src/mojo/edk/system/BUILD.gn +++ b/third_party/mojo/src/mojo/edk/system/BUILD.gn @@ -123,6 +123,7 @@ component("system") { "../embedder:delegates", "../embedder:platform", "../../public/c/system", + "../../public/cpp/system", ] deps = [ @@ -149,10 +150,14 @@ mojo_edk_source_set("test_utils") { "test_utils.h", ] + mojo_sdk_public_deps = [ + "mojo/public/c/system", + "mojo/public/cpp/system", + ] + deps = [ "//base", "//base/test:test_support", - "../../public/c/system", ] } diff --git a/third_party/mojo/src/mojo/edk/system/async_waiter.h b/third_party/mojo/src/mojo/edk/system/async_waiter.h index be228e5baa4aed..2c4d7701546020 100644 --- a/third_party/mojo/src/mojo/edk/system/async_waiter.h +++ b/third_party/mojo/src/mojo/edk/system/async_waiter.h @@ -6,10 +6,10 @@ #define MOJO_EDK_SYSTEM_ASYNC_WAITER_H_ #include "base/callback.h" -#include "base/macros.h" #include "mojo/edk/system/awakable.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -29,7 +29,7 @@ class MOJO_SYSTEM_IMPL_EXPORT AsyncWaiter final : public Awakable { AwakeCallback callback_; - DISALLOW_COPY_AND_ASSIGN(AsyncWaiter); + MOJO_DISALLOW_COPY_AND_ASSIGN(AsyncWaiter); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/awakable_list.h b/third_party/mojo/src/mojo/edk/system/awakable_list.h index 2c307f4b42a765..a34a4820887a9f 100644 --- a/third_party/mojo/src/mojo/edk/system/awakable_list.h +++ b/third_party/mojo/src/mojo/edk/system/awakable_list.h @@ -9,9 +9,9 @@ #include -#include "base/macros.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -49,7 +49,7 @@ class MOJO_SYSTEM_IMPL_EXPORT AwakableList { AwakeInfoList awakables_; - DISALLOW_COPY_AND_ASSIGN(AwakableList); + MOJO_DISALLOW_COPY_AND_ASSIGN(AwakableList); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/awakable_list_unittest.cc b/third_party/mojo/src/mojo/edk/system/awakable_list_unittest.cc index 0ef6a7a0a09f3e..728dbc33ee12cb 100644 --- a/third_party/mojo/src/mojo/edk/system/awakable_list_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/awakable_list_unittest.cc @@ -3,14 +3,12 @@ // found in the LICENSE file. // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a -// heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to +// heavily-loaded system). Sorry. |test::EpsilonDeadline()| may be increased to // increase tolerance and reduce observed flakiness (though doing so reduces the // meaningfulness of the test). #include "mojo/edk/system/awakable_list.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. -#include "base/time/time.h" #include "mojo/edk/system/handle_signals_state.h" #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" @@ -55,7 +53,7 @@ TEST(AwakableListTest, BasicCancel) { test::SimpleWaiterThread thread(&result, &context); awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); awakable_list.CancelAll(); } // Join |thread|. EXPECT_EQ(MOJO_RESULT_CANCELLED, result); @@ -102,7 +100,7 @@ TEST(AwakableListTest, BasicAwakeSatisfied) { test::SimpleWaiterThread thread(&result, &context); awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); awakable_list.AwakeForStateChange(HandleSignalsState( MOJO_HANDLE_SIGNAL_READABLE, MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); @@ -148,7 +146,7 @@ TEST(AwakableListTest, BasicAwakeUnsatisfiable) { test::SimpleWaiterThread thread(&result, &context); awakable_list.Add(thread.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 3); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); awakable_list.AwakeForStateChange(HandleSignalsState( MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_WRITABLE)); awakable_list.Remove(thread.waiter()); @@ -178,7 +176,7 @@ TEST(AwakableListTest, MultipleAwakables) { test::SimpleWaiterThread thread2(&result2, &context2); awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 2); thread2.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); awakable_list.CancelAll(); } // Join threads. EXPECT_EQ(MOJO_RESULT_CANCELLED, result1); @@ -195,7 +193,7 @@ TEST(AwakableListTest, MultipleAwakables) { test::SimpleWaiterThread thread2(&result2, &context2); awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 4); thread2.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); awakable_list.AwakeForStateChange(HandleSignalsState( MOJO_HANDLE_SIGNAL_READABLE, MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); @@ -216,7 +214,7 @@ TEST(AwakableListTest, MultipleAwakables) { test::SimpleWaiterThread thread2(&result2, &context2); awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 6); thread2.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); awakable_list.AwakeForStateChange(HandleSignalsState( MOJO_HANDLE_SIGNAL_NONE, MOJO_HANDLE_SIGNAL_READABLE)); awakable_list.Remove(thread2.waiter()); @@ -234,7 +232,7 @@ TEST(AwakableListTest, MultipleAwakables) { awakable_list.Add(thread1.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 7); thread1.Start(); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); // Should do nothing. awakable_list.AwakeForStateChange(HandleSignalsState( @@ -245,7 +243,7 @@ TEST(AwakableListTest, MultipleAwakables) { awakable_list.Add(thread2.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 8); thread2.Start(); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); // Awake #1. awakable_list.AwakeForStateChange(HandleSignalsState( @@ -253,7 +251,7 @@ TEST(AwakableListTest, MultipleAwakables) { MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE)); awakable_list.Remove(thread1.waiter()); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); test::SimpleWaiterThread thread3(&result3, &context3); awakable_list.Add(thread3.waiter(), MOJO_HANDLE_SIGNAL_WRITABLE, 9); @@ -263,7 +261,7 @@ TEST(AwakableListTest, MultipleAwakables) { awakable_list.Add(thread4.waiter(), MOJO_HANDLE_SIGNAL_READABLE, 10); thread4.Start(); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); // Awake #2 and #3 for unsatisfiability. awakable_list.AwakeForStateChange(HandleSignalsState( @@ -295,7 +293,7 @@ class KeepAwakable : public Awakable { int awake_count; - DISALLOW_COPY_AND_ASSIGN(KeepAwakable); + MOJO_DISALLOW_COPY_AND_ASSIGN(KeepAwakable); }; class RemoveAwakable : public Awakable { @@ -309,7 +307,7 @@ class RemoveAwakable : public Awakable { int awake_count; - DISALLOW_COPY_AND_ASSIGN(RemoveAwakable); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoveAwakable); }; TEST(AwakableListTest, KeepAwakablesReturningTrue) { diff --git a/third_party/mojo/src/mojo/edk/system/channel.cc b/third_party/mojo/src/mojo/edk/system/channel.cc index 0eab8ccd9b7682..470956f780e879 100644 --- a/third_party/mojo/src/mojo/edk/system/channel.cc +++ b/third_party/mojo/src/mojo/edk/system/channel.cc @@ -8,7 +8,6 @@ #include "base/bind.h" #include "base/logging.h" -#include "base/macros.h" #include "base/strings/stringprintf.h" #include "mojo/edk/embedder/platform_handle_vector.h" #include "mojo/edk/system/endpoint_relayer.h" @@ -176,10 +175,10 @@ void Channel::DetachEndpoint(ChannelEndpoint* endpoint, if (!SendControlMessage(MessageInTransit::Subtype::CHANNEL_REMOVE_ENDPOINT, local_id, remote_id)) { HandleLocalError(base::StringPrintf( - "Failed to send message to remove remote endpoint (local ID %u, remote " - "ID %u)", - static_cast(local_id.value()), - static_cast(remote_id.value()))); + "Failed to send message to remove remote endpoint " + "(local ID %u, remote ID %u)", + static_cast(local_id.value()), + static_cast(remote_id.value())).c_str()); } } @@ -289,7 +288,8 @@ void Channel::OnReadMessage( default: HandleRemoteError( base::StringPrintf("Received message of invalid type %u", - static_cast(message_view.type()))); + static_cast(message_view.type())) + .c_str()); break; } } @@ -362,9 +362,10 @@ void Channel::OnReadMessageForEndpoint( } } if (!endpoint) { - HandleRemoteError(base::StringPrintf( - "Received a message for nonexistent local destination ID %u", - static_cast(local_id.value()))); + HandleRemoteError( + base::StringPrintf( + "Received a message for nonexistent local destination ID %u", + static_cast(local_id.value())).c_str()); // This is strongly indicative of some problem. However, it's not a fatal // error, since it may indicate a buggy (or hostile) remote process. Don't // die even for Debug builds, since handling this properly needs to be @@ -513,10 +514,10 @@ bool Channel::OnRemoveEndpoint(ChannelEndpointId local_id, MessageInTransit::Subtype::CHANNEL_REMOVE_ENDPOINT_ACK, local_id, remote_id)) { HandleLocalError(base::StringPrintf( - "Failed to send message to ack remove remote endpoint (local ID %u, " - "remote ID %u)", - static_cast(local_id.value()), - static_cast(remote_id.value()))); + "Failed to send message to ack remove remote endpoint " + "(local ID %u, remote ID %u)", + static_cast(local_id.value()), + static_cast(remote_id.value())).c_str()); } return true; @@ -542,13 +543,13 @@ bool Channel::OnRemoveEndpointAck(ChannelEndpointId local_id) { return true; } -void Channel::HandleRemoteError(const base::StringPiece& error_message) { +void Channel::HandleRemoteError(const char* error_message) { // TODO(vtl): Is this how we really want to handle this? Probably we want to // terminate the connection, since it's spewing invalid stuff. LOG(WARNING) << error_message; } -void Channel::HandleLocalError(const base::StringPiece& error_message) { +void Channel::HandleLocalError(const char* error_message) { // TODO(vtl): Is this how we really want to handle this? // Sometimes we'll want to propagate the error back to the message pipe // (endpoint), and notify it that the remote is (effectively) closed. @@ -588,10 +589,10 @@ ChannelEndpointId Channel::AttachAndRunEndpoint( MessageInTransit::Subtype::CHANNEL_ATTACH_AND_RUN_ENDPOINT, local_id, remote_id)) { HandleLocalError(base::StringPrintf( - "Failed to send message to run remote endpoint (local ID %u, remote ID " - "%u)", - static_cast(local_id.value()), - static_cast(remote_id.value()))); + "Failed to send message to run remote endpoint (local " + "ID %u, remote ID %u)", + static_cast(local_id.value()), + static_cast(remote_id.value())).c_str()); // TODO(vtl): Should we continue on to |AttachAndRun()|? } diff --git a/third_party/mojo/src/mojo/edk/system/channel.h b/third_party/mojo/src/mojo/edk/system/channel.h index d39676a2afb0e0..015fa737409326 100644 --- a/third_party/mojo/src/mojo/edk/system/channel.h +++ b/third_party/mojo/src/mojo/edk/system/channel.h @@ -8,10 +8,8 @@ #include #include "base/containers/hash_tables.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" -#include "base/strings/string_piece.h" #include "base/synchronization/lock.h" #include "base/threading/thread_checker.h" #include "mojo/edk/embedder/scoped_platform_handle.h" @@ -22,6 +20,7 @@ #include "mojo/edk/system/raw_channel.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { @@ -50,7 +49,7 @@ class MessageInTransitQueue; // |ChannelEndpointClient| (e.g., |MessagePipe|), |ChannelEndpoint|, |Channel|. // Thus |Channel| may not call into |ChannelEndpoint| with |Channel|'s lock // held. -class MOJO_SYSTEM_IMPL_EXPORT Channel +class MOJO_SYSTEM_IMPL_EXPORT Channel final : public base::RefCountedThreadSafe, public RawChannel::Delegate { public: @@ -205,10 +204,10 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel // Handles errors (e.g., invalid messages) from the remote side. Callable from // any thread. - void HandleRemoteError(const base::StringPiece& error_message); + void HandleRemoteError(const char* error_message); // Handles internal errors/failures from the local side. Callable from any // thread. - void HandleLocalError(const base::StringPiece& error_message); + void HandleLocalError(const char* error_message); // Helper for |SerializeEndpoint...()|: Attaches the given (non-bootstrap) // endpoint to this channel and runs it. This assigns the endpoint both local @@ -263,7 +262,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel // if/when we wrap). RemoteChannelEndpointIdGenerator remote_id_generator_; - DISALLOW_COPY_AND_ASSIGN(Channel); + MOJO_DISALLOW_COPY_AND_ASSIGN(Channel); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/channel_endpoint.cc b/third_party/mojo/src/mojo/edk/system/channel_endpoint.cc index 30974c5f3976f0..113bbd58f5d9ec 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_endpoint.cc +++ b/third_party/mojo/src/mojo/edk/system/channel_endpoint.cc @@ -8,6 +8,7 @@ #include "base/threading/platform_thread.h" #include "mojo/edk/system/channel.h" #include "mojo/edk/system/channel_endpoint_client.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -17,8 +18,8 @@ ChannelEndpoint::ChannelEndpoint(ChannelEndpointClient* client, MessageInTransitQueue* message_queue) : client_(client), client_port_(client_port), - channel_(nullptr), - is_detached_from_channel_(false) { + channel_state_(ChannelState::NOT_YET_ATTACHED), + channel_(nullptr) { DCHECK(client_ || message_queue); if (message_queue) @@ -30,17 +31,22 @@ bool ChannelEndpoint::EnqueueMessage(scoped_ptr message) { base::AutoLock locker(lock_); - if (!channel_) { - // We may reach here if we haven't been attached/run yet. - // TODO(vtl): We may also reach here if the channel is shut down early for - // some reason (with live message pipes on it). Ideally, we'd return false - // (and not enqueue the message), but we currently don't have a way to check - // this. - channel_message_queue_.AddMessage(message.Pass()); - return true; + switch (channel_state_) { + case ChannelState::NOT_YET_ATTACHED: + case ChannelState::DETACHED: + // We may reach here if we haven't been attached/run yet. + // TODO(vtl): We may also reach here if the channel is shut down early for + // some reason (with live message pipes on it). Ideally, we'd return false + // (and not enqueue the message), but we currently don't have a way to + // check this. + channel_message_queue_.AddMessage(message.Pass()); + return true; + case ChannelState::ATTACHED: + return WriteMessageNoLock(message.Pass()); } - return WriteMessageNoLock(message.Pass()); + NOTREACHED(); + return false; } bool ChannelEndpoint::ReplaceClient(ChannelEndpointClient* client, @@ -52,7 +58,7 @@ bool ChannelEndpoint::ReplaceClient(ChannelEndpointClient* client, DCHECK(client != client_.get() || client_port != client_port_); client_ = client; client_port_ = client_port; - return !is_detached_from_channel_; + return channel_state_ != ChannelState::DETACHED; } void ChannelEndpoint::DetachFromClient() { @@ -74,9 +80,11 @@ void ChannelEndpoint::AttachAndRun(Channel* channel, DCHECK(remote_id.is_valid()); base::AutoLock locker(lock_); + DCHECK(channel_state_ == ChannelState::NOT_YET_ATTACHED); DCHECK(!channel_); DCHECK(!local_id_.is_valid()); DCHECK(!remote_id_.is_valid()); + channel_state_ = ChannelState::ATTACHED; channel_ = channel; local_id_ = local_id; remote_id_ = remote_id; @@ -125,12 +133,12 @@ void ChannelEndpoint::DetachFromChannel() { if (channel_) ResetChannelNoLock(); else - DCHECK(is_detached_from_channel_); + DCHECK(channel_state_ == ChannelState::DETACHED); } // If |ReplaceClient()| is called (from another thread) after the above locked // section but before we call |OnDetachFromChannel()|, |ReplaceClient()| - // return false to notify the caller that the channel was already detached. + // returns false to notify the caller that the channel was already detached. // (The old client has to accept the arguably-spurious call to // |OnDetachFromChannel()|.) if (client) @@ -205,15 +213,15 @@ void ChannelEndpoint::OnReadMessageForClient( } void ChannelEndpoint::ResetChannelNoLock() { + DCHECK(channel_state_ == ChannelState::ATTACHED); DCHECK(channel_); DCHECK(local_id_.is_valid()); DCHECK(remote_id_.is_valid()); - DCHECK(!is_detached_from_channel_); + channel_state_ = ChannelState::DETACHED; channel_ = nullptr; local_id_ = ChannelEndpointId(); remote_id_ = ChannelEndpointId(); - is_detached_from_channel_ = true; } } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/channel_endpoint.h b/third_party/mojo/src/mojo/edk/system/channel_endpoint.h index 38245c47dd08ad..807b1a8b3c9660 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_endpoint.h +++ b/third_party/mojo/src/mojo/edk/system/channel_endpoint.h @@ -5,13 +5,13 @@ #ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_H_ #define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "mojo/edk/system/channel_endpoint_id.h" #include "mojo/edk/system/message_in_transit_queue.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -108,7 +108,7 @@ class MessageInTransit; // simultaneously, and both sides send "remove" messages). In that // case, it must still remain alive until it receives the "remove // ack" (and it must ack the "remove" message that it received). -class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpoint +class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpoint final : public base::RefCountedThreadSafe { public: // Constructor for a |ChannelEndpoint| with the given client (specified by @@ -168,8 +168,9 @@ class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpoint // Helper for |OnReadMessage()|, handling messages for the client. void OnReadMessageForClient(scoped_ptr message); - // Resets |channel_| to null (and sets |is_detached_from_channel_|). This may - // only be called if |channel_| is non-null. Must be called with |lock_| held. + // Resets |channel_| to null (and sets |channel_state_| to + // |ChannelState::DETACHED|). This may only be called if |channel_| is + // non-null. Must be called with |lock_| held. void ResetChannelNoLock(); // Protects the members below. @@ -190,21 +191,29 @@ class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpoint scoped_refptr client_; unsigned client_port_; + // State with respect to interaction with the |Channel|. + enum class ChannelState { + // |AttachAndRun()| has not been called yet (|channel_| is null). + NOT_YET_ATTACHED, + // |AttachAndRun()| has been called, but not |DetachFromChannel()| + // (|channel_| is non-null and valid). + ATTACHED, + // |DetachFromChannel()| has been called (|channel_| is null). + DETACHED + }; + ChannelState channel_state_; // |channel_| must be valid whenever it is non-null. Before |*channel_| gives // up its reference to this object, it must call |DetachFromChannel()|. // |local_id_| and |remote_id_| are valid if and only |channel_| is non-null. Channel* channel_; ChannelEndpointId local_id_; ChannelEndpointId remote_id_; - // This distinguishes the two cases of |channel| being null: not yet attached - // versus detached. - bool is_detached_from_channel_; // This queue is used before we're running on a channel and ready to send // messages to the channel. MessageInTransitQueue channel_message_queue_; - DISALLOW_COPY_AND_ASSIGN(ChannelEndpoint); + MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelEndpoint); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/channel_endpoint_client.h b/third_party/mojo/src/mojo/edk/system/channel_endpoint_client.h index c758e9c5485e45..98f6761ce351b8 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_endpoint_client.h +++ b/third_party/mojo/src/mojo/edk/system/channel_endpoint_client.h @@ -5,10 +5,10 @@ #ifndef MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_ #define MOJO_EDK_SYSTEM_CHANNEL_ENDPOINT_CLIENT_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -54,7 +54,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ChannelEndpointClient friend class base::RefCountedThreadSafe; private: - DISALLOW_COPY_AND_ASSIGN(ChannelEndpointClient); + MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelEndpointClient); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.cc b/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.cc index ed00f6ade515cb..9a13837fd04b8c 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.cc +++ b/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.cc @@ -4,12 +4,11 @@ #include "mojo/edk/system/channel_endpoint_id.h" -#include "base/compiler_specific.h" - namespace mojo { namespace system { -STATIC_CONST_MEMBER_DEFINITION const uint32_t ChannelEndpointId::kRemoteFlag; +MOJO_STATIC_CONST_MEMBER_DEFINITION const uint32_t + ChannelEndpointId::kRemoteFlag; ChannelEndpointId LocalChannelEndpointIdGenerator::GetNext() { ChannelEndpointId rv = next_; diff --git a/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.h b/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.h index afacb4e18cbe08..3cb2fd11888a73 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.h +++ b/third_party/mojo/src/mojo/edk/system/channel_endpoint_id.h @@ -12,8 +12,8 @@ #include "base/containers/hash_tables.h" #include "base/gtest_prod_util.h" -#include "base/macros.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -104,7 +104,7 @@ class MOJO_SYSTEM_IMPL_EXPORT LocalChannelEndpointIdGenerator { ChannelEndpointId next_; - DISALLOW_COPY_AND_ASSIGN(LocalChannelEndpointIdGenerator); + MOJO_DISALLOW_COPY_AND_ASSIGN(LocalChannelEndpointIdGenerator); }; // RemoteChannelEndpointIdGenerator -------------------------------------------- @@ -124,7 +124,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RemoteChannelEndpointIdGenerator { ChannelEndpointId next_; - DISALLOW_COPY_AND_ASSIGN(RemoteChannelEndpointIdGenerator); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteChannelEndpointIdGenerator); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/channel_endpoint_unittest.cc b/third_party/mojo/src/mojo/edk/system/channel_endpoint_unittest.cc index 78ba4899854ee1..e0bf9f15424b88 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_endpoint_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/channel_endpoint_unittest.cc @@ -4,13 +4,13 @@ #include "mojo/edk/system/channel_endpoint.h" -#include "base/macros.h" #include "base/synchronization/waitable_event.h" #include "base/test/test_timeouts.h" #include "mojo/edk/system/channel_test_base.h" #include "mojo/edk/system/message_in_transit_queue.h" #include "mojo/edk/system/message_in_transit_test_utils.h" #include "mojo/edk/system/test_channel_endpoint_client.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -40,7 +40,7 @@ class ChannelEndpointTest : public test::ChannelTestBase { } private: - DISALLOW_COPY_AND_ASSIGN(ChannelEndpointTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelEndpointTest); }; TEST_F(ChannelEndpointTest, Basic) { diff --git a/third_party/mojo/src/mojo/edk/system/channel_manager.h b/third_party/mojo/src/mojo/edk/system/channel_manager.h index 92185eb8ea9953..9a9c0e8501f3b5 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_manager.h +++ b/third_party/mojo/src/mojo/edk/system/channel_manager.h @@ -9,11 +9,11 @@ #include "base/callback_forward.h" #include "base/containers/hash_tables.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/system/channel_id.h" +#include "mojo/public/cpp/system/macros.h" namespace base { class TaskRunner; @@ -142,7 +142,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ChannelManager { base::hash_map>; ChannelIdToChannelMap channels_; - DISALLOW_COPY_AND_ASSIGN(ChannelManager); + MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManager); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/channel_manager_unittest.cc b/third_party/mojo/src/mojo/edk/system/channel_manager_unittest.cc index 12ca4b6fd114f1..afa9b15b79764c 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_manager_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/channel_manager_unittest.cc @@ -5,7 +5,6 @@ #include "mojo/edk/system/channel_manager.h" #include "base/callback.h" -#include "base/macros.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/task_runner.h" @@ -16,6 +15,7 @@ #include "mojo/edk/system/channel.h" #include "mojo/edk/system/channel_endpoint.h" #include "mojo/edk/system/message_pipe_dispatcher.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -41,7 +41,7 @@ class ChannelManagerTest : public testing::Test { // before it (and should outlive it). ChannelManager channel_manager_; - DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest); }; TEST_F(ChannelManagerTest, Basic) { @@ -147,7 +147,7 @@ class OtherThread : public base::SimpleThread { ChannelId channel_id_; base::Closure quit_closure_; - DISALLOW_COPY_AND_ASSIGN(OtherThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(OtherThread); }; TEST_F(ChannelManagerTest, CallsFromOtherThread) { diff --git a/third_party/mojo/src/mojo/edk/system/channel_test_base.h b/third_party/mojo/src/mojo/edk/system/channel_test_base.h index 81ef27f09f0f97..a177418b764259 100644 --- a/third_party/mojo/src/mojo/edk/system/channel_test_base.h +++ b/third_party/mojo/src/mojo/edk/system/channel_test_base.h @@ -7,12 +7,12 @@ #include "base/bind.h" #include "base/location.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/test/test_io_thread.h" #include "mojo/edk/embedder/simple_platform_support.h" #include "mojo/edk/system/channel.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -56,7 +56,7 @@ class ChannelTestBase : public testing::Test { scoped_ptr raw_channels_[2]; scoped_refptr channels_[2]; - DISALLOW_COPY_AND_ASSIGN(ChannelTestBase); + MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelTestBase); }; } // namespace test diff --git a/third_party/mojo/src/mojo/edk/system/connection_manager.h b/third_party/mojo/src/mojo/edk/system/connection_manager.h index e5e8c933e6e709..c92a121aab7560 100644 --- a/third_party/mojo/src/mojo/edk/system/connection_manager.h +++ b/third_party/mojo/src/mojo/edk/system/connection_manager.h @@ -5,10 +5,10 @@ #ifndef MOJO_EDK_SYSTEM_CONNECTION_MANAGER_H_ #define MOJO_EDK_SYSTEM_CONNECTION_MANAGER_H_ -#include "base/macros.h" #include "mojo/edk/system/connection_identifier.h" #include "mojo/edk/system/process_identifier.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { @@ -103,7 +103,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ConnectionManager { private: embedder::PlatformSupport* const platform_support_; - DISALLOW_COPY_AND_ASSIGN(ConnectionManager); + MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionManager); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc b/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc index ba4af9c21bcf61..cb22ef3401e20c 100644 --- a/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc @@ -11,7 +11,6 @@ #include -#include "base/macros.h" #include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/threading/thread_checker.h" @@ -22,6 +21,7 @@ #include "mojo/edk/system/master_connection_manager.h" #include "mojo/edk/system/slave_connection_manager.h" #include "mojo/edk/test/test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -75,7 +75,7 @@ class TestSlaveInfo { base::ThreadChecker thread_checker_; std::string name_; - DISALLOW_COPY_AND_ASSIGN(TestSlaveInfo); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestSlaveInfo); }; // Connects the given |slave| (with the given |slave_process_delegate|) to the @@ -138,7 +138,7 @@ class MockMasterProcessDelegate : public embedder::MasterProcessDelegate { unsigned on_slave_disconnect_calls_; std::string last_slave_disconnect_name_; - DISALLOW_COPY_AND_ASSIGN(MockMasterProcessDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(MockMasterProcessDelegate); }; class MockSlaveProcessDelegate : public embedder::SlaveProcessDelegate { @@ -177,7 +177,7 @@ class MockSlaveProcessDelegate : public embedder::SlaveProcessDelegate { unsigned on_master_disconnect_calls_; - DISALLOW_COPY_AND_ASSIGN(MockSlaveProcessDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(MockSlaveProcessDelegate); }; class ConnectionManagerTest : public testing::Test { @@ -197,7 +197,7 @@ class ConnectionManagerTest : public testing::Test { base::MessageLoop message_loop_; MockMasterProcessDelegate master_process_delegate_; - DISALLOW_COPY_AND_ASSIGN(ConnectionManagerTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionManagerTest); }; TEST_F(ConnectionManagerTest, BasicConnectSlaves) { diff --git a/third_party/mojo/src/mojo/edk/system/core.cc b/third_party/mojo/src/mojo/edk/system/core.cc index 887a9a7fdc32e1..35d6614a084c78 100644 --- a/third_party/mojo/src/mojo/edk/system/core.cc +++ b/third_party/mojo/src/mojo/edk/system/core.cc @@ -23,6 +23,7 @@ #include "mojo/edk/system/shared_buffer_dispatcher.h" #include "mojo/edk/system/waiter.h" #include "mojo/public/c/system/macros.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -203,10 +204,10 @@ MojoResult Core::CreateMessagePipe( if (result != MOJO_RESULT_OK) return result; - scoped_refptr dispatcher0( - new MessagePipeDispatcher(validated_options)); - scoped_refptr dispatcher1( - new MessagePipeDispatcher(validated_options)); + scoped_refptr dispatcher0 = + MessagePipeDispatcher::Create(validated_options); + scoped_refptr dispatcher1 = + MessagePipeDispatcher::Create(validated_options); std::pair handle_pair; { @@ -369,10 +370,10 @@ MojoResult Core::CreateDataPipe( if (result != MOJO_RESULT_OK) return result; - scoped_refptr producer_dispatcher( - new DataPipeProducerDispatcher()); - scoped_refptr consumer_dispatcher( - new DataPipeConsumerDispatcher()); + scoped_refptr producer_dispatcher = + DataPipeProducerDispatcher::Create(); + scoped_refptr consumer_dispatcher = + DataPipeConsumerDispatcher::Create(); std::pair handle_pair; { diff --git a/third_party/mojo/src/mojo/edk/system/core.h b/third_party/mojo/src/mojo/edk/system/core.h index 0c38008d7432fc..407a06488c8cab 100644 --- a/third_party/mojo/src/mojo/edk/system/core.h +++ b/third_party/mojo/src/mojo/edk/system/core.h @@ -8,7 +8,6 @@ #include #include "base/callback.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" @@ -20,6 +19,7 @@ #include "mojo/public/c/system/data_pipe.h" #include "mojo/public/c/system/message_pipe.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { @@ -183,7 +183,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Core { base::Lock mapping_table_lock_; // Protects |mapping_table_|. MappingTable mapping_table_; - DISALLOW_COPY_AND_ASSIGN(Core); + MOJO_DISALLOW_COPY_AND_ASSIGN(Core); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/core_test_base.cc b/third_party/mojo/src/mojo/edk/system/core_test_base.cc index 0e5836321616ff..bfdcb1bcc39e26 100644 --- a/third_party/mojo/src/mojo/edk/system/core_test_base.cc +++ b/third_party/mojo/src/mojo/edk/system/core_test_base.cc @@ -6,13 +6,13 @@ #include -#include "base/compiler_specific.h" #include "base/logging.h" #include "base/memory/ref_counted.h" #include "mojo/edk/system/configuration.h" #include "mojo/edk/system/core.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/memory.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -24,15 +24,20 @@ namespace { class MockDispatcher : public Dispatcher { public: - explicit MockDispatcher(CoreTestBase::MockHandleInfo* info) : info_(info) { - CHECK(info_); - info_->IncrementCtorCallCount(); + static scoped_refptr Create( + CoreTestBase::MockHandleInfo* info) { + return make_scoped_refptr(new MockDispatcher(info)); } // |Dispatcher| private methods: Type GetType() const override { return Type::UNKNOWN; } private: + explicit MockDispatcher(CoreTestBase::MockHandleInfo* info) : info_(info) { + CHECK(info_); + info_->IncrementCtorCallCount(); + } + ~MockDispatcher() override { info_->IncrementDtorCallCount(); } // |Dispatcher| protected methods: @@ -153,12 +158,12 @@ class MockDispatcher : public Dispatcher { scoped_refptr CreateEquivalentDispatcherAndCloseImplNoLock() override { - return scoped_refptr(new MockDispatcher(info_)); + return Create(info_); } CoreTestBase::MockHandleInfo* const info_; - DISALLOW_COPY_AND_ASSIGN(MockDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(MockDispatcher); }; } // namespace @@ -182,7 +187,7 @@ void CoreTestBase::TearDown() { MojoHandle CoreTestBase::CreateMockHandle(CoreTestBase::MockHandleInfo* info) { CHECK(core_); - scoped_refptr dispatcher(new MockDispatcher(info)); + scoped_refptr dispatcher = MockDispatcher::Create(info); return core_->AddDispatcher(dispatcher); } diff --git a/third_party/mojo/src/mojo/edk/system/core_test_base.h b/third_party/mojo/src/mojo/edk/system/core_test_base.h index 3eb23642dcc7d6..ce329187087827 100644 --- a/third_party/mojo/src/mojo/edk/system/core_test_base.h +++ b/third_party/mojo/src/mojo/edk/system/core_test_base.h @@ -5,10 +5,10 @@ #ifndef MOJO_EDK_SYSTEM_CORE_TEST_BASE_H_ #define MOJO_EDK_SYSTEM_CORE_TEST_BASE_H_ -#include "base/macros.h" #include "base/synchronization/lock.h" #include "mojo/edk/embedder/simple_platform_support.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -41,7 +41,7 @@ class CoreTestBase : public testing::Test { embedder::SimplePlatformSupport platform_support_; Core* core_; - DISALLOW_COPY_AND_ASSIGN(CoreTestBase); + MOJO_DISALLOW_COPY_AND_ASSIGN(CoreTestBase); }; class CoreTestBase_MockHandleInfo { @@ -107,7 +107,7 @@ class CoreTestBase_MockHandleInfo { bool add_awakable_allowed_; std::vector added_awakables_; - DISALLOW_COPY_AND_ASSIGN(CoreTestBase_MockHandleInfo); + MOJO_DISALLOW_COPY_AND_ASSIGN(CoreTestBase_MockHandleInfo); }; } // namespace test diff --git a/third_party/mojo/src/mojo/edk/system/core_unittest.cc b/third_party/mojo/src/mojo/edk/system/core_unittest.cc index c562097d262478..0ef0aa1260922a 100644 --- a/third_party/mojo/src/mojo/edk/system/core_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/core_unittest.cc @@ -9,10 +9,10 @@ #include #include "base/bind.h" -#include "base/threading/platform_thread.h" -#include "base/time/time.h" #include "mojo/edk/system/awakable.h" #include "mojo/edk/system/core_test_base.h" +#include "mojo/edk/system/test_utils.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -30,7 +30,7 @@ TEST_F(CoreTest, GetTimeTicksNow) { const MojoTimeTicks start = core()->GetTimeTicksNow(); EXPECT_NE(static_cast(0), start) << "GetTimeTicksNow should return nonzero value"; - base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(15)); + test::Sleep(test::DeadlineFromMilliseconds(15)); const MojoTimeTicks finish = core()->GetTimeTicksNow(); // Allow for some fuzz in sleep. EXPECT_GE((finish - start), static_cast(8000)) @@ -734,7 +734,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) { hss.satisfied_signals); EXPECT_EQ(kAllSignals, hss.satisfiable_signals); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_passing[1], UserPointer(buffer), @@ -774,7 +774,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) { hss.satisfied_signals); EXPECT_EQ(kAllSignals, hss.satisfiable_signals); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_passed[1], UserPointer(buffer), @@ -797,7 +797,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) { hss.satisfied_signals); EXPECT_EQ(kAllSignals, hss.satisfiable_signals); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_passing[1], UserPointer(buffer), @@ -832,7 +832,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing1) { hss.satisfied_signals); EXPECT_EQ(kAllSignals, hss.satisfiable_signals); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_received, UserPointer(buffer), @@ -1079,7 +1079,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) { hss.satisfied_signals); EXPECT_EQ(kAllSignals, hss.satisfiable_signals); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_passing[1], UserPointer(buffer), @@ -1135,7 +1135,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) { hss.satisfied_signals); EXPECT_EQ(kAllSignals, hss.satisfiable_signals); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_passing[1], UserPointer(buffer), @@ -1206,7 +1206,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) { core()->Wait(h_passing[1], MOJO_HANDLE_SIGNAL_READABLE, 1000000000, NullUserPointer())); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_passing[1], UserPointer(buffer), @@ -1256,7 +1256,7 @@ TEST_F(CoreTest, MessagePipeBasicLocalHandlePassing2) { hss.satisfied_signals); EXPECT_EQ(kAllSignals, hss.satisfiable_signals); num_bytes = kBufferSize; - num_handles = arraysize(handles); + num_handles = MOJO_ARRAYSIZE(handles); EXPECT_EQ(MOJO_RESULT_OK, core()->ReadMessage( h_passing[1], UserPointer(buffer), diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe.h b/third_party/mojo/src/mojo/edk/system/data_pipe.h index c539f1bb30535e..1e0b64ff2cea51 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe.h +++ b/third_party/mojo/src/mojo/edk/system/data_pipe.h @@ -8,7 +8,6 @@ #include #include "base/compiler_specific.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "mojo/edk/embedder/platform_handle_vector.h" @@ -18,6 +17,7 @@ #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/data_pipe.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -35,7 +35,7 @@ class MessageInTransitQueue; // Its subclasses implement the three cases: local producer and consumer, local // producer and remote consumer, and remote producer and local consumer. This // class is thread-safe. -class MOJO_SYSTEM_IMPL_EXPORT DataPipe : public ChannelEndpointClient { +class MOJO_SYSTEM_IMPL_EXPORT DataPipe final : public ChannelEndpointClient { public: // The default options for |MojoCreateDataPipe()|. (Real uses should obtain // this via |ValidateCreateOptions()| with a null |in_options|; this is @@ -268,7 +268,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipe : public ChannelEndpointClient { uint32_t consumer_two_phase_max_num_bytes_read_; scoped_ptr impl_; - DISALLOW_COPY_AND_ASSIGN(DataPipe); + MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipe); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.cc b/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.cc index 076b72407ad150..ac917d99bb472e 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.cc +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.cc @@ -11,9 +11,6 @@ namespace mojo { namespace system { -DataPipeConsumerDispatcher::DataPipeConsumerDispatcher() { -} - void DataPipeConsumerDispatcher::Init(scoped_refptr data_pipe) { DCHECK(data_pipe); data_pipe_ = data_pipe; @@ -33,12 +30,14 @@ DataPipeConsumerDispatcher::Deserialize(Channel* channel, return nullptr; DCHECK(data_pipe); - scoped_refptr dispatcher( - new DataPipeConsumerDispatcher()); + scoped_refptr dispatcher = Create(); dispatcher->Init(data_pipe); return dispatcher; } +DataPipeConsumerDispatcher::DataPipeConsumerDispatcher() { +} + DataPipeConsumerDispatcher::~DataPipeConsumerDispatcher() { // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. DCHECK(!data_pipe_); @@ -59,8 +58,7 @@ scoped_refptr DataPipeConsumerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { lock().AssertAcquired(); - scoped_refptr rv = - new DataPipeConsumerDispatcher(); + scoped_refptr rv = Create(); rv->Init(data_pipe_); data_pipe_ = nullptr; return scoped_refptr(rv.get()); diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.h b/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.h index 02f88879869e42..7d8b5ee875a896 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.h +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_consumer_dispatcher.h @@ -5,10 +5,10 @@ #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ #define MOJO_EDK_SYSTEM_DATA_PIPE_CONSUMER_DISPATCHER_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -18,9 +18,12 @@ class DataPipe; // This is the |Dispatcher| implementation for the consumer handle for data // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is // thread-safe. -class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher : public Dispatcher { +class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final + : public Dispatcher { public: - DataPipeConsumerDispatcher(); + static scoped_refptr Create() { + return make_scoped_refptr(new DataPipeConsumerDispatcher()); + } // Must be called before any other methods. void Init(scoped_refptr data_pipe); @@ -37,6 +40,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher : public Dispatcher { DataPipe* GetDataPipeForTest() { return data_pipe_.get(); } private: + DataPipeConsumerDispatcher(); ~DataPipeConsumerDispatcher() override; // |Dispatcher| protected methods: @@ -71,7 +75,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher : public Dispatcher { // Protected by |lock()|: scoped_refptr data_pipe_; // This will be null if closed. - DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h b/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h index 20ca900044e145..4dac32dee50321 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h @@ -7,14 +7,13 @@ #include -#include "base/compiler_specific.h" -#include "base/macros.h" #include "mojo/edk/embedder/platform_handle_vector.h" #include "mojo/edk/system/data_pipe.h" #include "mojo/edk/system/handle_signals_state.h" #include "mojo/edk/system/memory.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/data_pipe.h" +#include "mojo/public/c/system/macros.h" #include "mojo/public/c/system/types.h" namespace mojo { @@ -130,7 +129,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeImpl { private: DataPipe* owner_; - DISALLOW_COPY_AND_ASSIGN(DataPipeImpl); + MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeImpl); }; // TODO(vtl): This is not the ideal place for the following structs; find @@ -138,7 +137,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeImpl { // Serialized form of a producer dispatcher. This will actually be followed by a // serialized |ChannelEndpoint|; we want to preserve alignment guarantees. -struct ALIGNAS(8) SerializedDataPipeProducerDispatcher { +struct MOJO_ALIGNAS(8) SerializedDataPipeProducerDispatcher { // Only validated (and thus canonicalized) options should be serialized. // However, the deserializer must revalidate (as with everything received). MojoCreateDataPipeOptions validated_options; @@ -150,7 +149,7 @@ struct ALIGNAS(8) SerializedDataPipeProducerDispatcher { // Serialized form of a consumer dispatcher. This will actually be followed by a // serialized |ChannelEndpoint|; we want to preserve alignment guarantees. -struct ALIGNAS(8) SerializedDataPipeConsumerDispatcher { +struct MOJO_ALIGNAS(8) SerializedDataPipeConsumerDispatcher { // Only validated (and thus canonicalized) options should be serialized. // However, the deserializer must revalidate (as with everything received). MojoCreateDataPipeOptions validated_options; diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_impl_unittest.cc b/third_party/mojo/src/mojo/edk/system/data_pipe_impl_unittest.cc index 1688e3d288acdc..3b0470bb1b19a6 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_impl_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_impl_unittest.cc @@ -12,11 +12,9 @@ #include "base/bind.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/test/test_io_thread.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. #include "mojo/edk/embedder/platform_channel_pair.h" #include "mojo/edk/embedder/simple_platform_support.h" #include "mojo/edk/system/channel.h" @@ -29,6 +27,7 @@ #include "mojo/edk/system/raw_channel.h" #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -80,7 +79,7 @@ class DataPipeImplTestHelper { DataPipeImplTestHelper() {} private: - DISALLOW_COPY_AND_ASSIGN(DataPipeImplTestHelper); + MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeImplTestHelper); }; // DataPipeImplTest ------------------------------------------------------------ @@ -183,7 +182,7 @@ class DataPipeImplTest : public testing::Test { scoped_ptr helper_; - DISALLOW_COPY_AND_ASSIGN(DataPipeImplTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeImplTest); }; // LocalDataPipeImplTestHelper ------------------------------------------------- @@ -215,7 +214,7 @@ class LocalDataPipeImplTestHelper : public DataPipeImplTestHelper { private: scoped_refptr dp_; - DISALLOW_COPY_AND_ASSIGN(LocalDataPipeImplTestHelper); + MOJO_DISALLOW_COPY_AND_ASSIGN(LocalDataPipeImplTestHelper); }; // RemoteDataPipeImplTestHelper ------------------------------------------------ @@ -350,7 +349,7 @@ class RemoteDataPipeImplTestHelper : public DataPipeImplTestHelper { scoped_refptr dp_; - DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTestHelper); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTestHelper); }; // RemoteProducerDataPipeImplTestHelper ---------------------------------------- @@ -367,7 +366,7 @@ class RemoteProducerDataPipeImplTestHelper void DoTransfer() override { // This is the producer dispatcher we'll send. scoped_refptr to_send = - new DataPipeProducerDispatcher(); + DataPipeProducerDispatcher::Create(); to_send->Init(dp()); scoped_refptr to_receive; SendDispatcher(0, to_send, &to_receive); @@ -400,7 +399,7 @@ class RemoteProducerDataPipeImplTestHelper scoped_refptr producer_dispatcher_; private: - DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper); }; // RemoteConsumerDataPipeImplTestHelper ---------------------------------------- @@ -417,7 +416,7 @@ class RemoteConsumerDataPipeImplTestHelper void DoTransfer() override { // This is the consumer dispatcher we'll send. scoped_refptr to_send = - new DataPipeConsumerDispatcher(); + DataPipeConsumerDispatcher::Create(); to_send->Init(dp()); scoped_refptr to_receive; SendDispatcher(0, to_send, &to_receive); @@ -450,7 +449,7 @@ class RemoteConsumerDataPipeImplTestHelper scoped_refptr consumer_dispatcher_; private: - DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper); }; // RemoteProducerDataPipeImplTestHelper2 --------------------------------------- @@ -472,7 +471,7 @@ class RemoteProducerDataPipeImplTestHelper2 void DoTransfer() override { // This is the producer dispatcher we'll send. scoped_refptr to_send = - new DataPipeProducerDispatcher(); + DataPipeProducerDispatcher::Create(); to_send->Init(dp()); scoped_refptr to_receive; SendDispatcher(0, to_send, &to_receive); @@ -497,7 +496,7 @@ class RemoteProducerDataPipeImplTestHelper2 } private: - DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper2); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper2); }; // RemoteConsumerDataPipeImplTestHelper2 --------------------------------------- @@ -519,7 +518,7 @@ class RemoteConsumerDataPipeImplTestHelper2 void DoTransfer() override { // This is the consumer dispatcher we'll send. scoped_refptr to_send = - new DataPipeConsumerDispatcher(); + DataPipeConsumerDispatcher::Create(); to_send->Init(dp()); scoped_refptr to_receive; SendDispatcher(0, to_send, &to_receive); @@ -544,7 +543,7 @@ class RemoteConsumerDataPipeImplTestHelper2 } private: - DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper2); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper2); }; // Test case instantiation ----------------------------------------------------- @@ -586,7 +585,7 @@ TYPED_TEST(DataPipeImplTest, CreateAndMaybeTransfer) { EXPECT_EQ(MOJO_RESULT_OK, DataPipe::ValidateCreateOptions(NullUserPointer(), &test_options[0])); - for (size_t i = 0; i < arraysize(test_options); i++) { + for (size_t i = 0; i < MOJO_ARRAYSIZE(test_options); i++) { this->Create(test_options[i]); this->DoTransfer(); this->ProducerClose(); @@ -613,7 +612,8 @@ TYPED_TEST(DataPipeImplTest, SimpleReadWrite) { uint32_t num_bytes = 0; // Try reading; nothing there yet. - num_bytes = static_cast(arraysize(elements) * sizeof(elements[0])); + num_bytes = + static_cast(MOJO_ARRAYSIZE(elements) * sizeof(elements[0])); EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, this->ConsumerReadData(UserPointer(elements), MakeUserPointer(&num_bytes), false, false)); @@ -1458,7 +1458,7 @@ TYPED_TEST(DataPipeImplTest, AllOrNone) { // Try writing way too much. uint32_t num_bytes = 20u * sizeof(int32_t); int32_t buffer[100]; - Seq(0, arraysize(buffer), buffer); + Seq(0, MOJO_ARRAYSIZE(buffer), buffer); EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, this->ProducerWriteData(UserPointer(buffer), MakeUserPointer(&num_bytes), true)); @@ -1477,7 +1477,7 @@ TYPED_TEST(DataPipeImplTest, AllOrNone) { // Write some data. num_bytes = 5u * sizeof(int32_t); - Seq(100, arraysize(buffer), buffer); + Seq(100, MOJO_ARRAYSIZE(buffer), buffer); EXPECT_EQ(MOJO_RESULT_OK, this->ProducerWriteData(UserPointer(buffer), MakeUserPointer(&num_bytes), true)); @@ -1503,7 +1503,7 @@ TYPED_TEST(DataPipeImplTest, AllOrNone) { // Too much. num_bytes = 6u * sizeof(int32_t); - Seq(200, arraysize(buffer), buffer); + Seq(200, MOJO_ARRAYSIZE(buffer), buffer); EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, this->ProducerWriteData(UserPointer(buffer), MakeUserPointer(&num_bytes), true)); @@ -1525,7 +1525,7 @@ TYPED_TEST(DataPipeImplTest, AllOrNone) { // Just a little. num_bytes = 2u * sizeof(int32_t); - Seq(300, arraysize(buffer), buffer); + Seq(300, MOJO_ARRAYSIZE(buffer), buffer); EXPECT_EQ(MOJO_RESULT_OK, this->ProducerWriteData(UserPointer(buffer), MakeUserPointer(&num_bytes), true)); @@ -1533,7 +1533,7 @@ TYPED_TEST(DataPipeImplTest, AllOrNone) { // Just right. num_bytes = 3u * sizeof(int32_t); - Seq(400, arraysize(buffer), buffer); + Seq(400, MOJO_ARRAYSIZE(buffer), buffer); EXPECT_EQ(MOJO_RESULT_OK, this->ProducerWriteData(UserPointer(buffer), MakeUserPointer(&num_bytes), true)); @@ -1548,7 +1548,7 @@ TYPED_TEST(DataPipeImplTest, AllOrNone) { if (num_bytes >= 10u * sizeof(int32_t)) break; - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); } EXPECT_EQ(10u * sizeof(int32_t), num_bytes); @@ -1755,7 +1755,7 @@ TYPED_TEST(DataPipeImplTest, TwoPhaseAllOrNone) { break; EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, result); - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); } EXPECT_EQ(6u * sizeof(int32_t), num_bytes); @@ -1768,7 +1768,7 @@ TYPED_TEST(DataPipeImplTest, TwoPhaseAllOrNone) { if (num_bytes >= 10u * sizeof(int32_t)) break; - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); } EXPECT_EQ(10u * sizeof(int32_t), num_bytes); @@ -1827,7 +1827,7 @@ TYPED_TEST(DataPipeImplTest, TwoPhaseAllOrNone) { // this.) TYPED_TEST(DataPipeImplTest, WrapAround) { unsigned char test_data[1000]; - for (size_t i = 0; i < arraysize(test_data); i++) + for (size_t i = 0; i < MOJO_ARRAYSIZE(test_data); i++) test_data[i] = static_cast(i); const MojoCreateDataPipeOptions options = { @@ -1909,7 +1909,7 @@ TYPED_TEST(DataPipeImplTest, WrapAround) { EXPECT_EQ(MOJO_RESULT_OUT_OF_RANGE, result); } - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); } EXPECT_EQ(90u, total_num_bytes); @@ -1922,7 +1922,7 @@ TYPED_TEST(DataPipeImplTest, WrapAround) { if (num_bytes >= 100u) break; - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); } EXPECT_EQ(100u, num_bytes); @@ -1941,8 +1941,8 @@ TYPED_TEST(DataPipeImplTest, WrapAround) { // Read as much as possible (using |ConsumerReadData()|). We should read 100 // bytes. - num_bytes = - static_cast(arraysize(read_buffer) * sizeof(read_buffer[0])); + num_bytes = static_cast(MOJO_ARRAYSIZE(read_buffer) * + sizeof(read_buffer[0])); memset(read_buffer, 0, num_bytes); EXPECT_EQ(MOJO_RESULT_OK, this->ConsumerReadData(UserPointer(read_buffer), @@ -2000,7 +2000,7 @@ TYPED_TEST(DataPipeImplTest, WriteCloseProducerRead) { if (num_bytes >= 2u * kTestDataSize) break; - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); } EXPECT_EQ(2u * kTestDataSize, num_bytes); @@ -2267,7 +2267,7 @@ TYPED_TEST(DataPipeImplTest, TwoPhaseMoreInvalidArguments) { // Wait a bit, to make sure that if a signal were (incorrectly) sent, it'd // have time to propagate. - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); // Still no data. num_bytes = 1000u; @@ -2289,7 +2289,7 @@ TYPED_TEST(DataPipeImplTest, TwoPhaseMoreInvalidArguments) { EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, this->ProducerEndWriteData(0u)); // Wait a bit (as above). - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); // Still no data. num_bytes = 1000u; @@ -2311,7 +2311,7 @@ TYPED_TEST(DataPipeImplTest, TwoPhaseMoreInvalidArguments) { EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, this->ProducerEndWriteData(0u)); // Wait a bit (as above). - base::PlatformThread::Sleep(test::EpsilonTimeout()); + test::Sleep(test::EpsilonDeadline()); // Still no data. num_bytes = 1000u; diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.cc b/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.cc index ccd0291a582210..88190cfe591926 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.cc +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.cc @@ -11,9 +11,6 @@ namespace mojo { namespace system { -DataPipeProducerDispatcher::DataPipeProducerDispatcher() { -} - void DataPipeProducerDispatcher::Init(scoped_refptr data_pipe) { DCHECK(data_pipe); data_pipe_ = data_pipe; @@ -33,12 +30,14 @@ DataPipeProducerDispatcher::Deserialize(Channel* channel, return nullptr; DCHECK(data_pipe); - scoped_refptr dispatcher( - new DataPipeProducerDispatcher()); + scoped_refptr dispatcher = Create(); dispatcher->Init(data_pipe); return dispatcher; } +DataPipeProducerDispatcher::DataPipeProducerDispatcher() { +} + DataPipeProducerDispatcher::~DataPipeProducerDispatcher() { // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. DCHECK(!data_pipe_); @@ -59,8 +58,7 @@ scoped_refptr DataPipeProducerDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { lock().AssertAcquired(); - scoped_refptr rv = - new DataPipeProducerDispatcher(); + scoped_refptr rv = Create(); rv->Init(data_pipe_); data_pipe_ = nullptr; return scoped_refptr(rv.get()); diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.h b/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.h index 0a563d741eb2da..86697fe3961460 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.h +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_producer_dispatcher.h @@ -5,10 +5,10 @@ #ifndef MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ #define MOJO_EDK_SYSTEM_DATA_PIPE_PRODUCER_DISPATCHER_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -18,9 +18,12 @@ class DataPipe; // This is the |Dispatcher| implementation for the producer handle for data // pipes (created by the Mojo primitive |MojoCreateDataPipe()|). This class is // thread-safe. -class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher : public Dispatcher { +class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final + : public Dispatcher { public: - DataPipeProducerDispatcher(); + static scoped_refptr Create() { + return make_scoped_refptr(new DataPipeProducerDispatcher()); + } // Must be called before any other methods. void Init(scoped_refptr data_pipe); @@ -37,6 +40,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher : public Dispatcher { DataPipe* GetDataPipeForTest() { return data_pipe_.get(); } private: + DataPipeProducerDispatcher(); ~DataPipeProducerDispatcher() override; // |Dispatcher| protected methods: @@ -71,7 +75,7 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher : public Dispatcher { // Protected by |lock()|: scoped_refptr data_pipe_; // This will be null if closed. - DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_unittest.cc b/third_party/mojo/src/mojo/edk/system/data_pipe_unittest.cc index c2982380dfc27f..e56f43bf1cc09c 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_unittest.cc @@ -10,6 +10,7 @@ #include #include "mojo/edk/system/configuration.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -80,7 +81,7 @@ TEST(DataPipeTest, ValidateCreateOptionsValid) { // Different flags. MojoCreateDataPipeOptionsFlags flags_values[] = { MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE}; - for (size_t i = 0; i < arraysize(flags_values); i++) { + for (size_t i = 0; i < MOJO_ARRAYSIZE(flags_values); i++) { const MojoCreateDataPipeOptionsFlags flags = flags_values[i]; // Flags member, but nothing beyond. diff --git a/third_party/mojo/src/mojo/edk/system/dispatcher.h b/third_party/mojo/src/mojo/edk/system/dispatcher.h index d7b7780ccf198f..ed6999dc160981 100644 --- a/third_party/mojo/src/mojo/edk/system/dispatcher.h +++ b/third_party/mojo/src/mojo/edk/system/dispatcher.h @@ -11,7 +11,6 @@ #include #include -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" @@ -23,6 +22,7 @@ #include "mojo/public/c/system/data_pipe.h" #include "mojo/public/c/system/message_pipe.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { @@ -362,7 +362,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher mutable base::Lock lock_; bool is_closed_; - DISALLOW_COPY_AND_ASSIGN(Dispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(Dispatcher); }; // Wrapper around a |Dispatcher| pointer, while it's being processed to be diff --git a/third_party/mojo/src/mojo/edk/system/dispatcher_unittest.cc b/third_party/mojo/src/mojo/edk/system/dispatcher_unittest.cc index 2b853d27927dbe..10c2b862fb8038 100644 --- a/third_party/mojo/src/mojo/edk/system/dispatcher_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/dispatcher_unittest.cc @@ -4,7 +4,6 @@ #include "mojo/edk/system/dispatcher.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_vector.h" #include "base/synchronization/waitable_event.h" @@ -12,6 +11,7 @@ #include "mojo/edk/embedder/platform_shared_buffer.h" #include "mojo/edk/system/memory.h" #include "mojo/edk/system/waiter.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -19,7 +19,7 @@ namespace system { namespace { // Trivial subclass that makes the constructor public. -class TrivialDispatcher : public Dispatcher { +class TrivialDispatcher final : public Dispatcher { public: TrivialDispatcher() {} @@ -35,7 +35,7 @@ class TrivialDispatcher : public Dispatcher { return scoped_refptr(new TrivialDispatcher()); } - DISALLOW_COPY_AND_ASSIGN(TrivialDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(TrivialDispatcher); }; TEST(DispatcherTest, Basic) { @@ -245,7 +245,7 @@ class ThreadSafetyStressThread : public base::SimpleThread { Waiter waiter_; - DISALLOW_COPY_AND_ASSIGN(ThreadSafetyStressThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(ThreadSafetyStressThread); }; TEST(DispatcherTest, ThreadSafetyStress) { diff --git a/third_party/mojo/src/mojo/edk/system/endpoint_relayer.h b/third_party/mojo/src/mojo/edk/system/endpoint_relayer.h index dba4367552a661..8b17a50b78c853 100644 --- a/third_party/mojo/src/mojo/edk/system/endpoint_relayer.h +++ b/third_party/mojo/src/mojo/edk/system/endpoint_relayer.h @@ -5,12 +5,12 @@ #ifndef MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ #define MOJO_EDK_SYSTEM_ENDPOINT_RELAYER_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "mojo/edk/system/channel_endpoint_client.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -19,7 +19,8 @@ class ChannelEndpoint; // This is a simple |ChannelEndpointClient| that just relays messages between // two |ChannelEndpoint|s (without the overhead of |MessagePipe|). -class MOJO_SYSTEM_IMPL_EXPORT EndpointRelayer : public ChannelEndpointClient { +class MOJO_SYSTEM_IMPL_EXPORT EndpointRelayer final + : public ChannelEndpointClient { public: // A class that can inspect and optionally handle messages of type // |Type::ENDPOINT_CLIENT| received from either |ChannelEndpoint|. @@ -58,7 +59,7 @@ class MOJO_SYSTEM_IMPL_EXPORT EndpointRelayer : public ChannelEndpointClient { Filter() {} private: - DISALLOW_COPY_AND_ASSIGN(Filter); + MOJO_DISALLOW_COPY_AND_ASSIGN(Filter); }; EndpointRelayer(); @@ -86,7 +87,7 @@ class MOJO_SYSTEM_IMPL_EXPORT EndpointRelayer : public ChannelEndpointClient { scoped_refptr endpoints_[2]; scoped_ptr filter_; - DISALLOW_COPY_AND_ASSIGN(EndpointRelayer); + MOJO_DISALLOW_COPY_AND_ASSIGN(EndpointRelayer); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/endpoint_relayer_unittest.cc b/third_party/mojo/src/mojo/edk/system/endpoint_relayer_unittest.cc index 88001c00a177dd..8cc9b23d8e3fef 100644 --- a/third_party/mojo/src/mojo/edk/system/endpoint_relayer_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/endpoint_relayer_unittest.cc @@ -5,7 +5,6 @@ #include "mojo/edk/system/endpoint_relayer.h" #include "base/logging.h" -#include "base/macros.h" #include "base/synchronization/waitable_event.h" #include "base/test/test_timeouts.h" #include "mojo/edk/system/channel_endpoint_id.h" @@ -13,6 +12,7 @@ #include "mojo/edk/system/message_in_transit_queue.h" #include "mojo/edk/system/message_in_transit_test_utils.h" #include "mojo/edk/system/test_channel_endpoint_client.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -84,7 +84,7 @@ class EndpointRelayerTest : public test::ChannelTestBase { scoped_refptr endpoint1a_; scoped_refptr endpoint1b_; - DISALLOW_COPY_AND_ASSIGN(EndpointRelayerTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(EndpointRelayerTest); }; TEST_F(EndpointRelayerTest, Basic) { @@ -179,7 +179,7 @@ class TestFilter : public EndpointRelayer::Filter { private: MessageInTransitQueue* const filtered_messages_; - DISALLOW_COPY_AND_ASSIGN(TestFilter); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestFilter); }; TEST_F(EndpointRelayerTest, Filter) { diff --git a/third_party/mojo/src/mojo/edk/system/handle_signals_state.h b/third_party/mojo/src/mojo/edk/system/handle_signals_state.h index 3391ea0fd3a769..78a3d65529edbe 100644 --- a/third_party/mojo/src/mojo/edk/system/handle_signals_state.h +++ b/third_party/mojo/src/mojo/edk/system/handle_signals_state.h @@ -5,7 +5,6 @@ #ifndef MOJO_EDK_SYSTEM_HANDLE_SIGNALS_STATE_H_ #define MOJO_EDK_SYSTEM_HANDLE_SIGNALS_STATE_H_ -#include "base/macros.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" @@ -14,7 +13,7 @@ namespace system { // Just "add" some constructors and methods to the C struct // |MojoHandleSignalsState| (for convenience). This should add no overhead. -struct MOJO_SYSTEM_IMPL_EXPORT HandleSignalsState +struct MOJO_SYSTEM_IMPL_EXPORT HandleSignalsState final : public MojoHandleSignalsState { HandleSignalsState() { satisfied_signals = MOJO_HANDLE_SIGNAL_NONE; diff --git a/third_party/mojo/src/mojo/edk/system/handle_table.cc b/third_party/mojo/src/mojo/edk/system/handle_table.cc index e054919eca83e5..15ff5d8f8eebfa 100644 --- a/third_party/mojo/src/mojo/edk/system/handle_table.cc +++ b/third_party/mojo/src/mojo/edk/system/handle_table.cc @@ -5,8 +5,8 @@ #include "mojo/edk/system/handle_table.h" #include + #include "base/logging.h" -#include "base/macros.h" #include "mojo/edk/system/configuration.h" #include "mojo/edk/system/dispatcher.h" diff --git a/third_party/mojo/src/mojo/edk/system/handle_table.h b/third_party/mojo/src/mojo/edk/system/handle_table.h index 64ad1836836143..83c7208924bfe2 100644 --- a/third_party/mojo/src/mojo/edk/system/handle_table.h +++ b/third_party/mojo/src/mojo/edk/system/handle_table.h @@ -9,10 +9,10 @@ #include #include "base/containers/hash_tables.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -135,7 +135,7 @@ class MOJO_SYSTEM_IMPL_EXPORT HandleTable { HandleToEntryMap handle_to_entry_map_; MojoHandle next_handle_; // Invariant: never |MOJO_HANDLE_INVALID|. - DISALLOW_COPY_AND_ASSIGN(HandleTable); + MOJO_DISALLOW_COPY_AND_ASSIGN(HandleTable); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/incoming_endpoint.h b/third_party/mojo/src/mojo/edk/system/incoming_endpoint.h index 6a6f04fc91811a..22bf0b9437079e 100644 --- a/third_party/mojo/src/mojo/edk/system/incoming_endpoint.h +++ b/third_party/mojo/src/mojo/edk/system/incoming_endpoint.h @@ -7,12 +7,12 @@ #include -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "mojo/edk/system/channel_endpoint_client.h" #include "mojo/edk/system/message_in_transit_queue.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" struct MojoCreateDataPipeOptions; @@ -26,7 +26,8 @@ class MessagePipe; // This is a simple |ChannelEndpointClient| that only receives messages. It's // used for endpoints that are "received" by |Channel|, but not yet turned into // |MessagePipe|s or |DataPipe|s. -class MOJO_SYSTEM_IMPL_EXPORT IncomingEndpoint : public ChannelEndpointClient { +class MOJO_SYSTEM_IMPL_EXPORT IncomingEndpoint final + : public ChannelEndpointClient { public: IncomingEndpoint(); @@ -55,7 +56,7 @@ class MOJO_SYSTEM_IMPL_EXPORT IncomingEndpoint : public ChannelEndpointClient { scoped_refptr endpoint_; MessageInTransitQueue message_queue_; - DISALLOW_COPY_AND_ASSIGN(IncomingEndpoint); + MOJO_DISALLOW_COPY_AND_ASSIGN(IncomingEndpoint); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/ipc_support.h b/third_party/mojo/src/mojo/edk/system/ipc_support.h index 3d83e12c9ec310..33441fbc66e7cb 100644 --- a/third_party/mojo/src/mojo/edk/system/ipc_support.h +++ b/third_party/mojo/src/mojo/edk/system/ipc_support.h @@ -7,7 +7,6 @@ #include "base/callback_forward.h" #include "base/gtest_prod_util.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/task_runner.h" @@ -18,6 +17,7 @@ #include "mojo/edk/system/connection_identifier.h" #include "mojo/edk/system/process_identifier.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { @@ -172,7 +172,7 @@ class MOJO_SYSTEM_IMPL_EXPORT IPCSupport { scoped_ptr connection_manager_; scoped_ptr channel_manager_; - DISALLOW_COPY_AND_ASSIGN(IPCSupport); + MOJO_DISALLOW_COPY_AND_ASSIGN(IPCSupport); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/ipc_support_unittest.cc b/third_party/mojo/src/mojo/edk/system/ipc_support_unittest.cc index b613e457fec496..823f6b9f526c8e 100644 --- a/third_party/mojo/src/mojo/edk/system/ipc_support_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/ipc_support_unittest.cc @@ -4,11 +4,13 @@ #include "mojo/edk/system/ipc_support.h" +#include +#include + #include "base/bind.h" #include "base/command_line.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/synchronization/waitable_event.h" #include "base/test/test_io_thread.h" #include "base/test/test_timeouts.h" @@ -18,12 +20,15 @@ #include "mojo/edk/embedder/slave_process_delegate.h" #include "mojo/edk/system/channel_manager.h" #include "mojo/edk/system/connection_identifier.h" +#include "mojo/edk/system/dispatcher.h" +#include "mojo/edk/system/message_pipe.h" #include "mojo/edk/system/message_pipe_dispatcher.h" #include "mojo/edk/system/process_identifier.h" #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" #include "mojo/edk/test/multiprocess_test_helper.h" #include "mojo/edk/test/test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -35,9 +40,11 @@ const char kConnectionIdFlag[] = "test-connection-id"; class TestMasterProcessDelegate : public embedder::MasterProcessDelegate { public: TestMasterProcessDelegate() - : on_slave_disconnect_event_(true, false) {} // Manual reset. + : on_slave_disconnect_event_(false, false) {} // Auto reset. ~TestMasterProcessDelegate() override {} + // Warning: There's only one slave disconnect event (which resets + // automatically). bool TryWaitForOnSlaveDisconnect() { return on_slave_disconnect_event_.TimedWait(TestTimeouts::action_timeout()); } @@ -52,7 +59,7 @@ class TestMasterProcessDelegate : public embedder::MasterProcessDelegate { base::WaitableEvent on_slave_disconnect_event_; - DISALLOW_COPY_AND_ASSIGN(TestMasterProcessDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestMasterProcessDelegate); }; class TestSlaveProcessDelegate : public embedder::SlaveProcessDelegate { @@ -66,79 +73,283 @@ class TestSlaveProcessDelegate : public embedder::SlaveProcessDelegate { void OnMasterDisconnect() override { NOTREACHED(); } - DISALLOW_COPY_AND_ASSIGN(TestSlaveProcessDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestSlaveProcessDelegate); }; -TEST(IPCSupportTest, MasterSlave) { - embedder::SimplePlatformSupport platform_support; - base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); - TestMasterProcessDelegate master_process_delegate; +// Represents the master's side of its connection to a slave. +class TestSlaveConnection { + public: + TestSlaveConnection(base::TestIOThread* test_io_thread, + IPCSupport* master_ipc_support) + : test_io_thread_(test_io_thread), + master_ipc_support_(master_ipc_support), + connection_id_(master_ipc_support_->GenerateConnectionIdentifier()), + slave_id_(kInvalidProcessIdentifier), + event_(true, false) {} + ~TestSlaveConnection() {} + + // After this is called, |ShutdownChannelToSlave()| must be called (possibly + // after |WaitForChannelToSlave()|) before destruction. + scoped_refptr ConnectToSlave() { + embedder::PlatformChannelPair channel_pair; + // Note: |ChannelId|s and |ProcessIdentifier|s are interchangeable. + scoped_refptr mp = + master_ipc_support_->ConnectToSlave( + connection_id_, nullptr, channel_pair.PassServerHandle(), + base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event_)), + nullptr, &slave_id_); + EXPECT_TRUE(mp); + EXPECT_NE(slave_id_, kInvalidProcessIdentifier); + EXPECT_NE(slave_id_, kMasterProcessIdentifier); + slave_platform_handle_ = channel_pair.PassClientHandle(); + return mp; + } + + void WaitForChannelToSlave() { + EXPECT_TRUE(event_.TimedWait(TestTimeouts::action_timeout())); + } + + void ShutdownChannelToSlave() { + // Since |event_| is manual-reset, calling this multiple times is OK. + WaitForChannelToSlave(); + + test_io_thread_->PostTaskAndWait( + FROM_HERE, + base::Bind(&ChannelManager::ShutdownChannelOnIOThread, + base::Unretained(master_ipc_support_->channel_manager()), + slave_id_)); + } + + embedder::ScopedPlatformHandle PassSlavePlatformHandle() { + return slave_platform_handle_.Pass(); + } + + const ConnectionIdentifier& connection_id() const { return connection_id_; } + + private: + base::TestIOThread* const test_io_thread_; + IPCSupport* const master_ipc_support_; + const ConnectionIdentifier connection_id_; + // The master's message pipe dispatcher. + scoped_refptr message_pipe_; + ProcessIdentifier slave_id_; + base::WaitableEvent event_; + embedder::ScopedPlatformHandle slave_platform_handle_; + + MOJO_DISALLOW_COPY_AND_ASSIGN(TestSlaveConnection); +}; + +// Encapsulates the state of a slave. (Note, however, that we share a +// |PlatformSupport| and an I/O thread.) +class TestSlave { + public: + // Note: Before destruction, |ShutdownIPCSupport()| must be called. + TestSlave(embedder::PlatformSupport* platform_support, + base::TestIOThread* test_io_thread, + embedder::ScopedPlatformHandle platform_handle) + : test_io_thread_(test_io_thread), + slave_ipc_support_(platform_support, + embedder::ProcessType::SLAVE, + test_io_thread->task_runner(), + &slave_process_delegate_, + test_io_thread->task_runner(), + platform_handle.Pass()), + event_(true, false) {} + ~TestSlave() {} + + // After this is called, |ShutdownChannelToMaster()| must be called (possibly + // after |WaitForChannelToMaster()|) before destruction. + scoped_refptr ConnectToMaster( + const ConnectionIdentifier& connection_id) { + ProcessIdentifier master_id = kInvalidProcessIdentifier; + scoped_refptr mp = + slave_ipc_support_.ConnectToMaster( + connection_id, + base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event_)), + nullptr, &master_id); + EXPECT_TRUE(mp); + EXPECT_EQ(kMasterProcessIdentifier, master_id); + return mp; + } + + void WaitForChannelToMaster() { + EXPECT_TRUE(event_.TimedWait(TestTimeouts::action_timeout())); + } + + void ShutdownChannelToMaster() { + // Since |event_| is manual-reset, calling this multiple times is OK. + WaitForChannelToMaster(); + + test_io_thread_->PostTaskAndWait( + FROM_HERE, + base::Bind(&ChannelManager::ShutdownChannelOnIOThread, + base::Unretained(slave_ipc_support_.channel_manager()), + kMasterProcessIdentifier)); + } + + // No other methods may be called after this. + void ShutdownIPCSupport() { + test_io_thread_->PostTaskAndWait( + FROM_HERE, base::Bind(&IPCSupport::ShutdownOnIOThread, + base::Unretained(&slave_ipc_support_))); + } + + private: + base::TestIOThread* const test_io_thread_; + TestSlaveProcessDelegate slave_process_delegate_; + IPCSupport slave_ipc_support_; + base::WaitableEvent event_; + + MOJO_DISALLOW_COPY_AND_ASSIGN(TestSlave); +}; + +class IPCSupportTest : public testing::Test { + public: // Note: Run master process delegate methods on the I/O thread. - IPCSupport master_ipc_support( - &platform_support, embedder::ProcessType::MASTER, - test_io_thread.task_runner(), &master_process_delegate, - test_io_thread.task_runner(), embedder::ScopedPlatformHandle()); + IPCSupportTest() + : test_io_thread_(base::TestIOThread::kAutoStart), + master_ipc_support_(&platform_support(), + embedder::ProcessType::MASTER, + test_io_thread_.task_runner(), + &master_process_delegate_, + test_io_thread_.task_runner(), + embedder::ScopedPlatformHandle()) {} + ~IPCSupportTest() override {} + + void ShutdownMasterIPCSupport() { + test_io_thread_.PostTaskAndWait( + FROM_HERE, base::Bind(&IPCSupport::ShutdownOnIOThread, + base::Unretained(&master_ipc_support_))); + } - ConnectionIdentifier connection_id = - master_ipc_support.GenerateConnectionIdentifier(); + embedder::SimplePlatformSupport& platform_support() { + return platform_support_; + } + base::TestIOThread& test_io_thread() { return test_io_thread_; } + TestMasterProcessDelegate& master_process_delegate() { + return master_process_delegate_; + } + IPCSupport& master_ipc_support() { return master_ipc_support_; } - embedder::PlatformChannelPair channel_pair; - // Note: |ChannelId|s and |ProcessIdentifier|s are interchangeable. - ProcessIdentifier slave_id = kInvalidProcessIdentifier; - base::WaitableEvent event1(true, false); - scoped_refptr master_mp = - master_ipc_support.ConnectToSlave( - connection_id, nullptr, channel_pair.PassServerHandle(), - base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event1)), - nullptr, &slave_id); - ASSERT_TRUE(master_mp); - EXPECT_NE(slave_id, kInvalidProcessIdentifier); - EXPECT_NE(slave_id, kMasterProcessIdentifier); - // Note: We don't have to wait on |event1| now, but we'll have to do so before - // tearing down the channel. + private: + embedder::SimplePlatformSupport platform_support_; + base::TestIOThread test_io_thread_; - TestSlaveProcessDelegate slave_process_delegate; - // Note: Run process delegate methods on the I/O thread. - IPCSupport slave_ipc_support( - &platform_support, embedder::ProcessType::SLAVE, - test_io_thread.task_runner(), &slave_process_delegate, - test_io_thread.task_runner(), channel_pair.PassClientHandle()); + // All tests require a master. + TestMasterProcessDelegate master_process_delegate_; + IPCSupport master_ipc_support_; - ProcessIdentifier master_id = kInvalidProcessIdentifier; - base::WaitableEvent event2(true, false); - scoped_refptr slave_mp = - slave_ipc_support.ConnectToMaster( - connection_id, - base::Bind(&base::WaitableEvent::Signal, base::Unretained(&event2)), - nullptr, &master_id); - ASSERT_TRUE(slave_mp); - EXPECT_EQ(kMasterProcessIdentifier, master_id); - - // Set up waiting on the slave end first (to avoid racing). + MOJO_DISALLOW_COPY_AND_ASSIGN(IPCSupportTest); +}; + +// Tests writing a message (containing just data) to |write_mp| and then reading +// it from |read_mp| (it should be the next message, i.e., there should be no +// other messages already enqueued in that direction). +void TestWriteReadMessage(scoped_refptr write_mp, + scoped_refptr read_mp) { + // Set up waiting on the read end first (to avoid racing). Waiter waiter; waiter.Init(); ASSERT_EQ( MOJO_RESULT_OK, - slave_mp->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr)); + read_mp->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr)); - // Write a message with just 'x' through the master's end. + // Write a message with just 'x' through the write end. EXPECT_EQ(MOJO_RESULT_OK, - master_mp->WriteMessage(UserPointer("x"), 1, nullptr, - MOJO_WRITE_MESSAGE_FLAG_NONE)); + write_mp->WriteMessage(UserPointer("x"), 1, nullptr, + MOJO_WRITE_MESSAGE_FLAG_NONE)); // Wait for it to arrive. EXPECT_EQ(MOJO_RESULT_OK, waiter.Wait(test::ActionDeadline(), nullptr)); - slave_mp->RemoveAwakable(&waiter, nullptr); + read_mp->RemoveAwakable(&waiter, nullptr); - // Read the message from the slave's end. + // Read the message from the read end. char buffer[10] = {}; uint32_t buffer_size = static_cast(sizeof(buffer)); EXPECT_EQ(MOJO_RESULT_OK, - slave_mp->ReadMessage(UserPointer(buffer), - MakeUserPointer(&buffer_size), 0, nullptr, - MOJO_READ_MESSAGE_FLAG_NONE)); + read_mp->ReadMessage(UserPointer(buffer), + MakeUserPointer(&buffer_size), 0, nullptr, + MOJO_READ_MESSAGE_FLAG_NONE)); EXPECT_EQ(1u, buffer_size); EXPECT_EQ('x', buffer[0]); +} + +using MessagePipeDispatcherPair = + std::pair, + scoped_refptr>; +MessagePipeDispatcherPair CreateMessagePipe() { + MessagePipeDispatcherPair rv; + rv.first = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + rv.second = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + scoped_refptr mp(MessagePipe::CreateLocalLocal()); + rv.first->Init(mp, 0); + rv.second->Init(mp, 1); + return rv; +} + +// Writes a message pipe dispatcher (in a message) to |write_mp| and reads it +// from |read_mp| (it should be the next message, i.e., there should be no other +// other messages already enqueued in that direction). +scoped_refptr SendMessagePipeDispatcher( + scoped_refptr write_mp, + scoped_refptr read_mp, + scoped_refptr mp_to_send) { + CHECK_NE(mp_to_send, write_mp); + CHECK_NE(mp_to_send, read_mp); + + // Set up waiting on the read end first (to avoid racing). + Waiter waiter; + waiter.Init(); + CHECK_EQ( + read_mp->AddAwakable(&waiter, MOJO_HANDLE_SIGNAL_READABLE, 0, nullptr), + MOJO_RESULT_OK); + + // Write a message with just |mp_to_send| through the write end. + DispatcherTransport transport( + test::DispatcherTryStartTransport(mp_to_send.get())); + CHECK(transport.is_valid()); + std::vector transports; + transports.push_back(transport); + CHECK_EQ(write_mp->WriteMessage(NullUserPointer(), 0, &transports, + MOJO_WRITE_MESSAGE_FLAG_NONE), + MOJO_RESULT_OK); + transport.End(); + + // Wait for it to arrive. + CHECK_EQ(waiter.Wait(test::ActionDeadline(), nullptr), MOJO_RESULT_OK); + read_mp->RemoveAwakable(&waiter, nullptr); + + // Read the message from the read end. + DispatcherVector dispatchers; + uint32_t num_dispatchers = 10; + CHECK_EQ( + read_mp->ReadMessage(NullUserPointer(), NullUserPointer(), &dispatchers, + &num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE), + MOJO_RESULT_OK); + CHECK_EQ(dispatchers.size(), 1u); + CHECK_EQ(num_dispatchers, 1u); + CHECK_EQ(dispatchers[0]->GetType(), Dispatcher::Type::MESSAGE_PIPE); + return scoped_refptr( + static_cast(dispatchers[0].get())); +} + +TEST_F(IPCSupportTest, MasterSlave) { + TestSlaveConnection slave_connection(&test_io_thread(), + &master_ipc_support()); + scoped_refptr master_mp = + slave_connection.ConnectToSlave(); + + TestSlave slave(&platform_support(), &test_io_thread(), + slave_connection.PassSlavePlatformHandle()); + scoped_refptr slave_mp = + slave.ConnectToMaster(slave_connection.connection_id()); + + // Test that we can send a message from the master to the slave. + TestWriteReadMessage(master_mp, slave_mp); + // And vice versa. + TestWriteReadMessage(slave_mp, master_mp); // Don't need the message pipe anymore. master_mp->Close(); @@ -147,51 +358,100 @@ TEST(IPCSupportTest, MasterSlave) { // A message was sent through the message pipe, |Channel|s must have been // established on both sides. The events have thus almost certainly been // signalled, but we'll wait just to be sure. - EXPECT_TRUE(event1.TimedWait(TestTimeouts::action_timeout())); - EXPECT_TRUE(event2.TimedWait(TestTimeouts::action_timeout())); - - test_io_thread.PostTaskAndWait( - FROM_HERE, - base::Bind(&ChannelManager::ShutdownChannelOnIOThread, - base::Unretained(slave_ipc_support.channel_manager()), - master_id)); - test_io_thread.PostTaskAndWait( - FROM_HERE, base::Bind(&IPCSupport::ShutdownOnIOThread, - base::Unretained(&slave_ipc_support))); + slave_connection.WaitForChannelToSlave(); + slave.WaitForChannelToMaster(); - EXPECT_TRUE(master_process_delegate.TryWaitForOnSlaveDisconnect()); + slave.ShutdownChannelToMaster(); + slave.ShutdownIPCSupport(); + EXPECT_TRUE(master_process_delegate().TryWaitForOnSlaveDisconnect()); - test_io_thread.PostTaskAndWait( - FROM_HERE, - base::Bind(&ChannelManager::ShutdownChannelOnIOThread, - base::Unretained(master_ipc_support.channel_manager()), - slave_id)); - test_io_thread.PostTaskAndWait( - FROM_HERE, base::Bind(&IPCSupport::ShutdownOnIOThread, - base::Unretained(&master_ipc_support))); + slave_connection.ShutdownChannelToSlave(); + ShutdownMasterIPCSupport(); +} + +// Simulates a master and two slaves. Initially, there are just message pipes +// from the master to the slaves. This tests the master creating a message pipe +// and sending an end to each slave, which should result in a direct connection +// between the two slaves (TODO(vtl): this part doesn't happen yet). +// TODO(vtl): There are various other similar scenarios we'll need to test, so +// we'll need to factor out some of the code. +// TODO(vtl): In this scenario, we can't test the intermediary (the master) +// going away. +TEST_F(IPCSupportTest, ConnectTwoSlaves) { + TestSlaveConnection slave1_connection(&test_io_thread(), + &master_ipc_support()); + scoped_refptr master_mp1 = + slave1_connection.ConnectToSlave(); + + TestSlave slave1(&platform_support(), &test_io_thread(), + slave1_connection.PassSlavePlatformHandle()); + scoped_refptr slave1_mp = + slave1.ConnectToMaster(slave1_connection.connection_id()); + + TestSlaveConnection slave2_connection(&test_io_thread(), + &master_ipc_support()); + scoped_refptr master_mp2 = + slave2_connection.ConnectToSlave(); + + TestSlave slave2(&platform_support(), &test_io_thread(), + slave2_connection.PassSlavePlatformHandle()); + scoped_refptr slave2_mp = + slave2.ConnectToMaster(slave2_connection.connection_id()); + + TestWriteReadMessage(master_mp1, slave1_mp); + TestWriteReadMessage(slave1_mp, master_mp1); + TestWriteReadMessage(master_mp2, slave2_mp); + TestWriteReadMessage(slave2_mp, master_mp2); + + // Make a message pipe (logically "in" the master) and send one end to each + // slave. + MessagePipeDispatcherPair send_mps = CreateMessagePipe(); + scoped_refptr slave1_received_mp = + SendMessagePipeDispatcher(master_mp1, slave1_mp, send_mps.first); + scoped_refptr slave2_received_mp = + SendMessagePipeDispatcher(master_mp2, slave2_mp, send_mps.second); + + // These should be connected. + TestWriteReadMessage(slave1_received_mp, slave2_received_mp); + TestWriteReadMessage(slave2_received_mp, slave1_received_mp); + + master_mp1->Close(); + master_mp2->Close(); + slave1_mp->Close(); + slave2_mp->Close(); + + // They should still be connected. + TestWriteReadMessage(slave1_received_mp, slave2_received_mp); + TestWriteReadMessage(slave2_received_mp, slave1_received_mp); + + slave1_received_mp->Close(); + slave2_received_mp->Close(); + + slave1.ShutdownChannelToMaster(); + slave1.ShutdownIPCSupport(); + EXPECT_TRUE(master_process_delegate().TryWaitForOnSlaveDisconnect()); + slave1_connection.ShutdownChannelToSlave(); + + slave2.ShutdownChannelToMaster(); + slave2.ShutdownIPCSupport(); + EXPECT_TRUE(master_process_delegate().TryWaitForOnSlaveDisconnect()); + slave2_connection.ShutdownChannelToSlave(); + + ShutdownMasterIPCSupport(); } } // namespace // Note: This test isn't in an anonymous namespace, since it needs to be // friended by |IPCSupport|. -TEST(IPCSupportTest, MasterSlaveInternal) { - embedder::SimplePlatformSupport platform_support; - base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); - TestMasterProcessDelegate master_process_delegate; - // Note: Run master process delegate methods on the I/O thread. - IPCSupport master_ipc_support( - &platform_support, embedder::ProcessType::MASTER, - test_io_thread.task_runner(), &master_process_delegate, - test_io_thread.task_runner(), embedder::ScopedPlatformHandle()); - +TEST_F(IPCSupportTest, MasterSlaveInternal) { ConnectionIdentifier connection_id = - master_ipc_support.GenerateConnectionIdentifier(); + master_ipc_support().GenerateConnectionIdentifier(); embedder::PlatformChannelPair channel_pair; ProcessIdentifier slave_id = kInvalidProcessIdentifier; embedder::ScopedPlatformHandle master_second_platform_handle = - master_ipc_support.ConnectToSlaveInternal( + master_ipc_support().ConnectToSlaveInternal( connection_id, nullptr, channel_pair.PassServerHandle(), &slave_id); ASSERT_TRUE(master_second_platform_handle.is_valid()); EXPECT_NE(slave_id, kInvalidProcessIdentifier); @@ -200,9 +460,9 @@ TEST(IPCSupportTest, MasterSlaveInternal) { TestSlaveProcessDelegate slave_process_delegate; // Note: Run process delegate methods on the I/O thread. IPCSupport slave_ipc_support( - &platform_support, embedder::ProcessType::SLAVE, - test_io_thread.task_runner(), &slave_process_delegate, - test_io_thread.task_runner(), channel_pair.PassClientHandle()); + &platform_support(), embedder::ProcessType::SLAVE, + test_io_thread().task_runner(), &slave_process_delegate, + test_io_thread().task_runner(), channel_pair.PassClientHandle()); embedder::ScopedPlatformHandle slave_second_platform_handle = slave_ipc_support.ConnectToMasterInternal(connection_id); @@ -222,15 +482,13 @@ TEST(IPCSupportTest, MasterSlaveInternal) { EXPECT_EQ(1u, n); EXPECT_EQ('x', c); - test_io_thread.PostTaskAndWait( + test_io_thread().PostTaskAndWait( FROM_HERE, base::Bind(&IPCSupport::ShutdownOnIOThread, base::Unretained(&slave_ipc_support))); - EXPECT_TRUE(master_process_delegate.TryWaitForOnSlaveDisconnect()); + EXPECT_TRUE(master_process_delegate().TryWaitForOnSlaveDisconnect()); - test_io_thread.PostTaskAndWait( - FROM_HERE, base::Bind(&IPCSupport::ShutdownOnIOThread, - base::Unretained(&master_ipc_support))); + ShutdownMasterIPCSupport(); } // This is a true multiprocess version of IPCSupportTest.MasterSlaveInternal. @@ -244,22 +502,13 @@ TEST(IPCSupportTest, MasterSlaveInternal) { #else #define MAYBE_MultiprocessMasterSlaveInternal MultiprocessMasterSlaveInternal #endif // defined(OS_ANDROID) -TEST(IPCSupportTest, MAYBE_MultiprocessMasterSlaveInternal) { - embedder::SimplePlatformSupport platform_support; - base::TestIOThread test_io_thread(base::TestIOThread::kAutoStart); - TestMasterProcessDelegate master_process_delegate; - // Note: Run process delegate methods on the I/O thread. - IPCSupport ipc_support(&platform_support, embedder::ProcessType::MASTER, - test_io_thread.task_runner(), &master_process_delegate, - test_io_thread.task_runner(), - embedder::ScopedPlatformHandle()); - +TEST_F(IPCSupportTest, MAYBE_MultiprocessMasterSlaveInternal) { ConnectionIdentifier connection_id = - ipc_support.GenerateConnectionIdentifier(); + master_ipc_support().GenerateConnectionIdentifier(); mojo::test::MultiprocessTestHelper multiprocess_test_helper; ProcessIdentifier slave_id = kInvalidProcessIdentifier; embedder::ScopedPlatformHandle second_platform_handle = - ipc_support.ConnectToSlaveInternal( + master_ipc_support().ConnectToSlaveInternal( connection_id, nullptr, multiprocess_test_helper.server_platform_handle.Pass(), &slave_id); ASSERT_TRUE(second_platform_handle.is_valid()); @@ -283,12 +532,10 @@ TEST(IPCSupportTest, MAYBE_MultiprocessMasterSlaveInternal) { EXPECT_EQ(1u, n); EXPECT_EQ('!', c); - EXPECT_TRUE(master_process_delegate.TryWaitForOnSlaveDisconnect()); + EXPECT_TRUE(master_process_delegate().TryWaitForOnSlaveDisconnect()); EXPECT_TRUE(multiprocess_test_helper.WaitForChildTestShutdown()); - test_io_thread.PostTaskAndWait(FROM_HERE, - base::Bind(&IPCSupport::ShutdownOnIOThread, - base::Unretained(&ipc_support))); + ShutdownMasterIPCSupport(); } MOJO_MULTIPROCESS_TEST_CHILD_TEST(MultiprocessMasterSlaveInternal) { diff --git a/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc b/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc index 938ce68c651637..321b22e9ee214a 100644 --- a/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc +++ b/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc @@ -14,7 +14,6 @@ #include -#include "base/compiler_specific.h" #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/channel.h" @@ -30,7 +29,7 @@ namespace system { // Assert some things about some things defined in data_pipe_impl.h (don't make // the assertions there, to avoid including message_in_transit.h). -static_assert(ALIGNOF(SerializedDataPipeConsumerDispatcher) == +static_assert(MOJO_ALIGNOF(SerializedDataPipeConsumerDispatcher) == MessageInTransit::kMessageAlignment, "Wrong alignment"); static_assert(sizeof(SerializedDataPipeConsumerDispatcher) % diff --git a/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.h b/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.h index 48233f24425ae4..07b4c1e8654764 100644 --- a/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.h +++ b/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.h @@ -5,11 +5,11 @@ #ifndef MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ #define MOJO_EDK_SYSTEM_LOCAL_DATA_PIPE_IMPL_H_ -#include "base/macros.h" #include "base/memory/aligned_memory.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/data_pipe_impl.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -19,7 +19,7 @@ class MessageInTransitQueue; // |LocalDataPipeImpl| is a subclass that "implements" |DataPipe| for data pipes // whose producer and consumer are both local. See |DataPipeImpl| for more // details. -class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipeImpl : public DataPipeImpl { +class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipeImpl final : public DataPipeImpl { public: LocalDataPipeImpl(); ~LocalDataPipeImpl() override; @@ -87,7 +87,7 @@ class MOJO_SYSTEM_IMPL_EXPORT LocalDataPipeImpl : public DataPipeImpl { size_t start_index_; size_t current_num_bytes_; - DISALLOW_COPY_AND_ASSIGN(LocalDataPipeImpl); + MOJO_DISALLOW_COPY_AND_ASSIGN(LocalDataPipeImpl); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/local_message_pipe_endpoint.h b/third_party/mojo/src/mojo/edk/system/local_message_pipe_endpoint.h index f792d90ac0f69f..0f06847a4735ab 100644 --- a/third_party/mojo/src/mojo/edk/system/local_message_pipe_endpoint.h +++ b/third_party/mojo/src/mojo/edk/system/local_message_pipe_endpoint.h @@ -5,18 +5,17 @@ #ifndef MOJO_EDK_SYSTEM_LOCAL_MESSAGE_PIPE_ENDPOINT_H_ #define MOJO_EDK_SYSTEM_LOCAL_MESSAGE_PIPE_ENDPOINT_H_ -#include "base/compiler_specific.h" -#include "base/macros.h" #include "mojo/edk/system/awakable_list.h" #include "mojo/edk/system/handle_signals_state.h" #include "mojo/edk/system/message_in_transit_queue.h" #include "mojo/edk/system/message_pipe_endpoint.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { -class MOJO_SYSTEM_IMPL_EXPORT LocalMessagePipeEndpoint +class MOJO_SYSTEM_IMPL_EXPORT LocalMessagePipeEndpoint final : public MessagePipeEndpoint { public: // If |message_queue| is non-null, its contents will be taken as the queue of @@ -58,7 +57,7 @@ class MOJO_SYSTEM_IMPL_EXPORT LocalMessagePipeEndpoint MessageInTransitQueue message_queue_; AwakableList awakable_list_; - DISALLOW_COPY_AND_ASSIGN(LocalMessagePipeEndpoint); + MOJO_DISALLOW_COPY_AND_ASSIGN(LocalMessagePipeEndpoint); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/mapping_table.h b/third_party/mojo/src/mojo/edk/system/mapping_table.h index ed1732d35a0a55..5af16557c24d7d 100644 --- a/third_party/mojo/src/mojo/edk/system/mapping_table.h +++ b/third_party/mojo/src/mojo/edk/system/mapping_table.h @@ -10,10 +10,10 @@ #include #include "base/containers/hash_tables.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { @@ -53,7 +53,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MappingTable { base::hash_map; AddressToMappingMap address_to_mapping_map_; - DISALLOW_COPY_AND_ASSIGN(MappingTable); + MOJO_DISALLOW_COPY_AND_ASSIGN(MappingTable); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/master_connection_manager.cc b/third_party/mojo/src/mojo/edk/system/master_connection_manager.cc index 9966ae015efb61..d756f734d79725 100644 --- a/third_party/mojo/src/mojo/edk/system/master_connection_manager.cc +++ b/third_party/mojo/src/mojo/edk/system/master_connection_manager.cc @@ -16,6 +16,7 @@ #include "mojo/edk/system/message_in_transit.h" #include "mojo/edk/system/raw_channel.h" #include "mojo/edk/system/transport_data.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -33,7 +34,7 @@ static_assert(kMasterProcessIdentifier != kFirstSlaveProcessIdentifier, // |MasterConnectionManager::Helper| is not thread-safe, and must only be used // on its |owner_|'s private thread. -class MasterConnectionManager::Helper : public RawChannel::Delegate { +class MasterConnectionManager::Helper final : public RawChannel::Delegate { public: Helper(MasterConnectionManager* owner, ProcessIdentifier process_identifier, @@ -61,7 +62,7 @@ class MasterConnectionManager::Helper : public RawChannel::Delegate { embedder::SlaveInfo const slave_info_; scoped_ptr raw_channel_; - DISALLOW_COPY_AND_ASSIGN(Helper); + MOJO_DISALLOW_COPY_AND_ASSIGN(Helper); }; MasterConnectionManager::Helper::Helper( diff --git a/third_party/mojo/src/mojo/edk/system/master_connection_manager.h b/third_party/mojo/src/mojo/edk/system/master_connection_manager.h index 49fd17bee1bd3e..b7992c8846364e 100644 --- a/third_party/mojo/src/mojo/edk/system/master_connection_manager.h +++ b/third_party/mojo/src/mojo/edk/system/master_connection_manager.h @@ -8,13 +8,13 @@ #include #include "base/containers/hash_tables.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/lock.h" #include "base/threading/thread.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/system/connection_manager.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace base { class TaskRunner; @@ -36,7 +36,7 @@ namespace system { // its internal, private thread), with condition that |Init()| be called before // anything else and |Shutdown()| be called before destruction (and no other // public methods may be called during/after |Shutdown()|). -class MOJO_SYSTEM_IMPL_EXPORT MasterConnectionManager +class MOJO_SYSTEM_IMPL_EXPORT MasterConnectionManager final : public ConnectionManager { public: // Note: None of the public methods may be called from |private_thread_|. @@ -142,7 +142,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MasterConnectionManager base::hash_map pending_connections_; // Owns its values. - DISALLOW_COPY_AND_ASSIGN(MasterConnectionManager); + MOJO_DISALLOW_COPY_AND_ASSIGN(MasterConnectionManager); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/memory.h b/third_party/mojo/src/mojo/edk/system/memory.h index 2f1bde450e1e36..31d67cc94d84d3 100644 --- a/third_party/mojo/src/mojo/edk/system/memory.h +++ b/third_party/mojo/src/mojo/edk/system/memory.h @@ -9,10 +9,10 @@ #include #include // For |memcpy()|. -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/macros.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -307,7 +307,7 @@ class UserPointerReader { scoped_ptr buffer_; - DISALLOW_COPY_AND_ASSIGN(UserPointerReader); + MOJO_DISALLOW_COPY_AND_ASSIGN(UserPointerReader); }; // Implementation of |UserPointer::Writer|. @@ -336,7 +336,7 @@ class UserPointerWriter { size_t count_; scoped_ptr buffer_; - DISALLOW_COPY_AND_ASSIGN(UserPointerWriter); + MOJO_DISALLOW_COPY_AND_ASSIGN(UserPointerWriter); }; // Implementation of |UserPointer::ReaderWriter|. @@ -368,7 +368,7 @@ class UserPointerReaderWriter { size_t count_; scoped_ptr buffer_; - DISALLOW_COPY_AND_ASSIGN(UserPointerReaderWriter); + MOJO_DISALLOW_COPY_AND_ASSIGN(UserPointerReaderWriter); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/message_in_transit.cc b/third_party/mojo/src/mojo/edk/system/message_in_transit.cc index 490933624d1679..7ac54e1afdfe82 100644 --- a/third_party/mojo/src/mojo/edk/system/message_in_transit.cc +++ b/third_party/mojo/src/mojo/edk/system/message_in_transit.cc @@ -8,7 +8,6 @@ #include -#include "base/compiler_specific.h" #include "base/logging.h" #include "mojo/edk/system/configuration.h" #include "mojo/edk/system/transport_data.h" @@ -16,7 +15,8 @@ namespace mojo { namespace system { -STATIC_CONST_MEMBER_DEFINITION const size_t MessageInTransit::kMessageAlignment; +MOJO_STATIC_CONST_MEMBER_DEFINITION const size_t + MessageInTransit::kMessageAlignment; struct MessageInTransit::PrivateStructForCompileAsserts { // The size of |Header| must be a multiple of the alignment. diff --git a/third_party/mojo/src/mojo/edk/system/message_in_transit.h b/third_party/mojo/src/mojo/edk/system/message_in_transit.h index 7e79c48f91b2df..063c8d61f6c5fa 100644 --- a/third_party/mojo/src/mojo/edk/system/message_in_transit.h +++ b/third_party/mojo/src/mojo/edk/system/message_in_transit.h @@ -11,13 +11,13 @@ #include #include -#include "base/macros.h" #include "base/memory/aligned_memory.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/channel_endpoint_id.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/memory.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -150,7 +150,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessageInTransit { // Though this struct is trivial, disallow copy and assign, since it doesn't // own its data. (If you're copying/assigning this, you're probably doing // something wrong.) - DISALLOW_COPY_AND_ASSIGN(View); + MOJO_DISALLOW_COPY_AND_ASSIGN(View); }; // |bytes| is optional; if null, the message data will be zero-initialized. @@ -281,7 +281,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessageInTransit { // some reason.) scoped_ptr dispatchers_; - DISALLOW_COPY_AND_ASSIGN(MessageInTransit); + MOJO_DISALLOW_COPY_AND_ASSIGN(MessageInTransit); }; // So logging macros and |DCHECK_EQ()|, etc. work. diff --git a/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.cc b/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.cc index ab5195ef3cd43b..1307135d063c4d 100644 --- a/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.cc +++ b/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.cc @@ -5,7 +5,6 @@ #include "mojo/edk/system/message_in_transit_queue.h" #include "base/logging.h" -#include "base/stl_util.h" namespace mojo { namespace system { @@ -21,7 +20,9 @@ MessageInTransitQueue::~MessageInTransitQueue() { } void MessageInTransitQueue::Clear() { - STLDeleteElements(&queue_); + for (auto* message : queue_) + delete message; + queue_.clear(); } void MessageInTransitQueue::Swap(MessageInTransitQueue* other) { diff --git a/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.h b/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.h index f636aef459a2dd..f7464bd6272476 100644 --- a/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.h +++ b/third_party/mojo/src/mojo/edk/system/message_in_transit_queue.h @@ -7,10 +7,10 @@ #include -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/message_in_transit.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -35,6 +35,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessageInTransitQueue { return make_scoped_ptr(rv); } + const MessageInTransit* PeekMessage() const { return queue_.front(); } MessageInTransit* PeekMessage() { return queue_.front(); } void DiscardMessage() { @@ -52,7 +53,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessageInTransitQueue { // |scoped_ptr|/|unique_ptr|s. std::deque queue_; - DISALLOW_COPY_AND_ASSIGN(MessageInTransitQueue); + MOJO_DISALLOW_COPY_AND_ASSIGN(MessageInTransitQueue); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.cc b/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.cc index a8717d607f640f..0d7cc2425fd3d2 100644 --- a/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.cc +++ b/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.cc @@ -17,7 +17,7 @@ scoped_ptr MakeTestMessage(unsigned id) { static_cast(sizeof(id)), &id)); } -void VerifyTestMessage(MessageInTransit* message, unsigned id) { +void VerifyTestMessage(const MessageInTransit* message, unsigned id) { ASSERT_TRUE(message); EXPECT_EQ(MessageInTransit::Type::ENDPOINT_CLIENT, message->type()); EXPECT_EQ(MessageInTransit::Subtype::ENDPOINT_CLIENT_DATA, diff --git a/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.h b/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.h index cfcc8cf50d5b5f..283783871ff76a 100644 --- a/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.h +++ b/third_party/mojo/src/mojo/edk/system/message_in_transit_test_utils.h @@ -21,7 +21,7 @@ scoped_ptr MakeTestMessage(unsigned id); // Verifies a test message: ASSERTs that |message| is non-null, and EXPECTs that // it looks like a message created using |MakeTestMessage(id)| (see above). -void VerifyTestMessage(MessageInTransit* message, unsigned id); +void VerifyTestMessage(const MessageInTransit* message, unsigned id); // Checks if |message| looks like a test message created using // |MakeTestMessage()|, in which case it returns true and sets |*id|. (Otherwise diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe.h b/third_party/mojo/src/mojo/edk/system/message_pipe.h index df0501484e5715..8a843885f24339 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe.h +++ b/third_party/mojo/src/mojo/edk/system/message_pipe.h @@ -10,7 +10,6 @@ #include -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" @@ -24,6 +23,7 @@ #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/message_pipe.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -36,7 +36,7 @@ class MessageInTransitQueue; // |MessagePipe| is the secondary object implementing a message pipe (see the // explanatory comment in core.cc). It is typically owned by the dispatcher(s) // corresponding to the local endpoints. This class is thread-safe. -class MOJO_SYSTEM_IMPL_EXPORT MessagePipe : public ChannelEndpointClient { +class MOJO_SYSTEM_IMPL_EXPORT MessagePipe final : public ChannelEndpointClient { public: // Creates a |MessagePipe| with two new |LocalMessagePipeEndpoint|s. static MessagePipe* CreateLocalLocal(); @@ -139,7 +139,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipe : public ChannelEndpointClient { base::Lock lock_; // Protects the following members. scoped_ptr endpoints_[2]; - DISALLOW_COPY_AND_ASSIGN(MessagePipe); + MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipe); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.cc b/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.cc index 95faede941721e..ddbe863dc05adc 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.cc +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.cc @@ -25,11 +25,6 @@ const MojoCreateMessagePipeOptions static_cast(sizeof(MojoCreateMessagePipeOptions)), MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE}; -MessagePipeDispatcher::MessagePipeDispatcher( - const MojoCreateMessagePipeOptions& /*validated_options*/) - : port_(kInvalidPort) { -} - // static MojoResult MessagePipeDispatcher::ValidateCreateOptions( UserPointer in_options, @@ -77,8 +72,8 @@ MessagePipeDispatcher::CreateRemoteMessagePipe( scoped_refptr* channel_endpoint) { scoped_refptr message_pipe( MessagePipe::CreateLocalProxy(channel_endpoint)); - scoped_refptr dispatcher( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr dispatcher = + Create(kDefaultCreateOptions); dispatcher->Init(message_pipe, 0); return dispatcher; } @@ -95,12 +90,15 @@ scoped_refptr MessagePipeDispatcher::Deserialize( DCHECK(message_pipe); DCHECK(port == 0 || port == 1); - scoped_refptr dispatcher( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr dispatcher = + Create(kDefaultCreateOptions); dispatcher->Init(message_pipe, port); return dispatcher; } +MessagePipeDispatcher::MessagePipeDispatcher() : port_(kInvalidPort) { +} + MessagePipeDispatcher::~MessagePipeDispatcher() { // |Close()|/|CloseImplNoLock()| should have taken care of the pipe. DCHECK(!message_pipe_); @@ -135,8 +133,7 @@ MessagePipeDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { // TODO(vtl): Currently, there are no options, so we just use // |kDefaultCreateOptions|. Eventually, we'll have to duplicate the options // too. - scoped_refptr rv = - new MessagePipeDispatcher(kDefaultCreateOptions); + scoped_refptr rv = Create(kDefaultCreateOptions); rv->Init(message_pipe_, port_); message_pipe_ = nullptr; port_ = kInvalidPort; diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h b/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h index fb16dd3f22d125..9df5fed5332518 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher.h @@ -5,11 +5,11 @@ #ifndef MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ #define MOJO_EDK_SYSTEM_MESSAGE_PIPE_DISPATCHER_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/memory.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -20,15 +20,17 @@ class MessagePipeDispatcherTransport; // This is the |Dispatcher| implementation for message pipes (created by the // Mojo primitive |MojoCreateMessagePipe()|). This class is thread-safe. -class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher : public Dispatcher { +class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher final : public Dispatcher { public: // The default options to use for |MojoCreateMessagePipe()|. (Real uses // should obtain this via |ValidateCreateOptions()| with a null |in_options|; // this is exposed directly for testing convenience.) static const MojoCreateMessagePipeOptions kDefaultCreateOptions; - MessagePipeDispatcher( - const MojoCreateMessagePipeOptions& /*validated_options*/); + static scoped_refptr Create( + const MojoCreateMessagePipeOptions& /*validated_options*/) { + return make_scoped_refptr(new MessagePipeDispatcher()); + } // Validates and/or sets default options for |MojoCreateMessagePipeOptions|. // If non-null, |in_options| must point to a struct of at least @@ -62,6 +64,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher : public Dispatcher { private: friend class MessagePipeDispatcherTransport; + MessagePipeDispatcher(); ~MessagePipeDispatcher() override; // Gets a dumb pointer to |message_pipe_|. This must be called under the @@ -107,7 +110,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipeDispatcher : public Dispatcher { scoped_refptr message_pipe_; // This will be null if closed. unsigned port_; - DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); }; class MessagePipeDispatcherTransport : public DispatcherTransport { diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher_unittest.cc b/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher_unittest.cc index 55aedb38921359..f93cd9065b3718 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_dispatcher_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a -// heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to +// heavily-loaded system). Sorry. |test::EpsilonDeadline()| may be increased to // increase tolerance and reduce observed flakiness (though doing so reduces the // meaningfulness of the test). @@ -16,13 +16,12 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_vector.h" #include "base/rand_util.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. #include "base/threading/simple_thread.h" -#include "base/time/time.h" #include "mojo/edk/system/message_pipe.h" #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" #include "mojo/edk/system/waiter_test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -41,11 +40,11 @@ TEST(MessagePipeDispatcherTest, Basic) { // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. for (unsigned i = 0; i < 2; i++) { - scoped_refptr d0(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d0 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); EXPECT_EQ(Dispatcher::Type::MESSAGE_PIPE, d0->GetType()); - scoped_refptr d1(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d1 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); { scoped_refptr mp(MessagePipe::CreateLocalLocal()); d0->Init(mp, i); // 0, 1. @@ -76,7 +75,7 @@ TEST(MessagePipeDispatcherTest, Basic) { stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); EXPECT_EQ(1u, context); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); hss = HandleSignalsState(); d0->RemoveAwakable(&w, &hss); EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, @@ -109,7 +108,7 @@ TEST(MessagePipeDispatcherTest, Basic) { d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); hss = HandleSignalsState(); d0->RemoveAwakable(&w, &hss); EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); @@ -121,10 +120,10 @@ TEST(MessagePipeDispatcherTest, Basic) { d0->AddAwakable(&w, MOJO_HANDLE_SIGNAL_READABLE, 3, nullptr)); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, - w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), nullptr)); - base::TimeDelta elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + w.Wait(2 * test::EpsilonDeadline(), nullptr)); + MojoDeadline elapsed = stopwatch.Elapsed(); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); hss = HandleSignalsState(); d0->RemoveAwakable(&w, &hss); EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); @@ -153,10 +152,10 @@ TEST(MessagePipeDispatcherTest, Basic) { TEST(MessagePipeDispatcherTest, InvalidParams) { char buffer[1]; - scoped_refptr d0( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); - scoped_refptr d1( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d0 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + scoped_refptr d1 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); { scoped_refptr mp(MessagePipe::CreateLocalLocal()); d0->Init(mp, 0); @@ -183,10 +182,10 @@ TEST(MessagePipeDispatcherTest, InvalidParams) { TEST(MessagePipeDispatcherTest, InvalidParamsDeath) { const char kMemoryCheckFailedRegex[] = "Check failed"; - scoped_refptr d0( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); - scoped_refptr d1( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d0 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + scoped_refptr d1 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); { scoped_refptr mp(MessagePipe::CreateLocalLocal()); d0->Init(mp, 0); @@ -223,10 +222,10 @@ TEST(MessagePipeDispatcherTest, BasicClosed) { // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. for (unsigned i = 0; i < 2; i++) { - scoped_refptr d0(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); - scoped_refptr d1(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d0 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + scoped_refptr d1 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); { scoped_refptr mp(MessagePipe::CreateLocalLocal()); d0->Init(mp, i); // 0, 1. @@ -351,7 +350,7 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { int32_t buffer[1]; const uint32_t kBufferSize = static_cast(sizeof(buffer)); uint32_t buffer_size; - base::TimeDelta elapsed; + MojoDeadline elapsed; bool did_wait; MojoResult result; uint32_t context; @@ -359,10 +358,10 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { // Run this test both with |d0| as port 0, |d1| as port 1 and vice versa. for (unsigned i = 0; i < 2; i++) { - scoped_refptr d0(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); - scoped_refptr d1(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d0 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + scoped_refptr d1 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); { scoped_refptr mp(MessagePipe::CreateLocalLocal()); d0->Init(mp, i); // 0, 1. @@ -376,7 +375,7 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { &context, &hss); stopwatch.Start(); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); // Wake it up by writing to |d0|. buffer[0] = 123456789; EXPECT_EQ(MOJO_RESULT_OK, @@ -384,8 +383,8 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { nullptr, MOJO_WRITE_MESSAGE_FLAG_NONE)); } // Joins the thread. elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_TRUE(did_wait); EXPECT_EQ(MOJO_RESULT_OK, result); EXPECT_EQ(1u, context); @@ -401,7 +400,7 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { stopwatch.Start(); thread.Start(); } // Joins the thread. - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_FALSE(did_wait); EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, @@ -426,12 +425,12 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { &context, &hss); stopwatch.Start(); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); EXPECT_EQ(MOJO_RESULT_OK, d0->Close()); } // Joins the thread. elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_TRUE(did_wait); EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); EXPECT_EQ(3u, context); @@ -442,10 +441,10 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { } for (unsigned i = 0; i < 2; i++) { - scoped_refptr d0(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); - scoped_refptr d1(new MessagePipeDispatcher( - MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d0 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + scoped_refptr d1 = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); { scoped_refptr mp(MessagePipe::CreateLocalLocal()); d0->Init(mp, i); // 0, 1. @@ -460,12 +459,12 @@ TEST(MessagePipeDispatcherTest, MAYBE_BasicThreaded) { &context, &hss); stopwatch.Start(); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); } // Joins the thread. elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_TRUE(did_wait); EXPECT_EQ(MOJO_RESULT_CANCELLED, result); EXPECT_EQ(4u, context); @@ -528,7 +527,7 @@ class WriterThread : public base::SimpleThread { size_t* const messages_written_; size_t* const bytes_written_; - DISALLOW_COPY_AND_ASSIGN(WriterThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(WriterThread); }; class ReaderThread : public base::SimpleThread { @@ -615,17 +614,17 @@ class ReaderThread : public base::SimpleThread { size_t* const messages_read_; size_t* const bytes_read_; - DISALLOW_COPY_AND_ASSIGN(ReaderThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(ReaderThread); }; TEST(MessagePipeDispatcherTest, Stress) { static const size_t kNumWriters = 30; static const size_t kNumReaders = kNumWriters; - scoped_refptr d_write( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); - scoped_refptr d_read( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr d_write = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); + scoped_refptr d_read = MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); { scoped_refptr mp(MessagePipe::CreateLocalLocal()); d_write->Init(mp, 0); diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_endpoint.h b/third_party/mojo/src/mojo/edk/system/message_pipe_endpoint.h index 0b5f12eb7ff548..73d9a920a895fb 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_endpoint.h +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_endpoint.h @@ -9,7 +9,6 @@ #include -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/dispatcher.h" @@ -18,6 +17,7 @@ #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/message_pipe.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -81,7 +81,7 @@ class MOJO_SYSTEM_IMPL_EXPORT MessagePipeEndpoint { MessagePipeEndpoint() {} private: - DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint); + MOJO_DISALLOW_COPY_AND_ASSIGN(MessagePipeEndpoint); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_perftest.cc b/third_party/mojo/src/mojo/edk/system/message_pipe_perftest.cc index 3b22480f15f466..562acbd9f8a816 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_perftest.cc +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_perftest.cc @@ -12,11 +12,8 @@ #include "base/bind.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" -#include "base/pickle.h" #include "base/strings/stringprintf.h" #include "base/test/perf_time_logger.h" -#include "base/time/time.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/system/channel.h" #include "mojo/edk/system/local_message_pipe_endpoint.h" @@ -40,8 +37,7 @@ class MultiprocessMessagePipePerfTest void SetUpMeasurement(int message_count, size_t message_size) { message_count_ = message_count; message_size_ = message_size; - payload_ = base::Pickle(); - payload_.WriteString(std::string(message_size, '*')); + payload_ = std::string(message_size, '*'); read_buffer_.resize(message_size * 2); } @@ -86,7 +82,7 @@ class MultiprocessMessagePipePerfTest private: int message_count_; size_t message_size_; - base::Pickle payload_; + std::string payload_; std::string read_buffer_; scoped_ptr perf_logger_; }; @@ -123,8 +119,8 @@ MOJO_MULTIPROCESS_TEST_CHILD_MAIN(PingPongClient) { MOJO_READ_MESSAGE_FLAG_NONE), MOJO_RESULT_OK); - // Empty message indicates quitting - if (0 == read_size) + // Empty message indicates quit. + if (read_size == 0) break; CHECK_EQ(mp->WriteMessage(0, UserPointer(&buffer[0]), diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.cc b/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.cc index f227543fea28c7..efbae9593808ca 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.cc +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.cc @@ -5,10 +5,10 @@ #include "mojo/edk/system/message_pipe_test_utils.h" #include "base/bind.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. #include "mojo/edk/system/channel.h" #include "mojo/edk/system/channel_endpoint.h" #include "mojo/edk/system/message_pipe.h" +#include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" namespace mojo { @@ -57,7 +57,7 @@ void ChannelThread::Stop() { // TODO(vtl): Remove this once |Channel| has a // |FlushWriteBufferAndShutdown()| (or whatever). while (!channel_->IsWriteBufferEmpty()) - base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); + test::Sleep(test::DeadlineFromMilliseconds(20)); test_io_thread_.PostTaskAndWait( FROM_HERE, base::Bind(&ChannelThread::ShutdownChannelOnIOThread, diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.h b/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.h index c9d9c8bb75f3f0..3e8e0050a2ad80 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.h +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_test_utils.h @@ -10,6 +10,7 @@ #include "mojo/edk/system/channel.h" #include "mojo/edk/system/test_utils.h" #include "mojo/edk/test/multiprocess_test_helper.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -42,7 +43,7 @@ class ChannelThread { base::TestIOThread test_io_thread_; scoped_refptr channel_; - DISALLOW_COPY_AND_ASSIGN(ChannelThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelThread); }; #if !defined(OS_IOS) @@ -62,7 +63,7 @@ class MultiprocessMessagePipeTestBase : public testing::Test { ChannelThread channel_thread_; mojo::test::MultiprocessTestHelper helper_; - DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTestBase); + MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessMessagePipeTestBase); }; #endif diff --git a/third_party/mojo/src/mojo/edk/system/message_pipe_unittest.cc b/third_party/mojo/src/mojo/edk/system/message_pipe_unittest.cc index a30b63663d2968..52ace8046b458a 100644 --- a/third_party/mojo/src/mojo/edk/system/message_pipe_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/message_pipe_unittest.cc @@ -5,8 +5,6 @@ #include "mojo/edk/system/message_pipe.h" #include "base/memory/ref_counted.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. -#include "base/time/time.h" #include "mojo/edk/system/waiter.h" #include "mojo/edk/system/waiter_test_utils.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/third_party/mojo/src/mojo/edk/system/multiprocess_message_pipe_unittest.cc b/third_party/mojo/src/mojo/edk/system/multiprocess_message_pipe_unittest.cc index ed2f30f2d91ca4..4f28bc5e9a48a9 100644 --- a/third_party/mojo/src/mojo/edk/system/multiprocess_message_pipe_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/multiprocess_message_pipe_unittest.cc @@ -16,7 +16,6 @@ #include "base/files/scoped_temp_dir.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "build/build_config.h" // TODO(vtl): Remove this. #include "mojo/edk/embedder/platform_shared_buffer.h" #include "mojo/edk/embedder/scoped_platform_handle.h" @@ -471,9 +470,9 @@ TEST_P(MultiprocessMessagePipeTestWithPipeCount, PlatformHandlePassing) { fflush(fp.get()); rewind(fp.get()); - scoped_refptr dispatcher( - new PlatformHandleDispatcher(embedder::ScopedPlatformHandle( - mojo::test::PlatformHandleFromFILE(fp.Pass())))); + scoped_refptr dispatcher = + PlatformHandleDispatcher::Create(embedder::ScopedPlatformHandle( + mojo::test::PlatformHandleFromFILE(fp.Pass()))); dispatchers.push_back(dispatcher); DispatcherTransport transport( test::DispatcherTryStartTransport(dispatcher.get())); diff --git a/third_party/mojo/src/mojo/edk/system/options_validation.h b/third_party/mojo/src/mojo/edk/system/options_validation.h index 9724e38b9ca3ab..6a0dae450b8dac 100644 --- a/third_party/mojo/src/mojo/edk/system/options_validation.h +++ b/third_party/mojo/src/mojo/edk/system/options_validation.h @@ -17,10 +17,10 @@ #include #include "base/logging.h" -#include "base/macros.h" #include "mojo/edk/system/memory.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -81,7 +81,7 @@ class UserOptionsReader { UserPointer::Reader options_reader_; - DISALLOW_COPY_AND_ASSIGN(UserOptionsReader); + MOJO_DISALLOW_COPY_AND_ASSIGN(UserOptionsReader); }; // Macro to invoke |UserOptionsReader::HasMember()| parametrized by diff --git a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc index 94e10e2fec5844..d33c960c2924d4 100644 --- a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc +++ b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc @@ -21,11 +21,6 @@ struct SerializedPlatformHandleDispatcher { } // namespace -PlatformHandleDispatcher::PlatformHandleDispatcher( - embedder::ScopedPlatformHandle platform_handle) - : platform_handle_(platform_handle.Pass()) { -} - embedder::ScopedPlatformHandle PlatformHandleDispatcher::PassPlatformHandle() { base::AutoLock locker(lock()); return platform_handle_.Pass(); @@ -66,8 +61,12 @@ scoped_refptr PlatformHandleDispatcher::Deserialize( std::swap(platform_handle, (*platform_handles)[platform_handle_index]); } - return scoped_refptr(new PlatformHandleDispatcher( - embedder::ScopedPlatformHandle(platform_handle))); + return Create(embedder::ScopedPlatformHandle(platform_handle)); +} + +PlatformHandleDispatcher::PlatformHandleDispatcher( + embedder::ScopedPlatformHandle platform_handle) + : platform_handle_(platform_handle.Pass()) { } PlatformHandleDispatcher::~PlatformHandleDispatcher() { @@ -81,8 +80,7 @@ void PlatformHandleDispatcher::CloseImplNoLock() { scoped_refptr PlatformHandleDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { lock().AssertAcquired(); - return scoped_refptr( - new PlatformHandleDispatcher(platform_handle_.Pass())); + return Create(platform_handle_.Pass()); } void PlatformHandleDispatcher::StartSerializeImplNoLock( diff --git a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.h b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.h index 6eb56b72f650ea..9e2e37d7aeb21c 100644 --- a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.h +++ b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.h @@ -5,21 +5,24 @@ #ifndef MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ #define MOJO_EDK_SYSTEM_PLATFORM_HANDLE_DISPATCHER_H_ -#include "base/macros.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/system/simple_dispatcher.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { // A dispatcher that simply wraps/transports a |PlatformHandle| (only for use by // the embedder). -class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher +class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher final : public SimpleDispatcher { public: - explicit PlatformHandleDispatcher( - embedder::ScopedPlatformHandle platform_handle); + static scoped_refptr Create( + embedder::ScopedPlatformHandle platform_handle) { + return make_scoped_refptr( + new PlatformHandleDispatcher(platform_handle.Pass())); + } embedder::ScopedPlatformHandle PassPlatformHandle(); @@ -35,6 +38,8 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher embedder::PlatformHandleVector* platform_handles); private: + explicit PlatformHandleDispatcher( + embedder::ScopedPlatformHandle platform_handle); ~PlatformHandleDispatcher() override; // |Dispatcher| protected methods: @@ -52,7 +57,7 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher embedder::ScopedPlatformHandle platform_handle_; - DISALLOW_COPY_AND_ASSIGN(PlatformHandleDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformHandleDispatcher); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher_unittest.cc b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher_unittest.cc index 3b37b721723472..55887a79704c97 100644 --- a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher_unittest.cc @@ -36,8 +36,8 @@ TEST(PlatformHandleDispatcherTest, Basic) { EXPECT_FALSE(fp); ASSERT_TRUE(h.is_valid()); - scoped_refptr dispatcher( - new PlatformHandleDispatcher(h.Pass())); + scoped_refptr dispatcher = + PlatformHandleDispatcher::Create(h.Pass()); EXPECT_FALSE(h.is_valid()); EXPECT_EQ(Dispatcher::Type::PLATFORM_HANDLE, dispatcher->GetType()); @@ -72,9 +72,9 @@ TEST(PlatformHandleDispatcherTest, CreateEquivalentDispatcherAndClose) { CreateAndOpenTemporaryFileInDir(temp_dir.path(), &unused)); EXPECT_EQ(sizeof(kFooBar), fwrite(kFooBar, 1, sizeof(kFooBar), fp.get())); - scoped_refptr dispatcher( - new PlatformHandleDispatcher( - mojo::test::PlatformHandleFromFILE(fp.Pass()))); + scoped_refptr dispatcher = + PlatformHandleDispatcher::Create( + mojo::test::PlatformHandleFromFILE(fp.Pass())); DispatcherTransport transport( test::DispatcherTryStartTransport(dispatcher.get())); diff --git a/third_party/mojo/src/mojo/edk/system/proxy_message_pipe_endpoint.h b/third_party/mojo/src/mojo/edk/system/proxy_message_pipe_endpoint.h index 6e106990f35ce8..385379bcca2e51 100644 --- a/third_party/mojo/src/mojo/edk/system/proxy_message_pipe_endpoint.h +++ b/third_party/mojo/src/mojo/edk/system/proxy_message_pipe_endpoint.h @@ -5,11 +5,11 @@ #ifndef MOJO_EDK_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ #define MOJO_EDK_SYSTEM_PROXY_MESSAGE_PIPE_ENDPOINT_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "mojo/edk/system/message_in_transit.h" #include "mojo/edk/system/message_pipe_endpoint.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -27,7 +27,7 @@ class MessagePipe; // remote consists of a |LocalMessagePipeEndpoint| and a // |ProxyMessagePipeEndpoint|, with only the local endpoint being accessible via // a |MessagePipeDispatcher|. -class MOJO_SYSTEM_IMPL_EXPORT ProxyMessagePipeEndpoint +class MOJO_SYSTEM_IMPL_EXPORT ProxyMessagePipeEndpoint final : public MessagePipeEndpoint { public: explicit ProxyMessagePipeEndpoint(ChannelEndpoint* channel_endpoint); @@ -52,7 +52,7 @@ class MOJO_SYSTEM_IMPL_EXPORT ProxyMessagePipeEndpoint scoped_refptr channel_endpoint_; - DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); + MOJO_DISALLOW_COPY_AND_ASSIGN(ProxyMessagePipeEndpoint); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel.cc b/third_party/mojo/src/mojo/edk/system/raw_channel.cc index 2dd4cba0506755..ac9f3ffc32a603 100644 --- a/third_party/mojo/src/mojo/edk/system/raw_channel.cc +++ b/third_party/mojo/src/mojo/edk/system/raw_channel.cc @@ -12,7 +12,6 @@ #include "base/location.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" -#include "base/stl_util.h" #include "mojo/edk/system/message_in_transit.h" #include "mojo/edk/system/transport_data.h" @@ -44,15 +43,15 @@ RawChannel::WriteBuffer::WriteBuffer(size_t serialized_platform_handle_size) } RawChannel::WriteBuffer::~WriteBuffer() { - STLDeleteElements(&message_queue_); + message_queue_.Clear(); } bool RawChannel::WriteBuffer::HavePlatformHandlesToSend() const { - if (message_queue_.empty()) + if (message_queue_.IsEmpty()) return false; const TransportData* transport_data = - message_queue_.front()->transport_data(); + message_queue_.PeekMessage()->transport_data(); if (!transport_data) return false; @@ -76,7 +75,7 @@ void RawChannel::WriteBuffer::GetPlatformHandlesToSend( void** serialization_data) { DCHECK(HavePlatformHandlesToSend()); - MessageInTransit* message = message_queue_.front(); + MessageInTransit* message = message_queue_.PeekMessage(); TransportData* transport_data = message->transport_data(); embedder::PlatformHandleVector* all_platform_handles = transport_data->platform_handles(); @@ -99,10 +98,10 @@ void RawChannel::WriteBuffer::GetPlatformHandlesToSend( void RawChannel::WriteBuffer::GetBuffers(std::vector* buffers) const { buffers->clear(); - if (message_queue_.empty()) + if (message_queue_.IsEmpty()) return; - MessageInTransit* message = message_queue_.front(); + const MessageInTransit* message = message_queue_.PeekMessage(); DCHECK_LT(data_offset_, message->total_size()); size_t bytes_to_write = message->total_size() - data_offset_; @@ -206,7 +205,7 @@ void RawChannel::Shutdown() { base::AutoLock locker(write_lock_); - LOG_IF(WARNING, !write_buffer_->message_queue_.empty()) + LOG_IF(WARNING, !write_buffer_->message_queue_.IsEmpty()) << "Shutting down RawChannel with write buffer nonempty"; // Reset the delegate so that it won't receive further calls. @@ -229,7 +228,7 @@ bool RawChannel::WriteMessage(scoped_ptr message) { if (write_stopped_) return false; - if (!write_buffer_->message_queue_.empty()) { + if (!write_buffer_->message_queue_.IsEmpty()) { EnqueueMessageNoLock(message.Pass()); return true; } @@ -260,7 +259,7 @@ bool RawChannel::WriteMessage(scoped_ptr message) { // Reminder: This must be thread-safe. bool RawChannel::IsWriteBufferEmpty() { base::AutoLock locker(write_lock_); - return write_buffer_->message_queue_.empty(); + return write_buffer_->message_queue_.IsEmpty(); } void RawChannel::OnReadCompleted(IOResult io_result, size_t bytes_read) { @@ -414,7 +413,7 @@ void RawChannel::OnWriteCompleted(IOResult io_result, bool did_fail = false; { base::AutoLock locker(write_lock_); - DCHECK_EQ(write_stopped_, write_buffer_->message_queue_.empty()); + DCHECK_EQ(write_stopped_, write_buffer_->message_queue_.IsEmpty()); if (write_stopped_) { NOTREACHED(); @@ -433,7 +432,7 @@ void RawChannel::OnWriteCompleted(IOResult io_result, void RawChannel::EnqueueMessageNoLock(scoped_ptr message) { write_lock_.AssertAcquired(); - write_buffer_->message_queue_.push_back(message.release()); + write_buffer_->message_queue_.AddMessage(message.Pass()); } bool RawChannel::OnReadMessageForRawChannel( @@ -477,22 +476,21 @@ bool RawChannel::OnWriteCompletedNoLock(IOResult io_result, write_lock_.AssertAcquired(); DCHECK(!write_stopped_); - DCHECK(!write_buffer_->message_queue_.empty()); + DCHECK(!write_buffer_->message_queue_.IsEmpty()); if (io_result == IO_SUCCEEDED) { write_buffer_->platform_handles_offset_ += platform_handles_written; write_buffer_->data_offset_ += bytes_written; - MessageInTransit* message = write_buffer_->message_queue_.front(); + MessageInTransit* message = write_buffer_->message_queue_.PeekMessage(); if (write_buffer_->data_offset_ >= message->total_size()) { // Complete write. CHECK_EQ(write_buffer_->data_offset_, message->total_size()); - write_buffer_->message_queue_.pop_front(); - delete message; + write_buffer_->message_queue_.DiscardMessage(); write_buffer_->platform_handles_offset_ = 0; write_buffer_->data_offset_ = 0; - if (write_buffer_->message_queue_.empty()) + if (write_buffer_->message_queue_.IsEmpty()) return true; } @@ -504,7 +502,7 @@ bool RawChannel::OnWriteCompletedNoLock(IOResult io_result, } write_stopped_ = true; - STLDeleteElements(&write_buffer_->message_queue_); + write_buffer_->message_queue_.Clear(); write_buffer_->platform_handles_offset_ = 0; write_buffer_->data_offset_ = 0; return false; diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel.h b/third_party/mojo/src/mojo/edk/system/raw_channel.h index 91feaab48afbe7..cbcc1b3fc63d54 100644 --- a/third_party/mojo/src/mojo/edk/system/raw_channel.h +++ b/third_party/mojo/src/mojo/edk/system/raw_channel.h @@ -5,17 +5,17 @@ #ifndef MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ #define MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ -#include #include -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #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/message_in_transit.h" +#include "mojo/edk/system/message_in_transit_queue.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace base { class MessageLoopForIO; @@ -142,7 +142,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { std::vector buffer_; size_t num_valid_bytes_; - DISALLOW_COPY_AND_ASSIGN(ReadBuffer); + MOJO_DISALLOW_COPY_AND_ASSIGN(ReadBuffer); }; class MOJO_SYSTEM_IMPL_EXPORT WriteBuffer { @@ -166,6 +166,9 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { // |GetSerializedPlatformHandleSize()| bytes per handle). Once all platform // handles have been sent, the message data should be written next (see // |GetBuffers()|). + // TODO(vtl): Maybe this method should be const, but + // |PlatformHandle::CloseIfNecessary()| isn't const (and actually modifies + // state). void GetPlatformHandlesToSend(size_t* num_platform_handles, embedder::PlatformHandle** platform_handles, void** serialization_data); @@ -181,9 +184,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { const size_t serialized_platform_handle_size_; - // TODO(vtl): When C++11 is available, switch this to a deque of - // |scoped_ptr|/|unique_ptr|s. - std::deque message_queue_; + MessageInTransitQueue message_queue_; // Platform handles are sent before the message data, but doing so may // require several passes. |platform_handles_offset_| indicates the position // in the first message's vector of platform handles to send next. @@ -193,7 +194,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { // write. size_t data_offset_; - DISALLOW_COPY_AND_ASSIGN(WriteBuffer); + MOJO_DISALLOW_COPY_AND_ASSIGN(WriteBuffer); }; RawChannel(); @@ -323,7 +324,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RawChannel { // are only used/invalidated on the I/O thread. base::WeakPtrFactory weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(RawChannel); + MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannel); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel_posix.cc b/third_party/mojo/src/mojo/edk/system/raw_channel_posix.cc index c14fa6b1684934..47862a709f6911 100644 --- a/third_party/mojo/src/mojo/edk/system/raw_channel_posix.cc +++ b/third_party/mojo/src/mojo/edk/system/raw_channel_posix.cc @@ -14,7 +14,6 @@ #include "base/bind.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/message_loop/message_loop.h" @@ -23,14 +22,15 @@ #include "mojo/edk/embedder/platform_handle.h" #include "mojo/edk/embedder/platform_handle_vector.h" #include "mojo/edk/system/transport_data.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { namespace { -class RawChannelPosix : public RawChannel, - public base::MessageLoopForIO::Watcher { +class RawChannelPosix final : public RawChannel, + public base::MessageLoopForIO::Watcher { public: explicit RawChannelPosix(embedder::ScopedPlatformHandle handle); ~RawChannelPosix() override; @@ -87,7 +87,7 @@ class RawChannelPosix : public RawChannel, // are only used/invalidated on the I/O thread. base::WeakPtrFactory weak_ptr_factory_; - DISALLOW_COPY_AND_ASSIGN(RawChannelPosix); + MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelPosix); }; RawChannelPosix::RawChannelPosix(embedder::ScopedPlatformHandle handle) diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc b/third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc index 6935845a49ce4f..bc27889d30ed05 100644 --- a/third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/raw_channel_unittest.cc @@ -16,16 +16,13 @@ #include "base/files/scoped_temp_dir.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/memory/scoped_vector.h" #include "base/rand_util.h" #include "base/synchronization/lock.h" #include "base/synchronization/waitable_event.h" #include "base/test/test_io_thread.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. #include "base/threading/simple_thread.h" -#include "base/time/time.h" #include "build/build_config.h" // TODO(vtl): Remove this. #include "mojo/edk/embedder/platform_channel_pair.h" #include "mojo/edk/embedder/platform_handle.h" @@ -34,6 +31,7 @@ #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/transport_data.h" #include "mojo/edk/test/test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -101,7 +99,7 @@ class RawChannelTest : public testing::Test { private: base::TestIOThread io_thread_; - DISALLOW_COPY_AND_ASSIGN(RawChannelTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelTest); }; // RawChannelTest.WriteMessage ------------------------------------------------- @@ -123,10 +121,10 @@ class WriteOnlyRawChannelDelegate : public RawChannel::Delegate { } private: - DISALLOW_COPY_AND_ASSIGN(WriteOnlyRawChannelDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(WriteOnlyRawChannelDelegate); }; -static const int64_t kMessageReaderSleepMs = 1; +static const unsigned kMessageReaderSleepMs = 1; static const size_t kMessageReaderMaxPollIterations = 3000; class TestMessageReaderAndChecker { @@ -176,8 +174,7 @@ class TestMessageReaderAndChecker { if (static_cast(read_size) < sizeof(buffer)) { i++; - base::PlatformThread::Sleep( - base::TimeDelta::FromMilliseconds(kMessageReaderSleepMs)); + test::Sleep(test::DeadlineFromMilliseconds(kMessageReaderSleepMs)); } } @@ -191,7 +188,7 @@ class TestMessageReaderAndChecker { // The start of the received data should always be on a message boundary. std::vector bytes_; - DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestMessageReaderAndChecker); }; // Tests writing (and verifies reading using our own custom reader). @@ -277,7 +274,7 @@ class ReadCheckerRawChannelDelegate : public RawChannel::Delegate { std::vector expected_sizes_; size_t position_; - DISALLOW_COPY_AND_ASSIGN(ReadCheckerRawChannelDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(ReadCheckerRawChannelDelegate); }; // Tests reading (writing using our own custom writer). @@ -335,7 +332,7 @@ class RawChannelWriterThread : public base::SimpleThread { RawChannel* const raw_channel_; size_t left_to_write_; - DISALLOW_COPY_AND_ASSIGN(RawChannelWriterThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelWriterThread); }; class ReadCountdownRawChannelDelegate : public RawChannel::Delegate { @@ -372,7 +369,7 @@ class ReadCountdownRawChannelDelegate : public RawChannel::Delegate { size_t expected_count_; size_t count_; - DISALLOW_COPY_AND_ASSIGN(ReadCountdownRawChannelDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(ReadCountdownRawChannelDelegate); }; TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { @@ -404,7 +401,7 @@ TEST_F(RawChannelTest, WriteMessageAndOnReadMessage) { // Sleep a bit, to let any extraneous reads be processed. (There shouldn't be // any, but we want to know about them.) - base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); + test::Sleep(test::DeadlineFromMilliseconds(100)); // Wait for reading to finish. reader_delegate.Wait(); @@ -471,7 +468,7 @@ class ErrorRecordingRawChannelDelegate bool expecting_read_error_; bool expecting_write_error_; - DISALLOW_COPY_AND_ASSIGN(ErrorRecordingRawChannelDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(ErrorRecordingRawChannelDelegate); }; // Tests (fatal) errors. @@ -497,7 +494,7 @@ TEST_F(RawChannelTest, OnError) { // Sleep a bit, to make sure we don't get another |OnError()| // notification. (If we actually get another one, |OnError()| crashes.) - base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); + test::Sleep(test::DeadlineFromMilliseconds(20)); io_thread()->PostTaskAndWait( FROM_HERE, base::Bind(&RawChannel::Shutdown, base::Unretained(rc.get()))); @@ -598,7 +595,7 @@ class ShutdownOnReadMessageRawChannelDelegate : public RawChannel::Delegate { base::WaitableEvent done_event_; bool did_shutdown_; - DISALLOW_COPY_AND_ASSIGN(ShutdownOnReadMessageRawChannelDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnReadMessageRawChannelDelegate); }; TEST_F(RawChannelTest, ShutdownOnReadMessage) { @@ -674,7 +671,7 @@ class ShutdownOnErrorRawChannelDelegate : public RawChannel::Delegate { base::WaitableEvent done_event_; bool did_shutdown_; - DISALLOW_COPY_AND_ASSIGN(ShutdownOnErrorRawChannelDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(ShutdownOnErrorRawChannelDelegate); }; TEST_F(RawChannelTest, ShutdownOnErrorRead) { @@ -795,7 +792,7 @@ class ReadPlatformHandlesCheckerRawChannelDelegate private: base::WaitableEvent done_event_; - DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate); + MOJO_DISALLOW_COPY_AND_ASSIGN(ReadPlatformHandlesCheckerRawChannelDelegate); }; #if defined(OS_POSIX) diff --git a/third_party/mojo/src/mojo/edk/system/raw_channel_win.cc b/third_party/mojo/src/mojo/edk/system/raw_channel_win.cc index 1553b73c62cfa4..10a9bff7baa54d 100644 --- a/third_party/mojo/src/mojo/edk/system/raw_channel_win.cc +++ b/third_party/mojo/src/mojo/edk/system/raw_channel_win.cc @@ -6,19 +6,17 @@ #include -#include "base/auto_reset.h" #include "base/bind.h" -#include "base/compiler_specific.h" #include "base/lazy_instance.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop/message_loop.h" #include "base/process/process.h" #include "base/synchronization/lock.h" #include "base/win/windows_version.h" #include "mojo/edk/embedder/platform_handle.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -70,7 +68,7 @@ VistaOrHigherFunctions::VistaOrHigherFunctions() base::LazyInstance g_vista_or_higher_functions = LAZY_INSTANCE_INITIALIZER; -class RawChannelWin : public RawChannel { +class RawChannelWin final : public RawChannel { public: RawChannelWin(embedder::ScopedPlatformHandle handle); ~RawChannelWin() override; @@ -158,7 +156,7 @@ class RawChannelWin : public RawChannel { size_t platform_handles_written_; base::MessageLoopForIO::IOContext write_context_; - DISALLOW_COPY_AND_ASSIGN(RawChannelIOHandler); + MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelIOHandler); }; // |RawChannel| private methods: @@ -181,7 +179,7 @@ class RawChannelWin : public RawChannel { const bool skip_completion_port_on_success_; - DISALLOW_COPY_AND_ASSIGN(RawChannelWin); + MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannelWin); }; RawChannelWin::RawChannelIOHandler::RawChannelIOHandler( @@ -254,18 +252,20 @@ void RawChannelWin::RawChannelIOHandler::OnIOCompleted( DCHECK(!owner_ || base::MessageLoop::current() == owner_->message_loop_for_io()); - { - // Suppress self-destruction inside |OnReadCompleted()|, etc. (in case they - // result in a call to |Shutdown()|). - base::AutoReset resetter(&suppress_self_destruct_, true); - - if (context == &read_context_) - OnReadCompleted(bytes_transferred, error); - else if (context == &write_context_) - OnWriteCompleted(bytes_transferred, error); - else - NOTREACHED(); - } + // Suppress self-destruction inside |OnReadCompleted()|, etc. (in case they + // result in a call to |Shutdown()|). + bool old_suppress_self_destruct = suppress_self_destruct_; + suppress_self_destruct_ = true; + + if (context == &read_context_) + OnReadCompleted(bytes_transferred, error); + else if (context == &write_context_) + OnWriteCompleted(bytes_transferred, error); + else + NOTREACHED(); + + // Maybe allow self-destruction again. + suppress_self_destruct_ = old_suppress_self_destruct; if (ShouldSelfDestruct()) delete this; diff --git a/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.h b/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.h index 68e856c9eabdbd..dbd1f7b61b2e09 100644 --- a/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.h +++ b/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.h @@ -5,13 +5,13 @@ #ifndef MOJO_EDK_SYSTEM_REMOTE_CONSUMER_DATA_PIPE_IMPL_H_ #define MOJO_EDK_SYSTEM_REMOTE_CONSUMER_DATA_PIPE_IMPL_H_ -#include "base/macros.h" #include "base/memory/aligned_memory.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/channel_endpoint.h" #include "mojo/edk/system/data_pipe_impl.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -19,7 +19,8 @@ namespace system { // |RemoteConsumerDataPipeImpl| is a subclass that "implements" |DataPipe| for // data pipes whose producer is local and whose consumer is remote. See // |DataPipeImpl| for more details. -class MOJO_SYSTEM_IMPL_EXPORT RemoteConsumerDataPipeImpl : public DataPipeImpl { +class MOJO_SYSTEM_IMPL_EXPORT RemoteConsumerDataPipeImpl final + : public DataPipeImpl { public: RemoteConsumerDataPipeImpl(ChannelEndpoint* channel_endpoint, size_t consumer_num_bytes); @@ -98,7 +99,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RemoteConsumerDataPipeImpl : public DataPipeImpl { // Used for two-phase writes. scoped_ptr buffer_; - DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImpl); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImpl); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/remote_data_pipe_impl_unittest.cc b/third_party/mojo/src/mojo/edk/system/remote_data_pipe_impl_unittest.cc index 40d2f6fdb0537e..e6a3179511c043 100644 --- a/third_party/mojo/src/mojo/edk/system/remote_data_pipe_impl_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/remote_data_pipe_impl_unittest.cc @@ -10,10 +10,8 @@ #include "base/bind.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/message_loop/message_loop.h" #include "base/test/test_io_thread.h" -#include "base/test/test_timeouts.h" #include "mojo/edk/embedder/platform_channel_pair.h" #include "mojo/edk/embedder/simple_platform_support.h" #include "mojo/edk/system/channel.h" @@ -26,6 +24,7 @@ #include "mojo/edk/system/raw_channel.h" #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -116,7 +115,7 @@ class RemoteDataPipeImplTest : public testing::Test { scoped_refptr channels_[2]; scoped_refptr message_pipes_[2]; - DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTest); }; // These tests are heavier-weight than ideal. They test remote data pipes by @@ -172,7 +171,7 @@ TEST_F(RemoteDataPipeImplTest, SendConsumerWithClosedProducer) { scoped_refptr dp(CreateLocal(sizeof(int32_t), 1000)); // This is the consumer dispatcher we'll send. scoped_refptr consumer = - new DataPipeConsumerDispatcher(); + DataPipeConsumerDispatcher::Create(); consumer->Init(dp); // Write to the producer and close it, before sending the consumer. diff --git a/third_party/mojo/src/mojo/edk/system/remote_message_pipe_unittest.cc b/third_party/mojo/src/mojo/edk/system/remote_message_pipe_unittest.cc index 6d22da753761b5..b222895469b307 100644 --- a/third_party/mojo/src/mojo/edk/system/remote_message_pipe_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/remote_message_pipe_unittest.cc @@ -15,10 +15,8 @@ #include "base/files/scoped_temp_dir.h" #include "base/location.h" #include "base/logging.h" -#include "base/macros.h" #include "base/message_loop/message_loop.h" #include "base/test/test_io_thread.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. #include "build/build_config.h" // TODO(vtl): Remove this. #include "mojo/edk/embedder/platform_channel_pair.h" #include "mojo/edk/embedder/platform_shared_buffer.h" @@ -36,6 +34,7 @@ #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" #include "mojo/edk/test/test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -165,7 +164,7 @@ class RemoteMessagePipeTest : public testing::Test { embedder::ScopedPlatformHandle platform_handles_[2]; scoped_refptr channels_[2]; - DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); }; TEST_F(RemoteMessagePipeTest, Basic) { @@ -616,8 +615,9 @@ TEST_F(RemoteMessagePipeTest, HandlePassing) { BootstrapChannelEndpoints(ep0, ep1); // We'll try to pass this dispatcher. - scoped_refptr dispatcher( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr dispatcher = + MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); scoped_refptr local_mp(MessagePipe::CreateLocalLocal()); dispatcher->Init(local_mp, 0); @@ -760,8 +760,9 @@ TEST_F(RemoteMessagePipeTest, HandlePassingHalfClosed) { uint32_t context = 0; // We'll try to pass this dispatcher. - scoped_refptr dispatcher( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr dispatcher = + MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); scoped_refptr local_mp(MessagePipe::CreateLocalLocal()); dispatcher->Init(local_mp, 0); @@ -1044,9 +1045,9 @@ TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { EXPECT_EQ(sizeof(kHello), fwrite(kHello, 1, sizeof(kHello), fp.get())); // We'll try to pass this dispatcher, which will cause a |PlatformHandle| to // be passed. - scoped_refptr dispatcher( - new PlatformHandleDispatcher( - mojo::test::PlatformHandleFromFILE(fp.Pass()))); + scoped_refptr dispatcher = + PlatformHandleDispatcher::Create( + mojo::test::PlatformHandleFromFILE(fp.Pass())); // Prepare to wait on MP 1, port 1. (Add the waiter now. Otherwise, if we do // it later, it might already be readable.) @@ -1129,7 +1130,7 @@ TEST_F(RemoteMessagePipeTest, MAYBE_PlatformHandlePassing) { // itself (not in the test). Also, any logged warnings/errors would also // probably be indicative of bugs. TEST_F(RemoteMessagePipeTest, RacingClosesStress) { - base::TimeDelta delay = base::TimeDelta::FromMilliseconds(5); + MojoDeadline delay = test::DeadlineFromMilliseconds(5); for (unsigned i = 0; i < 256; i++) { DVLOG(2) << "---------------------------------------- " << i; @@ -1142,20 +1143,20 @@ TEST_F(RemoteMessagePipeTest, RacingClosesStress) { BootstrapChannelEndpointNoWait(1, ep1); if (i & 1u) { - io_thread()->task_runner()->PostTask( - FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay)); + io_thread()->task_runner()->PostTask(FROM_HERE, + base::Bind(&test::Sleep, delay)); } if (i & 2u) - base::PlatformThread::Sleep(delay); + test::Sleep(delay); mp0->Close(0); if (i & 4u) { - io_thread()->task_runner()->PostTask( - FROM_HERE, base::Bind(&base::PlatformThread::Sleep, delay)); + io_thread()->task_runner()->PostTask(FROM_HERE, + base::Bind(&test::Sleep, delay)); } if (i & 8u) - base::PlatformThread::Sleep(delay); + test::Sleep(delay); mp1->Close(1); @@ -1180,8 +1181,9 @@ TEST_F(RemoteMessagePipeTest, PassMessagePipeHandleAcrossAndBack) { BootstrapChannelEndpoints(ep0, ep1); // We'll try to pass this dispatcher. - scoped_refptr dispatcher( - new MessagePipeDispatcher(MessagePipeDispatcher::kDefaultCreateOptions)); + scoped_refptr dispatcher = + MessagePipeDispatcher::Create( + MessagePipeDispatcher::kDefaultCreateOptions); scoped_refptr local_mp(MessagePipe::CreateLocalLocal()); dispatcher->Init(local_mp, 0); diff --git a/third_party/mojo/src/mojo/edk/system/remote_producer_data_pipe_impl.h b/third_party/mojo/src/mojo/edk/system/remote_producer_data_pipe_impl.h index 77117c58c8e574..49a1a3439992e4 100644 --- a/third_party/mojo/src/mojo/edk/system/remote_producer_data_pipe_impl.h +++ b/third_party/mojo/src/mojo/edk/system/remote_producer_data_pipe_impl.h @@ -5,13 +5,13 @@ #ifndef MOJO_EDK_SYSTEM_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ #define MOJO_EDK_SYSTEM_REMOTE_PRODUCER_DATA_PIPE_IMPL_H_ -#include "base/macros.h" #include "base/memory/aligned_memory.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "mojo/edk/system/channel_endpoint.h" #include "mojo/edk/system/data_pipe_impl.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -21,7 +21,8 @@ class MessageInTransitQueue; // |RemoteProducerDataPipeImpl| is a subclass that "implements" |DataPipe| for // data pipes whose producer is remote and whose consumer is local. See // |DataPipeImpl| for more details. -class MOJO_SYSTEM_IMPL_EXPORT RemoteProducerDataPipeImpl : public DataPipeImpl { +class MOJO_SYSTEM_IMPL_EXPORT RemoteProducerDataPipeImpl final + : public DataPipeImpl { public: explicit RemoteProducerDataPipeImpl(ChannelEndpoint* channel_endpoint); RemoteProducerDataPipeImpl(ChannelEndpoint* channel_endpoint, @@ -111,7 +112,7 @@ class MOJO_SYSTEM_IMPL_EXPORT RemoteProducerDataPipeImpl : public DataPipeImpl { size_t start_index_; size_t current_num_bytes_; - DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImpl); + MOJO_DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImpl); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc index 653c507f2ca4be..8ab8f10684938a 100644 --- a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc +++ b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc @@ -77,7 +77,7 @@ MojoResult SharedBufferDispatcher::Create( if (!shared_buffer) return MOJO_RESULT_RESOURCE_EXHAUSTED; - *result = new SharedBufferDispatcher(shared_buffer); + *result = CreateInternal(shared_buffer.Pass()); return MOJO_RESULT_OK; } @@ -132,8 +132,7 @@ scoped_refptr SharedBufferDispatcher::Deserialize( return nullptr; } - return scoped_refptr( - new SharedBufferDispatcher(shared_buffer)); + return CreateInternal(shared_buffer.Pass()); } SharedBufferDispatcher::SharedBufferDispatcher( @@ -187,9 +186,7 @@ scoped_refptr SharedBufferDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { lock().AssertAcquired(); DCHECK(shared_buffer_); - scoped_refptr shared_buffer; - shared_buffer.swap(shared_buffer_); - return scoped_refptr(new SharedBufferDispatcher(shared_buffer)); + return CreateInternal(shared_buffer_.Pass()); } MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( @@ -202,7 +199,8 @@ MojoResult SharedBufferDispatcher::DuplicateBufferHandleImplNoLock( if (result != MOJO_RESULT_OK) return result; - *new_dispatcher = new SharedBufferDispatcher(shared_buffer_); + // Note: Since this is "duplicate", we keep our ref to |shared_buffer_|. + *new_dispatcher = CreateInternal(shared_buffer_); return MOJO_RESULT_OK; } diff --git a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.h b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.h index db04d2aae8c603..deef5b44728240 100644 --- a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.h +++ b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.h @@ -5,11 +5,11 @@ #ifndef MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_ #define MOJO_EDK_SYSTEM_SHARED_BUFFER_DISPATCHER_H_ -#include "base/macros.h" #include "mojo/edk/embedder/platform_shared_buffer.h" #include "mojo/edk/system/memory.h" #include "mojo/edk/system/simple_dispatcher.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { @@ -22,7 +22,8 @@ namespace system { // TODO(vtl): We derive from SimpleDispatcher, even though we don't currently // have anything that's waitable. I want to add a "transferrable" wait flag // (which would entail overriding |GetHandleSignalsStateImplNoLock()|, etc.). -class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher : public SimpleDispatcher { +class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher final + : public SimpleDispatcher { public: // The default options to use for |MojoCreateSharedBuffer()|. (Real uses // should obtain this via |ValidateCreateOptions()| with a null |in_options|; @@ -40,6 +41,8 @@ class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher : public SimpleDispatcher { // Static factory method: |validated_options| must be validated (obviously). // On failure, |*result| will be left as-is. + // TODO(vtl): This should probably be made to return a scoped_refptr and have + // a MojoResult out parameter instead. static MojoResult Create( embedder::PlatformSupport* platform_support, const MojoCreateSharedBufferOptions& validated_options, @@ -58,8 +61,13 @@ class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher : public SimpleDispatcher { embedder::PlatformHandleVector* platform_handles); private: + static scoped_refptr CreateInternal( + scoped_refptr shared_buffer) { + return make_scoped_refptr(new SharedBufferDispatcher(shared_buffer.Pass())); + } + explicit SharedBufferDispatcher( - scoped_refptr shared_buffer_); + scoped_refptr shared_buffer); ~SharedBufferDispatcher() override; // Validates and/or sets default options for @@ -94,7 +102,7 @@ class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher : public SimpleDispatcher { scoped_refptr shared_buffer_; - DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher_unittest.cc b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher_unittest.cc index 42446c5dabe4cd..35c9d2e41a2671 100644 --- a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher_unittest.cc @@ -6,11 +6,11 @@ #include -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "mojo/edk/embedder/platform_shared_buffer.h" #include "mojo/edk/embedder/simple_platform_support.h" #include "mojo/edk/system/dispatcher.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -50,7 +50,7 @@ class SharedBufferDispatcherTest : public testing::Test { private: embedder::SimplePlatformSupport platform_support_; - DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcherTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcherTest); }; // Tests valid inputs to |ValidateCreateOptions()|. @@ -66,7 +66,7 @@ TEST_F(SharedBufferDispatcherTest, ValidateCreateOptionsValid) { // Different flags. MojoCreateSharedBufferOptionsFlags flags_values[] = { MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE}; - for (size_t i = 0; i < arraysize(flags_values); i++) { + for (size_t i = 0; i < MOJO_ARRAYSIZE(flags_values); i++) { const MojoCreateSharedBufferOptionsFlags flags = flags_values[i]; // Different capacities (size 1). @@ -189,7 +189,7 @@ TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsValid) { {sizeof(MojoDuplicateBufferHandleOptions), MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}, {sizeof(MojoDuplicateBufferHandleOptionsFlags), ~0u}}; - for (size_t i = 0; i < arraysize(options); i++) { + for (size_t i = 0; i < MOJO_ARRAYSIZE(options); i++) { scoped_refptr dispatcher2; EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->DuplicateBufferHandle( MakeUserPointer(&options[i]), &dispatcher2)); diff --git a/third_party/mojo/src/mojo/edk/system/simple_dispatcher.h b/third_party/mojo/src/mojo/edk/system/simple_dispatcher.h index eddf614e75c69e..1ec7ba74de462e 100644 --- a/third_party/mojo/src/mojo/edk/system/simple_dispatcher.h +++ b/third_party/mojo/src/mojo/edk/system/simple_dispatcher.h @@ -7,10 +7,10 @@ #include -#include "base/macros.h" #include "mojo/edk/system/awakable_list.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -42,7 +42,7 @@ class MOJO_SYSTEM_IMPL_EXPORT SimpleDispatcher : public Dispatcher { // Protected by |lock()|: AwakableList awakable_list_; - DISALLOW_COPY_AND_ASSIGN(SimpleDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(SimpleDispatcher); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/simple_dispatcher_unittest.cc b/third_party/mojo/src/mojo/edk/system/simple_dispatcher_unittest.cc index 58f1458deb8a4b..c9a15108a69750 100644 --- a/third_party/mojo/src/mojo/edk/system/simple_dispatcher_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/simple_dispatcher_unittest.cc @@ -3,29 +3,27 @@ // found in the LICENSE file. // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a -// heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to +// heavily-loaded system). Sorry. |test::EpsilonDeadline()| may be increased to // increase tolerance and reduce observed flakiness (though doing so reduces the // meaningfulness of the test). #include "mojo/edk/system/simple_dispatcher.h" #include "base/logging.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_vector.h" #include "base/synchronization/lock.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. -#include "base/time/time.h" #include "mojo/edk/system/test_utils.h" #include "mojo/edk/system/waiter.h" #include "mojo/edk/system/waiter_test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { namespace system { namespace { -class MockSimpleDispatcher : public SimpleDispatcher { +class MockSimpleDispatcher final : public SimpleDispatcher { public: MockSimpleDispatcher() : state_(MOJO_HANDLE_SIGNAL_NONE, @@ -82,7 +80,7 @@ class MockSimpleDispatcher : public SimpleDispatcher { // Protected by |lock()|: HandleSignalsState state_; - DISALLOW_COPY_AND_ASSIGN(MockSimpleDispatcher); + MOJO_DISALLOW_COPY_AND_ASSIGN(MockSimpleDispatcher); }; #if defined(OS_WIN) @@ -118,7 +116,7 @@ TEST(SimpleDispatcherTest, MAYBE_Basic) { d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_OK, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(1u, context); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); @@ -134,7 +132,7 @@ TEST(SimpleDispatcherTest, MAYBE_Basic) { d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_OK, w.Wait(0, &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(2u, context); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); @@ -149,9 +147,8 @@ TEST(SimpleDispatcherTest, MAYBE_Basic) { d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 3, nullptr)); d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); stopwatch.Start(); - EXPECT_EQ(MOJO_RESULT_OK, - w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_EQ(MOJO_RESULT_OK, w.Wait(2 * test::EpsilonDeadline(), &context)); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(3u, context); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); @@ -166,7 +163,7 @@ TEST(SimpleDispatcherTest, MAYBE_Basic) { d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 4, nullptr)); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, w.Wait(0, nullptr)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); @@ -181,10 +178,10 @@ TEST(SimpleDispatcherTest, MAYBE_Basic) { d->AddAwakable(&w, MOJO_HANDLE_SIGNAL_WRITABLE, 5, nullptr)); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, - w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), nullptr)); - base::TimeDelta elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + w.Wait(2 * test::EpsilonDeadline(), nullptr)); + MojoDeadline elapsed = stopwatch.Elapsed(); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); @@ -223,7 +220,7 @@ TEST(SimpleDispatcherTest, BasicUnsatisfiable) { stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(2u, context); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); @@ -239,7 +236,7 @@ TEST(SimpleDispatcherTest, BasicUnsatisfiable) { d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, w.Wait(0, &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(3u, context); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); @@ -256,8 +253,8 @@ TEST(SimpleDispatcherTest, BasicUnsatisfiable) { d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, - w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + w.Wait(2 * test::EpsilonDeadline(), &context)); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(4u, context); hss = HandleSignalsState(); d->RemoveAwakable(&w, &hss); @@ -294,7 +291,7 @@ TEST(SimpleDispatcherTest, BasicClosed) { EXPECT_EQ(MOJO_RESULT_OK, d->Close()); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(MOJO_DEADLINE_INDEFINITE, &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(2u, context); // Don't need to remove waiters from closed dispatchers. @@ -306,7 +303,7 @@ TEST(SimpleDispatcherTest, BasicClosed) { EXPECT_EQ(MOJO_RESULT_OK, d->Close()); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_CANCELLED, w.Wait(0, &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(3u, context); // Don't need to remove waiters from closed dispatchers. @@ -319,8 +316,8 @@ TEST(SimpleDispatcherTest, BasicClosed) { EXPECT_EQ(MOJO_RESULT_OK, d->Close()); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_CANCELLED, - w.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + w.Wait(2 * test::EpsilonDeadline(), &context)); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_EQ(4u, context); // Don't need to remove waiters from closed dispatchers. } @@ -352,7 +349,7 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) { // If we closed earlier, then probably we'd get a |MOJO_RESULT_CANCELLED|. EXPECT_EQ(MOJO_RESULT_OK, d->Close()); } - EXPECT_LT(stopwatch.Elapsed(), test::EpsilonTimeout()); + EXPECT_LT(stopwatch.Elapsed(), test::EpsilonDeadline()); EXPECT_FALSE(did_wait); EXPECT_EQ(MOJO_RESULT_ALREADY_EXISTS, result); EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE, hss.satisfied_signals); @@ -368,14 +365,14 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) { &context, &hss); stopwatch.Start(); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); } // Joins the thread. EXPECT_EQ(MOJO_RESULT_OK, d->Close()); } - base::TimeDelta elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + MojoDeadline elapsed = stopwatch.Elapsed(); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_TRUE(did_wait); EXPECT_EQ(MOJO_RESULT_OK, result); EXPECT_EQ(2u, context); @@ -392,14 +389,14 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) { &context, &hss); stopwatch.Start(); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_NONE); } // Joins the thread. EXPECT_EQ(MOJO_RESULT_OK, d->Close()); } elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_TRUE(did_wait); EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); EXPECT_EQ(3u, context); @@ -414,12 +411,12 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) { &context, &hss); stopwatch.Start(); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); EXPECT_EQ(MOJO_RESULT_OK, d->Close()); } // Joins the thread. elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_TRUE(did_wait); EXPECT_EQ(MOJO_RESULT_CANCELLED, result); EXPECT_EQ(4u, context); @@ -431,11 +428,11 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) { scoped_refptr d(new MockSimpleDispatcher()); { test::WaiterThread thread(d, MOJO_HANDLE_SIGNAL_READABLE, - 2 * test::EpsilonTimeout().InMicroseconds(), 5, - &did_wait, &result, &context, &hss); + 2 * test::EpsilonDeadline(), 5, &did_wait, + &result, &context, &hss); stopwatch.Start(); thread.Start(); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); // Not what we're waiting for. d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_WRITABLE); } // Joins the thread (after its wait times out). @@ -443,8 +440,8 @@ TEST(SimpleDispatcherTest, MAYBE_BasicThreaded) { EXPECT_EQ(MOJO_RESULT_OK, d->Close()); } elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_TRUE(did_wait); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); EXPECT_EQ(MOJO_HANDLE_SIGNAL_WRITABLE, hss.satisfied_signals); @@ -476,7 +473,7 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) { &did_wait[i], &result[i], &context[i], &hss[i])); threads.back()->Start(); } - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); EXPECT_EQ(MOJO_RESULT_OK, d->Close()); } // Joins the threads. @@ -505,7 +502,7 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) { &did_wait[i], &result[i], &context[i], &hss[i])); threads.back()->Start(); } - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); // This will wake up the ones waiting to write. EXPECT_EQ(MOJO_RESULT_OK, d->Close()); @@ -542,9 +539,9 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) { &did_wait[i], &result[i], &context[i], &hss[i])); threads.back()->Start(); } - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); d->SetSatisfiableSignals(MOJO_HANDLE_SIGNAL_READABLE); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); EXPECT_EQ(MOJO_RESULT_OK, d->Close()); } // Joins the threads. @@ -570,19 +567,17 @@ TEST(SimpleDispatcherTest, MAYBE_MultipleWaiters) { ScopedVector 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])); + d, MOJO_HANDLE_SIGNAL_READABLE, 3 * test::EpsilonDeadline(), 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])); + d, MOJO_HANDLE_SIGNAL_WRITABLE, 1 * test::EpsilonDeadline(), i, + &did_wait[i], &result[i], &context[i], &hss[i])); threads.back()->Start(); } - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); d->SetSatisfiedSignals(MOJO_HANDLE_SIGNAL_READABLE); // All those waiting for writable should have timed out. EXPECT_EQ(MOJO_RESULT_OK, d->Close()); diff --git a/third_party/mojo/src/mojo/edk/system/slave_connection_manager.h b/third_party/mojo/src/mojo/edk/system/slave_connection_manager.h index 8bbbe4e984d230..40fc79bf2ff7c5 100644 --- a/third_party/mojo/src/mojo/edk/system/slave_connection_manager.h +++ b/third_party/mojo/src/mojo/edk/system/slave_connection_manager.h @@ -5,7 +5,6 @@ #ifndef MOJO_EDK_SYSTEM_SLAVE_CONNECTION_MANAGER_H_ #define MOJO_EDK_SYSTEM_SLAVE_CONNECTION_MANAGER_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" @@ -16,6 +15,7 @@ #include "mojo/edk/system/connection_manager.h" #include "mojo/edk/system/raw_channel.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace base { class TaskRunner; @@ -35,7 +35,7 @@ namespace system { // its internal, private thread), with condition that |Init()| be called before // anything else and |Shutdown()| be called before destruction (and no other // public methods may be called during/after |Shutdown()|). -class MOJO_SYSTEM_IMPL_EXPORT SlaveConnectionManager +class MOJO_SYSTEM_IMPL_EXPORT SlaveConnectionManager final : public ConnectionManager, public RawChannel::Delegate { public: @@ -146,7 +146,7 @@ class MOJO_SYSTEM_IMPL_EXPORT SlaveConnectionManager base::Lock lock_; base::WaitableEvent event_; - DISALLOW_COPY_AND_ASSIGN(SlaveConnectionManager); + MOJO_DISALLOW_COPY_AND_ASSIGN(SlaveConnectionManager); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/test_channel_endpoint_client.h b/third_party/mojo/src/mojo/edk/system/test_channel_endpoint_client.h index f708d61ef827db..c2347d56435076 100644 --- a/third_party/mojo/src/mojo/edk/system/test_channel_endpoint_client.h +++ b/third_party/mojo/src/mojo/edk/system/test_channel_endpoint_client.h @@ -5,13 +5,13 @@ #ifndef MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ #define MOJO_EDK_SYSTEM_TEST_CHANNEL_ENDPOINT_CLIENT_H_ -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/synchronization/lock.h" #include "mojo/edk/system/channel_endpoint.h" #include "mojo/edk/system/channel_endpoint_client.h" #include "mojo/edk/system/message_in_transit_queue.h" +#include "mojo/public/cpp/system/macros.h" namespace base { class WaitableEvent; @@ -21,7 +21,7 @@ namespace mojo { namespace system { namespace test { -class TestChannelEndpointClient : public ChannelEndpointClient { +class TestChannelEndpointClient final : public ChannelEndpointClient { public: TestChannelEndpointClient(); @@ -59,7 +59,7 @@ class TestChannelEndpointClient : public ChannelEndpointClient { // Event to trigger if we read a message (may be null). base::WaitableEvent* read_event_; - DISALLOW_COPY_AND_ASSIGN(TestChannelEndpointClient); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestChannelEndpointClient); }; } // namespace test diff --git a/third_party/mojo/src/mojo/edk/system/test_utils.cc b/third_party/mojo/src/mojo/edk/system/test_utils.cc index d7947813a8cfff..8bd16ebc37a8d4 100644 --- a/third_party/mojo/src/mojo/edk/system/test_utils.cc +++ b/third_party/mojo/src/mojo/edk/system/test_utils.cc @@ -4,14 +4,22 @@ #include "mojo/edk/system/test_utils.h" +#include + +#include "base/logging.h" #include "base/test/test_timeouts.h" +#include "base/threading/platform_thread.h" // For |Sleep()|. #include "build/build_config.h" namespace mojo { namespace system { namespace test { -base::TimeDelta EpsilonTimeout() { +MojoDeadline DeadlineFromMilliseconds(unsigned milliseconds) { + return static_cast(milliseconds) * 1000; +} + +MojoDeadline EpsilonDeadline() { // Originally, our epsilon timeout was 10 ms, which was mostly fine but flaky on // some Windows bots. I don't recall ever seeing flakes on other bots. At 30 ms // tests seem reliable on Windows bots, but not at 25 ms. We'd like this timeout @@ -21,9 +29,9 @@ base::TimeDelta EpsilonTimeout() { // etc.). Based on this, set it to (usually be) 30 ms on Windows and 20 ms // elsewhere. #if defined(OS_WIN) || defined(OS_ANDROID) - return (TestTimeouts::tiny_timeout() * 3) / 10; + return (TinyDeadline() * 3) / 10; #else - return (TestTimeouts::tiny_timeout() * 2) / 10; + return (TinyDeadline() * 2) / 10; #endif } @@ -37,6 +45,30 @@ MojoDeadline ActionDeadline() { TestTimeouts::action_timeout().InMicroseconds()); } +void Sleep(MojoDeadline deadline) { + CHECK_LE(deadline, + static_cast(std::numeric_limits::max())); + base::PlatformThread::Sleep( + base::TimeDelta::FromMicroseconds(static_cast(deadline))); +} + +Stopwatch::Stopwatch() { +} + +Stopwatch::~Stopwatch() { +} + +void Stopwatch::Start() { + start_time_ = base::TimeTicks::Now(); +} + +MojoDeadline Stopwatch::Elapsed() { + int64_t result = (base::TimeTicks::Now() - start_time_).InMicroseconds(); + // |DCHECK_GE|, not |CHECK_GE|, since this may be performance-important. + DCHECK_GE(result, 0); + return static_cast(result); +} + } // namespace test } // namespace system } // namespace mojo diff --git a/third_party/mojo/src/mojo/edk/system/test_utils.h b/third_party/mojo/src/mojo/edk/system/test_utils.h index fba9c68cb8d794..6f8a96d637c47c 100644 --- a/third_party/mojo/src/mojo/edk/system/test_utils.h +++ b/third_party/mojo/src/mojo/edk/system/test_utils.h @@ -5,19 +5,21 @@ #ifndef MOJO_EDK_SYSTEM_TEST_UTILS_H_ #define MOJO_EDK_SYSTEM_TEST_UTILS_H_ -#include "base/macros.h" #include "base/time/time.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { namespace test { -// A timeout smaller than |TestTimeouts::tiny_timeout()|. Warning: This may lead -// to flakiness, but this is unavoidable if, e.g., you're trying to ensure that -// functions with timeouts are reasonably accurate. We want this to be as small -// as possible without causing too much flakiness. -base::TimeDelta EpsilonTimeout(); +MojoDeadline DeadlineFromMilliseconds(unsigned milliseconds); + +// A timeout smaller than |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. +// Warning: This may lead to flakiness, but this is unavoidable if, e.g., you're +// trying to ensure that functions with timeouts are reasonably accurate. We +// want this to be as small as possible without causing too much flakiness. +MojoDeadline EpsilonDeadline(); // |TestTimeouts::tiny_timeout()|, as a |MojoDeadline|. (Expect this to be on // the order of 100 ms.) @@ -27,22 +29,26 @@ MojoDeadline TinyDeadline(); // the order of 10 s.) MojoDeadline ActionDeadline(); +// Sleeps for at least the specified duration. +void Sleep(MojoDeadline deadline); + // Stopwatch ------------------------------------------------------------------- // A simple "stopwatch" for measuring time elapsed from a given starting point. class Stopwatch { public: - Stopwatch() {} - ~Stopwatch() {} - - void Start() { start_time_ = base::TimeTicks::Now(); } + Stopwatch(); + ~Stopwatch(); - base::TimeDelta Elapsed() { return base::TimeTicks::Now() - start_time_; } + void Start(); + // Returns the amount of time elapsed since the last call to |Start()| (in + // microseconds). + MojoDeadline Elapsed(); private: base::TimeTicks start_time_; - DISALLOW_COPY_AND_ASSIGN(Stopwatch); + MOJO_DISALLOW_COPY_AND_ASSIGN(Stopwatch); }; } // namespace test diff --git a/third_party/mojo/src/mojo/edk/system/transport_data.cc b/third_party/mojo/src/mojo/edk/system/transport_data.cc index 783a51d6eb0d81..8d9b229b08a4d6 100644 --- a/third_party/mojo/src/mojo/edk/system/transport_data.cc +++ b/third_party/mojo/src/mojo/edk/system/transport_data.cc @@ -6,7 +6,6 @@ #include -#include "base/compiler_specific.h" #include "base/logging.h" #include "mojo/edk/system/channel.h" #include "mojo/edk/system/configuration.h" @@ -26,9 +25,9 @@ static_assert(kMaxSizePerPlatformHandle % MessageInTransit::kMessageAlignment == 0, "kMaxSizePerPlatformHandle not a multiple of alignment"); -STATIC_CONST_MEMBER_DEFINITION const size_t +MOJO_STATIC_CONST_MEMBER_DEFINITION const size_t TransportData::kMaxSerializedDispatcherSize; -STATIC_CONST_MEMBER_DEFINITION const size_t +MOJO_STATIC_CONST_MEMBER_DEFINITION const size_t TransportData::kMaxSerializedDispatcherPlatformHandles; // static diff --git a/third_party/mojo/src/mojo/edk/system/transport_data.h b/third_party/mojo/src/mojo/edk/system/transport_data.h index 7cb25d3bb98dfb..20bb80fe3c3716 100644 --- a/third_party/mojo/src/mojo/edk/system/transport_data.h +++ b/third_party/mojo/src/mojo/edk/system/transport_data.h @@ -9,7 +9,6 @@ #include -#include "base/macros.h" #include "base/memory/aligned_memory.h" #include "base/memory/scoped_ptr.h" #include "build/build_config.h" @@ -17,6 +16,7 @@ #include "mojo/edk/embedder/platform_handle_vector.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -182,7 +182,7 @@ class MOJO_SYSTEM_IMPL_EXPORT TransportData { // TODO(vtl): With C++11, change it to a vector of |ScopedPlatformHandle|s. embedder::ScopedPlatformHandleVectorPtr platform_handles_; - DISALLOW_COPY_AND_ASSIGN(TransportData); + MOJO_DISALLOW_COPY_AND_ASSIGN(TransportData); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/unique_identifier.h b/third_party/mojo/src/mojo/edk/system/unique_identifier.h index 1a13b361bc90cb..7db5e383951af8 100644 --- a/third_party/mojo/src/mojo/edk/system/unique_identifier.h +++ b/third_party/mojo/src/mojo/edk/system/unique_identifier.h @@ -10,9 +10,9 @@ #include -#include "base/compiler_specific.h" #include "base/containers/hash_tables.h" #include "mojo/edk/system/system_impl_export.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -81,7 +81,7 @@ class MOJO_SYSTEM_IMPL_EXPORT UniqueIdentifier { static_assert(sizeof(UniqueIdentifier) == 16, "UniqueIdentifier has wrong size."); // We want to be able to take any buffer and cast it to a |UniqueIdentifier|. -static_assert(ALIGNOF(UniqueIdentifier) == 1, +static_assert(MOJO_ALIGNOF(UniqueIdentifier) == 1, "UniqueIdentifier requires nontrivial alignment."); } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/unique_identifier_unittest.cc b/third_party/mojo/src/mojo/edk/system/unique_identifier_unittest.cc index 15b70b466c3f3e..1522446246f8e6 100644 --- a/third_party/mojo/src/mojo/edk/system/unique_identifier_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/unique_identifier_unittest.cc @@ -8,8 +8,8 @@ #include #include "base/containers/hash_tables.h" -#include "base/macros.h" #include "mojo/edk/embedder/simple_platform_support.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { @@ -26,7 +26,7 @@ class UniqueIdentifierTest : public testing::Test { private: embedder::SimplePlatformSupport platform_support_; - DISALLOW_COPY_AND_ASSIGN(UniqueIdentifierTest); + MOJO_DISALLOW_COPY_AND_ASSIGN(UniqueIdentifierTest); }; TEST_F(UniqueIdentifierTest, Basic) { diff --git a/third_party/mojo/src/mojo/edk/system/waiter.h b/third_party/mojo/src/mojo/edk/system/waiter.h index b9b63cdc9bfbb1..945acbabd43120 100644 --- a/third_party/mojo/src/mojo/edk/system/waiter.h +++ b/third_party/mojo/src/mojo/edk/system/waiter.h @@ -7,12 +7,12 @@ #include -#include "base/macros.h" #include "base/synchronization/condition_variable.h" #include "base/synchronization/lock.h" #include "mojo/edk/system/awakable.h" #include "mojo/edk/system/system_impl_export.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -21,7 +21,7 @@ namespace system { // under other locks, in particular, |Dispatcher::lock_|s, so |Waiter| methods // must never call out to other objects (in particular, |Dispatcher|s). This // class is thread-safe. -class MOJO_SYSTEM_IMPL_EXPORT Waiter : public Awakable { +class MOJO_SYSTEM_IMPL_EXPORT Waiter final : public Awakable { public: Waiter(); ~Waiter(); @@ -70,7 +70,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Waiter : public Awakable { MojoResult awake_result_; uintptr_t awake_context_; - DISALLOW_COPY_AND_ASSIGN(Waiter); + MOJO_DISALLOW_COPY_AND_ASSIGN(Waiter); }; } // namespace system diff --git a/third_party/mojo/src/mojo/edk/system/waiter_test_utils.h b/third_party/mojo/src/mojo/edk/system/waiter_test_utils.h index b11d78dc5a282c..350d87f286ab8c 100644 --- a/third_party/mojo/src/mojo/edk/system/waiter_test_utils.h +++ b/third_party/mojo/src/mojo/edk/system/waiter_test_utils.h @@ -7,14 +7,13 @@ #include -#include "base/compiler_specific.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/threading/simple_thread.h" #include "mojo/edk/system/dispatcher.h" #include "mojo/edk/system/handle_signals_state.h" #include "mojo/edk/system/waiter.h" #include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace system { @@ -60,7 +59,7 @@ class SimpleWaiterThread : public base::SimpleThread { uint32_t* const context_; Waiter waiter_; - DISALLOW_COPY_AND_ASSIGN(SimpleWaiterThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(SimpleWaiterThread); }; // This is a more complex and realistic thread that has a |Waiter|, on which it @@ -95,7 +94,7 @@ class WaiterThread : public base::SimpleThread { Waiter waiter_; - DISALLOW_COPY_AND_ASSIGN(WaiterThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(WaiterThread); }; } // namespace test diff --git a/third_party/mojo/src/mojo/edk/system/waiter_unittest.cc b/third_party/mojo/src/mojo/edk/system/waiter_unittest.cc index 73a702cf4ae566..68f81062e81749 100644 --- a/third_party/mojo/src/mojo/edk/system/waiter_unittest.cc +++ b/third_party/mojo/src/mojo/edk/system/waiter_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. // NOTE(vtl): Some of these tests are inherently flaky (e.g., if run on a -// heavily-loaded system). Sorry. |test::EpsilonTimeout()| may be increased to +// heavily-loaded system). Sorry. |test::EpsilonDeadline()| may be increased to // increase tolerance and reduce observed flakiness (though doing so reduces the // meaningfulness of the test). @@ -11,20 +11,17 @@ #include -#include "base/macros.h" #include "base/synchronization/lock.h" -#include "base/threading/platform_thread.h" // For |Sleep()|. #include "base/threading/simple_thread.h" -#include "base/time/time.h" #include "mojo/edk/system/test_utils.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/gtest/include/gtest/gtest.h" namespace mojo { namespace system { namespace { -const int64_t kMicrosPerMs = 1000; -const int64_t kPollTimeMicros = 10 * kMicrosPerMs; // 10 ms. +const unsigned kPollTimeMs = 10; class WaitingThread : public base::SimpleThread { public: @@ -41,7 +38,7 @@ class WaitingThread : public base::SimpleThread { void WaitUntilDone(MojoResult* result, uint32_t* context, - base::TimeDelta* elapsed) { + MojoDeadline* elapsed) { for (;;) { { base::AutoLock locker(lock_); @@ -53,8 +50,7 @@ class WaitingThread : public base::SimpleThread { } } - base::PlatformThread::Sleep( - base::TimeDelta::FromMicroseconds(kPollTimeMicros)); + test::Sleep(test::DeadlineFromMilliseconds(kPollTimeMs)); } } @@ -65,7 +61,7 @@ class WaitingThread : public base::SimpleThread { test::Stopwatch stopwatch; MojoResult result; uint32_t context = static_cast(-1); - base::TimeDelta elapsed; + MojoDeadline elapsed; stopwatch.Start(); result = waiter_.Wait(deadline_, &context); @@ -87,75 +83,75 @@ class WaitingThread : public base::SimpleThread { bool done_; MojoResult result_; uint32_t context_; - base::TimeDelta elapsed_; + MojoDeadline elapsed_; - DISALLOW_COPY_AND_ASSIGN(WaitingThread); + MOJO_DISALLOW_COPY_AND_ASSIGN(WaitingThread); }; TEST(WaiterTest, Basic) { MojoResult result; uint32_t context; - base::TimeDelta elapsed; + MojoDeadline elapsed; // Finite deadline. // Awake immediately after thread start. { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); + WaitingThread thread(10 * test::EpsilonDeadline()); thread.Start(); thread.waiter()->Awake(MOJO_RESULT_OK, 1); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(MOJO_RESULT_OK, result); EXPECT_EQ(1u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); } // Awake before after thread start. { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); + WaitingThread thread(10 * test::EpsilonDeadline()); thread.waiter()->Awake(MOJO_RESULT_CANCELLED, 2); thread.Start(); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(MOJO_RESULT_CANCELLED, result); EXPECT_EQ(2u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); } // Awake some time after thread start. { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); + WaitingThread thread(10 * test::EpsilonDeadline()); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); thread.waiter()->Awake(1, 3); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(1u, result); EXPECT_EQ(3u, context); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); } // Awake some longer time after thread start. { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); + WaitingThread thread(10 * test::EpsilonDeadline()); thread.Start(); - base::PlatformThread::Sleep(5 * test::EpsilonTimeout()); + test::Sleep(5 * test::EpsilonDeadline()); thread.waiter()->Awake(2, 4); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(2u, result); EXPECT_EQ(4u, context); - EXPECT_GT(elapsed, (5 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (5 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (5 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (5 + 1) * test::EpsilonDeadline()); } // Don't awake -- time out (on another thread). { - WaitingThread thread(2 * test::EpsilonTimeout().InMicroseconds()); + WaitingThread thread(2 * test::EpsilonDeadline()); thread.Start(); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, result); EXPECT_EQ(static_cast(-1), context); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); } // No (indefinite) deadline. @@ -168,7 +164,7 @@ TEST(WaiterTest, Basic) { thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(MOJO_RESULT_OK, result); EXPECT_EQ(5u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); } // Awake before after thread start. @@ -179,39 +175,39 @@ TEST(WaiterTest, Basic) { thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(MOJO_RESULT_CANCELLED, result); EXPECT_EQ(6u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); } // Awake some time after thread start. { WaitingThread thread(MOJO_DEADLINE_INDEFINITE); thread.Start(); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); thread.waiter()->Awake(1, 7); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(1u, result); EXPECT_EQ(7u, context); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); } // Awake some longer time after thread start. { WaitingThread thread(MOJO_DEADLINE_INDEFINITE); thread.Start(); - base::PlatformThread::Sleep(5 * test::EpsilonTimeout()); + test::Sleep(5 * test::EpsilonDeadline()); thread.waiter()->Awake(2, 8); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(2u, result); EXPECT_EQ(8u, context); - EXPECT_GT(elapsed, (5 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (5 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (5 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (5 + 1) * test::EpsilonDeadline()); } } TEST(WaiterTest, TimeOut) { test::Stopwatch stopwatch; - base::TimeDelta elapsed; + MojoDeadline elapsed; Waiter waiter; uint32_t context = 123; @@ -220,25 +216,25 @@ TEST(WaiterTest, TimeOut) { stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, waiter.Wait(0, &context)); elapsed = stopwatch.Elapsed(); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); EXPECT_EQ(123u, context); waiter.Init(); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, - waiter.Wait(2 * test::EpsilonTimeout().InMicroseconds(), &context)); + waiter.Wait(2 * test::EpsilonDeadline(), &context)); elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (2 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (2 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (2 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (2 + 1) * test::EpsilonDeadline()); EXPECT_EQ(123u, context); waiter.Init(); stopwatch.Start(); EXPECT_EQ(MOJO_RESULT_DEADLINE_EXCEEDED, - waiter.Wait(5 * test::EpsilonTimeout().InMicroseconds(), &context)); + waiter.Wait(5 * test::EpsilonDeadline(), &context)); elapsed = stopwatch.Elapsed(); - EXPECT_GT(elapsed, (5 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (5 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (5 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (5 + 1) * test::EpsilonDeadline()); EXPECT_EQ(123u, context); } @@ -246,7 +242,7 @@ TEST(WaiterTest, TimeOut) { TEST(WaiterTest, MultipleAwakes) { MojoResult result; uint32_t context; - base::TimeDelta elapsed; + MojoDeadline elapsed; { WaitingThread thread(MOJO_DEADLINE_INDEFINITE); @@ -256,7 +252,7 @@ TEST(WaiterTest, MultipleAwakes) { thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(MOJO_RESULT_OK, result); EXPECT_EQ(1u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); } { @@ -267,33 +263,33 @@ TEST(WaiterTest, MultipleAwakes) { thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(1u, result); EXPECT_EQ(3u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); } { WaitingThread thread(MOJO_DEADLINE_INDEFINITE); thread.Start(); thread.waiter()->Awake(10, 5); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); thread.waiter()->Awake(20, 6); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(10u, result); EXPECT_EQ(5u, context); - EXPECT_LT(elapsed, test::EpsilonTimeout()); + EXPECT_LT(elapsed, test::EpsilonDeadline()); } { - WaitingThread thread(10 * test::EpsilonTimeout().InMicroseconds()); + WaitingThread thread(10 * test::EpsilonDeadline()); thread.Start(); - base::PlatformThread::Sleep(1 * test::EpsilonTimeout()); + test::Sleep(1 * test::EpsilonDeadline()); thread.waiter()->Awake(MOJO_RESULT_FAILED_PRECONDITION, 7); - base::PlatformThread::Sleep(2 * test::EpsilonTimeout()); + test::Sleep(2 * test::EpsilonDeadline()); thread.waiter()->Awake(MOJO_RESULT_OK, 8); thread.WaitUntilDone(&result, &context, &elapsed); EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); EXPECT_EQ(7u, context); - EXPECT_GT(elapsed, (1 - 1) * test::EpsilonTimeout()); - EXPECT_LT(elapsed, (1 + 1) * test::EpsilonTimeout()); + EXPECT_GT(elapsed, (1 - 1) * test::EpsilonDeadline()); + EXPECT_LT(elapsed, (1 + 1) * test::EpsilonDeadline()); } } diff --git a/third_party/mojo/src/mojo/edk/test/BUILD.gn b/third_party/mojo/src/mojo/edk/test/BUILD.gn index 75821b2a3f6b74..fa6f83603adede 100644 --- a/third_party/mojo/src/mojo/edk/test/BUILD.gn +++ b/third_party/mojo/src/mojo/edk/test/BUILD.gn @@ -25,6 +25,8 @@ mojo_edk_source_set("test_support") { ] mojo_edk_deps = [ "mojo/edk/system" ] + + mojo_sdk_public_deps = [ "mojo/public/cpp/system" ] } mojo_edk_source_set("run_all_unittests") { @@ -71,6 +73,8 @@ mojo_edk_source_set("test_support_impl") { mojo_sdk_deps = [ "mojo/public/c/test_support" ] + mojo_sdk_public_deps = [ "mojo/public/cpp/system" ] + sources = [ "test_support_impl.cc", "test_support_impl.h", diff --git a/third_party/mojo/src/mojo/edk/test/multiprocess_test_helper.h b/third_party/mojo/src/mojo/edk/test/multiprocess_test_helper.h index b2887ac87ff213..fb00510f18bd36 100644 --- a/third_party/mojo/src/mojo/edk/test/multiprocess_test_helper.h +++ b/third_party/mojo/src/mojo/edk/test/multiprocess_test_helper.h @@ -7,11 +7,11 @@ #include -#include "base/macros.h" #include "base/process/process.h" #include "base/test/multiprocess_test.h" #include "base/test/test_timeouts.h" #include "mojo/edk/embedder/scoped_platform_handle.h" +#include "mojo/public/cpp/system/macros.h" #include "testing/multiprocess_func_list.h" namespace mojo { @@ -66,7 +66,7 @@ class MultiprocessTestHelper { // Valid after |StartChild()| and before |WaitForChildShutdown()|. base::Process test_child_; - DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); + MOJO_DISALLOW_COPY_AND_ASSIGN(MultiprocessTestHelper); }; // Use this to declare the child process's "main()" function for tests using diff --git a/third_party/mojo/src/mojo/edk/test/scoped_ipc_support.h b/third_party/mojo/src/mojo/edk/test/scoped_ipc_support.h index 961bafac8a8d3b..f8d44e0c59f68d 100644 --- a/third_party/mojo/src/mojo/edk/test/scoped_ipc_support.h +++ b/third_party/mojo/src/mojo/edk/test/scoped_ipc_support.h @@ -6,7 +6,6 @@ #define MOJO_EDK_TEST_SCOPED_IPC_SUPPORT_H_ #include "base/callback.h" -#include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/synchronization/waitable_event.h" #include "base/task_runner.h" @@ -15,6 +14,7 @@ #include "mojo/edk/embedder/process_type.h" #include "mojo/edk/embedder/scoped_platform_handle.h" #include "mojo/edk/embedder/slave_process_delegate.h" +#include "mojo/public/cpp/system/macros.h" namespace mojo { namespace test { @@ -39,7 +39,7 @@ class ScopedIPCSupportHelper { // Set after shut down. base::WaitableEvent event_; - DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupportHelper); + MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupportHelper); }; } // namespace internal @@ -61,7 +61,7 @@ class ScopedIPCSupport : public embedder::ProcessDelegate { internal::ScopedIPCSupportHelper helper_; - DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport); + MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport); }; // Like |ScopedIPCSupport|, but with |ProcessType::MASTER|. It will (optionally) @@ -84,7 +84,7 @@ class ScopedMasterIPCSupport : public embedder::MasterProcessDelegate { internal::ScopedIPCSupportHelper helper_; base::Callback on_slave_disconnect_; - DISALLOW_COPY_AND_ASSIGN(ScopedMasterIPCSupport); + MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedMasterIPCSupport); }; // Like |ScopedIPCSupport|, but with |ProcessType::SLAVE|. It will (optionally) @@ -107,7 +107,7 @@ class ScopedSlaveIPCSupport : public embedder::SlaveProcessDelegate { internal::ScopedIPCSupportHelper helper_; base::Closure on_master_disconnect_; - DISALLOW_COPY_AND_ASSIGN(ScopedSlaveIPCSupport); + MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSlaveIPCSupport); }; } // namespace test diff --git a/third_party/mojo/src/mojo/edk/test/test_support_impl.h b/third_party/mojo/src/mojo/edk/test/test_support_impl.h index 533bfce803d3dc..589253a0eb83f8 100644 --- a/third_party/mojo/src/mojo/edk/test/test_support_impl.h +++ b/third_party/mojo/src/mojo/edk/test/test_support_impl.h @@ -5,7 +5,9 @@ #ifndef MOJO_EDK_TEST_TEST_SUPPORT_IMPL_H_ #define MOJO_EDK_TEST_TEST_SUPPORT_IMPL_H_ -#include "base/macros.h" +#include + +#include "mojo/public/cpp/system/macros.h" #include "mojo/public/tests/test_support_private.h" namespace mojo { @@ -25,7 +27,7 @@ class TestSupportImpl : public TestSupport { const char* relative_path) override; private: - DISALLOW_COPY_AND_ASSIGN(TestSupportImpl); + MOJO_DISALLOW_COPY_AND_ASSIGN(TestSupportImpl); }; } // namespace test diff --git a/third_party/mojo/src/mojo/edk/test/test_utils.h b/third_party/mojo/src/mojo/edk/test/test_utils.h index 9287457cd93a4a..9c21a1a29ed109 100644 --- a/third_party/mojo/src/mojo/edk/test/test_utils.h +++ b/third_party/mojo/src/mojo/edk/test/test_utils.h @@ -10,7 +10,6 @@ #include -#include "base/files/file_path.h" #include "base/files/scoped_file.h" #include "mojo/edk/embedder/platform_handle.h" #include "mojo/edk/embedder/scoped_platform_handle.h" @@ -48,9 +47,6 @@ embedder::ScopedPlatformHandle PlatformHandleFromFILE(base::ScopedFILE fp); base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h, const char* mode); -// Returns the path to the mojom js bindings file. -base::FilePath GetFilePathForJSResource(const std::string& path); - } // namespace test } // namespace mojo diff --git a/third_party/mojo/src/mojo/edk/test/test_utils_posix.cc b/third_party/mojo/src/mojo/edk/test/test_utils_posix.cc index 6491baffb65eb8..182aa337edc14b 100644 --- a/third_party/mojo/src/mojo/edk/test/test_utils_posix.cc +++ b/third_party/mojo/src/mojo/edk/test/test_utils_posix.cc @@ -7,8 +7,6 @@ #include #include -#include "base/base_paths.h" -#include "base/path_service.h" #include "base/posix/eintr_wrapper.h" namespace mojo { @@ -89,12 +87,5 @@ base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h, return rv.Pass(); } -base::FilePath GetFilePathForJSResource(const std::string& path) { - std::string binding_path = "gen/" + path + ".js"; - base::FilePath exe_dir; - PathService::Get(base::DIR_EXE, &exe_dir); - return exe_dir.AppendASCII(binding_path); -} - } // namespace test } // namespace mojo diff --git a/third_party/mojo/src/mojo/edk/test/test_utils_win.cc b/third_party/mojo/src/mojo/edk/test/test_utils_win.cc index 2387945774225f..c74f009989ade4 100644 --- a/third_party/mojo/src/mojo/edk/test/test_utils_win.cc +++ b/third_party/mojo/src/mojo/edk/test/test_utils_win.cc @@ -9,10 +9,6 @@ #include #include -#include "base/base_paths.h" -#include "base/path_service.h" -#include "base/strings/string_util.h" - namespace mojo { namespace test { @@ -112,13 +108,5 @@ base::ScopedFILE FILEFromPlatformHandle(embedder::ScopedPlatformHandle h, return rv.Pass(); } -base::FilePath GetFilePathForJSResource(const std::string& path) { - std::string binding_path = "gen/" + path + ".js"; - base::ReplaceChars(binding_path, "//", "\\", &binding_path); - base::FilePath exe_dir; - PathService::Get(base::DIR_EXE, &exe_dir); - return exe_dir.AppendASCII(binding_path); -} - } // namespace test } // namespace mojo diff --git a/third_party/mojo/src/mojo/public/VERSION b/third_party/mojo/src/mojo/public/VERSION index 56df3760c7ddb2..0841b63ee6645f 100644 --- a/third_party/mojo/src/mojo/public/VERSION +++ b/third_party/mojo/src/mojo/public/VERSION @@ -1 +1 @@ -bdbb0c7e396fc4044a8b194058d7a7e529715286 \ No newline at end of file +a05bfef8096006056b2fff78092faf14d1319782 \ No newline at end of file diff --git a/third_party/mojo/src/mojo/public/cpp/bindings/lib/validate_params.h b/third_party/mojo/src/mojo/public/cpp/bindings/lib/validate_params.h index 40d7cb65f8b016..274a01233906a5 100644 --- a/third_party/mojo/src/mojo/public/cpp/bindings/lib/validate_params.h +++ b/third_party/mojo/src/mojo/public/cpp/bindings/lib/validate_params.h @@ -25,6 +25,8 @@ class ArrayValidateParams { delete element_validate_params; } + // TODO(vtl): The members of this class shouldn't be public. + // If |expected_num_elements| is not 0, the array is expected to have exactly // that number of elements. uint32_t expected_num_elements; @@ -37,6 +39,7 @@ class ArrayValidateParams { // nullptr. In the case of maps, this is used to validate the value array. ArrayValidateParams* element_validate_params; + private: MOJO_DISALLOW_COPY_AND_ASSIGN(ArrayValidateParams); }; diff --git a/third_party/mojo/src/mojo/public/cpp/system/macros.h b/third_party/mojo/src/mojo/public/cpp/system/macros.h index ecc42fbe750253..7f0fcd7751f60a 100644 --- a/third_party/mojo/src/mojo/public/cpp/system/macros.h +++ b/third_party/mojo/src/mojo/public/cpp/system/macros.h @@ -12,26 +12,27 @@ #include "mojo/public/c/system/macros.h" // Symbols exposed. // A macro to disallow the copy constructor and operator= functions. -// This should be used in the private: declarations for a class. #define MOJO_DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) + TypeName(const TypeName&) = delete; \ + void operator=(const TypeName&) = delete // Used to calculate the number of elements in an array. -// (See |arraysize()| in Chromium's base/basictypes.h for more details.) +// (See |arraysize()| in Chromium's base/macros.h for more details.) namespace mojo { +namespace internal { template char(&ArraySizeHelper(T(&array)[N]))[N]; #if !defined(_MSC_VER) template char(&ArraySizeHelper(const T(&array)[N]))[N]; #endif +} // namespace internal } // namespace mojo -#define MOJO_ARRAYSIZE(array) (sizeof(::mojo::ArraySizeHelper(array))) +#define MOJO_ARRAYSIZE(array) (sizeof(::mojo::internal::ArraySizeHelper(array))) // Used to make a type move-only. See Chromium's base/move.h for more -// details. The MoveOnlyTypeForCPP03 typedef is for Chromium's base/callback to -// tell that this type is move-only. +// details. The MoveOnlyTypeForCPP03 typedef is for Chromium's base/callback.h +// to tell that this type is move-only. #define MOJO_MOVE_ONLY_TYPE(type) \ private: \ type(type&); \ @@ -53,17 +54,28 @@ char(&ArraySizeHelper(const T(&array)[N]))[N]; // information. This workaround does not appear to be necessary after VS2015. // Use like: // -// In .h file: +// In the .h file: // struct Foo { // static const int kBar = 5; // }; // -// In .cc file: -// STATIC_CONST_MEMBER_DEFINITION const int Foo::kBar; +// In the .cc file: +// MOJO_STATIC_CONST_MEMBER_DEFINITION const int Foo::kBar; #if defined(_MSC_VER) && _MSC_VER < 1900 #define MOJO_STATIC_CONST_MEMBER_DEFINITION __declspec(selectany) #else #define MOJO_STATIC_CONST_MEMBER_DEFINITION #endif +namespace mojo { + +// Used to explicitly mark the return value of a function as unused. (You this +// if you are really sure you don't want to do anything with the return value of +// a function marked with |MOJO_WARN_UNUSED_RESULT|. +template +inline void ignore_result(const T&) { +} + +} // namespace mojo + #endif // MOJO_PUBLIC_CPP_SYSTEM_MACROS_H_ diff --git a/third_party/mojo/src/mojo/public/cpp/system/tests/macros_unittest.cc b/third_party/mojo/src/mojo/public/cpp/system/tests/macros_unittest.cc index 27a61bdcb5a584..72a9b242776e52 100644 --- a/third_party/mojo/src/mojo/public/cpp/system/tests/macros_unittest.cc +++ b/third_party/mojo/src/mojo/public/cpp/system/tests/macros_unittest.cc @@ -19,6 +19,19 @@ #include "testing/gtest/include/gtest/gtest.h" namespace mojo { + +// The test for |MOJO_STATIC_CONST_MEMBER_DEFINITION| is really a compile/link +// test. To test it fully would really require a header file and multiple .cc +// files, but we'll just cursorily verify it. +// +// This is defined outside of an anonymous namespace because +// MOJO_STATIC_CONST_MEMBER_DEFINITION may not be used on internal symbols. +struct StructWithStaticConstMember { + static const int kStaticConstMember = 123; +}; +MOJO_STATIC_CONST_MEMBER_DEFINITION +const int StructWithStaticConstMember::kStaticConstMember; + namespace { // Note: MSVS is very strict (and arguably buggy) about warnings for classes @@ -105,7 +118,7 @@ class MoveOnlyInt { int value_; }; -TEST(MacrosCppTest, MoveOnlyTypeForCpp03) { +TEST(MacrosCppTest, MoveOnlyType) { MoveOnlyInt x(123); EXPECT_TRUE(x.is_set()); EXPECT_EQ(123, x.value()); @@ -124,5 +137,23 @@ TEST(MacrosCppTest, MoveOnlyTypeForCpp03) { EXPECT_EQ(123, z.value()); } +// Use it, to make sure things get linked in and to avoid any warnings about +// unused things. +TEST(MacrosCppTest, StaticConstMemberDefinition) { + EXPECT_EQ(123, StructWithStaticConstMember::kStaticConstMember); +} + +// The test for |ignore_result()| is also just a compilation test. (Note that +// |MOJO_WARN_UNUSED_RESULT| can only be used in the prototype. +int ReturnsIntYouMustUse() MOJO_WARN_UNUSED_RESULT; + +int ReturnsIntYouMustUse() { + return 123; +} + +TEST(MacrosCppTest, IgnoreResult) { + ignore_result(ReturnsIntYouMustUse()); +} + } // namespace } // namespace mojo diff --git a/third_party/mojo/src/mojo/public/dart/CHANGELOG.md b/third_party/mojo/src/mojo/public/dart/CHANGELOG.md index 048cbc49fa8328..dcb340c07f3b32 100644 --- a/third_party/mojo/src/mojo/public/dart/CHANGELOG.md +++ b/third_party/mojo/src/mojo/public/dart/CHANGELOG.md @@ -1,3 +1,15 @@ +## 0.0.13 + + - 70 changes: https://github.com/domokit/mojo/compare/889091e...136e0d4 + +## 0.0.12 + + - 29 changes: https://github.com/domokit/mojo/compare/e25e3e2...432ce45 + +## 0.0.11 + + - 197 changes: https://github.com/domokit/mojo/compare/bdbb0c7...fb1b726 + ## 0.0.10 - 23 changes: https://github.com/domokit/mojo/compare/1b7bcee...be9dad7 diff --git a/third_party/mojo/src/mojo/public/dart/lib/src/event_stream.dart b/third_party/mojo/src/mojo/public/dart/lib/src/event_stream.dart index febfc9d591d4e2..f6797d43f685e6 100644 --- a/third_party/mojo/src/mojo/public/dart/lib/src/event_stream.dart +++ b/third_party/mojo/src/mojo/public/dart/lib/src/event_stream.dart @@ -43,9 +43,9 @@ class MojoEventStream extends Stream> { return _handleWatcherClose(immediate: immediate); } else { _localClose(); - return new Future.value(null); } } + return new Future.value(null); } StreamSubscription> listen(void onData(List event), diff --git a/third_party/mojo/src/mojo/public/dart/lib/src/handle.dart b/third_party/mojo/src/mojo/public/dart/lib/src/handle.dart index e7ac3eb811f713..42edf7899929c6 100644 --- a/third_party/mojo/src/mojo/public/dart/lib/src/handle.dart +++ b/third_party/mojo/src/mojo/public/dart/lib/src/handle.dart @@ -7,7 +7,8 @@ part of core; class _HandleCreationRecord { final MojoHandle handle; final StackTrace stack; - _HandleCreationRecord(this.handle, this.stack); + String description; + _HandleCreationRecord(this.handle, this.stack, {this.description}); } class MojoHandle { @@ -17,8 +18,8 @@ class MojoHandle { int _h; int get h => _h; - MojoHandle(this._h) { - assert(_addUnclosedHandle(this)); + MojoHandle(this._h, {String description}) { + assert(_addUnclosedHandle(this, description: description)); } MojoHandle._internal(this._h); @@ -99,7 +100,7 @@ class MojoHandle { // _addUnclosedHandle(), _removeUnclosedHandle(), and dumpLeakedHandles() // should only be used inside of assert() statements. - static bool _addUnclosedHandle(MojoHandle handle) { + static bool _addUnclosedHandle(MojoHandle handle, {String description}) { var stack; try { assert(false); @@ -107,11 +108,19 @@ class MojoHandle { stack = s; } - var handleCreate = new _HandleCreationRecord(handle, stack); + var handleCreate = new _HandleCreationRecord( + handle, stack, description: description); _unclosedHandles[handle.h] = handleCreate; return true; } + static bool _setHandleLeakDescription(MojoHandle handle, String description) { + if (_unclosedHandles.containsKey(handle.h)) { + _unclosedHandles[handle.h].description = description; + } + return true; + } + static bool _removeUnclosedHandle(MojoHandle handle) { _unclosedHandles.remove(handle._h); return true; @@ -122,8 +131,11 @@ class MojoHandle { for (var handle in MojoHandle._unclosedHandles.keys) { var handleCreation = MojoHandle._unclosedHandles[handle]; if (handleCreation != null) { - print("HANDLE LEAK: handle: $handle, created at:"); - print("${handleCreation.stack}"); + print("HANDLE LEAK: handle: $handle"); + if (handleCreation.description != null) { + print("HANDLE LEAK: message: ${handleCreation.description}"); + } + print("HANDLE LEAK: stack at creation:\n${handleCreation.stack}"); noleaks = false; } } diff --git a/third_party/mojo/src/mojo/public/dart/lib/src/message_pipe.dart b/third_party/mojo/src/mojo/public/dart/lib/src/message_pipe.dart index 29ae078b926b8a..62c7cb3a88bc6a 100644 --- a/third_party/mojo/src/mojo/public/dart/lib/src/message_pipe.dart +++ b/third_party/mojo/src/mojo/public/dart/lib/src/message_pipe.dart @@ -109,6 +109,11 @@ class MojoMessagePipeEndpoint { MojoMessagePipeReadResult query() => read(null); + bool setDescription(String description) { + assert(MojoHandle._setHandleLeakDescription(handle, description)); + return true; + } + void close() { handle.close(); handle = null; diff --git a/third_party/mojo/src/mojo/public/dart/pubspec.yaml b/third_party/mojo/src/mojo/public/dart/pubspec.yaml index e8d5fc69c6ea47..3944b3486cfa97 100644 --- a/third_party/mojo/src/mojo/public/dart/pubspec.yaml +++ b/third_party/mojo/src/mojo/public/dart/pubspec.yaml @@ -4,4 +4,4 @@ dependencies: description: Dart files to support executing inside Mojo. homepage: https://github.com/domokit/mojo name: mojo -version: 0.0.10 +version: 0.0.13 diff --git a/third_party/mojo/src/mojo/public/dart/rules.gni b/third_party/mojo/src/mojo/public/dart/rules.gni index 7786cd49f64dc4..36fc92d15e0763 100644 --- a/third_party/mojo/src/mojo/public/dart/rules.gni +++ b/third_party/mojo/src/mojo/public/dart/rules.gni @@ -116,7 +116,7 @@ template("dartzip_package") { rebase_path(package_output), rebase_path("$target_gen_dir/${package_target_name}_analyze.stamp"), "--no-hints", - "--url-mapping=dart:mojo.io,/" + + "--url-mapping=dart:io,/" + rebase_path("mojo/public/dart/lib/io.dart", "/", mojo_sdk_root), ] diff --git a/third_party/mojo/src/mojo/public/go/bindings/message.go b/third_party/mojo/src/mojo/public/go/bindings/message.go index 0e0833c5a427fc..1ce64d9e9f5fee 100644 --- a/third_party/mojo/src/mojo/public/go/bindings/message.go +++ b/third_party/mojo/src/mojo/public/go/bindings/message.go @@ -85,7 +85,7 @@ func (h *MessageHeader) Encode(encoder *Encoder) error { if err := encoder.WriteUint32(h.Flags); err != nil { return err } - if h.RequestId != 0 { + if h.Flags != MessageNoFlag { if err := encoder.WriteUint64(h.RequestId); err != nil { return err } @@ -140,14 +140,14 @@ func (h *MessageHeader) Decode(decoder *Decoder) error { func (h *MessageHeader) dataSize() uint32 { var size uint32 size = 2 * 4 - if h.RequestId != 0 { + if h.Flags != MessageNoFlag { size += 8 } return size } func (h *MessageHeader) version() uint32 { - if h.RequestId != 0 { + if h.Flags != MessageNoFlag { return 1 } else { return 0 diff --git a/third_party/mojo/src/mojo/public/interfaces/bindings/tests/test_unions.mojom b/third_party/mojo/src/mojo/public/interfaces/bindings/tests/test_unions.mojom index 8794259ff33ddf..6e631b22afd4e5 100644 --- a/third_party/mojo/src/mojo/public/interfaces/bindings/tests/test_unions.mojom +++ b/third_party/mojo/src/mojo/public/interfaces/bindings/tests/test_unions.mojom @@ -49,10 +49,6 @@ struct WrapperStruct { HandleUnion? handle_union; }; -struct HandleStruct { - SmallCache f_small_cache; -}; - struct DummyStruct { int8 f_int8; }; @@ -81,5 +77,10 @@ interface SmallCache { }; interface UnionInterface { - Echo(PodUnion in) => (PodUnion out); + Echo(PodUnion in_val) => (PodUnion out_val); +}; + +struct TryNonNullStruct { + DummyStruct? nullable; + DummyStruct non_nullable; }; diff --git a/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ExecutorFactory.java b/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ExecutorFactory.java index e24c96684e81e4..c621d9b0be83ec 100644 --- a/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ExecutorFactory.java +++ b/third_party/mojo/src/mojo/public/java/bindings/src/org/chromium/mojo/bindings/ExecutorFactory.java @@ -140,7 +140,7 @@ private boolean readNotifyBufferMessage() { */ private void runNextAction() { Runnable toRun = null; - synchronized (mWriteHandle) { + synchronized (mLock) { toRun = mPendingActions.remove(0); } toRun.run(); diff --git a/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/InvalidHandle.java b/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/InvalidHandle.java index 9dff70e2e63c4f..9c20fddb1d6e75 100644 --- a/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/InvalidHandle.java +++ b/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/InvalidHandle.java @@ -82,7 +82,7 @@ public UntypedHandle toUntypedHandle() { */ @Override public int releaseNativeHandle() { - return -1; + return 0; } /** diff --git a/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/MojoException.java b/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/MojoException.java index e06f647aeb023b..4e0e3e959713dc 100644 --- a/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/MojoException.java +++ b/third_party/mojo/src/mojo/public/java/system/src/org/chromium/mojo/system/MojoException.java @@ -18,6 +18,14 @@ public MojoException(int code) { mCode = code; } + /** + * Constructor. + */ + public MojoException(Throwable cause) { + super(cause); + mCode = MojoResult.UNKNOWN; + } + /** * The mojo result code associated with this exception. See {@link MojoResult} for possible * values. diff --git a/third_party/mojo/src/mojo/public/js/codec.js b/third_party/mojo/src/mojo/public/js/codec.js index 2930c59f274993..90766e6fcfa697 100644 --- a/third_party/mojo/src/mojo/public/js/codec.js +++ b/third_party/mojo/src/mojo/public/js/codec.js @@ -46,6 +46,10 @@ define("mojo/public/js/codec", [ this.next = base; } + Decoder.prototype.align = function() { + this.next = align(this.next); + }; + Decoder.prototype.skip = function(offset) { this.next += offset; }; @@ -213,6 +217,10 @@ define("mojo/public/js/codec", [ this.next = base; } + Encoder.prototype.align = function() { + this.next = align(this.next); + }; + Encoder.prototype.skip = function(offset) { this.next += offset; }; diff --git a/third_party/mojo/src/mojo/public/js/union_unittests.js b/third_party/mojo/src/mojo/public/js/union_unittests.js new file mode 100644 index 00000000000000..5dcda7d11746bb --- /dev/null +++ b/third_party/mojo/src/mojo/public/js/union_unittests.js @@ -0,0 +1,184 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +define([ + "gin/test/expect", + "mojo/public/interfaces/bindings/tests/test_unions.mojom", + "mojo/public/js/codec", + "mojo/public/js/validator", +], function(expect, + unions, + codec, + validator) { + function testConstructors() { + var u = new unions.PodUnion(); + expect(u.$data).toEqual(null); + expect(u.$tag).toBeUndefined(); + + u.f_uint32 = 32; + + expect(u.f_uint32).toEqual(32); + expect(u.$tag).toEqual(unions.PodUnion.Tags.f_uint32); + + var u = new unions.PodUnion({f_uint64: 64}); + expect(u.f_uint64).toEqual(64); + expect(u.$tag).toEqual(unions.PodUnion.Tags.f_uint64); + expect(function() {var v = u.f_uint32;}).toThrow(); + + expect(function() { + var u = new unions.PodUnion({ + f_uint64: 64, + f_uint32: 32, + }); + }).toThrow(); + + expect(function() { + var u = new unions.PodUnion({ foo: 64 }); }).toThrow(); + + expect(function() { + var u = new unions.PodUnion([1,2,3,4]); }).toThrow(); + } + + function structEncodeDecode(struct) { + var structClass = struct.constructor; + var builder = new codec.MessageBuilder(1234, structClass.encodedSize); + builder.encodeStruct(structClass, struct); + + var message = builder.finish(); + + var messageValidator = new validator.Validator(message); + var err = structClass.validate(messageValidator, codec.kMessageHeaderSize); + expect(err).toEqual(validator.validationError.NONE); + + var reader = new codec.MessageReader(message); + var view = reader.decoder.buffer.dataView; + + return reader.decodeStruct(structClass); + } + + function testBasicEncoding() { + var s = new unions.WrapperStruct({ + pod_union: new unions.PodUnion({ + f_uint64: 64})}); + + var decoded = structEncodeDecode(s); + expect(decoded).toEqual(s); + + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion({ + f_dummy: new unions.DummyStruct({ + f_int8: 8})})}); + + var decoded = structEncodeDecode(s); + expect(decoded).toEqual(s); + + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion({ + f_array_int8: [1, 2, 3]})}); + + var decoded = structEncodeDecode(s); + expect(decoded).toEqual(s); + + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion({ + f_map_int8: new Map([ + ["first", 1], + ["second", 2], + ])})}); + + var decoded = structEncodeDecode(s); + expect(decoded).toEqual(s); + + // Encoding a union with no member set is an error. + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion()}); + expect(function() { + structEncodeDecode(s); }).toThrow(); + } + + function testUnionsInArrayEncoding() { + var s = new unions.SmallStruct({ + pod_union_array: [ + new unions.PodUnion({f_uint32: 32}), + new unions.PodUnion({f_uint64: 64}), + ] + }); + + var decoded = structEncodeDecode(s); + expect(decoded).toEqual(s); + } + + function testUnionsInMapEncoding() { + var s = new unions.SmallStruct({ + pod_union_map: new Map([ + ["thirty-two", new unions.PodUnion({f_uint32: 32})], + ["sixty-four", new unions.PodUnion({f_uint64: 64})], + ]) + }); + + var decoded = structEncodeDecode(s); + expect(decoded).toEqual(s); + } + + function testNestedUnionsEncoding() { + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion({ + f_pod_union: new unions.PodUnion({f_uint32: 32}) + })}); + var decoded = structEncodeDecode(s); + expect(decoded).toEqual(s); + } + + function structValidate(struct) { + var structClass = struct.constructor; + var builder = new codec.MessageBuilder(1234, structClass.encodedSize); + builder.encodeStruct(structClass, struct); + + var message = builder.finish(); + + var messageValidator = new validator.Validator(message); + return structClass.validate(messageValidator, codec.kMessageHeaderSize); + } + + function testNullUnionMemberValidation() { + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion({ + f_dummy: null})}); + + var err = structValidate(s); + expect(err).toEqual(validator.validationError.UNEXPECTED_NULL_POINTER); + + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion({ + f_nullable: null})}); + + var err = structValidate(s); + expect(err).toEqual(validator.validationError.NONE); + } + + function testNullUnionValidation() { + var s = new unions.SmallStructNonNullableUnion({ + pod_union: null}); + + var err = structValidate(s); + expect(err).toEqual(validator.validationError.UNEXPECTED_NULL_UNION); + + var s = new unions.WrapperStruct({ + object_union: new unions.ObjectUnion({ + f_pod_union: null}) + }); + + var err = structValidate(s); + expect(err).toEqual(validator.validationError.UNEXPECTED_NULL_UNION); + } + + testConstructors(); + testBasicEncoding(); + testUnionsInArrayEncoding(); + testUnionsInMapEncoding(); + testNestedUnionsEncoding(); + testNullUnionMemberValidation(); + testNullUnionValidation(); + this.result = "PASS"; +}); diff --git a/third_party/mojo/src/mojo/public/js/validator.js b/third_party/mojo/src/mojo/public/js/validator.js index 5568c5f52a6881..cbf7521b5c3bfa 100644 --- a/third_party/mojo/src/mojo/public/js/validator.js +++ b/third_party/mojo/src/mojo/public/js/validator.js @@ -22,6 +22,8 @@ define("mojo/public/js/validator", [ 'VALIDATION_ERROR_MESSAGE_HEADER_MISSING_REQUEST_ID', DIFFERENT_SIZED_ARRAYS_IN_MAP: 'VALIDATION_ERROR_DIFFERENT_SIZED_ARRAYS_IN_MAP', + INVALID_UNION_SIZE: 'VALIDATION_ERROR_INVALID_UNION_SIZE', + UNEXPECTED_NULL_UNION: 'VALIDATION_ERROR_UNEXPECTED_NULL_UNION', }; var NULL_MOJO_POINTER = "NULL_MOJO_POINTER"; @@ -173,6 +175,14 @@ define("mojo/public/js/validator", [ return Number.isSafeInteger(bufferOffset) ? bufferOffset : null; } + Validator.prototype.decodeUnionSize = function(offset) { + return this.message.buffer.getUint32(offset); + }; + + Validator.prototype.decodeUnionTag = function(offset) { + return this.message.buffer.getUint32(offset + 4); + }; + Validator.prototype.validateArrayPointer = function( offset, elementSize, elementType, nullable, expectedDimensionSizes, currentDimension) { @@ -201,6 +211,30 @@ define("mojo/public/js/validator", [ return structClass.validate(this, structOffset); } + Validator.prototype.validateUnion = function( + offset, unionClass, nullable) { + var size = this.message.buffer.getUint32(offset); + if (size == 0) { + return nullable ? + validationError.NONE : validationError.UNEXPECTED_NULL_UNION; + } + + return unionClass.validate(this, offset); + } + + Validator.prototype.validateNestedUnion = function( + offset, unionClass, nullable) { + var unionOffset = this.decodePointer(offset); + if (unionOffset === null) + return validationError.ILLEGAL_POINTER; + + if (unionOffset === NULL_MOJO_POINTER) + return nullable ? + validationError.NONE : validationError.UNEXPECTED_NULL_UNION; + + return this.validateUnion(unionOffset, unionClass, nullable); + } + // This method assumes that the array at arrayPointerOffset has // been validated. diff --git a/third_party/mojo/src/mojo/public/mojo_application.gni b/third_party/mojo/src/mojo/public/mojo_application.gni index fd3160cc6235db..7ab5a3118e0a63 100644 --- a/third_party/mojo/src/mojo/public/mojo_application.gni +++ b/third_party/mojo/src/mojo/public/mojo_application.gni @@ -25,7 +25,7 @@ template("mojo_native_application") { library_name = "lib${library_target_name}.so" } else if (is_win) { library_name = "${library_target_name}.dll" - } else if (is_mac) { + } else if (is_mac || is_ios) { library_name = "lib${library_target_name}.dylib" } else { assert(false, "Platform not supported.") diff --git a/third_party/mojo/src/mojo/public/tools/NETWORK_SERVICE_VERSION b/third_party/mojo/src/mojo/public/tools/NETWORK_SERVICE_VERSION index 9bd67c40f90114..7b21d79bf0d2fb 100644 --- a/third_party/mojo/src/mojo/public/tools/NETWORK_SERVICE_VERSION +++ b/third_party/mojo/src/mojo/public/tools/NETWORK_SERVICE_VERSION @@ -1 +1 @@ -d4e095822875bead3d6a7d6144a087b6794e5066 +36d008970120c7bce0e7cb0a6543fd0b653dad88 \ No newline at end of file diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl index 28e6ceb7384846..927b3ffa1c09fb 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_definition.tmpl @@ -29,14 +29,14 @@ } {%- endif %} {%- if kind|is_array_kind or kind|is_string_kind %} - const mojo::internal::ArrayValidateParams {{name}}_validate_params = - {{kind|get_array_validate_params|indent(6)}}; + const mojo::internal::ArrayValidateParams {{name}}_validate_params( + {{kind|get_array_validate_params_ctor_args|indent(6)}}); if (!{{wrapper_type}}::Data_::Validate( mojo::internal::DecodePointerRaw(&object->{{name}}.offset), bounds_checker, &{{name}}_validate_params)) { {%- elif kind|is_map_kind %} - const mojo::internal::ArrayValidateParams {{name}}_validate_params = - {{kind.value_kind|get_map_validate_params|indent(6)}}; + const mojo::internal::ArrayValidateParams {{name}}_validate_params( + {{kind.value_kind|get_map_validate_params_ctor_args|indent(6)}}); if (!{{wrapper_type}}::Data_::Validate( mojo::internal::DecodePointerRaw(&object->{{name}}.offset), bounds_checker, &{{name}}_validate_params)) { diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl index 6c8254ea253abe..48b76e54038004 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl @@ -45,13 +45,13 @@ {%- set kind = pf.field.kind %} {%- if kind|is_object_kind %} {%- if kind|is_array_kind %} - const mojo::internal::ArrayValidateParams {{name}}_validate_params = - {{kind|get_array_validate_params|indent(10)}}; + const mojo::internal::ArrayValidateParams {{name}}_validate_params( + {{kind|get_array_validate_params_ctor_args|indent(10)}}); mojo::SerializeArray_(mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr, &{{name}}_validate_params); {%- elif kind|is_map_kind %} - const mojo::internal::ArrayValidateParams {{name}}_validate_params = - {{kind.value_kind|get_map_validate_params|indent(10)}}; + const mojo::internal::ArrayValidateParams {{name}}_validate_params( + {{kind.value_kind|get_map_validate_params_ctor_args|indent(10)}}); mojo::SerializeMap_( mojo::internal::Forward({{input_field}}), {{buffer}}, &{{output}}->{{name}}.ptr, &{{name}}_validate_params); diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl index f07c487baa4fad..120b1231a5340e 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl @@ -55,14 +55,14 @@ void SerializeUnion_({{union.name}}Ptr input, mojo::internal::Buffer* buf, mojo::internal::Forward(*(input_acc.data()->{{field.name}})), buf, &result->data.f_{{field.name}}.ptr, false); {% elif field.kind|is_array_kind %} - const mojo::internal::ArrayValidateParams {{field.name}}_validate_params = - {{field.kind|get_array_validate_params|indent(16)}}; + const mojo::internal::ArrayValidateParams {{field.name}}_validate_params( + {{field.kind|get_array_validate_params_ctor_args|indent(16)}}); SerializeArray_( mojo::internal::Forward(*(input_acc.data()->{{field.name}})), buf, &result->data.f_{{field.name}}.ptr, &{{field.name}}_validate_params); {% elif field.kind|is_map_kind %} - const mojo::internal::ArrayValidateParams {{field.name}}_validate_params = - {{field.kind.value_kind|get_map_validate_params|indent(16)}}; + const mojo::internal::ArrayValidateParams {{field.name}}_validate_params( + {{field.kind.value_kind|get_map_validate_params_ctor_args|indent(16)}}); SerializeMap_( mojo::internal::Forward(*(input_acc.data()->{{field.name}})), buf, &result->data.f_{{field.name}}.ptr, &{{field.name}}_validate_params); diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl index d12c54b43eccad..5cb1dc8b68d129 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/validation_macros.tmpl @@ -15,9 +15,8 @@ if (!mojo::internal::ValidateEncodedPointer(&{{field_expr}}->offset)) { {%- endmacro %} {%- macro validate_array_or_string(field_expr, field) -%} -const mojo::internal::ArrayValidateParams - {{field.name}}_validate_params = - {{field.kind|get_array_validate_params|indent(8)}}; +const mojo::internal::ArrayValidateParams {{field.name}}_validate_params( + {{field.kind|get_array_validate_params_ctor_args|indent(4)}}); if (!{{field.kind|cpp_wrapper_type}}::Data_::Validate( mojo::internal::DecodePointerRaw(&{{field_expr}}->offset), bounds_checker, &{{field.name}}_validate_params)) { diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl index 1378fa399d6f13..65c932a86e4e86 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/interface_definition.tmpl @@ -46,8 +46,10 @@ class {{interface|name}}ProxyImpl extends bindings.Proxy { {{interface|name}}ProxyImpl.unbound() : super.unbound(); static {{interface|name}}ProxyImpl newFromEndpoint( - core.MojoMessagePipeEndpoint endpoint) => - new {{interface|name}}ProxyImpl.fromEndpoint(endpoint); + core.MojoMessagePipeEndpoint endpoint) { + assert(endpoint.setDescription("For {{interface|name}}ProxyImpl")); + return new {{interface|name}}ProxyImpl.fromEndpoint(endpoint); + } String get name => {{interface|name}}Name; @@ -155,8 +157,10 @@ class {{interface|name}}Proxy implements bindings.ProxyBase { } static {{interface|name}}Proxy newFromEndpoint( - core.MojoMessagePipeEndpoint endpoint) => - new {{interface|name}}Proxy.fromEndpoint(endpoint); + core.MojoMessagePipeEndpoint endpoint) { + assert(endpoint.setDescription("For {{interface|name}}Proxy")); + return new {{interface|name}}Proxy.fromEndpoint(endpoint); + } Future close({bool immediate: false}) => impl.close(immediate: immediate); @@ -187,8 +191,10 @@ class {{interface|name}}Stub extends bindings.Stub { {{interface|name}}Stub.unbound() : super.unbound(); static {{interface|name}}Stub newFromEndpoint( - core.MojoMessagePipeEndpoint endpoint) => - new {{interface|name}}Stub.fromEndpoint(endpoint); + core.MojoMessagePipeEndpoint endpoint) { + assert(endpoint.setDescription("For {{interface|name}}Stub")); + return new {{interface|name}}Stub.fromEndpoint(endpoint); + } static const String name = {{interface|name}}Name; diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl index b4a74207a5d5bf..511201eb30da38 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/dart_templates/union_definition.tmpl @@ -12,7 +12,7 @@ enum {{union|name}}Tag { {%- endmacro %} {%- macro wrapper_def(union) %} -class {{union|name}}Wrapper extends bindings.Union { +class {{union|name}} extends bindings.Union { static final _tag_to_int = const { {%- for field in union.fields %} {{union|name}}Tag.{{field|tag_name}}: {{field.ordinal}}, @@ -44,12 +44,12 @@ class {{union|name}}Wrapper extends bindings.Union { } {%- endfor %} - static {{union|name}}Wrapper decode(bindings.Decoder decoder0, int offset) { + static {{union|name}} decode(bindings.Decoder decoder0, int offset) { int size = decoder0.decodeUint32(offset); if (size == 0) { return null; } - {{union|name}}Wrapper result = new {{union|name}}Wrapper(); + {{union|name}} result = new {{union|name}}(); // TODO(azani): Handle unknown union member. {{union|name}}Tag tag = _int_to_tag[decoder0.decodeUint32(offset + 4)]; @@ -87,7 +87,7 @@ class {{union|name}}Wrapper extends bindings.Union { } String toString() { - String result = "{{union|name}}Wrapper("; + String result = "{{union|name}}("; switch (_tag) { {%- for field in union.fields %} case {{union|name}}Tag.{{field|tag_name}}: @@ -97,7 +97,8 @@ class {{union|name}}Wrapper extends bindings.Union { default: result += "unknown"; } - result += ": $_data)" + result += ": $_data)"; + return result; } } {%- endmacro %} diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/module_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/module_definition.tmpl index 64480817db2874..86ea2ce257e085 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/module_definition.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/module_definition.tmpl @@ -14,6 +14,12 @@ {%- include "struct_definition.tmpl" %} {%- endfor -%} +{#--- Union definitions #} +{%- from "union_definition.tmpl" import union_def %} +{%- for union in unions %} +{{union_def(union)|indent(2)}} +{%- endfor %} + {#--- Interface definitions #} {%- for interface in interfaces -%} {%- include "interface_definition.tmpl" %} @@ -29,6 +35,9 @@ {%- for struct in structs if struct.exported %} exports.{{struct.name}} = {{struct.name}}; {%- endfor %} +{%- for union in unions %} + exports.{{union.name}} = {{union.name}}; +{%- endfor %} {%- for interface in interfaces %} exports.{{interface.name}} = {{interface.name}}; {#--- Interface Client #} diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl index cd0cb6d643db4d..ca80d677de92b0 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/struct_definition.tmpl @@ -34,40 +34,16 @@ {{struct.name}}.validate = function(messageValidator, offset) { var err; -{% macro check_err() -%} + err = messageValidator.validateStructHeader(offset, {{struct.name}}.encodedSize, {{struct.versions[-1].version}}); if (err !== validator.validationError.NONE) return err; -{%- endmacro %} - err = messageValidator.validateStructHeader(offset, {{struct.name}}.encodedSize, {{struct.versions[-1].version}}); - {{check_err()}} +{%- from "validation_macros.tmpl" import validate_struct_field %} {%- for packed_field in struct.packed.packed_fields %} -{%- set field_name = packed_field.field.name %} -{%- if packed_field.field|is_string_pointer_field %} - // validate {{struct.name}}.{{field_name}} - err = messageValidator.validateStringPointer({{packed_field|validate_string_params}}) - {{check_err()}} -{%- elif packed_field.field|is_array_pointer_field %} - // validate {{struct.name}}.{{field_name}} - err = messageValidator.validateArrayPointer({{packed_field|validate_array_params}}); - {{check_err()}} -{%- elif packed_field.field|is_struct_pointer_field %} - // validate {{struct.name}}.{{field_name}} - err = messageValidator.validateStructPointer({{packed_field|validate_struct_params}}); - {{check_err()}} -{%- elif packed_field.field|is_map_pointer_field %} - // validate {{struct.name}}.{{field_name}} - err = messageValidator.validateMapPointer({{packed_field|validate_map_params}}); - {{check_err()}} -{%- elif packed_field.field|is_interface_field %} - // validate {{struct.name}}.{{field_name}} - err = messageValidator.validateInterface({{packed_field|validate_interface_params}}); - {{check_err()}} -{%- elif packed_field.field|is_handle_field %} - // validate {{struct.name}}.{{field_name}} - err = messageValidator.validateHandle({{packed_field|validate_handle_params}}) - {{check_err()}} -{%- endif %} +{%- set offset = packed_field|field_offset %} +{%- set field = packed_field.field %} +{%- set name = struct.name ~ '.' ~ field.name %} +{{validate_struct_field(field, offset, name)|indent(4)}} {%- endfor %} return validator.validationError.NONE; diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/union_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/union_definition.tmpl new file mode 100644 index 00000000000000..3c903bc1f29668 --- /dev/null +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/union_definition.tmpl @@ -0,0 +1,146 @@ +{%- macro union_def(union) %} +function {{union.name}}(value) { + this.initDefault_(); + this.initValue_(value); +} + +{{tags(union)}} + +{{union.name}}.prototype.initDefault_ = function() { + this.$data = null; + this.$tag = undefined; +} + +{{union.name}}.prototype.initValue_ = function(value) { + if (value == undefined) { + return; + } + + var keys = Object.keys(value); + if (keys.length == 0) { + return; + } + + if (keys.length > 1) { + throw new TypeError("You may set only one member on a union."); + } + + var fields = [ +{%- for field in union.fields %} + "{{field.name}}", +{%- endfor %} + ]; + + if (fields.indexOf(keys[0]) < 0) { + throw new ReferenceError(keys[0] + " is not a {{union.name}} member."); + + } + + this[keys[0]] = value[keys[0]]; +} + +{%- for field in union.fields %} +Object.defineProperty({{union.name}}.prototype, "{{field.name}}", { + get: function() { + if (this.$tag != {{union.name}}.Tags.{{field.name}}) { + throw new ReferenceError( + "{{union.name}}.{{field.name}} is not currently set."); + } + return this.$data; + }, + + set: function(value) { + this.$tag = {{union.name}}.Tags.{{field.name}}; + this.$data = value; + } +}); +{%- endfor %} + +{{encode(union)|indent(2)}} + +{{decode(union)|indent(2)}} + +{{validate(union)|indent(2)}} + +{{union.name}}.encodedSize = 16; +{%- endmacro %} + +{%- macro tags(union) %} +{{union.name}}.Tags = { +{%- for field in union.fields %} + {{field.name}}: {{field.ordinal}}, +{%- endfor %} +}; +{%- endmacro %} + +{%- macro encode(union) %} +{{union.name}}.encode = function(encoder, val) { + if (val == null) { + encoder.writeUint64(0); + encoder.writeUint64(0); + return; + } + if (val.$tag == undefined) { + throw new TypeError("Cannot encode unions with an unknown member set."); + } + + encoder.writeUint32(16); + encoder.writeUint32(val.$tag); + switch (val.$tag) { +{%- for field in union.fields %} + case {{union.name}}.Tags.{{field.name}}: + encoder.{{field.kind|union_encode_snippet}}val.{{field.name}}); + break; +{%- endfor %} + } + encoder.align(); +}; +{%- endmacro %} + +{%- macro decode(union) %} +{{union.name}}.decode = function(decoder) { + var size = decoder.readUint32(); + if (size == 0) { + decoder.readUint32(); + decoder.readUint64(); + return null; + } + + var result = new {{union.name}}(); + var tag = decoder.readUint32(); + switch (tag) { +{%- for field in union.fields %} + case {{union.name}}.Tags.{{field.name}}: + result.{{field.name}} = decoder.{{field.kind|union_decode_snippet}}; + break; +{%- endfor %} + } + decoder.align(); + + return result; +}; +{%- endmacro %} + +{%- from "validation_macros.tmpl" import validate_union_field %} +{%- macro validate(union) %} +{{union.name}}.validate = function(messageValidator, offset) { + var size = messageValidator.decodeUnionSize(offset); + if (size != 16) { + return validator.validationError.INVALID_UNION_SIZE; + } + + var tag = messageValidator.decodeUnionTag(offset); + var data_offset = offset + 8; + var err; + switch (tag) { +{%- for field in union.fields %} +{%- set name = union.name ~ '.' ~ field.name %} + case {{union.name}}.Tags.{{field.name}}: + {{validate_union_field(field, "data_offset", name)}} + break; +{%- endfor %} + } + + return validator.validationError.NONE; +}; +{%- endmacro %} diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/validation_macros.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/validation_macros.tmpl new file mode 100644 index 00000000000000..7a39749b6bfb04 --- /dev/null +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/js_templates/validation_macros.tmpl @@ -0,0 +1,52 @@ +{% macro _check_err() -%} +if (err !== validator.validationError.NONE) + return err; +{%- endmacro %} + +{%- macro _validate_field(field, offset, name) %} +{%- if field|is_string_pointer_field %} +// validate {{name}} +err = messageValidator.validateStringPointer({{offset}}, {{field|validate_string_params}}) +{{_check_err()}} +{%- elif field|is_array_pointer_field %} +// validate {{name}} +err = messageValidator.validateArrayPointer({{offset}}, {{field|validate_array_params}}); +{{_check_err()}} +{%- elif field|is_struct_pointer_field %} +// validate {{name}} +err = messageValidator.validateStructPointer({{offset}}, {{field|validate_struct_params}}); +{{_check_err()}} +{%- elif field|is_map_pointer_field %} +// validate {{name}} +err = messageValidator.validateMapPointer({{offset}}, {{field|validate_map_params}}); +{{_check_err()}} +{%- elif field|is_interface_field %} +// validate {{name}} +err = messageValidator.validateInterface({{offset}}, {{field|validate_interface_params}}); +{{_check_err()}} +{%- elif field|is_handle_field %} +// validate {{name}} +err = messageValidator.validateHandle({{offset}}, {{field|validate_handle_params}}) +{{_check_err()}} +{%- endif %} +{%- endmacro %} + +{%- macro validate_struct_field(field, offset, name) %} +{%- if field|is_union_field %} +// validate {{name}} +err = messageValidator.validateUnion({{offset}}, {{field|validate_union_params}}); +{{_check_err()}} +{%- else %} +{{_validate_field(field, offset, name)}} +{%- endif %} +{%- endmacro %} + +{%- macro validate_union_field(field, offset, name) %} +{%- if field|is_union_field %} +// validate {{name}} +err = messageValidator.validateNestedUnion({{offset}}, {{field|validate_union_params}}); +{{_check_err()}} +{%- else %} +{{_validate_field(field, offset, name)}} +{%- endif %} +{%- endmacro %} diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_cpp_generator.py b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_cpp_generator.py index f321c448b0d139..3d590872ad7c1a 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_cpp_generator.py +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_cpp_generator.py @@ -54,7 +54,7 @@ def DefaultValue(field): return "" def NamespaceToArray(namespace): - return namespace.split('.') if namespace else [] + return namespace.split(".") if namespace else [] def GetNameForKind(kind, internal = False): parts = [] @@ -286,11 +286,11 @@ def TranslateConstants(token, kind): # so the integral constant -2147483648 causes it grief: it decides to # represent 2147483648 as an unsigned integer, and then warns that the unary # minus operator doesn't make sense on unsigned types. Doh! - if kind == mojom.INT32 and token == '-2147483648': - return '(-%d - 1) /* %s */' % ( - 2**31 - 1, 'Workaround for MSVC bug; see https://crbug.com/445618') + if kind == mojom.INT32 and token == "-2147483648": + return "(-%d - 1) /* %s */" % ( + 2**31 - 1, "Workaround for MSVC bug; see https://crbug.com/445618") - return '%s%s' % (token, _kind_to_cpp_literal_suffix.get(kind, '')) + return "%s%s" % (token, _kind_to_cpp_literal_suffix.get(kind, "")) def ExpressionToText(value, kind=None): return TranslateConstants(value, kind) @@ -307,11 +307,7 @@ def ShouldInlineStruct(struct): def ShouldInlineUnion(union): return not any(mojom.IsMoveOnlyKind(field.kind) for field in union.fields) -def GetArrayValidateParams(kind, new=False): - if (not mojom.IsArrayKind(kind) and not mojom.IsMapKind(kind) and - not mojom.IsStringKind(kind)): - return "nullptr" - +def GetArrayValidateParamsCtorArgs(kind): if mojom.IsStringKind(kind): expected_num_elements = 0 element_is_nullable = False @@ -319,25 +315,30 @@ def GetArrayValidateParams(kind, new=False): elif mojom.IsMapKind(kind): expected_num_elements = 0 element_is_nullable = mojom.IsNullableKind(kind.value_kind) - element_validate_params = GetArrayValidateParams(kind.value_kind, new=True) + element_validate_params = GetNewArrayValidateParams(kind.value_kind) else: expected_num_elements = generator.ExpectedArraySize(kind) or 0 element_is_nullable = mojom.IsNullableKind(kind.kind) - element_validate_params = GetArrayValidateParams(kind.kind, new=True) + element_validate_params = GetNewArrayValidateParams(kind.kind) + + return "%d, %s, %s" % (expected_num_elements, + "true" if element_is_nullable else "false", + element_validate_params) + +def GetNewArrayValidateParams(kind): + if (not mojom.IsArrayKind(kind) and not mojom.IsMapKind(kind) and + not mojom.IsStringKind(kind)): + return "nullptr" - return "%smojo::internal::ArrayValidateParams(%d, %s,\n%s) " % ( - 'new ' if new else '', - expected_num_elements, - 'true' if element_is_nullable else 'false', - element_validate_params) + return "new mojo::internal::ArrayValidateParams(%s)" % ( + GetArrayValidateParamsCtorArgs(kind)) -def GetMapValidateParams(value_kind): +def GetMapValidateParamsCtorArgs(value_kind): # Unlike GetArrayValidateParams, we are given the wrapped kind, instead of # the raw array kind. So we wrap the return value of GetArrayValidateParams. element_is_nullable = mojom.IsNullableKind(value_kind) - return "mojo::internal::ArrayValidateParams(0, %s,\n%s) " % ( - 'true' if element_is_nullable else 'false', - GetArrayValidateParams(value_kind, new=True)) + return "0, %s, %s" % ("true" if element_is_nullable else "false", + GetNewArrayValidateParams(value_kind)) class Generator(generator.Generator): @@ -353,8 +354,8 @@ class Generator(generator.Generator): "cpp_wrapper_type": GetCppWrapperType, "default_value": DefaultValue, "expression_to_text": ExpressionToText, - "get_array_validate_params": GetArrayValidateParams, - "get_map_validate_params": GetMapValidateParams, + "get_array_validate_params_ctor_args": GetArrayValidateParamsCtorArgs, + "get_map_validate_params_ctor_args": GetMapValidateParamsCtorArgs, "get_name_for_kind": GetNameForKind, "get_pad": pack.GetPad, "has_callbacks": mojom.HasCallbacks, diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_dart_generator.py b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_dart_generator.py index 8c9a368a17fc8d..87c16ef8819e3f 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_dart_generator.py +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_dart_generator.py @@ -154,7 +154,7 @@ def DartDeclType(kind): if mojom.IsStructKind(kind): return GetDartType(kind) if mojom.IsUnionKind(kind): - return "%sWrapper" % GetDartType(kind) + return GetDartType(kind) if mojom.IsArrayKind(kind): array_type = DartDeclType(kind.kind) return "List<" + array_type + ">" @@ -204,10 +204,8 @@ def GetNameForElement(element): return GetNameForElement(element.kind) if isinstance(element, (mojom.Method, mojom.Parameter, - mojom.StructField)): + mojom.Field)): return CamelCase(element.name) - if isinstance(element, mojom.UnionField): - return "f%s" % UpperCamelCase(element.name) if isinstance(element, mojom.EnumValue): return (GetNameForElement(element.enum) + '.' + ConstantStyle(element.name)) @@ -221,7 +219,7 @@ def GetUnionFieldTagName(element): if not isinstance(element, mojom.UnionField): raise Exception('Unexpected element: %s is not a union field.' % element) - return 'tag%s' % UpperCamelCase(element.name) + return CamelCase(element.name) def GetInterfaceResponseName(method): return UpperCamelCase(method.name + 'Response') diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_js_generator.py b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_js_generator.py index 5315c35e87a22e..438267e9803fd6 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_js_generator.py +++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/mojom_js_generator.py @@ -52,6 +52,8 @@ def JavaScriptDefaultValue(field): return _kind_to_javascript_default_value[field.kind] if mojom.IsStructKind(field.kind): return "null" + if mojom.IsUnionKind(field.kind): + return "null" if mojom.IsArrayKind(field.kind): return "null" if mojom.IsMapKind(field.kind): @@ -61,6 +63,7 @@ def JavaScriptDefaultValue(field): return _kind_to_javascript_default_value[mojom.MSGPIPE] if mojom.IsEnumKind(field.kind): return "0" + raise Exception("No valid default: %s" % field) def JavaScriptPayloadSize(packed): @@ -107,6 +110,8 @@ def CodecType(kind): pointer_type = "NullablePointerTo" if mojom.IsNullableKind(kind) \ else "PointerTo" return "new codec.%s(%s)" % (pointer_type, JavaScriptType(kind)) + if mojom.IsUnionKind(kind): + return JavaScriptType(kind) if mojom.IsArrayKind(kind): array_type = "NullableArrayOf" if mojom.IsNullableKind(kind) else "ArrayOf" array_length = "" if kind.length is None else ", %d" % kind.length @@ -124,13 +129,14 @@ def CodecType(kind): key_type = ElementCodecType(kind.key_kind) value_type = ElementCodecType(kind.value_kind) return "new codec.%s(%s, %s)" % (map_type, key_type, value_type) - return kind + raise Exception("No codec type for %s" % kind) + def ElementCodecType(kind): return "codec.PackedBool" if mojom.IsBoolKind(kind) else CodecType(kind) def JavaScriptDecodeSnippet(kind): - if kind in mojom.PRIMITIVES: + if kind in mojom.PRIMITIVES or mojom.IsUnionKind(kind): return "decodeStruct(%s)" % CodecType(kind) if mojom.IsStructKind(kind): return "decodeStructPointer(%s)" % JavaScriptType(kind) @@ -143,15 +149,20 @@ def JavaScriptDecodeSnippet(kind): return "decodeArrayPointer(%s)" % CodecType(kind.kind) if mojom.IsInterfaceKind(kind): return "decodeStruct(%s)" % CodecType(kind) + if mojom.IsUnionKind(kind): + return "decodeUnion(%s)" % CodecType(kind) if mojom.IsInterfaceRequestKind(kind): return JavaScriptDecodeSnippet(mojom.MSGPIPE) if mojom.IsEnumKind(kind): return JavaScriptDecodeSnippet(mojom.INT32) + raise Exception("No decode snippet for %s" % kind) def JavaScriptEncodeSnippet(kind): - if kind in mojom.PRIMITIVES: + if kind in mojom.PRIMITIVES or mojom.IsUnionKind(kind): return "encodeStruct(%s, " % CodecType(kind) + if mojom.IsUnionKind(kind): + return "encodeStruct(%s, " % JavaScriptType(kind) if mojom.IsStructKind(kind): return "encodeStructPointer(%s, " % JavaScriptType(kind) if mojom.IsMapKind(kind): @@ -167,14 +178,27 @@ def JavaScriptEncodeSnippet(kind): return JavaScriptEncodeSnippet(mojom.MSGPIPE) if mojom.IsEnumKind(kind): return JavaScriptEncodeSnippet(mojom.INT32) + raise Exception("No encode snippet for %s" % kind) + + +def JavaScriptUnionDecodeSnippet(kind): + if mojom.IsUnionKind(kind): + return "decodeStructPointer(%s)" % JavaScriptType(kind) + return JavaScriptDecodeSnippet(kind) + + +def JavaScriptUnionEncodeSnippet(kind): + if mojom.IsUnionKind(kind): + return "encodeStructPointer(%s, " % JavaScriptType(kind) + return JavaScriptEncodeSnippet(kind) def JavaScriptFieldOffset(packed_field): return "offset + codec.kStructHeaderSize + %s" % packed_field.offset -def JavaScriptNullableParam(packed_field): - return "true" if mojom.IsNullableKind(packed_field.field.kind) else "false" +def JavaScriptNullableParam(field): + return "true" if mojom.IsNullableKind(field.kind) else "false" def GetArrayExpectedDimensionSizes(kind): @@ -188,49 +212,49 @@ def GetArrayExpectedDimensionSizes(kind): return expected_dimension_sizes -def JavaScriptValidateArrayParams(packed_field): - nullable = JavaScriptNullableParam(packed_field) - field_offset = JavaScriptFieldOffset(packed_field) - element_kind = packed_field.field.kind.kind +def JavaScriptValidateArrayParams(field): + nullable = JavaScriptNullableParam(field) + element_kind = field.kind.kind element_size = pack.PackedField.GetSizeForKind(element_kind) expected_dimension_sizes = GetArrayExpectedDimensionSizes( - packed_field.field.kind) + field.kind) element_type = ElementCodecType(element_kind) - return "%s, %s, %s, %s, %s, 0" % \ - (field_offset, element_size, element_type, nullable, + return "%s, %s, %s, %s, 0" % \ + (element_size, element_type, nullable, expected_dimension_sizes) -def JavaScriptValidateStructParams(packed_field): - nullable = JavaScriptNullableParam(packed_field) - field_offset = JavaScriptFieldOffset(packed_field) - struct_type = JavaScriptType(packed_field.field.kind) - return "%s, %s, %s" % (field_offset, struct_type, nullable) +def JavaScriptValidateStructParams(field): + nullable = JavaScriptNullableParam(field) + struct_type = JavaScriptType(field.kind) + return "%s, %s" % (struct_type, nullable) +def JavaScriptValidateUnionParams(field): + nullable = JavaScriptNullableParam(field) + union_type = JavaScriptType(field.kind) + return "%s, %s" % (union_type, nullable) -def JavaScriptValidateMapParams(packed_field): - nullable = JavaScriptNullableParam(packed_field) - field_offset = JavaScriptFieldOffset(packed_field) - keys_type = ElementCodecType(packed_field.field.kind.key_kind) - values_kind = packed_field.field.kind.value_kind; +def JavaScriptValidateMapParams(field): + nullable = JavaScriptNullableParam(field) + keys_type = ElementCodecType(field.kind.key_kind) + values_kind = field.kind.value_kind; values_type = ElementCodecType(values_kind) values_nullable = "true" if mojom.IsNullableKind(values_kind) else "false" - return "%s, %s, %s, %s, %s" % \ - (field_offset, nullable, keys_type, values_type, values_nullable) + return "%s, %s, %s, %s" % \ + (nullable, keys_type, values_type, values_nullable) -def JavaScriptValidateStringParams(packed_field): - nullable = JavaScriptNullableParam(packed_field) - return "%s, %s" % (JavaScriptFieldOffset(packed_field), nullable) +def JavaScriptValidateStringParams(field): + nullable = JavaScriptNullableParam(field) + return "%s" % (nullable) -def JavaScriptValidateHandleParams(packed_field): - nullable = JavaScriptNullableParam(packed_field) - field_offset = JavaScriptFieldOffset(packed_field) - return "%s, %s" % (field_offset, nullable) +def JavaScriptValidateHandleParams(field): + nullable = JavaScriptNullableParam(field) + return "%s" % (nullable) -def JavaScriptValidateInterfaceParams(packed_field): - return JavaScriptValidateHandleParams(packed_field) +def JavaScriptValidateInterfaceParams(field): + return JavaScriptValidateHandleParams(field) def JavaScriptProxyMethodParameterValue(parameter): name = parameter.name; @@ -303,6 +327,9 @@ def IsHandleField(field): def IsInterfaceField(field): return mojom.IsInterfaceKind(field.kind) +def IsUnionField(field): + return mojom.IsUnionKind(field.kind) + class Generator(generator.Generator): @@ -311,6 +338,8 @@ class Generator(generator.Generator): "payload_size": JavaScriptPayloadSize, "decode_snippet": JavaScriptDecodeSnippet, "encode_snippet": JavaScriptEncodeSnippet, + "union_decode_snippet": JavaScriptUnionDecodeSnippet, + "union_encode_snippet": JavaScriptUnionEncodeSnippet, "expression_to_text": ExpressionToText, "field_offset": JavaScriptFieldOffset, "has_callbacks": mojom.HasCallbacks, @@ -318,6 +347,7 @@ class Generator(generator.Generator): "is_map_pointer_field": IsMapPointerField, "is_struct_pointer_field": IsStructPointerField, "is_string_pointer_field": IsStringPointerField, + "is_union_field": IsUnionField, "is_handle_field": IsHandleField, "is_interface_field": IsInterfaceField, "js_type": JavaScriptType, @@ -330,6 +360,7 @@ class Generator(generator.Generator): "validate_map_params": JavaScriptValidateMapParams, "validate_string_params": JavaScriptValidateStringParams, "validate_struct_params": JavaScriptValidateStructParams, + "validate_union_params": JavaScriptValidateUnionParams, } def GetParameters(self): @@ -340,6 +371,7 @@ def GetParameters(self): "enums": self.module.enums, "module": self.module, "structs": self.GetStructs() + self.GetStructsFromMethods(), + "unions": self.GetUnions(), "interfaces": self.GetInterfaces(), "imported_interfaces": self.GetImportedInterfaces(), } diff --git a/third_party/mojo/src/mojo/public/tools/bindings/mojom.gni b/third_party/mojo/src/mojo/public/tools/bindings/mojom.gni index 0ec51f883efcc9..03dd431e6289c6 100644 --- a/third_party/mojo/src/mojo/public/tools/bindings/mojom.gni +++ b/third_party/mojo/src/mojo/public/tools/bindings/mojom.gni @@ -109,6 +109,8 @@ template("mojom") { "$generator_root/generators/js_templates/module.amd.tmpl", "$generator_root/generators/js_templates/module_definition.tmpl", "$generator_root/generators/js_templates/struct_definition.tmpl", + "$generator_root/generators/js_templates/union_definition.tmpl", + "$generator_root/generators/js_templates/validation_macros.tmpl", "$generator_root/generators/python_templates/module.py.tmpl", "$generator_root/generators/python_templates/module_macros.tmpl", "$generator_root/generators/mojom_cpp_generator.py", diff --git a/third_party/mojo/src/mojo/public/tools/download_shell_binary.py b/third_party/mojo/src/mojo/public/tools/download_shell_binary.py index c8f0f401ebe95a..4710f7edf7d8a1 100755 --- a/third_party/mojo/src/mojo/public/tools/download_shell_binary.py +++ b/third_party/mojo/src/mojo/public/tools/download_shell_binary.py @@ -15,10 +15,6 @@ "android-arm" : "MojoShell.apk" } -if not sys.platform.startswith("linux"): - print "Not supported for your platform" - sys.exit(0) - CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) sys.path.insert(0, os.path.join(CURRENT_PATH, "pylib")) import gs @@ -41,7 +37,15 @@ def download(tools_directory, version_file): except IOError: pass # If the stamp file does not exist we need to download new binaries. - for platform in ["linux-x64", "android-arm"]: + if sys.platform.startswith("linux"): + platforms = ["linux-x64", "android-arm"] + elif sys.platform == "darwin": + platforms = ["android-arm"] + else: + print "No prebuilt shell available for %s" % sys.platform + return 0 + + for platform in platforms: download_version_for_platform(version, platform, tools_directory) with open(stamp_path, 'w') as stamp_file: diff --git a/third_party/mojo/src/mojo/public/tools/git/dart_pub_get.py b/third_party/mojo/src/mojo/public/tools/git/dart_pub_get.py index f2b0ddc3b17896..8d4106b3e309c9 100755 --- a/third_party/mojo/src/mojo/public/tools/git/dart_pub_get.py +++ b/third_party/mojo/src/mojo/public/tools/git/dart_pub_get.py @@ -14,11 +14,14 @@ import subprocess import sys -def pub_get(dart_sdk_path, target_directory): +def pub_get(dart_sdk_path, target_directory, upgrade): cmd = [ os.path.join(dart_sdk_path, "bin/pub") ] - cmd.extend(["get"]) + if upgrade: + cmd.extend(["upgrade"]) + else: + cmd.extend(["get"]) # Cache the downloaded pubs inside the repo to avoid the chance of multiple # simultaneous builds in different repos stomping on each other. @@ -36,7 +39,7 @@ def pub_get(dart_sdk_path, target_directory): -def main(repository_root, dart_sdk_path, dirs_to_ignore): +def main(repository_root, dart_sdk_path, dirs_to_ignore, upgrade): os.chdir(repository_root) # Relativize dart_sdk_path to repository_root. @@ -52,7 +55,7 @@ def main(repository_root, dart_sdk_path, dirs_to_ignore): ignore = reduce(lambda x, y: x or f.startswith(y), dirs_to_ignore, False) if ignore: continue - pub_get(dart_sdk_path_from_root, os.path.dirname(f)) + pub_get(dart_sdk_path_from_root, os.path.dirname(f), upgrade) if __name__ == '__main__': @@ -80,8 +83,13 @@ def main(repository_root, dart_sdk_path, dirs_to_ignore): "relative to the root of the repo. 'pub get' will " "not be run for any subdirectories of these " "directories.") + parser.add_argument("--upgrade", + action="store_true", + default=False, + help="Upgrade pub package dependencies") args = parser.parse_args() _current_path = os.path.dirname(os.path.realpath(__file__)) _repository_root = os.path.join(_current_path, args.repository_root) _dart_sdk_path = os.path.join(_current_path, args.dart_sdk_directory) - sys.exit(main(_repository_root, _dart_sdk_path, args.dirs_to_ignore)) + sys.exit( + main(_repository_root, _dart_sdk_path, args.dirs_to_ignore, args.upgrade))