Title: [185412] trunk/Source/WebKit2
Revision
185412
Author
[email protected]
Date
2015-06-10 06:00:49 -0700 (Wed, 10 Jun 2015)

Log Message

NetworkCache: Delete old cache versions
https://bugs.webkit.org/show_bug.cgi?id=145800

Reviewed by Darin Adler.

* CMakeLists.txt:
* NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
(WebKit::NetworkCache::BlobStorage::synchronize):
* NetworkProcess/cache/NetworkCacheFileSystem.cpp: Added.
(WebKit::NetworkCache::directoryEntryType):
(WebKit::NetworkCache::traverseDirectory):

    Pass entry type as callback argument.

(WebKit::NetworkCache::deleteDirectoryRecursively):

    Add helper.

(WebKit::NetworkCache::fileTimes):
(WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
* NetworkProcess/cache/NetworkCacheFileSystem.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h.

    Move code to cpp.

(WebKit::NetworkCache::traverseDirectory): Deleted.
(WebKit::NetworkCache::traverseCacheFiles): Deleted.
(WebKit::NetworkCache::fileTimes): Deleted.
(WebKit::NetworkCache::updateFileModificationTimeIfNeeded): Deleted.
* NetworkProcess/cache/NetworkCacheFileSystemPosix.h: Removed.
* NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
* NetworkProcess/cache/NetworkCacheStatistics.cpp:
(WebKit::NetworkCache::Statistics::bootstrapFromNetworkCache):
* NetworkProcess/cache/NetworkCacheStorage.cpp:
(WebKit::NetworkCache::makeBlobDirectoryPath):
(WebKit::NetworkCache::traverseRecordsFiles):

    Move cache hierarchy aware traversal code here from NetworkCacheFileSystem (for better layering).
    Rename for clarity.

(WebKit::NetworkCache::deleteEmptyRecordsDirectories):

    Factor to a function.

(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::synchronize):
(WebKit::NetworkCache::Storage::traverse):
(WebKit::NetworkCache::Storage::clear):

    Use traverseRecordsFiles for traversal.

(WebKit::NetworkCache::Storage::shrink):
(WebKit::NetworkCache::Storage::deleteOldVersions):

    Delete version subdirectories with version number less than the current version.
    Remove code for clearing unversioned V1 caches. No one should have them.

* NetworkProcess/cache/NetworkCacheStorage.h:
* UIProcess/API/APIUserContentExtensionStore.cpp:
* WebKit2.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit2/CMakeLists.txt (185411 => 185412)


--- trunk/Source/WebKit2/CMakeLists.txt	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/CMakeLists.txt	2015-06-10 13:00:49 UTC (rev 185412)
@@ -171,6 +171,7 @@
     NetworkProcess/cache/NetworkCacheDecoder.cpp
     NetworkProcess/cache/NetworkCacheEncoder.cpp
     NetworkProcess/cache/NetworkCacheEntry.cpp
+    NetworkProcess/cache/NetworkCacheFileSystem.cpp
     NetworkProcess/cache/NetworkCacheKey.cpp
     NetworkProcess/cache/NetworkCacheStatistics.cpp
     NetworkProcess/cache/NetworkCacheStorage.cpp

Modified: trunk/Source/WebKit2/ChangeLog (185411 => 185412)


--- trunk/Source/WebKit2/ChangeLog	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/ChangeLog	2015-06-10 13:00:49 UTC (rev 185412)
@@ -1,3 +1,65 @@
+2015-06-10  Antti Koivisto  <[email protected]>
+
+        NetworkCache: Delete old cache versions
+        https://bugs.webkit.org/show_bug.cgi?id=145800
+
+        Reviewed by Darin Adler.
+
+        * CMakeLists.txt:
+        * NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
+        (WebKit::NetworkCache::BlobStorage::synchronize):
+        * NetworkProcess/cache/NetworkCacheFileSystem.cpp: Added.
+        (WebKit::NetworkCache::directoryEntryType):
+        (WebKit::NetworkCache::traverseDirectory):
+
+            Pass entry type as callback argument.
+
+        (WebKit::NetworkCache::deleteDirectoryRecursively):
+
+            Add helper.
+
+        (WebKit::NetworkCache::fileTimes):
+        (WebKit::NetworkCache::updateFileModificationTimeIfNeeded):
+        * NetworkProcess/cache/NetworkCacheFileSystem.h: Copied from Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h.
+
+            Move code to cpp.
+
+        (WebKit::NetworkCache::traverseDirectory): Deleted.
+        (WebKit::NetworkCache::traverseCacheFiles): Deleted.
+        (WebKit::NetworkCache::fileTimes): Deleted.
+        (WebKit::NetworkCache::updateFileModificationTimeIfNeeded): Deleted.
+        * NetworkProcess/cache/NetworkCacheFileSystemPosix.h: Removed.
+        * NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
+        * NetworkProcess/cache/NetworkCacheStatistics.cpp:
+        (WebKit::NetworkCache::Statistics::bootstrapFromNetworkCache):
+        * NetworkProcess/cache/NetworkCacheStorage.cpp:
+        (WebKit::NetworkCache::makeBlobDirectoryPath):
+        (WebKit::NetworkCache::traverseRecordsFiles):
+
+            Move cache hierarchy aware traversal code here from NetworkCacheFileSystem (for better layering).
+            Rename for clarity.
+
+        (WebKit::NetworkCache::deleteEmptyRecordsDirectories):
+
+            Factor to a function.
+
+        (WebKit::NetworkCache::Storage::Storage):
+        (WebKit::NetworkCache::Storage::synchronize):
+        (WebKit::NetworkCache::Storage::traverse):
+        (WebKit::NetworkCache::Storage::clear):
+
+            Use traverseRecordsFiles for traversal.
+
+        (WebKit::NetworkCache::Storage::shrink):
+        (WebKit::NetworkCache::Storage::deleteOldVersions):
+
+            Delete version subdirectories with version number less than the current version.
+            Remove code for clearing unversioned V1 caches. No one should have them.
+
+        * NetworkProcess/cache/NetworkCacheStorage.h:
+        * UIProcess/API/APIUserContentExtensionStore.cpp:
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2015-06-10  Zan Dobersek  <[email protected]>
 
         [GTK] Web Inspector is broken

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.cpp (185411 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2015-06-10 13:00:49 UTC (rev 185412)
@@ -29,10 +29,11 @@
 #if ENABLE(NETWORK_CACHE)
 
 #include "Logging.h"
-#include "NetworkCacheFileSystemPosix.h"
+#include "NetworkCacheFileSystem.h"
 #include <WebCore/FileSystem.h>
 #include <fcntl.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <wtf/RunLoop.h>
 #include <wtf/SHA1.h>
 #include <wtf/text/StringBuilder.h>
@@ -58,7 +59,9 @@
 
     m_approximateSize = 0;
     auto blobDirectory = blobDirectoryPath();
-    traverseDirectory(blobDirectory, DT_REG, [this, &blobDirectory](const String& name) {
+    traverseDirectory(blobDirectory, [this, &blobDirectory](const String& name, DirectoryEntryType type) {
+        if (type != DirectoryEntryType::File)
+            return;
         auto path = WebCore::pathByAppendingComponent(blobDirectory, name);
         auto filePath = WebCore::fileSystemRepresentation(path);
         struct stat stat;

Added: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.cpp (0 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.cpp	2015-06-10 13:00:49 UTC (rev 185412)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2015 Apple Inc. 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 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.
+ */
+
+#include "config.h"
+#include "NetworkCacheFileSystem.h"
+
+#if ENABLE(NETWORK_CACHE)
+
+#include <WebCore/FileSystem.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <wtf/text/CString.h>
+
+#if USE(SOUP)
+#include <wtf/gobject/GRefPtr.h>
+#endif
+
+namespace WebKit {
+namespace NetworkCache {
+
+static DirectoryEntryType directoryEntryType(uint8_t dtype)
+{
+    switch (dtype) {
+    case DT_DIR:
+        return DirectoryEntryType::Directory;
+    case DT_REG:
+        return DirectoryEntryType::File;
+    default:
+        ASSERT_NOT_REACHED();
+        return DirectoryEntryType::File;
+    }
+}
+
+void traverseDirectory(const String& path, const std::function<void (const String&, DirectoryEntryType)>& function)
+{
+    DIR* dir = opendir(WebCore::fileSystemRepresentation(path).data());
+    if (!dir)
+        return;
+    dirent* dp;
+    while ((dp = readdir(dir))) {
+        if (dp->d_type != DT_DIR && dp->d_type != DT_REG)
+            continue;
+        const char* name = dp->d_name;
+        if (!strcmp(name, ".") || !strcmp(name, ".."))
+            continue;
+        auto nameString = String::fromUTF8(name);
+        if (nameString.isNull())
+            continue;
+        function(nameString, directoryEntryType(dp->d_type));
+    }
+    closedir(dir);
+}
+
+void deleteDirectoryRecursively(const String& path)
+{
+    traverseDirectory(path, [&path](const String& name, DirectoryEntryType type) {
+        String entryPath = WebCore::pathByAppendingComponent(path, name);
+        switch (type) {
+        case DirectoryEntryType::File:
+            WebCore::deleteFile(entryPath);
+            break;
+        case DirectoryEntryType::Directory:
+            deleteDirectoryRecursively(entryPath);
+            break;
+        // This doesn't follow symlinks.
+        }
+    });
+    WebCore::deleteEmptyDirectory(path);
+}
+
+FileTimes fileTimes(const String& path)
+{
+#if HAVE(STAT_BIRTHTIME)
+    struct stat fileInfo;
+    if (stat(WebCore::fileSystemRepresentation(path).data(), &fileInfo))
+        return { };
+    return { std::chrono::system_clock::from_time_t(fileInfo.st_birthtime), std::chrono::system_clock::from_time_t(fileInfo.st_mtime) };
+#elif USE(SOUP)
+    // There's no st_birthtime in some operating systems like Linux, so we use xattrs to set/get the creation time.
+    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(WebCore::fileSystemRepresentation(path).data()));
+    GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(file.get(), "xattr::birthtime,time::modified", G_FILE_QUERY_INFO_NONE, nullptr, nullptr));
+    if (!fileInfo)
+        return { };
+    const char* birthtimeString = g_file_info_get_attribute_string(fileInfo.get(), "xattr::birthtime");
+    if (!birthtimeString)
+        return { };
+    return { std::chrono::system_clock::from_time_t(g_ascii_strtoull(birthtimeString, nullptr, 10)),
+        std::chrono::system_clock::from_time_t(g_file_info_get_attribute_uint64(fileInfo.get(), "time::modified")) };
+#endif
+}
+
+void updateFileModificationTimeIfNeeded(const String& path)
+{
+    auto times = fileTimes(path);
+    if (times.creation != times.modification) {
+        // Don't update more than once per hour.
+        if (std::chrono::system_clock::now() - times.modification < std::chrono::hours(1))
+            return;
+    }
+    // This really updates both the access time and the modification time.
+    utimes(WebCore::fileSystemRepresentation(path).data(), nullptr);
+}
+
+}
+}
+
+#endif // ENABLE(NETWORK_CACHE)

Copied: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.h (from rev 185362, trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h) (0 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.h	                        (rev 0)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystem.h	2015-06-10 13:00:49 UTC (rev 185412)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2015 Apple Inc. 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 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 NetworkCacheFileSystem_h
+#define NetworkCacheFileSystem_h
+
+#if ENABLE(NETWORK_CACHE)
+
+#include <WebCore/FileSystem.h>
+#include <functional>
+
+namespace WebKit {
+namespace NetworkCache {
+
+enum class DirectoryEntryType { Directory, File };
+void traverseDirectory(const String& path, const std::function<void (const String& fileName, DirectoryEntryType)>&);
+
+void deleteDirectoryRecursively(const String& path);
+
+struct FileTimes {
+    std::chrono::system_clock::time_point creation;
+    std::chrono::system_clock::time_point modification;
+};
+FileTimes fileTimes(const String& path);
+void updateFileModificationTimeIfNeeded(const String& path);
+
+}
+}
+
+#endif 
+
+#endif
+

Deleted: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h (185411 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheFileSystemPosix.h	2015-06-10 13:00:49 UTC (rev 185412)
@@ -1,117 +0,0 @@
-/*
- * Copyright (C) 2015 Apple Inc. 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 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 NetworkCacheFileSystemPosix_h
-#define NetworkCacheFileSystemPosix_h
-
-#if ENABLE(NETWORK_CACHE)
-
-#include <WebCore/FileSystem.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <wtf/text/CString.h>
-
-#if USE(SOUP)
-#include <wtf/gobject/GRefPtr.h>
-#endif
-
-namespace WebKit {
-namespace NetworkCache {
-
-template <typename Function>
-static void traverseDirectory(const String& path, uint8_t type, const Function& function)
-{
-    DIR* dir = opendir(WebCore::fileSystemRepresentation(path).data());
-    if (!dir)
-        return;
-    struct dirent* dp;
-    while ((dp = readdir(dir))) {
-        if (dp->d_type != type)
-            continue;
-        const char* name = dp->d_name;
-        if (!strcmp(name, ".") || !strcmp(name, ".."))
-            continue;
-        function(String(name));
-    }
-    closedir(dir);
-}
-
-template <typename Function>
-inline void traverseCacheFiles(const String& cachePath, const Function& function)
-{
-    traverseDirectory(cachePath, DT_DIR, [&cachePath, &function](const String& subdirName) {
-        String partitionPath = WebCore::pathByAppendingComponent(cachePath, subdirName);
-        traverseDirectory(partitionPath, DT_REG, [&function, &partitionPath](const String& fileName) {
-            function(fileName, partitionPath);
-        });
-    });
-}
-
-struct FileTimes {
-    std::chrono::system_clock::time_point creation;
-    std::chrono::system_clock::time_point modification;
-};
-
-inline FileTimes fileTimes(const String& path)
-{
-#if HAVE(STAT_BIRTHTIME)
-    struct stat fileInfo;
-    if (stat(WebCore::fileSystemRepresentation(path).data(), &fileInfo))
-        return { };
-    return { std::chrono::system_clock::from_time_t(fileInfo.st_birthtime), std::chrono::system_clock::from_time_t(fileInfo.st_mtime) };
-#elif USE(SOUP)
-    // There's no st_birthtime in some operating systems like Linux, so we use xattrs to set/get the creation time.
-    GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(WebCore::fileSystemRepresentation(path).data()));
-    GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(file.get(), "xattr::birthtime,time::modified", G_FILE_QUERY_INFO_NONE, nullptr, nullptr));
-    if (!fileInfo)
-        return { };
-    const char* birthtimeString = g_file_info_get_attribute_string(fileInfo.get(), "xattr::birthtime");
-    if (!birthtimeString)
-        return { };
-    return { std::chrono::system_clock::from_time_t(g_ascii_strtoull(birthtimeString, nullptr, 10)),
-        std::chrono::system_clock::from_time_t(g_file_info_get_attribute_uint64(fileInfo.get(), "time::modified")) };
-#endif
-}
-
-inline void updateFileModificationTimeIfNeeded(const String& path)
-{
-    auto times = fileTimes(path);
-    if (times.creation != times.modification) {
-        // Don't update more than once per hour.
-        if (std::chrono::system_clock::now() - times.modification < std::chrono::hours(1))
-            return;
-    }
-    // This really updates both the access time and the modification time.
-    utimes(WebCore::fileSystemRepresentation(path).data(), 0);
-}
-
-}
-}
-
-#endif // ENABLE(NETWORK_CACHE)
-
-#endif // NetworkCacheFileSystemPosix_h
-

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm (185411 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm	2015-06-10 13:00:49 UTC (rev 185412)
@@ -28,7 +28,7 @@
 
 #if ENABLE(NETWORK_CACHE)
 
-#include "NetworkCacheFileSystemPosix.h"
+#include "NetworkCacheFileSystem.h"
 #include <dispatch/dispatch.h>
 #include <mach/vm_param.h>
 #include <sys/mman.h>

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp (185411 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelSoup.cpp	2015-06-10 13:00:49 UTC (rev 185412)
@@ -28,7 +28,7 @@
 
 #if ENABLE(NETWORK_CACHE)
 
-#include "NetworkCacheFileSystemPosix.h"
+#include "NetworkCacheFileSystem.h"
 #include <wtf/MainThread.h>
 #include <wtf/gobject/GMainLoopSource.h>
 #include <wtf/gobject/GMutexLocker.h>

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp (185411 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStatistics.cpp	2015-06-10 13:00:49 UTC (rev 185412)
@@ -30,7 +30,7 @@
 
 #include "Logging.h"
 #include "NetworkCache.h"
-#include "NetworkCacheFileSystemPosix.h"
+#include "NetworkCacheFileSystem.h"
 #include "NetworkProcess.h"
 #include <WebCore/DiagnosticLoggingKeys.h>
 #include <WebCore/DiagnosticLoggingResultType.h>
@@ -144,7 +144,7 @@
     LOG(NetworkCache, "(NetworkProcess) Bootstrapping the network cache statistics database from the network cache...");
 
     Vector<StringCapture> hashes;
-    traverseCacheFiles(networkCachePath, [&hashes](const String& hashString, const String&) {
+    traverseRecordsFiles(networkCachePath, [&hashes](const String& hashString, const String&) {
         Key::HashType hash;
         if (!Key::stringToHash(hashString, hash))
             return;

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp (185411 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp	2015-06-10 13:00:49 UTC (rev 185412)
@@ -30,7 +30,7 @@
 
 #include "Logging.h"
 #include "NetworkCacheCoders.h"
-#include "NetworkCacheFileSystemPosix.h"
+#include "NetworkCacheFileSystem.h"
 #include "NetworkCacheIOChannel.h"
 #include <wtf/PageBlock.h>
 #include <wtf/RandomNumber.h>
@@ -99,6 +99,30 @@
     return WebCore::pathByAppendingComponent(makeVersionedDirectoryPath(baseDirectoryPath), blobsDirectoryName);
 }
 
+void traverseRecordsFiles(const String& recordsPath, const std::function<void (const String&, const String&)>& function)
+{
+    traverseDirectory(recordsPath, [&recordsPath, &function](const String& subdirName, DirectoryEntryType type) {
+        if (type != DirectoryEntryType::Directory)
+            return;
+        String partitionPath = WebCore::pathByAppendingComponent(recordsPath, subdirName);
+        traverseDirectory(partitionPath, [&function, &partitionPath](const String& fileName, DirectoryEntryType type) {
+            if (type != DirectoryEntryType::File)
+                return;
+            function(fileName, partitionPath);
+        });
+    });
+}
+
+static void deleteEmptyRecordsDirectories(const String& recordsPath)
+{
+    traverseDirectory(recordsPath, [&recordsPath](const String& subdirName, DirectoryEntryType type) {
+        if (type != DirectoryEntryType::Directory)
+            return;
+        // Let system figure out if it is really empty.
+        WebCore::deleteEmptyDirectory(WebCore::pathByAppendingComponent(recordsPath, subdirName));
+    });
+}
+
 Storage::Storage(const String& baseDirectoryPath)
     : m_basePath(baseDirectoryPath)
     , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
@@ -150,7 +174,7 @@
         auto bodyFilter = std::make_unique<ContentsFilter>();
         size_t recordsSize = 0;
         unsigned count = 0;
-        traverseCacheFiles(recordsPath(), [&recordFilter, &bodyFilter, &recordsSize, &count](const String& fileName, const String& partitionPath) {
+        traverseRecordsFiles(recordsPath(), [&recordFilter, &bodyFilter, &recordsSize, &count](const String& fileName, const String& partitionPath) {
             auto filePath = WebCore::pathByAppendingComponent(partitionPath, fileName);
 
             bool isBody = fileName.endsWith(bodyPostfix);
@@ -664,7 +688,7 @@
     
     ioQueue().dispatch([this, flags, traverseHandlerPtr] {
         auto& traverseHandler = *traverseHandlerPtr;
-        traverseCacheFiles(recordsPath(), [this, flags, &traverseHandler](const String& fileName, const String& partitionPath) {
+        traverseRecordsFiles(recordsPath(), [this, flags, &traverseHandler](const String& fileName, const String& partitionPath) {
             if (fileName.length() != Key::hashStringLength())
                 return;
             auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
@@ -729,20 +753,18 @@
 
     ioQueue().dispatch([this, modifiedSinceTime, completionHandlerPtr] {
         auto recordsPath = this->recordsPath();
-        traverseDirectory(recordsPath, DT_DIR, [&recordsPath, modifiedSinceTime](const String& subdirName) {
-            String subdirPath = WebCore::pathByAppendingComponent(recordsPath, subdirName);
-            traverseDirectory(subdirPath, DT_REG, [&subdirPath, modifiedSinceTime](const String& fileName) {
-                auto filePath = WebCore::pathByAppendingComponent(subdirPath, fileName);
-                if (modifiedSinceTime > std::chrono::system_clock::time_point::min()) {
-                    auto times = fileTimes(filePath);
-                    if (times.modification < modifiedSinceTime)
-                        return;
-                }
-                WebCore::deleteFile(filePath);
-            });
-            WebCore::deleteEmptyDirectory(subdirPath);
+        traverseRecordsFiles(recordsPath, [modifiedSinceTime](const String& fileName, const String& partitionPath) {
+            auto filePath = WebCore::pathByAppendingComponent(partitionPath, fileName);
+            if (modifiedSinceTime > std::chrono::system_clock::time_point::min()) {
+                auto times = fileTimes(filePath);
+                if (times.modification < modifiedSinceTime)
+                    return;
+            }
+            WebCore::deleteFile(filePath);
         });
 
+        deleteEmptyRecordsDirectories(recordsPath);
+
         // This cleans unreferences blobs.
         m_blobStorage.synchronize();
 
@@ -809,7 +831,7 @@
 
     backgroundIOQueue().dispatch([this] {
         auto recordsPath = this->recordsPath();
-        traverseCacheFiles(recordsPath, [this](const String& fileName, const String& partitionPath) {
+        traverseRecordsFiles(recordsPath, [this](const String& fileName, const String& partitionPath) {
             if (fileName.length() != Key::hashStringLength())
                 return;
             auto recordPath = WebCore::pathByAppendingComponent(partitionPath, fileName);
@@ -829,11 +851,7 @@
             }
         });
 
-        // Let system figure out if they are really empty.
-        traverseDirectory(recordsPath, DT_DIR, [&recordsPath](const String& subdirName) {
-            auto partitionPath = WebCore::pathByAppendingComponent(recordsPath, subdirName);
-            WebCore::deleteEmptyDirectory(partitionPath);
-        });
+        deleteEmptyRecordsDirectories(recordsPath);
 
         RunLoop::main().dispatch([this] {
             m_shrinkInProgress = false;
@@ -847,20 +865,27 @@
 
 void Storage::deleteOldVersions()
 {
-    // Delete V1 cache.
     backgroundIOQueue().dispatch([this] {
         auto cachePath = basePath();
-        traverseDirectory(cachePath, DT_DIR, [&cachePath](const String& subdirName) {
-            if (subdirName.startsWith(versionDirectoryPrefix))
+        traverseDirectory(cachePath, [&cachePath](const String& subdirName, DirectoryEntryType type) {
+            if (type != DirectoryEntryType::Directory)
                 return;
-            String partitionPath = WebCore::pathByAppendingComponent(cachePath, subdirName);
-            traverseDirectory(partitionPath, DT_REG, [&partitionPath](const String& fileName) {
-                WebCore::deleteFile(WebCore::pathByAppendingComponent(partitionPath, fileName));
-            });
-            WebCore::deleteEmptyDirectory(partitionPath);
+            if (!subdirName.startsWith(versionDirectoryPrefix))
+                return;
+            auto versionString = subdirName.substring(strlen(versionDirectoryPrefix));
+            bool success;
+            unsigned directoryVersion = versionString.toUIntStrict(&success);
+            if (!success)
+                return;
+            if (directoryVersion >= version)
+                return;
+
+            auto oldVersionPath = WebCore::pathByAppendingComponent(cachePath, subdirName);
+            LOG(NetworkCacheStorage, "(NetworkProcess) deleting old cache version, path %s", oldVersionPath.utf8().data());
+
+            deleteDirectoryRecursively(oldVersionPath);
         });
     });
-    // FIXME: Delete V2 cache.
 }
 
 }

Modified: trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h (185411 => 185412)


--- trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h	2015-06-10 13:00:49 UTC (rev 185412)
@@ -158,6 +158,9 @@
     BlobStorage m_blobStorage;
 };
 
+// FIXME: Remove, used by NetworkCacheStatistics only.
+void traverseRecordsFiles(const String& recordsPath, const std::function<void (const String&, const String&)>&);
+
 }
 }
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp (185411 => 185412)


--- trunk/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/UIProcess/API/APIUserContentExtensionStore.cpp	2015-06-10 13:00:49 UTC (rev 185412)
@@ -32,7 +32,7 @@
 #include "NetworkCacheData.h"
 #include "NetworkCacheDecoder.h"
 #include "NetworkCacheEncoder.h"
-#include "NetworkCacheFileSystemPosix.h"
+#include "NetworkCacheFileSystem.h"
 #include "SharedMemory.h"
 #include "WebCompiledContentExtension.h"
 #include <WebCore/ContentExtensionCompiler.h>

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (185411 => 185412)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-06-10 11:29:33 UTC (rev 185411)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-06-10 13:00:49 UTC (rev 185412)
@@ -1199,7 +1199,7 @@
 		7CF47FFF17276AE3008ACB91 /* WKBundlePageBannerMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CF47FFD17276AE3008ACB91 /* WKBundlePageBannerMac.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		7EC4F0FB18E4ACBB008056AF /* NetworkProcessCocoa.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7EC4F0F918E4A945008056AF /* NetworkProcessCocoa.mm */; };
 		83048AE61ACA45DC0082C832 /* ProcessThrottlerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 83048AE51ACA45DC0082C832 /* ProcessThrottlerClient.h */; };
-		834B250F1A831A8D00CFB150 /* NetworkCacheFileSystemPosix.h in Headers */ = {isa = PBXBuildFile; fileRef = 834B250E1A831A8D00CFB150 /* NetworkCacheFileSystemPosix.h */; };
+		834B250F1A831A8D00CFB150 /* NetworkCacheFileSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = 834B250E1A831A8D00CFB150 /* NetworkCacheFileSystem.h */; };
 		834B25121A842C8700CFB150 /* NetworkCacheStatistics.h in Headers */ = {isa = PBXBuildFile; fileRef = 834B25101A842C8700CFB150 /* NetworkCacheStatistics.h */; };
 		8360349F1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */; };
 		836034A01ACB34D600626549 /* WebSQLiteDatabaseTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */; };
@@ -1805,6 +1805,7 @@
 		E4436ECE1A0D040B00EAD204 /* NetworkCacheKey.h in Headers */ = {isa = PBXBuildFile; fileRef = E4436EC11A0CFDB200EAD204 /* NetworkCacheKey.h */; };
 		E4436ECF1A0D040B00EAD204 /* NetworkCacheStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = E4436EC21A0CFDB200EAD204 /* NetworkCacheStorage.h */; };
 		E4436ED01A0D040B00EAD204 /* NetworkCacheStorage.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4436EC31A0CFDB200EAD204 /* NetworkCacheStorage.cpp */; };
+		E4697CCD1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4697CCC1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp */; };
 		E47D1E981B0649FB002676A8 /* NetworkCacheData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47D1E961B062B66002676A8 /* NetworkCacheData.cpp */; };
 		E489D28A1A0A2DB80078C06A /* NetworkCacheCoder.h in Headers */ = {isa = PBXBuildFile; fileRef = E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */; };
 		E489D28B1A0A2DB80078C06A /* NetworkCacheCoders.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */; };
@@ -3434,7 +3435,7 @@
 		7CF47FFD17276AE3008ACB91 /* WKBundlePageBannerMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundlePageBannerMac.h; sourceTree = "<group>"; };
 		7EC4F0F918E4A945008056AF /* NetworkProcessCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = NetworkProcessCocoa.mm; path = NetworkProcess/cocoa/NetworkProcessCocoa.mm; sourceTree = "<group>"; };
 		83048AE51ACA45DC0082C832 /* ProcessThrottlerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProcessThrottlerClient.h; sourceTree = "<group>"; };
-		834B250E1A831A8D00CFB150 /* NetworkCacheFileSystemPosix.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheFileSystemPosix.h; sourceTree = "<group>"; };
+		834B250E1A831A8D00CFB150 /* NetworkCacheFileSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheFileSystem.h; sourceTree = "<group>"; };
 		834B25101A842C8700CFB150 /* NetworkCacheStatistics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheStatistics.h; sourceTree = "<group>"; };
 		8360349D1ACB34D600626549 /* WebSQLiteDatabaseTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebSQLiteDatabaseTracker.cpp; sourceTree = "<group>"; };
 		8360349E1ACB34D600626549 /* WebSQLiteDatabaseTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebSQLiteDatabaseTracker.h; sourceTree = "<group>"; };
@@ -4084,6 +4085,7 @@
 		E4436EC11A0CFDB200EAD204 /* NetworkCacheKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheKey.h; sourceTree = "<group>"; };
 		E4436EC21A0CFDB200EAD204 /* NetworkCacheStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheStorage.h; sourceTree = "<group>"; };
 		E4436EC31A0CFDB200EAD204 /* NetworkCacheStorage.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheStorage.cpp; sourceTree = "<group>"; };
+		E4697CCC1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheFileSystem.cpp; sourceTree = "<group>"; };
 		E47D1E961B062B66002676A8 /* NetworkCacheData.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheData.cpp; sourceTree = "<group>"; };
 		E489D2831A0A2DB80078C06A /* NetworkCacheCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkCacheCoder.h; sourceTree = "<group>"; };
 		E489D2841A0A2DB80078C06A /* NetworkCacheCoders.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkCacheCoders.cpp; sourceTree = "<group>"; };
@@ -7569,7 +7571,8 @@
 				E489D2891A0A2DB80078C06A /* NetworkCacheEncoder.h */,
 				E413F59E1AC1AF9D00345360 /* NetworkCacheEntry.cpp */,
 				E413F59B1AC1ADB600345360 /* NetworkCacheEntry.h */,
-				834B250E1A831A8D00CFB150 /* NetworkCacheFileSystemPosix.h */,
+				834B250E1A831A8D00CFB150 /* NetworkCacheFileSystem.h */,
+				E4697CCC1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp */,
 				E42E060B1AA7440D00B11699 /* NetworkCacheIOChannel.h */,
 				E42E060D1AA750E500B11699 /* NetworkCacheIOChannelCocoa.mm */,
 				E4436EC01A0CFDB200EAD204 /* NetworkCacheKey.cpp */,
@@ -7864,7 +7867,7 @@
 				E489D28E1A0A2DB80078C06A /* NetworkCacheDecoder.h in Headers */,
 				E489D2901A0A2DB80078C06A /* NetworkCacheEncoder.h in Headers */,
 				E413F59D1AC1ADC400345360 /* NetworkCacheEntry.h in Headers */,
-				834B250F1A831A8D00CFB150 /* NetworkCacheFileSystemPosix.h in Headers */,
+				834B250F1A831A8D00CFB150 /* NetworkCacheFileSystem.h in Headers */,
 				E42E06101AA7523B00B11699 /* NetworkCacheIOChannel.h in Headers */,
 				E4436ECE1A0D040B00EAD204 /* NetworkCacheKey.h in Headers */,
 				834B25121A842C8700CFB150 /* NetworkCacheStatistics.h in Headers */,
@@ -9676,6 +9679,7 @@
 				E42E06141AA75B7000B11699 /* NetworkCacheDataCocoa.mm in Sources */,
 				E489D28D1A0A2DB80078C06A /* NetworkCacheDecoder.cpp in Sources */,
 				E489D28F1A0A2DB80078C06A /* NetworkCacheEncoder.cpp in Sources */,
+				E4697CCD1B25EB8F001B0A6C /* NetworkCacheFileSystem.cpp in Sources */,
 				E413F59F1AC1AF9D00345360 /* NetworkCacheEntry.cpp in Sources */,
 				E42E060F1AA7523400B11699 /* NetworkCacheIOChannelCocoa.mm in Sources */,
 				E4436ECD1A0D040B00EAD204 /* NetworkCacheKey.cpp in Sources */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to