Title: [290854] trunk/Source/WebCore
- Revision
- 290854
- Author
- [email protected]
- Date
- 2022-03-04 16:48:00 -0800 (Fri, 04 Mar 2022)
Log Message
Modernize OriginLock
https://bugs.webkit.org/show_bug.cgi?id=237485
Reviewed by Darin Adler.
OriginLock subclasses ThreadSafeRefCounted. As a result, it should have a create()
factory function instead of an error-prone public constructor. Its functions should
also take String parameters by const reference instead of by value.
* Modules/webdatabase/DatabaseTracker.cpp:
(WebCore::DatabaseTracker::originLockFor):
* Modules/webdatabase/DatabaseTracker.h:
* Modules/webdatabase/OriginLock.cpp:
(WebCore::lockFileNameForPath):
(WebCore::OriginLock::OriginLock):
(WebCore::OriginLock::deleteLockFile):
(WebCore::OriginLock::lockFileNameForPath): Deleted.
* Modules/webdatabase/OriginLock.h:
(WebCore::OriginLock::create):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (290853 => 290854)
--- trunk/Source/WebCore/ChangeLog 2022-03-04 23:45:03 UTC (rev 290853)
+++ trunk/Source/WebCore/ChangeLog 2022-03-05 00:48:00 UTC (rev 290854)
@@ -1,3 +1,25 @@
+2022-03-04 Chris Dumez <[email protected]>
+
+ Modernize OriginLock
+ https://bugs.webkit.org/show_bug.cgi?id=237485
+
+ Reviewed by Darin Adler.
+
+ OriginLock subclasses ThreadSafeRefCounted. As a result, it should have a create()
+ factory function instead of an error-prone public constructor. Its functions should
+ also take String parameters by const reference instead of by value.
+
+ * Modules/webdatabase/DatabaseTracker.cpp:
+ (WebCore::DatabaseTracker::originLockFor):
+ * Modules/webdatabase/DatabaseTracker.h:
+ * Modules/webdatabase/OriginLock.cpp:
+ (WebCore::lockFileNameForPath):
+ (WebCore::OriginLock::OriginLock):
+ (WebCore::OriginLock::deleteLockFile):
+ (WebCore::OriginLock::lockFileNameForPath): Deleted.
+ * Modules/webdatabase/OriginLock.h:
+ (WebCore::OriginLock::create):
+
2022-03-04 Kate Cheney <[email protected]>
about:blank iframes do not always inherit parent CSP
Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp (290853 => 290854)
--- trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp 2022-03-04 23:45:03 UTC (rev 290853)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp 2022-03-05 00:48:00 UTC (rev 290854)
@@ -595,7 +595,7 @@
delete nameMap;
}
-RefPtr<OriginLock> DatabaseTracker::originLockFor(const SecurityOriginData& origin)
+Ref<OriginLock> DatabaseTracker::originLockFor(const SecurityOriginData& origin)
{
Locker lockDatabase { m_databaseGuard };
String databaseIdentifier = origin.databaseIdentifier();
@@ -607,17 +607,9 @@
// thread-safe, since our copy is guarded by the m_databaseGuard mutex.
databaseIdentifier = databaseIdentifier.isolatedCopy();
- OriginLockMap::AddResult addResult =
- m_originLockMap.add(databaseIdentifier, RefPtr<OriginLock>());
- if (!addResult.isNewEntry)
- return addResult.iterator->value;
-
- String path = originPath(origin);
- RefPtr<OriginLock> lock = adoptRef(*new OriginLock(path));
- ASSERT(lock);
- addResult.iterator->value = lock;
-
- return lock;
+ return m_originLockMap.ensure(databaseIdentifier, [&] {
+ return OriginLock::create(originPath(origin));
+ }).iterator->value;
}
void DatabaseTracker::deleteOriginLockFor(const SecurityOriginData& origin)
Modified: trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.h (290853 => 290854)
--- trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.h 2022-03-04 23:45:03 UTC (rev 290853)
+++ trunk/Source/WebCore/Modules/webdatabase/DatabaseTracker.h 2022-03-05 00:48:00 UTC (rev 290854)
@@ -90,7 +90,7 @@
WEBCORE_EXPORT uint64_t usage(const SecurityOriginData&);
WEBCORE_EXPORT uint64_t quota(const SecurityOriginData&);
WEBCORE_EXPORT void setQuota(const SecurityOriginData&, uint64_t);
- RefPtr<OriginLock> originLockFor(const SecurityOriginData&);
+ Ref<OriginLock> originLockFor(const SecurityOriginData&);
WEBCORE_EXPORT void deleteAllDatabasesImmediately();
WEBCORE_EXPORT void deleteDatabasesModifiedSince(WallTime);
@@ -169,7 +169,7 @@
Lock m_databaseGuard;
SQLiteDatabase m_database WTF_GUARDED_BY_LOCK(m_databaseGuard);
- using OriginLockMap = HashMap<String, RefPtr<OriginLock>>;
+ using OriginLockMap = HashMap<String, Ref<OriginLock>>;
OriginLockMap m_originLockMap WTF_GUARDED_BY_LOCK(m_databaseGuard);
String m_databaseDirectoryPath;
Modified: trunk/Source/WebCore/Modules/webdatabase/OriginLock.cpp (290853 => 290854)
--- trunk/Source/WebCore/Modules/webdatabase/OriginLock.cpp 2022-03-04 23:45:03 UTC (rev 290853)
+++ trunk/Source/WebCore/Modules/webdatabase/OriginLock.cpp 2022-03-05 00:48:00 UTC (rev 290854)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,16 +28,13 @@
namespace WebCore {
-String OriginLock::lockFileNameForPath(String originPath)
+static String lockFileNameForPath(const String& originPath)
{
return FileSystem::pathByAppendingComponent(originPath, ".lock"_s);
}
-OriginLock::OriginLock(String originPath)
+OriginLock::OriginLock(const String& originPath)
: m_lockFileName(lockFileNameForPath(originPath).isolatedCopy())
-#if USE(FILE_LOCK)
- , m_lockHandle(FileSystem::invalidPlatformFileHandle)
-#endif
{
}
@@ -76,12 +73,12 @@
m_mutex.unlock();
}
-void OriginLock::deleteLockFile(String originPath)
+void OriginLock::deleteLockFile(const String& originPath)
{
+#if USE(FILE_LOCK)
+ FileSystem::deleteFile(lockFileNameForPath(originPath));
+#else
UNUSED_PARAM(originPath);
-#if USE(FILE_LOCK)
- String lockFileName = OriginLock::lockFileNameForPath(originPath);
- FileSystem::deleteFile(lockFileName);
#endif
}
Modified: trunk/Source/WebCore/Modules/webdatabase/OriginLock.h (290853 => 290854)
--- trunk/Source/WebCore/Modules/webdatabase/OriginLock.h 2022-03-04 23:45:03 UTC (rev 290853)
+++ trunk/Source/WebCore/Modules/webdatabase/OriginLock.h 2022-03-05 00:48:00 UTC (rev 290854)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2022 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -33,23 +33,25 @@
namespace WebCore {
class OriginLock : public ThreadSafeRefCounted<OriginLock> {
- WTF_MAKE_NONCOPYABLE(OriginLock); WTF_MAKE_FAST_ALLOCATED;
public:
- explicit OriginLock(String originPath);
+ static Ref<OriginLock> create(const String& originPath)
+ {
+ return adoptRef(*new OriginLock(originPath));
+ }
WEBCORE_EXPORT ~OriginLock();
void lock();
void unlock();
- static void deleteLockFile(String originPath);
+ static void deleteLockFile(const String& originPath);
private:
- static String lockFileNameForPath(String originPath);
+ explicit OriginLock(const String& originPath);
String m_lockFileName;
Lock m_mutex;
#if USE(FILE_LOCK)
- FileSystem::PlatformFileHandle m_lockHandle;
+ FileSystem::PlatformFileHandle m_lockHandle { FileSystem::invalidPlatformFileHandle };
#endif
};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes