Skip to content

Commit

Permalink
Move function definitions in StorageUtilities.h to StorageUtilities.cpp
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=259745
rdar://113287619

Reviewed by Chris Dumez.

These functions are too complicated to make inline useful. This patch also moves StorageUtilities to WebCore so WebCore
code could use the utility functions later.

* Source/WebCore/Headers.cmake:
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/storage/Storage.idl:
* Source/WebCore/storage/StorageUtilities.cpp: Renamed from Source/WebKit/NetworkProcess/storage/StorageUtilities.h.
(WebCore::StorageUtilities::readOriginFromFile):
(WebCore::StorageUtilities::writeOriginToFile):
* Source/WebCore/storage/StorageUtilities.h: Added.
* Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp:
(WebKit::CacheStorageManager::originsOfCacheStorageData):
(WebKit::CacheStorageManager::CacheStorageManager):
* Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::writeOriginToFileIfNecessary):
(WebKit::NetworkStorageManager::getAllOrigins):
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:

Canonical link: https://commits.webkit.org/266555@main
  • Loading branch information
szewai committed Aug 3, 2023
1 parent 4fdd040 commit ef13171
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
storage/StorageNamespaceProvider.h
storage/StorageQuotaManager.h
storage/StorageType.h
storage/StorageUtilities.h

style/StyleAppearance.h
style/StyleChange.h
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,7 @@ storage/StorageEventDispatcher.cpp
storage/StorageMap.cpp
storage/StorageNamespaceProvider.cpp
storage/StorageQuotaManager.cpp
storage/StorageUtilities.cpp
style/AttributeChangeInvalidation.cpp
style/ChildChangeInvalidation.cpp
style/ClassChangeInvalidation.cpp
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/WebCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3424,6 +3424,7 @@
936583B726AB92B5004E61F4 /* IDBTransactionDurability.h in Headers */ = {isa = PBXBuildFile; fileRef = 936583B626AB9174004E61F4 /* IDBTransactionDurability.h */; settings = {ATTRIBUTES = (Private, ); }; };
9370918D1416D86B00477333 /* textAreaResizeCorner@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9370918C1416D86B00477333 /* textAreaResizeCorner@2x.png */; };
9377ABA015DEFEEF0031FD04 /* Pagination.h in Headers */ = {isa = PBXBuildFile; fileRef = 9377AB9F15DEFEEF0031FD04 /* Pagination.h */; settings = {ATTRIBUTES = (Private, ); }; };
9377D8322A7AD93400F5E7F1 /* StorageUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 9377D8302A7AD93200F5E7F1 /* StorageUtilities.h */; settings = {ATTRIBUTES = (Private, ); }; };
937FF3D51A1012D6008EBA31 /* DictionaryLookup.h in Headers */ = {isa = PBXBuildFile; fileRef = 937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */; settings = {ATTRIBUTES = (Private, ); }; };
9380F47409A11AB4001FDB34 /* Widget.h in Headers */ = {isa = PBXBuildFile; fileRef = 9380F47209A11AB4001FDB34 /* Widget.h */; settings = {ATTRIBUTES = (Private, ); }; };
9382AAB40D8C386100F357A6 /* NodeWithIndex.h in Headers */ = {isa = PBXBuildFile; fileRef = 9382AAB10D8C386100F357A6 /* NodeWithIndex.h */; };
Expand Down Expand Up @@ -14331,6 +14332,8 @@
9371080D1DB754550060744E /* WindowOrWorkerGlobalScope.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WindowOrWorkerGlobalScope.idl; sourceTree = "<group>"; };
9372B5202559E51E00E058CF /* BoundaryPoint.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = BoundaryPoint.cpp; sourceTree = "<group>"; };
9377AB9F15DEFEEF0031FD04 /* Pagination.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Pagination.h; sourceTree = "<group>"; };
9377D8302A7AD93200F5E7F1 /* StorageUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageUtilities.h; sourceTree = "<group>"; };
9377D8312A7AD93300F5E7F1 /* StorageUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageUtilities.cpp; sourceTree = "<group>"; };
937FF3D41A1012D6008EBA31 /* DictionaryLookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DictionaryLookup.h; sourceTree = "<group>"; };
937FF3D61A10131B008EBA31 /* DictionaryLookup.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DictionaryLookup.mm; sourceTree = "<group>"; };
9380F47109A11AB4001FDB34 /* Widget.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Widget.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -21597,6 +21600,8 @@
41DE7C7A222DA13D00532B65 /* StorageQuotaManager.cpp */,
41DE7C7B222DA13E00532B65 /* StorageQuotaManager.h */,
5166D3CC1E8ED41100AD62E3 /* StorageType.h */,
9377D8312A7AD93300F5E7F1 /* StorageUtilities.cpp */,
9377D8302A7AD93200F5E7F1 /* StorageUtilities.h */,
);
indentWidth = 4;
path = storage;
Expand Down Expand Up @@ -40854,6 +40859,7 @@
41DE7C7C222DA14300532B65 /* StorageQuotaManager.h in Headers */,
5C9EF2F321F06190003BDC56 /* StorageSessionProvider.h in Headers */,
5166D3CD1E8ED48F00AD62E3 /* StorageType.h in Headers */,
9377D8322A7AD93400F5E7F1 /* StorageUtilities.h in Headers */,
4682D2001F79783000C863DB /* StoredCredentialsPolicy.h in Headers */,
416E6FE81BBD12DF000A6033 /* StreamInternalsBuiltins.h in Headers */,
7C5266981F1B0302000F068B /* StringAdaptors.h in Headers */,
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/storage/Storage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
deleter undefined removeItem(DOMString key);
undefined clear();
};

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Apple Inc. All rights reserved.
* Copyright (C) 2023 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand All @@ -23,17 +23,19 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#pragma once
#include "config.h"
#include "StorageUtilities.h"

#include <WebCore/ClientOrigin.h>
#include <WebCore/WebCorePersistentCoders.h>
#include "ClientOrigin.h"
#include "WebCorePersistentCoders.h"
#include <wtf/FileSystem.h>
#include <wtf/Scope.h>
#include <wtf/persistence/PersistentCoders.h>

namespace WebKit {
namespace WebCore {
namespace StorageUtilities {

static inline std::optional<WebCore::ClientOrigin> readOriginFromFile(const String& filePath)
std::optional<ClientOrigin> readOriginFromFile(const String& filePath)
{
ASSERT(!RunLoop::isMain());

Expand All @@ -53,12 +55,12 @@ static inline std::optional<WebCore::ClientOrigin> readOriginFromFile(const Stri
return std::nullopt;

WTF::Persistence::Decoder decoder({ originContent->data(), originContent->size() });
std::optional<WebCore::ClientOrigin> origin;
std::optional<ClientOrigin> origin;
decoder >> origin;
return origin;
}

static inline bool writeOriginToFile(const String& filePath, const WebCore::ClientOrigin& origin)
bool writeOriginToFile(const String& filePath, const ClientOrigin& origin)
{
if (filePath.isEmpty() || FileSystem::fileExists(filePath))
return false;
Expand All @@ -80,4 +82,8 @@ static inline bool writeOriginToFile(const String& filePath, const WebCore::Clie
return true;
}

}
} // namespace WebKit
} // namespace StorageUtilities



37 changes: 37 additions & 0 deletions Source/WebCore/storage/StorageUtilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2023 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.
*/

#pragma once

namespace WebCore {
struct ClientOrigin;

namespace StorageUtilities {

WEBCORE_EXPORT std::optional<ClientOrigin> readOriginFromFile(const String& path);
WEBCORE_EXPORT bool writeOriginToFile(const String& path, const ClientOrigin&);

} // namespace StorageUtilities
} // namespace WebCore
6 changes: 3 additions & 3 deletions Source/WebKit/NetworkProcess/storage/CacheStorageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

#include "CacheStorageCache.h"
#include "CacheStorageRegistry.h"
#include "StorageUtilities.h"
#include <WebCore/ClientOrigin.h>
#include <WebCore/StorageUtilities.h>
#include <wtf/CallbackAggregator.h>
#include <wtf/Scope.h>
#include <wtf/persistence/PersistentEncoder.h>
Expand Down Expand Up @@ -191,7 +191,7 @@ HashSet<WebCore::ClientOrigin> CacheStorageManager::originsOfCacheStorageData(co
HashSet<WebCore::ClientOrigin> result;
for (auto& originName : FileSystem::listDirectory(rootDirectory)) {
auto originFile = FileSystem::pathByAppendingComponents(rootDirectory, { originName, originFileName });
if (auto origin = readOriginFromFile(originFile))
if (auto origin = WebCore::StorageUtilities::readOriginFromFile(originFile))
result.add(*origin);
}

Expand Down Expand Up @@ -250,7 +250,7 @@ CacheStorageManager::CacheStorageManager(const String& path, CacheStorageRegistr
return;

auto originFile = FileSystem::pathByAppendingComponent(m_path, originFileName);
writeOriginToFile(originFile, *origin);
WebCore::StorageUtilities::writeOriginToFile(originFile, *origin);
}

CacheStorageManager::~CacheStorageManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
#include "StorageAreaBase.h"
#include "StorageAreaMapMessages.h"
#include "StorageAreaRegistry.h"
#include "StorageUtilities.h"
#include "UnifiedOriginStorageLevel.h"
#include "WebsiteDataType.h"
#include <WebCore/SecurityOriginData.h>
#include <WebCore/StorageUtilities.h>
#include <WebCore/UniqueIDBDatabaseConnection.h>
#include <WebCore/UniqueIDBDatabaseTransaction.h>
#include <pal/crypto/CryptoDigest.h>
Expand Down Expand Up @@ -347,7 +347,7 @@ void NetworkStorageManager::writeOriginToFileIfNecessary(const WebCore::ClientOr
return;

auto originFile = originFilePath(originDirectory);
bool didWrite = writeOriginToFile(originFile, origin);
bool didWrite = WebCore::StorageUtilities::writeOriginToFile(originFile, origin);
auto timestamp = FileSystem::fileCreationTime(originFile);
manager->setOriginFileCreationTimestamp(timestamp);
#if PLATFORM(IOS_FAMILY)
Expand Down Expand Up @@ -929,7 +929,7 @@ HashSet<WebCore::ClientOrigin> NetworkStorageManager::getAllOrigins()
allOrigins.add(origin);

forEachOriginDirectory([&](auto directory) {
if (auto origin = readOriginFromFile(originFilePath(directory)))
if (auto origin = WebCore::StorageUtilities::readOriginFromFile(originFilePath(directory)))
allOrigins.add(*origin);
});

Expand Down
4 changes: 0 additions & 4 deletions Source/WebKit/WebKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,6 @@
935BF8002936BF1A00B41326 /* CacheStorageManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 935BF7F62936BF1800B41326 /* CacheStorageManager.h */; };
935BF8042936BF1A00B41326 /* CacheStorageRecord.h in Headers */ = {isa = PBXBuildFile; fileRef = 935BF7FA2936BF1900B41326 /* CacheStorageRecord.h */; };
935BF8072936C9FD00B41326 /* CacheStorageRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 935BF8062936C9FC00B41326 /* CacheStorageRegistry.h */; };
935BF80A2936CB8500B41326 /* StorageUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 935BF8092936CB8400B41326 /* StorageUtilities.h */; };
935EEB9B1277617C003322B8 /* WKBundleBackForwardListItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 935EEB981277616D003322B8 /* WKBundleBackForwardListItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
935EEB9F127761AC003322B8 /* WKBundleBackForwardList.h in Headers */ = {isa = PBXBuildFile; fileRef = 935EEB961277616D003322B8 /* WKBundleBackForwardList.h */; settings = {ATTRIBUTES = (Private, ); }; };
93735EBB1C92986300336FA7 /* WKPreviewActionItemInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 93735EBA1C92986300336FA7 /* WKPreviewActionItemInternal.h */; };
Expand Down Expand Up @@ -5988,7 +5987,6 @@
935BF7FB2936BF1A00B41326 /* CacheStorageCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CacheStorageCache.cpp; sourceTree = "<group>"; };
935BF8062936C9FC00B41326 /* CacheStorageRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CacheStorageRegistry.h; sourceTree = "<group>"; };
935BF8082936CA2F00B41326 /* CacheStorageRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CacheStorageRegistry.cpp; sourceTree = "<group>"; };
935BF8092936CB8400B41326 /* StorageUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageUtilities.h; sourceTree = "<group>"; };
935EEB951277616D003322B8 /* WKBundleBackForwardList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleBackForwardList.cpp; sourceTree = "<group>"; };
935EEB961277616D003322B8 /* WKBundleBackForwardList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBundleBackForwardList.h; sourceTree = "<group>"; };
935EEB971277616D003322B8 /* WKBundleBackForwardListItem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKBundleBackForwardListItem.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -11683,7 +11681,6 @@
93E799D6276121080074008A /* StorageAreaBase.h */,
93E799C5276027360074008A /* StorageAreaRegistry.cpp */,
93E799C6276027370074008A /* StorageAreaRegistry.h */,
935BF8092936CB8400B41326 /* StorageUtilities.h */,
);
path = storage;
sourceTree = "<group>";
Expand Down Expand Up @@ -14732,7 +14729,6 @@
1A334DEE16DE8F88006A8E38 /* StorageAreaMapMessages.h in Headers */,
93E799C7276027460074008A /* StorageAreaRegistry.h in Headers */,
465F4E06230B2E95003CEDB7 /* StorageNamespaceIdentifier.h in Headers */,
935BF80A2936CB8500B41326 /* StorageUtilities.h in Headers */,
7B73123C25CC8525003B2796 /* StreamClientConnection.h in Headers */,
7BE5134B29768F0E00814F18 /* StreamClientConnectionBuffer.h in Headers */,
7B73123A25CC8525003B2796 /* StreamConnectionBuffer.h in Headers */,
Expand Down

0 comments on commit ef13171

Please sign in to comment.