diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-02 12:21:57 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2022-02-12 08:13:00 +0000 |
commit | 606d85f2a5386472314d39923da28c70c60dc8e7 (patch) | |
tree | a8f4d7bf997f349f45605e6058259fba0630e4d7 /chromium/mojo | |
parent | 5786336dda477d04fb98483dca1a5426eebde2d7 (diff) | |
download | qtwebengine-chromium-606d85f2a5386472314d39923da28c70c60dc8e7.tar.gz |
BASELINE: Update Chromium to 96.0.4664.181
Change-Id: I762cd1da89d73aa6313b4a753fe126c34833f046
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/mojo')
177 files changed, 1223 insertions, 497 deletions
diff --git a/chromium/mojo/OWNERS b/chromium/mojo/OWNERS index 341cd128276..fa4cae5f33a 100644 --- a/chromium/mojo/OWNERS +++ b/chromium/mojo/OWNERS @@ -5,4 +5,4 @@ rockot@google.com rsesek@chromium.org # For Fuchsia-specific changes: -per-file *_fuchsia*=file://build/fuchsia/OWNERS +per-file ..._fuchsia*=file://build/fuchsia/OWNERS diff --git a/chromium/mojo/core/BUILD.gn b/chromium/mojo/core/BUILD.gn index ae3c1b2386f..711b89e64dd 100644 --- a/chromium/mojo/core/BUILD.gn +++ b/chromium/mojo/core/BUILD.gn @@ -5,6 +5,7 @@ import("//build/config/chromeos/ui_mode.gni") import("//build/config/compiler/compiler.gni") import("//build/config/nacl/config.gni") +import("//chrome/process_version_rc_template.gni") import("//testing/libfuzzer/fuzzer_test.gni") import("//testing/test.gni") @@ -190,6 +191,13 @@ core_impl_source_set("impl_for_embedder") { for_shared_library = false } +if (is_win) { + process_version_rc_template("mojo_core_version") { + sources = [ "mojo_core.ver" ] + output = "$target_gen_dir/mojo_core_version.rc" + } +} + if (is_chromeos || is_linux || is_android || is_win) { core_impl_source_set("impl_for_shared_library") { for_shared_library = true @@ -206,6 +214,7 @@ if (is_chromeos || is_linux || is_android || is_win) { ] if (is_win) { sources += [ "mojo_core.def" ] + deps += [ ":mojo_core_version" ] } else { configs += [ ":export_only_thunks_api" ] } diff --git a/chromium/mojo/core/atomic_flag.h b/chromium/mojo/core/atomic_flag.h index aec7f4ee65b..e5a79033a52 100644 --- a/chromium/mojo/core/atomic_flag.h +++ b/chromium/mojo/core/atomic_flag.h @@ -33,6 +33,10 @@ namespace core { class AtomicFlag { public: AtomicFlag() : flag_(0) {} + + AtomicFlag(const AtomicFlag&) = delete; + AtomicFlag& operator=(const AtomicFlag&) = delete; + ~AtomicFlag() = default; void Set(bool value) { base::subtle::Release_Store(&flag_, value ? 1 : 0); } @@ -43,8 +47,6 @@ class AtomicFlag { private: base::subtle::Atomic32 flag_; - - DISALLOW_COPY_AND_ASSIGN(AtomicFlag); }; } // namespace core diff --git a/chromium/mojo/core/broker.h b/chromium/mojo/core/broker.h index a22210d4b9f..27e070c5d7a 100644 --- a/chromium/mojo/core/broker.h +++ b/chromium/mojo/core/broker.h @@ -26,6 +26,10 @@ class Broker { // Otherwise, no initialization message is expected and this will not wait for // one. Broker(PlatformHandle handle, bool wait_for_channel_handle); + + Broker(const Broker&) = delete; + Broker& operator=(const Broker&) = delete; + ~Broker(); // Returns the platform handle that should be used to establish a NodeChannel @@ -49,8 +53,6 @@ class Broker { // with message ordering since we can only have one request at a time // in-flight. base::Lock lock_; - - DISALLOW_COPY_AND_ASSIGN(Broker); }; } // namespace core diff --git a/chromium/mojo/core/broker_host.cc b/chromium/mojo/core/broker_host.cc index 3b44ca3f5fa..211c8fbef9b 100644 --- a/chromium/mojo/core/broker_host.cc +++ b/chromium/mojo/core/broker_host.cc @@ -50,12 +50,15 @@ BrokerHost::~BrokerHost() { } bool BrokerHost::PrepareHandlesForClient( - std::vector<PlatformHandleInTransit>* handles) { + std::vector<PlatformHandleInTransit>* handles, + bool check_on_failure) { #if defined(OS_WIN) bool handles_ok = true; for (auto& handle : *handles) { - if (!handle.TransferToProcess(client_process_.Duplicate())) + if (!handle.TransferToProcess(client_process_.Duplicate(), + check_on_failure)) { handles_ok = false; + } } return handles_ok; #else @@ -81,7 +84,7 @@ bool BrokerHost::SendChannel(PlatformHandle handle) { // This may legitimately fail on Windows if the client process is in another // session, e.g., is an elevated process. - if (!PrepareHandlesForClient(&handles)) + if (!PrepareHandlesForClient(&handles, /*check_on_failure=*/false)) return false; message->SetHandles(std::move(handles)); @@ -135,7 +138,7 @@ void BrokerHost::OnBufferRequest(uint32_t num_bytes) { const base::UnguessableToken& guid = region.GetGUID(); response->guid_high = guid.GetHighForSerialization(); response->guid_low = guid.GetLowForSerialization(); - PrepareHandlesForClient(&handles); + PrepareHandlesForClient(&handles, /*check_on_failure=*/true); message->SetHandles(std::move(handles)); } diff --git a/chromium/mojo/core/broker_host.h b/chromium/mojo/core/broker_host.h index f17681ce9f1..b4f004f2df3 100644 --- a/chromium/mojo/core/broker_host.h +++ b/chromium/mojo/core/broker_host.h @@ -32,6 +32,9 @@ class BrokerHost : public Channel::Delegate, ConnectionParams connection_params, const ProcessErrorCallback& process_error_callback); + BrokerHost(const BrokerHost&) = delete; + BrokerHost& operator=(const BrokerHost&) = delete; + // Send |handle| to the client, to be used to establish a NodeChannel to us. bool SendChannel(PlatformHandle handle); @@ -43,7 +46,8 @@ class BrokerHost : public Channel::Delegate, private: ~BrokerHost() override; - bool PrepareHandlesForClient(std::vector<PlatformHandleInTransit>* handles); + bool PrepareHandlesForClient(std::vector<PlatformHandleInTransit>* handles, + bool check_on_failure); // Channel::Delegate: void OnChannelMessage(const void* payload, @@ -63,8 +67,6 @@ class BrokerHost : public Channel::Delegate, #endif scoped_refptr<Channel> channel_; - - DISALLOW_COPY_AND_ASSIGN(BrokerHost); }; } // namespace core diff --git a/chromium/mojo/core/channel.cc b/chromium/mojo/core/channel.cc index 5935ef3cecf..0bbdafa3afb 100644 --- a/chromium/mojo/core/channel.cc +++ b/chromium/mojo/core/channel.cc @@ -84,6 +84,10 @@ struct ComplexMessage : public Channel::Message { size_t max_handles, size_t payload_size, MessageType message_type); + + ComplexMessage(const ComplexMessage&) = delete; + ComplexMessage& operator=(const ComplexMessage&) = delete; + ~ComplexMessage() override = default; // Message impl: @@ -120,10 +124,12 @@ struct ComplexMessage : public Channel::Message { // On OSX, handles are serialised into the extra header section. MachPortsExtraHeader* mach_ports_header_ = nullptr; #endif - DISALLOW_COPY_AND_ASSIGN(ComplexMessage); }; struct TrivialMessage : public Channel::Message { + TrivialMessage(const TrivialMessage&) = delete; + TrivialMessage& operator=(const TrivialMessage&) = delete; + ~TrivialMessage() override = default; // TryConstruct should be used to build a TrivialMessage. @@ -153,7 +159,6 @@ struct TrivialMessage : public Channel::Message { alignas(sizeof(void*)) uint8_t data_[256 - sizeof(Channel::Message)]; static constexpr size_t kInternalCapacity = sizeof(data_); - DISALLOW_COPY_AND_ASSIGN(TrivialMessage); }; static_assert(sizeof(TrivialMessage) == 256, @@ -699,6 +704,9 @@ class Channel::ReadBuffer { data_ = MakeAlignedBuffer(size_); } + ReadBuffer(const ReadBuffer&) = delete; + ReadBuffer& operator=(const ReadBuffer&) = delete; + ~ReadBuffer() { DCHECK(data_); } const char* occupied_bytes() const { @@ -782,8 +790,6 @@ class Channel::ReadBuffer { // The total number of occupied bytes, including discarded bytes. size_t num_occupied_bytes_ = 0; - - DISALLOW_COPY_AND_ASSIGN(ReadBuffer); }; Channel::Channel(Delegate* delegate, diff --git a/chromium/mojo/core/channel.h b/chromium/mojo/core/channel.h index 7288dd87c25..7c628d96ced 100644 --- a/chromium/mojo/core/channel.h +++ b/chromium/mojo/core/channel.h @@ -62,6 +62,9 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel // A message to be written to a channel. struct MOJO_SYSTEM_IMPL_EXPORT Message { + Message(const Message&) = delete; + Message& operator=(const Message&) = delete; + virtual ~Message() = default; enum class MessageType : uint16_t { @@ -234,8 +237,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel // be transmitted if the message is written to a channel. Includes all // headers and user payload. size_t size_ = 0; - - DISALLOW_COPY_AND_ASSIGN(Message); }; // Error types which may be reported by a Channel instance to its delegate. @@ -280,6 +281,9 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel HandlePolicy handle_policy, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); + Channel(const Channel&) = delete; + Channel& operator=(const Channel&) = delete; + #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_MAC) // At this point only ChannelPosix needs InitFeatures. static void set_posix_use_writev(bool use_writev); @@ -426,8 +430,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Channel // Handle to the process on the other end of this Channel, iff known. base::Process remote_process_; - - DISALLOW_COPY_AND_ASSIGN(Channel); }; } // namespace core diff --git a/chromium/mojo/core/channel_fuchsia.cc b/chromium/mojo/core/channel_fuchsia.cc index 7b112ded3fe..7dc36b12d0e 100644 --- a/chromium/mojo/core/channel_fuchsia.cc +++ b/chromium/mojo/core/channel_fuchsia.cc @@ -46,25 +46,22 @@ bool UnwrapFdioHandle(PlatformHandleInTransit handle, return true; } - // Try to transfer the FD, and if that fails (for example if the file has - // already been dup()d into another FD) then fall back to cloning it. + // TODO(crbug.com/1254755) The FD should be transferred and only clone if this + // is impossible. Unfortunately, as fdio_fd_transfer currently takes ownership + // of the fd even when it fails, this is currently not possible. + + // Try to clone the FD, and if that fails (because |fd| has insufficient + // rights to clone the underlying object), fall back to transferring it. zx::handle result; - zx_status_t status = fdio_fd_transfer(handle.handle().GetFD().get(), - result.reset_and_get_address()); - if (status == ZX_OK) { - // On success, the fd in |handle| has been transferred and is no longer - // valid. Release from the PlatformHandle to avoid close()ing an invalid - // an invalid handle. - handle.CompleteTransit(); - } else if (status == ZX_ERR_UNAVAILABLE) { - // No luck, try cloning instead. - status = fdio_fd_clone(handle.handle().GetFD().get(), - result.reset_and_get_address()); + zx_status_t status = fdio_fd_clone(handle.handle().GetFD().get(), + result.reset_and_get_address()); + if (status == ZX_ERR_ACCESS_DENIED) { + status = fdio_fd_transfer(handle.TakeHandle().ReleaseFD(), + result.reset_and_get_address()); } if (status != ZX_OK) { - ZX_DLOG(ERROR, status) << "fdio_fd_clone/transfer(" - << handle.handle().GetFD().get() << ")"; + ZX_DLOG(ERROR, status) << "fdio_fd_clone/transfer"; return false; } @@ -104,6 +101,9 @@ class MessageView { MessageView& operator=(MessageView&& other) = default; + MessageView(const MessageView&) = delete; + MessageView& operator=(const MessageView&) = delete; + ~MessageView() = default; const void* data() const { @@ -144,8 +144,6 @@ class MessageView { Channel::MessagePtr message_; size_t offset_; std::vector<PlatformHandleInTransit> handles_; - - DISALLOW_COPY_AND_ASSIGN(MessageView); }; class ChannelFuchsia : public Channel, @@ -164,6 +162,9 @@ class ChannelFuchsia : public Channel, CHECK(handle_.is_valid()); } + ChannelFuchsia(const ChannelFuchsia&) = delete; + ChannelFuchsia& operator=(const ChannelFuchsia&) = delete; + void Start() override { if (io_task_runner_->RunsTasksInCurrentSequence()) { StartOnIOThread(); @@ -403,8 +404,6 @@ class ChannelFuchsia : public Channel, base::Lock write_lock_; bool reject_writes_ = false; - - DISALLOW_COPY_AND_ASSIGN(ChannelFuchsia); }; } // namespace diff --git a/chromium/mojo/core/channel_linux.cc b/chromium/mojo/core/channel_linux.cc index 20333a7d19b..22c391d2797 100644 --- a/chromium/mojo/core/channel_linux.cc +++ b/chromium/mojo/core/channel_linux.cc @@ -181,6 +181,10 @@ class EventFDNotifier : public DataAvailableNotifier, public base::MessagePumpForIO::FdWatcher { public: EventFDNotifier(EventFDNotifier&& efd) = default; + + EventFDNotifier(const EventFDNotifier&) = delete; + EventFDNotifier& operator=(const EventFDNotifier&) = delete; + ~EventFDNotifier() override { reset(); } static constexpr int kEfdFlags = EFD_CLOEXEC | EFD_NONBLOCK; @@ -318,8 +322,6 @@ class EventFDNotifier : public DataAvailableNotifier, base::ScopedFD fd_; std::unique_ptr<base::MessagePumpForIO::FdWatchController> watcher_; scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; - - DISALLOW_COPY_AND_ASSIGN(EventFDNotifier); }; } // namespace @@ -331,6 +333,10 @@ class EventFDNotifier : public DataAvailableNotifier, class ChannelLinux::SharedBuffer { public: SharedBuffer(SharedBuffer&& other) = default; + + SharedBuffer(const SharedBuffer&) = delete; + SharedBuffer& operator=(const SharedBuffer&) = delete; + ~SharedBuffer() { reset(); } enum class Error { kSuccess = 0, kGeneralError = 1, kControlCorruption = 2 }; @@ -602,8 +608,6 @@ class ChannelLinux::SharedBuffer { uint8_t* base_ptr_ = nullptr; size_t len_ = 0; - - DISALLOW_COPY_AND_ASSIGN(SharedBuffer); }; ChannelLinux::ChannelLinux( diff --git a/chromium/mojo/core/channel_mac.cc b/chromium/mojo/core/channel_mac.cc index 51ccc3200f2..d325190db28 100644 --- a/chromium/mojo/core/channel_mac.cc +++ b/chromium/mojo/core/channel_mac.cc @@ -69,6 +69,9 @@ class ChannelMac : public Channel, } } + ChannelMac(const ChannelMac&) = delete; + ChannelMac& operator=(const ChannelMac&) = delete; + void Start() override { io_task_runner_->PostTask( FROM_HERE, base::BindOnce(&ChannelMac::StartOnIOThread, this)); @@ -708,8 +711,6 @@ class ChannelMac : public Channel, // When |handshake_done_| is false or |send_buffer_contains_message_| is true, // calls to Write() will enqueue messages here. base::circular_deque<MessagePtr> pending_messages_; - - DISALLOW_COPY_AND_ASSIGN(ChannelMac); }; } // namespace diff --git a/chromium/mojo/core/channel_posix.cc b/chromium/mojo/core/channel_posix.cc index 782d4f03307..f05582c4339 100644 --- a/chromium/mojo/core/channel_posix.cc +++ b/chromium/mojo/core/channel_posix.cc @@ -65,6 +65,9 @@ class MessageView { MessageView& operator=(MessageView&& other) = default; + MessageView(const MessageView&) = delete; + MessageView& operator=(const MessageView&) = delete; + ~MessageView() { if (message_) { UMA_HISTOGRAM_TIMES("Mojo.Channel.WriteMessageLatency", @@ -111,8 +114,6 @@ class MessageView { size_t num_handles_sent_ = 0; base::TimeTicks start_time_ = base::TimeTicks::Now(); - - DISALLOW_COPY_AND_ASSIGN(MessageView); }; ChannelPosix::ChannelPosix( @@ -132,8 +133,8 @@ ChannelPosix::ChannelPosix( } ChannelPosix::~ChannelPosix() { - DCHECK(!read_watcher_); - DCHECK(!write_watcher_); + CHECK(!read_watcher_); + CHECK(!write_watcher_); } void ChannelPosix::Start() { @@ -158,7 +159,6 @@ void ChannelPosix::Write(MessagePtr message) { message->NumHandlesForTransit()); bool write_error = false; - bool queued = false; { base::AutoLock lock(write_lock_); if (reject_writes_) @@ -169,7 +169,6 @@ void ChannelPosix::Write(MessagePtr message) { } else { outgoing_messages_.emplace_back(std::move(message), 0); } - queued = !outgoing_messages_.empty(); } if (write_error) { // Invoke OnWriteError() asynchronously on the IO thread, in case Write() @@ -178,7 +177,6 @@ void ChannelPosix::Write(MessagePtr message) { base::BindOnce(&ChannelPosix::OnWriteError, this, Error::kDisconnected)); } - UMA_HISTOGRAM_BOOLEAN("Mojo.Channel.WriteQueued", queued); } void ChannelPosix::LeakHandle() { diff --git a/chromium/mojo/core/channel_posix.h b/chromium/mojo/core/channel_posix.h index 306e8d2bcf7..7b4ca78ac36 100644 --- a/chromium/mojo/core/channel_posix.h +++ b/chromium/mojo/core/channel_posix.h @@ -32,6 +32,9 @@ class ChannelPosix : public Channel, HandlePolicy handle_policy, scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); + ChannelPosix(const ChannelPosix&) = delete; + ChannelPosix& operator=(const ChannelPosix&) = delete; + void Start() override; void ShutDownImpl() override; void Write(MessagePtr message) override; @@ -121,8 +124,6 @@ class ChannelPosix : public Channel, base::Lock fds_to_close_lock_; std::vector<base::ScopedFD> fds_to_close_; #endif // defined(OS_IOS) - - DISALLOW_COPY_AND_ASSIGN(ChannelPosix); }; } // namespace core diff --git a/chromium/mojo/core/channel_unittest.cc b/chromium/mojo/core/channel_unittest.cc index 0a377457310..ae250a3a8f5 100644 --- a/chromium/mojo/core/channel_unittest.cc +++ b/chromium/mojo/core/channel_unittest.cc @@ -293,6 +293,9 @@ class RejectHandlesDelegate : public Channel::Delegate { public: RejectHandlesDelegate() = default; + RejectHandlesDelegate(const RejectHandlesDelegate&) = delete; + RejectHandlesDelegate& operator=(const RejectHandlesDelegate&) = delete; + size_t num_messages() const { return num_messages_; } // Channel::Delegate: @@ -315,8 +318,6 @@ class RejectHandlesDelegate : public Channel::Delegate { private: size_t num_messages_ = 0; absl::optional<base::RunLoop> wait_for_error_loop_; - - DISALLOW_COPY_AND_ASSIGN(RejectHandlesDelegate); }; TEST(ChannelTest, RejectHandles) { @@ -529,6 +530,9 @@ class CallbackChannelDelegate : public Channel::Delegate { public: CallbackChannelDelegate() = default; + CallbackChannelDelegate(const CallbackChannelDelegate&) = delete; + CallbackChannelDelegate& operator=(const CallbackChannelDelegate&) = delete; + void OnChannelMessage(const void* payload, size_t payload_size, std::vector<PlatformHandle> handles) override { @@ -552,7 +556,6 @@ class CallbackChannelDelegate : public Channel::Delegate { private: base::OnceClosure on_message_; base::OnceClosure on_error_; - DISALLOW_COPY_AND_ASSIGN(CallbackChannelDelegate); }; TEST(ChannelTest, MessageSizeTest) { diff --git a/chromium/mojo/core/channel_win.cc b/chromium/mojo/core/channel_win.cc index 79fea3ec1f8..9347285c32d 100644 --- a/chromium/mojo/core/channel_win.cc +++ b/chromium/mojo/core/channel_win.cc @@ -102,6 +102,9 @@ class ChannelWin : public Channel, CHECK(handle_.IsValid()); } + ChannelWin(const ChannelWin&) = delete; + ChannelWin& operator=(const ChannelWin&) = delete; + void Start() override { io_task_runner_->PostTask( FROM_HERE, base::BindOnce(&ChannelWin::StartOnIOThread, this)); @@ -172,7 +175,7 @@ class ChannelWin : public Channel, base::win::Uint32ToHandle(extra_header_handles[i].handle); if (PlatformHandleInTransit::IsPseudoHandle(handle_value)) return false; - if (remote_process().IsValid()) { + if (remote_process().IsValid() && handle_value != INVALID_HANDLE_VALUE) { // If we know the remote process's handle, we assume it doesn't know // ours; that means any handle values still belong to that process, and // we need to transfer them to this process. @@ -420,8 +423,6 @@ class ChannelWin : public Channel, bool is_write_pending_ = false; bool leak_handle_ = false; - - DISALLOW_COPY_AND_ASSIGN(ChannelWin); }; } // namespace diff --git a/chromium/mojo/core/connection_params.h b/chromium/mojo/core/connection_params.h index c1f41c03140..754a1283826 100644 --- a/chromium/mojo/core/connection_params.h +++ b/chromium/mojo/core/connection_params.h @@ -21,6 +21,10 @@ class MOJO_SYSTEM_IMPL_EXPORT ConnectionParams { explicit ConnectionParams(PlatformChannelEndpoint endpoint); explicit ConnectionParams(PlatformChannelServerEndpoint server_endpoint); ConnectionParams(ConnectionParams&&); + + ConnectionParams(const ConnectionParams&) = delete; + ConnectionParams& operator=(const ConnectionParams&) = delete; + ~ConnectionParams(); ConnectionParams& operator=(ConnectionParams&&); @@ -47,8 +51,6 @@ class MOJO_SYSTEM_IMPL_EXPORT ConnectionParams { bool leak_endpoint_ = false; PlatformChannelEndpoint endpoint_; PlatformChannelServerEndpoint server_endpoint_; - - DISALLOW_COPY_AND_ASSIGN(ConnectionParams); }; } // namespace core diff --git a/chromium/mojo/core/core.cc b/chromium/mojo/core/core.cc index 35a3d3c477a..69b61785eb9 100644 --- a/chromium/mojo/core/core.cc +++ b/chromium/mojo/core/core.cc @@ -87,6 +87,9 @@ class ProcessDisconnectHandler { ProcessDisconnectHandler(MojoProcessErrorHandler handler, uintptr_t context) : handler_(handler), context_(context) {} + ProcessDisconnectHandler(const ProcessDisconnectHandler&) = delete; + ProcessDisconnectHandler& operator=(const ProcessDisconnectHandler&) = delete; + ~ProcessDisconnectHandler() { InvokeProcessErrorCallback(handler_, context_, std::string(), MOJO_PROCESS_ERROR_FLAG_DISCONNECTED); @@ -95,8 +98,6 @@ class ProcessDisconnectHandler { private: const MojoProcessErrorHandler handler_; const uintptr_t context_; - - DISALLOW_COPY_AND_ASSIGN(ProcessDisconnectHandler); }; void RunMojoProcessErrorHandler( @@ -449,8 +450,11 @@ MojoResult Core::GetMessageData(MojoMessageHandle message_handle, } RequestContext request_context; - return message->ExtractSerializedHandles( + Dispatcher::SetExtractingHandlesFromMessage(true); + MojoResult result = message->ExtractSerializedHandles( UserMessageImpl::ExtractBadHandlePolicy::kAbort, handles); + Dispatcher::SetExtractingHandlesFromMessage(false); + return result; } MojoResult Core::SetMessageContext( diff --git a/chromium/mojo/core/core.h b/chromium/mojo/core/core.h index 8946d534fd5..f952a1b348d 100644 --- a/chromium/mojo/core/core.h +++ b/chromium/mojo/core/core.h @@ -39,6 +39,10 @@ class PlatformSharedMemoryMapping; class MOJO_SYSTEM_IMPL_EXPORT Core { public: Core(); + + Core(const Core&) = delete; + Core& operator=(const Core&) = delete; + virtual ~Core(); static Core* Get(); @@ -360,8 +364,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Core { using MappingTable = std::unordered_map<void*, std::unique_ptr<PlatformSharedMemoryMapping>>; MappingTable mapping_table_; - - DISALLOW_COPY_AND_ASSIGN(Core); }; } // namespace core diff --git a/chromium/mojo/core/core_test_base.cc b/chromium/mojo/core/core_test_base.cc index e173d853d1a..aa5a37f2354 100644 --- a/chromium/mojo/core/core_test_base.cc +++ b/chromium/mojo/core/core_test_base.cc @@ -32,6 +32,9 @@ class MockDispatcher : public Dispatcher { return base::WrapRefCounted(new MockDispatcher(info)); } + MockDispatcher(const MockDispatcher&) = delete; + MockDispatcher& operator=(const MockDispatcher&) = delete; + // Dispatcher: Type GetType() const override { return Type::UNKNOWN; } @@ -97,8 +100,6 @@ class MockDispatcher : public Dispatcher { ~MockDispatcher() override { info_->IncrementDtorCallCount(); } CoreTestBase::MockHandleInfo* const info_; - - DISALLOW_COPY_AND_ASSIGN(MockDispatcher); }; } // namespace diff --git a/chromium/mojo/core/core_test_base.h b/chromium/mojo/core/core_test_base.h index ebc5fe154e3..908ef9df2d5 100644 --- a/chromium/mojo/core/core_test_base.h +++ b/chromium/mojo/core/core_test_base.h @@ -26,6 +26,10 @@ class CoreTestBase : public testing::Test { using MockHandleInfo = CoreTestBase_MockHandleInfo; CoreTestBase(); + + CoreTestBase(const CoreTestBase&) = delete; + CoreTestBase& operator=(const CoreTestBase&) = delete; + ~CoreTestBase() override; protected: @@ -33,14 +37,16 @@ class CoreTestBase : public testing::Test { MojoHandle CreateMockHandle(MockHandleInfo* info); Core* core(); - - private: - DISALLOW_COPY_AND_ASSIGN(CoreTestBase); }; class CoreTestBase_MockHandleInfo { public: CoreTestBase_MockHandleInfo(); + + CoreTestBase_MockHandleInfo(const CoreTestBase_MockHandleInfo&) = delete; + CoreTestBase_MockHandleInfo& operator=(const CoreTestBase_MockHandleInfo&) = + delete; + ~CoreTestBase_MockHandleInfo(); unsigned GetCtorCallCount() const; @@ -81,8 +87,6 @@ class CoreTestBase_MockHandleInfo { unsigned read_data_call_count_; unsigned begin_read_data_call_count_; unsigned end_read_data_call_count_; - - DISALLOW_COPY_AND_ASSIGN(CoreTestBase_MockHandleInfo); }; } // namespace test diff --git a/chromium/mojo/core/core_unittest.cc b/chromium/mojo/core/core_unittest.cc index 546aba020c8..b6b52df999a 100644 --- a/chromium/mojo/core/core_unittest.cc +++ b/chromium/mojo/core/core_unittest.cc @@ -35,7 +35,7 @@ TEST_F(CoreTest, GetTimeTicksNow) { const MojoTimeTicks start = core()->GetTimeTicksNow(); ASSERT_NE(static_cast<MojoTimeTicks>(0), start) << "GetTimeTicksNow should return nonzero value"; - base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(15)); + base::PlatformThread::Sleep(base::Milliseconds(15)); const MojoTimeTicks finish = core()->GetTimeTicksNow(); // Allow for some fuzz in sleep. ASSERT_GE((finish - start), static_cast<MojoTimeTicks>(8000)) diff --git a/chromium/mojo/core/data_pipe_consumer_dispatcher.cc b/chromium/mojo/core/data_pipe_consumer_dispatcher.cc index e64ac7eccdf..4e76209bb5d 100644 --- a/chromium/mojo/core/data_pipe_consumer_dispatcher.cc +++ b/chromium/mojo/core/data_pipe_consumer_dispatcher.cc @@ -59,6 +59,9 @@ class DataPipeConsumerDispatcher::PortObserverThunk scoped_refptr<DataPipeConsumerDispatcher> dispatcher) : dispatcher_(dispatcher) {} + PortObserverThunk(const PortObserverThunk&) = delete; + PortObserverThunk& operator=(const PortObserverThunk&) = delete; + private: ~PortObserverThunk() override = default; @@ -66,8 +69,6 @@ class DataPipeConsumerDispatcher::PortObserverThunk void OnPortStatusChanged() override { dispatcher_->OnPortStatusChanged(); } scoped_refptr<DataPipeConsumerDispatcher> dispatcher_; - - DISALLOW_COPY_AND_ASSIGN(PortObserverThunk); }; // static @@ -367,6 +368,7 @@ DataPipeConsumerDispatcher::Deserialize(const void* data, size_t num_handles) { if (num_ports != 1 || num_handles != 1 || num_bytes != sizeof(SerializedState)) { + AssertNotExtractingHandlesFromMessage(); return nullptr; } @@ -375,13 +377,16 @@ DataPipeConsumerDispatcher::Deserialize(const void* data, state->options.capacity_num_bytes < state->options.element_num_bytes || state->read_offset >= state->options.capacity_num_bytes || state->bytes_available > state->options.capacity_num_bytes) { + AssertNotExtractingHandlesFromMessage(); return nullptr; } NodeController* node_controller = Core::Get()->GetNodeController(); ports::PortRef port; - if (node_controller->node()->GetPort(ports[0], &port) != ports::OK) + if (node_controller->node()->GetPort(ports[0], &port) != ports::OK) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } auto region_handle = CreateSharedMemoryRegionHandleFromPlatformHandles( std::move(handles[0]), PlatformHandle()); @@ -395,6 +400,7 @@ DataPipeConsumerDispatcher::Deserialize(const void* data, base::UnsafeSharedMemoryRegion::Deserialize(std::move(region)); if (!ring_buffer.IsValid()) { DLOG(ERROR) << "Failed to deserialize shared buffer handle."; + AssertNotExtractingHandlesFromMessage(); return nullptr; } @@ -409,10 +415,13 @@ DataPipeConsumerDispatcher::Deserialize(const void* data, dispatcher->bytes_available_ = state->bytes_available; dispatcher->new_data_available_ = state->bytes_available > 0; dispatcher->peer_closed_ = state->flags & kFlagPeerClosed; - if (!dispatcher->InitializeNoLock()) + if (!dispatcher->InitializeNoLock()) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } if (state->options.capacity_num_bytes > dispatcher->ring_buffer_mapping_.mapped_size()) { + AssertNotExtractingHandlesFromMessage(); return nullptr; } dispatcher->UpdateSignalsStateNoLock(); diff --git a/chromium/mojo/core/data_pipe_consumer_dispatcher.h b/chromium/mojo/core/data_pipe_consumer_dispatcher.h index dd5b9350c14..e7d1e0d0b25 100644 --- a/chromium/mojo/core/data_pipe_consumer_dispatcher.h +++ b/chromium/mojo/core/data_pipe_consumer_dispatcher.h @@ -36,6 +36,10 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final const MojoCreateDataPipeOptions& options, uint64_t pipe_id); + DataPipeConsumerDispatcher(const DataPipeConsumerDispatcher&) = delete; + DataPipeConsumerDispatcher& operator=(const DataPipeConsumerDispatcher&) = + delete; + // Dispatcher: Type GetType() const override; MojoResult Close() override; @@ -116,8 +120,6 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeConsumerDispatcher final // Indicates whether any new data is available since the last read attempt. bool new_data_available_ = false; - - DISALLOW_COPY_AND_ASSIGN(DataPipeConsumerDispatcher); }; } // namespace core diff --git a/chromium/mojo/core/data_pipe_producer_dispatcher.cc b/chromium/mojo/core/data_pipe_producer_dispatcher.cc index 80ff8ee2ac4..65f72611eec 100644 --- a/chromium/mojo/core/data_pipe_producer_dispatcher.cc +++ b/chromium/mojo/core/data_pipe_producer_dispatcher.cc @@ -58,6 +58,9 @@ class DataPipeProducerDispatcher::PortObserverThunk scoped_refptr<DataPipeProducerDispatcher> dispatcher) : dispatcher_(dispatcher) {} + PortObserverThunk(const PortObserverThunk&) = delete; + PortObserverThunk& operator=(const PortObserverThunk&) = delete; + private: ~PortObserverThunk() override = default; @@ -65,8 +68,6 @@ class DataPipeProducerDispatcher::PortObserverThunk void OnPortStatusChanged() override { dispatcher_->OnPortStatusChanged(); } scoped_refptr<DataPipeProducerDispatcher> dispatcher_; - - DISALLOW_COPY_AND_ASSIGN(PortObserverThunk); }; // static @@ -328,6 +329,7 @@ DataPipeProducerDispatcher::Deserialize(const void* data, size_t num_handles) { if (num_ports != 1 || num_handles != 1 || num_bytes != sizeof(SerializedState)) { + AssertNotExtractingHandlesFromMessage(); return nullptr; } @@ -336,13 +338,16 @@ DataPipeProducerDispatcher::Deserialize(const void* data, state->options.capacity_num_bytes < state->options.element_num_bytes || state->write_offset >= state->options.capacity_num_bytes || state->available_capacity > state->options.capacity_num_bytes) { + AssertNotExtractingHandlesFromMessage(); return nullptr; } NodeController* node_controller = Core::Get()->GetNodeController(); ports::PortRef port; - if (node_controller->node()->GetPort(ports[0], &port) != ports::OK) + if (node_controller->node()->GetPort(ports[0], &port) != ports::OK) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } auto region_handle = CreateSharedMemoryRegionHandleFromPlatformHandles( std::move(handles[0]), PlatformHandle()); @@ -356,6 +361,7 @@ DataPipeProducerDispatcher::Deserialize(const void* data, base::UnsafeSharedMemoryRegion::Deserialize(std::move(region)); if (!ring_buffer.IsValid()) { DLOG(ERROR) << "Failed to deserialize shared buffer handle."; + AssertNotExtractingHandlesFromMessage(); return nullptr; } @@ -369,10 +375,13 @@ DataPipeProducerDispatcher::Deserialize(const void* data, dispatcher->write_offset_ = state->write_offset; dispatcher->available_capacity_ = state->available_capacity; dispatcher->peer_closed_ = state->flags & kFlagPeerClosed; - if (!dispatcher->InitializeNoLock()) + if (!dispatcher->InitializeNoLock()) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } if (state->options.capacity_num_bytes > dispatcher->ring_buffer_mapping_.mapped_size()) { + AssertNotExtractingHandlesFromMessage(); return nullptr; } dispatcher->UpdateSignalsStateNoLock(); diff --git a/chromium/mojo/core/data_pipe_producer_dispatcher.h b/chromium/mojo/core/data_pipe_producer_dispatcher.h index a95513782de..e648cd389a6 100644 --- a/chromium/mojo/core/data_pipe_producer_dispatcher.h +++ b/chromium/mojo/core/data_pipe_producer_dispatcher.h @@ -36,6 +36,10 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final const MojoCreateDataPipeOptions& options, uint64_t pipe_id); + DataPipeProducerDispatcher(const DataPipeProducerDispatcher&) = delete; + DataPipeProducerDispatcher& operator=(const DataPipeProducerDispatcher&) = + delete; + // Dispatcher: Type GetType() const override; MojoResult Close() override; @@ -107,8 +111,6 @@ class MOJO_SYSTEM_IMPL_EXPORT DataPipeProducerDispatcher final uint32_t write_offset_ = 0; uint32_t available_capacity_; - - DISALLOW_COPY_AND_ASSIGN(DataPipeProducerDispatcher); }; } // namespace core diff --git a/chromium/mojo/core/data_pipe_unittest.cc b/chromium/mojo/core/data_pipe_unittest.cc index 330c957cf1c..4308c0db8b1 100644 --- a/chromium/mojo/core/data_pipe_unittest.cc +++ b/chromium/mojo/core/data_pipe_unittest.cc @@ -63,7 +63,7 @@ base::TimeDelta EpsilonDeadline() { #else const int64_t deadline = (tiny_timeout * 2) / 10; #endif - return base::TimeDelta::FromMicroseconds(deadline); + return base::Microseconds(deadline); } // TODO(rockot): There are many uses of ASSERT where EXPECT would be more @@ -74,6 +74,9 @@ class DataPipeTest : public test::MojoTestBase { DataPipeTest() : producer_(MOJO_HANDLE_INVALID), consumer_(MOJO_HANDLE_INVALID) {} + DataPipeTest(const DataPipeTest&) = delete; + DataPipeTest& operator=(const DataPipeTest&) = delete; + ~DataPipeTest() override { if (producer_ != MOJO_HANDLE_INVALID) CHECK_EQ(MOJO_RESULT_OK, MojoClose(producer_)); @@ -173,9 +176,6 @@ class DataPipeTest : public test::MojoTestBase { } MojoHandle producer_, consumer_; - - private: - DISALLOW_COPY_AND_ASSIGN(DataPipeTest); }; TEST_F(DataPipeTest, Basic) { diff --git a/chromium/mojo/core/dispatcher.cc b/chromium/mojo/core/dispatcher.cc index 25959441808..b8e64d9ddca 100644 --- a/chromium/mojo/core/dispatcher.cc +++ b/chromium/mojo/core/dispatcher.cc @@ -5,6 +5,8 @@ #include "mojo/core/dispatcher.h" #include "base/logging.h" +#include "base/no_destructor.h" +#include "base/threading/thread_local.h" #include "mojo/core/configuration.h" #include "mojo/core/data_pipe_consumer_dispatcher.h" #include "mojo/core/data_pipe_producer_dispatcher.h" @@ -16,6 +18,15 @@ namespace mojo { namespace core { +namespace { + +base::ThreadLocalBoolean& IsExtractingHandlesFromMessage() { + static base::NoDestructor<base::ThreadLocalBoolean> flag; + return *flag; +} + +} // namespace + Dispatcher::DispatcherInTransit::DispatcherInTransit() = default; Dispatcher::DispatcherInTransit::DispatcherInTransit( @@ -23,6 +34,16 @@ Dispatcher::DispatcherInTransit::DispatcherInTransit( Dispatcher::DispatcherInTransit::~DispatcherInTransit() = default; +// static +void Dispatcher::SetExtractingHandlesFromMessage(bool extracting) { + IsExtractingHandlesFromMessage().Set(extracting); +} + +// static +void Dispatcher::AssertNotExtractingHandlesFromMessage() { + DCHECK(!IsExtractingHandlesFromMessage().Get()); +} + MojoResult Dispatcher::WatchDispatcher(scoped_refptr<Dispatcher> dispatcher, MojoHandleSignals signals, MojoTriggerCondition condition, diff --git a/chromium/mojo/core/dispatcher.h b/chromium/mojo/core/dispatcher.h index be62e70c8e2..7e497a2529d 100644 --- a/chromium/mojo/core/dispatcher.h +++ b/chromium/mojo/core/dispatcher.h @@ -74,6 +74,20 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher PLATFORM_HANDLE = -1, }; + Dispatcher(const Dispatcher&) = delete; + Dispatcher& operator=(const Dispatcher&) = delete; + + // TODO(crbug.com/1229671): Remove these and all callers. + // + // The assert is invoked at various points of handle deserialization failure. + // Such failures are expected and innocuous when destroying unread or unsent, + // discarded messages with attachments that may no longer be valid; but they + // are problematic when hit during normal message deserialization for messages + // the application expects to read and dispatch. Both this setter and the + // assertion are concerned only with their calling thread. + static void SetExtractingHandlesFromMessage(bool extracting); + static void AssertNotExtractingHandlesFromMessage(); + // All Dispatchers must minimally implement these methods. virtual Type GetType() const = 0; @@ -286,8 +300,6 @@ class MOJO_SYSTEM_IMPL_EXPORT Dispatcher Dispatcher(); virtual ~Dispatcher(); - - DISALLOW_COPY_AND_ASSIGN(Dispatcher); }; // So logging macros and |DCHECK_EQ()|, etc. work. diff --git a/chromium/mojo/core/embedder/scoped_ipc_support.h b/chromium/mojo/core/embedder/scoped_ipc_support.h index ff603294702..d19337a8193 100644 --- a/chromium/mojo/core/embedder/scoped_ipc_support.h +++ b/chromium/mojo/core/embedder/scoped_ipc_support.h @@ -105,12 +105,14 @@ class COMPONENT_EXPORT(MOJO_CORE_EMBEDDER) ScopedIPCSupport { ScopedIPCSupport( scoped_refptr<base::SingleThreadTaskRunner> io_thread_task_runner, ShutdownPolicy shutdown_policy); + + ScopedIPCSupport(const ScopedIPCSupport&) = delete; + ScopedIPCSupport& operator=(const ScopedIPCSupport&) = delete; + ~ScopedIPCSupport(); private: const ShutdownPolicy shutdown_policy_; - - DISALLOW_COPY_AND_ASSIGN(ScopedIPCSupport); }; } // namespace core diff --git a/chromium/mojo/core/handle_table.h b/chromium/mojo/core/handle_table.h index fdc9f21239a..e4234b18121 100644 --- a/chromium/mojo/core/handle_table.h +++ b/chromium/mojo/core/handle_table.h @@ -25,6 +25,10 @@ class MOJO_SYSTEM_IMPL_EXPORT HandleTable : public base::trace_event::MemoryDumpProvider { public: HandleTable(); + + HandleTable(const HandleTable&) = delete; + HandleTable& operator=(const HandleTable&) = delete; + ~HandleTable() override; // HandleTable is thread-hostile. All access should be gated by GetLock(). @@ -80,8 +84,6 @@ class MOJO_SYSTEM_IMPL_EXPORT HandleTable base::Lock lock_; uint32_t next_available_handle_ = 1; - - DISALLOW_COPY_AND_ASSIGN(HandleTable); }; } // namespace core diff --git a/chromium/mojo/core/handle_table_unittest.cc b/chromium/mojo/core/handle_table_unittest.cc index 0724fb09474..75edb11d6d8 100644 --- a/chromium/mojo/core/handle_table_unittest.cc +++ b/chromium/mojo/core/handle_table_unittest.cc @@ -29,13 +29,16 @@ class FakeMessagePipeDispatcher : public Dispatcher { public: FakeMessagePipeDispatcher() = default; + FakeMessagePipeDispatcher(const FakeMessagePipeDispatcher&) = delete; + FakeMessagePipeDispatcher& operator=(const FakeMessagePipeDispatcher&) = + delete; + Type GetType() const override { return Type::MESSAGE_PIPE; } MojoResult Close() override { return MOJO_RESULT_OK; } private: ~FakeMessagePipeDispatcher() override = default; - DISALLOW_COPY_AND_ASSIGN(FakeMessagePipeDispatcher); }; void CheckNameAndValue(base::trace_event::ProcessMemoryDump* pmd, diff --git a/chromium/mojo/core/invitation_dispatcher.h b/chromium/mojo/core/invitation_dispatcher.h index 4d4739eaa55..44792f35163 100644 --- a/chromium/mojo/core/invitation_dispatcher.h +++ b/chromium/mojo/core/invitation_dispatcher.h @@ -22,6 +22,9 @@ class MOJO_SYSTEM_IMPL_EXPORT InvitationDispatcher : public Dispatcher { public: InvitationDispatcher(); + InvitationDispatcher(const InvitationDispatcher&) = delete; + InvitationDispatcher& operator=(const InvitationDispatcher&) = delete; + // Dispatcher: Type GetType() const override; MojoResult Close() override; @@ -39,8 +42,6 @@ class MOJO_SYSTEM_IMPL_EXPORT InvitationDispatcher : public Dispatcher { base::Lock lock_; bool is_closed_ = false; PortMapping attached_ports_; - - DISALLOW_COPY_AND_ASSIGN(InvitationDispatcher); }; } // namespace core diff --git a/chromium/mojo/core/invitation_unittest.cc b/chromium/mojo/core/invitation_unittest.cc index 2c8eeef9fee..4782d68be52 100644 --- a/chromium/mojo/core/invitation_unittest.cc +++ b/chromium/mojo/core/invitation_unittest.cc @@ -47,6 +47,10 @@ const char kSecondaryChannelHandleSwitch[] = "test-secondary-channel-handle"; class InvitationTest : public test::MojoTestBase { public: InvitationTest() = default; + + InvitationTest(const InvitationTest&) = delete; + InvitationTest& operator=(const InvitationTest&) = delete; + ~InvitationTest() override = default; protected: @@ -74,8 +78,6 @@ class InvitationTest : public test::MojoTestBase { private: base::test::TaskEnvironment task_environment_; - - DISALLOW_COPY_AND_ASSIGN(InvitationTest); }; void PrepareToPassRemoteEndpoint(PlatformChannel* channel, @@ -404,6 +406,9 @@ void InvitationTest::SendInvitationToClient( class TestClientBase : public InvitationTest { public: + TestClientBase(const TestClientBase&) = delete; + TestClientBase& operator=(const TestClientBase&) = delete; + static MojoHandle AcceptInvitation(MojoAcceptInvitationFlags flags, base::StringPiece switch_name = {}) { const auto& command_line = *base::CommandLine::ForCurrentProcess(); @@ -439,9 +444,6 @@ class TestClientBase : public InvitationTest { MojoAcceptInvitation(&transport_endpoint, &options, &invitation)); return invitation; } - - private: - DISALLOW_COPY_AND_ASSIGN(TestClientBase); }; #define DEFINE_TEST_CLIENT(name) \ @@ -587,6 +589,10 @@ class RemoteProcessState { public: RemoteProcessState() : callback_task_runner_(base::SequencedTaskRunnerHandle::Get()) {} + + RemoteProcessState(const RemoteProcessState&) = delete; + RemoteProcessState& operator=(const RemoteProcessState&) = delete; + ~RemoteProcessState() = default; bool disconnected() { @@ -620,8 +626,6 @@ class RemoteProcessState { bool disconnected_ = false; std::string expected_error_message_; base::RepeatingClosure error_callback_; - - DISALLOW_COPY_AND_ASSIGN(RemoteProcessState); }; void TestProcessErrorHandler(uintptr_t context, diff --git a/chromium/mojo/core/message_pipe_dispatcher.cc b/chromium/mojo/core/message_pipe_dispatcher.cc index bbe013f6fd1..96229d4f319 100644 --- a/chromium/mojo/core/message_pipe_dispatcher.cc +++ b/chromium/mojo/core/message_pipe_dispatcher.cc @@ -46,6 +46,9 @@ class MessagePipeDispatcher::PortObserverThunk explicit PortObserverThunk(scoped_refptr<MessagePipeDispatcher> dispatcher) : dispatcher_(dispatcher) {} + PortObserverThunk(const PortObserverThunk&) = delete; + PortObserverThunk& operator=(const PortObserverThunk&) = delete; + private: ~PortObserverThunk() override = default; @@ -53,8 +56,6 @@ class MessagePipeDispatcher::PortObserverThunk void OnPortStatusChanged() override { dispatcher_->OnPortStatusChanged(); } scoped_refptr<MessagePipeDispatcher> dispatcher_; - - DISALLOW_COPY_AND_ASSIGN(PortObserverThunk); }; #if DCHECK_IS_ON() @@ -64,6 +65,10 @@ class MessagePipeDispatcher::PortObserverThunk class PeekSizeMessageFilter : public ports::MessageFilter { public: PeekSizeMessageFilter() = default; + + PeekSizeMessageFilter(const PeekSizeMessageFilter&) = delete; + PeekSizeMessageFilter& operator=(const PeekSizeMessageFilter&) = delete; + ~PeekSizeMessageFilter() override = default; // ports::MessageFilter: @@ -78,8 +83,6 @@ class PeekSizeMessageFilter : public ports::MessageFilter { private: size_t message_size_ = 0; - - DISALLOW_COPY_AND_ASSIGN(PeekSizeMessageFilter); }; #endif // DCHECK_IS_ON() @@ -357,19 +360,25 @@ scoped_refptr<Dispatcher> MessagePipeDispatcher::Deserialize( size_t num_ports, PlatformHandle* handles, size_t num_handles) { - if (num_ports != 1 || num_handles || num_bytes != sizeof(SerializedState)) + if (num_ports != 1 || num_handles || num_bytes != sizeof(SerializedState)) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } const SerializedState* state = static_cast<const SerializedState*>(data); ports::Node* node = Core::Get()->GetNodeController()->node(); ports::PortRef port; - if (node->GetPort(ports[0], &port) != ports::OK) + if (node->GetPort(ports[0], &port) != ports::OK) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } ports::PortStatus status; - if (node->GetStatus(port, &status) != ports::OK) + if (node->GetStatus(port, &status) != ports::OK) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } return new MessagePipeDispatcher(Core::Get()->GetNodeController(), port, state->pipe_id, state->endpoint); diff --git a/chromium/mojo/core/message_pipe_dispatcher.h b/chromium/mojo/core/message_pipe_dispatcher.h index 9747a588e45..15fd57241b0 100644 --- a/chromium/mojo/core/message_pipe_dispatcher.h +++ b/chromium/mojo/core/message_pipe_dispatcher.h @@ -40,6 +40,9 @@ class MessagePipeDispatcher : public Dispatcher { uint64_t pipe_id, int endpoint); + MessagePipeDispatcher(const MessagePipeDispatcher&) = delete; + MessagePipeDispatcher& operator=(const MessagePipeDispatcher&) = delete; + // Fuses this pipe with |other|. Returns |true| on success or |false| on // failure. Regardless of the return value, both dispatchers are closed by // this call. @@ -108,8 +111,6 @@ class MessagePipeDispatcher : public Dispatcher { absl::optional<uint64_t> receive_queue_length_limit_; absl::optional<uint64_t> receive_queue_memory_size_limit_; absl::optional<uint64_t> unread_message_count_limit_; - - DISALLOW_COPY_AND_ASSIGN(MessagePipeDispatcher); }; } // namespace core diff --git a/chromium/mojo/core/message_pipe_perftest.cc b/chromium/mojo/core/message_pipe_perftest.cc index f7ae32e345c..1ff5b9dcaf6 100644 --- a/chromium/mojo/core/message_pipe_perftest.cc +++ b/chromium/mojo/core/message_pipe_perftest.cc @@ -31,6 +31,9 @@ class MessagePipePerfTest : public test::MojoTestBase { public: MessagePipePerfTest() : message_count_(0), message_size_(0) {} + MessagePipePerfTest(const MessagePipePerfTest&) = delete; + MessagePipePerfTest& operator=(const MessagePipePerfTest&) = delete; + void SetUpMeasurement(int message_count, size_t message_size) { message_count_ = message_count; message_size_ = message_size; @@ -123,8 +126,6 @@ class MessagePipePerfTest : public test::MojoTestBase { std::string payload_; std::vector<uint8_t> read_buffer_; std::unique_ptr<base::PerfTimeLogger> perf_logger_; - - DISALLOW_COPY_AND_ASSIGN(MessagePipePerfTest); }; TEST_F(MessagePipePerfTest, PingPong) { diff --git a/chromium/mojo/core/message_pipe_unittest.cc b/chromium/mojo/core/message_pipe_unittest.cc index 9aa13f69f2f..5f5bd879c9b 100644 --- a/chromium/mojo/core/message_pipe_unittest.cc +++ b/chromium/mojo/core/message_pipe_unittest.cc @@ -35,6 +35,9 @@ class MessagePipeTest : public test::MojoTestBase { CHECK_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(nullptr, &pipe0_, &pipe1_)); } + MessagePipeTest(const MessagePipeTest&) = delete; + MessagePipeTest& operator=(const MessagePipeTest&) = delete; + ~MessagePipeTest() override { if (pipe0_ != MOJO_HANDLE_INVALID) CHECK_EQ(MOJO_RESULT_OK, MojoClose(pipe0_)); @@ -78,9 +81,6 @@ class MessagePipeTest : public test::MojoTestBase { } MojoHandle pipe0_, pipe1_; - - private: - DISALLOW_COPY_AND_ASSIGN(MessagePipeTest); }; using FuseMessagePipeTest = test::MojoTestBase; diff --git a/chromium/mojo/core/message_unittest.cc b/chromium/mojo/core/message_unittest.cc index cb0747c09ea..981e82031b7 100644 --- a/chromium/mojo/core/message_unittest.cc +++ b/chromium/mojo/core/message_unittest.cc @@ -102,6 +102,10 @@ class NeverSerializedMessage : public TestMessageBase { NeverSerializedMessage( base::OnceClosure destruction_callback = base::OnceClosure()) : destruction_callback_(std::move(destruction_callback)) {} + + NeverSerializedMessage(const NeverSerializedMessage&) = delete; + NeverSerializedMessage& operator=(const NeverSerializedMessage&) = delete; + ~NeverSerializedMessage() override { if (destruction_callback_) std::move(destruction_callback_).Run(); @@ -116,8 +120,6 @@ class NeverSerializedMessage : public TestMessageBase { void SerializePayload(void* buffer) override { NOTREACHED(); } base::OnceClosure destruction_callback_; - - DISALLOW_COPY_AND_ASSIGN(NeverSerializedMessage); }; class SimpleMessage : public TestMessageBase { @@ -127,6 +129,9 @@ class SimpleMessage : public TestMessageBase { : contents_(contents), destruction_callback_(std::move(destruction_callback)) {} + SimpleMessage(const SimpleMessage&) = delete; + SimpleMessage& operator=(const SimpleMessage&) = delete; + ~SimpleMessage() override { if (destruction_callback_) std::move(destruction_callback_).Run(); @@ -159,8 +164,6 @@ class SimpleMessage : public TestMessageBase { const std::string contents_; base::OnceClosure destruction_callback_; std::vector<mojo::ScopedMessagePipeHandle> handles_; - - DISALLOW_COPY_AND_ASSIGN(SimpleMessage); }; TEST_F(MessageTest, InvalidMessageObjects) { diff --git a/chromium/mojo/core/mojo_core.cc b/chromium/mojo/core/mojo_core.cc index bcbe12105fb..fc1763fa79d 100644 --- a/chromium/mojo/core/mojo_core.cc +++ b/chromium/mojo/core/mojo_core.cc @@ -35,6 +35,9 @@ class IPCSupport { mojo::core::Core::Get()->SetIOTaskRunner(ipc_thread_.task_runner()); } + IPCSupport(const IPCSupport&) = delete; + IPCSupport& operator=(const IPCSupport&) = delete; + ~IPCSupport() { base::WaitableEvent wait(base::WaitableEvent::ResetPolicy::MANUAL, base::WaitableEvent::InitialState::NOT_SIGNALED); @@ -54,8 +57,6 @@ class IPCSupport { #endif // !defined(COMPONENT_BUILD) base::Thread ipc_thread_; - - DISALLOW_COPY_AND_ASSIGN(IPCSupport); }; std::unique_ptr<IPCSupport>& GetIPCSupport() { diff --git a/chromium/mojo/core/mojo_core.ver b/chromium/mojo/core/mojo_core.ver new file mode 100644 index 00000000000..0f12b35bdd1 --- /dev/null +++ b/chromium/mojo/core/mojo_core.ver @@ -0,0 +1,2 @@ +INTERNAL_NAME=mojo_core +ORIGINAL_FILENAME=mojo_core.dll diff --git a/chromium/mojo/core/node_channel.h b/chromium/mojo/core/node_channel.h index 488908a4bc9..2aa0af56a90 100644 --- a/chromium/mojo/core/node_channel.h +++ b/chromium/mojo/core/node_channel.h @@ -90,6 +90,9 @@ class MOJO_SYSTEM_IMPL_EXPORT NodeChannel scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, const ProcessErrorCallback& process_error_callback); + NodeChannel(const NodeChannel&) = delete; + NodeChannel& operator=(const NodeChannel&) = delete; + static Channel::MessagePtr CreateEventMessage(size_t capacity, size_t payload_size, void** payload, @@ -219,8 +222,6 @@ class MOJO_SYSTEM_IMPL_EXPORT NodeChannel base::Lock remote_process_handle_lock_; base::Process remote_process_handle_; - - DISALLOW_COPY_AND_ASSIGN(NodeChannel); }; } // namespace core diff --git a/chromium/mojo/core/node_controller.cc b/chromium/mojo/core/node_controller.cc index 9f2e79b9e04..6e1092096dd 100644 --- a/chromium/mojo/core/node_controller.cc +++ b/chromium/mojo/core/node_controller.cc @@ -20,6 +20,7 @@ #include "mojo/core/broker.h" #include "mojo/core/broker_host.h" #include "mojo/core/configuration.h" +#include "mojo/core/ports/name.h" #include "mojo/core/request_context.h" #include "mojo/core/user_message_impl.h" #include "mojo/public/cpp/platform/named_platform_channel.h" @@ -121,6 +122,10 @@ class ThreadDestructionObserver } } + ThreadDestructionObserver(const ThreadDestructionObserver&) = delete; + ThreadDestructionObserver& operator=(const ThreadDestructionObserver&) = + delete; + private: explicit ThreadDestructionObserver(base::OnceClosure callback) : callback_(std::move(callback)) { @@ -138,8 +143,6 @@ class ThreadDestructionObserver } base::OnceClosure callback_; - - DISALLOW_COPY_AND_ASSIGN(ThreadDestructionObserver); }; } // namespace @@ -888,6 +891,11 @@ void NodeController::OnAddBrokerClient(const ports::NodeName& from_node, return; } + if (!GetConfiguration().is_broker_process) { + DLOG(ERROR) << "Ignoring AddBrokerClient on non-broker node."; + return; + } + if (GetPeerChannel(client_name)) { DLOG(ERROR) << "Ignoring AddBrokerClient for known client."; DropPeer(from_node, nullptr); @@ -1127,6 +1135,12 @@ void NodeController::OnIntroduce(const ports::NodeName& from_node, const uint64_t remote_capabilities) { DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); + if (broker_name_ == ports::kInvalidNodeName || from_node != broker_name_) { + DVLOG(1) << "Ignoring introduction from non-broker process."; + DropPeer(from_node, nullptr); + return; + } + if (!channel_handle.is_valid()) { node_->LostConnectionToNode(name); diff --git a/chromium/mojo/core/node_controller.h b/chromium/mojo/core/node_controller.h index 040eeab79f7..8d5aa032063 100644 --- a/chromium/mojo/core/node_controller.h +++ b/chromium/mojo/core/node_controller.h @@ -53,6 +53,10 @@ class MOJO_SYSTEM_IMPL_EXPORT NodeController : public ports::NodeDelegate, // |core| owns and out-lives us. NodeController(); + + NodeController(const NodeController&) = delete; + NodeController& operator=(const NodeController&) = delete; + ~NodeController() override; const ports::NodeName& name() const { return name_; } @@ -336,8 +340,6 @@ class MOJO_SYSTEM_IMPL_EXPORT NodeController : public ports::NodeDelegate, // Broker for sync shared buffer creation on behalf of broker clients. std::unique_ptr<Broker> broker_; #endif - - DISALLOW_COPY_AND_ASSIGN(NodeController); }; } // namespace core diff --git a/chromium/mojo/core/options_validation.h b/chromium/mojo/core/options_validation.h index 89c12d0c887..a6c00fde6ae 100644 --- a/chromium/mojo/core/options_validation.h +++ b/chromium/mojo/core/options_validation.h @@ -42,6 +42,9 @@ class UserOptionsReader { // (Or maybe assert that its type is uint32_t?) } + UserOptionsReader(const UserOptionsReader&) = delete; + UserOptionsReader& operator=(const UserOptionsReader&) = delete; + bool is_valid() const { return !!options_; } const Options& options() const { @@ -75,8 +78,6 @@ class UserOptionsReader { } const Options* options_; - - DISALLOW_COPY_AND_ASSIGN(UserOptionsReader); }; // Macro to invoke |UserOptionsReader<Options>::HasMember()| parametrized by diff --git a/chromium/mojo/core/platform_handle_dispatcher.cc b/chromium/mojo/core/platform_handle_dispatcher.cc index 7029b965369..d933c5d6e6a 100644 --- a/chromium/mojo/core/platform_handle_dispatcher.cc +++ b/chromium/mojo/core/platform_handle_dispatcher.cc @@ -77,8 +77,10 @@ scoped_refptr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize( size_t num_ports, PlatformHandle* handles, size_t num_handles) { - if (num_bytes || num_ports || num_handles != 1) + if (num_bytes || num_ports || num_handles != 1) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } return PlatformHandleDispatcher::Create(std::move(handles[0])); } diff --git a/chromium/mojo/core/platform_handle_dispatcher.h b/chromium/mojo/core/platform_handle_dispatcher.h index 8d9627c393e..ced85f894c2 100644 --- a/chromium/mojo/core/platform_handle_dispatcher.h +++ b/chromium/mojo/core/platform_handle_dispatcher.h @@ -20,6 +20,9 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher : public Dispatcher { static scoped_refptr<PlatformHandleDispatcher> Create( PlatformHandle platform_handle); + PlatformHandleDispatcher(const PlatformHandleDispatcher&) = delete; + PlatformHandleDispatcher& operator=(const PlatformHandleDispatcher&) = delete; + PlatformHandle TakePlatformHandle(); // Dispatcher: @@ -51,8 +54,6 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformHandleDispatcher : public Dispatcher { bool in_transit_ = false; bool is_closed_ = false; PlatformHandle platform_handle_; - - DISALLOW_COPY_AND_ASSIGN(PlatformHandleDispatcher); }; } // namespace core diff --git a/chromium/mojo/core/platform_handle_in_transit.cc b/chromium/mojo/core/platform_handle_in_transit.cc index 67813bf649d..c3e6a08387f 100644 --- a/chromium/mojo/core/platform_handle_in_transit.cc +++ b/chromium/mojo/core/platform_handle_in_transit.cc @@ -6,13 +6,16 @@ #include <utility> +#include "base/debug/alias.h" #include "base/logging.h" #include "base/process/process_handle.h" #include "build/build_config.h" #if defined(OS_WIN) +#include <ntstatus.h> #include <windows.h> +#include "base/win/nt_status.h" #include "base/win/scoped_handle.h" #endif @@ -24,16 +27,42 @@ namespace { #if defined(OS_WIN) HANDLE TransferHandle(HANDLE handle, base::ProcessHandle from_process, - base::ProcessHandle to_process) { + base::ProcessHandle to_process, + bool check_on_failure = true) { + HANDLE out_handle; BOOL result = - ::DuplicateHandle(from_process, handle, to_process, &handle, 0, FALSE, + ::DuplicateHandle(from_process, handle, to_process, &out_handle, 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE); if (result) { - return handle; - } else { - DPLOG(ERROR) << "DuplicateHandle failed"; + return out_handle; + } + + if (!check_on_failure) { return INVALID_HANDLE_VALUE; } + + const DWORD error = ::GetLastError(); + + // ERROR_ACCESS_DENIED may indicate that the remote process (which could be + // either the source or destination process here) is already terminated or has + // begun termination and therefore no longer has a handle table. We don't want + // these cases to crash because we know they happen in practice and are + // largely unavoidable. + if (error == ERROR_ACCESS_DENIED && + base::win::GetLastNtStatus() == STATUS_PROCESS_IS_TERMINATING) { + DVLOG(1) << "DuplicateHandle from " << from_process << " to " << to_process + << " for handle " << handle + << " failed due to process termination"; + return INVALID_HANDLE_VALUE; + } + + base::debug::Alias(&handle); + base::debug::Alias(&from_process); + base::debug::Alias(&to_process); + base::debug::Alias(&error); + PLOG(FATAL) << "DuplicateHandle failed from " << from_process << " to " + << to_process << " for handle " << handle; + return INVALID_HANDLE_VALUE; } void CloseHandleInProcess(HANDLE handle, const base::Process& process) { @@ -108,14 +137,15 @@ void PlatformHandleInTransit::CompleteTransit() { owning_process_ = base::Process(); } -bool PlatformHandleInTransit::TransferToProcess(base::Process target_process) { +bool PlatformHandleInTransit::TransferToProcess(base::Process target_process, + bool check_on_failure) { DCHECK(target_process.IsValid()); DCHECK(!owning_process_.IsValid()); DCHECK(handle_.is_valid()); #if defined(OS_WIN) remote_handle_ = TransferHandle(handle_.ReleaseHandle(), base::GetCurrentProcessHandle(), - target_process.Handle()); + target_process.Handle(), check_on_failure); if (remote_handle_ == INVALID_HANDLE_VALUE) return false; #endif diff --git a/chromium/mojo/core/platform_handle_in_transit.h b/chromium/mojo/core/platform_handle_in_transit.h index ecf571bc7a1..21a7d9512d4 100644 --- a/chromium/mojo/core/platform_handle_in_transit.h +++ b/chromium/mojo/core/platform_handle_in_transit.h @@ -28,6 +28,10 @@ class PlatformHandleInTransit { PlatformHandleInTransit(); explicit PlatformHandleInTransit(PlatformHandle handle); PlatformHandleInTransit(PlatformHandleInTransit&&); + + PlatformHandleInTransit(const PlatformHandleInTransit&) = delete; + PlatformHandleInTransit& operator=(const PlatformHandleInTransit&) = delete; + ~PlatformHandleInTransit(); PlatformHandleInTransit& operator=(PlatformHandleInTransit&&); @@ -53,7 +57,8 @@ class PlatformHandleInTransit { void CompleteTransit(); // Transfers ownership of this (local) handle to |target_process|. - bool TransferToProcess(base::Process target_process); + bool TransferToProcess(base::Process target_process, + bool check_on_failure = true); #if defined(OS_WIN) HANDLE remote_handle() const { return remote_handle_; } @@ -96,8 +101,6 @@ class PlatformHandleInTransit { PlatformHandle handle_; base::Process owning_process_; - - DISALLOW_COPY_AND_ASSIGN(PlatformHandleInTransit); }; } // namespace core diff --git a/chromium/mojo/core/platform_shared_memory_mapping.h b/chromium/mojo/core/platform_shared_memory_mapping.h index 305f5e4ef15..dd14df31f74 100644 --- a/chromium/mojo/core/platform_shared_memory_mapping.h +++ b/chromium/mojo/core/platform_shared_memory_mapping.h @@ -36,6 +36,11 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedMemoryMapping { PlatformSharedMemoryMapping(base::subtle::PlatformSharedMemoryRegion* region, size_t offset, size_t length); + + PlatformSharedMemoryMapping(const PlatformSharedMemoryMapping&) = delete; + PlatformSharedMemoryMapping& operator=(const PlatformSharedMemoryMapping&) = + delete; + ~PlatformSharedMemoryMapping(); bool IsValid() const; @@ -49,8 +54,6 @@ class MOJO_SYSTEM_IMPL_EXPORT PlatformSharedMemoryMapping { const size_t length_; void* base_ = nullptr; std::unique_ptr<base::SharedMemoryMapping> mapping_; - - DISALLOW_COPY_AND_ASSIGN(PlatformSharedMemoryMapping); }; } // namespace core diff --git a/chromium/mojo/core/ports/event.h b/chromium/mojo/core/ports/event.h index 55c081e3e81..a3790010ef8 100644 --- a/chromium/mojo/core/ports/event.h +++ b/chromium/mojo/core/ports/event.h @@ -80,6 +80,10 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) Event { char padding[7]; }; #pragma pack(pop) + + Event(const Event&) = delete; + Event& operator=(const Event&) = delete; + virtual ~Event(); static ScopedEvent Deserialize(const void* buffer, size_t num_bytes); @@ -106,13 +110,15 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) Event { private: const Type type_; PortName port_name_; - - DISALLOW_COPY_AND_ASSIGN(Event); }; class COMPONENT_EXPORT(MOJO_CORE_PORTS) UserMessageEvent : public Event { public: explicit UserMessageEvent(size_t num_ports); + + UserMessageEvent(const UserMessageEvent&) = delete; + UserMessageEvent& operator=(const UserMessageEvent&) = delete; + ~UserMessageEvent() override; bool HasMessage() const { return !!message_; } @@ -158,13 +164,15 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) UserMessageEvent : public Event { std::vector<PortDescriptor> port_descriptors_; std::vector<PortName> ports_; std::unique_ptr<UserMessage> message_; - - DISALLOW_COPY_AND_ASSIGN(UserMessageEvent); }; class COMPONENT_EXPORT(MOJO_CORE_PORTS) PortAcceptedEvent : public Event { public: explicit PortAcceptedEvent(const PortName& port_name); + + PortAcceptedEvent(const PortAcceptedEvent&) = delete; + PortAcceptedEvent& operator=(const PortAcceptedEvent&) = delete; + ~PortAcceptedEvent() override; static ScopedEvent Deserialize(const PortName& port_name, @@ -174,8 +182,6 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) PortAcceptedEvent : public Event { private: size_t GetSerializedDataSize() const override; void SerializeData(void* buffer) const override; - - DISALLOW_COPY_AND_ASSIGN(PortAcceptedEvent); }; class COMPONENT_EXPORT(MOJO_CORE_PORTS) ObserveProxyEvent : public Event { @@ -185,6 +191,10 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) ObserveProxyEvent : public Event { const PortName& proxy_port_name, const NodeName& proxy_target_node_name, const PortName& proxy_target_port_name); + + ObserveProxyEvent(const ObserveProxyEvent&) = delete; + ObserveProxyEvent& operator=(const ObserveProxyEvent&) = delete; + ~ObserveProxyEvent() override; const NodeName& proxy_node_name() const { return proxy_node_name_; } @@ -209,13 +219,15 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) ObserveProxyEvent : public Event { const PortName proxy_port_name_; const NodeName proxy_target_node_name_; const PortName proxy_target_port_name_; - - DISALLOW_COPY_AND_ASSIGN(ObserveProxyEvent); }; class COMPONENT_EXPORT(MOJO_CORE_PORTS) ObserveProxyAckEvent : public Event { public: ObserveProxyAckEvent(const PortName& port_name, uint64_t last_sequence_num); + + ObserveProxyAckEvent(const ObserveProxyAckEvent&) = delete; + ObserveProxyAckEvent& operator=(const ObserveProxyAckEvent&) = delete; + ~ObserveProxyAckEvent() override; uint64_t last_sequence_num() const { return last_sequence_num_; } @@ -230,13 +242,15 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) ObserveProxyAckEvent : public Event { ScopedEvent Clone() const override; const uint64_t last_sequence_num_; - - DISALLOW_COPY_AND_ASSIGN(ObserveProxyAckEvent); }; class COMPONENT_EXPORT(MOJO_CORE_PORTS) ObserveClosureEvent : public Event { public: ObserveClosureEvent(const PortName& port_name, uint64_t last_sequence_num); + + ObserveClosureEvent(const ObserveClosureEvent&) = delete; + ObserveClosureEvent& operator=(const ObserveClosureEvent&) = delete; + ~ObserveClosureEvent() override; uint64_t last_sequence_num() const { return last_sequence_num_; } @@ -254,8 +268,6 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) ObserveClosureEvent : public Event { ScopedEvent Clone() const override; uint64_t last_sequence_num_; - - DISALLOW_COPY_AND_ASSIGN(ObserveClosureEvent); }; class COMPONENT_EXPORT(MOJO_CORE_PORTS) MergePortEvent : public Event { @@ -263,6 +275,10 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) MergePortEvent : public Event { MergePortEvent(const PortName& port_name, const PortName& new_port_name, const PortDescriptor& new_port_descriptor); + + MergePortEvent(const MergePortEvent&) = delete; + MergePortEvent& operator=(const MergePortEvent&) = delete; + ~MergePortEvent() override; const PortName& new_port_name() const { return new_port_name_; } @@ -280,8 +296,6 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) MergePortEvent : public Event { const PortName new_port_name_; const PortDescriptor new_port_descriptor_; - - DISALLOW_COPY_AND_ASSIGN(MergePortEvent); }; class COMPONENT_EXPORT(MOJO_CORE_PORTS) UserMessageReadAckRequestEvent diff --git a/chromium/mojo/core/ports/message_queue.h b/chromium/mojo/core/ports/message_queue.h index 1d34222c5eb..21d6ab0e100 100644 --- a/chromium/mojo/core/ports/message_queue.h +++ b/chromium/mojo/core/ports/message_queue.h @@ -32,6 +32,10 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) MessageQueue { public: explicit MessageQueue(); explicit MessageQueue(uint64_t next_sequence_num); + + MessageQueue(const MessageQueue&) = delete; + MessageQueue& operator=(const MessageQueue&) = delete; + ~MessageQueue(); void set_signalable(bool value) { signalable_ = value; } @@ -75,8 +79,6 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) MessageQueue { uint64_t next_sequence_num_; bool signalable_ = true; size_t total_queued_bytes_ = 0; - - DISALLOW_COPY_AND_ASSIGN(MessageQueue); }; } // namespace ports diff --git a/chromium/mojo/core/ports/node.cc b/chromium/mojo/core/ports/node.cc index d309b8838f6..ae4c2a2cc19 100644 --- a/chromium/mojo/core/ports/node.cc +++ b/chromium/mojo/core/ports/node.cc @@ -49,6 +49,10 @@ constexpr size_t kRandomNameCacheSize = 256; class RandomNameGenerator { public: RandomNameGenerator() = default; + + RandomNameGenerator(const RandomNameGenerator&) = delete; + RandomNameGenerator& operator=(const RandomNameGenerator&) = delete; + ~RandomNameGenerator() = default; PortName GenerateRandomPortName() { @@ -68,8 +72,6 @@ class RandomNameGenerator { base::Lock lock_; PortName cache_[kRandomNameCacheSize]; size_t cache_index_ = kRandomNameCacheSize; - - DISALLOW_COPY_AND_ASSIGN(RandomNameGenerator); }; base::LazyInstance<RandomNameGenerator>::Leaky g_name_generator = diff --git a/chromium/mojo/core/ports/node.h b/chromium/mojo/core/ports/node.h index e806e1d918c..70dea617b97 100644 --- a/chromium/mojo/core/ports/node.h +++ b/chromium/mojo/core/ports/node.h @@ -75,6 +75,10 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) Node { // Does not take ownership of the delegate. Node(const NodeName& name, NodeDelegate* delegate); + + Node(const Node&) = delete; + Node& operator=(const Node&) = delete; + ~Node(); // Returns true iff there are no open ports referring to another node or ports @@ -185,6 +189,10 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) Node { class DelegateHolder { public: DelegateHolder(Node* node, NodeDelegate* delegate); + + DelegateHolder(const DelegateHolder&) = delete; + DelegateHolder& operator=(const DelegateHolder&) = delete; + ~DelegateHolder(); NodeDelegate* operator->() const { @@ -201,8 +209,6 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) Node { Node* const node_; NodeDelegate* const delegate_; - - DISALLOW_COPY_AND_ASSIGN(DelegateHolder); }; int OnUserMessage(std::unique_ptr<UserMessageEvent> message); @@ -310,8 +316,6 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) Node { // port on a peer node. The key to this map is the corresponding peer node // name. std::unordered_map<NodeName, PeerPortMap> peer_port_maps_; - - DISALLOW_COPY_AND_ASSIGN(Node); }; } // namespace ports diff --git a/chromium/mojo/core/ports/port.h b/chromium/mojo/core/ports/port.h index cd798df0bd2..fbd46e713ac 100644 --- a/chromium/mojo/core/ports/port.h +++ b/chromium/mojo/core/ports/port.h @@ -176,6 +176,9 @@ class Port : public base::RefCountedThreadSafe<Port> { Port(uint64_t next_sequence_num_to_send, uint64_t next_sequence_num_to_receive); + Port(const Port&) = delete; + Port& operator=(const Port&) = delete; + void AssertLockAcquired() { #if DCHECK_IS_ON() lock_.AssertAcquired(); @@ -189,8 +192,6 @@ class Port : public base::RefCountedThreadSafe<Port> { ~Port(); base::Lock lock_; - - DISALLOW_COPY_AND_ASSIGN(Port); }; } // namespace ports diff --git a/chromium/mojo/core/ports/port_locker.h b/chromium/mojo/core/ports/port_locker.h index 0da26545635..3ee349dd5ce 100644 --- a/chromium/mojo/core/ports/port_locker.h +++ b/chromium/mojo/core/ports/port_locker.h @@ -29,6 +29,10 @@ class PortLocker { // |PortRef*|s. The sequence may be reordered by this constructor, and upon // return, all referenced ports' locks are held. PortLocker(const PortRef** port_refs, size_t num_ports); + + PortLocker(const PortLocker&) = delete; + PortLocker& operator=(const PortLocker&) = delete; + ~PortLocker(); // Provides safe access to a PortRef's Port. Note that in release builds this @@ -60,14 +64,16 @@ class PortLocker { private: const PortRef** const port_refs_; const size_t num_ports_; - - DISALLOW_COPY_AND_ASSIGN(PortLocker); }; // Convenience wrapper for a PortLocker that locks a single port. class SinglePortLocker { public: explicit SinglePortLocker(const PortRef* port_ref); + + SinglePortLocker(const SinglePortLocker&) = delete; + SinglePortLocker& operator=(const SinglePortLocker&) = delete; + ~SinglePortLocker(); Port* port() const { return locker_.GetPort(*port_ref_); } @@ -75,8 +81,6 @@ class SinglePortLocker { private: const PortRef* port_ref_; PortLocker locker_; - - DISALLOW_COPY_AND_ASSIGN(SinglePortLocker); }; } // namespace ports diff --git a/chromium/mojo/core/ports/user_message.h b/chromium/mojo/core/ports/user_message.h index e30e316a08b..9a5e45cfc48 100644 --- a/chromium/mojo/core/ports/user_message.h +++ b/chromium/mojo/core/ports/user_message.h @@ -29,6 +29,10 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) UserMessage { struct TypeInfo {}; explicit UserMessage(const TypeInfo* type_info); + + UserMessage(const UserMessage&) = delete; + UserMessage& operator=(const UserMessage&) = delete; + virtual ~UserMessage(); const TypeInfo* type_info() const { return type_info_; } @@ -47,8 +51,6 @@ class COMPONENT_EXPORT(MOJO_CORE_PORTS) UserMessage { private: const TypeInfo* const type_info_; - - DISALLOW_COPY_AND_ASSIGN(UserMessage); }; } // namespace ports diff --git a/chromium/mojo/core/request_context.h b/chromium/mojo/core/request_context.h index 89988f27d30..9bbfc55e0b2 100644 --- a/chromium/mojo/core/request_context.h +++ b/chromium/mojo/core/request_context.h @@ -41,6 +41,10 @@ class MOJO_SYSTEM_IMPL_EXPORT RequestContext { RequestContext(); explicit RequestContext(Source source); + + RequestContext(const RequestContext&) = delete; + RequestContext& operator=(const RequestContext&) = delete; + ~RequestContext(); // Returns the current thread-local RequestContext. @@ -98,8 +102,6 @@ class MOJO_SYSTEM_IMPL_EXPORT RequestContext { // global LazyInstance, accessing a LazyInstance has a large cost relative to // the rest of this class and its usages. base::ThreadLocalPointer<RequestContext>* tls_context_; - - DISALLOW_COPY_AND_ASSIGN(RequestContext); }; } // namespace core diff --git a/chromium/mojo/core/shared_buffer_dispatcher.cc b/chromium/mojo/core/shared_buffer_dispatcher.cc index d49f4e3c726..e9bc911a2d2 100644 --- a/chromium/mojo/core/shared_buffer_dispatcher.cc +++ b/chromium/mojo/core/shared_buffer_dispatcher.cc @@ -125,6 +125,7 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize( PlatformHandle* platform_handles, size_t num_platform_handles) { if (num_bytes != sizeof(SerializedState)) { + AssertNotExtractingHandlesFromMessage(); LOG(ERROR) << "Invalid serialized shared buffer dispatcher (bad size)"; return nullptr; } @@ -132,13 +133,16 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize( const SerializedState* serialized_state = static_cast<const SerializedState*>(bytes); if (!serialized_state->num_bytes) { + AssertNotExtractingHandlesFromMessage(); LOG(ERROR) << "Invalid serialized shared buffer dispatcher (invalid num_bytes)"; return nullptr; } - if (num_ports) + if (num_ports) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } PlatformHandle handles[2]; #if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_MAC) @@ -152,8 +156,10 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize( return nullptr; } #else - if (num_platform_handles != 1) + if (num_platform_handles != 1) { + AssertNotExtractingHandlesFromMessage(); return nullptr; + } #endif handles[0] = std::move(platform_handles[0]); @@ -172,6 +178,7 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize( mode = base::subtle::PlatformSharedMemoryRegion::Mode::kUnsafe; break; default: + AssertNotExtractingHandlesFromMessage(); LOG(ERROR) << "Invalid serialized shared buffer access mode."; return nullptr; } @@ -181,6 +188,7 @@ scoped_refptr<SharedBufferDispatcher> SharedBufferDispatcher::Deserialize( std::move(handles[1])), mode, static_cast<size_t>(serialized_state->num_bytes), guid); if (!region.IsValid()) { + AssertNotExtractingHandlesFromMessage(); LOG(ERROR) << "Invalid serialized shared buffer dispatcher (invalid num_bytes?)"; return nullptr; diff --git a/chromium/mojo/core/shared_buffer_dispatcher.h b/chromium/mojo/core/shared_buffer_dispatcher.h index cbdb3533f96..e2faa0de3ad 100644 --- a/chromium/mojo/core/shared_buffer_dispatcher.h +++ b/chromium/mojo/core/shared_buffer_dispatcher.h @@ -62,6 +62,9 @@ class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher final : public Dispatcher { PlatformHandle* platform_handles, size_t num_handles); + SharedBufferDispatcher(const SharedBufferDispatcher&) = delete; + SharedBufferDispatcher& operator=(const SharedBufferDispatcher&) = delete; + // Passes the underlying PlatformSharedMemoryRegion. This dispatcher must be // closed after calling this function. base::subtle::PlatformSharedMemoryRegion PassPlatformSharedMemoryRegion(); @@ -114,8 +117,6 @@ class MOJO_SYSTEM_IMPL_EXPORT SharedBufferDispatcher final : public Dispatcher { bool in_transit_ = false; base::subtle::PlatformSharedMemoryRegion region_; - - DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcher); }; } // namespace core diff --git a/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc b/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc index 108359aeb71..84bae6bfbba 100644 --- a/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc +++ b/chromium/mojo/core/shared_buffer_dispatcher_unittest.cc @@ -46,10 +46,12 @@ void RevalidateCreateOptions( class SharedBufferDispatcherTest : public testing::Test { public: SharedBufferDispatcherTest() = default; - ~SharedBufferDispatcherTest() override = default; - private: - DISALLOW_COPY_AND_ASSIGN(SharedBufferDispatcherTest); + SharedBufferDispatcherTest(const SharedBufferDispatcherTest&) = delete; + SharedBufferDispatcherTest& operator=(const SharedBufferDispatcherTest&) = + delete; + + ~SharedBufferDispatcherTest() override = default; }; // Tests valid inputs to |ValidateCreateOptions()|. diff --git a/chromium/mojo/core/trap_unittest.cc b/chromium/mojo/core/trap_unittest.cc index 65595510930..4d755622185 100644 --- a/chromium/mojo/core/trap_unittest.cc +++ b/chromium/mojo/core/trap_unittest.cc @@ -35,6 +35,10 @@ class TriggerHelper { using ContextCallback = base::RepeatingCallback<void(const MojoTrapEvent&)>; TriggerHelper() = default; + + TriggerHelper(const TriggerHelper&) = delete; + TriggerHelper& operator=(const TriggerHelper&) = delete; + ~TriggerHelper() = default; MojoResult CreateTrap(MojoHandle* handle) { @@ -65,6 +69,9 @@ class TriggerHelper { explicit NotificationContext(const ContextCallback& callback) : callback_(callback) {} + NotificationContext(const NotificationContext&) = delete; + NotificationContext& operator=(const NotificationContext&) = delete; + ~NotificationContext() = default; void SetCancelCallback(base::OnceClosure cancel_callback) { @@ -81,30 +88,28 @@ class TriggerHelper { private: const ContextCallback callback_; base::OnceClosure cancel_callback_; - - DISALLOW_COPY_AND_ASSIGN(NotificationContext); }; static void Notify(const MojoTrapEvent* event) { reinterpret_cast<NotificationContext*>(event->trigger_context) ->Notify(*event); } - - DISALLOW_COPY_AND_ASSIGN(TriggerHelper); }; class ThreadedRunner : public base::SimpleThread { public: explicit ThreadedRunner(base::OnceClosure callback) : SimpleThread("ThreadedRunner"), callback_(std::move(callback)) {} + + ThreadedRunner(const ThreadedRunner&) = delete; + ThreadedRunner& operator=(const ThreadedRunner&) = delete; + ~ThreadedRunner() override = default; void Run() override { std::move(callback_).Run(); } private: base::OnceClosure callback_; - - DISALLOW_COPY_AND_ASSIGN(ThreadedRunner); }; void ExpectNoNotification(const MojoTrapEvent* event) { @@ -1370,7 +1375,7 @@ TEST_F(TrapTest, OtherThreadRemovesTriggerDuringEventHandler) { // Give the other thread sufficient time to race with the completion // of this callback. There should be no race, since the cancellation // notification must be mutually exclusive to this notification. - base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); + base::PlatformThread::Sleep(base::Seconds(1)); callback_done = true; }, diff --git a/chromium/mojo/core/user_message_impl.cc b/chromium/mojo/core/user_message_impl.cc index ec0686b629d..33fdbf5c204 100644 --- a/chromium/mojo/core/user_message_impl.cc +++ b/chromium/mojo/core/user_message_impl.cc @@ -284,6 +284,10 @@ class MessageMemoryDumpProvider : public base::trace_event::MemoryDumpProvider { this, "MojoMessages", nullptr); } + MessageMemoryDumpProvider(const MessageMemoryDumpProvider&) = delete; + MessageMemoryDumpProvider& operator=(const MessageMemoryDumpProvider&) = + delete; + ~MessageMemoryDumpProvider() override { base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( this); @@ -299,8 +303,6 @@ class MessageMemoryDumpProvider : public base::trace_event::MemoryDumpProvider { base::subtle::NoBarrier_Load(&g_message_count)); return true; } - - DISALLOW_COPY_AND_ASSIGN(MessageMemoryDumpProvider); }; void EnsureMemoryDumpProviderExists() { diff --git a/chromium/mojo/core/user_message_impl.h b/chromium/mojo/core/user_message_impl.h index 118f3f67270..c73b09a4f76 100644 --- a/chromium/mojo/core/user_message_impl.h +++ b/chromium/mojo/core/user_message_impl.h @@ -45,6 +45,9 @@ class MOJO_SYSTEM_IMPL_EXPORT UserMessageImpl : public ports::UserMessage { kAbort, }; + UserMessageImpl(const UserMessageImpl&) = delete; + UserMessageImpl& operator=(const UserMessageImpl&) = delete; + ~UserMessageImpl() override; // Creates a new ports::UserMessageEvent with an attached UserMessageImpl. @@ -213,8 +216,6 @@ class MOJO_SYSTEM_IMPL_EXPORT UserMessageImpl : public ports::UserMessage { // The node name from which this message was received, iff it came from // out-of-process and the source is known. ports::NodeName source_node_ = ports::kInvalidNodeName; - - DISALLOW_COPY_AND_ASSIGN(UserMessageImpl); }; } // namespace core diff --git a/chromium/mojo/core/watch.h b/chromium/mojo/core/watch.h index b2a81658332..35437f7a89b 100644 --- a/chromium/mojo/core/watch.h +++ b/chromium/mojo/core/watch.h @@ -34,6 +34,9 @@ class Watch : public base::RefCountedThreadSafe<Watch> { MojoHandleSignals signals, MojoTriggerCondition condition); + Watch(const Watch&) = delete; + Watch& operator=(const Watch&) = delete; + // Notifies the Watch of a potential state change. // // If |allowed_to_call_callback| is true, this may add a notification @@ -117,8 +120,6 @@ class Watch : public base::RefCountedThreadSafe<Watch> { // Guarded by |notification_lock_|. bool is_cancelled_ = false; - - DISALLOW_COPY_AND_ASSIGN(Watch); }; } // namespace core diff --git a/chromium/mojo/core/watcher_dispatcher.h b/chromium/mojo/core/watcher_dispatcher.h index 6a8bceda9fd..86b43eb3c4e 100644 --- a/chromium/mojo/core/watcher_dispatcher.h +++ b/chromium/mojo/core/watcher_dispatcher.h @@ -30,6 +30,9 @@ class WatcherDispatcher : public Dispatcher { // registered watch observes some relevant state change. explicit WatcherDispatcher(MojoTrapEventHandler handler); + WatcherDispatcher(const WatcherDispatcher&) = delete; + WatcherDispatcher& operator=(const WatcherDispatcher&) = delete; + // Methods used by watched dispatchers to notify watchers of events. void NotifyHandleState(Dispatcher* dispatcher, const HandleSignalsState& state); @@ -92,8 +95,6 @@ class WatcherDispatcher : public Dispatcher { // NOTE: This pointer is only used to index |ready_watches_| and may point to // an invalid object. It must therefore never be dereferenced. const Watch* last_watch_to_block_arming_ = nullptr; - - DISALLOW_COPY_AND_ASSIGN(WatcherDispatcher); }; } // namespace core diff --git a/chromium/mojo/core/watcher_set.h b/chromium/mojo/core/watcher_set.h index d85420ac00e..df3558396bb 100644 --- a/chromium/mojo/core/watcher_set.h +++ b/chromium/mojo/core/watcher_set.h @@ -24,6 +24,10 @@ class WatcherSet { public: // |owner| is the Dispatcher who owns this WatcherSet. explicit WatcherSet(Dispatcher* owner); + + WatcherSet(const WatcherSet&) = delete; + WatcherSet& operator=(const WatcherSet&) = delete; + ~WatcherSet(); // Notifies all watchers of the handle's current signals state. @@ -45,23 +49,23 @@ class WatcherSet { struct Entry { Entry(const scoped_refptr<WatcherDispatcher>& dispatcher); + + Entry(const Entry&) = delete; + Entry& operator=(const Entry&) = delete; + Entry(Entry&& other); + ~Entry(); Entry& operator=(Entry&& other); scoped_refptr<WatcherDispatcher> dispatcher; ContextSet contexts; - - private: - DISALLOW_COPY_AND_ASSIGN(Entry); }; Dispatcher* const owner_; base::flat_map<WatcherDispatcher*, Entry> watchers_; absl::optional<HandleSignalsState> last_known_state_; - - DISALLOW_COPY_AND_ASSIGN(WatcherSet); }; } // namespace core diff --git a/chromium/mojo/public/cpp/base/BUILD.gn b/chromium/mojo/public/cpp/base/BUILD.gn index 9760da63921..471a4a4151e 100644 --- a/chromium/mojo/public/cpp/base/BUILD.gn +++ b/chromium/mojo/public/cpp/base/BUILD.gn @@ -96,6 +96,8 @@ component("shared_typemap_traits") { "read_only_buffer_mojom_traits.h", "read_only_file_mojom_traits.cc", "read_only_file_mojom_traits.h", + "safe_base_name_mojom_traits.cc", + "safe_base_name_mojom_traits.h", "shared_memory_mojom_traits.cc", "shared_memory_mojom_traits.h", "time_mojom_traits.cc", @@ -130,6 +132,7 @@ source_set("tests") { "process_id_unittest.cc", "read_only_buffer_unittest.cc", "ref_counted_memory_unittest.cc", + "safe_base_name_unittest.cc", "shared_memory_unittest.cc", "string16_unittest.cc", "text_direction_unittest.cc", diff --git a/chromium/mojo/public/cpp/base/big_buffer.h b/chromium/mojo/public/cpp/base/big_buffer.h index fd3e0cbaf47..2a3a9d5ce31 100644 --- a/chromium/mojo/public/cpp/base/big_buffer.h +++ b/chromium/mojo/public/cpp/base/big_buffer.h @@ -29,6 +29,11 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBufferSharedMemoryRegion { BigBufferSharedMemoryRegion(mojo::ScopedSharedBufferHandle buffer_handle, size_t size); BigBufferSharedMemoryRegion(BigBufferSharedMemoryRegion&& other); + + BigBufferSharedMemoryRegion(const BigBufferSharedMemoryRegion&) = delete; + BigBufferSharedMemoryRegion& operator=(const BigBufferSharedMemoryRegion&) = + delete; + ~BigBufferSharedMemoryRegion(); BigBufferSharedMemoryRegion& operator=(BigBufferSharedMemoryRegion&& other); @@ -45,8 +50,6 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBufferSharedMemoryRegion { size_t size_; mojo::ScopedSharedBufferHandle buffer_handle_; mojo::ScopedSharedBufferMapping buffer_mapping_; - - DISALLOW_COPY_AND_ASSIGN(BigBufferSharedMemoryRegion); }; } // namespace internal @@ -93,6 +96,9 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBuffer { // before transfer to avoid leaking information to less privileged processes. explicit BigBuffer(size_t size); + BigBuffer(const BigBuffer&) = delete; + BigBuffer& operator=(const BigBuffer&) = delete; + ~BigBuffer(); BigBuffer& operator=(BigBuffer&& other); @@ -125,8 +131,6 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBuffer { std::unique_ptr<uint8_t[]> bytes_; size_t bytes_size_; absl::optional<internal::BigBufferSharedMemoryRegion> shared_memory_; - - DISALLOW_COPY_AND_ASSIGN(BigBuffer); }; // Similar to BigBuffer, but doesn't *necessarily* own the buffer storage. @@ -143,6 +147,10 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBufferView { // will retain an unsafe reference to |bytes| and must therefore not outlive // |bytes|. explicit BigBufferView(base::span<const uint8_t> bytes); + + BigBufferView(const BigBufferView&) = delete; + BigBufferView& operator=(const BigBufferView&) = delete; + ~BigBufferView(); BigBufferView& operator=(BigBufferView&& other); @@ -179,8 +187,6 @@ class COMPONENT_EXPORT(MOJO_BASE) BigBufferView { BigBuffer::StorageType storage_type_ = BigBuffer::StorageType::kBytes; base::span<const uint8_t> bytes_; absl::optional<internal::BigBufferSharedMemoryRegion> shared_memory_; - - DISALLOW_COPY_AND_ASSIGN(BigBufferView); }; } // namespace mojo_base diff --git a/chromium/mojo/public/cpp/base/safe_base_name_mojom_traits.cc b/chromium/mojo/public/cpp/base/safe_base_name_mojom_traits.cc new file mode 100644 index 00000000000..ddf2a2b808f --- /dev/null +++ b/chromium/mojo/public/cpp/base/safe_base_name_mojom_traits.cc @@ -0,0 +1,29 @@ +// Copyright 2021 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/base/safe_base_name_mojom_traits.h" +#include "mojo/public/cpp/base/file_path_mojom_traits.h" + +namespace mojo { + +// static +bool StructTraits<mojo_base::mojom::SafeBaseNameDataView, base::SafeBaseName>:: + Read(mojo_base::mojom::SafeBaseNameDataView data, base::SafeBaseName* out) { + base::FilePath path; + if (!data.ReadPath(&path)) + return false; + + if (path.BaseName() != path) + return false; + + auto maybe_basename = base::SafeBaseName::Create(path); + if (!maybe_basename) + return false; + + *out = *maybe_basename; + + return true; +} + +} // namespace mojo
\ No newline at end of file diff --git a/chromium/mojo/public/cpp/base/safe_base_name_mojom_traits.h b/chromium/mojo/public/cpp/base/safe_base_name_mojom_traits.h new file mode 100644 index 00000000000..aa6b81b2fd9 --- /dev/null +++ b/chromium/mojo/public/cpp/base/safe_base_name_mojom_traits.h @@ -0,0 +1,28 @@ +// Copyright 2021 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_BASE_SAFE_BASE_NAME_MOJOM_TRAITS_H_ +#define MOJO_PUBLIC_CPP_BASE_SAFE_BASE_NAME_MOJOM_TRAITS_H_ + +#include "base/component_export.h" +#include "base/files/safe_base_name.h" +#include "mojo/public/cpp/bindings/struct_traits.h" +#include "mojo/public/mojom/base/safe_base_name.mojom-shared.h" + +namespace mojo { + +template <> +struct COMPONENT_EXPORT(MOJO_BASE_SHARED_TRAITS) + StructTraits<mojo_base::mojom::SafeBaseNameDataView, base::SafeBaseName> { + static const base::FilePath& path(const base::SafeBaseName& path) { + return path.path(); + } + + static bool Read(mojo_base::mojom::SafeBaseNameDataView data, + base::SafeBaseName* out); +}; + +} // namespace mojo + +#endif // MOJO_PUBLIC_CPP_BASE_SAFE_BASE_NAME_MOJOM_TRAITS_H_ diff --git a/chromium/mojo/public/cpp/base/safe_base_name_unittest.cc b/chromium/mojo/public/cpp/base/safe_base_name_unittest.cc new file mode 100644 index 00000000000..863291b81c2 --- /dev/null +++ b/chromium/mojo/public/cpp/base/safe_base_name_unittest.cc @@ -0,0 +1,98 @@ +// Copyright 2021 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/base/safe_base_name_mojom_traits.h" +#include "mojo/public/cpp/test_support/test_utils.h" +#include "mojo/public/mojom/base/safe_base_name.mojom.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace mojo_base { + +namespace { +absl::optional<base::SafeBaseName> CreateSafeBaseName() { + return base::SafeBaseName::Create(base::FilePath()); +} +} // namespace + +TEST(SafeBaseNameTest, PathEmpty) { + absl::optional<base::SafeBaseName> basename = CreateSafeBaseName(); + absl::optional<base::SafeBaseName> basename_out = CreateSafeBaseName(); + + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::SafeBaseName>( + *basename, *basename_out)); + EXPECT_EQ(basename->path(), basename_out->path()); +} + +TEST(SafeBaseNameTest, PathContainsNoSeparators) { + absl::optional<base::SafeBaseName> basename( + base::SafeBaseName::Create(FILE_PATH_LITERAL("hello"))); + absl::optional<base::SafeBaseName> basename_out = CreateSafeBaseName(); + + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::SafeBaseName>( + *basename, *basename_out)); + EXPECT_EQ(basename->path(), basename_out->path()); +} + +TEST(SafeBaseNameTest, PathContainsSeparators) { + base::FilePath file = base::FilePath(FILE_PATH_LITERAL("hello")) + .Append(FILE_PATH_LITERAL("world")); + absl::optional<base::SafeBaseName> basename(base::SafeBaseName::Create(file)); + absl::optional<base::SafeBaseName> basename_out = CreateSafeBaseName(); + + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::SafeBaseName>( + *basename, *basename_out)); + EXPECT_EQ(basename->path(), basename_out->path()); +} + +TEST(SafeBaseNameTest, PathEndsWithSeparator) { + base::FilePath file = base::FilePath(FILE_PATH_LITERAL("hello")) + .Append(FILE_PATH_LITERAL("world")) + .AsEndingWithSeparator(); + absl::optional<base::SafeBaseName> basename(base::SafeBaseName::Create(file)); + absl::optional<base::SafeBaseName> basename_out = CreateSafeBaseName(); + + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::SafeBaseName>( + *basename, *basename_out)); + EXPECT_EQ(basename->path(), basename_out->path()); +} + +#if defined(FILE_PATH_USES_DRIVE_LETTERS) +TEST(SafeBaseNameTest, PathIsRootWin) { + mojo_base::mojom::SafeBaseNamePtr mojom_basename = + mojo_base::mojom::SafeBaseName::New(); + mojom_basename->path = base::FilePath(FILE_PATH_LITERAL("C:\\")); + absl::optional<base::SafeBaseName> basename_out = CreateSafeBaseName(); + + // Expect deserialization to fail because "C:\\ is an absolute path. See + // safe_base_name.h + ASSERT_FALSE(mojo::test::SerializeAndDeserialize<mojom::SafeBaseName>( + mojom_basename, *basename_out)); +} +#else +TEST(SafeBaseNameTest, PathIsRoot) { + mojo_base::mojom::SafeBaseNamePtr mojom_basename = + mojo_base::mojom::SafeBaseName::New(); + mojom_basename->path = base::FilePath(FILE_PATH_LITERAL("/")); + absl::optional<base::SafeBaseName> basename_out = CreateSafeBaseName(); + + // Expect deserialization to fail because "/" is an absolute path. See + // safe_base_name.h + ASSERT_FALSE(mojo::test::SerializeAndDeserialize<mojom::SafeBaseName>( + mojom_basename, *basename_out)); +} +#endif // FILE_PATH_USES_DRIVE_LETTERS + +#if defined(FILE_PATH_USES_WIN_SEPARATORS) +TEST(SafeBaseNameTest, PathIsFileInRootWin) { + absl::optional<base::SafeBaseName> basename( + base::SafeBaseName::Create(FILE_PATH_LITERAL("C:\\foo.txt"))); + absl::optional<base::SafeBaseName> basename_out = CreateSafeBaseName(); + + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::SafeBaseName>( + *basename, *basename_out)); + EXPECT_EQ(basename->path(), basename_out->path()); +} +#endif // FILE_PATH_USES_WIN_SEPARATORS + +} // namespace mojo_base
\ No newline at end of file diff --git a/chromium/mojo/public/cpp/base/time_mojom_traits.cc b/chromium/mojo/public/cpp/base/time_mojom_traits.cc index 1fc25d81440..164bec85360 100644 --- a/chromium/mojo/public/cpp/base/time_mojom_traits.cc +++ b/chromium/mojo/public/cpp/base/time_mojom_traits.cc @@ -14,8 +14,7 @@ int64_t StructTraits<mojo_base::mojom::TimeDataView, bool StructTraits<mojo_base::mojom::TimeDataView, base::Time>::Read( mojo_base::mojom::TimeDataView data, base::Time* time) { - *time = - base::Time() + base::TimeDelta::FromMicroseconds(data.internal_value()); + *time = base::Time() + base::Microseconds(data.internal_value()); return true; } @@ -28,7 +27,7 @@ StructTraits<mojo_base::mojom::TimeDeltaDataView, bool StructTraits<mojo_base::mojom::TimeDeltaDataView, base::TimeDelta>::Read( mojo_base::mojom::TimeDeltaDataView data, base::TimeDelta* delta) { - *delta = base::TimeDelta::FromMicroseconds(data.microseconds()); + *delta = base::Microseconds(data.microseconds()); return true; } @@ -41,8 +40,7 @@ StructTraits<mojo_base::mojom::TimeTicksDataView, bool StructTraits<mojo_base::mojom::TimeTicksDataView, base::TimeTicks>::Read( mojo_base::mojom::TimeTicksDataView data, base::TimeTicks* time) { - *time = base::TimeTicks() + - base::TimeDelta::FromMicroseconds(data.internal_value()); + *time = base::TimeTicks() + base::Microseconds(data.internal_value()); return true; } diff --git a/chromium/mojo/public/cpp/base/time_unittest.cc b/chromium/mojo/public/cpp/base/time_unittest.cc index fd1d230c318..f2ba5e8c909 100644 --- a/chromium/mojo/public/cpp/base/time_unittest.cc +++ b/chromium/mojo/public/cpp/base/time_unittest.cc @@ -19,7 +19,7 @@ TEST(TimeTest, Time) { } TEST(TimeTest, TimeDelta) { - base::TimeDelta in = base::TimeDelta::FromDays(123); + base::TimeDelta in = base::Days(123); base::TimeDelta out; ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::TimeDelta>(in, out)); diff --git a/chromium/mojo/public/cpp/base/values_unittest.cc b/chromium/mojo/public/cpp/base/values_unittest.cc index fddd1df9991..743d0097c1c 100644 --- a/chromium/mojo/public/cpp/base/values_unittest.cc +++ b/chromium/mojo/public/cpp/base/values_unittest.cc @@ -8,6 +8,8 @@ #include "base/test/gtest_util.h" #include "base/values.h" #include "mojo/public/cpp/base/values_mojom_traits.h" +#include "mojo/public/cpp/bindings/lib/validation_context.h" +#include "mojo/public/cpp/bindings/lib/validation_errors.h" #include "mojo/public/cpp/test_support/test_utils.h" #include "mojo/public/mojom/base/values.mojom.h" #include "testing/gtest/include/gtest/gtest.h" @@ -144,13 +146,36 @@ TEST(ValuesStructTraitsTest, SerializeInvalidListValue) { // A deeply nested base::Value should trigger a deserialization error. TEST(ValuesStructTraitsTest, DeeplyNestedValue) { base::Value in; - for (int i = 0; i < 100; ++i) { + for (int i = 0; i < kMaxRecursionDepth; ++i) { base::Value::ListStorage storage; storage.emplace_back(std::move(in)); in = base::Value(std::move(storage)); } - base::Value out; - ASSERT_FALSE(mojo::test::SerializeAndDeserialize<mojom::Value>(in, out)); + + // It should work if the depth is less than kMaxRecursionDepth. + { + mojo::internal::ValidationErrorObserverForTesting warning_observer{ + base::DoNothing()}; + base::Value out; + ASSERT_TRUE(mojo::test::SerializeAndDeserialize<mojom::Value>(in, out)); + EXPECT_EQ(mojo::internal::VALIDATION_ERROR_NONE, + warning_observer.last_error()); + } + + // Add one more depth. + base::Value::ListStorage storage; + storage.emplace_back(std::move(in)); + in = base::Value(std::move(storage)); + + // It gets VALIDATION_ERROR_MAX_RECURSION_DEPTH error. + { + mojo::internal::ValidationErrorObserverForTesting warning_observer{ + base::DoNothing()}; + base::Value out; + ASSERT_FALSE(mojo::test::SerializeAndDeserialize<mojom::Value>(in, out)); + EXPECT_EQ(mojo::internal::VALIDATION_ERROR_MAX_RECURSION_DEPTH, + warning_observer.last_error()); + } } } // namespace mojo_base diff --git a/chromium/mojo/public/cpp/bindings/BUILD.gn b/chromium/mojo/public/cpp/bindings/BUILD.gn index 13ad53b3ed3..d90318de106 100644 --- a/chromium/mojo/public/cpp/bindings/BUILD.gn +++ b/chromium/mojo/public/cpp/bindings/BUILD.gn @@ -281,7 +281,5 @@ if (!is_ios) { "//third_party/blink/renderer/platform:platform_export", "//third_party/blink/renderer/platform/wtf", ] - - public_configs = [ "//third_party/blink/renderer:config" ] } } diff --git a/chromium/mojo/public/cpp/bindings/README.md b/chromium/mojo/public/cpp/bindings/README.md index b950df5a773..334ba1c8fd9 100644 --- a/chromium/mojo/public/cpp/bindings/README.md +++ b/chromium/mojo/public/cpp/bindings/README.md @@ -1709,6 +1709,9 @@ C++ sources can depend on shared sources only, by referencing the `"${target_name}_shared"` target, e.g. `"//foo/mojom:mojom_shared"` in the example above. +For converting between Blink and non-Blink variants, please see +`//third_party/blink/public/platform/cross_variant_mojo_util.h`. + ## Versioning Considerations For general documentation of versioning in the Mojom IDL see diff --git a/chromium/mojo/public/cpp/bindings/associated_interface_ptr_info.h b/chromium/mojo/public/cpp/bindings/associated_interface_ptr_info.h index 7c4b9004f09..e1550758882 100644 --- a/chromium/mojo/public/cpp/bindings/associated_interface_ptr_info.h +++ b/chromium/mojo/public/cpp/bindings/associated_interface_ptr_info.h @@ -37,6 +37,10 @@ class AssociatedInterfacePtrInfo { uint32_t version) : handle_(std::move(handle)), version_(version) {} + AssociatedInterfacePtrInfo(const AssociatedInterfacePtrInfo&) = delete; + AssociatedInterfacePtrInfo& operator=(const AssociatedInterfacePtrInfo&) = + delete; + ~AssociatedInterfacePtrInfo() {} AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { @@ -76,8 +80,6 @@ class AssociatedInterfacePtrInfo { private: ScopedInterfaceEndpointHandle handle_; uint32_t version_; - - DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrInfo); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/associated_interface_request.h b/chromium/mojo/public/cpp/bindings/associated_interface_request.h index 6e80724a8ca..b439476852b 100644 --- a/chromium/mojo/public/cpp/bindings/associated_interface_request.h +++ b/chromium/mojo/public/cpp/bindings/associated_interface_request.h @@ -33,6 +33,10 @@ class AssociatedInterfaceRequest { explicit AssociatedInterfaceRequest(ScopedInterfaceEndpointHandle handle) : handle_(std::move(handle)) {} + AssociatedInterfaceRequest(const AssociatedInterfaceRequest&) = delete; + AssociatedInterfaceRequest& operator=(const AssociatedInterfaceRequest&) = + delete; + // Takes the interface endpoint handle from another // AssociatedInterfaceRequest. AssociatedInterfaceRequest(AssociatedInterfaceRequest&& other) { @@ -78,8 +82,6 @@ class AssociatedInterfaceRequest { private: ScopedInterfaceEndpointHandle handle_; - - DISALLOW_COPY_AND_ASSIGN(AssociatedInterfaceRequest); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/associated_remote.h b/chromium/mojo/public/cpp/bindings/associated_remote.h index 988aaef97da..67c2085e091 100644 --- a/chromium/mojo/public/cpp/bindings/associated_remote.h +++ b/chromium/mojo/public/cpp/bindings/associated_remote.h @@ -65,6 +65,9 @@ class AssociatedRemote { Bind(std::move(pending_remote), std::move(task_runner)); } + AssociatedRemote(const AssociatedRemote&) = delete; + AssociatedRemote& operator=(const AssociatedRemote&) = delete; + ~AssociatedRemote() = default; AssociatedRemote& operator=(AssociatedRemote&& other) noexcept { @@ -257,8 +260,6 @@ class AssociatedRemote { private: using State = internal::AssociatedInterfacePtrState<Interface>; mutable State internal_state_; - - DISALLOW_COPY_AND_ASSIGN(AssociatedRemote); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/callback_helpers.h b/chromium/mojo/public/cpp/bindings/callback_helpers.h index 94bc98ccda3..1bcb97d6b38 100644 --- a/chromium/mojo/public/cpp/bindings/callback_helpers.h +++ b/chromium/mojo/public/cpp/bindings/callback_helpers.h @@ -82,6 +82,9 @@ class CallbackWithDeleteHelper<void(Args...)> { : callback_(std::move(callback)), delete_callback_(std::move(delete_callback)) {} + CallbackWithDeleteHelper(const CallbackWithDeleteHelper&) = delete; + CallbackWithDeleteHelper& operator=(const CallbackWithDeleteHelper&) = delete; + ~CallbackWithDeleteHelper() { if (delete_callback_) std::move(delete_callback_).Run(); @@ -95,8 +98,6 @@ class CallbackWithDeleteHelper<void(Args...)> { private: CallbackType callback_; base::OnceClosure delete_callback_; - - DISALLOW_COPY_AND_ASSIGN(CallbackWithDeleteHelper); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/connection_group.h b/chromium/mojo/public/cpp/bindings/connection_group.h index ca3f8f210fc..273870ce8ca 100644 --- a/chromium/mojo/public/cpp/bindings/connection_group.h +++ b/chromium/mojo/public/cpp/bindings/connection_group.h @@ -85,6 +85,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ConnectionGroup static Ref Create(base::RepeatingClosure callback, scoped_refptr<base::SequencedTaskRunner> task_runner); + ConnectionGroup(const ConnectionGroup&) = delete; + ConnectionGroup& operator=(const ConnectionGroup&) = delete; + unsigned int GetNumRefsForTesting() const { return num_refs_; } private: @@ -93,6 +96,7 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ConnectionGroup ConnectionGroup(base::RepeatingClosure callback, scoped_refptr<base::SequencedTaskRunner> task_runner); + virtual ~ConnectionGroup(); void AddGroupRef(); @@ -109,8 +113,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ConnectionGroup // release, and doing that in conjunction with the RefCountedThreadSafe's own // lifetime-controlling ref count is not safely possible. std::atomic<unsigned int> num_refs_{0}; - - DISALLOW_COPY_AND_ASSIGN(ConnectionGroup); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/connector.h b/chromium/mojo/public/cpp/bindings/connector.h index 3975d01a434..c788d5adaf4 100644 --- a/chromium/mojo/public/cpp/bindings/connector.h +++ b/chromium/mojo/public/cpp/bindings/connector.h @@ -96,6 +96,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) Connector : public MessageReceiver { scoped_refptr<base::SequencedTaskRunner> runner, const char* interface_name = "unknown interface"); + Connector(const Connector&) = delete; + Connector& operator=(const Connector&) = delete; + ~Connector() override; const char* interface_name() const { return interface_name_; } @@ -358,8 +361,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) Connector : public MessageReceiver { // transferred (i.e., when |connected_| is set to false). base::WeakPtr<Connector> weak_self_; base::WeakPtrFactory<Connector> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(Connector); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/generic_pending_receiver.cc b/chromium/mojo/public/cpp/bindings/generic_pending_receiver.cc index 60bb7476f11..882f6f1cc18 100644 --- a/chromium/mojo/public/cpp/bindings/generic_pending_receiver.cc +++ b/chromium/mojo/public/cpp/bindings/generic_pending_receiver.cc @@ -5,6 +5,7 @@ #include "mojo/public/cpp/bindings/generic_pending_receiver.h" #include "base/strings/string_piece.h" +#include "base/trace_event/trace_event.h" namespace mojo { @@ -43,4 +44,9 @@ mojo::ScopedMessagePipeHandle GenericPendingReceiver::PassPipeIfNameIs( return mojo::ScopedMessagePipeHandle(); } +void GenericPendingReceiver::WriteIntoTrace(perfetto::TracedValue ctx) const { + auto dict = std::move(ctx).WriteDictionary(); + dict.Add("interface_name", interface_name_); +} + } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/generic_pending_receiver.h b/chromium/mojo/public/cpp/bindings/generic_pending_receiver.h index a7392438fc9..5e8c535f6b3 100644 --- a/chromium/mojo/public/cpp/bindings/generic_pending_receiver.h +++ b/chromium/mojo/public/cpp/bindings/generic_pending_receiver.h @@ -13,6 +13,7 @@ #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/system/message_pipe.h" #include "third_party/abseil-cpp/absl/types/optional.h" +#include "third_party/perfetto/include/perfetto/tracing/traced_value_forward.h" namespace mojo { @@ -38,6 +39,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) GenericPendingReceiver { : GenericPendingReceiver(Interface::Name_, request.PassMessagePipe()) {} GenericPendingReceiver(GenericPendingReceiver&&); + + GenericPendingReceiver(const GenericPendingReceiver&) = delete; + GenericPendingReceiver& operator=(const GenericPendingReceiver&) = delete; + ~GenericPendingReceiver(); GenericPendingReceiver& operator=(GenericPendingReceiver&&); @@ -64,13 +69,13 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) GenericPendingReceiver { return mojo::PendingReceiver<Interface>(PassPipeIfNameIs(Interface::Name_)); } + void WriteIntoTrace(perfetto::TracedValue ctx) const; + private: mojo::ScopedMessagePipeHandle PassPipeIfNameIs(const char* interface_name); absl::optional<std::string> interface_name_; mojo::ScopedMessagePipeHandle pipe_; - - DISALLOW_COPY_AND_ASSIGN(GenericPendingReceiver); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h b/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h index 68963ea1fd0..957b709a28d 100644 --- a/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h +++ b/chromium/mojo/public/cpp/bindings/interface_endpoint_client.h @@ -60,6 +60,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InterfaceEndpointClient scoped_refptr<base::SequencedTaskRunner> task_runner, uint32_t interface_version, const char* interface_name); + + InterfaceEndpointClient(const InterfaceEndpointClient&) = delete; + InterfaceEndpointClient& operator=(const InterfaceEndpointClient&) = delete; + ~InterfaceEndpointClient() override; // Sets the error handler to receive notifications when an error is @@ -217,15 +221,16 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InterfaceEndpointClient struct SyncResponseInfo { public: explicit SyncResponseInfo(bool* in_response_received); + + SyncResponseInfo(const SyncResponseInfo&) = delete; + SyncResponseInfo& operator=(const SyncResponseInfo&) = delete; + ~SyncResponseInfo(); Message response; // Points to a stack-allocated variable. bool* response_received; - - private: - DISALLOW_COPY_AND_ASSIGN(SyncResponseInfo); }; using SyncResponseMap = std::map<uint64_t, std::unique_ptr<SyncResponseInfo>>; @@ -235,6 +240,11 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InterfaceEndpointClient class HandleIncomingMessageThunk : public MessageReceiver { public: explicit HandleIncomingMessageThunk(InterfaceEndpointClient* owner); + + HandleIncomingMessageThunk(const HandleIncomingMessageThunk&) = delete; + HandleIncomingMessageThunk& operator=(const HandleIncomingMessageThunk&) = + delete; + ~HandleIncomingMessageThunk() override; // MessageReceiver implementation: @@ -242,8 +252,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InterfaceEndpointClient private: InterfaceEndpointClient* const owner_; - - DISALLOW_COPY_AND_ASSIGN(HandleIncomingMessageThunk); }; void InitControllerIfNecessary(); @@ -317,8 +325,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InterfaceEndpointClient SEQUENCE_CHECKER(sequence_checker_); base::WeakPtrFactory<InterfaceEndpointClient> weak_ptr_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(InterfaceEndpointClient); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/interface_ptr.h b/chromium/mojo/public/cpp/bindings/interface_ptr.h index 6745a32b530..311cd58eee8 100644 --- a/chromium/mojo/public/cpp/bindings/interface_ptr.h +++ b/chromium/mojo/public/cpp/bindings/interface_ptr.h @@ -77,6 +77,9 @@ class InterfacePtr { return *this; } + InterfacePtr(const InterfacePtr&) = delete; + InterfacePtr& operator=(const InterfacePtr&) = delete; + // Closes the bound message pipe (if any) on destruction. ~InterfacePtr() {} @@ -224,8 +227,6 @@ class InterfacePtr { private: typedef internal::InterfacePtrState<Interface> State; mutable State internal_state_; - - DISALLOW_COPY_AND_ASSIGN(InterfacePtr); }; // If |info| is valid (containing a valid message pipe handle), returns an diff --git a/chromium/mojo/public/cpp/bindings/interface_ptr_info.h b/chromium/mojo/public/cpp/bindings/interface_ptr_info.h index ab07923a155..632777c1c8c 100644 --- a/chromium/mojo/public/cpp/bindings/interface_ptr_info.h +++ b/chromium/mojo/public/cpp/bindings/interface_ptr_info.h @@ -33,6 +33,9 @@ class InterfacePtrInfo { InterfacePtrInfo(InterfacePtrInfo&& other) = default; + InterfacePtrInfo(const InterfacePtrInfo&) = delete; + InterfacePtrInfo& operator=(const InterfacePtrInfo&) = delete; + ~InterfacePtrInfo() {} InterfacePtrInfo& operator=(InterfacePtrInfo&& other) = default; @@ -55,8 +58,6 @@ class InterfacePtrInfo { private: internal::PendingRemoteState state_; - - DISALLOW_COPY_AND_ASSIGN(InterfacePtrInfo); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/interface_request.h b/chromium/mojo/public/cpp/bindings/interface_request.h index 89c4a2066e7..0d5698f52dd 100644 --- a/chromium/mojo/public/cpp/bindings/interface_request.h +++ b/chromium/mojo/public/cpp/bindings/interface_request.h @@ -43,6 +43,9 @@ class InterfaceRequest { explicit InterfaceRequest(ScopedMessagePipeHandle handle) : state_(std::move(handle)) {} + InterfaceRequest(const InterfaceRequest&) = delete; + InterfaceRequest& operator=(const InterfaceRequest&) = delete; + // Takes the message pipe from another InterfaceRequest. InterfaceRequest(InterfaceRequest&& other) = default; @@ -108,8 +111,6 @@ class InterfaceRequest { private: internal::PendingReceiverState state_; - - DISALLOW_COPY_AND_ASSIGN(InterfaceRequest); }; // Creates a new message pipe over which Interface is to be served. Binds the diff --git a/chromium/mojo/public/cpp/bindings/lib/binder_map_internal.h b/chromium/mojo/public/cpp/bindings/lib/binder_map_internal.h index 4200f305265..6b75f5e6df3 100644 --- a/chromium/mojo/public/cpp/bindings/lib/binder_map_internal.h +++ b/chromium/mojo/public/cpp/bindings/lib/binder_map_internal.h @@ -82,6 +82,11 @@ class GenericCallbackBinderWithContext { scoped_refptr<base::SequencedTaskRunner> task_runner) : callback_(std::move(callback)), task_runner_(std::move(task_runner)) {} + GenericCallbackBinderWithContext(const GenericCallbackBinderWithContext&) = + delete; + GenericCallbackBinderWithContext& operator=( + const GenericCallbackBinderWithContext&) = delete; + ~GenericCallbackBinderWithContext() = default; void BindInterface(ContextValueType context, @@ -123,7 +128,6 @@ class GenericCallbackBinderWithContext { const GenericBinderType callback_; const scoped_refptr<base::SequencedTaskRunner> task_runner_; - DISALLOW_COPY_AND_ASSIGN(GenericCallbackBinderWithContext); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/binding_state.h b/chromium/mojo/public/cpp/bindings/lib/binding_state.h index e111ffa5a59..25e735cdcd3 100644 --- a/chromium/mojo/public/cpp/bindings/lib/binding_state.h +++ b/chromium/mojo/public/cpp/bindings/lib/binding_state.h @@ -111,6 +111,9 @@ class BindingState : public BindingStateBase { stub_.set_sink(std::move(impl)); } + BindingState(const BindingState&) = delete; + BindingState& operator=(const BindingState&) = delete; + ~BindingState() { Close(); } void Bind(PendingReceiverState* receiver_state, @@ -139,8 +142,6 @@ class BindingState : public BindingStateBase { private: typename Interface::template Stub_<ImplRefTraits> stub_; - - DISALLOW_COPY_AND_ASSIGN(BindingState); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/buffer.cc b/chromium/mojo/public/cpp/bindings/lib/buffer.cc index da524c52be4..ca50210d620 100644 --- a/chromium/mojo/public/cpp/bindings/lib/buffer.cc +++ b/chromium/mojo/public/cpp/bindings/lib/buffer.cc @@ -89,7 +89,7 @@ size_t Buffer::Allocate(size_t num_bytes) { return block_start; } -void Buffer::AttachHandles(std::vector<ScopedHandle>* handles) { +bool Buffer::AttachHandles(std::vector<ScopedHandle>* handles) { DCHECK(message_.is_valid()); uint32_t new_size = 0; @@ -97,11 +97,13 @@ void Buffer::AttachHandles(std::vector<ScopedHandle>* handles) { message_.value(), 0, reinterpret_cast<MojoHandle*>(handles->data()), static_cast<uint32_t>(handles->size()), nullptr, &data_, &new_size); if (rv != MOJO_RESULT_OK) - return; + return false; size_ = new_size; for (auto& handle : *handles) ignore_result(handle.release()); + handles->clear(); + return true; } void Buffer::Seal() { diff --git a/chromium/mojo/public/cpp/bindings/lib/buffer.h b/chromium/mojo/public/cpp/bindings/lib/buffer.h index 9f2a7684906..3536af93c36 100644 --- a/chromium/mojo/public/cpp/bindings/lib/buffer.h +++ b/chromium/mojo/public/cpp/bindings/lib/buffer.h @@ -10,6 +10,7 @@ #include <vector> +#include "base/compiler_specific.h" #include "base/component_export.h" #include "base/macros.h" #include "mojo/public/cpp/system/handle.h" @@ -52,6 +53,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) Buffer { size_t size); Buffer(Buffer&& other); + + Buffer(const Buffer&) = delete; + Buffer& operator=(const Buffer&) = delete; + ~Buffer(); Buffer& operator=(Buffer&& other); @@ -93,7 +98,7 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) Buffer { // Serializes |handles| into the buffer object. Only valid to call when this // Buffer is backed by a message object. - void AttachHandles(std::vector<ScopedHandle>* handles); + bool AttachHandles(std::vector<ScopedHandle>* handles) WARN_UNUSED_RESULT; // Seals this Buffer so it can no longer be used for allocation, and ensures // the backing message object has a complete accounting of the size of the @@ -121,8 +126,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) Buffer { // The current write offset into |data_| if this Buffer is being used for // message creation. size_t cursor_ = 0; - - DISALLOW_COPY_AND_ASSIGN(Buffer); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/connector.cc b/chromium/mojo/public/cpp/bindings/lib/connector.cc index 92a9756cbae..c1d111c126a 100644 --- a/chromium/mojo/public/cpp/bindings/lib/connector.cc +++ b/chromium/mojo/public/cpp/bindings/lib/connector.cc @@ -66,6 +66,10 @@ bool EnableTaskPerMessage() { class Connector::ActiveDispatchTracker { public: explicit ActiveDispatchTracker(const base::WeakPtr<Connector>& connector); + + ActiveDispatchTracker(const ActiveDispatchTracker&) = delete; + ActiveDispatchTracker& operator=(const ActiveDispatchTracker&) = delete; + ~ActiveDispatchTracker(); void NotifyBeginNesting(); @@ -75,8 +79,6 @@ class Connector::ActiveDispatchTracker { RunLoopNestingObserver* const nesting_observer_; ActiveDispatchTracker* outer_tracker_ = nullptr; ActiveDispatchTracker* inner_tracker_ = nullptr; - - DISALLOW_COPY_AND_ASSIGN(ActiveDispatchTracker); }; // Watches the MessageLoop on the current thread. Notifies the current chain of @@ -88,6 +90,9 @@ class Connector::RunLoopNestingObserver base::RunLoop::AddNestingObserverOnCurrentThread(this); } + RunLoopNestingObserver(const RunLoopNestingObserver&) = delete; + RunLoopNestingObserver& operator=(const RunLoopNestingObserver&) = delete; + ~RunLoopNestingObserver() override { base::RunLoop::RemoveNestingObserverOnCurrentThread(this); } @@ -113,8 +118,6 @@ class Connector::RunLoopNestingObserver friend class ActiveDispatchTracker; ActiveDispatchTracker* top_tracker_ = nullptr; - - DISALLOW_COPY_AND_ASSIGN(RunLoopNestingObserver); }; Connector::ActiveDispatchTracker::ActiveDispatchTracker( diff --git a/chromium/mojo/public/cpp/bindings/lib/control_message_handler.cc b/chromium/mojo/public/cpp/bindings/lib/control_message_handler.cc index 3cbf6007350..36e7b380f84 100644 --- a/chromium/mojo/public/cpp/bindings/lib/control_message_handler.cc +++ b/chromium/mojo/public/cpp/bindings/lib/control_message_handler.cc @@ -140,7 +140,7 @@ bool ControlMessageHandler::RunOrClosePipe(Message* message) { if (input.is_require_version()) return interface_version_ >= input.get_require_version()->version; if (input.is_enable_idle_tracking()) { - return owner_->AcceptEnableIdleTracking(base::TimeDelta::FromMicroseconds( + return owner_->AcceptEnableIdleTracking(base::Microseconds( input.get_enable_idle_tracking()->timeout_in_microseconds)); } if (input.is_message_ack()) diff --git a/chromium/mojo/public/cpp/bindings/lib/control_message_handler.h b/chromium/mojo/public/cpp/bindings/lib/control_message_handler.h index aee16cbd3e2..cc9bf19e3c0 100644 --- a/chromium/mojo/public/cpp/bindings/lib/control_message_handler.h +++ b/chromium/mojo/public/cpp/bindings/lib/control_message_handler.h @@ -25,6 +25,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ControlMessageHandler ControlMessageHandler(InterfaceEndpointClient* owner, uint32_t interface_version); + + ControlMessageHandler(const ControlMessageHandler&) = delete; + ControlMessageHandler& operator=(const ControlMessageHandler&) = delete; + ~ControlMessageHandler() override; // Call the following methods only if IsControlMessage() returned true. @@ -40,8 +44,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ControlMessageHandler InterfaceEndpointClient* const owner_; uint32_t interface_version_; - - DISALLOW_COPY_AND_ASSIGN(ControlMessageHandler); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.cc b/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.cc index 57b61edc862..956a11cf572 100644 --- a/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.cc +++ b/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.cc @@ -50,11 +50,15 @@ class RunResponseForwardToCallback : public MessageReceiver { public: explicit RunResponseForwardToCallback(RunCallback callback) : callback_(std::move(callback)) {} + + RunResponseForwardToCallback(const RunResponseForwardToCallback&) = delete; + RunResponseForwardToCallback& operator=(const RunResponseForwardToCallback&) = + delete; + bool Accept(Message* message) override; private: RunCallback callback_; - DISALLOW_COPY_AND_ASSIGN(RunResponseForwardToCallback); }; bool RunResponseForwardToCallback::Accept(Message* message) { diff --git a/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.h b/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.h index b6d7cc89622..6d766e3fc03 100644 --- a/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.h +++ b/chromium/mojo/public/cpp/bindings/lib/control_message_proxy.h @@ -26,6 +26,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ControlMessageProxy { public: // Doesn't take ownership of |owner|. It must outlive this object. explicit ControlMessageProxy(InterfaceEndpointClient* owner); + + ControlMessageProxy(const ControlMessageProxy&) = delete; + ControlMessageProxy& operator=(const ControlMessageProxy&) = delete; + ~ControlMessageProxy(); void QueryVersion(base::OnceCallback<void(uint32_t)> callback); @@ -48,8 +52,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ControlMessageProxy { bool encountered_error_ = false; base::OnceClosure pending_flush_callback_; - - DISALLOW_COPY_AND_ASSIGN(ControlMessageProxy); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc b/chromium/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc index 4e8d1c3c6d2..a9dfb632c09 100644 --- a/chromium/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc +++ b/chromium/mojo/public/cpp/bindings/lib/interface_endpoint_client.cc @@ -233,6 +233,10 @@ class ResponderThunk : public MessageReceiverWithStatus { : endpoint_client_(endpoint_client), accept_was_invoked_(false), task_runner_(std::move(runner)) {} + + ResponderThunk(const ResponderThunk&) = delete; + ResponderThunk& operator=(const ResponderThunk&) = delete; + ~ResponderThunk() override { if (!accept_was_invoked_) { // The Service handled a message that was expecting a response @@ -301,8 +305,6 @@ class ResponderThunk : public MessageReceiverWithStatus { bool accept_was_invoked_; scoped_refptr<base::SequencedTaskRunner> task_runner_; ConnectionGroup::Ref connection_group_; - - DISALLOW_COPY_AND_ASSIGN(ResponderThunk); }; } // namespace 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 f43f651ba7b..606a85b02e7 100644 --- a/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.h +++ b/chromium/mojo/public/cpp/bindings/lib/interface_ptr_state.h @@ -40,6 +40,10 @@ namespace internal { class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InterfacePtrStateBase { public: InterfacePtrStateBase(); + + InterfacePtrStateBase(const InterfacePtrStateBase&) = delete; + InterfacePtrStateBase& operator=(const InterfacePtrStateBase&) = delete; + ~InterfacePtrStateBase(); MessagePipeHandle handle() const { @@ -115,8 +119,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InterfacePtrStateBase { scoped_refptr<base::SequencedTaskRunner> runner_; uint32_t version_ = 0; - - DISALLOW_COPY_AND_ASSIGN(InterfacePtrStateBase); }; template <typename Interface> @@ -125,6 +127,10 @@ class InterfacePtrState : public InterfacePtrStateBase { using Proxy = typename Interface::Proxy_; InterfacePtrState() = default; + + InterfacePtrState(const InterfacePtrState&) = delete; + InterfacePtrState& operator=(const InterfacePtrState&) = delete; + ~InterfacePtrState() = default; Proxy* instance() { @@ -256,8 +262,6 @@ class InterfacePtrState : public InterfacePtrStateBase { } std::unique_ptr<Proxy> proxy_; - - DISALLOW_COPY_AND_ASSIGN(InterfacePtrState); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/may_auto_lock.h b/chromium/mojo/public/cpp/bindings/lib/may_auto_lock.h index 96fb8d2bd97..bcd913df534 100644 --- a/chromium/mojo/public/cpp/bindings/lib/may_auto_lock.h +++ b/chromium/mojo/public/cpp/bindings/lib/may_auto_lock.h @@ -23,6 +23,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MayAutoLock { lock_->Acquire(); } + MayAutoLock(const MayAutoLock&) = delete; + MayAutoLock& operator=(const MayAutoLock&) = delete; + ~MayAutoLock() { if (lock_) { lock_->AssertAcquired(); @@ -32,7 +35,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MayAutoLock { private: base::Lock* lock_; - DISALLOW_COPY_AND_ASSIGN(MayAutoLock); }; // Similar to base::AutoUnlock, except that it does nothing if |lock| passed @@ -47,6 +49,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MayAutoUnlock { } } + MayAutoUnlock(const MayAutoUnlock&) = delete; + MayAutoUnlock& operator=(const MayAutoUnlock&) = delete; + ~MayAutoUnlock() { if (lock_) lock_->Acquire(); @@ -54,7 +59,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MayAutoUnlock { private: base::Lock* lock_; - DISALLOW_COPY_AND_ASSIGN(MayAutoUnlock); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/message.cc b/chromium/mojo/public/cpp/bindings/lib/message.cc index 7c8f2e293e0..b34680704c8 100644 --- a/chromium/mojo/public/cpp/bindings/lib/message.cc +++ b/chromium/mojo/public/cpp/bindings/lib/message.cc @@ -107,7 +107,8 @@ void CreateSerializedMessageObject(uint32_t name, handles ? reinterpret_cast<MojoHandle*>(handles->data()) : nullptr, handles ? static_cast<uint32_t>(handles->size()) : 0, nullptr, &buffer, &buffer_size); - DCHECK_EQ(MOJO_RESULT_OK, rv); + // TODO(crbug.com/1239934): Relax this assertion or fail more gracefully. + CHECK_EQ(MOJO_RESULT_OK, rv); if (handles) { // Handle ownership has been taken by MojoAppendMessageData. for (size_t i = 0; i < handles->size(); ++i) @@ -266,7 +267,10 @@ Message::Message(base::span<const uint8_t> payload, handle_->value(), static_cast<uint32_t>(payload.size()), reinterpret_cast<MojoHandle*>(handles.data()), static_cast<uint32_t>(handles.size()), &options, &buffer, &buffer_size); - DCHECK_EQ(MOJO_RESULT_OK, rv); + + // TODO(crbug.com/1239934): Relax this assertion or fail more gracefully. + CHECK_EQ(MOJO_RESULT_OK, rv); + // Handle ownership has been taken by MojoAppendMessageData. for (auto& handle : handles) ignore_result(handle.release()); @@ -423,7 +427,11 @@ void Message::SerializeHandles(AssociatedGroupController* group_controller) { if (mutable_associated_endpoint_handles()->empty()) { // Attaching only non-associated handles is easier since we don't have to // modify the message header. Faster path for that. - payload_buffer_.AttachHandles(mutable_handles()); + bool attached = payload_buffer_.AttachHandles(mutable_handles()); + + // TODO(crbug.com/1239934): Relax this assertion or fail more gracefully. + CHECK(attached); + return; } diff --git a/chromium/mojo/public/cpp/bindings/lib/message_internal.h b/chromium/mojo/public/cpp/bindings/lib/message_internal.h index 1703786e05a..f35e95c563f 100644 --- a/chromium/mojo/public/cpp/bindings/lib/message_internal.h +++ b/chromium/mojo/public/cpp/bindings/lib/message_internal.h @@ -59,6 +59,10 @@ static_assert(sizeof(MessageHeaderV2) == 48, "Bad sizeof(MessageHeaderV2)"); class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MessageDispatchContext { public: explicit MessageDispatchContext(Message* message); + + MessageDispatchContext(const MessageDispatchContext&) = delete; + MessageDispatchContext& operator=(const MessageDispatchContext&) = delete; + ~MessageDispatchContext(); static MessageDispatchContext* current(); @@ -68,8 +72,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MessageDispatchContext { private: MessageDispatchContext* outer_context_; Message* message_; - - DISALLOW_COPY_AND_ASSIGN(MessageDispatchContext); }; COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) 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 40cb6c0c65d..61e9aeae9bc 100644 --- a/chromium/mojo/public/cpp/bindings/lib/message_quota_checker.h +++ b/chromium/mojo/public/cpp/bindings/lib/message_quota_checker.h @@ -56,8 +56,7 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MessageQuotaChecker double GetDecayedRateAverage(base::TimeTicks when) const; // The length of a sampling interval in seconds. - static constexpr base::TimeDelta kSamplingInterval = - base::TimeDelta::FromSeconds(5); + static constexpr base::TimeDelta kSamplingInterval = base::Seconds(5); // Returns the start of the sampling interval after the interval that // |when| falls into. diff --git a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc index 605e51344d6..e62252a1399 100644 --- a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc +++ b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.cc @@ -45,6 +45,9 @@ class MultiplexRouter::InterfaceEndpoint handle_created_(false), client_(nullptr) {} + InterfaceEndpoint(const InterfaceEndpoint&) = delete; + InterfaceEndpoint& operator=(const InterfaceEndpoint&) = delete; + // --------------------------------------------------------------------------- // The following public methods are safe to call from any sequence without // locking. @@ -247,8 +250,6 @@ class MultiplexRouter::InterfaceEndpoint // Guarded by the router's lock. Used to synchronously wait on replies. std::unique_ptr<SequenceLocalSyncEventWatcher> sync_watcher_; base::flat_set<uint64_t> requests_with_external_sync_waiter_; - - DISALLOW_COPY_AND_ASSIGN(InterfaceEndpoint); }; // MessageWrapper objects are always destroyed under the router's lock. On @@ -264,6 +265,9 @@ class MultiplexRouter::MessageWrapper { MessageWrapper(MessageWrapper&& other) : router_(other.router_), value_(std::move(other.value_)) {} + MessageWrapper(const MessageWrapper&) = delete; + MessageWrapper& operator=(const MessageWrapper&) = delete; + ~MessageWrapper() { if (!router_ || value_.IsNull()) return; @@ -300,8 +304,6 @@ class MultiplexRouter::MessageWrapper { private: MultiplexRouter* router_ = nullptr; Message value_; - - DISALLOW_COPY_AND_ASSIGN(MessageWrapper); }; struct MultiplexRouter::Task { diff --git a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h index 3d3bbb16e25..df94c8a6e9d 100644 --- a/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h +++ b/chromium/mojo/public/cpp/bindings/lib/multiplex_router.h @@ -111,6 +111,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MultiplexRouter scoped_refptr<base::SequencedTaskRunner> runner, const char* primary_interface_name = "unknown interface"); + MultiplexRouter(const MultiplexRouter&) = delete; + MultiplexRouter& operator=(const MultiplexRouter&) = delete; + // Sets a MessageReceiver which can filter a message after validation but // before dispatch. void SetIncomingMessageFilter(std::unique_ptr<MessageFilter> filter); @@ -357,8 +360,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MultiplexRouter bool testing_mode_ = false; bool being_destructed_ = false; - - DISALLOW_COPY_AND_ASSIGN(MultiplexRouter); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc b/chromium/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc index 874d6d52c6b..dd8b94ec6e9 100644 --- a/chromium/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc +++ b/chromium/mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.cc @@ -25,6 +25,9 @@ class ScopedInterfaceEndpointHandle::State scoped_refptr<AssociatedGroupController> group_controller) : id_(id), group_controller_(group_controller) {} + State(const State&) = delete; + State& operator=(const State&) = delete; + void InitPendingState(scoped_refptr<State> peer) { DCHECK(!lock_); DCHECK(!pending_association_); @@ -276,8 +279,6 @@ class ScopedInterfaceEndpointHandle::State InterfaceId id_ = kInvalidInterfaceId; scoped_refptr<AssociatedGroupController> group_controller_; - - DISALLOW_COPY_AND_ASSIGN(State); }; // ScopedInterfaceEndpointHandle ----------------------------------------------- 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 03ff19e3a9b..15577287609 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 @@ -36,14 +36,15 @@ using WatcherStateMap = struct WatcherState : public base::RefCounted<WatcherState> { WatcherState() = default; + WatcherState(const WatcherState&) = delete; + WatcherState& operator=(const WatcherState&) = delete; + bool watcher_was_destroyed = false; private: friend class base::RefCounted<WatcherState>; ~WatcherState() = default; - - DISALLOW_COPY_AND_ASSIGN(WatcherState); }; } // namespace @@ -67,6 +68,9 @@ class SequenceLocalSyncEventWatcher::SequenceLocalState { event_watcher_.AllowWokenUpBySyncWatchOnSameThread(); } + SequenceLocalState(const SequenceLocalState&) = delete; + SequenceLocalState& operator=(const SequenceLocalState&) = delete; + ~SequenceLocalState() {} // Initializes a SequenceLocalState instance in sequence-local storage if @@ -196,8 +200,6 @@ class SequenceLocalSyncEventWatcher::SequenceLocalState { base::flat_set<const SequenceLocalSyncEventWatcher*> ready_watchers_; base::WeakPtrFactory<SequenceLocalState> weak_ptr_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(SequenceLocalState); }; void SequenceLocalSyncEventWatcher::SequenceLocalState::OnEventSignaled() { @@ -235,6 +237,9 @@ class SequenceLocalSyncEventWatcher::Registration { watcher_state_iterator_(shared_state_->RegisterWatcher(watcher)), watcher_state_(watcher_state_iterator_->second) {} + Registration(const Registration&) = delete; + Registration& operator=(const Registration&) = delete; + ~Registration() { if (weak_shared_state_) { // Because |this| may itself be owned by sequence- or thread-local storage @@ -257,8 +262,6 @@ class SequenceLocalSyncEventWatcher::Registration { SequenceLocalState* const shared_state_; WatcherStateMap::iterator watcher_state_iterator_; const scoped_refptr<WatcherState> watcher_state_; - - DISALLOW_COPY_AND_ASSIGN(Registration); }; SequenceLocalSyncEventWatcher::SequenceLocalSyncEventWatcher( diff --git a/chromium/mojo/public/cpp/bindings/lib/sync_call_restrictions.cc b/chromium/mojo/public/cpp/bindings/lib/sync_call_restrictions.cc index 45103aff08b..fbc73a508e7 100644 --- a/chromium/mojo/public/cpp/bindings/lib/sync_call_restrictions.cc +++ b/chromium/mojo/public/cpp/bindings/lib/sync_call_restrictions.cc @@ -22,6 +22,10 @@ namespace { class GlobalSyncCallSettings { public: GlobalSyncCallSettings() = default; + + GlobalSyncCallSettings(const GlobalSyncCallSettings&) = delete; + GlobalSyncCallSettings& operator=(const GlobalSyncCallSettings&) = delete; + ~GlobalSyncCallSettings() = default; bool sync_call_allowed_by_default() const { @@ -37,8 +41,6 @@ class GlobalSyncCallSettings { private: mutable base::Lock lock_; bool sync_call_allowed_by_default_ = true; - - DISALLOW_COPY_AND_ASSIGN(GlobalSyncCallSettings); }; GlobalSyncCallSettings& GetGlobalSettings() { diff --git a/chromium/mojo/public/cpp/bindings/lib/test_random_mojo_delays.cc b/chromium/mojo/public/cpp/bindings/lib/test_random_mojo_delays.cc index 55afb4184db..9d75fa290a9 100644 --- a/chromium/mojo/public/cpp/bindings/lib/test_random_mojo_delays.cc +++ b/chromium/mojo/public/cpp/bindings/lib/test_random_mojo_delays.cc @@ -25,10 +25,8 @@ namespace internal { namespace { constexpr int kInverseProbabilityOfDelay = 8; constexpr int kInverseProbabilityOfNotResuming = 10; -constexpr base::TimeDelta kMillisecondsToResume = - base::TimeDelta::FromMilliseconds(2); -constexpr base::TimeDelta kPauseBindingsFrequency = - base::TimeDelta::FromMilliseconds(7); +constexpr base::TimeDelta kMillisecondsToResume = base::Milliseconds(2); +constexpr base::TimeDelta kPauseBindingsFrequency = base::Milliseconds(7); } // namespace // TODO(mpdenton) This only adds random delays on method call processing. This diff --git a/chromium/mojo/public/cpp/bindings/lib/unserialized_message_context.h b/chromium/mojo/public/cpp/bindings/lib/unserialized_message_context.h index baac62045a9..188baab3833 100644 --- a/chromium/mojo/public/cpp/bindings/lib/unserialized_message_context.h +++ b/chromium/mojo/public/cpp/bindings/lib/unserialized_message_context.h @@ -23,6 +23,11 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) UnserializedMessageContext { UnserializedMessageContext(const Tag* tag, uint32_t message_name, uint32_t message_flags); + + UnserializedMessageContext(const UnserializedMessageContext&) = delete; + UnserializedMessageContext& operator=(const UnserializedMessageContext&) = + delete; + virtual ~UnserializedMessageContext(); template <typename MessageType> @@ -50,8 +55,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) UnserializedMessageContext { // Message implementation which needs to query such metadata for both // serialized and unserialized message objects. MessageHeaderV1 header_; - - DISALLOW_COPY_AND_ASSIGN(UnserializedMessageContext); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/validate_params.h b/chromium/mojo/public/cpp/bindings/lib/validate_params.h index c0ee8e02a74..540cbd9bbac 100644 --- a/chromium/mojo/public/cpp/bindings/lib/validate_params.h +++ b/chromium/mojo/public/cpp/bindings/lib/validate_params.h @@ -49,6 +49,9 @@ class ContainerValidateParams { : expected_num_elements(in_expected_num_elements), validate_enum_func(in_validate_enum_func) {} + ContainerValidateParams(const ContainerValidateParams&) = delete; + ContainerValidateParams& operator=(const ContainerValidateParams&) = delete; + ~ContainerValidateParams() { if (element_validate_params) delete element_validate_params; @@ -77,9 +80,6 @@ class ContainerValidateParams { // Validation function for enum elements. ValidateEnumFunc validate_enum_func = nullptr; - - private: - DISALLOW_COPY_AND_ASSIGN(ContainerValidateParams); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/validation_context.h b/chromium/mojo/public/cpp/bindings/lib/validation_context.h index a0e8a034082..2584c2635f9 100644 --- a/chromium/mojo/public/cpp/bindings/lib/validation_context.h +++ b/chromium/mojo/public/cpp/bindings/lib/validation_context.h @@ -56,6 +56,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ValidationContext { const char* description, ValidatorType validator_type); + ValidationContext(const ValidationContext&) = delete; + ValidationContext& operator=(const ValidationContext&) = delete; + ~ValidationContext(); // Claims the specified memory range. @@ -134,12 +137,13 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ValidationContext { ++ctx_->stack_depth_; } + ScopedDepthTracker(const ScopedDepthTracker&) = delete; + ScopedDepthTracker& operator=(const ScopedDepthTracker&) = delete; + ~ScopedDepthTracker() { --ctx_->stack_depth_; } private: ValidationContext* ctx_; - - DISALLOW_COPY_AND_ASSIGN(ScopedDepthTracker); }; // Returns true if the recursion depth limit has been reached. @@ -174,8 +178,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ValidationContext { uint32_t associated_endpoint_handle_end_; int stack_depth_; - - DISALLOW_COPY_AND_ASSIGN(ValidationContext); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/bindings/lib/validation_errors.h b/chromium/mojo/public/cpp/bindings/lib/validation_errors.h index e7fc8713b84..e451d8507d3 100644 --- a/chromium/mojo/public/cpp/bindings/lib/validation_errors.h +++ b/chromium/mojo/public/cpp/bindings/lib/validation_errors.h @@ -99,12 +99,16 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ScopedSuppressValidationErrorLoggingForTests { public: ScopedSuppressValidationErrorLoggingForTests(); + + ScopedSuppressValidationErrorLoggingForTests( + const ScopedSuppressValidationErrorLoggingForTests&) = delete; + ScopedSuppressValidationErrorLoggingForTests& operator=( + const ScopedSuppressValidationErrorLoggingForTests&) = delete; + ~ScopedSuppressValidationErrorLoggingForTests(); private: const bool was_suppressed_; - - DISALLOW_COPY_AND_ASSIGN(ScopedSuppressValidationErrorLoggingForTests); }; // Only used by validation tests and when there is only one thread doing message @@ -113,6 +117,12 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ValidationErrorObserverForTesting { public: explicit ValidationErrorObserverForTesting(base::RepeatingClosure callback); + + ValidationErrorObserverForTesting(const ValidationErrorObserverForTesting&) = + delete; + ValidationErrorObserverForTesting& operator=( + const ValidationErrorObserverForTesting&) = delete; + ~ValidationErrorObserverForTesting(); ValidationError last_error() const { return last_error_; } @@ -124,8 +134,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) private: ValidationError last_error_; base::RepeatingClosure callback_; - - DISALLOW_COPY_AND_ASSIGN(ValidationErrorObserverForTesting); }; // Used only by MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING. Don't use it directly. @@ -141,6 +149,12 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) SerializationWarningObserverForTesting { public: SerializationWarningObserverForTesting(); + + SerializationWarningObserverForTesting( + const SerializationWarningObserverForTesting&) = delete; + SerializationWarningObserverForTesting& operator=( + const SerializationWarningObserverForTesting&) = delete; + ~SerializationWarningObserverForTesting(); ValidationError last_warning() const { return last_warning_; } @@ -148,8 +162,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) private: ValidationError last_warning_; - - DISALLOW_COPY_AND_ASSIGN(SerializationWarningObserverForTesting); }; // Used to record that Deserialize() of a Mojo string failed because it was not diff --git a/chromium/mojo/public/cpp/bindings/lib/validation_util.h b/chromium/mojo/public/cpp/bindings/lib/validation_util.h index a321d37349f..d38d4b2cb94 100644 --- a/chromium/mojo/public/cpp/bindings/lib/validation_util.h +++ b/chromium/mojo/public/cpp/bindings/lib/validation_util.h @@ -184,8 +184,6 @@ template <typename T> bool ValidateContainer(const Pointer<T>& input, ValidationContext* validation_context, const ContainerValidateParams* validate_params) { - ValidationContext::ScopedDepthTracker depth_tracker(validation_context); - return ValidateParams(input, validation_context) && T::Validate(input.Get(), validation_context, validate_params); } @@ -202,7 +200,6 @@ bool ValidateStruct(const Pointer<T>& input, template <typename T> bool ValidateInlinedUnion(const T& input, ValidationContext* validation_context) { - ValidationContext::ScopedDepthTracker depth_tracker(validation_context); if (validation_context->ExceedsMaxDepth()) { ReportValidationError(validation_context, VALIDATION_ERROR_MAX_RECURSION_DEPTH); @@ -214,8 +211,6 @@ bool ValidateInlinedUnion(const T& input, template <typename T> bool ValidateNonInlinedUnion(const Pointer<T>& input, ValidationContext* validation_context) { - ValidationContext::ScopedDepthTracker depth_tracker(validation_context); - return ValidateParams(input, validation_context) && T::Validate(input.Get(), validation_context, false); } diff --git a/chromium/mojo/public/cpp/bindings/message.h b/chromium/mojo/public/cpp/bindings/message.h index 70723f6eccd..52b0d76513a 100644 --- a/chromium/mojo/public/cpp/bindings/message.h +++ b/chromium/mojo/public/cpp/bindings/message.h @@ -104,6 +104,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) Message { // calling IsNull() on it will return |true|). static Message CreateFromMessageHandle(ScopedMessageHandle* message_handle); + Message(const Message&) = delete; + Message& operator=(const Message&) = delete; + ~Message(); // Moves |other| into a new Message object. The moved-from Message becomes @@ -297,8 +300,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) Message { const char* interface_name_ = nullptr; const char* method_name_ = nullptr; #endif - - DISALLOW_COPY_AND_ASSIGN(Message); }; class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) MessageFilter { @@ -381,13 +382,14 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) PassThroughFilter : public MessageReceiver { public: PassThroughFilter(); + + PassThroughFilter(const PassThroughFilter&) = delete; + PassThroughFilter& operator=(const PassThroughFilter&) = delete; + ~PassThroughFilter() override; // MessageReceiver: bool Accept(Message* message) override; - - private: - DISALLOW_COPY_AND_ASSIGN(PassThroughFilter); }; // Reports the currently dispatching Message as bad. Note that this is only diff --git a/chromium/mojo/public/cpp/bindings/message_dispatcher.h b/chromium/mojo/public/cpp/bindings/message_dispatcher.h index a279418f6d4..7dc8dffcc54 100644 --- a/chromium/mojo/public/cpp/bindings/message_dispatcher.h +++ b/chromium/mojo/public/cpp/bindings/message_dispatcher.h @@ -26,6 +26,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MessageDispatcher MessageDispatcher(MessageDispatcher&& other); MessageDispatcher& operator=(MessageDispatcher&& other); + + MessageDispatcher(const MessageDispatcher&) = delete; + MessageDispatcher& operator=(const MessageDispatcher&) = delete; + ~MessageDispatcher() override; void SetValidator(std::unique_ptr<MessageReceiver> validator); @@ -45,8 +49,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) MessageDispatcher MessageReceiver* sink_; base::WeakPtrFactory<MessageDispatcher> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(MessageDispatcher); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/pending_associated_receiver.h b/chromium/mojo/public/cpp/bindings/pending_associated_receiver.h index fb6837c9bdf..69fffe9d6eb 100644 --- a/chromium/mojo/public/cpp/bindings/pending_associated_receiver.h +++ b/chromium/mojo/public/cpp/bindings/pending_associated_receiver.h @@ -59,6 +59,10 @@ class PendingAssociatedReceiver { std::move(other))) {} #endif // !defined(OS_NACL) + PendingAssociatedReceiver(const PendingAssociatedReceiver&) = delete; + PendingAssociatedReceiver& operator=(const PendingAssociatedReceiver&) = + delete; + ~PendingAssociatedReceiver() = default; PendingAssociatedReceiver& operator=(PendingAssociatedReceiver&& other) { @@ -121,8 +125,6 @@ class PendingAssociatedReceiver { private: ScopedInterfaceEndpointHandle handle_; - - DISALLOW_COPY_AND_ASSIGN(PendingAssociatedReceiver); }; // Constructs an invalid PendingAssociatedReceiver of any arbitrary interface diff --git a/chromium/mojo/public/cpp/bindings/pending_associated_remote.h b/chromium/mojo/public/cpp/bindings/pending_associated_remote.h index bb68431e3eb..72ee1cccccf 100644 --- a/chromium/mojo/public/cpp/bindings/pending_associated_remote.h +++ b/chromium/mojo/public/cpp/bindings/pending_associated_remote.h @@ -59,6 +59,9 @@ class PendingAssociatedRemote { std::move(other))) {} #endif // !defined(OS_NACL) + PendingAssociatedRemote(const PendingAssociatedRemote&) = delete; + PendingAssociatedRemote& operator=(const PendingAssociatedRemote&) = delete; + ~PendingAssociatedRemote() = default; PendingAssociatedRemote& operator=(PendingAssociatedRemote&& other) { @@ -118,8 +121,6 @@ class PendingAssociatedRemote { private: ScopedInterfaceEndpointHandle handle_; uint32_t version_ = 0; - - DISALLOW_COPY_AND_ASSIGN(PendingAssociatedRemote); }; // Constructs an invalid PendingAssociatedRemote of any arbitrary interface diff --git a/chromium/mojo/public/cpp/bindings/pending_receiver.h b/chromium/mojo/public/cpp/bindings/pending_receiver.h index 9ca1d24d8b3..108bb794616 100644 --- a/chromium/mojo/public/cpp/bindings/pending_receiver.h +++ b/chromium/mojo/public/cpp/bindings/pending_receiver.h @@ -80,6 +80,9 @@ class PendingReceiver { std::forward<T>(other))) {} #endif // !defined(OS_NACL) + PendingReceiver(const PendingReceiver&) = delete; + PendingReceiver& operator=(const PendingReceiver&) = delete; + ~PendingReceiver() = default; PendingReceiver& operator=(PendingReceiver&&) noexcept = default; @@ -144,8 +147,6 @@ class PendingReceiver { private: internal::PendingReceiverState state_; - - DISALLOW_COPY_AND_ASSIGN(PendingReceiver); }; class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) NullReceiver { diff --git a/chromium/mojo/public/cpp/bindings/pending_remote.h b/chromium/mojo/public/cpp/bindings/pending_remote.h index d6448cb4e18..aec4e89eecb 100644 --- a/chromium/mojo/public/cpp/bindings/pending_remote.h +++ b/chromium/mojo/public/cpp/bindings/pending_remote.h @@ -81,6 +81,9 @@ class PendingRemote { std::move(other))) {} #endif // !defined(OS_NACL) + PendingRemote(const PendingRemote&) = delete; + PendingRemote& operator=(const PendingRemote&) = delete; + ~PendingRemote() = default; PendingRemote& operator=(PendingRemote&&) noexcept = default; @@ -129,8 +132,6 @@ class PendingRemote { private: internal::PendingRemoteState state_; - - DISALLOW_COPY_AND_ASSIGN(PendingRemote); }; class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) NullRemote { diff --git a/chromium/mojo/public/cpp/bindings/pipe_control_message_handler.h b/chromium/mojo/public/cpp/bindings/pipe_control_message_handler.h index bf2bd781cfe..7ce1ab39a05 100644 --- a/chromium/mojo/public/cpp/bindings/pipe_control_message_handler.h +++ b/chromium/mojo/public/cpp/bindings/pipe_control_message_handler.h @@ -22,6 +22,11 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) PipeControlMessageHandler public: explicit PipeControlMessageHandler( PipeControlMessageHandlerDelegate* delegate); + + PipeControlMessageHandler(const PipeControlMessageHandler&) = delete; + PipeControlMessageHandler& operator=(const PipeControlMessageHandler&) = + delete; + ~PipeControlMessageHandler() override; // Sets the description for this handler. Used only when reporting validation @@ -46,8 +51,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) PipeControlMessageHandler std::string description_; PipeControlMessageHandlerDelegate* const delegate_; - - DISALLOW_COPY_AND_ASSIGN(PipeControlMessageHandler); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/pipe_control_message_proxy.h b/chromium/mojo/public/cpp/bindings/pipe_control_message_proxy.h index 18f60c98637..38a2f06d060 100644 --- a/chromium/mojo/public/cpp/bindings/pipe_control_message_proxy.h +++ b/chromium/mojo/public/cpp/bindings/pipe_control_message_proxy.h @@ -27,6 +27,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) PipeControlMessageProxy { // be used from multiple sequences, |receiver| must be thread-safe. explicit PipeControlMessageProxy(MessageReceiver* receiver); + PipeControlMessageProxy(const PipeControlMessageProxy&) = delete; + PipeControlMessageProxy& operator=(const PipeControlMessageProxy&) = delete; + void NotifyPeerEndpointClosed(InterfaceId id, const absl::optional<DisconnectReason>& reason); void PausePeerUntilFlushCompletes(PendingFlush flush); @@ -39,8 +42,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) PipeControlMessageProxy { private: // Not owned. MessageReceiver* receiver_; - - DISALLOW_COPY_AND_ASSIGN(PipeControlMessageProxy); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/receiver.h b/chromium/mojo/public/cpp/bindings/receiver.h index 87818aa0e61..acb9d5c892b 100644 --- a/chromium/mojo/public/cpp/bindings/receiver.h +++ b/chromium/mojo/public/cpp/bindings/receiver.h @@ -74,6 +74,9 @@ class Receiver { Bind(std::move(pending_receiver), std::move(task_runner)); } + Receiver(const Receiver&) = delete; + Receiver& operator=(const Receiver&) = delete; + ~Receiver() = default; // Indicates whether this Receiver is bound, meaning it may continue to @@ -301,8 +304,6 @@ class Receiver { private: internal::BindingState<Interface, ImplRefTraits> internal_state_; - - DISALLOW_COPY_AND_ASSIGN(Receiver); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/receiver_set.cc b/chromium/mojo/public/cpp/bindings/receiver_set.cc index 38dc3cc2174..35ccc1790f5 100644 --- a/chromium/mojo/public/cpp/bindings/receiver_set.cc +++ b/chromium/mojo/public/cpp/bindings/receiver_set.cc @@ -107,6 +107,17 @@ bool ReceiverSetState::Remove(ReceiverId id) { return true; } +bool ReceiverSetState::RemoveWithReason(ReceiverId id, + uint32_t custom_reason_code, + const std::string& description) { + auto it = entries_.find(id); + if (it == entries_.end()) + return false; + it->second->receiver().ResetWithReason(custom_reason_code, description); + entries_.erase(it); + return true; +} + void ReceiverSetState::FlushForTesting() { // We avoid flushing while iterating over |entries_| because this set may be // mutated during individual flush operations. Instead, snapshot the diff --git a/chromium/mojo/public/cpp/bindings/receiver_set.h b/chromium/mojo/public/cpp/bindings/receiver_set.h index 16de0e656b7..b8388a8fcf9 100644 --- a/chromium/mojo/public/cpp/bindings/receiver_set.h +++ b/chromium/mojo/public/cpp/bindings/receiver_set.h @@ -65,6 +65,8 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ReceiverSetState { std::unique_ptr<MessageFilter> filter, RepeatingConnectionErrorWithReasonCallback disconnect_handler) = 0; virtual void FlushForTesting() = 0; + virtual void ResetWithReason(uint32_t custom_reason_code, + const std::string& description) = 0; }; class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) Entry { @@ -116,6 +118,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ReceiverSetState { ReportBadMessageCallback GetBadMessageCallback(); ReceiverId Add(std::unique_ptr<ReceiverState> receiver); bool Remove(ReceiverId id); + bool RemoveWithReason(ReceiverId id, + uint32_t custom_reason_code, + const std::string& description); void FlushForTesting(); void SetDispatchContext(const void* context, ReceiverId receiver_id); void OnDisconnect(ReceiverId id, @@ -232,6 +237,12 @@ class ReceiverSetBase { // disconnected. No further messages or disconnection notifications will be // scheduled or executed for the removed receiver. bool Remove(ReceiverId id) { return state_.Remove(id); } + // Similar to the method above, but also specifies a disconnect reason. + bool RemoveWithReason(ReceiverId id, + uint32_t custom_reason_code, + const std::string& description) { + return state_.RemoveWithReason(id, custom_reason_code, description); + } // Unbinds and takes all receivers in this set. std::vector<PendingType> TakeReceivers() { @@ -250,6 +261,14 @@ class ReceiverSetBase { // ReceiverSet will not schedule or execute any further method invocations or // disconnection notifications until a new receiver is added to the set. void Clear() { state_.entries().clear(); } + // Similar to the method above, but also specifies a disconnect reason. + void ClearWithReason(uint32_t custom_reason_code, + const std::string& description) { + for (auto& entry : state_.entries()) + entry.second->receiver().ResetWithReason(custom_reason_code, description); + + Clear(); + } // Predicate to test if a receiver exists in the set. // @@ -355,6 +374,11 @@ class ReceiverSetBase { void FlushForTesting() override { receiver_.FlushForTesting(); } + void ResetWithReason(uint32_t custom_reason_code, + const std::string& description) override { + receiver_.ResetWithReason(custom_reason_code, description); + } + ImplPointerType SwapImplForTesting(ImplPointerType new_impl) { return receiver_.SwapImplForTesting(std::move(new_impl)); } diff --git a/chromium/mojo/public/cpp/bindings/remote.h b/chromium/mojo/public/cpp/bindings/remote.h index b7a614f6396..2691bad5d58 100644 --- a/chromium/mojo/public/cpp/bindings/remote.h +++ b/chromium/mojo/public/cpp/bindings/remote.h @@ -84,6 +84,9 @@ class Remote { Bind(std::move(pending_remote), std::move(task_runner)); } + Remote(const Remote&) = delete; + Remote& operator=(const Remote&) = delete; + ~Remote() = default; Remote& operator=(Remote&& other) noexcept { @@ -385,8 +388,6 @@ class Remote { private: using State = internal::InterfacePtrState<Interface>; mutable State internal_state_; - - DISALLOW_COPY_AND_ASSIGN(Remote); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/remote_set.h b/chromium/mojo/public/cpp/bindings/remote_set.h index 3426704c8fe..a6697047984 100644 --- a/chromium/mojo/public/cpp/bindings/remote_set.h +++ b/chromium/mojo/public/cpp/bindings/remote_set.h @@ -88,6 +88,10 @@ class RemoteSetImpl { }; RemoteSetImpl() = default; + + RemoteSetImpl(const RemoteSetImpl&) = delete; + RemoteSetImpl& operator=(const RemoteSetImpl&) = delete; + ~RemoteSetImpl() = default; // Adds a new remote to this set and returns a unique ID that can be used to @@ -166,8 +170,6 @@ class RemoteSetImpl { RemoteSetElementId::Generator remote_set_element_id_generator_; Storage storage_; DisconnectHandler disconnect_handler_; - - DISALLOW_COPY_AND_ASSIGN(RemoteSetImpl); }; template <typename Interface> diff --git a/chromium/mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h b/chromium/mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h index 78a6313de16..a3a8e9031f0 100644 --- a/chromium/mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h +++ b/chromium/mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h @@ -37,6 +37,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ScopedInterfaceEndpointHandle { ScopedInterfaceEndpointHandle(ScopedInterfaceEndpointHandle&& other); + ScopedInterfaceEndpointHandle(const ScopedInterfaceEndpointHandle&) = delete; + ScopedInterfaceEndpointHandle& operator=( + const ScopedInterfaceEndpointHandle&) = delete; + ~ScopedInterfaceEndpointHandle(); ScopedInterfaceEndpointHandle& operator=( @@ -113,8 +117,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS_BASE) ScopedInterfaceEndpointHandle { CreateGroupControllerGetter() const; scoped_refptr<State> state_; - - DISALLOW_COPY_AND_ASSIGN(ScopedInterfaceEndpointHandle); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/sequence_local_sync_event_watcher.h b/chromium/mojo/public/cpp/bindings/sequence_local_sync_event_watcher.h index 5994f8f844c..c32a5425e31 100644 --- a/chromium/mojo/public/cpp/bindings/sequence_local_sync_event_watcher.h +++ b/chromium/mojo/public/cpp/bindings/sequence_local_sync_event_watcher.h @@ -31,6 +31,11 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SequenceLocalSyncEventWatcher { public: explicit SequenceLocalSyncEventWatcher( const base::RepeatingClosure& callback); + + SequenceLocalSyncEventWatcher(const SequenceLocalSyncEventWatcher&) = delete; + SequenceLocalSyncEventWatcher& operator=( + const SequenceLocalSyncEventWatcher&) = delete; + ~SequenceLocalSyncEventWatcher(); // Signals the shared event on behalf of this specific watcher. Safe to call @@ -60,8 +65,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SequenceLocalSyncEventWatcher { const std::unique_ptr<Registration> registration_; const base::RepeatingClosure callback_; bool can_wake_up_during_any_watch_ = false; - - DISALLOW_COPY_AND_ASSIGN(SequenceLocalSyncEventWatcher); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/service_factory.h b/chromium/mojo/public/cpp/bindings/service_factory.h index 59595219e2f..ba3f7a30eda 100644 --- a/chromium/mojo/public/cpp/bindings/service_factory.h +++ b/chromium/mojo/public/cpp/bindings/service_factory.h @@ -71,6 +71,10 @@ struct ServiceFactoryTraits; class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ServiceFactory { public: ServiceFactory(); + + ServiceFactory(const ServiceFactory&) = delete; + ServiceFactory& operator=(const ServiceFactory&) = delete; + ~ServiceFactory(); // Adds a new service to the factory. The argument may be any function that @@ -105,6 +109,10 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ServiceFactory { class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) InstanceHolderBase { public: InstanceHolderBase(); + + InstanceHolderBase(const InstanceHolderBase&) = delete; + InstanceHolderBase& operator=(const InstanceHolderBase&) = delete; + virtual ~InstanceHolderBase(); void WatchPipe(MessagePipeHandle pipe, @@ -115,8 +123,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ServiceFactory { SimpleWatcher watcher_; base::OnceClosure disconnect_callback_; - - DISALLOW_COPY_AND_ASSIGN(InstanceHolderBase); }; template <typename Interface> @@ -124,12 +130,14 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ServiceFactory { public: explicit InstanceHolder(std::unique_ptr<Interface> instance) : instance_(std::move(instance)) {} + + InstanceHolder(const InstanceHolder&) = delete; + InstanceHolder& operator=(const InstanceHolder&) = delete; + ~InstanceHolder() override = default; private: const std::unique_ptr<Interface> instance_; - - DISALLOW_COPY_AND_ASSIGN(InstanceHolder); }; template <typename Func> @@ -155,8 +163,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) ServiceFactory { instances_; base::WeakPtrFactory<ServiceFactory> weak_ptr_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(ServiceFactory); }; namespace internal { diff --git a/chromium/mojo/public/cpp/bindings/shared_remote.h b/chromium/mojo/public/cpp/bindings/shared_remote.h index 15f5ff397e9..a1dbd176b60 100644 --- a/chromium/mojo/public/cpp/bindings/shared_remote.h +++ b/chromium/mojo/public/cpp/bindings/shared_remote.h @@ -54,14 +54,16 @@ class ThreadSafeForwarder : public internal::ThreadSafeForwarderBase { // method. explicit ThreadSafeForwarder(scoped_refptr<ThreadSafeProxy> thread_safe_proxy) : ThreadSafeForwarderBase(std::move(thread_safe_proxy)), proxy_(this) {} + + ThreadSafeForwarder(const ThreadSafeForwarder&) = delete; + ThreadSafeForwarder& operator=(const ThreadSafeForwarder&) = delete; + ~ThreadSafeForwarder() override = default; ProxyType& proxy() { return proxy_; } private: ProxyType proxy_; - - DISALLOW_COPY_AND_ASSIGN(ThreadSafeForwarder); }; template <typename Interface> @@ -108,6 +110,9 @@ class SharedRemoteBase remote_(std::move(remote), task_runner_), associated_group_(*remote_.internal_state()->associated_group()) {} + RemoteWrapper(const RemoteWrapper&) = delete; + RemoteWrapper& operator=(const RemoteWrapper&) = delete; + std::unique_ptr<ThreadSafeForwarder<InterfaceType>> CreateForwarder() { return std::make_unique<ThreadSafeForwarder<InterfaceType>>( remote_.internal_state()->CreateThreadSafeProxy( @@ -189,8 +194,6 @@ class SharedRemoteBase const scoped_refptr<base::SequencedTaskRunner> task_runner_; RemoteType remote_; AssociatedGroup associated_group_; - - DISALLOW_COPY_AND_ASSIGN(RemoteWrapper); }; struct RemoteWrapperDeleter { @@ -219,10 +222,11 @@ class SharedRemoteBase DISALLOW_COPY_AND_ASSIGN(SharedRemoteBase); }; -// SharedRemote wraps a non-thread-safe Remote and proxies messages to it. -// Unlike normal Remote objects, SharedRemote is copyable and usable from any -// thread, but has some additional overhead and latency in message transmission -// as a trade-off. +// SharedRemote wraps a non-thread-safe Remote and proxies messages to it. Note +// that SharedRemote itself is also NOT THREAD-SAFE, but unlike Remote it IS +// copyable cross-thread, and each copy is usable from its own thread. The +// trade-off compared to a Remote is some additional overhead and latency in +// message transmission, as sending a message usually incurs a task hop. // // Async calls are posted to the bound sequence (the sequence that the // underlying Remote is bound to, i.e. |bind_task_runner| below), and responses diff --git a/chromium/mojo/public/cpp/bindings/struct_ptr.h b/chromium/mojo/public/cpp/bindings/struct_ptr.h index 5d8875c8933..3f7dc2e2d00 100644 --- a/chromium/mojo/public/cpp/bindings/struct_ptr.h +++ b/chromium/mojo/public/cpp/bindings/struct_ptr.h @@ -43,6 +43,9 @@ class StructPtr { StructPtr() = default; StructPtr(std::nullptr_t) {} + StructPtr(const StructPtr&) = delete; + StructPtr& operator=(const StructPtr&) = delete; + ~StructPtr() = default; StructPtr& operator=(std::nullptr_t) { @@ -124,8 +127,6 @@ class StructPtr { } std::unique_ptr<Struct> ptr_; - - DISALLOW_COPY_AND_ASSIGN(StructPtr); }; // Designed to be used when Struct is small and copyable. @@ -141,6 +142,9 @@ class InlinedStructPtr { InlinedStructPtr() = default; InlinedStructPtr(std::nullptr_t) {} + InlinedStructPtr(const InlinedStructPtr&) = delete; + InlinedStructPtr& operator=(const InlinedStructPtr&) = delete; + ~InlinedStructPtr() = default; InlinedStructPtr& operator=(std::nullptr_t) { @@ -232,8 +236,6 @@ class InlinedStructPtr { mutable Struct value_; State state_ = NIL; - - DISALLOW_COPY_AND_ASSIGN(InlinedStructPtr); }; namespace internal { diff --git a/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h b/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h index fc4142741f7..986469b5c09 100644 --- a/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h +++ b/chromium/mojo/public/cpp/bindings/sync_call_restrictions.h @@ -67,6 +67,10 @@ class ScopedAllowSyncCallForTesting; // the current sequence during its lifetime. class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncCallRestrictions { public: + SyncCallRestrictions() = delete; + SyncCallRestrictions(const SyncCallRestrictions&) = delete; + SyncCallRestrictions& operator=(const SyncCallRestrictions&) = delete; + #if ENABLE_SYNC_CALL_RESTRICTIONS // Checks whether the current sequence is allowed to make sync calls, and // causes a DCHECK if not. @@ -134,28 +138,31 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncCallRestrictions { class ScopedAllowSyncCall { public: ScopedAllowSyncCall() { IncreaseScopedAllowCount(); } + + ScopedAllowSyncCall(const ScopedAllowSyncCall&) = delete; + ScopedAllowSyncCall& operator=(const ScopedAllowSyncCall&) = delete; + ~ScopedAllowSyncCall() { DecreaseScopedAllowCount(); } private: #if ENABLE_SYNC_CALL_RESTRICTIONS base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_wait_; #endif - - DISALLOW_COPY_AND_ASSIGN(ScopedAllowSyncCall); }; - - DISALLOW_IMPLICIT_CONSTRUCTORS(SyncCallRestrictions); }; class ScopedAllowSyncCallForTesting { public: ScopedAllowSyncCallForTesting() {} + + ScopedAllowSyncCallForTesting(const ScopedAllowSyncCallForTesting&) = delete; + ScopedAllowSyncCallForTesting& operator=( + const ScopedAllowSyncCallForTesting&) = delete; + ~ScopedAllowSyncCallForTesting() {} private: SyncCallRestrictions::ScopedAllowSyncCall scoped_allow_sync_call_; - - DISALLOW_COPY_AND_ASSIGN(ScopedAllowSyncCallForTesting); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/sync_event_watcher.h b/chromium/mojo/public/cpp/bindings/sync_event_watcher.h index 3d722048a74..6f5375cad39 100644 --- a/chromium/mojo/public/cpp/bindings/sync_event_watcher.h +++ b/chromium/mojo/public/cpp/bindings/sync_event_watcher.h @@ -26,6 +26,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncEventWatcher { public: SyncEventWatcher(base::WaitableEvent* event, base::RepeatingClosure callback); + SyncEventWatcher(const SyncEventWatcher&) = delete; + SyncEventWatcher& operator=(const SyncEventWatcher&) = delete; + ~SyncEventWatcher(); // Registers |event_| with SyncHandleRegistry, so that when others perform @@ -65,8 +68,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncEventWatcher { scoped_refptr<base::RefCountedData<bool>> destroyed_; SEQUENCE_CHECKER(sequence_checker_); - - DISALLOW_COPY_AND_ASSIGN(SyncEventWatcher); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h b/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h index 5ed7e7b827e..1099aea47b1 100644 --- a/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h +++ b/chromium/mojo/public/cpp/bindings/sync_handle_watcher.h @@ -33,6 +33,9 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncHandleWatcher { MojoHandleSignals handle_signals, const SyncHandleRegistry::HandleCallback& callback); + SyncHandleWatcher(const SyncHandleWatcher&) = delete; + SyncHandleWatcher& operator=(const SyncHandleWatcher&) = delete; + ~SyncHandleWatcher(); // Registers |handle_| with SyncHandleRegistry, so that when others perform @@ -66,8 +69,6 @@ class COMPONENT_EXPORT(MOJO_CPP_BINDINGS) SyncHandleWatcher { scoped_refptr<base::RefCountedData<bool>> destroyed_; SEQUENCE_CHECKER(sequence_checker_); - - DISALLOW_COPY_AND_ASSIGN(SyncHandleWatcher); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/platform/named_platform_channel.h b/chromium/mojo/public/cpp/platform/named_platform_channel.h index 6faad4e56ce..f84b98cf0cf 100644 --- a/chromium/mojo/public/cpp/platform/named_platform_channel.h +++ b/chromium/mojo/public/cpp/platform/named_platform_channel.h @@ -66,6 +66,10 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) NamedPlatformChannel { NamedPlatformChannel(const Options& options); NamedPlatformChannel(NamedPlatformChannel&& other); + + NamedPlatformChannel(const NamedPlatformChannel&) = delete; + NamedPlatformChannel& operator=(const NamedPlatformChannel&) = delete; + ~NamedPlatformChannel(); NamedPlatformChannel& operator=(NamedPlatformChannel&& other); @@ -114,8 +118,6 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) NamedPlatformChannel { ServerName server_name_; PlatformChannelServerEndpoint server_endpoint_; - - DISALLOW_COPY_AND_ASSIGN(NamedPlatformChannel); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/platform/platform_channel.h b/chromium/mojo/public/cpp/platform/platform_channel.h index bf13b9c5e65..ee65fdb4d23 100644 --- a/chromium/mojo/public/cpp/platform/platform_channel.h +++ b/chromium/mojo/public/cpp/platform/platform_channel.h @@ -51,6 +51,10 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannel { PlatformChannel(); PlatformChannel(PlatformChannel&& other); + + PlatformChannel(const PlatformChannel&) = delete; + PlatformChannel& operator=(const PlatformChannel&) = delete; + ~PlatformChannel(); PlatformChannel& operator=(PlatformChannel&& other); @@ -114,8 +118,6 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannel { private: PlatformChannelEndpoint local_endpoint_; PlatformChannelEndpoint remote_endpoint_; - - DISALLOW_COPY_AND_ASSIGN(PlatformChannel); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/platform/platform_channel_endpoint.h b/chromium/mojo/public/cpp/platform/platform_channel_endpoint.h index 36812be7ff6..b97e896e144 100644 --- a/chromium/mojo/public/cpp/platform/platform_channel_endpoint.h +++ b/chromium/mojo/public/cpp/platform/platform_channel_endpoint.h @@ -20,6 +20,10 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannelEndpoint { PlatformChannelEndpoint(); PlatformChannelEndpoint(PlatformChannelEndpoint&& other); explicit PlatformChannelEndpoint(PlatformHandle handle); + + PlatformChannelEndpoint(const PlatformChannelEndpoint&) = delete; + PlatformChannelEndpoint& operator=(const PlatformChannelEndpoint&) = delete; + ~PlatformChannelEndpoint(); PlatformChannelEndpoint& operator=(PlatformChannelEndpoint&& other); @@ -36,8 +40,6 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannelEndpoint { private: PlatformHandle handle_; - - DISALLOW_COPY_AND_ASSIGN(PlatformChannelEndpoint); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/platform/platform_channel_server_endpoint.h b/chromium/mojo/public/cpp/platform/platform_channel_server_endpoint.h index f80d9e3b686..7fffc60de13 100644 --- a/chromium/mojo/public/cpp/platform/platform_channel_server_endpoint.h +++ b/chromium/mojo/public/cpp/platform/platform_channel_server_endpoint.h @@ -20,6 +20,11 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannelServerEndpoint { PlatformChannelServerEndpoint(); PlatformChannelServerEndpoint(PlatformChannelServerEndpoint&& other); explicit PlatformChannelServerEndpoint(PlatformHandle handle); + + PlatformChannelServerEndpoint(const PlatformChannelServerEndpoint&) = delete; + PlatformChannelServerEndpoint& operator=( + const PlatformChannelServerEndpoint&) = delete; + ~PlatformChannelServerEndpoint(); PlatformChannelServerEndpoint& operator=( @@ -37,8 +42,6 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformChannelServerEndpoint { private: PlatformHandle handle_; - - DISALLOW_COPY_AND_ASSIGN(PlatformChannelServerEndpoint); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/platform/platform_handle.h b/chromium/mojo/public/cpp/platform/platform_handle.h index 504ffd53db3..088e75f398e 100644 --- a/chromium/mojo/public/cpp/platform/platform_handle.h +++ b/chromium/mojo/public/cpp/platform/platform_handle.h @@ -71,6 +71,9 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformHandle { explicit PlatformHandle(base::ScopedFD fd); #endif + PlatformHandle(const PlatformHandle&) = delete; + PlatformHandle& operator=(const PlatformHandle&) = delete; + ~PlatformHandle(); PlatformHandle& operator=(PlatformHandle&& other); @@ -228,8 +231,6 @@ class COMPONENT_EXPORT(MOJO_CPP_PLATFORM) PlatformHandle { #if defined(OS_POSIX) || defined(OS_FUCHSIA) base::ScopedFD fd_; #endif - - DISALLOW_COPY_AND_ASSIGN(PlatformHandle); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/README.md b/chromium/mojo/public/cpp/system/README.md index 20e73dfc882..9a77597624d 100644 --- a/chromium/mojo/public/cpp/system/README.md +++ b/chromium/mojo/public/cpp/system/README.md @@ -369,7 +369,7 @@ wait_set.AddEvent(&timeout_event); // Ensure the Wait() lasts no more than 5 seconds. bg_thread->task_runner()->PostDelayedTask(FROM_HERE, base::BindOnce([](base::WaitableEvent* e) { e->Signal(); }, &timeout_event); - base::TimeDelta::FromSeconds(5)); + base::Seconds(5)); base::WaitableEvent* ready_event = nullptr; size_t num_ready_handles = 1; diff --git a/chromium/mojo/public/cpp/system/data_pipe_drainer.h b/chromium/mojo/public/cpp/system/data_pipe_drainer.h index 949c9d13dd2..23f78efdb79 100644 --- a/chromium/mojo/public/cpp/system/data_pipe_drainer.h +++ b/chromium/mojo/public/cpp/system/data_pipe_drainer.h @@ -27,6 +27,10 @@ class MOJO_CPP_SYSTEM_EXPORT DataPipeDrainer { }; DataPipeDrainer(Client*, mojo::ScopedDataPipeConsumerHandle source); + + DataPipeDrainer(const DataPipeDrainer&) = delete; + DataPipeDrainer& operator=(const DataPipeDrainer&) = delete; + ~DataPipeDrainer(); private: @@ -38,8 +42,6 @@ class MOJO_CPP_SYSTEM_EXPORT DataPipeDrainer { mojo::SimpleWatcher handle_watcher_; base::WeakPtrFactory<DataPipeDrainer> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(DataPipeDrainer); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/data_pipe_producer.cc b/chromium/mojo/public/cpp/system/data_pipe_producer.cc index bb474ca29df..a8349efa8ab 100644 --- a/chromium/mojo/public/cpp/system/data_pipe_producer.cc +++ b/chromium/mojo/public/cpp/system/data_pipe_producer.cc @@ -50,6 +50,9 @@ class DataPipeProducer::SequenceState producer_handle_(std::move(producer_handle)), callback_(std::move(callback)) {} + SequenceState(const SequenceState&) = delete; + SequenceState& operator=(const SequenceState&) = delete; + void Cancel() { base::AutoLock lock(lock_); is_cancelled_ = true; @@ -171,8 +174,6 @@ class DataPipeProducer::SequenceState base::Lock lock_; bool is_cancelled_ GUARDED_BY(lock_) = false; - - DISALLOW_COPY_AND_ASSIGN(SequenceState); }; DataPipeProducer::DataPipeProducer(ScopedDataPipeProducerHandle producer) diff --git a/chromium/mojo/public/cpp/system/data_pipe_producer.h b/chromium/mojo/public/cpp/system/data_pipe_producer.h index 557c116f8ba..4ffa1d88285 100644 --- a/chromium/mojo/public/cpp/system/data_pipe_producer.h +++ b/chromium/mojo/public/cpp/system/data_pipe_producer.h @@ -59,6 +59,10 @@ class MOJO_CPP_SYSTEM_EXPORT DataPipeProducer { // Constructs a new DataPipeProducer which will write data to |producer|. explicit DataPipeProducer(ScopedDataPipeProducerHandle producer); + + DataPipeProducer(const DataPipeProducer&) = delete; + DataPipeProducer& operator=(const DataPipeProducer&) = delete; + ~DataPipeProducer(); // Attempts to eventually write all of |data_source|'s contents to the pipe. @@ -97,8 +101,6 @@ class MOJO_CPP_SYSTEM_EXPORT DataPipeProducer { ScopedDataPipeProducerHandle producer_; scoped_refptr<SequenceState> sequence_state_; base::WeakPtrFactory<DataPipeProducer> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(DataPipeProducer); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/file_data_source.h b/chromium/mojo/public/cpp/system/file_data_source.h index 02a7bf3fda5..0cd9399505f 100644 --- a/chromium/mojo/public/cpp/system/file_data_source.h +++ b/chromium/mojo/public/cpp/system/file_data_source.h @@ -21,6 +21,10 @@ class MOJO_CPP_SYSTEM_EXPORT FileDataSource final static MojoResult ConvertFileErrorToMojoResult(base::File::Error error); FileDataSource(base::File file); + + FileDataSource(const FileDataSource&) = delete; + FileDataSource& operator=(const FileDataSource&) = delete; + ~FileDataSource() override; // |end| should be greater than or equal to |start|. Otherwise subsequent @@ -36,8 +40,6 @@ class MOJO_CPP_SYSTEM_EXPORT FileDataSource final MojoResult error_; uint64_t start_offset_; uint64_t end_offset_; - - DISALLOW_COPY_AND_ASSIGN(FileDataSource); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/filtered_data_source.h b/chromium/mojo/public/cpp/system/filtered_data_source.h index 74c228c23cb..1dac2d895ff 100644 --- a/chromium/mojo/public/cpp/system/filtered_data_source.h +++ b/chromium/mojo/public/cpp/system/filtered_data_source.h @@ -44,6 +44,10 @@ class MOJO_CPP_SYSTEM_EXPORT FilteredDataSource final FilteredDataSource(std::unique_ptr<DataPipeProducer::DataSource> source, std::unique_ptr<Filter> filter); + + FilteredDataSource(const FilteredDataSource&) = delete; + FilteredDataSource& operator=(const FilteredDataSource&) = delete; + ~FilteredDataSource() override; private: @@ -54,8 +58,6 @@ class MOJO_CPP_SYSTEM_EXPORT FilteredDataSource final std::unique_ptr<DataPipeProducer::DataSource> source_; std::unique_ptr<Filter> filter_; - - DISALLOW_COPY_AND_ASSIGN(FilteredDataSource); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/handle.h b/chromium/mojo/public/cpp/system/handle.h index a0bd46ba2aa..bc473ca9aff 100644 --- a/chromium/mojo/public/cpp/system/handle.h +++ b/chromium/mojo/public/cpp/system/handle.h @@ -77,6 +77,10 @@ class ScopedHandleBase { ScopedHandleBase() {} explicit ScopedHandleBase(HandleType handle) : handle_(handle) {} + + ScopedHandleBase(const ScopedHandleBase&) = delete; + ScopedHandleBase& operator=(const ScopedHandleBase&) = delete; + ~ScopedHandleBase() { CloseIfNecessary(); } template <class CompatibleHandleType> @@ -138,8 +142,6 @@ class ScopedHandleBase { } HandleType handle_; - - DISALLOW_COPY_AND_ASSIGN(ScopedHandleBase); }; template <typename HandleType> diff --git a/chromium/mojo/public/cpp/system/handle_signal_tracker.h b/chromium/mojo/public/cpp/system/handle_signal_tracker.h index 7f4913b0522..94e1e5188e5 100644 --- a/chromium/mojo/public/cpp/system/handle_signal_tracker.h +++ b/chromium/mojo/public/cpp/system/handle_signal_tracker.h @@ -37,6 +37,10 @@ class MOJO_CPP_SYSTEM_EXPORT HandleSignalTracker { MojoHandleSignals signals, scoped_refptr<base::SequencedTaskRunner> task_runner = base::SequencedTaskRunnerHandle::Get()); + + HandleSignalTracker(const HandleSignalTracker&) = delete; + HandleSignalTracker& operator=(const HandleSignalTracker&) = delete; + ~HandleSignalTracker(); const HandleSignalsState& last_known_state() const { @@ -67,8 +71,6 @@ class MOJO_CPP_SYSTEM_EXPORT HandleSignalTracker { // Watches for the signal(s) to be cleared. May only be armed when // |high_watcher_| is not. SimpleWatcher low_watcher_; - - DISALLOW_COPY_AND_ASSIGN(HandleSignalTracker); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/invitation.h b/chromium/mojo/public/cpp/system/invitation.h index 5191a097a44..05d657f0cb1 100644 --- a/chromium/mojo/public/cpp/system/invitation.h +++ b/chromium/mojo/public/cpp/system/invitation.h @@ -56,6 +56,10 @@ class MOJO_CPP_SYSTEM_EXPORT OutgoingInvitation { public: OutgoingInvitation(); OutgoingInvitation(OutgoingInvitation&& other); + + OutgoingInvitation(const OutgoingInvitation&) = delete; + OutgoingInvitation& operator=(const OutgoingInvitation&) = delete; + ~OutgoingInvitation(); OutgoingInvitation& operator=(OutgoingInvitation&& other); @@ -147,8 +151,6 @@ class MOJO_CPP_SYSTEM_EXPORT OutgoingInvitation { private: ScopedInvitationHandle handle_; - - DISALLOW_COPY_AND_ASSIGN(OutgoingInvitation); }; // An IncomingInvitation can be accepted by an invited process by calling @@ -159,6 +161,10 @@ class MOJO_CPP_SYSTEM_EXPORT IncomingInvitation { IncomingInvitation(); IncomingInvitation(IncomingInvitation&& other); explicit IncomingInvitation(ScopedInvitationHandle handle); + + IncomingInvitation(const IncomingInvitation&) = delete; + IncomingInvitation& operator=(const IncomingInvitation&) = delete; + ~IncomingInvitation(); IncomingInvitation& operator=(IncomingInvitation&& other); @@ -197,8 +203,6 @@ class MOJO_CPP_SYSTEM_EXPORT IncomingInvitation { private: ScopedInvitationHandle handle_; - - DISALLOW_COPY_AND_ASSIGN(IncomingInvitation); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/isolated_connection.h b/chromium/mojo/public/cpp/system/isolated_connection.h index 42c90532ad8..065a8f55f9b 100644 --- a/chromium/mojo/public/cpp/system/isolated_connection.h +++ b/chromium/mojo/public/cpp/system/isolated_connection.h @@ -38,6 +38,10 @@ namespace mojo { class MOJO_CPP_SYSTEM_EXPORT IsolatedConnection { public: IsolatedConnection(); + + IsolatedConnection(const IsolatedConnection&) = delete; + IsolatedConnection& operator=(const IsolatedConnection&) = delete; + ~IsolatedConnection(); // Connects to a process at the other end of the channel. Returns a primordial @@ -51,8 +55,6 @@ class MOJO_CPP_SYSTEM_EXPORT IsolatedConnection { private: const base::UnguessableToken token_; - - DISALLOW_COPY_AND_ASSIGN(IsolatedConnection); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/scope_to_message_pipe.h b/chromium/mojo/public/cpp/system/scope_to_message_pipe.h index 73282deb11d..7292886a2d4 100644 --- a/chromium/mojo/public/cpp/system/scope_to_message_pipe.h +++ b/chromium/mojo/public/cpp/system/scope_to_message_pipe.h @@ -22,6 +22,10 @@ namespace internal { class MOJO_CPP_SYSTEM_EXPORT MessagePipeScoperBase { public: explicit MessagePipeScoperBase(ScopedMessagePipeHandle pipe); + + MessagePipeScoperBase(const MessagePipeScoperBase&) = delete; + MessagePipeScoperBase& operator=(const MessagePipeScoperBase&) = delete; + virtual ~MessagePipeScoperBase(); static void StartWatchingPipe(std::unique_ptr<MessagePipeScoperBase> scoper); @@ -29,8 +33,6 @@ class MOJO_CPP_SYSTEM_EXPORT MessagePipeScoperBase { private: ScopedMessagePipeHandle pipe_; SimpleWatcher pipe_watcher_; - - DISALLOW_COPY_AND_ASSIGN(MessagePipeScoperBase); }; template <typename T> @@ -39,12 +41,14 @@ class MessagePipeScoper : public MessagePipeScoperBase { explicit MessagePipeScoper(T scoped_object, ScopedMessagePipeHandle pipe) : MessagePipeScoperBase(std::move(pipe)), scoped_object_(std::move(scoped_object)) {} + + MessagePipeScoper(const MessagePipeScoper&) = delete; + MessagePipeScoper& operator=(const MessagePipeScoper&) = delete; + ~MessagePipeScoper() override = default; private: T scoped_object_; - - DISALLOW_COPY_AND_ASSIGN(MessagePipeScoper); }; } // namespace internal diff --git a/chromium/mojo/public/cpp/system/simple_watcher.cc b/chromium/mojo/public/cpp/system/simple_watcher.cc index 700fda474bf..53c5b9d0569 100644 --- a/chromium/mojo/public/cpp/system/simple_watcher.cc +++ b/chromium/mojo/public/cpp/system/simple_watcher.cc @@ -54,6 +54,9 @@ class SimpleWatcher::Context : public base::RefCountedThreadSafe<Context> { return context; } + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; + static void CallNotify(const MojoTrapEvent* event) { auto* context = reinterpret_cast<Context*>(event->trigger_context); context->Notify(event->result, event->signals_state, event->flags); @@ -107,8 +110,6 @@ class SimpleWatcher::Context : public base::RefCountedThreadSafe<Context> { const scoped_refptr<base::SequencedTaskRunner> task_runner_; const int watch_id_; const char* handler_tag_ = nullptr; - - DISALLOW_COPY_AND_ASSIGN(Context); }; SimpleWatcher::SimpleWatcher(const base::Location& from_here, diff --git a/chromium/mojo/public/cpp/system/simple_watcher.h b/chromium/mojo/public/cpp/system/simple_watcher.h index 3ccec253e88..94e45ba67a8 100644 --- a/chromium/mojo/public/cpp/system/simple_watcher.h +++ b/chromium/mojo/public/cpp/system/simple_watcher.h @@ -91,6 +91,10 @@ class MOJO_CPP_SYSTEM_EXPORT SimpleWatcher { scoped_refptr<base::SequencedTaskRunner> runner = base::SequencedTaskRunnerHandle::Get(), const char* handler_tag = nullptr); + + SimpleWatcher(const SimpleWatcher&) = delete; + SimpleWatcher& operator=(const SimpleWatcher&) = delete; + ~SimpleWatcher(); // Indicates if the SimpleWatcher is currently watching a handle. @@ -229,8 +233,6 @@ class MOJO_CPP_SYSTEM_EXPORT SimpleWatcher { const char* handler_tag_ = nullptr; base::WeakPtrFactory<SimpleWatcher> weak_factory_{this}; - - DISALLOW_COPY_AND_ASSIGN(SimpleWatcher); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/string_data_source.h b/chromium/mojo/public/cpp/system/string_data_source.h index a9e46b41c5f..cd5afd94cf3 100644 --- a/chromium/mojo/public/cpp/system/string_data_source.h +++ b/chromium/mojo/public/cpp/system/string_data_source.h @@ -30,6 +30,10 @@ class MOJO_CPP_SYSTEM_EXPORT StringDataSource final }; StringDataSource(base::span<const char> data, AsyncWritingMode mode); + + StringDataSource(const StringDataSource&) = delete; + StringDataSource& operator=(const StringDataSource&) = delete; + ~StringDataSource() override; private: @@ -39,8 +43,6 @@ class MOJO_CPP_SYSTEM_EXPORT StringDataSource final std::string data_; base::span<const char> data_view_; - - DISALLOW_COPY_AND_ASSIGN(StringDataSource); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/system/wait.cc b/chromium/mojo/public/cpp/system/wait.cc index ba27a6e786c..1cdf593edd2 100644 --- a/chromium/mojo/public/cpp/system/wait.cc +++ b/chromium/mojo/public/cpp/system/wait.cc @@ -22,6 +22,9 @@ class TriggerContext : public base::RefCountedThreadSafe<TriggerContext> { : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, base::WaitableEvent::InitialState::NOT_SIGNALED) {} + TriggerContext(const TriggerContext&) = delete; + TriggerContext& operator=(const TriggerContext&) = delete; + base::WaitableEvent& event() { return event_; } MojoResult wait_result() const { return wait_result_; } MojoHandleSignalsState wait_state() const { return wait_state_; } @@ -58,8 +61,6 @@ class TriggerContext : public base::RefCountedThreadSafe<TriggerContext> { // apart from waiting on |event()|. MojoResult wait_result_ = MOJO_RESULT_UNKNOWN; MojoHandleSignalsState wait_state_ = {0, 0}; - - DISALLOW_COPY_AND_ASSIGN(TriggerContext); }; } // namespace diff --git a/chromium/mojo/public/cpp/system/wait_set.cc b/chromium/mojo/public/cpp/system/wait_set.cc index 455de49e042..b6de2c538b3 100644 --- a/chromium/mojo/public/cpp/system/wait_set.cc +++ b/chromium/mojo/public/cpp/system/wait_set.cc @@ -29,6 +29,9 @@ class WaitSet::State : public base::RefCountedThreadSafe<State> { DCHECK_EQ(MOJO_RESULT_OK, rv); } + State(const State&) = delete; + State& operator=(const State&) = delete; + void ShutDown() { // NOTE: This may immediately invoke Notify for every context. trap_handle_.reset(); @@ -234,6 +237,9 @@ class WaitSet::State : public base::RefCountedThreadSafe<State> { Context(scoped_refptr<State> state, Handle handle) : state_(state), handle_(handle) {} + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; + Handle handle() const { return handle_; } uintptr_t context_value() const { @@ -256,8 +262,6 @@ class WaitSet::State : public base::RefCountedThreadSafe<State> { const scoped_refptr<State> state_; const Handle handle_; - - DISALLOW_COPY_AND_ASSIGN(Context); }; ~State() {} @@ -327,8 +331,6 @@ class WaitSet::State : public base::RefCountedThreadSafe<State> { // to guard against event starvation, as base::WaitableEvent::WaitMany gives // preference to events in left-to-right order. size_t waitable_index_shift_ = 0; - - DISALLOW_COPY_AND_ASSIGN(State); }; WaitSet::WaitSet() : state_(new State) {} diff --git a/chromium/mojo/public/cpp/system/wait_set.h b/chromium/mojo/public/cpp/system/wait_set.h index efb54dea39d..d57d0367173 100644 --- a/chromium/mojo/public/cpp/system/wait_set.h +++ b/chromium/mojo/public/cpp/system/wait_set.h @@ -35,6 +35,10 @@ namespace mojo { class MOJO_CPP_SYSTEM_EXPORT WaitSet { public: WaitSet(); + + WaitSet(const WaitSet&) = delete; + WaitSet& operator=(const WaitSet&) = delete; + ~WaitSet(); // Adds |event| to the set of events to wait on. If successful, any future @@ -116,8 +120,6 @@ class MOJO_CPP_SYSTEM_EXPORT WaitSet { // Thread-safe state associated with this WaitSet. Used to aggregate // notifications from watched handles. scoped_refptr<State> state_; - - DISALLOW_COPY_AND_ASSIGN(WaitSet); }; } // namespace mojo diff --git a/chromium/mojo/public/cpp/test_support/BUILD.gn b/chromium/mojo/public/cpp/test_support/BUILD.gn index 3312a371ba8..ddd87c43f86 100644 --- a/chromium/mojo/public/cpp/test_support/BUILD.gn +++ b/chromium/mojo/public/cpp/test_support/BUILD.gn @@ -6,6 +6,7 @@ static_library("test_utils") { testonly = true sources = [ + "fake_message_dispatch_context.h", "lib/test_support.cc", "lib/test_utils.cc", "test_utils.h", diff --git a/chromium/mojo/public/cpp/test_support/fake_message_dispatch_context.h b/chromium/mojo/public/cpp/test_support/fake_message_dispatch_context.h new file mode 100644 index 00000000000..33e65eec228 --- /dev/null +++ b/chromium/mojo/public/cpp/test_support/fake_message_dispatch_context.h @@ -0,0 +1,31 @@ +// Copyright 2019 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_TEST_SUPPORT_FAKE_MESSAGE_DISPATCH_CONTEXT_H_ +#define MOJO_PUBLIC_CPP_TEST_SUPPORT_FAKE_MESSAGE_DISPATCH_CONTEXT_H_ + +#include "mojo/public/cpp/bindings/lib/message_internal.h" +#include "mojo/public/cpp/bindings/message.h" + +namespace mojo { + +// A fake MessageDispatchContext that can be used in unit tests. This is +// typically used so that the code under test can call BadMessage() without +// triggering DCHECKs. +class FakeMessageDispatchContext { + public: + FakeMessageDispatchContext() + : dummy_message_(0, 0, 0, 0, nullptr), context_(&dummy_message_) {} + FakeMessageDispatchContext(const FakeMessageDispatchContext&) = delete; + FakeMessageDispatchContext operator=(const FakeMessageDispatchContext&) = + delete; + + private: + mojo::Message dummy_message_; + mojo::internal::MessageDispatchContext context_; +}; + +} // namespace mojo + +#endif // MOJO_PUBLIC_CPP_TEST_SUPPORT_FAKE_MESSAGE_DISPATCH_CONTEXT_H_ diff --git a/chromium/mojo/public/cpp/test_support/test_utils.h b/chromium/mojo/public/cpp/test_support/test_utils.h index a62679f5e5c..e16a3437c0e 100644 --- a/chromium/mojo/public/cpp/test_support/test_utils.h +++ b/chromium/mojo/public/cpp/test_support/test_utils.h @@ -96,6 +96,10 @@ void IterateAndReportPerf(const char* test_name, class BadMessageObserver { public: BadMessageObserver(); + + BadMessageObserver(const BadMessageObserver&) = delete; + BadMessageObserver& operator=(const BadMessageObserver&) = delete; + ~BadMessageObserver(); // Waits for the bad message and returns the error string. @@ -110,8 +114,6 @@ class BadMessageObserver { std::string last_error_for_bad_message_; bool got_bad_message_; base::RunLoop run_loop_; - - DISALLOW_COPY_AND_ASSIGN(BadMessageObserver); }; } // namespace test diff --git a/chromium/mojo/public/interfaces/bindings/tests/test_structs.mojom b/chromium/mojo/public/interfaces/bindings/tests/test_structs.mojom index d9912088f9c..4abc6c0a08e 100644 --- a/chromium/mojo/public/interfaces/bindings/tests/test_structs.mojom +++ b/chromium/mojo/public/interfaces/bindings/tests/test_structs.mojom @@ -365,11 +365,11 @@ struct MultiVersionStructV7 { // A struct where the fields are not sorted by their ordinals. struct ReorderedStruct { [MinVersion=2] - int32 a@3 = 3; + int32 a@1 = 3; [MinVersion=4] - int32 b@6 = 6; + int32 b@2 = 6; [MinVersion=1] - int32 c@1 = 1; + int32 c@0 = 1; }; // Used to verify that interfaces that are struct members can be defined in the diff --git a/chromium/mojo/public/java/system/base_run_loop.cc b/chromium/mojo/public/java/system/base_run_loop.cc index aa625cfadba..8f0d62525ad 100644 --- a/chromium/mojo/public/java/system/base_run_loop.cc +++ b/chromium/mojo/public/java/system/base_run_loop.cc @@ -61,7 +61,7 @@ static void JNI_BaseRunLoop_PostDelayedTask( ->task_runner() ->PostDelayedTask(FROM_HERE, base::BindOnce(&RunJavaRunnable, runnable_ref), - base::TimeDelta::FromMicroseconds(delay)); + base::Microseconds(delay)); } static void JNI_BaseRunLoop_DeleteMessageLoop( diff --git a/chromium/mojo/public/java/system/javatests/mojo_test_rule.cc b/chromium/mojo/public/java/system/javatests/mojo_test_rule.cc index 77498ed22da..e439007673a 100644 --- a/chromium/mojo/public/java/system/javatests/mojo_test_rule.cc +++ b/chromium/mojo/public/java/system/javatests/mojo_test_rule.cc @@ -60,7 +60,7 @@ static void JNI_MojoTestRule_RunLoop(JNIEnv* env, if (timeout_ms) { base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, run_loop.QuitWhenIdleClosure(), - base::TimeDelta::FromMilliseconds(timeout_ms)); + base::Milliseconds(timeout_ms)); run_loop.Run(); } else { run_loop.RunUntilIdle(); diff --git a/chromium/mojo/public/java/system/watcher_impl.cc b/chromium/mojo/public/java/system/watcher_impl.cc index e251d2e6cbb..065677fa935 100644 --- a/chromium/mojo/public/java/system/watcher_impl.cc +++ b/chromium/mojo/public/java/system/watcher_impl.cc @@ -26,6 +26,9 @@ class WatcherImpl { SimpleWatcher::ArmingPolicy::AUTOMATIC, base::SequencedTaskRunnerHandle::Get()) {} + WatcherImpl(const WatcherImpl&) = delete; + WatcherImpl& operator=(const WatcherImpl&) = delete; + ~WatcherImpl() = default; jint Start(JNIEnv* env, @@ -67,8 +70,6 @@ class WatcherImpl { SimpleWatcher watcher_; base::android::ScopedJavaGlobalRef<jobject> java_watcher_; - - DISALLOW_COPY_AND_ASSIGN(WatcherImpl); }; } // namespace diff --git a/chromium/mojo/public/mojom/base/BUILD.gn b/chromium/mojo/public/mojom/base/BUILD.gn index a110e1ab4e7..c8e5866d103 100644 --- a/chromium/mojo/public/mojom/base/BUILD.gn +++ b/chromium/mojo/public/mojom/base/BUILD.gn @@ -25,6 +25,7 @@ mojom_component("base") { "read_only_buffer.mojom", "read_only_file.mojom", "ref_counted_memory.mojom", + "safe_base_name.mojom", "shared_memory.mojom", "string16.mojom", "text_direction.mojom", @@ -54,6 +55,21 @@ mojom_component("base") { { types = [ { + mojom = "mojo_base.mojom.SafeBasename" + cpp = "::base::SafeBasename" + }, + ] + traits_headers = + [ "//mojo/public/cpp/base/safe_base_name_mojom_traits.h" ] + traits_public_deps = [ + "//base", + "//mojo/public/cpp/base", + "//mojo/public/cpp/base:shared_typemap_traits", + ] + }, + { + types = [ + { mojom = "mojo_base.mojom.BigBuffer" cpp = "::mojo_base::BigBuffer" move_only = true diff --git a/chromium/mojo/public/mojom/base/safe_base_name.mojom b/chromium/mojo/public/mojom/base/safe_base_name.mojom new file mode 100644 index 00000000000..3c993b4db1b --- /dev/null +++ b/chromium/mojo/public/mojom/base/safe_base_name.mojom @@ -0,0 +1,12 @@ +// Copyright 2021 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +module mojo_base.mojom; + +import "mojo/public/mojom/base/file_path.mojom"; + +// mojom transport for base::SafeBaseName. +struct SafeBaseName { + FilePath path; +}; diff --git a/chromium/mojo/public/tools/bindings/README.md b/chromium/mojo/public/tools/bindings/README.md index da427e40e79..1e5af58ec58 100644 --- a/chromium/mojo/public/tools/bindings/README.md +++ b/chromium/mojo/public/tools/bindings/README.md @@ -645,10 +645,10 @@ the following hard constraints: * For any given struct or interface, if any field or method explicitly specifies an ordinal value, all fields or methods must explicitly specify an ordinal value. -* For an *N*-field struct or *N*-method interface, the set of explicitly - assigned ordinal values must be limited to the range *[0, N-1]*. Interfaces - should include placeholder methods to fill the ordinal positions of removed - methods (for example "Unused_Message_7@7()" or "RemovedMessage@42()", etc). +* For an *N*-field struct, the set of explicitly assigned ordinal values must be + limited to the range *[0, N-1]*. Structs should include placeholder fields + to fill the ordinal positions of removed fields (for example "Unused_Field" + or "RemovedField", etc). You may reorder fields, but you must ensure that the ordinal values of existing fields remain unchanged. For example, the following struct remains diff --git a/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl b/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl index bff6a170343..cb0dea9f51d 100644 --- a/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl +++ b/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_definition.tmpl @@ -73,13 +73,16 @@ class {{class_name}}_{{method.name}}_HandleSyncResponse {%- endfor %} { DCHECK(!*result_); } + + {{class_name}}_{{method.name}}_HandleSyncResponse(const {{class_name}}_{{method.name}}_HandleSyncResponse&) = delete; + {{class_name}}_{{method.name}}_HandleSyncResponse& operator=(const {{class_name}}_{{method.name}}_HandleSyncResponse&) = delete; + bool Accept(mojo::Message* message) override; private: bool* result_; {%- for param in method.response_parameters %} {{param.kind|cpp_wrapper_call_type}}* out_{{param.name}}_; {%- endfor -%} - DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_HandleSyncResponse); }; {%- endif %} @@ -90,10 +93,13 @@ class {{class_name}}_{{method.name}}_ForwardToCallback {{class_name}}::{{method.name}}Callback callback ) : callback_(std::move(callback)) { } + + {{class_name}}_{{method.name}}_ForwardToCallback(const {{class_name}}_{{method.name}}_ForwardToCallback&) = delete; + {{class_name}}_{{method.name}}_ForwardToCallback& operator=(const {{class_name}}_{{method.name}}_ForwardToCallback&) = delete; + bool Accept(mojo::Message* message) override; private: {{class_name}}::{{method.name}}Callback callback_; - DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ForwardToCallback); }; {%- endif %} {%- endfor %} @@ -247,6 +253,9 @@ class {{class_name}}_{{method.name}}_ProxyToResponder { std::move(proxy)); } + {{class_name}}_{{method.name}}_ProxyToResponder(const {{class_name}}_{{method.name}}_ProxyToResponder&) = delete; + {{class_name}}_{{method.name}}_ProxyToResponder& operator=(const {{class_name}}_{{method.name}}_ProxyToResponder&) = delete; + ~{{class_name}}_{{method.name}}_ProxyToResponder() { #if DCHECK_IS_ON() if (responder_) { @@ -288,8 +297,6 @@ class {{class_name}}_{{method.name}}_ProxyToResponder { uint64_t request_id_; bool is_sync_; std::unique_ptr<mojo::MessageReceiverWithStatus> responder_; - - DISALLOW_COPY_AND_ASSIGN({{class_name}}_{{method.name}}_ProxyToResponder); }; {%- if method|method_supports_lazy_serialization %} diff --git a/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_macros.tmpl b/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_macros.tmpl index a373d5ba09d..f31d1c4f7e4 100644 --- a/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_macros.tmpl +++ b/chromium/mojo/public/tools/bindings/generators/cpp_templates/interface_macros.tmpl @@ -122,6 +122,10 @@ class {{message_typename}} , param_{{param.name}}_(std::move(param_{{param.name}})) {%- endif %} {%- endfor -%} {} + + {{message_typename}}(const {{message_typename}}&) = delete; + {{message_typename}}& operator=(const {{message_typename}}&) = delete; + ~{{message_typename}}() override = default; static mojo::Message Build( @@ -251,8 +255,6 @@ class {{message_typename}} {%- for param in parameters %} {{param.kind|cpp_wrapper_type}} param_{{param.name}}_; {%- endfor %} - - DISALLOW_COPY_AND_ASSIGN({{message_typename}}); }; const mojo::internal::UnserializedMessageContext::Tag diff --git a/chromium/mojo/public/tools/bindings/generators/cpp_templates/module-test-utils.h.tmpl b/chromium/mojo/public/tools/bindings/generators/cpp_templates/module-test-utils.h.tmpl index 89403243d87..1f60def3791 100644 --- a/chromium/mojo/public/tools/bindings/generators/cpp_templates/module-test-utils.h.tmpl +++ b/chromium/mojo/public/tools/bindings/generators/cpp_templates/module-test-utils.h.tmpl @@ -59,6 +59,10 @@ class {{export_attribute}} {{interface.name}}InterceptorForTesting : public {{in class {{export_attribute}} {{interface.name}}AsyncWaiter { public: explicit {{interface.name}}AsyncWaiter({{interface.name}}* proxy); + + {{interface.name}}AsyncWaiter(const {{interface.name}}AsyncWaiter&) = delete; + {{interface.name}}AsyncWaiter& operator=(const {{interface.name}}AsyncWaiter&) = delete; + ~{{interface.name}}AsyncWaiter(); {%- for method in interface.methods if method.response_parameters != None %} @@ -68,8 +72,6 @@ class {{export_attribute}} {{interface.name}}AsyncWaiter { private: {{interface.name}}* const proxy_; - - DISALLOW_COPY_AND_ASSIGN({{interface.name}}AsyncWaiter); }; {% endfor %} diff --git a/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl b/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl index 436dad6de01..1652da75ba3 100644 --- a/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl +++ b/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl @@ -45,6 +45,12 @@ class {{export_attribute}} {{struct.name}} { {%- if not loop.last -%},{%- endif %} {%- endfor %}); {% endfor %} + +{%- if struct|contains_move_only_members %} +{{struct.name}}(const {{struct.name}}&) = delete; +{{struct.name}}& operator=(const {{struct.name}}&) = delete; +{%- endif %} + ~{{struct.name}}(); // Clone() is a template so it is only instantiated if it is used. Thus, the @@ -135,15 +141,11 @@ class {{export_attribute}} {{struct.name}} { {%- endfor %} // Serialise this struct into a trace. - void WriteIntoTrace(perfetto::TracedValue context) const; + void WriteIntoTrace(perfetto::TracedValue traced_context) const; private: static bool Validate(const void* data, mojo::internal::ValidationContext* validation_context); - -{%- if struct|contains_move_only_members %} - DISALLOW_COPY_AND_ASSIGN({{struct.name}}); -{%- endif %} }; // The comparison operators are templates, so they are only instantiated if they diff --git a/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl b/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl index 504d4673577..eba234eff90 100644 --- a/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl +++ b/chromium/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_definition.tmpl @@ -32,8 +32,9 @@ size_t {{struct.name}}::Hash(size_t seed) const { } {%- endif %} -void {{struct.name}}::WriteIntoTrace(perfetto::TracedValue context) const { - auto dict = std::move(context).WriteDictionary(); +void {{struct.name}}::WriteIntoTrace( + perfetto::TracedValue traced_context) const { + auto dict = std::move(traced_context).WriteDictionary(); {%- for field in struct.fields %} perfetto::WriteIntoTracedValueWithFallback( dict.AddItem( diff --git a/chromium/mojo/public/tools/bindings/generators/js_templates/lite/interface_definition_for_module.tmpl b/chromium/mojo/public/tools/bindings/generators/js_templates/lite/interface_definition_for_module.tmpl index e2236b2e6d3..6ed5b6e0c73 100644 --- a/chromium/mojo/public/tools/bindings/generators/js_templates/lite/interface_definition_for_module.tmpl +++ b/chromium/mojo/public/tools/bindings/generators/js_templates/lite/interface_definition_for_module.tmpl @@ -1,7 +1,7 @@ {% macro generateMethodAnnotation(method) %} /** {%- for param in method.parameters %} - * @param { {{param.kind|param_type_in_js_module}} } {{param.name|sanitize_identifier}} + * @param { {{param.kind|type_in_js_module_with_nullability}} } {{param.name|sanitize_identifier}} {%- endfor -%} {%- if method.response_parameters != None %} {%- if method.response_parameters|length == 0 %} @@ -9,7 +9,7 @@ {%- else %} * @return {!Promise<{ {%- for response_parameter in method.response_parameters %} - {{response_parameter.name}}: {{response_parameter.kind|param_type_in_js_module}}, + {{response_parameter.name}}: {{response_parameter.kind|type_in_js_module_with_nullability}}, {%- endfor %} * }>} {%- endif %} diff --git a/chromium/mojo/public/tools/bindings/generators/mojom_js_generator.py b/chromium/mojo/public/tools/bindings/generators/mojom_js_generator.py index 5b831bbb019..3769a77d1db 100644 --- a/chromium/mojo/public/tools/bindings/generators/mojom_js_generator.py +++ b/chromium/mojo/public/tools/bindings/generators/mojom_js_generator.py @@ -130,7 +130,7 @@ _kind_to_lite_js_type = { _js_reserved_keywords = [ 'arguments', 'await', - 'break' + 'break', 'case', 'catch', 'class', @@ -367,12 +367,10 @@ class Generator(generator.Generator): "method_passes_associated_kinds": mojom.MethodPassesAssociatedKinds, "namespace_declarations": self._NamespaceDeclarations, "closure_type_with_nullability": self._ClosureTypeWithNullability, - "lite_closure_param_type": self._LiteClosureParamType, "lite_closure_type": self._LiteClosureType, "lite_closure_type_with_nullability": self._LiteClosureTypeWithNullability, "lite_closure_field_type": self._LiteClosureFieldType, - "param_type_in_js_module": self._GetParamTypeInJsModule, "payload_size": JavaScriptPayloadSize, "spec_type_in_js_module": self._GetSpecTypeInJsModule, "to_camel": generator.ToCamel, @@ -454,7 +452,7 @@ class Generator(generator.Generator): def _GetBindingsLibraryPath(self, for_webui_module=False): if for_webui_module: - return "chrome://resources/mojo/mojo/public/js/bindings.js" + return "//resources/mojo/mojo/public/js/bindings.js" return self._GetRelativePath('mojo/public/js/bindings.js') def _SetUniqueNameForImports(self): @@ -602,32 +600,6 @@ class Generator(generator.Generator): def _ClosureTypeWithNullability(self, kind): return ("" if mojom.IsNullableKind(kind) else "!") + self._ClosureType(kind) - def _GetParamTypeNameForNewBindings(self, kind, for_module=False): - def get_type_name(kind): - if mojom.IsEnumKind(kind): - return "number" - prefix = "" if mojom.IsNullableKind(kind) else "!" - if mojom.IsArrayKind(kind): - return prefix + ("Array<%s>" % get_type_name(kind.kind)) - if mojom.IsMapKind(kind) and self._IsStringableKind(kind.key_kind): - return "(%sMap<%s, %s>|%sObject<%s, %s>)" % ( - prefix, get_type_name(kind.key_kind), get_type_name( - kind.value_kind), prefix, get_type_name( - kind.key_kind), get_type_name(kind.value_kind)) - if mojom.IsMapKind(kind): - return "{}Map<{}, {}>".format(prefix, get_type_name(kind.key_kind), - get_type_name(kind.value_kind)) - return prefix + self._GetTypeNameForNewBindings(kind, - for_module=for_module) - - return get_type_name(kind) - - def _LiteClosureParamType(self, kind): - return self._GetParamTypeNameForNewBindings(kind, for_module=False) - - def _GetParamTypeInJsModule(self, kind): - return self._GetParamTypeNameForNewBindings(kind, for_module=True) - def _LiteClosureTypeWithNullability(self, kind): return self._GetTypeNameForNewBindings(kind, with_nullability=True, diff --git a/chromium/mojo/public/tools/mojom/check_stable_mojom_compatibility.py b/chromium/mojo/public/tools/mojom/check_stable_mojom_compatibility.py index 08bd672f5ba..0fe5ee501ea 100755 --- a/chromium/mojo/public/tools/mojom/check_stable_mojom_compatibility.py +++ b/chromium/mojo/public/tools/mojom/check_stable_mojom_compatibility.py @@ -18,7 +18,6 @@ import json import os import os.path import shutil -import six import sys import tempfile @@ -73,10 +72,8 @@ def _ValidateDelta(root, delta): try: ast = parser.Parse(contents, mojom) except Exception as e: - six.reraise( - ParseError, - 'encountered exception {0} while parsing {1}'.format(e, mojom), - sys.exc_info()[2]) + raise ParseError('encountered exception {0} while parsing {1}'.format( + e, mojom)) for imp in ast.import_list: parseMojom(imp.import_filename, file_overrides, override_modules) diff --git a/chromium/mojo/public/tools/mojom/mojom/generate/translate.py b/chromium/mojo/public/tools/mojom/mojom/generate/translate.py index 7580b78002e..92233c95d90 100644 --- a/chromium/mojo/public/tools/mojom/mojom/generate/translate.py +++ b/chromium/mojo/public/tools/mojom/mojom/generate/translate.py @@ -414,6 +414,11 @@ def _UnionField(module, parsed_field, union): """ field = mojom.UnionField() field.mojom_name = parsed_field.mojom_name + # Disallow unions from being self-recursive. + parsed_typename = parsed_field.typename + if parsed_typename.endswith('?'): + parsed_typename = parsed_typename[:-1] + assert parsed_typename != union.mojom_name field.kind = _Kind(module.kinds, _MapKind(parsed_field.typename), (module.mojom_namespace, union.mojom_name)) field.ordinal = parsed_field.ordinal.value if parsed_field.ordinal else None @@ -696,6 +701,11 @@ def _CollectReferencedKinds(module, all_defined_kinds): for referenced_kind in extract_referenced_user_kinds(param.kind): sanitized_kind = sanitize_kind(referenced_kind) referenced_user_kinds[sanitized_kind.spec] = sanitized_kind + # Consts can reference imported enums. + for const in module.constants: + if not const.kind in mojom.PRIMITIVES: + sanitized_kind = sanitize_kind(const.kind) + referenced_user_kinds[sanitized_kind.spec] = sanitized_kind return referenced_user_kinds @@ -741,6 +751,16 @@ def _AssertTypeIsStable(kind): assertDependencyIsStable(response_param.kind) +def _AssertStructIsValid(kind): + expected_ordinals = set(range(0, len(kind.fields))) + ordinals = set(map(lambda field: field.ordinal, kind.fields)) + if ordinals != expected_ordinals: + raise Exception( + 'Structs must use contiguous ordinals starting from 0. ' + + '{} is missing the following ordinals: {}.'.format( + kind.mojom_name, ', '.join(map(str, expected_ordinals - ordinals)))) + + def _Module(tree, path, imports): """ Args: @@ -847,6 +867,9 @@ def _Module(tree, path, imports): if kind.stable: _AssertTypeIsStable(kind) + for kind in module.structs: + _AssertStructIsValid(kind) + return module diff --git a/chromium/mojo/public/tools/mojom/mojom/generate/translate_unittest.py b/chromium/mojo/public/tools/mojom/mojom/generate/translate_unittest.py index 19905c8a954..e4cd9e6075c 100644 --- a/chromium/mojo/public/tools/mojom/mojom/generate/translate_unittest.py +++ b/chromium/mojo/public/tools/mojom/mojom/generate/translate_unittest.py @@ -71,3 +71,20 @@ class TranslateTest(unittest.TestCase): translate._MapKind("asso<SomeInterface>?"), "?asso:x:SomeInterface") self.assertEquals( translate._MapKind("asso<SomeInterface&>?"), "?asso:r:x:SomeInterface") + + def testSelfRecursiveUnions(self): + """Verifies _UnionField() raises when a union is self-recursive.""" + tree = ast.Mojom(None, ast.ImportList(), [ + ast.Union("SomeUnion", None, + ast.UnionBody([ast.UnionField("a", None, None, "SomeUnion")])) + ]) + with self.assertRaises(Exception): + translate.OrderedModule(tree, "mojom_tree", []) + + tree = ast.Mojom(None, ast.ImportList(), [ + ast.Union( + "SomeUnion", None, + ast.UnionBody([ast.UnionField("a", None, None, "SomeUnion?")])) + ]) + with self.assertRaises(Exception): + translate.OrderedModule(tree, "mojom_tree", []) |