Index: third_party/WebKit/Source/core/fetch/Resource.h |
diff --git a/third_party/WebKit/Source/core/fetch/Resource.h b/third_party/WebKit/Source/core/fetch/Resource.h |
index 4558e2feb730d588ae141acd6db72ccd2c0a0826..fb1f31fe4a687103d510adff2a989b614d419429 100644 |
--- a/third_party/WebKit/Source/core/fetch/Resource.h |
+++ b/third_party/WebKit/Source/core/fetch/Resource.h |
@@ -49,7 +49,6 @@ struct FetchInitiatorInfo; |
class CachedMetadata; |
class FetchRequest; |
class ResourceClient; |
-class ResourcePtrBase; |
class ResourceFetcher; |
class ResourceTimingInfo; |
class InspectorResource; |
@@ -60,7 +59,7 @@ class SharedBuffer; |
// A resource that is held in the cache. Classes who want to use this object should derive |
// from ResourceClient, 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. |
-class CORE_EXPORT Resource : public NoBaseWillBeGarbageCollectedFinalized<Resource> { |
+class CORE_EXPORT Resource : public RefCountedWillBeGarbageCollectedFinalized<Resource> { |
WTF_MAKE_NONCOPYABLE(Resource); |
USING_FAST_MALLOC_WITH_TYPE_NAME_WILL_BE_REMOVED(blink::Resource); |
friend class InspectorResource; |
@@ -92,16 +91,13 @@ public: |
}; |
// Exposed for testing. |
- Resource(const ResourceRequest&, Type); |
-#if ENABLE(OILPAN) |
- virtual ~Resource(); |
-#else |
-protected: |
- // Only deleteIfPossible should delete this. |
+ static PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest& request, Type type) |
+ { |
+ return adoptRefWillBeNoop(new Resource(request, type)); |
+ } |
virtual ~Resource(); |
-public: |
-#endif |
- virtual void dispose(); |
+ |
+ virtual void removedFromMemoryCache(); |
DECLARE_VIRTUAL_TRACE(); |
virtual void load(ResourceFetcher*, const ResourceLoaderOptions&); |
@@ -141,7 +137,6 @@ public: |
void addClient(ResourceClient*); |
void removeClient(ResourceClient*); |
bool hasClients() const { return !m_clients.isEmpty() || !m_clientsAwaitingCallback.isEmpty() || !m_finishedClients.isEmpty(); } |
- bool deleteIfPossible(); |
enum PreloadResult { |
PreloadNotReferenced, |
@@ -208,8 +203,6 @@ public: |
// This may return nullptr when the resource isn't cacheable. |
CachedMetadataHandler* cacheHandler(); |
- bool hasOneHandle() const; |
- bool canDelete() const; |
String reasonNotDeletable() const; |
// List of acceptable MIME types separated by ",". |
@@ -229,9 +222,6 @@ public: |
void increasePreloadCount() { ++m_preloadCount; } |
void decreasePreloadCount() { ASSERT(m_preloadCount); --m_preloadCount; } |
- void registerHandle(ResourcePtrBase* h); |
- void unregisterHandle(ResourcePtrBase* h); |
- |
bool canReuseRedirectChain(); |
bool mustRevalidateDueToCacheHeaders(); |
bool canUseCacheValidator(); |
@@ -245,7 +235,6 @@ public: |
double stalenessLifetime(); |
bool isPurgeable() const; |
- bool wasPurged() const; |
bool lock(); |
void setCacheIdentifier(const String& cacheIdentifier) { m_cacheIdentifier = cacheIdentifier; } |
@@ -276,38 +265,13 @@ public: |
#endif |
protected: |
+ Resource(const ResourceRequest&, Type); |
+ |
virtual void checkNotify(); |
virtual void finishOnePart(); |
virtual void destroyDecodedDataForFailedRevalidation() { } |
- // Normal resource pointers will silently switch what Resource* they reference when we |
- // successfully revalidated the resource. We need a way to guarantee that the Resource |
- // that received the 304 response survives long enough to switch everything over to the |
- // revalidatedresource. The normal mechanisms for keeping a Resource alive externally |
- // (ResourcePtrs and ResourceClients registering themselves) don't work in this case, so |
- // have a separate internal protector). |
- class InternalResourcePtr { |
- STACK_ALLOCATED(); |
- public: |
- explicit InternalResourcePtr(Resource* resource) |
- : m_resource(resource) |
- { |
- m_resource->incrementProtectorCount(); |
- } |
- |
- ~InternalResourcePtr() |
- { |
- m_resource->decrementProtectorCount(); |
- m_resource->deleteIfPossible(); |
- } |
- private: |
- RawPtrWillBeMember<Resource> m_resource; |
- }; |
- |
- void incrementProtectorCount() { m_protectorCount++; } |
- void decrementProtectorCount() { m_protectorCount--; } |
- |
void setEncodedSize(size_t); |
void setDecodedSize(size_t); |
void didAccessDecodedData(); |
@@ -329,7 +293,7 @@ protected: |
ResourceCallback(); |
void runTask(); |
OwnPtr<CancellableTaskFactory> m_callbackTaskFactory; |
- WillBeHeapHashSet<RawPtrWillBeMember<Resource>> m_resourcesWithPendingClients; |
+ WillBeHeapHashSet<RefPtrWillBeMember<Resource>> m_resourcesWithPendingClients; |
}; |
bool hasClient(ResourceClient* client) { return m_clients.contains(client) || m_clientsAwaitingCallback.contains(client) || m_finishedClients.contains(client); } |
@@ -378,8 +342,6 @@ private: |
bool unlock(); |
- bool hasRightHandleCountApartFromCache(unsigned targetCount) const; |
- |
void setCachedMetadata(unsigned dataTypeID, const char*, size_t, CachedMetadataHandler::CacheType); |
void clearCachedMetadata(CachedMetadataHandler::CacheType); |
CachedMetadata* cachedMetadata(unsigned dataTypeID) const; |
@@ -401,9 +363,7 @@ private: |
size_t m_encodedSize; |
size_t m_decodedSize; |
- unsigned m_handleCount; |
unsigned m_preloadCount; |
- unsigned m_protectorCount; |
String m_cacheIdentifier; |
@@ -412,13 +372,9 @@ private: |
unsigned m_loading : 1; |
- unsigned m_switchingClientsToRevalidatedResource : 1; |
- |
unsigned m_type : 4; // Type |
unsigned m_status : 3; // Status |
- unsigned m_wasPurged : 1; |
- |
unsigned m_needsSynchronousCacheHit : 1; |
unsigned m_linkPreload : 1; |
@@ -433,7 +389,7 @@ private: |
class ResourceFactory { |
STACK_ALLOCATED(); |
public: |
- virtual Resource* create(const ResourceRequest&, const String&) const = 0; |
+ virtual PassRefPtrWillBeRawPtr<Resource> create(const ResourceRequest&, const String&) const = 0; |
Resource::Type type() const { return m_type; } |
protected: |
@@ -444,7 +400,7 @@ protected: |
#define DEFINE_RESOURCE_TYPE_CASTS(typeName) \ |
DEFINE_TYPE_CASTS(typeName##Resource, Resource, resource, resource->type() == Resource::typeName, resource.type() == Resource::typeName); \ |
- inline typeName##Resource* to##typeName##Resource(const ResourcePtr<Resource>& ptr) { return to##typeName##Resource(ptr.get()); } |
+ inline typeName##Resource* to##typeName##Resource(const RefPtrWillBeRawPtr<Resource>& ptr) { return to##typeName##Resource(ptr.get()); } |
} // namespace blink |