#ifndef CachedResource_h
#define CachedResource_h
#include "PlatformString.h"
#include "ResourceResponse.h"
#include "SharedBuffer.h"
#include <wtf/HashCountedSet.h>
#include <wtf/Vector.h>
#include <time.h>
namespace WebCore {
class Cache;
class CachedResourceClient;
class DocLoader;
class Request;
class CachedResource {
friend class Cache;
public:
enum Type {
ImageResource,
CSSStyleSheet,
Script
#if ENABLE(XSLT)
, XSLStyleSheet
#endif
#if ENABLE(XBL)
, XBL
#endif
};
enum Status {
NotCached, Unknown, New, Pending, Cached };
CachedResource(const String& URL, Type, bool forCache = true, bool sendResourceLoadCallbacks = false);
virtual ~CachedResource();
virtual void setEncoding(const String&) { }
virtual void data(PassRefPtr<SharedBuffer> data, bool allDataReceived) = 0;
virtual void error() = 0;
const String &url() const { return m_url; }
Type type() const { return m_type; }
virtual void ref(CachedResourceClient*);
void deref(CachedResourceClient*);
bool referenced() const { return !m_clients.isEmpty(); }
virtual void allReferencesRemoved() {};
unsigned count() const { return m_clients.size(); }
Status status() const { return m_status; }
unsigned size() const { return encodedSize() + decodedSize(); }
unsigned encodedSize() const { return m_encodedSize; }
unsigned decodedSize() const { return m_decodedSize; }
bool isLoaded() const { return !m_loading; }
void setLoading(bool b) { m_loading = b; }
virtual bool isImage() const { return false; }
unsigned accessCount() const { return m_accessCount; }
void increaseAccessCount() { m_accessCount++; }
void finish();
void setInCache(bool b) { m_inCache = b; }
bool inCache() const { return m_inCache; }
void setInLiveDecodedResourcesList(bool b) { m_inLiveDecodedResourcesList = b; }
bool inLiveDecodedResourcesList() { return m_inLiveDecodedResourcesList; }
void setRequest(Request*);
SharedBuffer* data() const { return m_data.get(); }
void setResponse(const ResourceResponse& response) { m_response = response; }
const ResourceResponse& response() const { return m_response; }
bool canDelete() const { return !referenced() && !m_request; }
bool isExpired() const;
virtual bool schedule() const { return false; }
String accept() const { return m_accept; }
void setAccept(const String& accept) { m_accept = accept; }
bool errorOccurred() const { return m_errorOccurred; }
bool treatAsLocal() const { return m_shouldTreatAsLocal; }
bool sendResourceLoadCallbacks() const { return m_sendResourceLoadCallbacks; }
virtual void destroyDecodedData() {};
void setDocLoader(DocLoader* docLoader) { m_docLoader = docLoader; }
protected:
void setEncodedSize(unsigned);
void setDecodedSize(unsigned);
void didAccessDecodedData(double timeStamp);
HashCountedSet<CachedResourceClient*> m_clients;
String m_url;
String m_accept;
Request* m_request;
ResourceResponse m_response;
RefPtr<SharedBuffer> m_data;
Type m_type;
Status m_status;
bool m_errorOccurred;
private:
unsigned m_encodedSize;
unsigned m_decodedSize;
unsigned m_accessCount;
unsigned m_inLiveDecodedResourcesList;
double m_lastDecodedAccessTime;
bool m_sendResourceLoadCallbacks;
protected:
bool m_inCache;
bool m_loading;
bool m_expireDateChanged;
#ifndef NDEBUG
bool m_deleted;
unsigned m_lruIndex;
#endif
private:
CachedResource* m_nextInAllResourcesList;
CachedResource* m_prevInAllResourcesList;
CachedResource* m_nextInLiveResourcesList;
CachedResource* m_prevInLiveResourcesList;
bool m_shouldTreatAsLocal;
DocLoader* m_docLoader; };
}
#endif