Changeset 181630 in webkit
- Timestamp:
- Mar 17, 2015, 3:04:34 AM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 5 edited
-
ChangeLog (modified) (1 diff)
-
Platform/IPC/Connection.cpp (modified) (7 diffs)
-
Platform/IPC/Connection.h (modified) (1 diff)
-
Platform/IPC/mac/ConnectionMac.mm (modified) (1 diff)
-
Platform/IPC/unix/ConnectionUnix.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r181629 r181630 1 2015-03-17 Zan Dobersek <zdobersek@igalia.com> 2 3 [WK2] Use C++ lambdas in IPC::Connection 4 https://bugs.webkit.org/show_bug.cgi?id=138018 5 6 Reviewed by Anders Carlsson. 7 8 Replace uses of WTF::bind() in the IPC::Connection class with C++ lambdas. 9 10 * Platform/IPC/Connection.cpp: 11 (IPC::Connection::dispatchWorkQueueMessageReceiverMessage): 12 (IPC::Connection::invalidate): 13 (IPC::Connection::sendMessage): 14 (IPC::Connection::processIncomingMessage): Simplify the error messages so we 15 don't have to format strings on-the-fly, removing the issues of cross-thread 16 string copying altogether. 17 (IPC::Connection::dispatchDidReceiveInvalidMessage): The parameters are now 18 of the StringReference type. 19 (IPC::Connection::enqueueIncomingMessage): 20 * Platform/IPC/Connection.h: 21 * Platform/IPC/mac/ConnectionMac.mm: 22 (IPC::Connection::receiveSourceEventHandler): 23 * Platform/IPC/unix/ConnectionUnix.cpp: 24 (IPC::Connection::open): 25 1 26 2015-03-17 Zan Dobersek <zdobersek@igalia.com> 2 27 -
trunk/Source/WebKit2/Platform/IPC/Connection.cpp
r179592 r181630 301 301 } 302 302 303 void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver* workQueueMessageReceiver, MessageDecoder* incomingMessageDecoder) 304 { 305 std::unique_ptr<MessageDecoder> decoder(incomingMessageDecoder); 306 307 if (!decoder->isSyncMessage()) { 308 workQueueMessageReceiver->didReceiveMessage(*this, *decoder); 303 void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver& workQueueMessageReceiver, MessageDecoder& decoder) 304 { 305 if (!decoder.isSyncMessage()) { 306 workQueueMessageReceiver.didReceiveMessage(*this, decoder); 309 307 return; 310 308 } 311 309 312 310 uint64_t syncRequestID = 0; 313 if (!decoder ->decode(syncRequestID) || !syncRequestID) {311 if (!decoder.decode(syncRequestID) || !syncRequestID) { 314 312 // We received an invalid sync message. 315 313 // FIXME: Handle this. 316 decoder ->markInvalid();314 decoder.markInvalid(); 317 315 return; 318 316 } 319 317 320 318 #if HAVE(DTRACE) 321 auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID, incomingMessageDecoder->UUID());319 auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID, decoder.UUID()); 322 320 #else 323 321 auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID); … … 325 323 326 324 // Hand off both the decoder and encoder to the work queue message receiver. 327 workQueueMessageReceiver ->didReceiveSyncMessage(*this, *decoder, replyEncoder);325 workQueueMessageReceiver.didReceiveSyncMessage(*this, decoder, replyEncoder); 328 326 329 327 // FIXME: If the message was invalid, we should send back a SyncMessageError. 330 ASSERT(!decoder ->isInvalid());328 ASSERT(!decoder.isInvalid()); 331 329 332 330 if (replyEncoder) … … 348 346 } 349 347 350 // Reset the client. 351 m_client = 0; 352 353 m_connectionQueue->dispatch(WTF::bind(&Connection::platformInvalidate, this)); 348 m_client = nullptr; 349 350 RefPtr<Connection> protectedThis(this); 351 m_connectionQueue->dispatch([protectedThis] { 352 protectedThis->platformInvalidate(); 353 }); 354 354 } 355 355 … … 398 398 399 399 // FIXME: We should add a boolean flag so we don't call this when work has already been scheduled. 400 m_connectionQueue->dispatch(WTF::bind(&Connection::sendOutgoingMessages, this)); 400 RefPtr<Connection> protectedThis(this); 401 m_connectionQueue->dispatch([protectedThis] { 402 protectedThis->sendOutgoingMessages(); 403 }); 401 404 return true; 402 405 } … … 654 657 655 658 if (!m_workQueueMessageReceivers.isValidKey(message->messageReceiverName())) { 656 if (message->messageReceiverName().isEmpty() && message->messageName().isEmpty()) { 657 // Something went wrong when decoding the message. Encode the message length so we can figure out if this 658 // happens for certain message lengths. 659 CString messageReceiverName = "<unknown message>"; 660 CString messageName = String::format("<message length: %zu bytes>", message->length()).utf8(); 661 662 m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, messageReceiverName, messageName)); 663 return; 664 } 665 666 m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, message->messageReceiverName().toString(), message->messageName().toString())); 659 RefPtr<Connection> protectedThis(this); 660 StringReference messageReceiverName = message->messageReceiverName(); 661 StringCapture capturedMessageReceiverName(messageReceiverName.isEmpty() ? "<unknown message receiver>" : String(messageReceiverName.data(), messageReceiverName.size())); 662 StringReference messageName = message->messageName(); 663 StringCapture capturedMessageName(messageName.isEmpty() ? "<unknown message>" : String(messageName.data(), messageName.size())); 664 665 m_clientRunLoop.dispatch([protectedThis, capturedMessageReceiverName, capturedMessageName] { 666 protectedThis->dispatchDidReceiveInvalidMessage(capturedMessageReceiverName.string().utf8(), capturedMessageName.string().utf8()); 667 }); 667 668 return; 668 669 } … … 670 671 auto it = m_workQueueMessageReceivers.find(message->messageReceiverName()); 671 672 if (it != m_workQueueMessageReceivers.end()) { 672 it->value.first->dispatch(bind(&Connection::dispatchWorkQueueMessageReceiverMessage, this, it->value.second, message.release())); 673 RefPtr<Connection> protectedThis(this); 674 RefPtr<WorkQueueMessageReceiver>& workQueueMessageReceiver = it->value.second; 675 MessageDecoder* decoderPtr = message.release(); 676 it->value.first->dispatch([protectedThis, workQueueMessageReceiver, decoderPtr] { 677 std::unique_ptr<MessageDecoder> decoder(decoderPtr); 678 protectedThis->dispatchWorkQueueMessageReceiverMessage(*workQueueMessageReceiver, *decoder); 679 }); 673 680 return; 674 681 } … … 830 837 } 831 838 832 m_clientRunLoop.dispatch(WTF::bind(&Connection::dispatchOneMessage, this)); 839 RefPtr<Connection> protectedThis(this); 840 m_clientRunLoop.dispatch([protectedThis] { 841 protectedThis->dispatchOneMessage(); 842 }); 833 843 } 834 844 -
trunk/Source/WebKit2/Platform/IPC/Connection.h
r180410 r181630 214 214 void processIncomingSyncReply(std::unique_ptr<MessageDecoder>); 215 215 216 void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver *, MessageDecoder*);216 void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver&, MessageDecoder&); 217 217 218 218 bool canSendOutgoingMessages() const; -
trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm
r180054 r181630 511 511 if (m_isServer) { 512 512 // Server connections aren't supposed to have their exception ports overriden. Treat this as an invalid message. 513 m_clientRunLoop.dispatch(bind(&Connection::dispatchDidReceiveInvalidMessage, this, decoder->messageReceiverName().toString(), decoder->messageName().toString())); 513 RefPtr<Connection> protectedThis(this); 514 StringReference messageReceiverName = decoder->messageReceiverName(); 515 StringCapture capturedMessageReceiverName(String(messageReceiverName.data(), messageReceiverName.size())); 516 StringReference messageName = decoder->messageName(); 517 StringCapture capturedMessageName(String(messageName.data(), messageName.size())); 518 m_clientRunLoop.dispatch([protectedThis, capturedMessageReceiverName, capturedMessageName] { 519 protectedThis->dispatchDidReceiveInvalidMessage(capturedMessageReceiverName.string().utf8(), capturedMessageName.string().utf8()); 520 }); 514 521 return; 515 522 } -
trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp
r176762 r181630 389 389 } 390 390 391 RefPtr<Connection> protectedThis(this); 391 392 m_isConnected = true; 392 393 #if PLATFORM(GTK) 393 RefPtr<Connection> protector(this);394 394 m_connectionQueue->registerSocketEventHandler(m_socketDescriptor, 395 [ =] {396 protect or->readyReadHandler();395 [protectedThis] { 396 protectedThis->readyReadHandler(); 397 397 }, 398 [ =] {399 protect or->connectionDidClose();398 [protectedThis] { 399 protectedThis->connectionDidClose(); 400 400 }); 401 401 #elif PLATFORM(EFL) 402 RefPtr<Connection> protector(this);403 402 m_connectionQueue->registerSocketEventHandler(m_socketDescriptor, 404 [protect or] {405 protect or->readyReadHandler();403 [protectedThis] { 404 protectedThis->readyReadHandler(); 406 405 }); 407 406 #endif 408 407 409 // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal 410 // handler. 411 m_connectionQueue->dispatch(WTF::bind(&Connection::readyReadHandler, this)); 408 // Schedule a call to readyReadHandler. Data may have arrived before installation of the signal handler. 409 m_connectionQueue->dispatch([protectedThis] { 410 protectedThis->readyReadHandler(); 411 }); 412 412 413 413 return true;
Note:
See TracChangeset
for help on using the changeset viewer.