diff options
Diffstat (limited to 'Source/WebCore/loader/appcache/ApplicationCacheStorage.h')
-rw-r--r-- | Source/WebCore/loader/appcache/ApplicationCacheStorage.h | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/Source/WebCore/loader/appcache/ApplicationCacheStorage.h b/Source/WebCore/loader/appcache/ApplicationCacheStorage.h index 76eaa3ecf..9d17a1bcd 100644 --- a/Source/WebCore/loader/appcache/ApplicationCacheStorage.h +++ b/Source/WebCore/loader/appcache/ApplicationCacheStorage.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008, 2010, 2011 Apple Inc. All Rights Reserved. + * Copyright (C) 2008-2017 Apple Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,8 +23,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef ApplicationCacheStorage_h -#define ApplicationCacheStorage_h +#pragma once #include "SecurityOriginHash.h" #include "SQLiteDatabase.h" @@ -42,10 +41,9 @@ class ApplicationCacheResource; class URL; class SecurityOrigin; class SharedBuffer; -template <class T> class StorageIDJournal; +template<typename> class StorageIDJournal; -class ApplicationCacheStorage { - WTF_MAKE_NONCOPYABLE(ApplicationCacheStorage); WTF_MAKE_FAST_ALLOCATED; +class ApplicationCacheStorage : public RefCounted<ApplicationCacheStorage> { public: enum FailureReason { OriginQuotaReached, @@ -53,20 +51,21 @@ public: DiskOrOperationFailure }; - void setCacheDirectory(const String&); + WEBCORE_EXPORT static Ref<ApplicationCacheStorage> create(const String& cacheDirectory, const String& flatFileSubdirectoryName); + const String& cacheDirectory() const; - void setMaximumSize(int64_t size); - int64_t maximumSize() const; + WEBCORE_EXPORT void setMaximumSize(int64_t size); + WEBCORE_EXPORT int64_t maximumSize() const; bool isMaximumSizeReached() const; int64_t spaceNeeded(int64_t cacheToSave); int64_t defaultOriginQuota() const { return m_defaultOriginQuota; } - void setDefaultOriginQuota(int64_t quota); - bool calculateUsageForOrigin(const SecurityOrigin*, int64_t& usage); - bool calculateQuotaForOrigin(const SecurityOrigin*, int64_t& quota); - bool calculateRemainingSizeForOriginExcludingCache(const SecurityOrigin*, ApplicationCache*, int64_t& remainingSize); - bool storeUpdatedQuotaForOrigin(const SecurityOrigin*, int64_t quota); + WEBCORE_EXPORT void setDefaultOriginQuota(int64_t quota); + WEBCORE_EXPORT bool calculateUsageForOrigin(const SecurityOrigin*, int64_t& usage); + WEBCORE_EXPORT bool calculateQuotaForOrigin(const SecurityOrigin&, int64_t& quota); + bool calculateRemainingSizeForOriginExcludingCache(const SecurityOrigin&, ApplicationCache*, int64_t& remainingSize); + WEBCORE_EXPORT bool storeUpdatedQuotaForOrigin(const SecurityOrigin*, int64_t quota); bool checkOriginQuota(ApplicationCacheGroup*, ApplicationCache* oldCache, ApplicationCache* newCache, int64_t& totalSpaceNeeded); ApplicationCacheGroup* cacheGroupForURL(const URL&); // Cache to load a main resource from. @@ -74,38 +73,47 @@ public: ApplicationCacheGroup* findOrCreateCacheGroup(const URL& manifestURL); ApplicationCacheGroup* findInMemoryCacheGroup(const URL& manifestURL) const; - void cacheGroupDestroyed(ApplicationCacheGroup*); - void cacheGroupMadeObsolete(ApplicationCacheGroup*); - - bool storeNewestCache(ApplicationCacheGroup*, ApplicationCache* oldCache, FailureReason& failureReason); - bool storeNewestCache(ApplicationCacheGroup*); // Updates the cache group, but doesn't remove old cache. + void cacheGroupDestroyed(ApplicationCacheGroup&); + void cacheGroupMadeObsolete(ApplicationCacheGroup&); + + bool storeNewestCache(ApplicationCacheGroup&, ApplicationCache* oldCache, FailureReason&); + bool storeNewestCache(ApplicationCacheGroup&); // Updates the cache group, but doesn't remove old cache. bool store(ApplicationCacheResource*, ApplicationCache*); bool storeUpdatedType(ApplicationCacheResource*, ApplicationCache*); // Removes the group if the cache to be removed is the newest one (so, storeNewestCache() needs to be called beforehand when updating). void remove(ApplicationCache*); - - void empty(); - - static bool storeCopyOfCache(const String& cacheDirectory, ApplicationCacheHost*); - bool manifestURLs(Vector<URL>* urls); + WEBCORE_EXPORT void empty(); + + bool getManifestURLs(Vector<URL>* urls); bool cacheGroupSize(const String& manifestURL, int64_t* size); bool deleteCacheGroup(const String& manifestURL); - void vacuumDatabaseFile(); + WEBCORE_EXPORT void vacuumDatabaseFile(); + + WEBCORE_EXPORT void getOriginsWithCache(HashSet<RefPtr<SecurityOrigin>, SecurityOriginHash>&); + WEBCORE_EXPORT void deleteAllEntries(); + + // FIXME: This should be consolidated with deleteAllEntries(). + WEBCORE_EXPORT void deleteAllCaches(); + + // FIXME: This should be consolidated with deleteCacheGroup(). + WEBCORE_EXPORT void deleteCacheForOrigin(const SecurityOrigin&); - void getOriginsWithCache(HashSet<RefPtr<SecurityOrigin>, SecurityOriginHash>&); - void deleteAllEntries(); + // FIXME: This should be consolidated with calculateUsageForOrigin(). + WEBCORE_EXPORT int64_t diskUsageForOrigin(const SecurityOrigin&); static int64_t unknownQuota() { return -1; } static int64_t noQuota() { return std::numeric_limits<int64_t>::max(); } + private: - ApplicationCacheStorage(); - PassRefPtr<ApplicationCache> loadCache(unsigned storageID); + ApplicationCacheStorage(const String& cacheDirectory, const String& flatFileSubdirectoryName); + + RefPtr<ApplicationCache> loadCache(unsigned storageID); ApplicationCacheGroup* loadCacheGroup(const URL& manifestURL); - typedef StorageIDJournal<ApplicationCacheResource> ResourceStorageIDJournal; - typedef StorageIDJournal<ApplicationCacheGroup> GroupStorageIDJournal; + using ResourceStorageIDJournal = StorageIDJournal<ApplicationCacheResource>; + using GroupStorageIDJournal = StorageIDJournal<ApplicationCacheGroup>; bool store(ApplicationCacheGroup*, GroupStorageIDJournal*); bool store(ApplicationCache*, ResourceStorageIDJournal*); @@ -115,7 +123,7 @@ private: bool ensureOriginRecord(const SecurityOrigin*); bool shouldStoreResourceAsFlatFile(ApplicationCacheResource*); void deleteTables(); - bool writeDataToUniqueFileInDirectory(SharedBuffer*, const String& directory, String& outFilename, const String& fileExtension); + bool writeDataToUniqueFileInDirectory(SharedBuffer&, const String& directory, String& outFilename, const String& fileExtension); void loadManifestHostHashes(); @@ -129,8 +137,9 @@ private: void checkForMaxSizeReached(); void checkForDeletedResources(); long long flatFileAreaSize(); - - String m_cacheDirectory; + + const String m_cacheDirectory; + const String m_flatFileSubdirectoryName; String m_cacheFile; int64_t m_maximumSize; @@ -144,14 +153,9 @@ private: // we keep a hash set of the hosts of the manifest URLs of all non-obsolete cache groups. HashCountedSet<unsigned, AlreadyHashed> m_cacheHostSet; - typedef HashMap<String, ApplicationCacheGroup*> CacheGroupMap; - CacheGroupMap m_cachesInMemory; // Excludes obsolete cache groups. + HashMap<String, ApplicationCacheGroup*> m_cachesInMemory; // Excludes obsolete cache groups. - friend ApplicationCacheStorage& cacheStorage(); + friend class WTF::NeverDestroyed<ApplicationCacheStorage>; }; - -ApplicationCacheStorage& cacheStorage(); - -} // namespace WebCore -#endif // ApplicationCacheStorage_h +} // namespace WebCore |