From: zandobersek@gmail.com Date: Tue, 17 Mar 2015 10:04:34 +0000 (+0000) Subject: [WK2] Use C++ lambdas in IPC::Connection X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=0eaa1c8826f1c04f7a1e92bd46320acd5aa870b7 [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): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@181630 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index c72bfe9..9eaa675 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,5 +1,30 @@ 2015-03-17 Zan Dobersek + [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 + [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 diff --git a/Source/WebKit2/Platform/IPC/Connection.cpp b/Source/WebKit2/Platform/IPC/Connection.cpp index e210fe8..57b4c57 100644 --- a/Source/WebKit2/Platform/IPC/Connection.cpp +++ b/Source/WebKit2/Platform/IPC/Connection.cpp @@ -300,34 +300,32 @@ void Connection::removeWorkQueueMessageReceiver(StringReference messageReceiverN }); } -void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver* workQueueMessageReceiver, MessageDecoder* incomingMessageDecoder) +void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver& workQueueMessageReceiver, MessageDecoder& decoder) { - std::unique_ptr 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("IPC", "SyncMessageReply", syncRequestID, incomingMessageDecoder->UUID()); + auto replyEncoder = std::make_unique("IPC", "SyncMessageReply", syncRequestID, decoder.UUID()); #else auto replyEncoder = std::make_unique("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 @@ void Connection::invalidate() return; } - // Reset the client. - m_client = 0; + m_client = nullptr; - m_connectionQueue->dispatch(WTF::bind(&Connection::platformInvalidate, this)); + RefPtr protectedThis(this); + m_connectionQueue->dispatch([protectedThis] { + protectedThis->platformInvalidate(); + }); } void Connection::markCurrentlyDispatchedMessageAsInvalid() @@ -397,7 +397,10 @@ bool Connection::sendMessage(std::unique_ptr encoder, unsigned m } // 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 protectedThis(this); + m_connectionQueue->dispatch([protectedThis] { + protectedThis->sendOutgoingMessages(); + }); return true; } @@ -653,23 +656,27 @@ void Connection::processIncomingMessage(std::unique_ptr message) } 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 = ""; - CString messageName = String::format("", message->length()).utf8(); - - m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, messageReceiverName, messageName)); - return; - } - - m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, message->messageReceiverName().toString(), message->messageName().toString())); + RefPtr protectedThis(this); + StringReference messageReceiverName = message->messageReceiverName(); + StringCapture capturedMessageReceiverName(messageReceiverName.isEmpty() ? "" : String(messageReceiverName.data(), messageReceiverName.size())); + StringReference messageName = message->messageName(); + StringCapture capturedMessageName(messageName.isEmpty() ? "" : String(messageName.data(), messageName.size())); + + 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 protectedThis(this); + RefPtr& workQueueMessageReceiver = it->value.second; + MessageDecoder* decoderPtr = message.release(); + it->value.first->dispatch([protectedThis, workQueueMessageReceiver, decoderPtr] { + std::unique_ptr decoder(decoderPtr); + protectedThis->dispatchWorkQueueMessageReceiverMessage(*workQueueMessageReceiver, *decoder); + }); return; } @@ -829,7 +836,10 @@ void Connection::enqueueIncomingMessage(std::unique_ptr incoming m_incomingMessages.append(WTF::move(incomingMessage)); } - m_clientRunLoop.dispatch(WTF::bind(&Connection::dispatchOneMessage, this)); + RefPtr protectedThis(this); + m_clientRunLoop.dispatch([protectedThis] { + protectedThis->dispatchOneMessage(); + }); } void Connection::dispatchMessage(MessageDecoder& decoder) diff --git a/Source/WebKit2/Platform/IPC/Connection.h b/Source/WebKit2/Platform/IPC/Connection.h index 132198b..20bc738 100644 --- a/Source/WebKit2/Platform/IPC/Connection.h +++ b/Source/WebKit2/Platform/IPC/Connection.h @@ -213,7 +213,7 @@ private: void processIncomingMessage(std::unique_ptr); void processIncomingSyncReply(std::unique_ptr); - void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver*, MessageDecoder*); + void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver&, MessageDecoder&); bool canSendOutgoingMessages() const; bool platformCanSendOutgoingMessages() const; diff --git a/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm b/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm index 25e2821..4b7e6ee 100644 --- a/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm +++ b/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm @@ -510,7 +510,14 @@ void Connection::receiveSourceEventHandler() 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 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; diff --git a/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp b/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp index 16be014..4dd95fd 100644 --- a/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp +++ b/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp @@ -388,27 +388,27 @@ bool Connection::open() } } + RefPtr protectedThis(this); m_isConnected = true; #if PLATFORM(GTK) - RefPtr protector(this); m_connectionQueue->registerSocketEventHandler(m_socketDescriptor, - [=] { - protector->readyReadHandler(); + [protectedThis] { + protectedThis->readyReadHandler(); }, - [=] { - protector->connectionDidClose(); + [protectedThis] { + protectedThis->connectionDidClose(); }); #elif PLATFORM(EFL) - RefPtr 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; }