⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181630 in webkit


Ignore:
Timestamp:
Mar 17, 2015, 3:04:34 AM (11 years ago)
Author:
zandobersek@gmail.com
Message:

[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):

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r181629 r181630  
     12015-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
    1262015-03-17  Zan Dobersek  <zdobersek@igalia.com>
    227
  • trunk/Source/WebKit2/Platform/IPC/Connection.cpp

    r179592 r181630  
    301301}
    302302
    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);
     303void Connection::dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver& workQueueMessageReceiver, MessageDecoder& decoder)
     304{
     305    if (!decoder.isSyncMessage()) {
     306        workQueueMessageReceiver.didReceiveMessage(*this, decoder);
    309307        return;
    310308    }
    311309
    312310    uint64_t syncRequestID = 0;
    313     if (!decoder->decode(syncRequestID) || !syncRequestID) {
     311    if (!decoder.decode(syncRequestID) || !syncRequestID) {
    314312        // We received an invalid sync message.
    315313        // FIXME: Handle this.
    316         decoder->markInvalid();
     314        decoder.markInvalid();
    317315        return;
    318316    }
    319317
    320318#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());
    322320#else
    323321    auto replyEncoder = std::make_unique<MessageEncoder>("IPC", "SyncMessageReply", syncRequestID);
     
    325323
    326324    // 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);
    328326
    329327    // FIXME: If the message was invalid, we should send back a SyncMessageError.
    330     ASSERT(!decoder->isInvalid());
     328    ASSERT(!decoder.isInvalid());
    331329
    332330    if (replyEncoder)
     
    348346    }
    349347   
    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    });
    354354}
    355355
     
    398398   
    399399    // 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    });
    401404    return true;
    402405}
     
    654657
    655658    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        });
    667668        return;
    668669    }
     
    670671    auto it = m_workQueueMessageReceivers.find(message->messageReceiverName());
    671672    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        });
    673680        return;
    674681    }
     
    830837    }
    831838
    832     m_clientRunLoop.dispatch(WTF::bind(&Connection::dispatchOneMessage, this));
     839    RefPtr<Connection> protectedThis(this);
     840    m_clientRunLoop.dispatch([protectedThis] {
     841        protectedThis->dispatchOneMessage();
     842    });
    833843}
    834844
  • trunk/Source/WebKit2/Platform/IPC/Connection.h

    r180410 r181630  
    214214    void processIncomingSyncReply(std::unique_ptr<MessageDecoder>);
    215215
    216     void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver*, MessageDecoder*);
     216    void dispatchWorkQueueMessageReceiverMessage(WorkQueueMessageReceiver&, MessageDecoder&);
    217217
    218218    bool canSendOutgoingMessages() const;
  • trunk/Source/WebKit2/Platform/IPC/mac/ConnectionMac.mm

    r180054 r181630  
    511511        if (m_isServer) {
    512512            // 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            });
    514521            return;
    515522        }
  • trunk/Source/WebKit2/Platform/IPC/unix/ConnectionUnix.cpp

    r176762 r181630  
    389389    }
    390390
     391    RefPtr<Connection> protectedThis(this);
    391392    m_isConnected = true;
    392393#if PLATFORM(GTK)
    393     RefPtr<Connection> protector(this);
    394394    m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
    395         [=] {
    396             protector->readyReadHandler();
     395        [protectedThis] {
     396            protectedThis->readyReadHandler();
    397397        },
    398         [=] {
    399             protector->connectionDidClose();
     398        [protectedThis] {
     399            protectedThis->connectionDidClose();
    400400        });
    401401#elif PLATFORM(EFL)
    402     RefPtr<Connection> protector(this);
    403402    m_connectionQueue->registerSocketEventHandler(m_socketDescriptor,
    404         [protector] {
    405             protector->readyReadHandler();
     403        [protectedThis] {
     404            protectedThis->readyReadHandler();
    406405        });
    407406#endif
    408407
    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    });
    412412
    413413    return true;
Note: See TracChangeset for help on using the changeset viewer.