2004-10-20 05:00:23 +00:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cin: */
|
2012-05-21 11:12:37 +00: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 05:00:23 +00:00
|
|
|
|
2007-05-14 20:09:20 +00:00
|
|
|
#ifndef nsOfflineCacheDevice_h__
|
|
|
|
#define nsOfflineCacheDevice_h__
|
2004-10-20 05:00:23 +00:00
|
|
|
|
|
|
|
#include "nsCacheDevice.h"
|
2008-08-26 23:09:02 +00:00
|
|
|
#include "nsIApplicationCache.h"
|
|
|
|
#include "nsIApplicationCacheService.h"
|
2004-10-20 05:00:23 +00:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "mozIStorageConnection.h"
|
2007-07-26 00:47:33 +00:00
|
|
|
#include "mozIStorageFunction.h"
|
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2004-10-20 05:00:23 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2007-07-26 00:47:33 +00:00
|
|
|
#include "nsCOMArray.h"
|
2008-08-26 23:09:02 +00:00
|
|
|
#include "nsInterfaceHashtable.h"
|
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsWeakReference.h"
|
2012-06-06 03:18:25 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2004-10-20 05:00:23 +00:00
|
|
|
|
2008-09-30 18:34:23 +00:00
|
|
|
class nsIURI;
|
2007-07-26 00:47:33 +00:00
|
|
|
class nsOfflineCacheDevice;
|
|
|
|
|
2012-06-06 03:18:25 +00:00
|
|
|
class nsApplicationCacheNamespace MOZ_FINAL : public nsIApplicationCacheNamespace
|
2008-09-30 18:34:23 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIAPPLICATIONCACHENAMESPACE
|
|
|
|
|
|
|
|
nsApplicationCacheNamespace() : mItemType(0) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
PRUint32 mItemType;
|
|
|
|
nsCString mNamespaceSpec;
|
|
|
|
nsCString mData;
|
|
|
|
};
|
|
|
|
|
2012-06-06 03:18:25 +00:00
|
|
|
class nsOfflineCacheEvictionFunction MOZ_FINAL : public mozIStorageFunction {
|
2007-07-26 00:47:33 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_MOZISTORAGEFUNCTION
|
|
|
|
|
|
|
|
nsOfflineCacheEvictionFunction(nsOfflineCacheDevice *device)
|
|
|
|
: mDevice(device)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void Reset() { mItems.Clear(); }
|
|
|
|
void Apply();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsOfflineCacheDevice *mDevice;
|
|
|
|
nsCOMArray<nsIFile> mItems;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2007-05-14 20:09:20 +00:00
|
|
|
class nsOfflineCacheDevice : public nsCacheDevice
|
2012-04-30 17:57:09 +00:00
|
|
|
, public nsISupports
|
2004-10-20 05:00:23 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-05-14 20:09:20 +00:00
|
|
|
nsOfflineCacheDevice();
|
2004-10-20 05:00:23 +00:00
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2004-10-20 05:00:23 +00:00
|
|
|
/**
|
|
|
|
* nsCacheDevice methods
|
|
|
|
*/
|
2007-05-14 20:09:20 +00:00
|
|
|
|
2004-10-20 05:00:23 +00:00
|
|
|
virtual nsresult Init();
|
|
|
|
virtual nsresult Shutdown();
|
|
|
|
|
|
|
|
virtual const char * GetDeviceID(void);
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual nsCacheEntry * FindEntry(nsCString * key, bool *collision);
|
2004-10-20 05:00:23 +00:00
|
|
|
virtual nsresult DeactivateEntry(nsCacheEntry * entry);
|
|
|
|
virtual nsresult BindEntry(nsCacheEntry * entry);
|
|
|
|
virtual void DoomEntry( nsCacheEntry * entry );
|
|
|
|
|
|
|
|
virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
|
|
|
|
nsCacheAccessMode mode,
|
|
|
|
PRUint32 offset,
|
|
|
|
nsIInputStream ** result);
|
|
|
|
|
|
|
|
virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
|
|
|
|
nsCacheAccessMode mode,
|
|
|
|
PRUint32 offset,
|
|
|
|
nsIOutputStream ** result);
|
|
|
|
|
|
|
|
virtual nsresult GetFileForEntry(nsCacheEntry * entry,
|
|
|
|
nsIFile ** result);
|
|
|
|
|
|
|
|
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
|
|
|
|
|
|
|
virtual nsresult Visit(nsICacheVisitor * visitor);
|
|
|
|
|
|
|
|
virtual nsresult EvictEntries(const char * clientID);
|
|
|
|
|
2007-05-14 20:09:20 +00:00
|
|
|
/* Entry ownership */
|
2007-07-25 05:35:39 +00:00
|
|
|
nsresult GetOwnerDomains(const char * clientID,
|
|
|
|
PRUint32 * count,
|
|
|
|
char *** domains);
|
|
|
|
nsresult GetOwnerURIs(const char * clientID,
|
|
|
|
const nsACString & ownerDomain,
|
|
|
|
PRUint32 * count,
|
|
|
|
char *** uris);
|
2007-05-14 20:09:20 +00:00
|
|
|
nsresult SetOwnedKeys(const char * clientID,
|
|
|
|
const nsACString & ownerDomain,
|
|
|
|
const nsACString & ownerUrl,
|
|
|
|
PRUint32 count,
|
|
|
|
const char ** keys);
|
|
|
|
nsresult GetOwnedKeys(const char * clientID,
|
|
|
|
const nsACString & ownerDomain,
|
|
|
|
const nsACString & ownerUrl,
|
|
|
|
PRUint32 * 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,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool * isOwned);
|
2007-05-14 20:09:20 +00:00
|
|
|
|
|
|
|
nsresult ClearKeysOwnedByDomain(const char *clientID,
|
|
|
|
const nsACString &ownerDomain);
|
|
|
|
nsresult EvictUnownedEntries(const char *clientID);
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
nsresult ActivateCache(const nsCSubstring &group,
|
|
|
|
const nsCSubstring &clientID);
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsActiveCache(const nsCSubstring &group,
|
2008-08-26 23:09:02 +00:00
|
|
|
const nsCSubstring &clientID);
|
|
|
|
nsresult GetGroupForCache(const nsCSubstring &clientID,
|
|
|
|
nsCString &out);
|
2007-05-14 20:09:20 +00:00
|
|
|
|
2012-04-30 17:57:09 +00:00
|
|
|
nsresult CreateApplicationCache(const nsACString &group,
|
|
|
|
nsIApplicationCache **out);
|
|
|
|
|
|
|
|
nsresult GetApplicationCache(const nsACString &clientID,
|
|
|
|
nsIApplicationCache **out);
|
|
|
|
|
|
|
|
nsresult GetActiveCache(const nsACString &group,
|
|
|
|
nsIApplicationCache **out);
|
|
|
|
|
|
|
|
nsresult DeactivateGroup(const nsACString &group);
|
|
|
|
|
|
|
|
nsresult ChooseApplicationCache(const nsACString &key,
|
|
|
|
nsIApplicationCache **out);
|
|
|
|
|
|
|
|
nsresult CacheOpportunistically(nsIApplicationCache* cache,
|
|
|
|
const nsACString &key);
|
|
|
|
|
|
|
|
nsresult GetGroups(PRUint32 *count,char ***keys);
|
|
|
|
|
|
|
|
nsresult GetGroupsTimeOrdered(PRUint32 *count,
|
|
|
|
char ***keys);
|
|
|
|
|
2012-06-28 22:27:03 +00:00
|
|
|
bool IsLocked(const nsACString &key);
|
|
|
|
void Lock(const nsACString &key);
|
|
|
|
void Unlock(const nsACString &key);
|
|
|
|
|
2004-10-20 05:00:23 +00:00
|
|
|
/**
|
|
|
|
* Preference accessors
|
|
|
|
*/
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
void SetCacheParentDirectory(nsIFile * parentDir);
|
2004-10-20 05:00:23 +00:00
|
|
|
void SetCapacity(PRUint32 capacity);
|
2012-07-11 18:20:17 +00:00
|
|
|
void SetAutoShutdown() { mAutoShutdown = true; }
|
|
|
|
bool AutoShutdown(nsIApplicationCache * aAppCache);
|
2004-10-20 05:00:23 +00:00
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsIFile * BaseDirectory() { return mBaseDirectory; }
|
|
|
|
nsIFile * CacheDirectory() { return mCacheDirectory; }
|
2004-10-20 05:00:23 +00:00
|
|
|
PRUint32 CacheCapacity() { return mCacheCapacity; }
|
|
|
|
PRUint32 CacheSize();
|
|
|
|
PRUint32 EntryCount();
|
|
|
|
|
2007-05-14 20:09:20 +00:00
|
|
|
private:
|
2008-08-26 23:09:02 +00:00
|
|
|
friend class nsApplicationCache;
|
|
|
|
|
|
|
|
static PLDHashOperator ShutdownApplicationCache(const nsACString &key,
|
|
|
|
nsIWeakReference *weakRef,
|
|
|
|
void *ctx);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool GetStrictFileOriginPolicy();
|
2008-08-28 01:15:32 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Initialized() { return mDB != nsnull; }
|
2008-08-26 23:09:02 +00:00
|
|
|
|
|
|
|
nsresult InitActiveCaches();
|
2004-10-20 05:00:23 +00:00
|
|
|
nsresult UpdateEntry(nsCacheEntry *entry);
|
|
|
|
nsresult UpdateEntrySize(nsCacheEntry *entry, PRUint32 newSize);
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult DeleteEntry(nsCacheEntry *entry, bool deleteData);
|
2004-10-20 05:00:23 +00:00
|
|
|
nsresult DeleteData(nsCacheEntry *entry);
|
|
|
|
nsresult EnableEvictionObserver();
|
|
|
|
nsresult DisableEvictionObserver();
|
2008-08-26 23:09:02 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool CanUseCache(nsIURI *keyURI, const nsCString &clientID);
|
2008-09-30 18:34:23 +00:00
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
nsresult MarkEntry(const nsCString &clientID,
|
|
|
|
const nsACString &key,
|
|
|
|
PRUint32 typeBits);
|
|
|
|
nsresult UnmarkEntry(const nsCString &clientID,
|
|
|
|
const nsACString &key,
|
|
|
|
PRUint32 typeBits);
|
2008-09-30 18:34:23 +00:00
|
|
|
|
|
|
|
nsresult CacheOpportunistically(const nsCString &clientID,
|
|
|
|
const nsACString &key);
|
2008-08-26 23:09:02 +00:00
|
|
|
nsresult GetTypes(const nsCString &clientID,
|
|
|
|
const nsACString &key,
|
|
|
|
PRUint32 *typeBits);
|
2008-09-30 18:34:23 +00:00
|
|
|
|
|
|
|
nsresult GetMatchingNamespace(const nsCString &clientID,
|
|
|
|
const nsACString &key,
|
|
|
|
nsIApplicationCacheNamespace **out);
|
2008-08-26 23:09:02 +00:00
|
|
|
nsresult GatherEntries(const nsCString &clientID,
|
|
|
|
PRUint32 typeBits,
|
|
|
|
PRUint32 *count,
|
|
|
|
char *** values);
|
2008-09-30 18:34:23 +00:00
|
|
|
nsresult AddNamespace(const nsCString &clientID,
|
|
|
|
nsIApplicationCacheNamespace *ns);
|
2008-08-26 23:09:02 +00:00
|
|
|
|
2009-02-22 19:09:10 +00:00
|
|
|
nsresult GetUsage(const nsACString &clientID,
|
|
|
|
PRUint32 *usage);
|
|
|
|
|
2007-07-25 05:35:39 +00:00
|
|
|
nsresult RunSimpleQuery(mozIStorageStatement *statment,
|
|
|
|
PRUint32 resultIndex,
|
|
|
|
PRUint32 * count,
|
|
|
|
char *** values);
|
2004-10-20 05:00:23 +00:00
|
|
|
|
2007-07-26 00:47:33 +00:00
|
|
|
nsCOMPtr<mozIStorageConnection> mDB;
|
|
|
|
nsRefPtr<nsOfflineCacheEvictionFunction> mEvictionFunction;
|
|
|
|
|
2004-10-27 22:19:32 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_CacheSize;
|
2009-02-22 19:09:10 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_ApplicationCacheSize;
|
2004-10-27 22:19:32 +00: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-14 20:09:20 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_ClearDomain;
|
2008-08-26 23:09:02 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_MarkEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_UnmarkEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_GetTypes;
|
2008-09-30 18:34:23 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_FindNamespaceEntry;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_InsertNamespaceEntry;
|
2008-08-26 23:09:02 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_CleanupUnmarked;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_GatherEntries;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_ActivateClient;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_DeactivateGroup;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_FindClient;
|
2008-09-30 18:34:23 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_FindClientByNamespace;
|
2009-02-22 19:09:10 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_EnumerateGroups;
|
2012-03-31 00:52:06 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> mStatement_EnumerateGroupsTimeOrder;
|
2004-10-27 22:19:32 +00:00
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> mBaseDirectory;
|
|
|
|
nsCOMPtr<nsIFile> mCacheDirectory;
|
2008-12-15 05:57:24 +00:00
|
|
|
PRUint32 mCacheCapacity; // in bytes
|
2004-10-20 05:00:23 +00:00
|
|
|
PRInt32 mDeltaCounter;
|
2012-07-11 18:20:17 +00:00
|
|
|
bool mAutoShutdown;
|
2008-08-26 23:09:02 +00:00
|
|
|
|
|
|
|
nsInterfaceHashtable<nsCStringHashKey, nsIWeakReference> mCaches;
|
|
|
|
nsClassHashtable<nsCStringHashKey, nsCString> mActiveCachesByGroup;
|
2011-11-08 20:22:15 +00:00
|
|
|
nsTHashtable<nsCStringHashKey> mActiveCaches;
|
2012-06-28 22:27:03 +00:00
|
|
|
nsTHashtable<nsCStringHashKey> mLockedEntries;
|
2010-08-24 01:06:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIThread> mInitThread;
|
2004-10-20 05:00:23 +00:00
|
|
|
};
|
|
|
|
|
2007-05-14 20:09:20 +00:00
|
|
|
#endif // nsOfflineCacheDevice_h__
|