Remove create functions from MessageDecoder and ArgumentDecoder
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Sep 2013 19:23:13 +0000 (19:23 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Sep 2013 19:23:13 +0000 (19:23 +0000)
https://bugs.webkit.org/show_bug.cgi?id=121850

Reviewed by Antti Koivisto.

* Platform/CoreIPC/ArgumentDecoder.cpp:
(CoreIPC::ArgumentDecoder::ArgumentDecoder):
* Platform/CoreIPC/ArgumentDecoder.h:
* Platform/CoreIPC/MessageDecoder.cpp:
(CoreIPC::MessageDecoder::MessageDecoder):
* Platform/CoreIPC/MessageDecoder.h:
* Platform/CoreIPC/mac/ConnectionMac.cpp:
(CoreIPC::createMessageDecoder):
* WebProcess/WebPage/DecoderAdapter.cpp:
(WebKit::DecoderAdapter::DecoderAdapter):
(WebKit::DecoderAdapter::decodeBytes):
(WebKit::DecoderAdapter::decodeBool):
(WebKit::DecoderAdapter::decodeUInt16):
(WebKit::DecoderAdapter::decodeUInt32):
(WebKit::DecoderAdapter::decodeUInt64):
(WebKit::DecoderAdapter::decodeInt32):
(WebKit::DecoderAdapter::decodeInt64):
(WebKit::DecoderAdapter::decodeFloat):
(WebKit::DecoderAdapter::decodeDouble):
(WebKit::DecoderAdapter::decodeString):
* WebProcess/WebPage/DecoderAdapter.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::postInjectedBundleMessage):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156349 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/Platform/CoreIPC/ArgumentDecoder.cpp
Source/WebKit2/Platform/CoreIPC/ArgumentDecoder.h
Source/WebKit2/Platform/CoreIPC/MessageDecoder.cpp
Source/WebKit2/Platform/CoreIPC/MessageDecoder.h
Source/WebKit2/Platform/CoreIPC/mac/ConnectionMac.cpp
Source/WebKit2/WebProcess/WebPage/DecoderAdapter.cpp
Source/WebKit2/WebProcess/WebPage/DecoderAdapter.h
Source/WebKit2/WebProcess/WebProcess.cpp

index 75c5d89..f6b587f 100644 (file)
@@ -1,3 +1,34 @@
+2013-09-24  Anders Carlsson  <andersca@apple.com>
+
+        Remove create functions from MessageDecoder and ArgumentDecoder
+        https://bugs.webkit.org/show_bug.cgi?id=121850
+
+        Reviewed by Antti Koivisto.
+
+        * Platform/CoreIPC/ArgumentDecoder.cpp:
+        (CoreIPC::ArgumentDecoder::ArgumentDecoder):
+        * Platform/CoreIPC/ArgumentDecoder.h:
+        * Platform/CoreIPC/MessageDecoder.cpp:
+        (CoreIPC::MessageDecoder::MessageDecoder):
+        * Platform/CoreIPC/MessageDecoder.h:
+        * Platform/CoreIPC/mac/ConnectionMac.cpp:
+        (CoreIPC::createMessageDecoder):
+        * WebProcess/WebPage/DecoderAdapter.cpp:
+        (WebKit::DecoderAdapter::DecoderAdapter):
+        (WebKit::DecoderAdapter::decodeBytes):
+        (WebKit::DecoderAdapter::decodeBool):
+        (WebKit::DecoderAdapter::decodeUInt16):
+        (WebKit::DecoderAdapter::decodeUInt32):
+        (WebKit::DecoderAdapter::decodeUInt64):
+        (WebKit::DecoderAdapter::decodeInt32):
+        (WebKit::DecoderAdapter::decodeInt64):
+        (WebKit::DecoderAdapter::decodeFloat):
+        (WebKit::DecoderAdapter::decodeDouble):
+        (WebKit::DecoderAdapter::decodeString):
+        * WebProcess/WebPage/DecoderAdapter.h:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::postInjectedBundleMessage):
+
 2013-09-24  Mark Rowe  <mrowe@apple.com>
 
         <rdar://problem/14971518> WebKit should build against the Xcode default toolchain when targeting OS X 10.8
index e23d28a..6d55078 100644 (file)
 
 namespace CoreIPC {
 
-PassOwnPtr<ArgumentDecoder> ArgumentDecoder::create(const uint8_t* buffer, size_t bufferSize)
+ArgumentDecoder::ArgumentDecoder(const uint8_t* buffer, size_t bufferSize)
 {
-    Vector<Attachment> attachments;
-    return adoptPtr(new ArgumentDecoder(buffer, bufferSize, attachments));
+    initialize(buffer, bufferSize);
 }
 
-ArgumentDecoder::ArgumentDecoder(const uint8_t* buffer, size_t bufferSize, Vector<Attachment>& attachments)
+ArgumentDecoder::ArgumentDecoder(const uint8_t* buffer, size_t bufferSize, Vector<Attachment> attachments)
 {
     initialize(buffer, bufferSize);
 
-    m_attachments.swap(attachments);
+    m_attachments = std::move(attachments);
 }
 
 ArgumentDecoder::~ArgumentDecoder()
index 33b1f60..e8dabb6 100644 (file)
@@ -37,7 +37,7 @@ class DataReference;
     
 class ArgumentDecoder {
 public:
-    static PassOwnPtr<ArgumentDecoder> create(const uint8_t* buffer, size_t bufferSize);
+    ArgumentDecoder(const uint8_t* buffer, size_t bufferSize);
     virtual ~ArgumentDecoder();
 
     uint64_t destinationID() const { return m_destinationID; }
@@ -93,7 +93,7 @@ public:
     bool removeAttachment(Attachment&);
 
 protected:
-    ArgumentDecoder(const uint8_t* buffer, size_t bufferSize, Vector<Attachment>&);
+    ArgumentDecoder(const uint8_t* buffer, size_t bufferSize, Vector<Attachment>);
 
     void initialize(const uint8_t* buffer, size_t bufferSize);
 
index 61bab3c..e7bc5d2 100644 (file)
 
 namespace CoreIPC {
 
-PassOwnPtr<MessageDecoder> MessageDecoder::create(const DataReference& buffer)
-{
-    Vector<Attachment> attachments;
-    return adoptPtr(new MessageDecoder(buffer, attachments));
-}
-
-PassOwnPtr<MessageDecoder> MessageDecoder::create(const DataReference& buffer, Vector<Attachment>& attachments)
-{
-    return adoptPtr(new MessageDecoder(buffer, attachments));
-}
-
 MessageDecoder::~MessageDecoder()
 {
 }
 
-MessageDecoder::MessageDecoder(const DataReference& buffer, Vector<Attachment>& attachments)
+MessageDecoder::MessageDecoder(const DataReference& buffer, Vector<Attachment> attachments)
     : ArgumentDecoder(buffer.data(), buffer.size(), attachments)
 {
     if (!decode(m_messageFlags))
index 0b2b4a4..e151da4 100644 (file)
@@ -36,8 +36,7 @@ class ImportanceAssertion;
 
 class MessageDecoder : public ArgumentDecoder {
 public:
-    static PassOwnPtr<MessageDecoder> create(const DataReference& buffer);
-    static PassOwnPtr<MessageDecoder> create(const DataReference& buffer, Vector<Attachment>&);
+    MessageDecoder(const DataReference& buffer, Vector<Attachment>);
     virtual ~MessageDecoder();
 
     StringReference messageReceiverName() const { return m_messageReceiverName; }
@@ -51,8 +50,6 @@ public:
 #endif
 
 private:
-    MessageDecoder(const DataReference& buffer, Vector<Attachment>&);
-
     uint8_t m_messageFlags;
     StringReference m_messageReceiverName;
     StringReference m_messageName;
index 4671af0..ffd0db3 100644 (file)
@@ -299,14 +299,14 @@ void Connection::initializeDeadNameSource()
     });
 }
 
-static PassOwnPtr<MessageDecoder> createMessageDecoder(mach_msg_header_t* header)
+static OwnPtr<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 MessageDecoder::create(DataReference(body, bodySize));
+        return createOwned<MessageDecoder>(DataReference(body, bodySize), Vector<Attachment>());
     }
 
     bool messageBodyIsOOL = header->msgh_id & MessageBodyIsOutOfLine;
@@ -351,22 +351,17 @@ static PassOwnPtr<MessageDecoder> createMessageDecoder(mach_msg_header_t* header
         uint8_t* messageBody = static_cast<uint8_t*>(messageBodyAttachment.address());
         size_t messageBodySize = messageBodyAttachment.size();
 
-        OwnPtr<MessageDecoder> decoder;
-
-        if (attachments.isEmpty())
-            decoder = MessageDecoder::create(DataReference(messageBody, messageBodySize));
-        else
-            decoder = MessageDecoder::create(DataReference(messageBody, messageBodySize), attachments);
+        OwnPtr<MessageDecoder> decoder = createOwned<MessageDecoder>(DataReference(messageBody, messageBodySize), std::move(attachments));
 
         vm_deallocate(mach_task_self(), reinterpret_cast<vm_address_t>(messageBodyAttachment.address()), messageBodyAttachment.size());
 
-        return decoder.release();
+        return decoder;
     }
 
     uint8_t* messageBody = descriptorData;
     size_t messageBodySize = header->msgh_size - (descriptorData - reinterpret_cast<uint8_t*>(header));
 
-    return MessageDecoder::create(DataReference(messageBody, messageBodySize), attachments);
+    return createOwned<MessageDecoder>(DataReference(messageBody, messageBodySize), attachments);
 }
 
 // The receive buffer size should always include the maximum trailer size.
index ef38a6f..1c4aa76 100644 (file)
 namespace WebKit {
 
 DecoderAdapter::DecoderAdapter(const uint8_t* buffer, size_t bufferSize)
-    : m_decoder(CoreIPC::ArgumentDecoder::create(buffer, bufferSize))
+    : m_decoder(buffer, bufferSize)
 {
     // Keep format compatibility by decoding an unused uint64_t value
     // that used to be encoded by the argument encoder.
     uint64_t value;
-    m_decoder->decode(value);
+    m_decoder.decode(value);
     ASSERT(!value);
 }
 
 bool DecoderAdapter::decodeBytes(Vector<uint8_t>& bytes)
 {
     CoreIPC::DataReference dataReference;
-    if (!m_decoder->decode(dataReference))
+    if (!m_decoder.decode(dataReference))
         return false;
 
     bytes = dataReference.vector();
@@ -54,42 +54,42 @@ bool DecoderAdapter::decodeBytes(Vector<uint8_t>& bytes)
 
 bool DecoderAdapter::decodeBool(bool& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeUInt16(uint16_t& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeUInt32(uint32_t& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeUInt64(uint64_t& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeInt32(int32_t& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeInt64(int64_t& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeFloat(float& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeDouble(double& value)
 {
-    return m_decoder->decode(value);
+    return m_decoder.decode(value);
 }
 
 bool DecoderAdapter::decodeString(String& value)
@@ -101,7 +101,7 @@ bool DecoderAdapter::decodeString(String& value)
     // without breaking encoding/decoding of the history tree.
 
     uint32_t length;
-    if (!m_decoder->decode(length))
+    if (!m_decoder.decode(length))
         return false;
 
     if (length == std::numeric_limits<uint32_t>::max()) {
@@ -111,26 +111,26 @@ bool DecoderAdapter::decodeString(String& value)
     }
 
     uint64_t lengthInBytes;
-    if (!m_decoder->decode(lengthInBytes))
+    if (!m_decoder.decode(lengthInBytes))
         return false;
 
     if (lengthInBytes % sizeof(UChar) || lengthInBytes / sizeof(UChar) != length) {
-        m_decoder->markInvalid();
+        m_decoder.markInvalid();
         return false;
     }
 
-    if (!m_decoder->bufferIsLargeEnoughToContain<UChar>(length)) {
-        m_decoder->markInvalid();
+    if (!m_decoder.bufferIsLargeEnoughToContain<UChar>(length)) {
+        m_decoder.markInvalid();
         return false;
     }
 
     UChar* buffer;
     String string = String::createUninitialized(length, buffer);
-    if (!m_decoder->decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(UChar), __alignof(UChar)))
+    if (!m_decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length * sizeof(UChar), __alignof(UChar)))
         return false;
 
     value = string;
     return true;
 }
 
-}
+} // namespace WebKit
index 671e189..d6b4eb7 100644 (file)
@@ -48,7 +48,7 @@ private:
     virtual bool decodeDouble(double&);
     virtual bool decodeString(String&);
 
-    OwnPtr<CoreIPC::ArgumentDecoder> m_decoder;
+    CoreIPC::ArgumentDecoder m_decoder;
 };
 
 } // namespace WebKit
index bcfc842..940f98e 100644 (file)
@@ -973,15 +973,15 @@ void WebProcess::postInjectedBundleMessage(const CoreIPC::DataReference& message
     if (!injectedBundle)
         return;
 
-    OwnPtr<CoreIPC::ArgumentDecoder> decoder = CoreIPC::ArgumentDecoder::create(messageData.data(), messageData.size());
+    CoreIPC::ArgumentDecoder decoder(messageData.data(), messageData.size());
 
     String messageName;
-    if (!decoder->decode(messageName))
+    if (!decoder.decode(messageName))
         return;
 
     RefPtr<APIObject> messageBody;
     InjectedBundleUserMessageDecoder messageBodyDecoder(messageBody);
-    if (!decoder->decode(messageBodyDecoder))
+    if (!decoder.decode(messageBodyDecoder))
         return;
 
     injectedBundle->didReceiveMessage(messageName, messageBody.get());