Skip to content

Commit

Permalink
Create IndexedDB version directory in network process
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=270192
rdar://123725258

Reviewed by Geoffrey Garen and Chris Dumez.

We currently create a v0 directory under IndexedDB root directory on main thread of UI process. This patch moves that to
the storage queue in network process to avoid blocking UI process. Also, instead of creating a symlink that points to
the root directory, we create an actual directory and move files into it, because the version upgrade was shipped over
4 years ago and most data should already be migrated to v1 directory. We don't have to keep the circular symlink now.
This patch also removes the v0 directory if it is not needed.

This change is covered by existing IndexedDB API tests (e.g IndexedDB.IndexedDBFileNameV0) as they are using different
versions of data.

* Source/WebKit/NetworkProcess/storage/IDBStorageManager.cpp:
(WebKit::IDBStorageManager::createVersionDirectoryIfNeeded):
* Source/WebKit/NetworkProcess/storage/IDBStorageManager.h:
* Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::NetworkStorageManager):
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::addSession):
(WebKit::NetworkProcessProxy::createSymLinkForFileUpgrade): Deleted.
* Source/WebKit/UIProcess/Network/NetworkProcessProxy.h:

Canonical link: https://commits.webkit.org/275555@main
  • Loading branch information
szewai committed Mar 1, 2024
1 parent 5daeceb commit bd9231e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 16 deletions.
50 changes: 50 additions & 0 deletions Source/WebKit/NetworkProcess/storage/IDBStorageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,56 @@ static bool migrateOriginDataImpl(const String& oldOriginDirectory, const String
return allMoved;
}

void IDBStorageManager::createVersionDirectoryIfNeeded(const String& rootDirectory)
{
if (rootDirectory.isEmpty())
return;

bool oldVersionDirectoryExists = false;
Vector<String> oldVersionNames;
auto fileNames = FileSystem::listDirectory(rootDirectory);
for (auto& name : fileNames) {
if (name == "v0"_s)
oldVersionDirectoryExists = true;
if (name != "v0"_s && name != "v1"_s) {
if (auto origin = WebCore::SecurityOriginData::fromDatabaseIdentifier(name))
oldVersionNames.append(name);
}
}

if (oldVersionNames.isEmpty() && !oldVersionDirectoryExists)
return;

// Delete file or symlink named v0.
auto oldVersionDirectory = FileSystem::pathByAppendingComponent(rootDirectory, "v0"_s);
if (auto fileType = FileSystem::fileType(oldVersionDirectory)) {
// v0 should not be a file in normal case.
if (*fileType == FileSystem::FileType::Regular) {
FileSystem::deleteFile(oldVersionDirectory);
oldVersionDirectoryExists = false;
} else if (*fileType == FileSystem::FileType::SymbolicLink) {
FileSystem::deleteNonEmptyDirectory(oldVersionDirectory);
oldVersionDirectoryExists = false;
}
}

if (oldVersionNames.isEmpty()) {
if (oldVersionDirectoryExists)
FileSystem::deleteEmptyDirectory(oldVersionDirectory);
return;
}

// Migrate data to v0 directory.
if (!oldVersionDirectoryExists)
FileSystem::makeAllDirectories(oldVersionDirectory);

for (auto& name : oldVersionNames) {
auto oldPath = FileSystem::pathByAppendingComponent(rootDirectory, name);
auto newPath = FileSystem::pathByAppendingComponent(oldVersionDirectory, name);
FileSystem::moveFile(oldPath, newPath);
}
}

String IDBStorageManager::idbStorageOriginDirectory(const String& rootDirectory, const WebCore::ClientOrigin& origin)
{
if (rootDirectory.isEmpty())
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/NetworkProcess/storage/IDBStorageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class IDBStorageRegistry;

class IDBStorageManager final : public WebCore::IDBServer::UniqueIDBDatabaseManager {
public:
static void createVersionDirectoryIfNeeded(const String& rootDirectory);
static String idbStorageOriginDirectory(const String& rootDirectory, const WebCore::ClientOrigin&);
static uint64_t idbStorageSize(const String& originDirectory);
static HashSet<WebCore::ClientOrigin> originsOfIDBStorageData(const String& rootDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ NetworkStorageManager::NetworkStorageManager(NetworkProcess& process, PAL::Sessi
}
#endif

IDBStorageManager::createVersionDirectoryIfNeeded(m_customIDBStoragePath);
RunLoop::main().dispatch([protectedThis = WTFMove(protectedThis)] { });
});
}
Expand Down
14 changes: 0 additions & 14 deletions Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,9 +1421,6 @@ void NetworkProcessProxy::addSession(WebsiteDataStore& store, SendParametersToNe
// DispatchMessageEvenWhenWaitingForSyncReply flag.
if (canSendMessage() && sendParametersToNetworkProcess == SendParametersToNetworkProcess::Yes)
send(Messages::NetworkProcess::AddWebsiteDataStore { store.parameters() }, 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
auto sessionID = store.sessionID();
if (!sessionID.isEphemeral())
createSymLinkForFileUpgrade(store.resolvedIndexedDBDatabaseDirectory());
}

void NetworkProcessProxy::removeSession(WebsiteDataStore& websiteDataStore, CompletionHandler<void(String&&)>&& completionHandler)
Expand Down Expand Up @@ -1693,17 +1690,6 @@ void NetworkProcessProxy::testProcessIncomingSyncMessagesWhenWaitingForSyncReply
reply(handled);
}

void NetworkProcessProxy::createSymLinkForFileUpgrade(const String& indexedDatabaseDirectory)
{
if (indexedDatabaseDirectory.isEmpty())
return;

String oldVersionDirectory = FileSystem::pathByAppendingComponent(indexedDatabaseDirectory, "v0"_s);
FileSystem::deleteEmptyDirectory(oldVersionDirectory);
if (!FileSystem::fileExists(oldVersionDirectory))
FileSystem::createSymbolicLink(indexedDatabaseDirectory, oldVersionDirectory);
}

void NetworkProcessProxy::preconnectTo(PAL::SessionID sessionID, WebPageProxyIdentifier webPageProxyID, WebCore::PageIdentifier webPageID, WebCore::ResourceRequest&& request, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, std::optional<NavigatingToAppBoundDomain> isNavigatingToAppBoundDomain)
{
if (!request.url().isValid() || !request.url().protocolIsInHTTPFamily())
Expand Down
2 changes: 0 additions & 2 deletions Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,6 @@ class NetworkProcessProxy final : public AuxiliaryProcessProxy {
enum class SendParametersToNetworkProcess : bool { No, Yes };
void addSession(WebsiteDataStore&, SendParametersToNetworkProcess);
void removeSession(WebsiteDataStore&, CompletionHandler<void(String&&)>&&);

void createSymLinkForFileUpgrade(const String& indexedDatabaseDirectory);

// ProcessThrottlerClient
void sendProcessDidResume(ResumeReason) final;
Expand Down

0 comments on commit bd9231e

Please sign in to comment.