Title: [218559] releases/WebKitGTK/webkit-2.16/Source/WebCore
- Revision
- 218559
- Author
- [email protected]
- Date
- 2017-06-20 00:46:04 -0700 (Tue, 20 Jun 2017)
Log Message
Merge r217682 - Make WebCore::defaultPortForProtocol() thread-safe
https://bugs.webkit.org/show_bug.cgi?id=172797
Reviewed by Brent Fulgham.
Make WebCore::defaultPortForProtocol() thread-safe since it is called from the SecurityOrigin
constructor and SecurityOrigin objects are constructed from various threads.
This should not regress the non-testing code paths since we only pay locking costs if
a default port override has been set by the tests.
* platform/URL.cpp:
(WebCore::defaultPortForProtocolMapLock):
(WebCore::defaultPortForProtocolMapForTesting):
(WebCore::ensureDefaultPortForProtocolMapForTesting):
(WebCore::registerDefaultPortForProtocolForTesting):
(WebCore::clearDefaultPortForProtocolMapForTesting):
(WebCore::defaultPortForProtocol):
Modified Paths
Diff
Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog (218558 => 218559)
--- releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog 2017-06-20 07:45:40 UTC (rev 218558)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/ChangeLog 2017-06-20 07:46:04 UTC (rev 218559)
@@ -1,3 +1,24 @@
+2017-06-01 Chris Dumez <[email protected]>
+
+ Make WebCore::defaultPortForProtocol() thread-safe
+ https://bugs.webkit.org/show_bug.cgi?id=172797
+
+ Reviewed by Brent Fulgham.
+
+ Make WebCore::defaultPortForProtocol() thread-safe since it is called from the SecurityOrigin
+ constructor and SecurityOrigin objects are constructed from various threads.
+
+ This should not regress the non-testing code paths since we only pay locking costs if
+ a default port override has been set by the tests.
+
+ * platform/URL.cpp:
+ (WebCore::defaultPortForProtocolMapLock):
+ (WebCore::defaultPortForProtocolMapForTesting):
+ (WebCore::ensureDefaultPortForProtocolMapForTesting):
+ (WebCore::registerDefaultPortForProtocolForTesting):
+ (WebCore::clearDefaultPortForProtocolMapForTesting):
+ (WebCore::defaultPortForProtocol):
+
2017-05-30 Dan Bernstein <[email protected]>
Fixed the build after r217588.
Modified: releases/WebKitGTK/webkit-2.16/Source/WebCore/platform/URL.cpp (218558 => 218559)
--- releases/WebKitGTK/webkit-2.16/Source/WebCore/platform/URL.cpp 2017-06-20 07:45:40 UTC (rev 218558)
+++ releases/WebKitGTK/webkit-2.16/Source/WebCore/platform/URL.cpp 2017-06-20 07:46:04 UTC (rev 218559)
@@ -549,29 +549,49 @@
#endif
+static Lock& defaultPortForProtocolMapForTestingLock()
+{
+ static NeverDestroyed<Lock> lock;
+ return lock;
+}
+
using DefaultPortForProtocolMapForTesting = HashMap<String, uint16_t>;
-static DefaultPortForProtocolMapForTesting& defaultPortForProtocolMapForTesting()
+static DefaultPortForProtocolMapForTesting*& defaultPortForProtocolMapForTesting()
{
- static NeverDestroyed<DefaultPortForProtocolMapForTesting> defaultPortForProtocolMap;
+ static DefaultPortForProtocolMapForTesting* defaultPortForProtocolMap;
return defaultPortForProtocolMap;
}
+static DefaultPortForProtocolMapForTesting& ensureDefaultPortForProtocolMapForTesting()
+{
+ DefaultPortForProtocolMapForTesting*& defaultPortForProtocolMap = defaultPortForProtocolMapForTesting();
+ if (!defaultPortForProtocolMap)
+ defaultPortForProtocolMap = new DefaultPortForProtocolMapForTesting;
+ return *defaultPortForProtocolMap;
+}
+
void registerDefaultPortForProtocolForTesting(uint16_t port, const String& protocol)
{
- defaultPortForProtocolMapForTesting().add(protocol, port);
+ LockHolder locker(defaultPortForProtocolMapForTestingLock());
+ ensureDefaultPortForProtocolMapForTesting().add(protocol, port);
}
void clearDefaultPortForProtocolMapForTesting()
{
- defaultPortForProtocolMapForTesting().clear();
+ LockHolder locker(defaultPortForProtocolMapForTestingLock());
+ if (auto* map = defaultPortForProtocolMapForTesting())
+ map->clear();
}
std::optional<uint16_t> defaultPortForProtocol(StringView protocol)
{
- const auto& defaultPortForProtocolMap = defaultPortForProtocolMapForTesting();
- auto iterator = defaultPortForProtocolMap.find(protocol.toStringWithoutCopying());
- if (iterator != defaultPortForProtocolMap.end())
- return iterator->value;
+ if (auto* overrideMap = defaultPortForProtocolMapForTesting()) {
+ LockHolder locker(defaultPortForProtocolMapForTestingLock());
+ ASSERT(overrideMap); // No need to null check again here since overrideMap cannot become null after being non-null.
+ auto iterator = overrideMap->find(protocol.toStringWithoutCopying());
+ if (iterator != overrideMap->end())
+ return iterator->value;
+ }
return URLParser::defaultPortForProtocol(protocol);
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes