Changeset 141465 in webkit


Ignore:
Timestamp:
Jan 31, 2013 12:47:12 PM (11 years ago)
Author:
andersca@apple.com
Message:

Get rid of IncomingMessage
https://bugs.webkit.org/show_bug.cgi?id=108514

Reviewed by Sam Weinig.

  • Platform/CoreIPC/Connection.cpp:

(Connection::SyncMessageState):
(ConnectionAndIncomingMessage):
(CoreIPC::Connection::SyncMessageState::~SyncMessageState):
(CoreIPC::Connection::SyncMessageState::processIncomingMessage):
(CoreIPC::Connection::SyncMessageState::dispatchMessages):
(CoreIPC::Connection::waitForMessage):
(CoreIPC::Connection::processIncomingMessage):
(CoreIPC::Connection::enqueueIncomingMessage):
(CoreIPC::Connection::dispatchMessage):
(CoreIPC::Connection::dispatchOneMessage):

  • Platform/CoreIPC/Connection.h:

(Connection):

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r141463 r141465  
     12013-01-31  Anders Carlsson  <andersca@apple.com>
     2
     3        Get rid of IncomingMessage
     4        https://bugs.webkit.org/show_bug.cgi?id=108514
     5
     6        Reviewed by Sam Weinig.
     7
     8        * Platform/CoreIPC/Connection.cpp:
     9        (Connection::SyncMessageState):
     10        (ConnectionAndIncomingMessage):
     11        (CoreIPC::Connection::SyncMessageState::~SyncMessageState):
     12        (CoreIPC::Connection::SyncMessageState::processIncomingMessage):
     13        (CoreIPC::Connection::SyncMessageState::dispatchMessages):
     14        (CoreIPC::Connection::waitForMessage):
     15        (CoreIPC::Connection::processIncomingMessage):
     16        (CoreIPC::Connection::enqueueIncomingMessage):
     17        (CoreIPC::Connection::dispatchMessage):
     18        (CoreIPC::Connection::dispatchOneMessage):
     19        * Platform/CoreIPC/Connection.h:
     20        (Connection):
     21
    1222013-01-31  Patrick Gansterer  <paroga@webkit.org>
    223
  • trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp

    r141432 r141465  
    5353    // Returns true if this message will be handled on a client thread that is currently
    5454    // waiting for a reply to a synchronous message.
    55     bool processIncomingMessage(Connection*, IncomingMessage&);
     55    bool processIncomingMessage(Connection*, OwnPtr<MessageDecoder>&);
    5656
    5757    // Dispatch pending sync messages. if allowedConnection is not null, will only dispatch messages
     
    8888    struct ConnectionAndIncomingMessage {
    8989        RefPtr<Connection> connection;
    90         IncomingMessage incomingMessage;
     90
     91        // FIXME: https://bugs.webkit.org/show_bug.cgi?id=87594
     92        // This should really an be OwnPtr, but we need Vector to work with move only objects first.
     93        MessageDecoder* message;
    9194    };
    9295    Vector<ConnectionAndIncomingMessage> m_messagesToDispatchWhileWaitingForSyncReply;
     
    132135    ASSERT(syncMessageStateMap().contains(m_runLoop));
    133136    syncMessageStateMap().remove(m_runLoop);
    134 }
    135 
    136 bool Connection::SyncMessageState::processIncomingMessage(Connection* connection, IncomingMessage& incomingMessage)
    137 {
    138     if (!incomingMessage.arguments()->shouldDispatchMessageWhenWaitingForSyncReply())
     137
     138    ASSERT(m_messagesToDispatchWhileWaitingForSyncReply.isEmpty());
     139}
     140
     141bool Connection::SyncMessageState::processIncomingMessage(Connection* connection, OwnPtr<MessageDecoder>& message)
     142{
     143    if (!message->shouldDispatchMessageWhenWaitingForSyncReply())
    139144        return false;
    140145
    141146    ConnectionAndIncomingMessage connectionAndIncomingMessage;
    142147    connectionAndIncomingMessage.connection = connection;
    143     connectionAndIncomingMessage.incomingMessage = incomingMessage;
     148    connectionAndIncomingMessage.message = message.leakPtr();
    144149
    145150    {
     
    180185        }
    181186
    182         connectionAndIncomingMessage.connection->dispatchMessage(connectionAndIncomingMessage.incomingMessage);
     187        connectionAndIncomingMessage.connection->dispatchMessage(adoptPtr(connectionAndIncomingMessage.message));
    183188    }
    184189
     
    347352        MutexLocker locker(m_incomingMessagesLock);
    348353
    349         for (Deque<IncomingMessage>::iterator it = m_incomingMessages.begin(), end = m_incomingMessages.end(); it != end; ++it) {
    350             IncomingMessage& message = *it;
    351 
    352             if (message.arguments()->messageReceiverName() == messageReceiverName && message.arguments()->messageName() == messageName && message.arguments()->destinationID() == destinationID) {
    353                 OwnPtr<MessageDecoder> decoder = message.releaseArguments();
     354        for (Deque<OwnPtr<MessageDecoder> >::iterator it = m_incomingMessages.begin(), end = m_incomingMessages.end(); it != end; ++it) {
     355            OwnPtr<MessageDecoder>& message = *it;
     356
     357            if (message->messageReceiverName() == messageReceiverName && message->messageName() == messageName && message->destinationID() == destinationID) {
     358                OwnPtr<MessageDecoder> returnedMessage = message.release();
    354359
    355360                m_incomingMessages.remove(it);
    356                 return decoder.release();
     361                return returnedMessage.release();
    357362            }
    358363        }
     
    568573}
    569574
    570 void Connection::processIncomingMessage(MessageID messageID, PassOwnPtr<MessageDecoder> decoder)
    571 {
    572     if (decoder->messageReceiverName() == "IPC" && decoder->messageName() == "SyncMessageReply") {
    573         processIncomingSyncReply(decoder);
    574         return;
    575     }
    576 
    577     IncomingMessage incomingMessage(messageID, decoder);
     575void Connection::processIncomingMessage(MessageID messageID, PassOwnPtr<MessageDecoder> incomingMessage)
     576{
     577    OwnPtr<MessageDecoder> message = incomingMessage;
     578
     579    if (message->messageReceiverName() == "IPC" && message->messageName() == "SyncMessageReply") {
     580        processIncomingSyncReply(message.release());
     581        return;
     582    }
    578583
    579584    // Check if this is a sync message or if it's a message that should be dispatched even when waiting for
    580585    // a sync reply. If it is, and we're waiting for a sync reply this message needs to be dispatched.
    581586    // If we don't we'll end up with a deadlock where both sync message senders are stuck waiting for a reply.
    582     if (m_syncMessageState->processIncomingMessage(this, incomingMessage))
     587    if (m_syncMessageState->processIncomingMessage(this, message))
    583588        return;
    584589
     
    587592        MutexLocker locker(m_waitForMessageMutex);
    588593
    589         HashMap<std::pair<std::pair<StringReference, StringReference>, uint64_t>, OwnPtr<MessageDecoder> >::iterator it = m_waitForMessageMap.find(std::make_pair(std::make_pair(incomingMessage.arguments()->messageReceiverName(), incomingMessage.arguments()->messageName()), incomingMessage.destinationID()));
     594        HashMap<std::pair<std::pair<StringReference, StringReference>, uint64_t>, OwnPtr<MessageDecoder> >::iterator it = m_waitForMessageMap.find(std::make_pair(std::make_pair(message->messageReceiverName(), message->messageName()), message->destinationID()));
    590595        if (it != m_waitForMessageMap.end()) {
    591             it->value = incomingMessage.releaseArguments();
     596            it->value = message.release();
    592597            ASSERT(it->value);
    593598       
     
    601606        bool didHandleMessage = false;
    602607
    603         MessageDecoder* decoder = incomingMessage.arguments();
    604         m_connectionQueueClients[i]->didReceiveMessageOnConnectionWorkQueue(this, *decoder, didHandleMessage);
     608        m_connectionQueueClients[i]->didReceiveMessageOnConnectionWorkQueue(this, *message, didHandleMessage);
    605609        if (didHandleMessage) {
    606610            // A connection queue client handled the message, our work here is done.
    607             incomingMessage.releaseArguments();
    608611            return;
    609612        }
    610613    }
    611614
    612     enqueueIncomingMessage(incomingMessage);
     615    enqueueIncomingMessage(message.release());
    613616}
    614617
     
    714717}
    715718
    716 void Connection::enqueueIncomingMessage(IncomingMessage& incomingMessage)
     719void Connection::enqueueIncomingMessage(PassOwnPtr<MessageDecoder> incomingMessage)
    717720{
    718721    {
     
    729732}
    730733
    731 void Connection::dispatchMessage(IncomingMessage& message)
    732 {
    733     OwnPtr<MessageDecoder> arguments = message.releaseArguments();
     734void Connection::dispatchMessage(PassOwnPtr<MessageDecoder> incomingMessage)
     735{
     736    OwnPtr<MessageDecoder> message = incomingMessage;
    734737
    735738    // If there's no client, return. We do this after calling releaseArguments so that
     
    740743    m_inDispatchMessageCount++;
    741744
    742     if (arguments->shouldDispatchMessageWhenWaitingForSyncReply())
     745    if (message->shouldDispatchMessageWhenWaitingForSyncReply())
    743746        m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount++;
    744747
     
    746749    m_didReceiveInvalidMessage = false;
    747750
    748     if (arguments->isSyncMessage())
    749         dispatchSyncMessage(message.messageID(), *arguments);
     751    if (message->isSyncMessage())
     752        dispatchSyncMessage(MessageID(), *message);
    750753    else
    751         dispatchMessage(message.messageID(), *arguments);
    752 
    753     m_didReceiveInvalidMessage |= arguments->isInvalid();
     754        dispatchMessage(MessageID(), *message);
     755
     756    m_didReceiveInvalidMessage |= message->isInvalid();
    754757    m_inDispatchMessageCount--;
    755758
    756     if (arguments->shouldDispatchMessageWhenWaitingForSyncReply())
     759    if (message->shouldDispatchMessageWhenWaitingForSyncReply())
    757760        m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount--;
    758761
    759762    if (m_didReceiveInvalidMessage && m_client)
    760         m_client->didReceiveInvalidMessage(this, arguments->messageReceiverName(), arguments->messageName());
     763        m_client->didReceiveInvalidMessage(this, message->messageReceiverName(), message->messageName());
    761764
    762765    m_didReceiveInvalidMessage = oldDidReceiveInvalidMessage;
     
    765768void Connection::dispatchOneMessage()
    766769{
    767     IncomingMessage incomingMessage;
     770    OwnPtr<MessageDecoder> message;
    768771
    769772    {
     
    772775            return;
    773776
    774         incomingMessage = m_incomingMessages.takeFirst();
    775     }
    776 
    777     dispatchMessage(incomingMessage);
     777        message = m_incomingMessages.takeFirst();
     778    }
     779
     780    dispatchMessage(message.release());
    778781}
    779782
  • trunk/Source/WebKit2/Platform/CoreIPC/Connection.h

    r141442 r141465  
    193193
    194194private:
    195     template<typename T> class Message {
    196     public:
    197         Message()
    198             : m_arguments(0)
    199         {
    200         }
    201 
    202         Message(MessageID messageID, PassOwnPtr<T> arguments)
    203             : m_messageID(messageID)
    204             , m_arguments(arguments.leakPtr())
    205         {
    206         }
    207        
    208         MessageID messageID() const { return m_messageID; }
    209         uint64_t destinationID() const { return m_arguments->destinationID(); }
    210 
    211         T* arguments() const { return m_arguments; }
    212        
    213         PassOwnPtr<T> releaseArguments()
    214         {
    215             OwnPtr<T> arguments = adoptPtr(m_arguments);
    216             m_arguments = 0;
    217 
    218             return arguments.release();
    219         }
    220        
    221     private:
    222         MessageID m_messageID;
    223         // The memory management of this class is very unusual. The class acts
    224         // as if it has an owning reference to m_arguments (e.g., accepting a
    225         // PassOwnPtr in its constructor) in all ways except that it does not
    226         // deallocate m_arguments on destruction.
    227         // FIXME: Does this leak m_arguments on destruction?
    228         T* m_arguments;
    229     };
    230 
    231195    Connection(Identifier, bool isServer, Client*, WebCore::RunLoop* clientRunLoop);
    232196    void platformInitialize(Identifier);
     
    252216    void connectionDidClose();
    253217   
    254     typedef Message<MessageDecoder> IncomingMessage;
    255 
    256218    // Called on the listener thread.
    257219    void dispatchConnectionDidClose();
    258220    void dispatchOneMessage();
    259     void dispatchMessage(IncomingMessage&);
     221    void dispatchMessage(PassOwnPtr<MessageDecoder>);
    260222    void dispatchMessage(MessageID, MessageDecoder&);
    261223    void dispatchSyncMessage(MessageID, MessageDecoder&);
     
    263225
    264226    // Can be called on any thread.
    265     void enqueueIncomingMessage(IncomingMessage&);
     227    void enqueueIncomingMessage(PassOwnPtr<MessageDecoder>);
    266228
    267229    Client* m_client;
     
    285247    // Incoming messages.
    286248    Mutex m_incomingMessagesLock;
    287     Deque<IncomingMessage> m_incomingMessages;
     249    Deque<OwnPtr<MessageDecoder> > m_incomingMessages;
    288250
    289251    // Outgoing messages.
Note: See TracChangeset for help on using the changeset viewer.