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/public/cpp | |
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/public/cpp')
57 files changed, 298 insertions, 138 deletions
diff --git a/chromium/mojo/public/cpp/base/big_buffer.cc b/chromium/mojo/public/cpp/base/big_buffer.cc index ecd5c0dfe55..59e3039ec29 100644 --- a/chromium/mojo/public/cpp/base/big_buffer.cc +++ b/chromium/mojo/public/cpp/base/big_buffer.cc @@ -67,6 +67,10 @@ void TryCreateSharedMemory( // instead produce an invalid buffer. This will always fail validation on // the receiving end. *storage_type = BigBuffer::StorageType::kInvalidBuffer; + + // TODO(crbug.com/1076341): Remove this temporary CHECK to investigate + // some bad IPC reports likely caused by this path. + CHECK(false); return; } } diff --git a/chromium/mojo/public/cpp/bindings/README.md b/chromium/mojo/public/cpp/bindings/README.md index 2c64ec743d8..db9b37d2a64 100644 --- a/chromium/mojo/public/cpp/bindings/README.md +++ b/chromium/mojo/public/cpp/bindings/README.md @@ -1139,23 +1139,23 @@ foo->SetBar(std::move(bar)); ### Performance considerations -When using associated interfaces on different sequences than the master sequence -(where the master interface lives): +When using associated interfaces on different sequences than the primary +sequence (where the primary interface lives): * Sending messages: send happens directly on the calling sequence. So there isn't sequence hopping. * Receiving messages: associated interfaces bound on a different sequence from - the master interface incur an extra sequence hop during dispatch. + the primary interface incur an extra sequence hop during dispatch. Therefore, performance-wise associated interfaces are better suited for -scenarios where message receiving happens on the master sequence. +scenarios where message receiving happens on the primary sequence. ### Testing -Associated interfaces need to be associated with a master interface before +Associated interfaces need to be associated with a primary interface before they can be used. This means one end of the associated interface must be sent -over one end of the master interface, or over one end of another associated -interface which itself already has a master interface. +over one end of the primary interface, or over one end of another associated +interface which itself already has a primary interface. If you want to test an associated interface endpoint without first associating it, you can use `AssociatedRemote::BindNewEndpointAndPassDedicatedReceiverForTesting`. diff --git a/chromium/mojo/public/cpp/bindings/associated_binding.h b/chromium/mojo/public/cpp/bindings/associated_binding.h index 2c7f8a3f9f7..a0b6eeadc21 100644 --- a/chromium/mojo/public/cpp/bindings/associated_binding.h +++ b/chromium/mojo/public/cpp/bindings/associated_binding.h @@ -11,8 +11,8 @@ #include "base/bind.h" #include "base/callback.h" +#include "base/check.h" #include "base/component_export.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" diff --git a/chromium/mojo/public/cpp/bindings/associated_group_controller.h b/chromium/mojo/public/cpp/bindings/associated_group_controller.h index 386ebdf8609..6de041783f5 100644 --- a/chromium/mojo/public/cpp/bindings/associated_group_controller.h +++ b/chromium/mojo/public/cpp/bindings/associated_group_controller.h @@ -38,7 +38,7 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) AssociatedGroupController // Creates an interface endpoint handle from a given interface ID. The handle // joins this associated group. // Typically, this method is used to (1) create an endpoint handle for the - // master interface; or (2) create an endpoint handle on receiving an + // primary interface; or (2) create an endpoint handle on receiving an // interface ID from the message pipe. // // On failure, the method returns an invalid handle. Usually that is because diff --git a/chromium/mojo/public/cpp/bindings/associated_interface_ptr.h b/chromium/mojo/public/cpp/bindings/associated_interface_ptr.h index f027f9ea2b1..956138c4277 100644 --- a/chromium/mojo/public/cpp/bindings/associated_interface_ptr.h +++ b/chromium/mojo/public/cpp/bindings/associated_interface_ptr.h @@ -12,8 +12,8 @@ #include <utility> #include "base/callback.h" +#include "base/check.h" #include "base/component_export.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/sequenced_task_runner.h" diff --git a/chromium/mojo/public/cpp/bindings/associated_receiver.h b/chromium/mojo/public/cpp/bindings/associated_receiver.h index 2087f4e4cde..f2857dcaa44 100644 --- a/chromium/mojo/public/cpp/bindings/associated_receiver.h +++ b/chromium/mojo/public/cpp/bindings/associated_receiver.h @@ -8,8 +8,8 @@ #include <memory> #include <utility> +#include "base/check.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/sequenced_task_runner.h" diff --git a/chromium/mojo/public/cpp/bindings/associated_remote.h b/chromium/mojo/public/cpp/bindings/associated_remote.h index 9aa834c11fd..32b010c61c9 100644 --- a/chromium/mojo/public/cpp/bindings/associated_remote.h +++ b/chromium/mojo/public/cpp/bindings/associated_remote.h @@ -9,8 +9,8 @@ #include <utility> #include "base/callback_forward.h" +#include "base/check.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/sequenced_task_runner.h" diff --git a/chromium/mojo/public/cpp/bindings/binding.h b/chromium/mojo/public/cpp/bindings/binding.h index bd650c79a40..4993de731f6 100644 --- a/chromium/mojo/public/cpp/bindings/binding.h +++ b/chromium/mojo/public/cpp/bindings/binding.h @@ -138,11 +138,10 @@ class Binding { // true if a method was successfully read and dispatched. // // This method may only be called if the object has been bound to a message - // pipe. This returns once a message is received either on the master + // pipe. This returns once a message is received either on the primary // interface or any associated interfaces. - bool WaitForIncomingMethodCall( - MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { - return internal_state_.WaitForIncomingMethodCall(deadline); + bool WaitForIncomingMethodCall() { + return internal_state_.WaitForIncomingMethodCall(); } // Closes the message pipe that was previously bound. Put this object into a diff --git a/chromium/mojo/public/cpp/bindings/connector.h b/chromium/mojo/public/cpp/bindings/connector.h index 91dd4655b6a..16e478c9ebd 100644 --- a/chromium/mojo/public/cpp/bindings/connector.h +++ b/chromium/mojo/public/cpp/bindings/connector.h @@ -161,10 +161,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) Connector : public MessageReceiver { // be added to the same group. void SetConnectionGroup(ConnectionGroup::Ref ref); - // Waits for the next message on the pipe, blocking until one arrives, - // |deadline| elapses, or an error happens. Returns |true| if a message has - // been delivered, |false| otherwise. - bool WaitForIncomingMessage(MojoDeadline deadline); + // Waits for the next message on the pipe, blocking until one arrives or an + // error happens. Returns |true| if a message has been delivered, |false| + // otherwise. + bool WaitForIncomingMessage(); // See Binding for details of pause/resume. void PauseIncomingMethodCallProcessing(); diff --git a/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h b/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h index d2e1d0574f5..c8065924b2e 100644 --- a/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h +++ b/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h @@ -12,10 +12,10 @@ #include <utility> #include "base/callback.h" +#include "base/check_op.h" #include "base/compiler_specific.h" #include "base/component_export.h" #include "base/location.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" diff --git a/chromium/mojo/public/cpp/bindings/interface_id.h b/chromium/mojo/public/cpp/bindings/interface_id.h index d6128537d20..8760fea068f 100644 --- a/chromium/mojo/public/cpp/bindings/interface_id.h +++ b/chromium/mojo/public/cpp/bindings/interface_id.h @@ -14,16 +14,16 @@ using InterfaceId = uint32_t; // IDs of associated interface can be generated at both sides of the message // pipe. In order to avoid collision, the highest bit is used as namespace bit: -// at the side where the client-side of the master interface lives, IDs are +// at the side where the client-side of the primary interface lives, IDs are // generated with the namespace bit set to 1; at the opposite side IDs are // generated with the namespace bit set to 0. const uint32_t kInterfaceIdNamespaceMask = 0x80000000; -const InterfaceId kMasterInterfaceId = 0x00000000; +const InterfaceId kPrimaryInterfaceId = 0x00000000; const InterfaceId kInvalidInterfaceId = 0xFFFFFFFF; -inline bool IsMasterInterfaceId(InterfaceId id) { - return id == kMasterInterfaceId; +inline bool IsPrimaryInterfaceId(InterfaceId id) { + return id == kPrimaryInterfaceId; } inline bool IsValidInterfaceId(InterfaceId id) { diff --git a/chromium/mojo/public/cpp/bindings/interface_ptr.h b/chromium/mojo/public/cpp/bindings/interface_ptr.h index 4f10be5acc5..6745a32b530 100644 --- a/chromium/mojo/public/cpp/bindings/interface_ptr.h +++ b/chromium/mojo/public/cpp/bindings/interface_ptr.h @@ -12,7 +12,7 @@ #include <utility> #include "base/callback_forward.h" -#include "base/logging.h" +#include "base/check.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/sequenced_task_runner.h" diff --git a/chromium/mojo/public/cpp/bindings/interface_request.h b/chromium/mojo/public/cpp/bindings/interface_request.h index 0b9fd64b193..3e44bfba2a7 100644 --- a/chromium/mojo/public/cpp/bindings/interface_request.h +++ b/chromium/mojo/public/cpp/bindings/interface_request.h @@ -80,7 +80,7 @@ class InterfaceRequest { Message message = PipeControlMessageProxy::ConstructPeerEndpointClosedMessage( - kMasterInterfaceId, DisconnectReason(custom_reason, description)); + kPrimaryInterfaceId, DisconnectReason(custom_reason, description)); MojoResult result = WriteMessageNew(state_.pipe.get(), message.TakeMojoMessage(), MOJO_WRITE_MESSAGE_FLAG_NONE); diff --git a/chromium/mojo/public/cpp/bindings/lib/array_internal.h b/chromium/mojo/public/cpp/bindings/lib/array_internal.h index e34349f2a72..cb8c5b30907 100644 --- a/chromium/mojo/public/cpp/bindings/lib/array_internal.h +++ b/chromium/mojo/public/cpp/bindings/lib/array_internal.h @@ -11,8 +11,8 @@ #include <limits> #include <new> +#include "base/check.h" #include "base/component_export.h" -#include "base/logging.h" #include "base/macros.h" #include "mojo/public/c/system/macros.h" #include "mojo/public/cpp/bindings/lib/bindings_internal.h" diff --git a/chromium/mojo/public/cpp/bindings/lib/binding_state.cc b/chromium/mojo/public/cpp/bindings/lib/binding_state.cc index f0eab656f1e..ecfe41c4652 100644 --- a/chromium/mojo/public/cpp/bindings/lib/binding_state.cc +++ b/chromium/mojo/public/cpp/bindings/lib/binding_state.cc @@ -36,9 +36,9 @@ void BindingStateBase::ResumeIncomingMethodCallProcessing() { router_->ResumeIncomingMethodCallProcessing(); } -bool BindingStateBase::WaitForIncomingMethodCall(MojoDeadline deadline) { +bool BindingStateBase::WaitForIncomingMethodCall() { DCHECK(router_); - return router_->WaitForIncomingMessage(deadline); + return router_->WaitForIncomingMessage(); } void BindingStateBase::PauseRemoteCallbacksUntilFlushCompletes( @@ -121,11 +121,11 @@ void BindingStateBase::BindInternal( : MultiplexRouter::SINGLE_INTERFACE); router_ = new MultiplexRouter(std::move(receiver_state->pipe), config, false, sequenced_runner); - router_->SetMasterInterfaceName(interface_name); + router_->SetPrimaryInterfaceName(interface_name); router_->SetConnectionGroup(std::move(receiver_state->connection_group)); endpoint_client_.reset(new InterfaceEndpointClient( - router_->CreateLocalEndpointHandle(kMasterInterfaceId), stub, + router_->CreateLocalEndpointHandle(kPrimaryInterfaceId), stub, std::move(request_validator), has_sync_methods, std::move(sequenced_runner), interface_version, interface_name)); endpoint_client_->SetIdleTrackingEnabledCallback( diff --git a/chromium/mojo/public/cpp/bindings/lib/binding_state.h b/chromium/mojo/public/cpp/bindings/lib/binding_state.h index cadb81a7fa6..598668482ff 100644 --- a/chromium/mojo/public/cpp/bindings/lib/binding_state.h +++ b/chromium/mojo/public/cpp/bindings/lib/binding_state.h @@ -11,8 +11,8 @@ #include "base/bind.h" #include "base/callback.h" +#include "base/check.h" #include "base/component_export.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" @@ -48,8 +48,7 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) BindingStateBase { void PauseIncomingMethodCallProcessing(); void ResumeIncomingMethodCallProcessing(); - bool WaitForIncomingMethodCall( - MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE); + bool WaitForIncomingMethodCall(); void PauseRemoteCallbacksUntilFlushCompletes(PendingFlush flush); void FlushAsync(AsyncFlusher flusher); diff --git a/chromium/mojo/public/cpp/bindings/lib/connector.cc b/chromium/mojo/public/cpp/bindings/lib/connector.cc index 5c92e2d65ba..c342d655d29 100644 --- a/chromium/mojo/public/cpp/bindings/lib/connector.cc +++ b/chromium/mojo/public/cpp/bindings/lib/connector.cc @@ -229,7 +229,7 @@ void Connector::SetConnectionGroup(ConnectionGroup::Ref ref) { connection_group_ = std::move(ref); } -bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { +bool Connector::WaitForIncomingMessage() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); if (error_) @@ -237,23 +237,13 @@ bool Connector::WaitForIncomingMessage(MojoDeadline deadline) { ResumeIncomingMethodCallProcessing(); - // TODO(rockot): Use a timed Wait here. Nobody uses anything but 0 or - // INDEFINITE deadlines at present, so we only support those. - DCHECK(deadline == 0 || deadline == MOJO_DEADLINE_INDEFINITE); - - MojoResult rv = MOJO_RESULT_UNKNOWN; - if (deadline == 0 && !message_pipe_->QuerySignalsState().readable()) + MojoResult rv = Wait(message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE); + if (rv != MOJO_RESULT_OK) { + // Users that call WaitForIncomingMessage() should expect their code to be + // re-entered, so we call the error handler synchronously. + HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION /* force_pipe_reset */, + false /* force_async_handler */); return false; - - if (deadline == MOJO_DEADLINE_INDEFINITE) { - rv = Wait(message_pipe_.get(), MOJO_HANDLE_SIGNAL_READABLE); - if (rv != MOJO_RESULT_OK) { - // Users that call WaitForIncomingMessage() should expect their code to be - // re-entered, so we call the error handler synchronously. - HandleError(rv != MOJO_RESULT_FAILED_PRECONDITION /* force_pipe_reset */, - false /* force_async_handler */); - return false; - } } Message message; @@ -505,9 +495,9 @@ bool Connector::DispatchMessage(Message message) { incoming_serialization_mode_); } - TRACE_EVENT_WITH_FLOW0( - TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), "mojo::Message Receive", - MANGLE_MESSAGE_ID(message.header()->trace_id), TRACE_EVENT_FLAG_FLOW_IN); + TRACE_EVENT_WITH_FLOW0("toplevel.flow", "mojo::Message Receive", + MANGLE_MESSAGE_ID(message.header()->trace_id), + TRACE_EVENT_FLAG_FLOW_IN); #if !BUILDFLAG(MOJO_TRACE_ENABLED) // This emits just full class name, and is inferior to mojo tracing. TRACE_EVENT0("mojom", heap_profiler_tag_); diff --git a/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.cc b/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.cc index 348c63d7c16..bd363911483 100644 --- a/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.cc +++ b/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.cc @@ -92,7 +92,7 @@ bool InterfacePtrStateBase::InitializeEndpointClient( DCHECK(runner_->RunsTasksInCurrentSequence()); router_ = new MultiplexRouter(std::move(handle_), config, true, runner_); endpoint_client_.reset(new InterfaceEndpointClient( - router_->CreateLocalEndpointHandle(kMasterInterfaceId), nullptr, + router_->CreateLocalEndpointHandle(kPrimaryInterfaceId), nullptr, std::move(payload_validator), false, std::move(runner_), // The version is only queried from the client so the value passed here // will not be used. diff --git a/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.h b/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.h index 0d259f37a2f..d1e37115f90 100644 --- a/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.h +++ b/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.h @@ -14,9 +14,9 @@ #include "base/bind.h" #include "base/callback_forward.h" +#include "base/check_op.h" #include "base/component_export.h" #include "base/location.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/memory/ref_counted.h" @@ -260,7 +260,7 @@ class InterfacePtrState : public InterfacePtrStateBase { Interface::PassesAssociatedKinds_, Interface::HasSyncMethods_, std::make_unique<typename Interface::ResponseValidator_>(), Interface::Name_)) { - router()->SetMasterInterfaceName(Interface::Name_); + router()->SetPrimaryInterfaceName(Interface::Name_); proxy_ = std::make_unique<Proxy>(endpoint_client()); } } diff --git a/chromium/mojo/public/cpp/bindings/lib/message.cc b/chromium/mojo/public/cpp/bindings/lib/message.cc index 7b8e92ecbf7..893ec949fbc 100644 --- a/chromium/mojo/public/cpp/bindings/lib/message.cc +++ b/chromium/mojo/public/cpp/bindings/lib/message.cc @@ -102,8 +102,8 @@ void CreateSerializedMessageObject(uint32_t name, std::vector<ScopedHandle>* handles, ScopedMessageHandle* out_handle, internal::Buffer* out_buffer) { - TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), - "mojo::Message Send", MANGLE_MESSAGE_ID(trace_id), + TRACE_EVENT_WITH_FLOW0("toplevel.flow", "mojo::Message Send", + MANGLE_MESSAGE_ID(trace_id), TRACE_EVENT_FLAG_FLOW_OUT); ScopedMessageHandle handle; @@ -148,8 +148,8 @@ void SerializeUnserializedContext(MojoMessageHandle message, reinterpret_cast<internal::UnserializedMessageContext*>(context_value); uint32_t trace_id = GetTraceId(context); - TRACE_EVENT_WITH_FLOW0(TRACE_DISABLED_BY_DEFAULT("toplevel.flow"), - "mojo::Message Send", MANGLE_MESSAGE_ID(trace_id), + TRACE_EVENT_WITH_FLOW0("toplevel.flow", "mojo::Message Send", + MANGLE_MESSAGE_ID(trace_id), TRACE_EVENT_FLAG_FLOW_OUT); void* buffer; diff --git a/chromium/mojo/public/cpp/bindings/lib/message_header_validator.cc b/chromium/mojo/public/cpp/bindings/lib/message_header_validator.cc index 25a651e4b45..e4f8a4905cd 100644 --- a/chromium/mojo/public/cpp/bindings/lib/message_header_validator.cc +++ b/chromium/mojo/public/cpp/bindings/lib/message_header_validator.cc @@ -90,7 +90,7 @@ bool IsValidMessageHeader(const internal::MessageHeader* header, size_t num_ids = header_v2->payload_interface_ids.Get()->size(); const uint32_t* ids = header_v2->payload_interface_ids.Get()->storage(); for (size_t i = 0; i < num_ids; ++i) { - if (!IsValidInterfaceId(ids[i]) || IsMasterInterfaceId(ids[i])) { + if (!IsValidInterfaceId(ids[i]) || IsPrimaryInterfaceId(ids[i])) { internal::ReportValidationError( validation_context, internal::VALIDATION_ERROR_ILLEGAL_INTERFACE_ID); diff --git a/chromium/mojo/public/cpp/bindings/lib/message_quota_checker.h b/chromium/mojo/public/cpp/bindings/lib/message_quota_checker.h index 071853640a6..37955350905 100644 --- a/chromium/mojo/public/cpp/bindings/lib/message_quota_checker.h +++ b/chromium/mojo/public/cpp/bindings/lib/message_quota_checker.h @@ -31,10 +31,10 @@ namespace internal { // outgoing queue. Additionally, |BeforeWrite()| should be called immediately // before writing each message to the corresponding message pipe. // -// Also note that messages posted to a different sequence with -// |base::PostTask()| and the like, need to be treated as locally queued. Task -// queues can grow arbitrarily long, and it's ideal to perform unread quota -// checks before posting. +// Also note that messages posted to a different sequence with base::ThreadPool +// and the like, need to be treated as locally queued. Task queues can grow +// arbitrarily long, and it's ideal to perform unread quota checks before +// posting. // // Either |BeforeMessagesEnqueued()| or |BeforeWrite()| may cause the quota // to be exceeded, thus invoking the |maybe_crash_function| set in this diff --git a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc index 4a825fd6a71..08da6c26ded 100644 --- a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc +++ b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc @@ -369,12 +369,12 @@ void MultiplexRouter::SetIncomingMessageFilter( dispatcher_.SetFilter(std::move(filter)); } -void MultiplexRouter::SetMasterInterfaceName(const char* name) { +void MultiplexRouter::SetPrimaryInterfaceName(const char* name) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); header_validator_->SetDescription(std::string(name) + - " [master] MessageHeaderValidator"); + " [primary] MessageHeaderValidator"); control_message_handler_.SetDescription( - std::string(name) + " [master] PipeControlMessageHandler"); + std::string(name) + " [primary] PipeControlMessageHandler"); connector_.SetWatcherHeapProfilerTag(name); } @@ -454,7 +454,7 @@ void MultiplexRouter::CloseEndpointHandle( DCHECK(!endpoint->closed()); UpdateEndpointStateMayRemove(endpoint, ENDPOINT_CLOSED); - if (!IsMasterInterfaceId(id) || reason) { + if (!IsPrimaryInterfaceId(id) || reason) { MayAutoUnlock unlocker(&lock_); control_message_proxy_.NotifyPeerEndpointClosed(id, reason); } @@ -575,7 +575,7 @@ bool MultiplexRouter::HasAssociatedEndpoints() const { if (endpoints_.size() == 0) return false; - return !base::Contains(endpoints_, kMasterInterfaceId); + return !base::Contains(endpoints_, kPrimaryInterfaceId); } void MultiplexRouter::EnableBatchDispatch() { @@ -674,7 +674,7 @@ bool MultiplexRouter::OnPeerAssociatedEndpointClosed( bool MultiplexRouter::WaitForFlushToComplete(ScopedMessagePipeHandle pipe) { // If this MultiplexRouter has an associated interface on some task runner - // other than the master interface's task runner, it is possible to process + // other than the primary interface's task runner, it is possible to process // incoming control messages on that task runner. We don't support this // control message on anything but the main interface though. if (!task_runner_->RunsTasksInCurrentSequence()) @@ -1048,7 +1048,7 @@ bool MultiplexRouter::InsertEndpointsForMessage(const Message& message) { MayAutoLock locker(&lock_); for (uint32_t i = 0; i < num_ids; ++i) { // Message header validation already ensures that the IDs are valid and not - // the master ID. + // the primary ID. // The IDs are from the remote side and therefore their namespace bit is // supposed to be different than the value that this router would use. if (set_interface_id_namespace_bit_ == diff --git a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h index 3063ec49703..16128e880b0 100644 --- a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h +++ b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h @@ -11,11 +11,11 @@ #include <memory> #include <string> +#include "base/check_op.h" #include "base/compiler_specific.h" #include "base/component_export.h" #include "base/containers/queue.h" #include "base/containers/small_map.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" @@ -47,7 +47,7 @@ namespace internal { // MultiplexRouter supports routing messages for multiple interfaces over a // single message pipe. // -// It is created on the sequence where the master interface of the message pipe +// It is created on the sequence where the primary interface of the message pipe // lives. // Some public methods are only allowed to be called on the creating sequence; // while the others are safe to call from any sequence. Please see the method @@ -61,14 +61,14 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MultiplexRouter public PipeControlMessageHandlerDelegate { public: enum Config { - // There is only the master interface running on this router. Please note + // There is only the primary interface running on this router. Please note // that because of interface versioning, the other side of the message pipe - // may use a newer master interface definition which passes associated + // may use a newer primary interface definition which passes associated // interfaces. In that case, this router may still receive pipe control // messages or messages targetting associated interfaces. SINGLE_INTERFACE, - // Similar to the mode above, there is only the master interface running on - // this router. Besides, the master interface has sync methods. + // Similar to the mode above, there is only the primary interface running on + // this router. Besides, the primary interface has sync methods. SINGLE_INTERFACE_WITH_SYNC_METHODS, // There may be associated interfaces running on this router. MULTI_INTERFACE @@ -85,10 +85,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MultiplexRouter // before dispatch. void SetIncomingMessageFilter(std::unique_ptr<MessageFilter> filter); - // Sets the master interface name for this router. Only used when reporting + // Sets the primary interface name for this router. Only used when reporting // message header or control message validation errors. // |name| must be a string literal. - void SetMasterInterfaceName(const char* name); + void SetPrimaryInterfaceName(const char* name); // Adds this object to a ConnectionGroup identified by |ref|. All receiving // pipe endpoints decoded from inbound messages on this MultiplexRouter will @@ -130,11 +130,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MultiplexRouter return connector_.PassMessagePipe(); } - // Blocks the current sequence until the first incoming message, or - // |deadline|. - bool WaitForIncomingMessage(MojoDeadline deadline) { + // Blocks the current sequence until the first incoming message. + bool WaitForIncomingMessage() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return connector_.WaitForIncomingMessage(deadline); + return connector_.WaitForIncomingMessage(); } // See Binding for details of pause/resume. diff --git a/chromium/mojo/public/cpp/bindings/lib/native_enum_serialization.h b/chromium/mojo/public/cpp/bindings/lib/native_enum_serialization.h index 4faf957c58e..6cd8c7f90fb 100644 --- a/chromium/mojo/public/cpp/bindings/lib/native_enum_serialization.h +++ b/chromium/mojo/public/cpp/bindings/lib/native_enum_serialization.h @@ -10,7 +10,7 @@ #include <type_traits> -#include "base/logging.h" +#include "base/check_op.h" #include "base/pickle.h" #include "ipc/ipc_param_traits.h" #include "mojo/public/cpp/bindings/lib/serialization_forward.h" diff --git a/chromium/mojo/public/cpp/bindings/lib/native_struct_serialization.h b/chromium/mojo/public/cpp/bindings/lib/native_struct_serialization.h index 5e2be21c981..41abb228c4f 100644 --- a/chromium/mojo/public/cpp/bindings/lib/native_struct_serialization.h +++ b/chromium/mojo/public/cpp/bindings/lib/native_struct_serialization.h @@ -10,8 +10,8 @@ #include <limits> +#include "base/check_op.h" #include "base/component_export.h" -#include "base/logging.h" #include "base/pickle.h" #include "ipc/ipc_message.h" #include "ipc/ipc_param_traits.h" diff --git a/chromium/mojo/public/cpp/bindings/lib/sequence_local_sync_event_watcher.cc b/chromium/mojo/public/cpp/bindings/lib/sequence_local_sync_event_watcher.cc index c443c65cf55..1d9178799df 100644 --- a/chromium/mojo/public/cpp/bindings/lib/sequence_local_sync_event_watcher.cc +++ b/chromium/mojo/public/cpp/bindings/lib/sequence_local_sync_event_watcher.cc @@ -99,6 +99,8 @@ class SequenceLocalSyncEventWatcher::SequenceLocalState { { base::AutoLock lock(ready_watchers_lock_); ready_watchers_.erase(iter->first); + if (ready_watchers_.empty()) + event_.Reset(); } registered_watchers_.erase(iter); @@ -206,8 +208,10 @@ void SequenceLocalSyncEventWatcher::SequenceLocalState::OnEventSignaled() { base::AutoLock lock(ready_watchers_lock_); std::swap(ready_watchers_, ready_watchers); } - if (ready_watchers.empty()) + if (ready_watchers.empty()) { + event_.Reset(); return; + } auto weak_self = weak_ptr_factory_.GetWeakPtr(); for (auto* watcher : ready_watchers) { diff --git a/chromium/mojo/public/cpp/bindings/map_data_view.h b/chromium/mojo/public/cpp/bindings/map_data_view.h index a65bb9eca14..5743829eeec 100644 --- a/chromium/mojo/public/cpp/bindings/map_data_view.h +++ b/chromium/mojo/public/cpp/bindings/map_data_view.h @@ -5,7 +5,7 @@ #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ #define MOJO_PUBLIC_CPP_BINDINGS_MAP_DATA_VIEW_H_ -#include "base/logging.h" +#include "base/check_op.h" #include "mojo/public/cpp/bindings/array_data_view.h" #include "mojo/public/cpp/bindings/lib/bindings_internal.h" #include "mojo/public/cpp/bindings/lib/map_data_internal.h" diff --git a/chromium/mojo/public/cpp/bindings/message.h b/chromium/mojo/public/cpp/bindings/message.h index 8dbb3df8875..8099cd4305b 100644 --- a/chromium/mojo/public/cpp/bindings/message.h +++ b/chromium/mojo/public/cpp/bindings/message.h @@ -14,10 +14,10 @@ #include <vector> #include "base/callback.h" +#include "base/check_op.h" #include "base/compiler_specific.h" #include "base/component_export.h" #include "base/containers/span.h" -#include "base/logging.h" #include "base/memory/ptr_util.h" #include "mojo/public/cpp/bindings/connection_group.h" #include "mojo/public/cpp/bindings/lib/buffer.h" diff --git a/chromium/mojo/public/cpp/bindings/pending_remote.h b/chromium/mojo/public/cpp/bindings/pending_remote.h index e67dd1a6691..64c9ab90653 100644 --- a/chromium/mojo/public/cpp/bindings/pending_remote.h +++ b/chromium/mojo/public/cpp/bindings/pending_remote.h @@ -9,8 +9,8 @@ #include <type_traits> #include <utility> +#include "base/check.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "base/macros.h" #include "build/build_config.h" #include "mojo/public/cpp/bindings/interface_ptr_info.h" diff --git a/chromium/mojo/public/cpp/bindings/receiver.h b/chromium/mojo/public/cpp/bindings/receiver.h index 045bd3e5dbc..6f8b9976581 100644 --- a/chromium/mojo/public/cpp/bindings/receiver.h +++ b/chromium/mojo/public/cpp/bindings/receiver.h @@ -8,8 +8,8 @@ #include <memory> #include <utility> +#include "base/check.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/sequenced_task_runner.h" @@ -204,7 +204,7 @@ class Receiver { // Blocks the calling thread until a new message arrives and is dispatched // to the bound implementation. bool WaitForIncomingCall() { - return internal_state_.WaitForIncomingMethodCall(MOJO_DEADLINE_INDEFINITE); + return internal_state_.WaitForIncomingMethodCall(); } // Pauses the Remote endpoint, stopping dispatch of callbacks on that end. Any diff --git a/chromium/mojo/public/cpp/bindings/remote.h b/chromium/mojo/public/cpp/bindings/remote.h index 45615bfb930..d71d2037141 100644 --- a/chromium/mojo/public/cpp/bindings/remote.h +++ b/chromium/mojo/public/cpp/bindings/remote.h @@ -9,8 +9,8 @@ #include <utility> #include "base/callback_forward.h" +#include "base/check.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/scoped_refptr.h" #include "base/sequenced_task_runner.h" diff --git a/chromium/mojo/public/cpp/bindings/strong_associated_binding.h b/chromium/mojo/public/cpp/bindings/strong_associated_binding.h index 0bb340c7d11..7425e87f2e4 100644 --- a/chromium/mojo/public/cpp/bindings/strong_associated_binding.h +++ b/chromium/mojo/public/cpp/bindings/strong_associated_binding.h @@ -11,7 +11,7 @@ #include "base/bind.h" #include "base/callback.h" -#include "base/logging.h" +#include "base/check.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "mojo/public/cpp/bindings/associated_binding.h" diff --git a/chromium/mojo/public/cpp/bindings/strong_associated_binding_set.h b/chromium/mojo/public/cpp/bindings/strong_associated_binding_set.h deleted file mode 100644 index 8c769698ba3..00000000000 --- a/chromium/mojo/public/cpp/bindings/strong_associated_binding_set.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2017 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef MOJO_PUBLIC_CPP_BINDINGS_STRONG_ASSOCIATED_BINDING_SET_H_ -#define MOJO_PUBLIC_CPP_BINDINGS_STRONG_ASSOCIATED_BINDING_SET_H_ - -#include "mojo/public/cpp/bindings/associated_binding.h" -#include "mojo/public/cpp/bindings/associated_binding_set.h" -#include "mojo/public/cpp/bindings/associated_interface_ptr.h" -#include "mojo/public/cpp/bindings/associated_interface_request.h" -#include "mojo/public/cpp/bindings/binding_set.h" -#include "mojo/public/cpp/bindings/unique_ptr_impl_ref_traits.h" - -namespace mojo { - -template <typename Interface, typename ContextType = void> -using StrongAssociatedBindingSet = BindingSetBase< - Interface, - AssociatedBinding<Interface, UniquePtrImplRefTraits<Interface>>, - ContextType>; - -} // namespace mojo - -#endif // MOJO_PUBLIC_CPP_BINDINGS_STRONG_ASSOCIATED_BINDING_SET_H_ diff --git a/chromium/mojo/public/cpp/bindings/strong_binding.h b/chromium/mojo/public/cpp/bindings/strong_binding.h index b1160453a96..e3940fba4b5 100644 --- a/chromium/mojo/public/cpp/bindings/strong_binding.h +++ b/chromium/mojo/public/cpp/bindings/strong_binding.h @@ -11,7 +11,7 @@ #include "base/bind.h" #include "base/callback.h" -#include "base/logging.h" +#include "base/check.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "mojo/public/cpp/bindings/binding.h" diff --git a/chromium/mojo/public/cpp/bindings/struct_ptr.h b/chromium/mojo/public/cpp/bindings/struct_ptr.h index 93431740434..ea2f52ea878 100644 --- a/chromium/mojo/public/cpp/bindings/struct_ptr.h +++ b/chromium/mojo/public/cpp/bindings/struct_ptr.h @@ -10,7 +10,7 @@ #include <memory> #include <new> -#include "base/logging.h" +#include "base/check.h" #include "base/macros.h" #include "base/optional.h" #include "mojo/public/cpp/bindings/lib/hash_util.h" diff --git a/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h b/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h index 60e11492057..599d24e260a 100644 --- a/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h +++ b/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h @@ -15,6 +15,10 @@ #define ENABLE_SYNC_CALL_RESTRICTIONS 0 #endif +namespace chromecast { +class CastCdmOriginProvider; +} // namespace chromecast + namespace sync_preferences { class PrefServiceSyncable; } @@ -82,6 +86,11 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncCallRestrictions { // For preventing frame swaps of wrong size during resize on Windows. // (https://crbug.com/811945) friend class ui::Compositor; + // For calling sync mojo API to get cdm origin. The service and the client are + // running in the same process, so it won't block anything. + // TODO(159346933) Remove once the origin isolation logic is moved outside of + // cast media service. + friend class chromecast::CastCdmOriginProvider; // END ALLOWED USAGE. #if ENABLE_SYNC_CALL_RESTRICTIONS diff --git a/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h b/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h index f75e1e232af..5ed7e7b827e 100644 --- a/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h +++ b/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h @@ -22,7 +22,7 @@ namespace mojo { // SyncHandleWatcher is used for sync methods. While a sync call is waiting for // response, we would like to block the sequence. On the other hand, we need // incoming sync method requests on the same sequence to be able to reenter. We -// also need master interface endpoints to continue dispatching messages for +// also need primary interface endpoints to continue dispatching messages for // associated endpoints on different sequence. // // This class is not thread safe. diff --git a/chromium/mojo/public/cpp/bindings/tests/BUILD.gn b/chromium/mojo/public/cpp/bindings/tests/BUILD.gn index 6fb6542728a..16674cc3366 100644 --- a/chromium/mojo/public/cpp/bindings/tests/BUILD.gn +++ b/chromium/mojo/public/cpp/bindings/tests/BUILD.gn @@ -67,7 +67,6 @@ source_set("tests") { ":test_extra_cpp_template_mojom", ":test_mojom", "//base/test:test_support", - "//mojo/core/embedder", "//mojo/public/cpp/bindings", "//mojo/public/cpp/system", "//mojo/public/cpp/test_support:test_utils", @@ -197,7 +196,10 @@ source_set("mojo_public_bindings_test_utils") { "validation_test_input_parser.h", ] - deps = [ "//mojo/public/c/system" ] + deps = [ + "//base", + "//mojo/public/c/system", + ] } action("generate_test_mojom") { diff --git a/chromium/mojo/public/cpp/platform/platform_channel.cc b/chromium/mojo/public/cpp/platform/platform_channel.cc index 3320bcce7eb..140fb8bf965 100644 --- a/chromium/mojo/public/cpp/platform/platform_channel.cc +++ b/chromium/mojo/public/cpp/platform/platform_channel.cc @@ -337,4 +337,10 @@ PlatformChannelEndpoint PlatformChannel::RecoverPassedEndpointFromCommandLine( command_line.GetSwitchValueASCII(kHandleSwitch)); } +// static +bool PlatformChannel::CommandLineHasPassedEndpoint( + const base::CommandLine& command_line) { + return command_line.HasSwitch(kHandleSwitch); +} + } // namespace mojo diff --git a/chromium/mojo/public/cpp/platform/platform_channel.h b/chromium/mojo/public/cpp/platform/platform_channel.h index 01d3ae19390..c7ef7badb8a 100644 --- a/chromium/mojo/public/cpp/platform/platform_channel.h +++ b/chromium/mojo/public/cpp/platform/platform_channel.h @@ -107,6 +107,10 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannel { static PlatformChannelEndpoint RecoverPassedEndpointFromCommandLine( const base::CommandLine& command_line) WARN_UNUSED_RESULT; + // Indicates whether |RecoverPassedEndpointFromCommandLine()| would succeed. + static bool CommandLineHasPassedEndpoint( + const base::CommandLine& command_line); + private: PlatformChannelEndpoint local_endpoint_; PlatformChannelEndpoint remote_endpoint_; diff --git a/chromium/mojo/public/cpp/platform/platform_handle.h b/chromium/mojo/public/cpp/platform/platform_handle.h index 0e01be2cfa7..338b992a2d0 100644 --- a/chromium/mojo/public/cpp/platform/platform_handle.h +++ b/chromium/mojo/public/cpp/platform/platform_handle.h @@ -5,9 +5,9 @@ #ifndef MOJO_PUBLIC_CPP_PLATFORM_PLATFORM_HANDLE_H_ #define MOJO_PUBLIC_CPP_PLATFORM_PLATFORM_HANDLE_H_ +#include "base/check_op.h" #include "base/component_export.h" #include "base/files/platform_file.h" -#include "base/logging.h" #include "base/macros.h" #include "build/build_config.h" #include "mojo/public/c/system/platform_handle.h" diff --git a/chromium/mojo/public/cpp/platform/socket_utils_posix.cc b/chromium/mojo/public/cpp/platform/socket_utils_posix.cc index 6199a36a69e..b135da1a4e8 100644 --- a/chromium/mojo/public/cpp/platform/socket_utils_posix.cc +++ b/chromium/mojo/public/cpp/platform/socket_utils_posix.cc @@ -14,6 +14,7 @@ #include "base/files/file_util.h" #include "base/logging.h" +#include "base/notreached.h" #include "base/posix/eintr_wrapper.h" #include "build/build_config.h" diff --git a/chromium/mojo/public/cpp/platform/socket_utils_posix.h b/chromium/mojo/public/cpp/platform/socket_utils_posix.h index 9e53d058127..3da31cc77e7 100644 --- a/chromium/mojo/public/cpp/platform/socket_utils_posix.h +++ b/chromium/mojo/public/cpp/platform/socket_utils_posix.h @@ -13,7 +13,6 @@ #include "base/component_export.h" #include "base/files/platform_file.h" #include "base/files/scoped_file.h" -#include "base/logging.h" #include "base/macros.h" struct iovec; // Declared in <sys/uio.h> diff --git a/chromium/mojo/public/cpp/system/BUILD.gn b/chromium/mojo/public/cpp/system/BUILD.gn index 8608e7b8f0d..7f8eaefbb1f 100644 --- a/chromium/mojo/public/cpp/system/BUILD.gn +++ b/chromium/mojo/public/cpp/system/BUILD.gn @@ -17,10 +17,13 @@ component("system") { "data_pipe_producer.h", "data_pipe_utils.cc", "data_pipe_utils.h", + "dynamic_library_support.cc", + "dynamic_library_support.h", "file_data_source.cc", "file_data_source.h", "filtered_data_source.cc", "filtered_data_source.h", + "functions.cc", "functions.h", "handle.h", "handle_signal_tracker.cc", diff --git a/chromium/mojo/public/cpp/system/buffer.h b/chromium/mojo/public/cpp/system/buffer.h index e20a8fe14d9..9b8700badf8 100644 --- a/chromium/mojo/public/cpp/system/buffer.h +++ b/chromium/mojo/public/cpp/system/buffer.h @@ -16,8 +16,8 @@ #include <memory> +#include "base/check_op.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "mojo/public/c/system/buffer.h" #include "mojo/public/cpp/system/handle.h" #include "mojo/public/cpp/system/system_export.h" diff --git a/chromium/mojo/public/cpp/system/data_pipe.h b/chromium/mojo/public/cpp/system/data_pipe.h index eb7d6e279ad..6cd2eb35428 100644 --- a/chromium/mojo/public/cpp/system/data_pipe.h +++ b/chromium/mojo/public/cpp/system/data_pipe.h @@ -14,8 +14,8 @@ #include <stdint.h> +#include "base/check.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "mojo/public/c/system/data_pipe.h" #include "mojo/public/cpp/system/handle.h" diff --git a/chromium/mojo/public/cpp/system/data_pipe_producer.cc b/chromium/mojo/public/cpp/system/data_pipe_producer.cc index 056620a794d..bb474ca29df 100644 --- a/chromium/mojo/public/cpp/system/data_pipe_producer.cc +++ b/chromium/mojo/public/cpp/system/data_pipe_producer.cc @@ -53,6 +53,8 @@ class DataPipeProducer::SequenceState void Cancel() { base::AutoLock lock(lock_); is_cancelled_ = true; + owning_task_runner()->PostTask( + FROM_HERE, base::BindOnce(&SequenceState::CancelOnSequence, this)); } void Start(std::unique_ptr<DataSource> data_source) { @@ -151,6 +153,13 @@ class DataPipeProducer::SequenceState std::move(producer_handle_), result)); } + void CancelOnSequence() { + if (!data_source_) + return; + data_source_->Abort(); + Finish(MOJO_RESULT_CANCELLED); + } + const scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; // State which is effectively owned and used only on the file sequence. diff --git a/chromium/mojo/public/cpp/system/dynamic_library_support.cc b/chromium/mojo/public/cpp/system/dynamic_library_support.cc new file mode 100644 index 00000000000..c106778e69c --- /dev/null +++ b/chromium/mojo/public/cpp/system/dynamic_library_support.cc @@ -0,0 +1,64 @@ +// 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/public/cpp/system/dynamic_library_support.h" + +#include <stdint.h> + +#include "base/command_line.h" +#include "build/build_config.h" +#include "mojo/public/c/system/functions.h" + +namespace mojo { + +namespace { + +// Helper for temporary storage related to |MojoInitialize()| calls. +struct InitializationState { + InitializationState(const base::Optional<base::FilePath>& path, + MojoInitializeFlags flags) { + options.flags = flags; + + if (path) { + utf8_path = path->AsUTF8Unsafe(); + options.mojo_core_path = utf8_path.c_str(); + options.mojo_core_path_length = static_cast<uint32_t>(utf8_path.size()); + } + +#if defined(OS_POSIX) || defined(OS_FUCHSIA) + // Build a temporary reconstructed argv to pass into the library so it can + // inspect the application command line if needed. + for (const std::string& s : base::CommandLine::ForCurrentProcess()->argv()) + argv.push_back(s.c_str()); + options.argc = static_cast<uint32_t>(argv.size()); + options.argv = argv.data(); +#endif + } + + MojoInitializeOptions options = {sizeof(MojoInitializeOptions)}; + std::string utf8_path; + std::vector<const char*> argv; +}; + +} // namespace + +MojoResult LoadCoreLibrary(base::Optional<base::FilePath> path) { + InitializationState state(path, MOJO_INITIALIZE_FLAG_LOAD_ONLY); + return MojoInitialize(&state.options); +} + +MojoResult InitializeCoreLibrary(MojoInitializeFlags flags) { + DCHECK_EQ(flags & MOJO_INITIALIZE_FLAG_LOAD_ONLY, 0u); + InitializationState state(base::nullopt, flags); + return MojoInitialize(&state.options); +} + +MojoResult LoadAndInitializeCoreLibrary(base::Optional<base::FilePath> path, + MojoInitializeFlags flags) { + DCHECK_EQ(flags & MOJO_INITIALIZE_FLAG_LOAD_ONLY, 0u); + InitializationState state(path, flags); + return MojoInitialize(&state.options); +} + +} // namespace mojo diff --git a/chromium/mojo/public/cpp/system/dynamic_library_support.h b/chromium/mojo/public/cpp/system/dynamic_library_support.h new file mode 100644 index 00000000000..97c30427cb6 --- /dev/null +++ b/chromium/mojo/public/cpp/system/dynamic_library_support.h @@ -0,0 +1,45 @@ +// 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_PUBLIC_CPP_SYSTEM_DYNAMIC_LIBRARY_SUPPORT_H_ +#define MOJO_PUBLIC_CPP_SYSTEM_DYNAMIC_LIBRARY_SUPPORT_H_ + +#include "base/files/file_path.h" +#include "base/optional.h" +#include "mojo/public/c/system/types.h" +#include "mojo/public/cpp/system/system_export.h" + +namespace mojo { + +// Helper to load Mojo Core dynamically from a shared library. If |path| is +// not given, the library path is assumed to be set in the +// MOJO_CORE_LIBRARY_PATH environment variable, or the library is searched for +// in the current working directory. +// +// This may only be called in a process that hasn't already initialized Mojo. +// Mojo is still not fully initialized or usable until |InitializeCoreLibrary()| +// is also called. These two functions are kept distinct to facilitate use +// cases where the client application must perform some work (e.g. sandbox +// configuration, forking, etc) between the loading and initialization steps. +MOJO_CPP_SYSTEM_EXPORT MojoResult +LoadCoreLibrary(base::Optional<base::FilePath> path); + +// Initializes the dynamic Mojo Core library previously loaded by +// |LoadCoreLibrary()| above. +// +// This may only be called in a process that hasn't already initialized Mojo. +MOJO_CPP_SYSTEM_EXPORT MojoResult +InitializeCoreLibrary(MojoInitializeFlags flags); + +// Loads and initializes Mojo Core from a shared library. This combines +// |LoadCoreLibrary()| and |InitializeCoreLibrary()| for convenience in cases +// where they don't need to be performed at different times by the client +// application. +MOJO_CPP_SYSTEM_EXPORT MojoResult +LoadAndInitializeCoreLibrary(base::Optional<base::FilePath> path, + MojoInitializeFlags flags); + +} // namespace mojo + +#endif // MOJO_PUBLIC_CPP_SYSTEM_DYNAMIC_LIBRARY_SUPPORT_H_ diff --git a/chromium/mojo/public/cpp/system/functions.cc b/chromium/mojo/public/cpp/system/functions.cc new file mode 100644 index 00000000000..74aee1a0973 --- /dev/null +++ b/chromium/mojo/public/cpp/system/functions.cc @@ -0,0 +1,36 @@ +// 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/public/cpp/system/functions.h" + +#include "base/callback.h" +#include "base/no_destructor.h" + +namespace mojo { + +namespace { + +DefaultProcessErrorHandler& GetDefaultProcessErrorHandler() { + static base::NoDestructor<DefaultProcessErrorHandler> handler; + return *handler; +} + +void HandleError(const MojoProcessErrorDetails* details) { + const DefaultProcessErrorHandler& handler = GetDefaultProcessErrorHandler(); + handler.Run( + std::string(details->error_message, details->error_message_length)); +} + +} // namespace + +void SetDefaultProcessErrorHandler(DefaultProcessErrorHandler handler) { + // Ensure any previously set handler is wiped out. + MojoSetDefaultProcessErrorHandler(nullptr, nullptr); + auto& global_handler = GetDefaultProcessErrorHandler(); + global_handler = std::move(handler); + if (global_handler) + MojoSetDefaultProcessErrorHandler(&HandleError, nullptr); +} + +} // namespace mojo diff --git a/chromium/mojo/public/cpp/system/functions.h b/chromium/mojo/public/cpp/system/functions.h index 31edf57ab54..4f45ecef20c 100644 --- a/chromium/mojo/public/cpp/system/functions.h +++ b/chromium/mojo/public/cpp/system/functions.h @@ -11,7 +11,11 @@ #ifndef MOJO_PUBLIC_CPP_SYSTEM_FUNCTIONS_H_ #define MOJO_PUBLIC_CPP_SYSTEM_FUNCTIONS_H_ +#include <string> + +#include "base/callback_forward.h" #include "mojo/public/c/system/functions.h" +#include "mojo/public/cpp/system/system_export.h" namespace mojo { @@ -21,6 +25,17 @@ inline MojoTimeTicks GetTimeTicksNow() { return MojoGetTimeTicksNow(); } +// Sets a callback to handle communication errors regarding peer processes whose +// identity is not explicitly known by this process, i.e. processes that are +// part of the same Mojo process network but which were not invited by this +// process. +// +// This can be used to globally listen for reports of bad incoming IPCs. +using DefaultProcessErrorHandler = + base::RepeatingCallback<void(const std::string& error)>; +void MOJO_CPP_SYSTEM_EXPORT +SetDefaultProcessErrorHandler(DefaultProcessErrorHandler handler); + } // namespace mojo #endif // MOJO_PUBLIC_CPP_SYSTEM_FUNCTIONS_H_ diff --git a/chromium/mojo/public/cpp/system/handle.h b/chromium/mojo/public/cpp/system/handle.h index 61e1e570a2b..a0bd46ba2aa 100644 --- a/chromium/mojo/public/cpp/system/handle.h +++ b/chromium/mojo/public/cpp/system/handle.h @@ -8,8 +8,8 @@ #include <stdint.h> #include <limits> +#include "base/check_op.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "base/macros.h" #include "mojo/public/c/system/functions.h" #include "mojo/public/c/system/types.h" diff --git a/chromium/mojo/public/cpp/system/message_pipe.h b/chromium/mojo/public/cpp/system/message_pipe.h index 3803a20dee5..92ac7a5fcba 100644 --- a/chromium/mojo/public/cpp/system/message_pipe.h +++ b/chromium/mojo/public/cpp/system/message_pipe.h @@ -16,8 +16,8 @@ #include <vector> +#include "base/check_op.h" #include "base/compiler_specific.h" -#include "base/logging.h" #include "mojo/public/c/system/message_pipe.h" #include "mojo/public/cpp/system/handle.h" #include "mojo/public/cpp/system/message.h" diff --git a/chromium/mojo/public/cpp/system/platform_handle.h b/chromium/mojo/public/cpp/system/platform_handle.h index 297be2263e7..eb69b3e661a 100644 --- a/chromium/mojo/public/cpp/system/platform_handle.h +++ b/chromium/mojo/public/cpp/system/platform_handle.h @@ -15,7 +15,6 @@ #include "base/compiler_specific.h" #include "base/files/platform_file.h" -#include "base/logging.h" #include "base/macros.h" #include "base/memory/read_only_shared_memory_region.h" #include "base/memory/unsafe_shared_memory_region.h" diff --git a/chromium/mojo/public/cpp/test_support/BUILD.gn b/chromium/mojo/public/cpp/test_support/BUILD.gn index 8bde2beb334..3312a371ba8 100644 --- a/chromium/mojo/public/cpp/test_support/BUILD.gn +++ b/chromium/mojo/public/cpp/test_support/BUILD.gn @@ -12,7 +12,6 @@ static_library("test_utils") { ] deps = [ - "//mojo/core/embedder", "//mojo/public/c/test_support", "//mojo/public/cpp/bindings", "//mojo/public/cpp/system", diff --git a/chromium/mojo/public/cpp/test_support/lib/test_utils.cc b/chromium/mojo/public/cpp/test_support/lib/test_utils.cc index 99e7f708bf2..062106db864 100644 --- a/chromium/mojo/public/cpp/test_support/lib/test_utils.cc +++ b/chromium/mojo/public/cpp/test_support/lib/test_utils.cc @@ -10,7 +10,7 @@ #include <vector> #include "base/bind.h" -#include "mojo/core/embedder/embedder.h" +#include "base/bind_helpers.h" #include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/wait.h" #include "mojo/public/cpp/test_support/test_support.h" @@ -80,13 +80,12 @@ void IterateAndReportPerf(const char* test_name, } BadMessageObserver::BadMessageObserver() : got_bad_message_(false) { - mojo::core::SetDefaultProcessErrorCallback(base::BindRepeating( + mojo::SetDefaultProcessErrorHandler(base::BindRepeating( &BadMessageObserver::OnReportBadMessage, base::Unretained(this))); } BadMessageObserver::~BadMessageObserver() { - mojo::core::SetDefaultProcessErrorCallback( - mojo::core::ProcessErrorCallback()); + mojo::SetDefaultProcessErrorHandler(base::NullCallback()); } std::string BadMessageObserver::WaitForBadMessage() { |