Modified: trunk/Source/WebKit2/ChangeLog (181629 => 181630)
--- trunk/Source/WebKit2/ChangeLog 2015-03-17 09:45:55 UTC (rev 181629)
+++ trunk/Source/WebKit2/ChangeLog 2015-03-17 10:04:34 UTC (rev 181630)
@@ -1,5 +1,30 @@
2015-03-17 Zan Dobersek <[email protected]>
+ [WK2] Use C++ lambdas in IPC::Connection
+ https://bugs.webkit.org/show_bug.cgi?id=138018
+
+ Reviewed by Anders Carlsson.
+
+ Replace uses of WTF::bind() in the IPC::Connection class with C++ lambdas.
+
+ * Platform/IPC/Connection.cpp:
+ (IPC::Connection::dispatchWorkQueueMessageReceiverMessage):
+ (IPC::Connection::invalidate):
+ (IPC::Connection::sendMessage):
+ (IPC::Connection::processIncomingMessage): Simplify the error messages so we
+ don't have to format strings on-the-fly, removing the issues of cross-thread
+ string copying altogether.
+ (IPC::Connection::dispatchDidReceiveInvalidMessage): The parameters are now
+ of the StringReference type.
+ (IPC::Connection::enqueueIncomingMessage):
+ * Platform/IPC/Connection.h:
+ * Platform/IPC/mac/ConnectionMac.mm:
+ (IPC::Connection::receiveSourceEventHandler):
+ * Platform/IPC/unix/ConnectionUnix.cpp:
+ (IPC::Connection::open):
+
+2015-03-17 Zan Dobersek <[email protected]>
+
[CMake] Use a forwarding header for ANGLE's ShaderLang.h to avoid picking up ANGLE's EGL headers
https://bugs.webkit.org/show_bug.cgi?id=142530
Modified: trunk/Source/WebKit2/Platform/IPC/Connection.cpp (181629 => 181630)
--- trunk/Source/WebKit2/Platform/IPC/Connection.cpp 2015-03-17 09:45:55 UTC (rev 181629)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.cpp 2015-03-17 10:04:34 UTC (rev 181630)
@@ -300,34 +300,32 @@
});
}
-void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver* workQueueMessageReceiver, MessageDecoder* incomingMessageDecoder)
+void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver& workQueueMessageReceiver, MessageDecoder& decoder)
{
- std::unique_ptr<MessageDecoder> decoder(incomingMessageDecoder);
-
- if (!decoder->isSyncMessage()) {
- workQueueMessageReceiver->didReceiveMessage(*this, *decoder);
+ if (!decoder.isSyncMessage()) {
+ workQueueMessageReceiver.didReceiveMessage(*this, decoder);
return;
}
uint64_t syncRequestID = 0;
- if (!decoder->decode(syncRequestID) || !syncRequestID) {
+ if (!decoder.decode(syncRequestID) || !syncRequestID) {
// We received an invalid sync message.
// FIXME: Handle this.
- decoder->markInvalid();
+ decoder.markInvalid();
return;
}
#if HAVE(DTRACE)
- auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID, incomingMessageDecoder->UUID());
+ auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID, decoder.UUID());
#else
auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID);
#endif
// Hand off both the decoder and encoder to the work queue message receiver.
- workQueueMessageReceiver->didReceiveSyncMessage(*this, *decoder, replyEncoder);
+ workQueueMessageReceiver.didReceiveSyncMessage(*this, decoder, replyEncoder);
// FIXME: If the message was invalid, we should send back a SyncMessageError.
- ASSERT(!decoder->isInvalid());
+ ASSERT(!decoder.isInvalid());
if (replyEncoder)
sendSyncReply(WTF::move(replyEncoder));
@@ -347,10 +345,12 @@
return;
}
- // Reset the client.
- m_client = 0;
+ m_client = nullptr;
- m_connectionQueue->dispatch(WTF::bind(&Connection::platformInvalidate, this));
+ RefPtr<Connection> protectedThis(this);
+ m_connectionQueue->dispatch([protectedThis] {
+ protectedThis->platformInvalidate();
+ });
}
void Connection::markCurrentlyDispatchedMessageAsInvalid()
@@ -397,7 +397,10 @@
}
// FIXME: We should add a boolean flag so we don't call this when work has already been scheduled.
- m_connectionQueue->dispatch(WTF::bind(&Connection::sendOutgoingMessages, this));
+ RefPtr<Connection> protectedThis(this);
+ m_connectionQueue->dispatch([protectedThis] {
+ protectedThis->sendOutgoingMessages();
+ });
return true;
}
@@ -653,23 +656,27 @@
}
if (!m_workQueueMessageReceivers.isValidKey(message->messageReceiverName())) {
- if (message->messageReceiverName().isEmpty() && message->messageName().isEmpty()) {
- // Something went wrong when decoding the message. Encode the message length so we can figure out if this
- // happens for certain message lengths.
- CString messageReceiverName = "<unknown message>";
- CString messageName = String::format("<message length: %zu bytes>", message->length()).utf8();
+ RefPtr<Connection> protectedThis(this);
+ StringReference messageReceiverName = message->messageReceiverName();
+ StringCapture capturedMessageReceiverName(messageReceiverName.isEmpty() ? "<unknown message receiver>" : String(messageReceiverName.data(), messageReceiverName.size()));
+ StringReference messageName = message->messageName();
+ StringCapture capturedMessageName(messageName.isEmpty() ? "<unknown message>" : String(messageName.data(), messageName.size()));
- m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, messageReceiverName, messageName));
- return;
- }
-
- m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, message->messageReceiverName().toString(), message->messageName().toString()));
+ m_clientRunLoop.dispatch([protectedThis, capturedMessageReceiverName, capturedMessageName] {
+ protectedThis->dispatchDidReceiveInvalidMessage(capturedMessageReceiverName.string().utf8(), capturedMessageName.string().utf8());
+ });
return;
}
auto it = m_workQueueMessageReceivers.find(message->messageReceiverName());
if (it != m_workQueueMessageReceivers.end()) {
- it->value.first->dispatch(bind(&Connection::dispatchWorkQueueMessageReceiverMessage, this, it->value.second, message.release()));
+ RefPtr<Connection> protectedThis(this);
+ RefPtr<WorkQueueMessageReceiver>& workQueueMessageReceiver = it->value.second;
+ MessageDecoder* decoderPtr = message.release();
+ it->value.first->dispatch([protectedThis, workQueueMessageReceiver, decoderPtr] {
+ std::unique_ptr<MessageDecoder> decoder(decoderPtr);
+ protectedThis->dispatchWorkQueueMessageReceiverMessage(*workQueueMessageReceiver, *decoder);
+ });
return;
}
@@ -829,7 +836,10 @@
m_incomingMessages.append(WTF::move(incomingMessage));
}
- m_clientRunLoop.dispatch(WTF::bind(&Connection::dispatchOneMessage, this));
+ RefPtr<Connection> protectedThis(this);
+ m_clientRunLoop.dispatch([protectedThis] {
+ protectedThis->dispatchOneMessage();
+ });
}
void Connection::dispatchMessage(MessageDecoder& decoder)
Modified: trunk/Source/WebKit2/Platform/IPC/Connection.h (181629 => 181630)
--- trunk/Source/WebKit2/Platform/IPC/Connection.h 2015-03-17 09:45:55 UTC (rev 181629)
+++ trunk/Source/WebKit2/Platform/IPC/Connection.h 2015-03-17 10:04:34 UTC (rev 181630)
@@ -213,7 +213,7 @@
void processIncomingMessage(std::unique_ptr<MessageDecoder>);
void processIncomingSyncReply(std::unique_ptr<MessageDecoder>);
- void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver*, MessageDecoder*);
+ void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver&, MessageDecoder&);
bool canSendOutgoingMessages() const;
bool platformCanSendOutgoingMessages() const;
Modified: trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm (181629 => 181630)
--- trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm 2015-03-17 09:45:55 UTC (rev 181629)
+++ trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm 2015-03-17 10:04:34 UTC (rev 181630)
@@ -510,7 +510,14 @@
if (decoder->messageReceiverName() == "IPC" && decoder->messageName() == "SetExceptionPort") {
if (m_isServer) {
// Server connections aren't supposed to have their exception ports overriden. Treat this as an invalid message.
- m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, decoder->messageReceiverName().toString(), decoder->messageName().toString()));
+ RefPtr<Connection> protectedThis(this);
+ StringReference messageReceiverName = decoder->messageReceiverName();
+ StringCapture capturedMessageReceiverName(String(messageReceiverName.data(), messageReceiverName.size()));
+ StringReference messageName = decoder->messageName();
+ StringCapture capturedMessageName(String(messageName.data(), messageName.size()));
+ m_clientRunLoop.dispatch([protectedThis, capturedMessageReceiverName, capturedMessageName] {
+ protectedThis->dispatchDidReceiveInvalidMessage(capturedMessageReceiverName.string().utf8(), capturedMessageName.string().utf8());
+ });
return;
}
MachPort exceptionPort;
Modified: trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp (181629 => 181630)
--- trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp 2015-03-17 09:45:55 UTC (rev 181629)
+++ trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp 2015-03-17 10:04:34 UTC (rev 181630)
@@ -388,27 +388,27 @@
}
}
+ RefPtr<Connection> protectedThis(this);
m_isConnected = true;
#if PLATFORM(GTK)
- RefPtr<Connection> protector(this);
m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
- [=] {
- protector->readyReadHandler();
+ [protectedThis] {
+ protectedThis->readyReadHandler();
},
- [=] {
- protector->connectionDidClose();
+ [protectedThis] {
+ protectedThis->connectionDidClose();
});
#elif PLATFORM(EFL)
- RefPtr<Connection> protector(this);
m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
- [protector] {
- protector->readyReadHandler();
+ [protectedThis] {
+ protectedThis->readyReadHandler();
});
#endif
- // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal
- // handler.
- m_connectionQueue->dispatch(WTF::bind(&Connection::readyReadHandler, this));
+ // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal handler.
+ m_connectionQueue->dispatch([protectedThis] {
+ protectedThis->readyReadHandler();
+ });
return true;
}