Diff
Modified: trunk/Source/WebKit2/ChangeLog (156359 => 156360)
--- trunk/Source/WebKit2/ChangeLog 2013-09-24 21:25:58 UTC (rev 156359)
+++ trunk/Source/WebKit2/ChangeLog 2013-09-24 21:46:18 UTC (rev 156360)
@@ -1,5 +1,33 @@
2013-09-24 Anders Carlsson <[email protected]>
+ Use std::unique_ptr for decoders as well
+ https://bugs.webkit.org/show_bug.cgi?id=121868
+
+ Reviewed by Andreas Kling.
+
+ * Platform/CoreIPC/Connection.cpp:
+ (CoreIPC::Connection::SyncMessageState::processIncomingMessage):
+ (CoreIPC::Connection::SyncMessageState::dispatchMessages):
+ (CoreIPC::Connection::waitForMessage):
+ (CoreIPC::Connection::sendSyncMessage):
+ (CoreIPC::Connection::sendSyncMessageFromSecondaryThread):
+ (CoreIPC::Connection::waitForSyncReply):
+ (CoreIPC::Connection::processIncomingSyncReply):
+ (CoreIPC::Connection::processIncomingMessage):
+ (CoreIPC::Connection::enqueueIncomingMessage):
+ (CoreIPC::Connection::dispatchMessage):
+ (CoreIPC::Connection::dispatchOneMessage):
+ * Platform/CoreIPC/Connection.h:
+ (CoreIPC::Connection::sendSync):
+ (CoreIPC::Connection::waitForAndDispatchImmediately):
+ * Platform/CoreIPC/mac/ConnectionMac.cpp:
+ (CoreIPC::createMessageDecoder):
+ (CoreIPC::Connection::receiveSourceEventHandler):
+ * WebProcess/InjectedBundle/InjectedBundle.cpp:
+ (WebKit::InjectedBundle::postSynchronousMessage):
+
+2013-09-24 Anders Carlsson <[email protected]>
+
Move MessageEncoder and ArgumentEncoder to std::unique_ptr
https://bugs.webkit.org/show_bug.cgi?id=121861
Modified: trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp (156359 => 156360)
--- trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp 2013-09-24 21:25:58 UTC (rev 156359)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Connection.cpp 2013-09-24 21:46:18 UTC (rev 156360)
@@ -53,7 +53,7 @@
// Returns true if this message will be handled on a client thread that is currently
// waiting for a reply to a synchronous message.
- bool processIncomingMessage(Connection*, OwnPtr<MessageDecoder>&);
+ bool processIncomingMessage(Connection*, std::unique_ptr<MessageDecoder>&);
// Dispatch pending sync messages. if allowedConnection is not null, will only dispatch messages
// from that connection and put the other messages back in the queue.
@@ -88,10 +88,7 @@
struct ConnectionAndIncomingMessage {
RefPtr<Connection> connection;
-
- // FIXME: https://bugs.webkit.org/show_bug.cgi?id=87594
- // This should really an be OwnPtr, but we need Vector to work with move only objects first.
- MessageDecoder* message;
+ std::unique_ptr<MessageDecoder> message;
};
Vector<ConnectionAndIncomingMessage> m_messagesToDispatchWhileWaitingForSyncReply;
};
@@ -99,7 +96,7 @@
class Connection::SecondaryThreadPendingSyncReply {
public:
// The reply decoder, will be null if there was an error processing the sync message on the other side.
- OwnPtr<MessageDecoder> replyDecoder;
+ std::unique_ptr<MessageDecoder> replyDecoder;
BinarySemaphore semaphore;
};
@@ -136,14 +133,14 @@
ASSERT(m_messagesToDispatchWhileWaitingForSyncReply.isEmpty());
}
-bool Connection::SyncMessageState::processIncomingMessage(Connection* connection, OwnPtr<MessageDecoder>& message)
+bool Connection::SyncMessageState::processIncomingMessage(Connection* connection, std::unique_ptr<MessageDecoder>& message)
{
if (!message->shouldDispatchMessageWhenWaitingForSyncReply())
return false;
ConnectionAndIncomingMessage connectionAndIncomingMessage;
connectionAndIncomingMessage.connection = connection;
- connectionAndIncomingMessage.message = message.leakPtr();
+ connectionAndIncomingMessage.message = std::move(message);
{
MutexLocker locker(m_mutex);
@@ -151,7 +148,7 @@
if (m_didScheduleDispatchMessagesWorkSet.add(connection).isNewEntry)
m_runLoop->dispatch(bind(&SyncMessageState::dispatchMessageAndResetDidScheduleDispatchMessagesForConnection, this, RefPtr<Connection>(connection)));
- m_messagesToDispatchWhileWaitingForSyncReply.append(connectionAndIncomingMessage);
+ m_messagesToDispatchWhileWaitingForSyncReply.append(std::move(connectionAndIncomingMessage));
}
wakeUpClientRunLoop();
@@ -178,16 +175,18 @@
if (allowedConnection && allowedConnection != connectionAndIncomingMessage.connection) {
// This incoming message belongs to another connection and we don't want to dispatch it now
// so mark it to be put back in the message queue.
- messagesToPutBack.append(connectionAndIncomingMessage);
+ messagesToPutBack.append(std::move(connectionAndIncomingMessage));
continue;
}
- connectionAndIncomingMessage.connection->dispatchMessage(adoptPtr(connectionAndIncomingMessage.message));
+ connectionAndIncomingMessage.connection->dispatchMessage(std::move(connectionAndIncomingMessage.message));
}
if (!messagesToPutBack.isEmpty()) {
MutexLocker locker(m_mutex);
- m_messagesToDispatchWhileWaitingForSyncReply.appendVector(messagesToPutBack);
+
+ for (auto& message : messagesToPutBack)
+ m_messagesToDispatchWhileWaitingForSyncReply.append(std::move(message));
}
}
@@ -378,17 +377,17 @@
return sendMessage(std::move(encoder));
}
-OwnPtr<MessageDecoder> Connection::waitForMessage(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, double timeout)
+std::unique_ptr<MessageDecoder> Connection::waitForMessage(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, double timeout)
{
// First, check if this message is already in the incoming messages queue.
{
MutexLocker locker(m_incomingMessagesLock);
for (auto it = m_incomingMessages.begin(), end = m_incomingMessages.end(); it != end; ++it) {
- OwnPtr<MessageDecoder>& message = *it;
+ std::unique_ptr<MessageDecoder>& message = *it;
if (message->messageReceiverName() == messageReceiverName && message->messageName() == messageName && message->destinationID() == destinationID) {
- OwnPtr<MessageDecoder> returnedMessage = std::move(message);
+ std::unique_ptr<MessageDecoder> returnedMessage = std::move(message);
m_incomingMessages.remove(it);
return returnedMessage;
@@ -414,14 +413,14 @@
while (true) {
MutexLocker locker(m_waitForMessageMutex);
- HashMap<std::pair<std::pair<StringReference, StringReference>, uint64_t>, OwnPtr<MessageDecoder>>::iterator it = m_waitForMessageMap.find(messageAndDestination);
+ auto it = m_waitForMessageMap.find(messageAndDestination);
if (it->value) {
- OwnPtr<MessageDecoder> decoder = it->value.release();
+ std::unique_ptr<MessageDecoder> decoder = std::move(it->value);
m_waitForMessageMap.remove(it);
- return decoder.release();
+ return decoder;
}
-
+
// Now we wait.
if (!m_waitForMessageCondition.timedWait(m_waitForMessageMutex, absoluteTime)) {
// We timed out, now remove the pending wait.
@@ -434,7 +433,7 @@
return nullptr;
}
-OwnPtr<MessageDecoder> Connection::sendSyncMessage(uint64_t syncRequestID, std::unique_ptr<MessageEncoder> encoder, double timeout, unsigned syncSendFlags)
+std::unique_ptr<MessageDecoder> Connection::sendSyncMessage(uint64_t syncRequestID, std::unique_ptr<MessageEncoder> encoder, double timeout, unsigned syncSendFlags)
{
if (RunLoop::current() != m_clientRunLoop) {
// No flags are supported for synchronous messages sent from secondary threads.
@@ -466,7 +465,7 @@
// Then wait for a reply. Waiting for a reply could involve dispatching incoming sync messages, so
// keep an extra reference to the connection here in case it's invalidated.
Ref<Connection> protect(*this);
- OwnPtr<MessageDecoder> reply = waitForSyncReply(syncRequestID, timeout, syncSendFlags);
+ std::unique_ptr<MessageDecoder> reply = waitForSyncReply(syncRequestID, timeout, syncSendFlags);
--m_inSendSyncCount;
@@ -480,10 +479,10 @@
if (!reply)
didFailToSendSyncMessage();
- return reply.release();
+ return reply;
}
-OwnPtr<MessageDecoder> Connection::sendSyncMessageFromSecondaryThread(uint64_t syncRequestID, std::unique_ptr<MessageEncoder> encoder, double timeout)
+std::unique_ptr<MessageDecoder> Connection::sendSyncMessageFromSecondaryThread(uint64_t syncRequestID, std::unique_ptr<MessageEncoder> encoder, double timeout)
{
ASSERT(RunLoop::current() != m_clientRunLoop);
@@ -520,7 +519,7 @@
return std::move(pendingReply.replyDecoder);
}
-OwnPtr<MessageDecoder> Connection::waitForSyncReply(uint64_t syncRequestID, double timeout, unsigned syncSendFlags)
+std::unique_ptr<MessageDecoder> Connection::waitForSyncReply(uint64_t syncRequestID, double timeout, unsigned syncSendFlags)
{
// Use a really long timeout.
if (timeout == NoTimeout)
@@ -572,7 +571,7 @@
return nullptr;
}
-void Connection::processIncomingSyncReply(OwnPtr<MessageDecoder> decoder)
+void Connection::processIncomingSyncReply(std::unique_ptr<MessageDecoder> decoder)
{
MutexLocker locker(m_syncReplyStateMutex);
@@ -609,13 +608,13 @@
// This can happen if the send timed out, so it's fine to ignore.
}
-void Connection::processIncomingMessage(OwnPtr<MessageDecoder> message)
+void Connection::processIncomingMessage(std::unique_ptr<MessageDecoder> message)
{
ASSERT(!message->messageReceiverName().isEmpty());
ASSERT(!message->messageName().isEmpty());
if (message->messageReceiverName() == "IPC" && message->messageName() == "SyncMessageReply") {
- processIncomingSyncReply(message.release());
+ processIncomingSyncReply(std::move(message));
return;
}
@@ -636,7 +635,7 @@
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().leakPtr()));
+ it->value.first->dispatch(bind(&Connection::dispatchWorkQueueMessageReceiverMessage, this, it->value.second, message.release()));
return;
}
@@ -652,7 +651,7 @@
auto it = m_waitForMessageMap.find(std::make_pair(std::make_pair(message->messageReceiverName(), message->messageName()), message->destinationID()));
if (it != m_waitForMessageMap.end()) {
- it->value = message.release();
+ it->value = std::move(message);
ASSERT(it->value);
m_waitForMessageCondition.signal();
@@ -660,7 +659,7 @@
}
}
- enqueueIncomingMessage(message.release());
+ enqueueIncomingMessage(std::move(message));
}
void Connection::postConnectionDidCloseOnConnectionWorkQueue()
@@ -774,7 +773,7 @@
exit(0);
}
-void Connection::enqueueIncomingMessage(OwnPtr<MessageDecoder> incomingMessage)
+void Connection::enqueueIncomingMessage(std::unique_ptr<MessageDecoder> incomingMessage)
{
{
MutexLocker locker(m_incomingMessagesLock);
@@ -789,7 +788,7 @@
m_client->didReceiveMessage(this, decoder);
}
-void Connection::dispatchMessage(OwnPtr<MessageDecoder> message)
+void Connection::dispatchMessage(std::unique_ptr<MessageDecoder> message)
{
// If there's no client, return. We do this after calling releaseArguments so that
// the ArgumentDecoder message will be freed.
@@ -823,7 +822,7 @@
void Connection::dispatchOneMessage()
{
- OwnPtr<MessageDecoder> message;
+ std::unique_ptr<MessageDecoder> message;
{
MutexLocker locker(m_incomingMessagesLock);
@@ -833,7 +832,7 @@
message = m_incomingMessages.takeFirst();
}
- dispatchMessage(message.release());
+ dispatchMessage(std::move(message));
}
void Connection::wakeUpRunLoop()
Modified: trunk/Source/WebKit2/Platform/CoreIPC/Connection.h (156359 => 156360)
--- trunk/Source/WebKit2/Platform/CoreIPC/Connection.h 2013-09-24 21:25:58 UTC (rev 156359)
+++ trunk/Source/WebKit2/Platform/CoreIPC/Connection.h 2013-09-24 21:46:18 UTC (rev 156360)
@@ -175,8 +175,8 @@
std::unique_ptr<MessageEncoder> createSyncMessageEncoder(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, uint64_t& syncRequestID);
bool sendMessage(std::unique_ptr<MessageEncoder>, unsigned messageSendFlags = 0);
- OwnPtr<MessageDecoder> sendSyncMessage(uint64_t syncRequestID, std::unique_ptr<MessageEncoder>, double timeout, unsigned syncSendFlags = 0);
- OwnPtr<MessageDecoder> sendSyncMessageFromSecondaryThread(uint64_t syncRequestID, std::unique_ptr<MessageEncoder>, double timeout);
+ std::unique_ptr<MessageDecoder> sendSyncMessage(uint64_t syncRequestID, std::unique_ptr<MessageEncoder>, double timeout, unsigned syncSendFlags = 0);
+ std::unique_ptr<MessageDecoder> sendSyncMessageFromSecondaryThread(uint64_t syncRequestID, std::unique_ptr<MessageEncoder>, double timeout);
bool sendSyncReply(std::unique_ptr<MessageEncoder>);
void wakeUpRunLoop();
@@ -193,13 +193,13 @@
bool isValid() const { return m_client; }
- OwnPtr<MessageDecoder> waitForMessage(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, double timeout);
+ std::unique_ptr<MessageDecoder> waitForMessage(StringReference messageReceiverName, StringReference messageName, uint64_t destinationID, double timeout);
- OwnPtr<MessageDecoder> waitForSyncReply(uint64_t syncRequestID, double timeout, unsigned syncSendFlags);
+ std::unique_ptr<MessageDecoder> waitForSyncReply(uint64_t syncRequestID, double timeout, unsigned syncSendFlags);
// Called on the connection work queue.
- void processIncomingMessage(OwnPtr<MessageDecoder>);
- void processIncomingSyncReply(OwnPtr<MessageDecoder>);
+ void processIncomingMessage(std::unique_ptr<MessageDecoder>);
+ void processIncomingSyncReply(std::unique_ptr<MessageDecoder>);
void addWorkQueueMessageReceiverOnConnectionWorkQueue(StringReference messageReceiverName, WorkQueue*, WorkQueueMessageReceiver*);
void removeWorkQueueMessageReceiverOnConnectionWorkQueue(StringReference messageReceiverName);
@@ -214,14 +214,14 @@
// Called on the listener thread.
void dispatchConnectionDidClose();
void dispatchOneMessage();
- void dispatchMessage(OwnPtr<MessageDecoder>);
+ void dispatchMessage(std::unique_ptr<MessageDecoder>);
void dispatchMessage(MessageDecoder&);
void dispatchSyncMessage(MessageDecoder&);
void dispatchDidReceiveInvalidMessage(const CString& messageReceiverNameString, const CString& messageNameString);
void didFailToSendSyncMessage();
// Can be called on any thread.
- void enqueueIncomingMessage(OwnPtr<MessageDecoder>);
+ void enqueueIncomingMessage(std::unique_ptr<MessageDecoder>);
Client* m_client;
bool m_isServer;
@@ -244,7 +244,7 @@
// Incoming messages.
Mutex m_incomingMessagesLock;
- Deque<OwnPtr<MessageDecoder>> m_incomingMessages;
+ Deque<std::unique_ptr<MessageDecoder>> m_incomingMessages;
// Outgoing messages.
Mutex m_outgoingMessagesLock;
@@ -252,7 +252,7 @@
ThreadCondition m_waitForMessageCondition;
Mutex m_waitForMessageMutex;
- HashMap<std::pair<std::pair<StringReference, StringReference>, uint64_t>, OwnPtr<MessageDecoder>> m_waitForMessageMap;
+ HashMap<std::pair<std::pair<StringReference, StringReference>, uint64_t>, std::unique_ptr<MessageDecoder>> m_waitForMessageMap;
// Represents a sync request for which we're waiting on a reply.
struct PendingSyncReply {
@@ -261,7 +261,7 @@
// The reply decoder, will be null if there was an error processing the sync
// message on the other side.
- OwnPtr<MessageDecoder> replyDecoder;
+ std::unique_ptr<MessageDecoder> replyDecoder;
// Will be set to true once a reply has been received.
bool didReceiveReply;
@@ -366,7 +366,7 @@
encoder->encode(message);
// Now send the message and wait for a reply.
- OwnPtr<MessageDecoder> replyDecoder = sendSyncMessage(syncRequestID, std::move(encoder), timeout, syncSendFlags);
+ std::unique_ptr<MessageDecoder> replyDecoder = sendSyncMessage(syncRequestID, std::move(encoder), timeout, syncSendFlags);
if (!replyDecoder)
return false;
@@ -376,7 +376,7 @@
template<typename T> bool Connection::waitForAndDispatchImmediately(uint64_t destinationID, double timeout)
{
- OwnPtr<MessageDecoder> decoder = waitForMessage(T::receiverName(), T::name(), destinationID, timeout);
+ std::unique_ptr<MessageDecoder> decoder = waitForMessage(T::receiverName(), T::name(), destinationID, timeout);
if (!decoder)
return false;
Modified: trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp (156359 => 156360)
--- trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp 2013-09-24 21:25:58 UTC (rev 156359)
+++ trunk/Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp 2013-09-24 21:46:18 UTC (rev 156360)
@@ -299,14 +299,14 @@
});
}
-static OwnPtr<MessageDecoder> createMessageDecoder(mach_msg_header_t* header)
+static std::unique_ptr<MessageDecoder> createMessageDecoder(mach_msg_header_t* header)
{
if (!(header->msgh_bits & MACH_MSGH_BITS_COMPLEX)) {
// We have a simple message.
uint8_t* body = reinterpret_cast<uint8_t*>(header + 1);
size_t bodySize = header->msgh_size - sizeof(mach_msg_header_t);
- return createOwned<MessageDecoder>(DataReference(body, bodySize), Vector<Attachment>());
+ return std::make_unique<MessageDecoder>(DataReference(body, bodySize), Vector<Attachment>());
}
bool messageBodyIsOOL = header->msgh_id & MessageBodyIsOutOfLine;
@@ -351,7 +351,7 @@
uint8_t* messageBody = static_cast<uint8_t*>(messageBodyAttachment.address());
size_t messageBodySize = messageBodyAttachment.size();
- OwnPtr<MessageDecoder> decoder = createOwned<MessageDecoder>(DataReference(messageBody, messageBodySize), std::move(attachments));
+ auto decoder = std::make_unique<MessageDecoder>(DataReference(messageBody, messageBodySize), std::move(attachments));
vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(messageBodyAttachment.address()), messageBodyAttachment.size());
@@ -361,7 +361,7 @@
uint8_t* messageBody = descriptorData;
size_t messageBodySize = header->msgh_size - (descriptorData - reinterpret_cast<uint8_t*>(header));
- return createOwned<MessageDecoder>(DataReference(messageBody, messageBodySize), attachments);
+ return std::make_unique<MessageDecoder>(DataReference(messageBody, messageBodySize), attachments);
}
// The receive buffer size should always include the maximum trailer size.
@@ -402,7 +402,7 @@
if (!header)
return;
- OwnPtr<MessageDecoder> decoder = createMessageDecoder(header);
+ std::unique_ptr<MessageDecoder> decoder = createMessageDecoder(header);
ASSERT(decoder);
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
@@ -449,7 +449,7 @@
return;
}
- processIncomingMessage(decoder.release());
+ processIncomingMessage(std::move(decoder));
}
void Connection::exceptionSourceEventHandler()
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp (156359 => 156360)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp 2013-09-24 21:25:58 UTC (rev 156359)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp 2013-09-24 21:46:18 UTC (rev 156360)
@@ -117,7 +117,7 @@
encoder->encode(messageName);
encoder->encode(InjectedBundleUserMessageEncoder(messageBody));
- OwnPtr<CoreIPC::MessageDecoder> replyDecoder = WebProcess::shared().parentProcessConnection()->sendSyncMessage(syncRequestID, std::move(encoder), CoreIPC::Connection::NoTimeout);
+ std::unique_ptr<CoreIPC::MessageDecoder> replyDecoder = WebProcess::shared().parentProcessConnection()->sendSyncMessage(syncRequestID, std::move(encoder), CoreIPC::Connection::NoTimeout);
if (!replyDecoder || !replyDecoder->decode(messageDecoder)) {
returnData = nullptr;
return;