Skip to content

Commit

Permalink
Use CheckedPtr for m_preloads in CachedResourceLoader
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=251440

Reviewed by NOBODY (OOPS!).

Made it possible to make CheckedPtr for CachedResource and deployed it in CachedResourceLoader::m_preloads.

* Source/WebCore/loader/cache/CachedResource.h:
(WebCore::CachedResource::isLinkPreload const):
(WebCore::CachedResource::isLinkPreload): Made this accessor function const.
* Source/WebCore/loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::preload):
(WebCore::CachedResourceLoader::clearPreloads):
* Source/WebCore/loader/cache/CachedResourceLoader.h:
  • Loading branch information
rniwa committed Jan 31, 2023
1 parent 93717e0 commit b572acb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Source/WebCore/loader/cache/CachedResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "Timer.h"
#include <pal/SessionID.h>
#include <time.h>
#include <wtf/CheckedRef.h>
#include <wtf/HashCountedSet.h>
#include <wtf/HashSet.h>
#include <wtf/TypeCasts.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ enum class CachePolicy : uint8_t;
// from CachedResourceClient, to get the function calls in case the requested data has arrived.
// This class also does the actual communication with the loader to obtain the resource from the network.
DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(CachedResource);
class CachedResource {
class CachedResource : public CanMakeCheckedPtr {
WTF_MAKE_NONCOPYABLE(CachedResource);
WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(CachedResource);
friend class MemoryCache;
Expand Down Expand Up @@ -258,7 +259,7 @@ class CachedResource {
bool isPreloaded() const { return m_preloadCount; }
void increasePreloadCount() { ++m_preloadCount; }
void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; }
bool isLinkPreload() { return m_isLinkPreload; }
bool isLinkPreload() const { return m_isLinkPreload; }
void setLinkPreload() { m_isLinkPreload = true; }
bool hasUnknownEncoding() { return m_hasUnknownEncoding; }
void setHasUnknownEncoding(bool hasUnknownEncoding) { m_hasUnknownEncoding = hasUnknownEncoding; }
Expand Down
8 changes: 4 additions & 4 deletions Source/WebCore/loader/cache/CachedResourceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ ResourceErrorOr<CachedResourceHandle<CachedResource>> CachedResourceLoader::prel
resourceValue->increasePreloadCount();

if (!m_preloads)
m_preloads = makeUnique<ListHashSet<CachedResource*>>();
m_preloads = makeUnique<ListHashSet<CheckedPtr<CachedResource>>>();
m_preloads->add(resourceValue.get());
}
return resource;
Expand Down Expand Up @@ -1700,12 +1700,12 @@ void CachedResourceLoader::clearPreloads(ClearPreloadsMode mode)
if (!m_preloads)
return;

std::unique_ptr<ListHashSet<CachedResource*>> remainingLinkPreloads;
for (auto* resource : *m_preloads) {
std::unique_ptr<ListHashSet<CheckedPtr<CachedResource>>> remainingLinkPreloads;
for (auto& resource : *m_preloads) {
ASSERT(resource);
if (mode == ClearPreloadsMode::ClearSpeculativePreloads && resource->isLinkPreload()) {
if (!remainingLinkPreloads)
remainingLinkPreloads = makeUnique<ListHashSet<CachedResource*>>();
remainingLinkPreloads = makeUnique<ListHashSet<CheckedPtr<CachedResource>>>();
remainingLinkPreloads->add(resource);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/loader/cache/CachedResourceLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ friend class ResourceCacheValidationSuppressor;

int m_requestCount { 0 };

std::unique_ptr<ListHashSet<CachedResource*>> m_preloads;
std::unique_ptr<ListHashSet<CheckedPtr<CachedResource>>> m_preloads;
Timer m_unusedPreloadsTimer;

Timer m_garbageCollectDocumentResourcesTimer;
Expand Down

0 comments on commit b572acb

Please sign in to comment.