summaryrefslogtreecommitdiff
path: root/Source/WebCore/dom/default
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/default
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/dom/default')
-rw-r--r--Source/WebCore/dom/default/PlatformMessagePortChannel.cpp81
-rw-r--r--Source/WebCore/dom/default/PlatformMessagePortChannel.h48
2 files changed, 51 insertions, 78 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
diff --git a/Source/WebCore/dom/default/PlatformMessagePortChannel.h b/Source/WebCore/dom/default/PlatformMessagePortChannel.h
index 6eb89d47d..4e4916a4f 100644
--- a/Source/WebCore/dom/default/PlatformMessagePortChannel.h
+++ b/Source/WebCore/dom/default/PlatformMessagePortChannel.h
@@ -28,13 +28,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef PlatformMessagePortChannel_h
-#define PlatformMessagePortChannel_h
+#pragma once
#include "MessagePortChannel.h"
-
#include <wtf/MessageQueue.h>
-#include <wtf/PassRefPtr.h>
#include <wtf/Threading.h>
namespace WebCore {
@@ -46,33 +43,24 @@ namespace WebCore {
// The goal of this implementation is to eliminate contention except when cloning or closing the port, so each side of the channel has its own separate mutex.
class PlatformMessagePortChannel : public ThreadSafeRefCounted<PlatformMessagePortChannel> {
public:
- class EventData {
- WTF_MAKE_NONCOPYABLE(EventData); WTF_MAKE_FAST_ALLOCATED;
- public:
- static std::unique_ptr<EventData> create(PassRefPtr<SerializedScriptValue>, PassOwnPtr<MessagePortChannelArray>);
-
- PassRefPtr<SerializedScriptValue> message() { return m_message; }
- PassOwnPtr<MessagePortChannelArray> channels() { return m_channels.release(); }
-
- private:
- EventData(PassRefPtr<SerializedScriptValue> message, PassOwnPtr<MessagePortChannelArray>);
- RefPtr<SerializedScriptValue> m_message;
- OwnPtr<MessagePortChannelArray> m_channels;
- };
-
// Wrapper for MessageQueue that allows us to do thread safe sharing by two proxies.
class MessagePortQueue : public ThreadSafeRefCounted<MessagePortQueue> {
public:
- static PassRefPtr<MessagePortQueue> create() { return adoptRef(new MessagePortQueue()); }
+ static Ref<MessagePortQueue> create() { return adoptRef(*new MessagePortQueue()); }
- std::unique_ptr<PlatformMessagePortChannel::EventData> tryGetMessage()
+ std::unique_ptr<MessagePortChannel::EventData> takeMessage()
{
return m_queue.tryGetMessage();
}
- bool appendAndCheckEmpty(std::unique_ptr<PlatformMessagePortChannel::EventData> message)
+ Deque<std::unique_ptr<MessagePortChannel::EventData>> takeAllMessages()
{
- return m_queue.appendAndCheckEmpty(std::move(message));
+ return m_queue.takeAllMessages();
+ }
+
+ bool appendAndCheckEmpty(std::unique_ptr<MessagePortChannel::EventData>&& message)
+ {
+ return m_queue.appendAndCheckEmpty(WTFMove(message));
}
bool isEmpty()
@@ -83,21 +71,21 @@ namespace WebCore {
private:
MessagePortQueue() { }
- MessageQueue<PlatformMessagePortChannel::EventData> m_queue;
+ MessageQueue<MessagePortChannel::EventData> m_queue;
};
~PlatformMessagePortChannel();
- static PassRefPtr<PlatformMessagePortChannel> create(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing);
- PlatformMessagePortChannel(PassRefPtr<MessagePortQueue> incoming, PassRefPtr<MessagePortQueue> outgoing);
+ static Ref<PlatformMessagePortChannel> create(MessagePortQueue* incoming, MessagePortQueue* outgoing);
+ PlatformMessagePortChannel(MessagePortQueue* incoming, MessagePortQueue* outgoing);
- PassRefPtr<PlatformMessagePortChannel> entangledChannel();
+ RefPtr<PlatformMessagePortChannel> entangledChannel();
void setRemotePort(MessagePort*);
void closeInternal();
- // Mutex used to ensure exclusive access to the object internals.
- Mutex m_mutex;
+ // Lock used to ensure exclusive access to the object internals.
+ Lock m_mutex;
// Pointer to our entangled pair - cleared when close() is called.
RefPtr<PlatformMessagePortChannel> m_entangledChannel;
@@ -107,9 +95,7 @@ namespace WebCore {
RefPtr<MessagePortQueue> m_outgoingQueue;
// The port we are connected to (the remote port) - this is the port that is notified when new messages arrive.
- MessagePort* m_remotePort;
+ MessagePort* m_remotePort { nullptr };
};
} // namespace WebCore
-
-#endif // PlatformMessagePortChannel_h