[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

zoltan at webkit.org zoltan at webkit.org
Wed Dec 22 14:55:43 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 9ef0b2d4a60bd2575e6cc23eb729c61236d04e58
Author: zoltan at webkit.org <zoltan at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Oct 25 13:48:58 2010 +0000

    [Qt] Implement SharedMemory for WebKit2
    https://bugs.webkit.org/show_bug.cgi?id=47345
    
    Reviewed by Kenneth Rohde Christiansen.
    
    Implement unimplemented functions in SharedMemoryQt.cpp.
    Rename MappedMemory.h to MappedMemoryPool.h, move MappedMemoryPool.{h|cpp} from
    Shared/qt to Platform/qt. Modify affected lines of WebKit2.pro.
    Move MappedMemory implementation into MappedMemoryPool. Remove unnecessary
    methods of MappedMemoryPool.
    
    * Platform/SharedMemory.h: Add a handle member for Qt.
    * Platform/qt/MappedMemoryPool.cpp: Copied from WebKit2/Shared/qt/MappedMemoryPool.cpp.
    (WebKit::MappedMemoryPool::searchForMappedMemory):
    (WebKit::MappedMemoryPool::mapMemory):
    (WebKit::MappedMemoryPool::mapFile):
    * Platform/qt/MappedMemoryPool.h: Copied from WebKit2/Shared/qt/MappedMemory.h.
    (WebKit::MappedMemoryPool::MappedMemory::mapSize):
    (WebKit::MappedMemoryPool::MappedMemory::markUsed):
    (WebKit::MappedMemoryPool::MappedMemory::markFree):
    (WebKit::MappedMemoryPool::MappedMemory::isFree):
    (WebKit::MappedMemoryPool::MappedMemory::data):
    (WebKit::MappedMemoryPool::MappedMemoryPool):
    Move MappedMemory implementation into MappedMemoryPool.
    * Platform/qt/SharedMemoryQt.cpp:
    (WebKit::SharedMemory::Handle::Handle): Implement.
    (WebKit::SharedMemory::Handle::~Handle):
    (WebKit::SharedMemory::Handle::isNull): Implement.
    (WebKit::SharedMemory::Handle::encode): Implement.
    (WebKit::SharedMemory::Handle::decode): Implement.
    (WebKit::SharedMemory::create): Implement.
    (WebKit::mapProtection): Added.
    (WebKit::SharedMemory::~SharedMemory): Implement.
    (WebKit::SharedMemory::createHandle): Implement.
    (WebKit::SharedMemory::systemPageSize): Implement.
    * Shared/qt/MappedMemory.h: Removed.
    * Shared/qt/MappedMemoryPool.cpp: Removed.
    * Shared/qt/UpdateChunk.cpp:
    (WebKit::UpdateChunk::UpdateChunk):
    (WebKit::UpdateChunk::decode):
    Modify to use MappedMemoryPool.
    * Shared/qt/UpdateChunk.h:
    * WebKit2.pro:
    Modify affected lines.
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@70450 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index 91bd82d..5b2f5f0 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,50 @@
+2010-10-25  Zoltan Horvath  <zoltan at webkit.org>
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        [Qt] Implement SharedMemory for WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=47345
+
+        Implement unimplemented functions in SharedMemoryQt.cpp.
+        Rename MappedMemory.h to MappedMemoryPool.h, move MappedMemoryPool.{h|cpp} from
+        Shared/qt to Platform/qt. Modify affected lines of WebKit2.pro.
+        Move MappedMemory implementation into MappedMemoryPool. Remove unnecessary 
+        methods of MappedMemoryPool.
+
+        * Platform/SharedMemory.h: Add a handle member for Qt.
+        * Platform/qt/MappedMemoryPool.cpp: Copied from WebKit2/Shared/qt/MappedMemoryPool.cpp.
+        (WebKit::MappedMemoryPool::searchForMappedMemory):
+        (WebKit::MappedMemoryPool::mapMemory):
+        (WebKit::MappedMemoryPool::mapFile):
+        * Platform/qt/MappedMemoryPool.h: Copied from WebKit2/Shared/qt/MappedMemory.h.
+        (WebKit::MappedMemoryPool::MappedMemory::mapSize):
+        (WebKit::MappedMemoryPool::MappedMemory::markUsed):
+        (WebKit::MappedMemoryPool::MappedMemory::markFree):
+        (WebKit::MappedMemoryPool::MappedMemory::isFree):
+        (WebKit::MappedMemoryPool::MappedMemory::data):
+        (WebKit::MappedMemoryPool::MappedMemoryPool):
+        Move MappedMemory implementation into MappedMemoryPool.
+        * Platform/qt/SharedMemoryQt.cpp:
+        (WebKit::SharedMemory::Handle::Handle): Implement.
+        (WebKit::SharedMemory::Handle::~Handle):
+        (WebKit::SharedMemory::Handle::isNull): Implement.
+        (WebKit::SharedMemory::Handle::encode): Implement.
+        (WebKit::SharedMemory::Handle::decode): Implement.
+        (WebKit::SharedMemory::create): Implement.
+        (WebKit::mapProtection): Added.
+        (WebKit::SharedMemory::~SharedMemory): Implement.
+        (WebKit::SharedMemory::createHandle): Implement.
+        (WebKit::SharedMemory::systemPageSize): Implement.
+        * Shared/qt/MappedMemory.h: Removed.
+        * Shared/qt/MappedMemoryPool.cpp: Removed.
+        * Shared/qt/UpdateChunk.cpp:
+        (WebKit::UpdateChunk::UpdateChunk):
+        (WebKit::UpdateChunk::decode):
+        Modify to use MappedMemoryPool.
+        * Shared/qt/UpdateChunk.h:
+        * WebKit2.pro:
+        Modify affected lines.
+
 2010-10-24  Sam Weinig  <sam at webkit.org>
 
         Reviewed by Dan Bernstein.
diff --git a/WebKit2/Platform/SharedMemory.h b/WebKit2/Platform/SharedMemory.h
index 25d9c24..cb6ca15 100644
--- a/WebKit2/Platform/SharedMemory.h
+++ b/WebKit2/Platform/SharedMemory.h
@@ -30,6 +30,10 @@
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 
+#if PLATFORM(QT)
+#include <wtf/text/WTFString.h>
+#endif
+
 namespace CoreIPC {
     class ArgumentDecoder;
     class ArgumentEncoder;
@@ -60,6 +64,8 @@ public:
         mutable mach_port_t m_port;
 #elif PLATFORM(WIN)
         mutable HANDLE m_handle;
+#elif PLATFORM(QT)
+        mutable String m_fileName;
 #endif
         size_t m_size;
     };
diff --git a/WebKit2/Platform/qt/MappedMemoryPool.cpp b/WebKit2/Platform/qt/MappedMemoryPool.cpp
new file mode 100644
index 0000000..a59aea0
--- /dev/null
+++ b/WebKit2/Platform/qt/MappedMemoryPool.cpp
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2010 University of Szeged
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "MappedMemoryPool.h"
+
+#include "StdLibExtras.h"
+#include <QDir>
+#include <QIODevice>
+#include <QTemporaryFile>
+
+namespace WebKit {
+
+MappedMemoryPool* MappedMemoryPool::instance()
+{
+    DEFINE_STATIC_LOCAL(MappedMemoryPool, singleton, ());
+    return &singleton;
+}
+
+MappedMemory* MappedMemoryPool::searchForMappedMemory(uchar* p)
+{
+    for (unsigned n = 0; n < m_pool.size(); ++n) {
+        MappedMemory& current = m_pool.at(n);
+        if (current.data() == p)
+            return reinterpret_cast<MappedMemory*>(&current);
+    }
+    return 0;
+}
+
+MappedMemory* MappedMemoryPool::mapMemory(size_t size, QIODevice::OpenMode openMode)
+{
+    for (unsigned n = 0; n < m_pool.size(); ++n) {
+        MappedMemory& current = m_pool.at(n);
+        if (current.dataSize >= size && current.isFree()) {
+            current.markUsed();
+            return &current;
+        }
+    }
+    MappedMemory newMap;
+    newMap.dataSize = size;
+    newMap.file = new QTemporaryFile(QDir::tempPath() + "/WebKit2UpdateChunk");
+    newMap.file->open(openMode);
+    newMap.file->resize(newMap.mapSize());
+    newMap.mappedBytes = newMap.file->map(0, newMap.mapSize());
+    newMap.file->close();
+    newMap.markUsed();
+    m_pool.append(newMap);
+    return &m_pool.last();
+}
+
+MappedMemory* MappedMemoryPool::mapFile(QString fileName, size_t size, QIODevice::OpenMode openMode)
+{
+    for (unsigned n = 0; n < m_pool.size(); ++n) {
+        MappedMemory& current = m_pool.at(n);
+        if (current.file->fileName() == fileName) {
+            ASSERT(!current.isFree());
+            return &current;
+        }
+    }
+    MappedMemory newMap;
+    newMap.file = new QFile(fileName);
+    if (!newMap.file->open(openMode))
+        return 0;
+    newMap.dataSize = size;
+    newMap.mappedBytes = newMap.file->map(0, newMap.mapSize());
+    ASSERT(!newMap.isFree());
+    newMap.file->close();
+    newMap.file->remove(); // The map stays alive even when the file is unlinked.
+    m_pool.append(newMap);
+    return &m_pool.last();
+}
+
+} // namespace WebKit
diff --git a/WebKit2/Platform/qt/MappedMemoryPool.h b/WebKit2/Platform/qt/MappedMemoryPool.h
new file mode 100644
index 0000000..14ca594
--- /dev/null
+++ b/WebKit2/Platform/qt/MappedMemoryPool.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2010 University of Szeged
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MappedMemoryPool_h
+#define MappedMemoryPool_h
+
+#include <QFile>
+#include <wtf/Vector.h>
+
+namespace WebKit {
+
+class MappedMemoryPool {
+public:
+    static MappedMemoryPool* instance();
+
+    struct MappedMemory {
+        QFile* file;
+        struct Data {
+            uint32_t isFree; // keep bytes aligned
+            uchar bytes;
+        };
+        union {
+            uchar* mappedBytes;
+            Data* dataPtr;
+        };
+        size_t dataSize;
+
+        size_t mapSize() const { return dataSize + sizeof(Data); }
+        void markUsed() { dataPtr->isFree = false; }
+        void markFree() { dataPtr->isFree = true; }
+        bool isFree() const { return dataPtr->isFree; }
+        uchar* data() const { return &dataPtr->bytes; }
+    };
+
+    MappedMemory* mapMemory(size_t size, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
+    MappedMemory* mapFile(QString fileName, size_t size, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
+    MappedMemory* searchForMappedMemory(uchar* p);
+
+private:
+    MappedMemoryPool() { };
+
+    Vector<MappedMemory> m_pool;
+};
+
+typedef MappedMemoryPool::MappedMemory MappedMemory;
+
+} // namespace WebKit
+
+#endif // MappedMemoryPool_h
diff --git a/WebKit2/Platform/qt/SharedMemoryQt.cpp b/WebKit2/Platform/qt/SharedMemoryQt.cpp
index 087a2ea..aba09f5 100644
--- a/WebKit2/Platform/qt/SharedMemoryQt.cpp
+++ b/WebKit2/Platform/qt/SharedMemoryQt.cpp
@@ -1,5 +1,7 @@
 /*
  * Copyright (C) 2010 Apple Inc. All rights reserved.
+ * Copyright (c) 2010 University of Szeged
+ * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -25,58 +27,131 @@
 
 #include "SharedMemory.h"
 
-#include "NotImplemented.h"
+#include "ArgumentDecoder.h"
+#include "ArgumentEncoder.h"
+#include "MappedMemoryPool.h"
+#include "WebCoreArgumentCoders.h"
+#include <QIODevice>
+#include <unistd.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebKit {
 
+static MappedMemoryPool* mappedMemoryPool = MappedMemoryPool::instance();
+
 SharedMemory::Handle::Handle()
+    : m_fileName()
+    , m_size(0)
 {
-    notImplemented();
 }
 
 SharedMemory::Handle::~Handle()
 {
-    notImplemented();
+}
+
+bool SharedMemory::Handle::isNull() const
+{
+    return m_fileName.isNull();
 }
 
 void SharedMemory::Handle::encode(CoreIPC::ArgumentEncoder* encoder) const
 {
-    notImplemented();
+    encoder->encodeUInt64(m_size);
+    encoder->encode(m_fileName);
+    m_fileName = String();
 }
 
 bool SharedMemory::Handle::decode(CoreIPC::ArgumentDecoder* decoder, Handle& handle)
 {
-    notImplemented();
-    return false;
+    ASSERT(!handle.m_size);
+    ASSERT(handle.m_fileName.isEmpty());
+
+    uint64_t size;
+    if (!decoder->decodeUInt64(size))
+        return false;
+
+    String fileName;
+    if (!decoder->decode(fileName))
+       return false;
+
+    handle.m_size = size;
+    handle.m_fileName = fileName;
+
+    return true;
 }
 
 PassRefPtr<SharedMemory> SharedMemory::create(size_t size)
 {
-    notImplemented();
-    return 0;
+    MappedMemory* mm = mappedMemoryPool->mapMemory(size, QIODevice::ReadWrite);
+
+    RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
+    sharedMemory->m_size = size;
+    sharedMemory->m_data = reinterpret_cast<void*>(mm->data());
+
+    return sharedMemory.release();
+}
+
+static inline QIODevice::OpenMode mapProtection(SharedMemory::Protection protection)
+{
+    switch (protection) {
+    case SharedMemory::ReadOnly:
+        return QIODevice::ReadOnly;
+    case SharedMemory::ReadWrite:
+        return QIODevice::ReadWrite;
+    }
+
+    ASSERT_NOT_REACHED();
+    return QIODevice::NotOpen;
 }
 
 PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection)
 {
-    notImplemented();
-    return 0;    
+    if (handle.isNull())
+        return 0;
+
+    QIODevice::OpenMode openMode = mapProtection(protection);
+
+    MappedMemory* mm = mappedMemoryPool->mapFile(QString(handle.m_fileName), handle.m_size, openMode);
+
+    RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory));
+    sharedMemory->m_size = handle.m_size;
+    sharedMemory->m_data = reinterpret_cast<void*>(mm->data());
+
+    return sharedMemory.release();
 }
 
 SharedMemory::~SharedMemory()
 {
-    notImplemented();
+    MappedMemory* mappedMemory = mappedMemoryPool->searchForMappedMemory(reinterpret_cast<uchar*>(m_data));
+    if (mappedMemory) { 
+        mappedMemory->markFree();
+        delete mappedMemory;
+    }
 }
-    
+
 bool SharedMemory::createHandle(Handle& handle, Protection protection)
 {
-    notImplemented();
-    return false;
+    ASSERT(handle.m_fileName.isNull());
+    ASSERT(!handle.m_size);
+
+    MappedMemory* mm = mappedMemoryPool->searchForMappedMemory(reinterpret_cast<uchar*>(m_data));
+
+    if (!mm)
+        return false;
+
+    handle.m_fileName = mm->file->fileName();
+    handle.m_size = m_size;
+
+    return true;
 }
 
 unsigned SharedMemory::systemPageSize()
 {
     static unsigned pageSize = 0;
 
+    if (!pageSize)
+        pageSize = getpagesize();
+
     return pageSize;
 }
 
diff --git a/WebKit2/Shared/qt/MappedMemory.h b/WebKit2/Shared/qt/MappedMemory.h
deleted file mode 100644
index 412c210..0000000
--- a/WebKit2/Shared/qt/MappedMemory.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright (C) 2010 Apple Inc. All rights reserved.
- * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
- * Copyright (C) 2010 University of Szeged
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef MappedMemory_h
-#define MappedMemory_h
-
-#include <QCoreApplication>
-#include <QFile>
-#include <wtf/Vector.h>
-
-namespace WebKit {
-struct MappedMemory {
-    QFile* file;
-    struct Data {
-        uint32_t isFree; // keep bytes aligned
-        uchar bytes;
-    };
-    union {
-        uchar* mappedBytes;
-        Data* dataPtr;
-    };
-    size_t dataSize;
-
-    size_t mapSize() const { return dataSize + sizeof(Data); }
-    void markUsed() { dataPtr->isFree = false; }
-    void markFree() { dataPtr->isFree = true; }
-    bool isFree() const { return dataPtr->isFree; }
-    uchar* data() const { return &dataPtr->bytes; }
-};
-
-class MappedMemoryPool : public QObject {
-    Q_OBJECT
-public:
-    static MappedMemoryPool* instance();
-    size_t size() const;
-    MappedMemory& at(size_t i);
-    MappedMemory& append(const MappedMemory&);
-
-private:
-    MappedMemoryPool();
-    Q_SLOT void cleanUp();
-
-    Vector<MappedMemory> m_pool;
-};
-} // namespace WebKit
-#endif // MappedMemory_h
diff --git a/WebKit2/Shared/qt/MappedMemoryPool.cpp b/WebKit2/Shared/qt/MappedMemoryPool.cpp
deleted file mode 100644
index f9f2f83..0000000
--- a/WebKit2/Shared/qt/MappedMemoryPool.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2010 University of Szeged
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "MappedMemory.h"
-
-#include "StdLibExtras.h"
-
-namespace WebKit {
-
-MappedMemoryPool::MappedMemoryPool()
-{
-    connect(QCoreApplication::instance(), SIGNAL(aboutToQuit()), SLOT(cleanUp()));
-}
-
-MappedMemoryPool* MappedMemoryPool::instance()
-{
-    DEFINE_STATIC_LOCAL(MappedMemoryPool, singleton, ());
-    return &singleton;
-}
-
-size_t MappedMemoryPool::size() const
-{
-    return m_pool.size();
-}
-
-MappedMemory& MappedMemoryPool::at(size_t i)
-{
-    return m_pool.at(i);
-}
-
-MappedMemory& MappedMemoryPool::append(const MappedMemory& newMap)
-{
-    m_pool.append(newMap);
-    return m_pool.last();
-}
-
-void MappedMemoryPool::cleanUp()
-{
-    size_t size = m_pool.size();
-
-    for (size_t i = 0; i < size; ++i) {
-        MappedMemory& chunk = m_pool.at(i);
-        if (!chunk.isFree())
-            chunk.file->unmap(chunk.mappedBytes);
-        chunk.file->remove();
-    }
-
-    delete this;
-}
-
-} // namespace WebKit
diff --git a/WebKit2/Shared/qt/UpdateChunk.cpp b/WebKit2/Shared/qt/UpdateChunk.cpp
index 8dd0f61..c7776ab 100644
--- a/WebKit2/Shared/qt/UpdateChunk.cpp
+++ b/WebKit2/Shared/qt/UpdateChunk.cpp
@@ -29,12 +29,9 @@
 
 #include "ArgumentDecoder.h"
 #include "ArgumentEncoder.h"
-#include "Attachment.h"
 #include "WebCoreArgumentCoders.h"
-#include <QDebug>
-#include <QDir>
+#include <QIODevice>
 #include <QImage>
-#include <QTemporaryFile>
 #include <WebCore/FloatRect.h>
 #include <wtf/text/WTFString.h>
 
@@ -43,48 +40,7 @@ using namespace std;
 
 namespace WebKit {
 
-static MappedMemory* mapMemory(size_t size)
-{
-    MappedMemoryPool* pool = MappedMemoryPool::instance();
-    for (unsigned n = 0; n < pool->size(); ++n) {
-        MappedMemory& current = pool->at(n);
-        if (current.dataSize >= size && current.isFree()) {
-            current.markUsed();
-            return &current;
-        }
-    }
-    MappedMemory newMap;
-    newMap.dataSize = size;
-    newMap.file = new QTemporaryFile(QDir::tempPath() + "/WebKit2UpdateChunk");
-    newMap.file->open(QIODevice::ReadWrite);
-    newMap.file->resize(newMap.mapSize());
-    newMap.mappedBytes = newMap.file->map(0, newMap.mapSize());
-    newMap.file->close();
-    newMap.markUsed();
-    return &pool->append(newMap);
-}
-
-static MappedMemory* mapFile(QString fileName, size_t size)
-{
-    MappedMemoryPool* pool = MappedMemoryPool::instance();
-    for (unsigned n = 0; n < pool->size(); ++n) {
-        MappedMemory& current = pool->at(n);
-        if (current.file->fileName() == fileName) {
-            ASSERT(!current.isFree());
-            return &current;
-        }
-    }
-    MappedMemory newMap;
-    newMap.file = new QFile(fileName);
-    if (!newMap.file->open(QIODevice::ReadWrite))
-        return 0;
-    newMap.dataSize = size;
-    newMap.mappedBytes = newMap.file->map(0, newMap.mapSize());
-    ASSERT(!newMap.isFree());
-    newMap.file->close();
-    newMap.file->remove(); // The map stays alive even when the file is unlinked.
-    return &pool->append(newMap);
-}
+static MappedMemoryPool* mappedMemoryPool = MappedMemoryPool::instance();
 
 UpdateChunk::UpdateChunk()
     : m_mappedMemory(0)
@@ -93,7 +49,7 @@ UpdateChunk::UpdateChunk()
 
 UpdateChunk::UpdateChunk(const IntRect& rect)
     : m_rect(rect)
-    , m_mappedMemory(mapMemory(size()))
+    , m_mappedMemory(mappedMemoryPool->mapMemory(size()))
 {
 }
 
@@ -124,12 +80,12 @@ bool UpdateChunk::decode(CoreIPC::ArgumentDecoder* decoder, UpdateChunk& chunk)
     if (!decoder->decode(rect))
         return false;
     chunk.m_rect = rect;
-    
+
     String fileName;
     if (!decoder->decode(fileName))
         return false;
 
-    chunk.m_mappedMemory = mapFile(fileName, chunk.size());
+    chunk.m_mappedMemory = mappedMemoryPool->mapFile(fileName, chunk.size());
 
     return chunk.m_mappedMemory->mappedBytes;
 }
diff --git a/WebKit2/Shared/qt/UpdateChunk.h b/WebKit2/Shared/qt/UpdateChunk.h
index 0c9286e..bd8a7fa 100644
--- a/WebKit2/Shared/qt/UpdateChunk.h
+++ b/WebKit2/Shared/qt/UpdateChunk.h
@@ -27,7 +27,7 @@
 #ifndef UpdateChunk_h
 #define UpdateChunk_h
 
-#include "MappedMemory.h"
+#include "MappedMemoryPool.h"
 #include <QImage>
 #include <WebCore/IntRect.h>
 
diff --git a/WebKit2/WebKit2.pro b/WebKit2/WebKit2.pro
index f04d52e..954c3af 100644
--- a/WebKit2/WebKit2.pro
+++ b/WebKit2/WebKit2.pro
@@ -106,6 +106,7 @@ INCLUDEPATH = \
     $$PWD \
     Platform \
     Platform/CoreIPC \
+    Platform/qt \
     Shared \
     Shared/API/c \
     Shared/CoreIPCSupport \
@@ -174,6 +175,7 @@ HEADERS += \
     Platform/Logging.h \
     Platform/Module.h \
     Platform/PlatformProcessIdentifier.h \
+    Platform/qt/MappedMemoryPool.h \
     Platform/RunLoop.h \
     Platform/SharedMemory.h \
     Platform/WorkItem.h \
@@ -203,7 +205,6 @@ HEADERS += \
     Shared/NativeWebKeyboardEvent.h \
     Shared/NotImplemented.h \
     Shared/StringPairVector.h \
-    Shared/qt/MappedMemory.h \
     Shared/qt/PlatformCertificateInfo.h \
     Shared/qt/UpdateChunk.h \
     Shared/qt/WebEventFactoryQt.h \
@@ -337,6 +338,7 @@ SOURCES += \
     Platform/Module.cpp \
     Platform/RunLoop.cpp \
     Platform/WorkQueue.cpp \
+    Platform/qt/MappedMemoryPool.cpp \
     Platform/qt/ModuleQt.cpp \
     Platform/qt/RunLoopQt.cpp \
     Platform/qt/SharedMemoryQt.cpp \
@@ -357,7 +359,6 @@ SOURCES += \
     Shared/MutableArray.cpp \
     Shared/MutableDictionary.cpp \
     Shared/qt/BackingStoreQt.cpp \
-    Shared/qt/MappedMemoryPool.cpp \
     Shared/qt/NativeWebKeyboardEventQt.cpp \
     Shared/qt/UpdateChunk.cpp \
     Shared/qt/WebCoreArgumentCodersQt.cpp \

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list