Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CheckedPtr for m_preloads in CachedResourceLoader #9386

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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