diff options
Diffstat (limited to 'Source/WebCore/dom/default/PlatformMessagePortChannel.cpp')
-rw-r--r-- | Source/WebCore/dom/default/PlatformMessagePortChannel.cpp | 81 |
1 files changed, 34 insertions, 47 deletions
diff --git a/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp b/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp index 902da1834..9be0c65bd 100644 --- a/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp +++ b/Source/WebCore/dom/default/PlatformMessagePortChannel.cpp @@ -37,34 +37,23 @@ namespace WebCore { -std::unique_ptr<PlatformMessagePortChannel::EventData> PlatformMessagePortChannel::EventData::create(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) +void MessagePortChannel::createChannel(MessagePort* port1, MessagePort* port2) { - return std::unique_ptr<EventData>(new EventData(message, channels)); -} - -PlatformMessagePortChannel::EventData::EventData(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) - : m_message(message) - , m_channels(channels) -{ -} - -void MessagePortChannel::createChannel(PassRefPtr<MessagePort> port1, PassRefPtr<MessagePort> port2) -{ - RefPtr<PlatformMessagePortChannel::MessagePortQueue> queue1 = PlatformMessagePortChannel::MessagePortQueue::create(); - RefPtr<PlatformMessagePortChannel::MessagePortQueue> queue2 = PlatformMessagePortChannel::MessagePortQueue::create(); + Ref<PlatformMessagePortChannel::MessagePortQueue> queue1 = PlatformMessagePortChannel::MessagePortQueue::create(); + Ref<PlatformMessagePortChannel::MessagePortQueue> queue2 = PlatformMessagePortChannel::MessagePortQueue::create(); - OwnPtr<MessagePortChannel> channel1 = adoptPtr(new MessagePortChannel(PlatformMessagePortChannel::create(queue1, queue2))); - OwnPtr<MessagePortChannel> channel2 = adoptPtr(new MessagePortChannel(PlatformMessagePortChannel::create(queue2, queue1))); + auto channel1 = std::make_unique<MessagePortChannel>(PlatformMessagePortChannel::create(queue1.ptr(), queue2.ptr())); + auto channel2 = std::make_unique<MessagePortChannel>(PlatformMessagePortChannel::create(queue2.ptr(), queue1.ptr())); channel1->m_channel->m_entangledChannel = channel2->m_channel; channel2->m_channel->m_entangledChannel = channel1->m_channel; - port1->entangle(channel2.release()); - port2->entangle(channel1.release()); + port1->entangle(WTFMove(channel2)); + port2->entangle(WTFMove(channel1)); } -MessagePortChannel::MessagePortChannel(PassRefPtr<PlatformMessagePortChannel> channel) - : m_channel(channel) +MessagePortChannel::MessagePortChannel(RefPtr<PlatformMessagePortChannel>&& channel) + : m_channel(WTFMove(channel)) { } @@ -88,30 +77,29 @@ void MessagePortChannel::disentangle() { RefPtr<PlatformMessagePortChannel> remote = m_channel->entangledChannel(); if (remote) - remote->setRemotePort(0); + remote->setRemotePort(nullptr); } -void MessagePortChannel::postMessageToRemote(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray> channels) +void MessagePortChannel::postMessageToRemote(Ref<SerializedScriptValue>&& message, std::unique_ptr<MessagePortChannelArray> channels) { - MutexLocker lock(m_channel->m_mutex); + LockHolder lock(m_channel->m_mutex); if (!m_channel->m_outgoingQueue) return; - bool wasEmpty = m_channel->m_outgoingQueue->appendAndCheckEmpty(PlatformMessagePortChannel::EventData::create(message, channels)); + bool wasEmpty = m_channel->m_outgoingQueue->appendAndCheckEmpty(std::make_unique<EventData>(WTFMove(message), WTFMove(channels))); if (wasEmpty && m_channel->m_remotePort) m_channel->m_remotePort->messageAvailable(); } -bool MessagePortChannel::tryGetMessageFromRemote(RefPtr<SerializedScriptValue>& message, OwnPtr<MessagePortChannelArray>& channels) +auto MessagePortChannel::takeMessageFromRemote() -> std::unique_ptr<EventData> { - MutexLocker lock(m_channel->m_mutex); - auto result = m_channel->m_incomingQueue->tryGetMessage(); - if (!result) - return false; - - message = result->message(); - channels = result->channels(); + LockHolder lock(m_channel->m_mutex); + return m_channel->m_incomingQueue->takeMessage(); +} - return true; +auto MessagePortChannel::takeAllMessagesFromRemote() -> Deque<std::unique_ptr<EventData>> +{ + LockHolder lock(m_channel->m_mutex); + return m_channel->m_incomingQueue->takeAllMessages(); } void MessagePortChannel::close() @@ -126,20 +114,20 @@ void MessagePortChannel::close() bool MessagePortChannel::isConnectedTo(MessagePort* port) { // FIXME: What guarantees that the result remains the same after we release the lock? - MutexLocker lock(m_channel->m_mutex); + LockHolder lock(m_channel->m_mutex); return m_channel->m_remotePort == port; } bool MessagePortChannel::hasPendingActivity() { // FIXME: What guarantees that the result remains the same after we release the lock? - MutexLocker lock(m_channel->m_mutex); + LockHolder lock(m_channel->m_mutex); return !m_channel->m_incomingQueue->isEmpty(); } MessagePort* MessagePortChannel::locallyEntangledPort(const ScriptExecutionContext* context) { - MutexLocker lock(m_channel->m_mutex); + LockHolder lock(m_channel->m_mutex); // See if both contexts are run by the same thread (are the same context, or are both documents). if (m_channel->m_remotePort) { // The remote port's ScriptExecutionContext is guaranteed not to change here - MessagePort::contextDestroyed() @@ -151,15 +139,14 @@ MessagePort* MessagePortChannel::locallyEntangledPort(const ScriptExecutionConte return 0; } -PassRefPtr<PlatformMessagePortChannel> PlatformMessagePortChannel::create(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing) +Ref<PlatformMessagePortChannel> PlatformMessagePortChannel::create(MessagePortQueue* incoming, MessagePortQueue* outgoing) { - return adoptRef(new PlatformMessagePortChannel(incoming, outgoing)); + return adoptRef(*new PlatformMessagePortChannel(incoming, outgoing)); } -PlatformMessagePortChannel::PlatformMessagePortChannel(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing) +PlatformMessagePortChannel::PlatformMessagePortChannel(MessagePortQueue* incoming, MessagePortQueue* outgoing) : m_incomingQueue(incoming) , m_outgoingQueue(outgoing) - , m_remotePort(0) { } @@ -169,28 +156,28 @@ PlatformMessagePortChannel::~PlatformMessagePortChannel() void PlatformMessagePortChannel::setRemotePort(MessagePort* port) { - MutexLocker lock(m_mutex); + LockHolder lock(m_mutex); // Should never set port if it is already set. ASSERT(!port || !m_remotePort); m_remotePort = port; } -PassRefPtr<PlatformMessagePortChannel> PlatformMessagePortChannel::entangledChannel() +RefPtr<PlatformMessagePortChannel> PlatformMessagePortChannel::entangledChannel() { // FIXME: What guarantees that the result remains the same after we release the lock? // This lock only guarantees that the returned pointer will not be pointing to released memory, // but not that it will still be pointing to this object's entangled port channel. - MutexLocker lock(m_mutex); + LockHolder lock(m_mutex); return m_entangledChannel; } void PlatformMessagePortChannel::closeInternal() { - MutexLocker lock(m_mutex); + LockHolder lock(m_mutex); // Disentangle ourselves from the other end. We still maintain a reference to our incoming queue, since previously-existing messages should still be delivered. - m_remotePort = 0; - m_entangledChannel = 0; - m_outgoingQueue = 0; + m_remotePort = nullptr; + m_entangledChannel = nullptr; + m_outgoingQueue = nullptr; } } // namespace WebCore |