diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/mojo/core | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/mojo/core')
50 files changed, 402 insertions, 185 deletions
diff --git a/chromium/mojo/core/BUILD.gn b/chromium/mojo/core/BUILD.gn index e6fcb96256f..c42daf24d62 100644 --- a/chromium/mojo/core/BUILD.gn +++ b/chromium/mojo/core/BUILD.gn @@ -2,6 +2,7 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/config/chromeos/ui_mode.gni") import("//build/config/compiler/compiler.gni") import("//build/config/nacl/config.gni") import("//testing/libfuzzer/fuzzer_test.gni") @@ -18,6 +19,7 @@ component("embedder_internal") { ":test_sources", "//mojo:*", "//mojo/core/embedder", + "//mojo/core/test:test_support", ] } @@ -57,6 +59,7 @@ template("core_impl_source_set") { "handle_table.h", "invitation_dispatcher.h", "message_pipe_dispatcher.h", + "node_channel.h", "node_controller.h", "options_validation.h", "platform_handle_dispatcher.h", @@ -86,7 +89,6 @@ template("core_impl_source_set") { "invitation_dispatcher.cc", "message_pipe_dispatcher.cc", "node_channel.cc", - "node_channel.h", "node_controller.cc", "platform_handle_dispatcher.cc", "platform_handle_in_transit.cc", @@ -160,7 +162,8 @@ template("core_impl_source_set") { # Use target_os == "chromeos" instead of is_chromeos because we need to # build NaCl targets (i.e. IRT) for ChromeOS the same as the rest of ChromeOS. - if (is_android || target_os == "chromeos") { + if (is_android || target_os == "chromeos" || + (target_os == "linux" && chromeos_is_browser_only)) { defines += [ "MOJO_CORE_LEGACY_PROTOCOL" ] } @@ -187,6 +190,7 @@ if (is_chromeos || is_linux || is_android || is_win) { defines = [ "MOJO_CORE_SHARED_LIBRARY" ] deps = [ ":impl_for_shared_library", + "//base:base_static", "//mojo/public/c/system:headers", ] if (is_win) { @@ -240,6 +244,7 @@ if (is_chromeos || is_linux || is_android || is_win) { test("mojo_core_unittests") { sources = [ "mojo_core_unittest.cc", + "mojo_core_unittest.h", "run_all_core_unittests.cc", ] @@ -289,6 +294,7 @@ source_set("test_sources") { "handle_table_unittest.cc", "message_pipe_unittest.cc", "message_unittest.cc", + "node_channel_unittest.cc", "options_validation_unittest.cc", "platform_handle_dispatcher_unittest.cc", "quota_unittest.cc", @@ -387,6 +393,7 @@ fuzzer_test("mojo_core_node_channel_fuzzer") { deps = [ ":core_impl_for_fuzzers", "//base", + "//mojo/core/test:test_support", "//mojo/public/cpp/platform", ] } diff --git a/chromium/mojo/core/atomic_flag.h b/chromium/mojo/core/atomic_flag.h index 075b837ab1b..aec7f4ee65b 100644 --- a/chromium/mojo/core/atomic_flag.h +++ b/chromium/mojo/core/atomic_flag.h @@ -33,7 +33,7 @@ namespace core { class AtomicFlag { public: AtomicFlag() : flag_(0) {} - ~AtomicFlag() {} + ~AtomicFlag() = default; void Set(bool value) { base::subtle::Release_Store(&flag_, value ? 1 : 0); } diff --git a/chromium/mojo/core/broker_win.cc b/chromium/mojo/core/broker_win.cc index e81bfd301cd..f734b6b6f55 100644 --- a/chromium/mojo/core/broker_win.cc +++ b/chromium/mojo/core/broker_win.cc @@ -8,6 +8,7 @@ #include <utility> #include "base/debug/alias.h" +#include "base/logging.h" #include "base/memory/platform_shared_memory_region.h" #include "base/numerics/safe_conversions.h" #include "base/strings/string_piece.h" @@ -118,7 +119,7 @@ Broker::Broker(PlatformHandle handle, bool wait_for_channel_handle) } } -Broker::~Broker() {} +Broker::~Broker() = default; PlatformChannelEndpoint Broker::GetInviterEndpoint() { return std::move(inviter_endpoint_); diff --git a/chromium/mojo/core/channel.cc b/chromium/mojo/core/channel.cc index 38cbaea5c99..5d855891e2e 100644 --- a/chromium/mojo/core/channel.cc +++ b/chromium/mojo/core/channel.cc @@ -11,6 +11,7 @@ #include <limits> #include <utility> +#include "base/logging.h" #include "base/macros.h" #include "base/memory/aligned_memory.h" #include "base/memory/ptr_util.h" @@ -577,7 +578,7 @@ Channel::Channel(Delegate* delegate, ? new ReadBuffer : nullptr) {} -Channel::~Channel() {} +Channel::~Channel() = default; void Channel::ShutDown() { ShutDownImpl(); diff --git a/chromium/mojo/core/channel.h b/chromium/mojo/core/channel.h index 62447f8756d..a639c53c452 100644 --- a/chromium/mojo/core/channel.h +++ b/chromium/mojo/core/channel.h @@ -252,7 +252,7 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel // was created (see Channel::Create). class Delegate { public: - virtual ~Delegate() {} + virtual ~Delegate() = default; // Notify of a received message. |payload| is not owned and must not be // retained; it will be null if |payload_size| is 0. |handles| are diff --git a/chromium/mojo/core/channel_fuchsia.cc b/chromium/mojo/core/channel_fuchsia.cc index 8ca10557d8d..2d818ac6804 100644 --- a/chromium/mojo/core/channel_fuchsia.cc +++ b/chromium/mojo/core/channel_fuchsia.cc @@ -99,16 +99,11 @@ class MessageView { DCHECK_GT(message_->data_num_bytes(), offset_); } - MessageView(MessageView&& other) { *this = std::move(other); } + MessageView(MessageView&& other) = default; - MessageView& operator=(MessageView&& other) { - message_ = std::move(other.message_); - offset_ = other.offset_; - handles_ = std::move(other.handles_); - return *this; - } + MessageView& operator=(MessageView&& other) = default; - ~MessageView() {} + ~MessageView() = default; const void* data() const { return static_cast<const char*>(message_->data()) + offset_; diff --git a/chromium/mojo/core/channel_posix.cc b/chromium/mojo/core/channel_posix.cc index 7b52b42f230..fb7c190b50a 100644 --- a/chromium/mojo/core/channel_posix.cc +++ b/chromium/mojo/core/channel_posix.cc @@ -47,11 +47,11 @@ class MessageView { DCHECK(!message_->data_num_bytes() || message_->data_num_bytes() > offset_); } - MessageView(MessageView&& other) { *this = std::move(other); } + MessageView(MessageView&& other) = default; MessageView& operator=(MessageView&& other) = default; - ~MessageView() {} + ~MessageView() = default; const void* data() const { return static_cast<const char*>(message_->data()) + offset_; diff --git a/chromium/mojo/core/channel_unittest.cc b/chromium/mojo/core/channel_unittest.cc index a57f2a4924d..6013ce22219 100644 --- a/chromium/mojo/core/channel_unittest.cc +++ b/chromium/mojo/core/channel_unittest.cc @@ -56,13 +56,13 @@ class TestChannel : public Channel { void Write(MessagePtr message) override {} protected: - ~TestChannel() override {} + ~TestChannel() override = default; }; // Not using GMock as I don't think it supports movable types. class MockChannelDelegate : public Channel::Delegate { public: - MockChannelDelegate() {} + MockChannelDelegate() = default; size_t GetReceivedPayloadSize() const { return payload_size_; } diff --git a/chromium/mojo/core/channel_win.cc b/chromium/mojo/core/channel_win.cc index 4ea0aeb6810..3fee0f2b78c 100644 --- a/chromium/mojo/core/channel_win.cc +++ b/chromium/mojo/core/channel_win.cc @@ -15,6 +15,7 @@ #include "base/containers/queue.h" #include "base/debug/activity_tracker.h" #include "base/location.h" +#include "base/logging.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/message_loop/message_loop_current.h" @@ -186,7 +187,7 @@ class ChannelWin : public Channel, private: // May run on any thread. - ~ChannelWin() override {} + ~ChannelWin() override = default; void StartOnIOThread() { base::MessageLoopCurrent::Get()->AddDestructionObserver(this); diff --git a/chromium/mojo/core/core.cc b/chromium/mojo/core/core.cc index d6092658b75..6d06ab1fdee 100644 --- a/chromium/mojo/core/core.cc +++ b/chromium/mojo/core/core.cc @@ -153,10 +153,6 @@ scoped_refptr<Dispatcher> Core::GetAndRemoveDispatcher(MojoHandle handle) { return dispatcher; } -void Core::SetDefaultProcessErrorCallback(ProcessErrorCallback callback) { - default_process_error_callback_ = std::move(callback); -} - MojoHandle Core::CreatePartialMessagePipe(ports::PortRef* peer) { RequestContext request_context; ports::PortRef local_port; @@ -1477,6 +1473,29 @@ MojoResult Core::QueryQuota(MojoHandle handle, return dispatcher->QueryQuota(type, limit, usage); } +MojoResult Core::SetDefaultProcessErrorHandler( + MojoDefaultProcessErrorHandler handler, + const MojoSetDefaultProcessErrorHandlerOptions* options) { + if (default_process_error_callback_ && handler) + return MOJO_RESULT_ALREADY_EXISTS; + + if (!handler) { + default_process_error_callback_.Reset(); + return MOJO_RESULT_OK; + } + + default_process_error_callback_ = base::BindRepeating( + [](MojoDefaultProcessErrorHandler handler, const std::string& error) { + MojoProcessErrorDetails details = {0}; + details.struct_size = sizeof(details); + details.error_message_length = static_cast<uint32_t>(error.size()); + details.error_message = error.c_str(); + handler(&details); + }, + handler); + return MOJO_RESULT_OK; +} + void Core::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { base::AutoLock lock(handles_->GetLock()); handles_->GetActiveHandlesForTest(handles); diff --git a/chromium/mojo/core/core.h b/chromium/mojo/core/core.h index eaed40c8650..37c8a229fcf 100644 --- a/chromium/mojo/core/core.h +++ b/chromium/mojo/core/core.h @@ -54,8 +54,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Core { scoped_refptr<Dispatcher> GetDispatcher(MojoHandle handle); scoped_refptr<Dispatcher> GetAndRemoveDispatcher(MojoHandle handle); - void SetDefaultProcessErrorCallback(ProcessErrorCallback callback); - // Creates a message pipe endpoint with an unbound peer port returned in // |*peer|. Useful for setting up cross-process bootstrap message pipes. The // returned message pipe handle is usable immediately by the caller. @@ -325,6 +323,10 @@ class MOJO_SYSTEM_IMPL_EXPORT Core { uint64_t* limit, uint64_t* usage); + MojoResult SetDefaultProcessErrorHandler( + MojoDefaultProcessErrorHandler handler, + const MojoSetDefaultProcessErrorHandlerOptions* options); + void GetActiveHandlesForTest(std::vector<MojoHandle>* handles); private: diff --git a/chromium/mojo/core/core_test_base.cc b/chromium/mojo/core/core_test_base.cc index 88645237567..e173d853d1a 100644 --- a/chromium/mojo/core/core_test_base.cc +++ b/chromium/mojo/core/core_test_base.cc @@ -105,9 +105,9 @@ class MockDispatcher : public Dispatcher { // CoreTestBase ---------------------------------------------------------------- -CoreTestBase::CoreTestBase() {} +CoreTestBase::CoreTestBase() = default; -CoreTestBase::~CoreTestBase() {} +CoreTestBase::~CoreTestBase() = default; MojoHandle CoreTestBase::CreateMockHandle(CoreTestBase::MockHandleInfo* info) { scoped_refptr<MockDispatcher> dispatcher = MockDispatcher::Create(info); @@ -133,7 +133,7 @@ CoreTestBase_MockHandleInfo::CoreTestBase_MockHandleInfo() begin_read_data_call_count_(0), end_read_data_call_count_(0) {} -CoreTestBase_MockHandleInfo::~CoreTestBase_MockHandleInfo() {} +CoreTestBase_MockHandleInfo::~CoreTestBase_MockHandleInfo() = default; unsigned CoreTestBase_MockHandleInfo::GetCtorCallCount() const { base::AutoLock locker(lock_); diff --git a/chromium/mojo/core/data_pipe_consumer_dispatcher.cc b/chromium/mojo/core/data_pipe_consumer_dispatcher.cc index 979a222c104..4cf36093574 100644 --- a/chromium/mojo/core/data_pipe_consumer_dispatcher.cc +++ b/chromium/mojo/core/data_pipe_consumer_dispatcher.cc @@ -59,7 +59,7 @@ class DataPipeConsumerDispatcher::PortObserverThunk : dispatcher_(dispatcher) {} private: - ~PortObserverThunk() override {} + ~PortObserverThunk() override = default; // NodeController::PortObserver: void OnPortStatusChanged() override { dispatcher_->OnPortStatusChanged(); } diff --git a/chromium/mojo/core/data_pipe_control_message.cc b/chromium/mojo/core/data_pipe_control_message.cc index cd782e5bc12..d59676ff0ef 100644 --- a/chromium/mojo/core/data_pipe_control_message.cc +++ b/chromium/mojo/core/data_pipe_control_message.cc @@ -4,6 +4,7 @@ #include "mojo/core/data_pipe_control_message.h" +#include "base/logging.h" #include "mojo/core/node_controller.h" #include "mojo/core/ports/event.h" #include "mojo/core/user_message_impl.h" diff --git a/chromium/mojo/core/data_pipe_producer_dispatcher.cc b/chromium/mojo/core/data_pipe_producer_dispatcher.cc index 4c0473d0b2f..cebe8dda57d 100644 --- a/chromium/mojo/core/data_pipe_producer_dispatcher.cc +++ b/chromium/mojo/core/data_pipe_producer_dispatcher.cc @@ -58,7 +58,7 @@ class DataPipeProducerDispatcher::PortObserverThunk : dispatcher_(dispatcher) {} private: - ~PortObserverThunk() override {} + ~PortObserverThunk() override = default; // NodeController::PortObserver: void OnPortStatusChanged() override { dispatcher_->OnPortStatusChanged(); } diff --git a/chromium/mojo/core/dispatcher.cc b/chromium/mojo/core/dispatcher.cc index a110dbdc8e4..25959441808 100644 --- a/chromium/mojo/core/dispatcher.cc +++ b/chromium/mojo/core/dispatcher.cc @@ -16,12 +16,12 @@ namespace mojo { namespace core { -Dispatcher::DispatcherInTransit::DispatcherInTransit() {} +Dispatcher::DispatcherInTransit::DispatcherInTransit() = default; Dispatcher::DispatcherInTransit::DispatcherInTransit( const DispatcherInTransit& other) = default; -Dispatcher::DispatcherInTransit::~DispatcherInTransit() {} +Dispatcher::DispatcherInTransit::~DispatcherInTransit() = default; MojoResult Dispatcher::WatchDispatcher(scoped_refptr<Dispatcher> dispatcher, MojoHandleSignals signals, @@ -190,9 +190,9 @@ scoped_refptr<Dispatcher> Dispatcher::Deserialize( } } -Dispatcher::Dispatcher() {} +Dispatcher::Dispatcher() = default; -Dispatcher::~Dispatcher() {} +Dispatcher::~Dispatcher() = default; } // namespace core } // namespace mojo diff --git a/chromium/mojo/core/embedder/embedder.cc b/chromium/mojo/core/embedder/embedder.cc index 8b9d331ad5b..3a4e3172938 100644 --- a/chromium/mojo/core/embedder/embedder.cc +++ b/chromium/mojo/core/embedder/embedder.cc @@ -7,10 +7,8 @@ #include <stdint.h> #include <utility> -#include "base/bind.h" #include "base/memory/ref_counted.h" #include "base/task_runner.h" -#include "build/build_config.h" #include "mojo/core/configuration.h" #include "mojo/core/core.h" #include "mojo/core/entrypoints.h" @@ -30,11 +28,7 @@ void Init() { Init(Configuration()); } -void SetDefaultProcessErrorCallback(ProcessErrorCallback callback) { - Core::Get()->SetDefaultProcessErrorCallback(std::move(callback)); -} - -scoped_refptr<base::TaskRunner> GetIOTaskRunner() { +scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() { return Core::Get()->GetNodeController()->io_task_runner(); } diff --git a/chromium/mojo/core/embedder/embedder.h b/chromium/mojo/core/embedder/embedder.h index 5d654009877..575b301468d 100644 --- a/chromium/mojo/core/embedder/embedder.h +++ b/chromium/mojo/core/embedder/embedder.h @@ -9,20 +9,16 @@ #include <string> -#include "base/callback.h" #include "base/component_export.h" #include "base/memory/ref_counted.h" #include "base/process/process_handle.h" -#include "base/task_runner.h" +#include "base/single_thread_task_runner.h" #include "build/build_config.h" #include "mojo/core/embedder/configuration.h" namespace mojo { namespace core { -using ProcessErrorCallback = - base::RepeatingCallback<void(const std::string& error)>; - // Basic configuration/initialization ------------------------------------------ // Must be called first, or just after setting configuration parameters, to @@ -35,16 +31,12 @@ void Init(const Configuration& configuration); // Like above but uses a default Configuration. COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) void Init(); -// Sets a default callback to invoke when an internal error is reported but -// cannot be associated with a specific child process. Calling this is optional. -COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) -void SetDefaultProcessErrorCallback(ProcessErrorCallback callback); - // Initialialization/shutdown for interprocess communication (IPC) ------------- -// Retrieves the TaskRunner used for IPC I/O, as set by ScopedIPCSupport. +// Retrieves the SequencedTaskRunner used for IPC I/O, as set by +// ScopedIPCSupport. COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) -scoped_refptr<base::TaskRunner> GetIOTaskRunner(); +scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner(); } // namespace core } // namespace mojo diff --git a/chromium/mojo/core/embedder/scoped_ipc_support.h b/chromium/mojo/core/embedder/scoped_ipc_support.h index aba6e712ad8..ff603294702 100644 --- a/chromium/mojo/core/embedder/scoped_ipc_support.h +++ b/chromium/mojo/core/embedder/scoped_ipc_support.h @@ -86,7 +86,7 @@ class COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) ScopedIPCSupport { // // There are other practical scenarios where fast shutdown is safe even if // the process may have live proxies. For example, content's browser process - // is treated as a sort of master process in the system, in the sense that if + // is treated as a sort of root process in the system, in the sense that if // the browser is terminated, no other part of the system is expected to // continue normal operation anyway. In this case the side-effects of fast // shutdown are irrelevant, so fast shutdown is preferred. diff --git a/chromium/mojo/core/entrypoints.cc b/chromium/mojo/core/entrypoints.cc index 466da7e08a5..7b342a516f5 100644 --- a/chromium/mojo/core/entrypoints.cc +++ b/chromium/mojo/core/entrypoints.cc @@ -350,6 +350,12 @@ MojoResult MojoShutdownImpl(const MojoShutdownOptions* options) { return MOJO_RESULT_UNIMPLEMENTED; } +MojoResult MojoSetDefaultProcessErrorHandlerImpl( + MojoDefaultProcessErrorHandler handler, + const MojoSetDefaultProcessErrorHandlerOptions* options) { + return g_core->SetDefaultProcessErrorHandler(handler, options); +} + } // extern "C" MojoSystemThunks g_thunks = {sizeof(MojoSystemThunks), @@ -396,7 +402,8 @@ MojoSystemThunks g_thunks = {sizeof(MojoSystemThunks), MojoAcceptInvitationImpl, MojoSetQuotaImpl, MojoQueryQuotaImpl, - MojoShutdownImpl}; + MojoShutdownImpl, + MojoSetDefaultProcessErrorHandlerImpl}; } // namespace diff --git a/chromium/mojo/core/handle_table.cc b/chromium/mojo/core/handle_table.cc index 62419a92363..9426281d73f 100644 --- a/chromium/mojo/core/handle_table.cc +++ b/chromium/mojo/core/handle_table.cc @@ -40,9 +40,9 @@ const char* GetNameForDispatcherType(Dispatcher::Type type) { } // namespace -HandleTable::HandleTable() {} +HandleTable::HandleTable() = default; -HandleTable::~HandleTable() {} +HandleTable::~HandleTable() = default; base::Lock& HandleTable::GetLock() { return lock_; @@ -191,14 +191,14 @@ bool HandleTable::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, return true; } -HandleTable::Entry::Entry() {} +HandleTable::Entry::Entry() = default; HandleTable::Entry::Entry(scoped_refptr<Dispatcher> dispatcher) : dispatcher(std::move(dispatcher)) {} HandleTable::Entry::Entry(const Entry& other) = default; -HandleTable::Entry::~Entry() {} +HandleTable::Entry::~Entry() = default; } // namespace core } // namespace mojo diff --git a/chromium/mojo/core/handle_table_unittest.cc b/chromium/mojo/core/handle_table_unittest.cc index 910b14e76cf..0724fb09474 100644 --- a/chromium/mojo/core/handle_table_unittest.cc +++ b/chromium/mojo/core/handle_table_unittest.cc @@ -27,14 +27,14 @@ namespace { class FakeMessagePipeDispatcher : public Dispatcher { public: - FakeMessagePipeDispatcher() {} + FakeMessagePipeDispatcher() = default; Type GetType() const override { return Type::MESSAGE_PIPE; } MojoResult Close() override { return MOJO_RESULT_OK; } private: - ~FakeMessagePipeDispatcher() override {} + ~FakeMessagePipeDispatcher() override = default; DISALLOW_COPY_AND_ASSIGN(FakeMessagePipeDispatcher); }; diff --git a/chromium/mojo/core/message_pipe_dispatcher.cc b/chromium/mojo/core/message_pipe_dispatcher.cc index 22ac04acc5f..e17fdabc2d3 100644 --- a/chromium/mojo/core/message_pipe_dispatcher.cc +++ b/chromium/mojo/core/message_pipe_dispatcher.cc @@ -47,7 +47,7 @@ class MessagePipeDispatcher::PortObserverThunk : dispatcher_(dispatcher) {} private: - ~PortObserverThunk() override {} + ~PortObserverThunk() override = default; // NodeController::PortObserver: void OnPortStatusChanged() override { dispatcher_->OnPortStatusChanged(); } @@ -63,8 +63,8 @@ class MessagePipeDispatcher::PortObserverThunk // the next available message on a port, for debug logging only. class PeekSizeMessageFilter : public ports::MessageFilter { public: - PeekSizeMessageFilter() {} - ~PeekSizeMessageFilter() override {} + PeekSizeMessageFilter() = default; + ~PeekSizeMessageFilter() override = default; // ports::MessageFilter: bool Match(const ports::UserMessageEvent& message_event) override { @@ -380,9 +380,8 @@ MojoResult MessagePipeDispatcher::CloseNoLock() { base::AutoUnlock unlock(signal_lock_); node_controller_->ClosePort(port_); - TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), - "MessagePipe closing", pipe_id_ + endpoint_, - TRACE_EVENT_FLAG_FLOW_OUT); + TRACE_EVENT_WITH_FLOW0("toplevel.flow", "MessagePipe closing", + pipe_id_ + endpoint_, TRACE_EVENT_FLAG_FLOW_OUT); } return MOJO_RESULT_OK; @@ -433,9 +432,9 @@ HandleSignalsState MessagePipeDispatcher::GetHandleSignalsStateNoLock() const { rv.satisfied_signals & MOJO_HANDLE_SIGNAL_PEER_CLOSED; last_known_satisfied_signals_ = rv.satisfied_signals; if (is_peer_closed && !was_peer_closed) { - TRACE_EVENT_WITH_FLOW0( - TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), "MessagePipe peer closed", - pipe_id_ + (1 - endpoint_), TRACE_EVENT_FLAG_FLOW_IN); + TRACE_EVENT_WITH_FLOW0("toplevel.flow", "MessagePipe peer closed", + pipe_id_ + (1 - endpoint_), + TRACE_EVENT_FLAG_FLOW_IN); } return rv; diff --git a/chromium/mojo/core/message_unittest.cc b/chromium/mojo/core/message_unittest.cc index c079e1106c6..cb0747c09ea 100644 --- a/chromium/mojo/core/message_unittest.cc +++ b/chromium/mojo/core/message_unittest.cc @@ -30,7 +30,7 @@ using MessageTest = test::MojoTestBase; // handles. class TestMessageBase { public: - virtual ~TestMessageBase() {} + virtual ~TestMessageBase() = default; static MojoMessageHandle MakeMessageHandle( std::unique_ptr<TestMessageBase> message) { diff --git a/chromium/mojo/core/mojo_core.cc b/chromium/mojo/core/mojo_core.cc index 7d28bcfdddd..2261a8a9adb 100644 --- a/chromium/mojo/core/mojo_core.cc +++ b/chromium/mojo/core/mojo_core.cc @@ -5,17 +5,25 @@ #include <stddef.h> #include "base/at_exit.h" +#include "base/base_switches.h" #include "base/bind.h" +#include "base/command_line.h" +#include "base/debug/stack_trace.h" +#include "base/feature_list.h" +#include "base/logging.h" #include "base/macros.h" #include "base/message_loop/message_pump_type.h" #include "base/no_destructor.h" +#include "base/rand_util.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" #include "base/time/time.h" +#include "build/build_config.h" #include "mojo/core/configuration.h" #include "mojo/core/core.h" #include "mojo/core/entrypoints.h" #include "mojo/public/c/system/core.h" +#include "mojo/public/c/system/macros.h" #include "mojo/public/c/system/thunks.h" namespace { @@ -56,6 +64,62 @@ std::unique_ptr<IPCSupport>& GetIPCSupport() { return *state; } +// This helper is only called from within the context of a newly loaded Mojo +// Core shared library, where various bits of static state (e.g. //base globals) +// will not yet be initialized. Base library initialization steps are thus +// consolidated here so that base APIs work as expected from within the loaded +// Mojo Core implementation. +// +// NOTE: This is a no-op in component builds, as we expect both the client +// application and the Mojo Core library to have been linked against the same +// base component library, and we furthermore expect that the client application +// has already initialized base globals by this point. +class GlobalStateInitializer { + public: + GlobalStateInitializer() = default; + + bool Initialize(int argc, const char* const* argv) { + if (initialized_) + return false; + initialized_ = true; +#if !defined(COMPONENT_BUILD) + base::CommandLine::Init(argc, argv); + + logging::LoggingSettings settings; + settings.logging_dest = + logging::LOG_TO_SYSTEM_DEBUG_LOG | logging::LOG_TO_STDERR; + logging::InitLogging(settings); + logging::SetLogItems(true, // Process ID + true, // Thread ID + true, // Timestamp + true); // Tick count + +#if !defined(OFFICIAL_BUILD) && !defined(OS_WIN) + // Correct stack dumping behavior requires symbol names in all loaded + // libraries to be cached. We do this here in case the calling process will + // imminently enter a sandbox. + base::debug::EnableInProcessStackDumping(); +#endif + +#if defined(OS_POSIX) + // Tickle base's PRNG. This lazily opens a static handle to /dev/urandom. + // Mojo Core uses the API internally, so it's important to warm the handle + // before potentially entering a sandbox. + base::RandUint64(); +#endif + + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + base::FeatureList::InitializeInstance( + command_line->GetSwitchValueASCII(switches::kEnableFeatures), + command_line->GetSwitchValueASCII(switches::kDisableFeatures)); +#endif // !defined(COMPONENT_BUILD) + return true; + } + + private: + bool initialized_ = false; +}; + } // namespace extern "C" { @@ -63,13 +127,47 @@ extern "C" { namespace { MojoResult InitializeImpl(const struct MojoInitializeOptions* options) { + std::unique_ptr<IPCSupport>& ipc_support = GetIPCSupport(); + if (ipc_support) { + // Already fully initialized, so there's nothing to do. + return MOJO_RESULT_FAILED_PRECONDITION; + } + + // NOTE: |MojoInitialize()| may be called more than once if the caller wishes + // to separate basic initialization from IPC support initialization. We only + // do basic initialization the first time this is called. + const bool should_initialize_ipc_support = + !options || ((options->flags & MOJO_INITIALIZE_FLAG_LOAD_ONLY) == 0); + + int argc = 0; + const char* const* argv = nullptr; + if (options && MOJO_IS_STRUCT_FIELD_PRESENT(options, argv)) { + argc = options->argc; + argv = options->argv; + } + + static base::NoDestructor<GlobalStateInitializer> global_state_initializer; + const bool was_global_state_already_initialized = + !global_state_initializer->Initialize(argc, argv); + + if (!should_initialize_ipc_support) { + if (was_global_state_already_initialized) + return MOJO_RESULT_ALREADY_EXISTS; + else + return MOJO_RESULT_OK; + } + + DCHECK(!mojo::core::Core::Get()); mojo::core::Configuration config; config.is_broker_process = options && options->flags & MOJO_INITIALIZE_FLAG_AS_BROKER; + config.force_direct_shared_memory_allocation = + options && options->flags & + MOJO_INITIALIZE_FLAG_FORCE_DIRECT_SHARED_MEMORY_ALLOCATION; mojo::core::internal::g_configuration = config; - mojo::core::InitializeCore(); - GetIPCSupport() = std::make_unique<IPCSupport>(); + ipc_support = std::make_unique<IPCSupport>(); + return MOJO_RESULT_OK; } diff --git a/chromium/mojo/core/mojo_core_unittest.cc b/chromium/mojo/core/mojo_core_unittest.cc index a6f07022b75..e97172c71f9 100644 --- a/chromium/mojo/core/mojo_core_unittest.cc +++ b/chromium/mojo/core/mojo_core_unittest.cc @@ -4,12 +4,14 @@ #include <stdint.h> +#include <tuple> #include <vector> #include "base/command_line.h" #include "base/process/launch.h" #include "base/test/multiprocess_test.h" #include "base/test/test_timeouts.h" +#include "mojo/core/mojo_core_unittest.h" #include "mojo/public/c/system/core.h" #include "mojo/public/cpp/platform/platform_channel.h" #include "mojo/public/cpp/platform/platform_handle.h" @@ -19,6 +21,11 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/multiprocess_func_list.h" +namespace switches { +const char kMojoLoadBeforeInit[] = "mojo-load-before-init"; +const char kMojoUseExplicitLibraryPath[] = "mojo-use-explicit-library-path"; +} // namespace switches + namespace { // TODO(https://crbug.com/902135): Re-enable this on MSAN. Currently hangs @@ -66,10 +73,27 @@ TEST(MojoCoreTest, SanityCheck) { EXPECT_EQ(MOJO_RESULT_OK, MojoClose(a)); } -TEST(MojoCoreTest, BasicMultiprocess) { +enum class InitializationMode { kCombinedLoadAndInit, kLoadBeforeInit }; + +enum class LoadPathSpec { kImplicit, kExplicit }; + +class MojoCoreMultiprocessTest + : public ::testing::TestWithParam< + std::tuple<InitializationMode, LoadPathSpec>> { + public: + void SetChildCommandLineForTestParams(base::CommandLine* command_line) { + if (std::get<0>(GetParam()) == InitializationMode::kLoadBeforeInit) + command_line->AppendSwitch(switches::kMojoLoadBeforeInit); + if (std::get<1>(GetParam()) == LoadPathSpec::kExplicit) + command_line->AppendSwitch(switches::kMojoUseExplicitLibraryPath); + } +}; + +TEST_P(MojoCoreMultiprocessTest, BasicMultiprocess) { base::CommandLine child_cmd(base::GetMultiProcessTestChildBaseCommandLine()); - base::LaunchOptions options; + SetChildCommandLineForTestParams(&child_cmd); + base::LaunchOptions options; mojo::PlatformChannel channel; channel.PrepareToPassRemoteEndpoint(&options, &child_cmd); base::Process child_process = base::SpawnMultiProcessTestChild( @@ -108,6 +132,15 @@ MULTIPROCESS_TEST_MAIN(BasicMultiprocessClientMain) { return 0; } + +INSTANTIATE_TEST_SUITE_P( + , + MojoCoreMultiprocessTest, + ::testing::Combine( + ::testing::Values(InitializationMode::kCombinedLoadAndInit, + InitializationMode::kLoadBeforeInit), + ::testing::Values(LoadPathSpec::kImplicit, LoadPathSpec::kExplicit))); + #endif // !defined(MEMORY_SANITIZER) } // namespace diff --git a/chromium/mojo/core/mojo_core_unittest.h b/chromium/mojo/core/mojo_core_unittest.h new file mode 100644 index 00000000000..ee25f11da9c --- /dev/null +++ b/chromium/mojo/core/mojo_core_unittest.h @@ -0,0 +1,21 @@ +// Copyright 2020 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_CORE_MOJO_CORE_UNITTEST_H_ +#define MOJO_CORE_MOJO_CORE_UNITTEST_H_ + +namespace switches { + +// Instructs the test runner to initialize the Mojo Core library in separate +// phases. Used by a unit test when launching a subprocess, to verify the +// correctness of phased initialization. +extern const char kMojoLoadBeforeInit[]; + +// Instructs the test runner to provide an explicit path to the Mojo Core shared +// library, rather than assuming it's present in the current working directory. +extern const char kMojoUseExplicitLibraryPath[]; + +} // namespace switches + +#endif // MOJO_CORE_MOJO_CORE_UNITTEST_H_ diff --git a/chromium/mojo/core/node_channel.cc b/chromium/mojo/core/node_channel.cc index e898b044286..061ea1026e9 100644 --- a/chromium/mojo/core/node_channel.cc +++ b/chromium/mojo/core/node_channel.cc @@ -228,7 +228,7 @@ void NodeChannel::NotifyBadMessage(const std::string& error) { } void NodeChannel::SetRemoteProcessHandle(ScopedProcessHandle process_handle) { - DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence()); { base::AutoLock lock(channel_lock_); if (channel_) @@ -253,7 +253,7 @@ ScopedProcessHandle NodeChannel::CloneRemoteProcessHandle() { } void NodeChannel::SetRemoteNodeName(const ports::NodeName& name) { - DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence()); remote_node_name_ = name; } @@ -468,15 +468,15 @@ NodeChannel::NodeChannel( Channel::HandlePolicy channel_handle_policy, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, const ProcessErrorCallback& process_error_callback) - : delegate_(delegate), - io_task_runner_(io_task_runner), + : base::RefCountedDeleteOnSequence<NodeChannel>(io_task_runner), + delegate_(delegate), process_error_callback_(process_error_callback) #if !defined(OS_NACL_SFI) , channel_(Channel::Create(this, std::move(connection_params), channel_handle_policy, - io_task_runner_)) + std::move(io_task_runner))) #endif { } @@ -499,15 +499,10 @@ void NodeChannel::CreateAndBindLocalBrokerHost( void NodeChannel::OnChannelMessage(const void* payload, size_t payload_size, std::vector<PlatformHandle> handles) { - DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence()); RequestContext request_context(RequestContext::Source::SYSTEM); - // Ensure this NodeChannel stays alive through the extent of this method. The - // delegate may have the only other reference to this object and it may choose - // to drop it here in response to, e.g., a malformed message. - scoped_refptr<NodeChannel> keepalive = this; - if (payload_size <= sizeof(Header)) { delegate_->OnChannelError(remote_node_name_, this); return; @@ -739,7 +734,7 @@ void NodeChannel::OnChannelMessage(const void* payload, } void NodeChannel::OnChannelError(Channel::Error error) { - DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); + DCHECK(owning_task_runner()->RunsTasksInCurrentSequence()); RequestContext request_context(RequestContext::Source::SYSTEM); diff --git a/chromium/mojo/core/node_channel.h b/chromium/mojo/core/node_channel.h index ea91f927049..58ab42bd01f 100644 --- a/chromium/mojo/core/node_channel.h +++ b/chromium/mojo/core/node_channel.h @@ -11,7 +11,7 @@ #include "base/callback.h" #include "base/containers/queue.h" #include "base/macros.h" -#include "base/memory/ref_counted.h" +#include "base/memory/ref_counted_delete_on_sequence.h" #include "base/process/process_handle.h" #include "base/single_thread_task_runner.h" #include "base/synchronization/lock.h" @@ -21,17 +21,19 @@ #include "mojo/core/embedder/process_error_callback.h" #include "mojo/core/ports/name.h" #include "mojo/core/scoped_process_handle.h" +#include "mojo/core/system_impl_export.h" namespace mojo { namespace core { // Wraps a Channel to send and receive Node control messages. -class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>, - public Channel::Delegate { +class MOJO_SYSTEM_IMPL_EXPORT NodeChannel + : public base::RefCountedDeleteOnSequence<NodeChannel>, + public Channel::Delegate { public: class Delegate { public: - virtual ~Delegate() {} + virtual ~Delegate() = default; virtual void OnAcceptInvitee(const ports::NodeName& from_node, const ports::NodeName& inviter_name, const ports::NodeName& token) = 0; @@ -92,8 +94,6 @@ class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>, void** data, size_t* num_data_bytes); - Channel* channel() const { return channel_.get(); } - // Start receiving messages. void Start(); @@ -155,7 +155,8 @@ class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>, #endif private: - friend class base::RefCountedThreadSafe<NodeChannel>; + friend class base::RefCountedDeleteOnSequence<NodeChannel>; + friend class base::DeleteHelper<NodeChannel>; using PendingMessageQueue = base::queue<Channel::MessagePtr>; using PendingRelayMessageQueue = @@ -181,13 +182,12 @@ class NodeChannel : public base::RefCountedThreadSafe<NodeChannel>, void WriteChannelMessage(Channel::MessagePtr message); Delegate* const delegate_; - const scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; const ProcessErrorCallback process_error_callback_; base::Lock channel_lock_; - scoped_refptr<Channel> channel_; + scoped_refptr<Channel> channel_ GUARDED_BY(channel_lock_); - // Must only be accessed from |io_task_runner_|'s thread. + // Must only be accessed from the owning task runner's thread. ports::NodeName remote_node_name_; base::Lock remote_process_handle_lock_; diff --git a/chromium/mojo/core/node_channel_fuzzer.cc b/chromium/mojo/core/node_channel_fuzzer.cc index 99047c000db..54fe757e0de 100644 --- a/chromium/mojo/core/node_channel_fuzzer.cc +++ b/chromium/mojo/core/node_channel_fuzzer.cc @@ -14,6 +14,7 @@ #include "mojo/core/connection_params.h" #include "mojo/core/entrypoints.h" #include "mojo/core/node_channel.h" // nogncheck +#include "mojo/core/test/mock_node_channel_delegate.h" #include "mojo/public/cpp/platform/platform_channel.h" #if defined(OS_WIN) @@ -24,60 +25,6 @@ using mojo::core::Channel; using mojo::core::ConnectionParams; using mojo::core::ports::NodeName; -// Implementation of NodeChannel::Delegate which does nothing. All of the -// interesting NodeChannel control message message parsing is done by -// NodeChannel by the time any of the delegate methods are invoked, so there's -// no need for this to do any work. -class FakeNodeChannelDelegate : public mojo::core::NodeChannel::Delegate { - public: - FakeNodeChannelDelegate() = default; - ~FakeNodeChannelDelegate() override = default; - - void OnAcceptInvitee(const NodeName& from_node, - const NodeName& inviter_name, - const NodeName& token) override {} - void OnAcceptInvitation(const NodeName& from_node, - const NodeName& token, - const NodeName& invitee_name) override {} - void OnAddBrokerClient(const NodeName& from_node, - const NodeName& client_name, - base::ProcessHandle process_handle) override {} - void OnBrokerClientAdded(const NodeName& from_node, - const NodeName& client_name, - mojo::PlatformHandle broker_channel) override {} - void OnAcceptBrokerClient(const NodeName& from_node, - const NodeName& broker_name, - mojo::PlatformHandle broker_channel) override {} - void OnEventMessage(const NodeName& from_node, - Channel::MessagePtr message) override {} - void OnRequestPortMerge( - const NodeName& from_node, - const mojo::core::ports::PortName& connector_port_name, - const std::string& token) override {} - void OnRequestIntroduction(const NodeName& from_node, - const NodeName& name) override {} - void OnIntroduce(const NodeName& from_node, - const NodeName& name, - mojo::PlatformHandle channel_handle) override {} - void OnBroadcast(const NodeName& from_node, - Channel::MessagePtr message) override {} -#if defined(OS_WIN) - void OnRelayEventMessage(const NodeName& from_node, - base::ProcessHandle from_process, - const NodeName& destination, - Channel::MessagePtr message) override {} - void OnEventMessageFromRelay(const NodeName& from_node, - const NodeName& source_node, - Channel::MessagePtr message) override {} -#endif - void OnAcceptPeer(const NodeName& from_node, - const NodeName& token, - const NodeName& peer_name, - const mojo::core::ports::PortName& port_name) override {} - void OnChannelError(const NodeName& node, - mojo::core::NodeChannel* channel) override {} -}; - // A fake delegate for the sending Channel endpoint. The sending Channel is not // being fuzzed and won't receive any interesting messages, so this doesn't need // to do anything. @@ -109,7 +56,7 @@ extern "C" int LLVMFuzzerTestOneInput(const unsigned char* data, size_t size) { // used to carry messages between processes. mojo::PlatformChannel channel; - FakeNodeChannelDelegate receiver_delegate; + mojo::core::MockNodeChannelDelegate receiver_delegate; auto receiver = mojo::core::NodeChannel::Create( &receiver_delegate, ConnectionParams(channel.TakeLocalEndpoint()), Channel::HandlePolicy::kRejectHandles, diff --git a/chromium/mojo/core/node_channel_unittest.cc b/chromium/mojo/core/node_channel_unittest.cc new file mode 100644 index 00000000000..13c46f13fea --- /dev/null +++ b/chromium/mojo/core/node_channel_unittest.cc @@ -0,0 +1,72 @@ +// Copyright 2020 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/core/node_channel.h" + +#include "base/bind_helpers.h" +#include "base/memory/scoped_refptr.h" +#include "base/message_loop/message_pump_type.h" +#include "base/test/task_environment.h" +#include "base/threading/thread.h" +#include "mojo/core/embedder/embedder.h" +#include "mojo/core/test/mock_node_channel_delegate.h" +#include "mojo/public/cpp/platform/platform_channel.h" +#include "mojo/public/cpp/platform/platform_channel_endpoint.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace mojo { +namespace core { +namespace { + +using NodeChannelTest = testing::Test; +using ports::NodeName; + +scoped_refptr<NodeChannel> CreateNodeChannel(NodeChannel::Delegate* delegate, + PlatformChannelEndpoint endpoint) { + return NodeChannel::Create(delegate, ConnectionParams(std::move(endpoint)), + Channel::HandlePolicy::kAcceptHandles, + GetIOTaskRunner(), base::NullCallback()); +} + +TEST_F(NodeChannelTest, DestructionIsSafe) { + // Regression test for https://crbug.com/1081874. + base::test::TaskEnvironment task_environment; + + PlatformChannel channel; + MockNodeChannelDelegate local_delegate; + auto local_channel = + CreateNodeChannel(&local_delegate, channel.TakeLocalEndpoint()); + local_channel->Start(); + MockNodeChannelDelegate remote_delegate; + auto remote_channel = + CreateNodeChannel(&remote_delegate, channel.TakeRemoteEndpoint()); + remote_channel->Start(); + + // Verify end-to-end operation + const NodeName kRemoteNodeName{123, 456}; + const NodeName kToken{987, 654}; + base::RunLoop loop; + EXPECT_CALL(local_delegate, + OnAcceptInvitee(ports::kInvalidNodeName, kRemoteNodeName, kToken)) + .WillRepeatedly([&] { loop.Quit(); }); + remote_channel->AcceptInvitee(kRemoteNodeName, kToken); + loop.Run(); + + // Now send another message to the local endpoint but tear it down + // immediately. This will race with the message being received on the IO + // thread, and although the corresponding delegate call may or may not + // dispatch as a result, the race should still be memory-safe. + remote_channel->AcceptInvitee(kRemoteNodeName, kToken); + + base::RunLoop error_loop; + EXPECT_CALL(remote_delegate, OnChannelError).WillOnce([&] { + error_loop.Quit(); + }); + local_channel.reset(); + error_loop.Run(); +} + +} // namespace +} // namespace core +} // namespace mojo diff --git a/chromium/mojo/core/node_controller.cc b/chromium/mojo/core/node_controller.cc index 345d22ae06b..ff93f0c3a6b 100644 --- a/chromium/mojo/core/node_controller.cc +++ b/chromium/mojo/core/node_controller.cc @@ -144,7 +144,7 @@ class ThreadDestructionObserver } // namespace -NodeController::~NodeController() {} +NodeController::~NodeController() = default; NodeController::NodeController(Core* core) : core_(core), diff --git a/chromium/mojo/core/node_controller.h b/chromium/mojo/core/node_controller.h index e9645084037..9494de5b809 100644 --- a/chromium/mojo/core/node_controller.h +++ b/chromium/mojo/core/node_controller.h @@ -48,7 +48,7 @@ class MOJO_SYSTEM_IMPL_EXPORT NodeController : public ports::NodeDelegate, virtual void OnPortStatusChanged() = 0; protected: - ~PortObserver() override {} + ~PortObserver() override = default; }; // |core| owns and out-lives us. diff --git a/chromium/mojo/core/options_validation.h b/chromium/mojo/core/options_validation.h index ae4120800ae..89c12d0c887 100644 --- a/chromium/mojo/core/options_validation.h +++ b/chromium/mojo/core/options_validation.h @@ -16,7 +16,7 @@ #include <algorithm> -#include "base/logging.h" +#include "base/check.h" #include "base/macros.h" #include "mojo/core/system_impl_export.h" #include "mojo/public/c/system/types.h" diff --git a/chromium/mojo/core/platform_shared_memory_mapping.h b/chromium/mojo/core/platform_shared_memory_mapping.h index b7c43ace9e0..305f5e4ef15 100644 --- a/chromium/mojo/core/platform_shared_memory_mapping.h +++ b/chromium/mojo/core/platform_shared_memory_mapping.h @@ -9,7 +9,6 @@ #include <memory> -#include "base/logging.h" #include "base/macros.h" #include "base/memory/platform_shared_memory_region.h" #include "base/memory/shared_memory_mapping.h" diff --git a/chromium/mojo/core/ports/message_filter.h b/chromium/mojo/core/ports/message_filter.h index f09903ffca4..21f8c1c8697 100644 --- a/chromium/mojo/core/ports/message_filter.h +++ b/chromium/mojo/core/ports/message_filter.h @@ -15,7 +15,7 @@ class UserMessageEvent; // arbitrary policy. class MessageFilter { public: - virtual ~MessageFilter() {} + virtual ~MessageFilter() = default; // Returns true if |message| should be accepted by whomever is applying this // filter. See MessageQueue::GetNextMessage(), for example. diff --git a/chromium/mojo/core/ports/node.cc b/chromium/mojo/core/ports/node.cc index 476594db0cb..5b2558a0465 100644 --- a/chromium/mojo/core/ports/node.cc +++ b/chromium/mojo/core/ports/node.cc @@ -15,6 +15,7 @@ #include "base/lazy_instance.h" #include "base/logging.h" #include "base/memory/ref_counted.h" +#include "base/notreached.h" #include "base/optional.h" #include "base/synchronization/lock.h" #include "base/threading/thread_local.h" @@ -1726,7 +1727,7 @@ Node::DelegateHolder::DelegateHolder(Node* node, NodeDelegate* delegate) DCHECK(node_); } -Node::DelegateHolder::~DelegateHolder() {} +Node::DelegateHolder::~DelegateHolder() = default; #if DCHECK_IS_ON() void Node::DelegateHolder::EnsureSafeDelegateAccess() const { diff --git a/chromium/mojo/core/ports/node_delegate.h b/chromium/mojo/core/ports/node_delegate.h index afe1c4cd975..3172779c06b 100644 --- a/chromium/mojo/core/ports/node_delegate.h +++ b/chromium/mojo/core/ports/node_delegate.h @@ -17,7 +17,7 @@ namespace ports { class NodeDelegate { public: - virtual ~NodeDelegate() {} + virtual ~NodeDelegate() = default; // Forward an event (possibly asynchronously) to the specified node. virtual void ForwardEvent(const NodeName& node, ScopedEvent event) = 0; diff --git a/chromium/mojo/core/ports/port.cc b/chromium/mojo/core/ports/port.cc index 0d2aa74650e..c46dc9ed25b 100644 --- a/chromium/mojo/core/ports/port.cc +++ b/chromium/mojo/core/ports/port.cc @@ -21,7 +21,7 @@ Port::Port(uint64_t next_sequence_num_to_send, peer_closed(false), peer_lost_unexpectedly(false) {} -Port::~Port() {} +Port::~Port() = default; } // namespace ports } // namespace core diff --git a/chromium/mojo/core/ports/port_ref.cc b/chromium/mojo/core/ports/port_ref.cc index a3d312bc399..7cbc53674c7 100644 --- a/chromium/mojo/core/ports/port_ref.cc +++ b/chromium/mojo/core/ports/port_ref.cc @@ -10,9 +10,9 @@ namespace mojo { namespace core { namespace ports { -PortRef::~PortRef() {} +PortRef::~PortRef() = default; -PortRef::PortRef() {} +PortRef::PortRef() = default; PortRef::PortRef(const PortName& name, scoped_refptr<Port> port) : name_(name), port_(std::move(port)) {} diff --git a/chromium/mojo/core/ports/port_ref.h b/chromium/mojo/core/ports/port_ref.h index b63d6cfcd00..afa75e54c17 100644 --- a/chromium/mojo/core/ports/port_ref.h +++ b/chromium/mojo/core/ports/port_ref.h @@ -6,7 +6,6 @@ #define MOJO_CORE_PORTS_PORT_REF_H_ #include "base/component_export.h" -#include "base/logging.h" #include "base/memory/ref_counted.h" #include "mojo/core/ports/name.h" diff --git a/chromium/mojo/core/ports/ports_unittest.cc b/chromium/mojo/core/ports/ports_unittest.cc index 07ee1155fd3..3353aa42e2e 100644 --- a/chromium/mojo/core/ports/ports_unittest.cc +++ b/chromium/mojo/core/ports/ports_unittest.cc @@ -44,7 +44,7 @@ class TestMessage : public UserMessage { TestMessage(const base::StringPiece& payload) : UserMessage(&kUserMessageTypeInfo), payload_(payload) {} - ~TestMessage() override {} + ~TestMessage() override = default; const std::string& payload() const { return payload_; } @@ -69,7 +69,7 @@ class TestNode; class MessageRouter { public: - virtual ~MessageRouter() {} + virtual ~MessageRouter() = default; virtual void ForwardEvent(TestNode* from_node, const NodeName& node_name, diff --git a/chromium/mojo/core/ports/user_data.h b/chromium/mojo/core/ports/user_data.h index e18d9b79d5f..2d2b25fc01b 100644 --- a/chromium/mojo/core/ports/user_data.h +++ b/chromium/mojo/core/ports/user_data.h @@ -15,7 +15,7 @@ class UserData : public base::RefCountedThreadSafe<UserData> { protected: friend class base::RefCountedThreadSafe<UserData>; - virtual ~UserData() {} + virtual ~UserData() = default; }; } // namespace ports diff --git a/chromium/mojo/core/request_context.cc b/chromium/mojo/core/request_context.cc index 582ff6fdf53..4ede95c4146 100644 --- a/chromium/mojo/core/request_context.cc +++ b/chromium/mojo/core/request_context.cc @@ -110,7 +110,7 @@ RequestContext::WatchNotifyFinalizer::WatchNotifyFinalizer( RequestContext::WatchNotifyFinalizer::WatchNotifyFinalizer( const WatchNotifyFinalizer& other) = default; -RequestContext::WatchNotifyFinalizer::~WatchNotifyFinalizer() {} +RequestContext::WatchNotifyFinalizer::~WatchNotifyFinalizer() = default; } // namespace core } // namespace mojo diff --git a/chromium/mojo/core/run_all_core_unittests.cc b/chromium/mojo/core/run_all_core_unittests.cc index 18b119ef4af..b8b1f199add 100644 --- a/chromium/mojo/core/run_all_core_unittests.cc +++ b/chromium/mojo/core/run_all_core_unittests.cc @@ -4,25 +4,54 @@ #include "base/base_switches.h" #include "base/bind.h" +#include "base/files/file_path.h" +#include "base/files/file_util.h" +#include "base/logging.h" +#include "base/optional.h" #include "base/test/launcher/unit_test_launcher.h" #include "base/test/test_suite.h" #include "build/build_config.h" +#include "mojo/core/mojo_core_unittest.h" #include "mojo/public/c/system/core.h" +#include "mojo/public/cpp/system/dynamic_library_support.h" + +base::FilePath GetMojoCoreLibraryPath() { +#if defined(OS_WIN) + const char kLibraryFilename[] = "mojo_core.dll"; +#else + const char kLibraryFilename[] = "libmojo_core.so"; +#endif + base::FilePath executable_dir = + base::CommandLine::ForCurrentProcess()->GetProgram().DirName(); + if (executable_dir.IsAbsolute()) + return executable_dir.AppendASCII(kLibraryFilename); + + base::FilePath current_directory; + CHECK(base::GetCurrentDirectory(¤t_directory)); + return current_directory.Append(executable_dir).AppendASCII(kLibraryFilename); +} int main(int argc, char** argv) { base::TestSuite test_suite(argc, argv); - MojoInitializeOptions options; - options.struct_size = sizeof(options); - options.flags = MOJO_INITIALIZE_FLAG_NONE; - options.mojo_core_path = NULL; - options.mojo_core_path_length = 0; - if (!base::CommandLine::ForCurrentProcess()->HasSwitch( - switches::kTestChildProcess)) { - options.flags = MOJO_INITIALIZE_FLAG_AS_BROKER; + MojoInitializeFlags flags = MOJO_INITIALIZE_FLAG_NONE; + const base::CommandLine& command_line = + *base::CommandLine::ForCurrentProcess(); + if (!command_line.HasSwitch(switches::kTestChildProcess)) + flags |= MOJO_INITIALIZE_FLAG_AS_BROKER; + + base::Optional<base::FilePath> library_path; + if (command_line.HasSwitch(switches::kMojoUseExplicitLibraryPath)) + library_path = GetMojoCoreLibraryPath(); + + if (command_line.HasSwitch(switches::kMojoLoadBeforeInit)) { + CHECK_EQ(MOJO_RESULT_OK, mojo::LoadCoreLibrary(library_path)); + CHECK_EQ(MOJO_RESULT_OK, mojo::InitializeCoreLibrary(flags)); + } else { + CHECK_EQ(MOJO_RESULT_OK, + mojo::LoadAndInitializeCoreLibrary(library_path, flags)); } - CHECK_EQ(MOJO_RESULT_OK, MojoInitialize(&options)); int result = base::LaunchUnitTests( argc, argv, base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite))); diff --git a/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc b/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc index b245b78330d..fe206b63146 100644 --- a/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc +++ b/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc @@ -45,8 +45,8 @@ void RevalidateCreateOptions( class SharedBufferDispatcherTest : public testing::Test { public: - SharedBufferDispatcherTest() {} - ~SharedBufferDispatcherTest() override {} + SharedBufferDispatcherTest() = default; + ~SharedBufferDispatcherTest() override = default; private: DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcherTest); diff --git a/chromium/mojo/core/test/BUILD.gn b/chromium/mojo/core/test/BUILD.gn index 1abadfc503d..9429c618530 100644 --- a/chromium/mojo/core/test/BUILD.gn +++ b/chromium/mojo/core/test/BUILD.gn @@ -7,6 +7,8 @@ import("//third_party/protobuf/proto_library.gni") static_library("test_support") { testonly = true sources = [ + "mock_node_channel_delegate.cc", + "mock_node_channel_delegate.h", "mojo_test_base.cc", "mojo_test_base.h", "test_utils.h", @@ -27,8 +29,10 @@ static_library("test_support") { public_deps = [ "//base", "//base/test:test_support", + "//mojo/core:embedder_internal", "//mojo/core/embedder", "//mojo/public/cpp/system", + "//testing/gmock", "//testing/gtest", ] } diff --git a/chromium/mojo/core/test_utils.cc b/chromium/mojo/core/test_utils.cc index eb025b4a3c4..acbfca018af 100644 --- a/chromium/mojo/core/test_utils.cc +++ b/chromium/mojo/core/test_utils.cc @@ -54,9 +54,9 @@ void Sleep(MojoDeadline deadline) { base::TimeDelta::FromMicroseconds(static_cast<int64_t>(deadline))); } -Stopwatch::Stopwatch() {} +Stopwatch::Stopwatch() = default; -Stopwatch::~Stopwatch() {} +Stopwatch::~Stopwatch() = default; void Stopwatch::Start() { start_time_ = base::TimeTicks::Now(); diff --git a/chromium/mojo/core/trap_unittest.cc b/chromium/mojo/core/trap_unittest.cc index f543b2f0ec3..8ff1f74a6ad 100644 --- a/chromium/mojo/core/trap_unittest.cc +++ b/chromium/mojo/core/trap_unittest.cc @@ -34,8 +34,8 @@ class TriggerHelper { public: using ContextCallback = base::RepeatingCallback<void(const MojoTrapEvent&)>; - TriggerHelper() {} - ~TriggerHelper() {} + TriggerHelper() = default; + ~TriggerHelper() = default; MojoResult CreateTrap(MojoHandle* handle) { return MojoCreateTrap(&Notify, nullptr, handle); @@ -65,7 +65,7 @@ class TriggerHelper { explicit NotificationContext(const ContextCallback& callback) : callback_(callback) {} - ~NotificationContext() {} + ~NotificationContext() = default; void SetCancelCallback(base::OnceClosure cancel_callback) { cancel_callback_ = std::move(cancel_callback); @@ -97,7 +97,7 @@ class ThreadedRunner : public base::SimpleThread { public: explicit ThreadedRunner(base::OnceClosure callback) : SimpleThread("ThreadedRunner"), callback_(std::move(callback)) {} - ~ThreadedRunner() override {} + ~ThreadedRunner() override = default; void Run() override { std::move(callback_).Run(); } diff --git a/chromium/mojo/core/watch.cc b/chromium/mojo/core/watch.cc index 996f0a7ca24..0d0429da097 100644 --- a/chromium/mojo/core/watch.cc +++ b/chromium/mojo/core/watch.cc @@ -78,7 +78,7 @@ void Watch::InvokeCallback(MojoResult result, watcher_->InvokeWatchCallback(context_, result, state, flags); } -Watch::~Watch() {} +Watch::~Watch() = default; #if DCHECK_IS_ON() void Watch::AssertWatcherLockAcquired() const { |