2004-10-20 09:00:23 +04:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cin: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2007-05-15 00:09:20 +04:00
|
|
|
#ifndef nsOfflineCacheDevice_h__
|
|
|
|
#define nsOfflineCacheDevice_h__
|
2004-10-20 09:00:23 +04:00
|
|
|
|
|
|
|
#include "nsCacheDevice.h"
|
2008-08-27 03:09:02 +04:00
|
|
|
#include "nsIApplicationCache.h"
|
|
|
|
#include "nsIApplicationCacheService.h"
|
2004-10-20 09:00:23 +04:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "mozIStorageConnection.h"
|
2007-07-26 04:47:33 +04:00
|
|
|
#include "mozIStorageFunction.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2004-10-20 09:00:23 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2007-07-26 04:47:33 +04:00
|
|
|
#include "nsCOMArray.h"
|
2008-08-27 03:09:02 +04:00
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsClassHashtable.h"
|
2018-10-31 23:39:03 +03:00
|
|
|
#include "nsIWeakReference.h"
|
2012-06-06 07:18:25 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-08-15 14:42:02 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2008-09-30 22:34:23 +04:00
|
|
|
class nsIURI;
|
2007-07-26 04:47:33 +04:00
|
|
|
class nsOfflineCacheDevice;
|
2013-04-10 04:21:07 +04:00
|
|
|
class mozIStorageService;
|
2016-01-18 22:20:08 +03:00
|
|
|
class nsILoadContextInfo;
|
|
|
|
namespace mozilla {
|
|
|
|
class OriginAttributesPattern;
|
|
|
|
}
|
2007-07-26 04:47:33 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsApplicationCacheNamespace final : public nsIApplicationCacheNamespace {
|
2008-09-30 22:34:23 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIAPPLICATIONCACHENAMESPACE
|
|
|
|
|
|
|
|
nsApplicationCacheNamespace() : mItemType(0) {}
|
|
|
|
|
|
|
|
private:
|
2018-04-30 19:46:04 +03:00
|
|
|
~nsApplicationCacheNamespace() = default;
|
2014-06-24 20:36:44 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mItemType;
|
2008-09-30 22:34:23 +04:00
|
|
|
nsCString mNamespaceSpec;
|
|
|
|
nsCString mData;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsOfflineCacheEvictionFunction final : public mozIStorageFunction {
|
2007-07-26 04:47:33 +04:00
|
|
|
public:
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-07-26 04:47:33 +04:00
|
|
|
NS_DECL_MOZISTORAGEFUNCTION
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
explicit nsOfflineCacheEvictionFunction(nsOfflineCacheDevice* device);
|
2007-07-26 04:47:33 +04:00
|
|
|
|
2017-02-18 19:35:50 +03:00
|
|
|
void Init();
|
|
|
|
void Reset();
|
2007-07-26 04:47:33 +04:00
|
|
|
void Apply();
|
|
|
|
|
|
|
|
private:
|
2018-04-30 19:46:04 +03:00
|
|
|
~nsOfflineCacheEvictionFunction() = default;
|
2014-06-24 20:36:44 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsOfflineCacheDevice* mDevice;
|
2017-02-18 19:35:50 +03:00
|
|
|
bool mTLSInited;
|
2007-07-26 04:47:33 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsOfflineCacheDevice final : public nsCacheDevice, public nsISupports {
|
2004-10-20 09:00:23 +04:00
|
|
|
public:
|
2007-05-15 00:09:20 +04:00
|
|
|
nsOfflineCacheDevice();
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2013-07-19 06:24:13 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2008-08-27 03:09:02 +04:00
|
|
|
|
2004-10-20 09:00:23 +04:00
|
|
|
/**
|
|
|
|
* nsCacheDevice methods
|
|
|
|
*/
|
2007-05-15 00:09:20 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult Init() override;
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult InitWithSqlite(mozIStorageService* ss);
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult Shutdown() override;
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual const char* GetDeviceID(void) override;
|
|
|
|
virtual nsCacheEntry* FindEntry(nsCString* key, bool* collision) override;
|
|
|
|
virtual nsresult DeactivateEntry(nsCacheEntry* entry) override;
|
|
|
|
virtual nsresult BindEntry(nsCacheEntry* entry) override;
|
|
|
|
virtual void DoomEntry(nsCacheEntry* entry) override;
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult OpenInputStreamForEntry(nsCacheEntry* entry,
|
2004-10-20 09:00:23 +04:00
|
|
|
nsCacheAccessMode mode,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t offset,
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIInputStream** result) override;
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult OpenOutputStreamForEntry(nsCacheEntry* entry,
|
2004-10-20 09:00:23 +04:00
|
|
|
nsCacheAccessMode mode,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t offset,
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIOutputStream** result) override;
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult GetFileForEntry(nsCacheEntry* entry,
|
|
|
|
nsIFile** result) override;
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult OnDataSizeChange(nsCacheEntry* entry,
|
2015-03-21 19:28:04 +03:00
|
|
|
int32_t deltaSize) override;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult Visit(nsICacheVisitor* visitor) override;
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
virtual nsresult EvictEntries(const char* clientID) override;
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2007-05-15 00:09:20 +04:00
|
|
|
/* Entry ownership */
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult GetOwnerDomains(const char* clientID, uint32_t* count,
|
|
|
|
char*** domains);
|
|
|
|
nsresult GetOwnerURIs(const char* clientID, const nsACString& ownerDomain,
|
|
|
|
uint32_t* count, char*** uris);
|
|
|
|
nsresult SetOwnedKeys(const char* clientID, const nsACString& ownerDomain,
|
|
|
|
const nsACString& ownerUrl, uint32_t count,
|
|
|
|
const char** keys);
|
|
|
|
nsresult GetOwnedKeys(const char* clientID, const nsACString& ownerDomain,
|
|
|
|
const nsACString& ownerUrl, uint32_t* count,
|
|
|
|
char*** keys);
|
|
|
|
nsresult AddOwnedKey(const char* clientID, const nsACString& ownerDomain,
|
|
|
|
const nsACString& ownerURI, const nsACString& key);
|
|
|
|
nsresult RemoveOwnedKey(const char* clientID, const nsACString& ownerDomain,
|
|
|
|
const nsACString& ownerURI, const nsACString& key);
|
|
|
|
nsresult KeyIsOwned(const char* clientID, const nsACString& ownerDomain,
|
|
|
|
const nsACString& ownerURI, const nsACString& key,
|
|
|
|
bool* isOwned);
|
|
|
|
|
|
|
|
nsresult ClearKeysOwnedByDomain(const char* clientID,
|
|
|
|
const nsACString& ownerDomain);
|
|
|
|
nsresult EvictUnownedEntries(const char* clientID);
|
|
|
|
|
|
|
|
static nsresult BuildApplicationCacheGroupID(nsIURI* aManifestURL,
|
|
|
|
nsACString const& aOriginSuffix,
|
|
|
|
nsACString& _result);
|
|
|
|
|
|
|
|
nsresult ActivateCache(const nsACString& group, const nsACString& clientID);
|
|
|
|
bool IsActiveCache(const nsACString& group, const nsACString& clientID);
|
|
|
|
nsresult CreateApplicationCache(const nsACString& group,
|
|
|
|
nsIApplicationCache** out);
|
|
|
|
|
|
|
|
nsresult GetApplicationCache(const nsACString& clientID,
|
|
|
|
nsIApplicationCache** out);
|
|
|
|
nsresult GetApplicationCache_Unlocked(const nsACString& clientID,
|
|
|
|
nsIApplicationCache** out);
|
|
|
|
|
|
|
|
nsresult GetActiveCache(const nsACString& group, nsIApplicationCache** out);
|
|
|
|
|
|
|
|
nsresult DeactivateGroup(const nsACString& group);
|
|
|
|
|
|
|
|
nsresult ChooseApplicationCache(const nsACString& key,
|
|
|
|
nsILoadContextInfo* loadContext,
|
|
|
|
nsIApplicationCache** out);
|
|
|
|
|
|
|
|
nsresult CacheOpportunistically(nsIApplicationCache* cache,
|
|
|
|
const nsACString& key);
|
|
|
|
|
|
|
|
nsresult Evict(nsILoadContextInfo* aInfo);
|
|
|
|
nsresult Evict(mozilla::OriginAttributesPattern const& aPattern);
|
|
|
|
|
2019-06-12 15:02:37 +03:00
|
|
|
nsresult GetGroups(nsTArray<nsCString>& keys);
|
2019-05-01 11:47:10 +03:00
|
|
|
|
2019-06-12 15:02:37 +03:00
|
|
|
nsresult GetGroupsTimeOrdered(nsTArray<nsCString>& keys);
|
2019-05-01 11:47:10 +03:00
|
|
|
|
|
|
|
bool IsLocked(const nsACString& key);
|
|
|
|
void Lock(const nsACString& key);
|
|
|
|
void Unlock(const nsACString& key);
|
2012-06-29 02:27:03 +04:00
|
|
|
|
2004-10-20 09:00:23 +04:00
|
|
|
/**
|
|
|
|
* Preference accessors
|
|
|
|
*/
|
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
void SetCacheParentDirectory(nsIFile* parentDir);
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetCapacity(uint32_t capacity);
|
2012-07-11 22:20:17 +04:00
|
|
|
void SetAutoShutdown() { mAutoShutdown = true; }
|
2019-05-01 11:47:10 +03:00
|
|
|
bool AutoShutdown(nsIApplicationCache* aAppCache);
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsIFile* BaseDirectory() { return mBaseDirectory; }
|
|
|
|
nsIFile* CacheDirectory() { return mCacheDirectory; }
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t CacheCapacity() { return mCacheCapacity; }
|
|
|
|
uint32_t CacheSize();
|
|
|
|
uint32_t EntryCount();
|
2014-06-24 20:36:44 +04:00
|
|
|
|
2007-05-15 00:09:20 +04:00
|
|
|
private:
|
2018-04-30 19:46:04 +03:00
|
|
|
~nsOfflineCacheDevice() = default;
|
2014-06-24 20:36:44 +04:00
|
|
|
|
2008-08-27 03:09:02 +04:00
|
|
|
friend class nsApplicationCache;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool GetStrictFileOriginPolicy();
|
2008-08-28 05:15:32 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
bool Initialized() { return mDB != nullptr; }
|
2008-08-27 03:09:02 +04:00
|
|
|
|
|
|
|
nsresult InitActiveCaches();
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult UpdateEntry(nsCacheEntry* entry);
|
|
|
|
nsresult UpdateEntrySize(nsCacheEntry* entry, uint32_t newSize);
|
|
|
|
nsresult DeleteEntry(nsCacheEntry* entry, bool deleteData);
|
|
|
|
nsresult DeleteData(nsCacheEntry* entry);
|
2004-10-20 09:00:23 +04:00
|
|
|
nsresult EnableEvictionObserver();
|
|
|
|
nsresult DisableEvictionObserver();
|
2008-08-27 03:09:02 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
bool CanUseCache(nsIURI* keyURI, const nsACString& clientID,
|
|
|
|
nsILoadContextInfo* loadContext);
|
2008-09-30 22:34:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult MarkEntry(const nsCString& clientID, const nsACString& key,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t typeBits);
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult UnmarkEntry(const nsCString& clientID, const nsACString& key,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t typeBits);
|
2008-09-30 22:34:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult CacheOpportunistically(const nsCString& clientID,
|
|
|
|
const nsACString& key);
|
|
|
|
nsresult GetTypes(const nsCString& clientID, const nsACString& key,
|
|
|
|
uint32_t* typeBits);
|
2008-09-30 22:34:23 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult GetMatchingNamespace(const nsCString& clientID,
|
|
|
|
const nsACString& key,
|
|
|
|
nsIApplicationCacheNamespace** out);
|
|
|
|
nsresult GatherEntries(const nsCString& clientID, uint32_t typeBits,
|
2019-06-12 15:02:37 +03:00
|
|
|
nsTArray<nsCString>& keys);
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult AddNamespace(const nsCString& clientID,
|
|
|
|
nsIApplicationCacheNamespace* ns);
|
2008-08-27 03:09:02 +04:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult GetUsage(const nsACString& clientID, uint32_t* usage);
|
2009-02-22 22:09:10 +03:00
|
|
|
|
2019-05-01 11:47:10 +03:00
|
|
|
nsresult RunSimpleQuery(mozIStorageStatement* statment, uint32_t resultIndex,
|
2019-06-12 15:02:37 +03:00
|
|
|
nsTArray<nsCString>& values);
|
2004-10-20 09:00:23 +04:00
|
|
|
|
2007-07-26 04:47:33 +04:00
|
|
|
nsCOMPtr<mozIStorageConnection> mDB;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsOfflineCacheEvictionFunction> mEvictionFunction;
|
2007-07-26 04:47:33 +04:00
|
|
|
|
2004-10-28 02:19:32 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_CacheSize;
|
2009-02-22 22:09:10 +03:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_ApplicationCacheSize;
|
2004-10-28 02:19:32 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_EntryCount;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_UpdateEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_UpdateEntrySize;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_DeleteEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_FindEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_BindEntry;
|
2007-05-15 00:09:20 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_ClearDomain;
|
2008-08-27 03:09:02 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_MarkEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_UnmarkEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_GetTypes;
|
2008-09-30 22:34:23 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_FindNamespaceEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_InsertNamespaceEntry;
|
2008-08-27 03:09:02 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_CleanupUnmarked;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_GatherEntries;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_ActivateClient;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_DeactivateGroup;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_FindClient;
|
2008-09-30 22:34:23 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_FindClientByNamespace;
|
2012-10-03 04:39:09 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_EnumerateApps;
|
2009-02-22 22:09:10 +03:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_EnumerateGroups;
|
2012-03-31 04:52:06 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_EnumerateGroupsTimeOrder;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-06-06 06:08:30 +04:00
|
|
|
nsCOMPtr<nsIFile> mBaseDirectory;
|
|
|
|
nsCOMPtr<nsIFile> mCacheDirectory;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mCacheCapacity; // in bytes
|
|
|
|
int32_t mDeltaCounter;
|
2012-07-11 22:20:17 +04:00
|
|
|
bool mAutoShutdown;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-08-15 14:42:02 +04:00
|
|
|
mozilla::Mutex mLock;
|
|
|
|
|
2008-08-27 03:09:02 +04:00
|
|
|
nsInterfaceHashtable<nsCStringHashKey, nsIWeakReference> mCaches;
|
|
|
|
nsClassHashtable<nsCStringHashKey, nsCString> mActiveCachesByGroup;
|
2011-11-09 00:22:15 +04:00
|
|
|
nsTHashtable<nsCStringHashKey> mActiveCaches;
|
2012-06-29 02:27:03 +04:00
|
|
|
nsTHashtable<nsCStringHashKey> mLockedEntries;
|
2010-08-24 05:06:23 +04:00
|
|
|
|
2017-06-01 23:43:44 +03:00
|
|
|
nsCOMPtr<nsIEventTarget> mInitEventTarget;
|
2004-10-20 09:00:23 +04:00
|
|
|
};
|
|
|
|
|
2007-05-15 00:09:20 +04:00
|
|
|
#endif // nsOfflineCacheDevice_h__
|