Changeset 141465 in webkit
- Timestamp:
- Jan 31, 2013 12:47:12 PM (11 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r141463 r141465 1 2013-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 1 22 2013-01-31 Patrick Gansterer <paroga@webkit.org> 2 23 -
trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp
r141432 r141465 53 53 // Returns true if this message will be handled on a client thread that is currently 54 54 // waiting for a reply to a synchronous message. 55 bool processIncomingMessage(Connection*, IncomingMessage&);55 bool processIncomingMessage(Connection*, OwnPtr<MessageDecoder>&); 56 56 57 57 // Dispatch pending sync messages. if allowedConnection is not null, will only dispatch messages … … 88 88 struct ConnectionAndIncomingMessage { 89 89 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; 91 94 }; 92 95 Vector<ConnectionAndIncomingMessage> m_messagesToDispatchWhileWaitingForSyncReply; … … 132 135 ASSERT(syncMessageStateMap().contains(m_runLoop)); 133 136 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 141 bool Connection::SyncMessageState::processIncomingMessage(Connection* connection, OwnPtr<MessageDecoder>& message) 142 { 143 if (!message->shouldDispatchMessageWhenWaitingForSyncReply()) 139 144 return false; 140 145 141 146 ConnectionAndIncomingMessage connectionAndIncomingMessage; 142 147 connectionAndIncomingMessage.connection = connection; 143 connectionAndIncomingMessage. incomingMessage = incomingMessage;148 connectionAndIncomingMessage.message = message.leakPtr(); 144 149 145 150 { … … 180 185 } 181 186 182 connectionAndIncomingMessage.connection->dispatchMessage( connectionAndIncomingMessage.incomingMessage);187 connectionAndIncomingMessage.connection->dispatchMessage(adoptPtr(connectionAndIncomingMessage.message)); 183 188 } 184 189 … … 347 352 MutexLocker locker(m_incomingMessagesLock); 348 353 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(); 354 359 355 360 m_incomingMessages.remove(it); 356 return decoder.release();361 return returnedMessage.release(); 357 362 } 358 363 } … … 568 573 } 569 574 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);575 void 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 } 578 583 579 584 // Check if this is a sync message or if it's a message that should be dispatched even when waiting for 580 585 // a sync reply. If it is, and we're waiting for a sync reply this message needs to be dispatched. 581 586 // 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)) 583 588 return; 584 589 … … 587 592 MutexLocker locker(m_waitForMessageMutex); 588 593 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())); 590 595 if (it != m_waitForMessageMap.end()) { 591 it->value = incomingMessage.releaseArguments();596 it->value = message.release(); 592 597 ASSERT(it->value); 593 598 … … 601 606 bool didHandleMessage = false; 602 607 603 MessageDecoder* decoder = incomingMessage.arguments(); 604 m_connectionQueueClients[i]->didReceiveMessageOnConnectionWorkQueue(this, *decoder, didHandleMessage); 608 m_connectionQueueClients[i]->didReceiveMessageOnConnectionWorkQueue(this, *message, didHandleMessage); 605 609 if (didHandleMessage) { 606 610 // A connection queue client handled the message, our work here is done. 607 incomingMessage.releaseArguments();608 611 return; 609 612 } 610 613 } 611 614 612 enqueueIncomingMessage( incomingMessage);615 enqueueIncomingMessage(message.release()); 613 616 } 614 617 … … 714 717 } 715 718 716 void Connection::enqueueIncomingMessage( IncomingMessage&incomingMessage)719 void Connection::enqueueIncomingMessage(PassOwnPtr<MessageDecoder> incomingMessage) 717 720 { 718 721 { … … 729 732 } 730 733 731 void Connection::dispatchMessage( IncomingMessage& message)732 { 733 OwnPtr<MessageDecoder> arguments = message.releaseArguments();734 void Connection::dispatchMessage(PassOwnPtr<MessageDecoder> incomingMessage) 735 { 736 OwnPtr<MessageDecoder> message = incomingMessage; 734 737 735 738 // If there's no client, return. We do this after calling releaseArguments so that … … 740 743 m_inDispatchMessageCount++; 741 744 742 if ( arguments->shouldDispatchMessageWhenWaitingForSyncReply())745 if (message->shouldDispatchMessageWhenWaitingForSyncReply()) 743 746 m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount++; 744 747 … … 746 749 m_didReceiveInvalidMessage = false; 747 750 748 if ( arguments->isSyncMessage())749 dispatchSyncMessage( message.messageID(), *arguments);751 if (message->isSyncMessage()) 752 dispatchSyncMessage(MessageID(), *message); 750 753 else 751 dispatchMessage( message.messageID(), *arguments);752 753 m_didReceiveInvalidMessage |= arguments->isInvalid();754 dispatchMessage(MessageID(), *message); 755 756 m_didReceiveInvalidMessage |= message->isInvalid(); 754 757 m_inDispatchMessageCount--; 755 758 756 if ( arguments->shouldDispatchMessageWhenWaitingForSyncReply())759 if (message->shouldDispatchMessageWhenWaitingForSyncReply()) 757 760 m_inDispatchMessageMarkedDispatchWhenWaitingForSyncReplyCount--; 758 761 759 762 if (m_didReceiveInvalidMessage && m_client) 760 m_client->didReceiveInvalidMessage(this, arguments->messageReceiverName(), arguments->messageName());763 m_client->didReceiveInvalidMessage(this, message->messageReceiverName(), message->messageName()); 761 764 762 765 m_didReceiveInvalidMessage = oldDidReceiveInvalidMessage; … … 765 768 void Connection::dispatchOneMessage() 766 769 { 767 IncomingMessage incomingMessage;770 OwnPtr<MessageDecoder> message; 768 771 769 772 { … … 772 775 return; 773 776 774 incomingMessage = m_incomingMessages.takeFirst();775 } 776 777 dispatchMessage( incomingMessage);777 message = m_incomingMessages.takeFirst(); 778 } 779 780 dispatchMessage(message.release()); 778 781 } 779 782 -
trunk/Source/WebKit2/Platform/CoreIPC/Connection.h
r141442 r141465 193 193 194 194 private: 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 acts224 // as if it has an owning reference to m_arguments (e.g., accepting a225 // PassOwnPtr in its constructor) in all ways except that it does not226 // deallocate m_arguments on destruction.227 // FIXME: Does this leak m_arguments on destruction?228 T* m_arguments;229 };230 231 195 Connection(Identifier, bool isServer, Client*, WebCore::RunLoop* clientRunLoop); 232 196 void platformInitialize(Identifier); … … 252 216 void connectionDidClose(); 253 217 254 typedef Message<MessageDecoder> IncomingMessage;255 256 218 // Called on the listener thread. 257 219 void dispatchConnectionDidClose(); 258 220 void dispatchOneMessage(); 259 void dispatchMessage( IncomingMessage&);221 void dispatchMessage(PassOwnPtr<MessageDecoder>); 260 222 void dispatchMessage(MessageID, MessageDecoder&); 261 223 void dispatchSyncMessage(MessageID, MessageDecoder&); … … 263 225 264 226 // Can be called on any thread. 265 void enqueueIncomingMessage( IncomingMessage&);227 void enqueueIncomingMessage(PassOwnPtr<MessageDecoder>); 266 228 267 229 Client* m_client; … … 285 247 // Incoming messages. 286 248 Mutex m_incomingMessagesLock; 287 Deque< IncomingMessage> m_incomingMessages;249 Deque<OwnPtr<MessageDecoder> > m_incomingMessages; 288 250 289 251 // Outgoing messages.
Note: See TracChangeset
for help on using the changeset viewer.