1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is nsCacheService.h, released February 10, 2001.
15
* The Initial Developer of the Original Code is Netscape Communications
16
* Corporation. Portions created by Netscape are
17
* Copyright (C) 2001 Netscape Communications Corporation. All
21
* Gordon Sheridan <gordon@netscape.com>
22
* Patrick C. Beard <beard@netscape.com>
23
* Darin Fisher <darin@netscape.com>
27
#ifndef _nsCacheService_h_
28
#define _nsCacheService_h_
30
#include "nsICacheService.h"
31
#include "nsCacheSession.h"
32
#include "nsCacheDevice.h"
33
#include "nsCacheEntry.h"
36
#include "nsIObserver.h"
38
#include "nsIEventQueueService.h"
39
#include "nsProxiedService.h"
42
class nsCacheProfilePrefObserver;
43
class nsDiskCacheDevice;
44
class nsMemoryCacheDevice;
47
/******************************************************************************
49
******************************************************************************/
51
class nsCacheService : public nsICacheService
55
NS_DECL_NSICACHESERVICE
58
virtual ~nsCacheService();
60
// Define a Create method to be used with a factory:
62
Create(nsISupports* outer, const nsIID& iid, void* *result);
66
* Methods called by nsCacheSession
68
static nsresult OpenCacheEntry(nsCacheSession * session,
70
nsCacheAccessMode accessRequested,
72
nsICacheListener * listener,
73
nsICacheEntryDescriptor ** result);
75
static nsresult EvictEntriesForSession(nsCacheSession * session);
77
static nsresult IsStorageEnabledForPolicy(nsCacheStoragePolicy storagePolicy,
81
* Methods called by nsCacheEntryDescriptor
84
static void CloseDescriptor(nsCacheEntryDescriptor * descriptor);
86
static nsresult GetFileForEntry(nsCacheEntry * entry,
89
static nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
90
nsCacheAccessMode mode,
92
nsIInputStream ** result);
94
static nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
95
nsCacheAccessMode mode,
97
nsIOutputStream ** result);
99
static nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
101
static PRLock * ServiceLock();
103
static nsresult SetCacheElement(nsCacheEntry * entry, nsISupports * element);
105
static nsresult ValidateEntry(nsCacheEntry * entry);
109
* Methods called by any cache classes
113
nsCacheService * GlobalInstance() { return gService; }
115
static nsresult DoomEntry(nsCacheEntry * entry);
117
static void ProxyObjectRelease(nsISupports * object, PRThread * thread);
119
static PRBool IsStorageEnabledForPolicy_Locked(nsCacheStoragePolicy policy);
122
* Methods called by nsCacheProfilePrefObserver
124
static void OnProfileShutdown(PRBool cleanse);
125
static void OnProfileChanged();
127
static void SetDiskCacheEnabled(PRBool enabled);
128
static void SetDiskCacheCapacity(PRInt32 capacity);
130
static void SetMemoryCacheEnabled(PRBool enabled);
131
static void SetMemoryCacheCapacity(PRInt32 capacity);
139
nsresult CreateDiskDevice();
140
nsresult CreateMemoryDevice();
142
nsresult CreateRequest(nsCacheSession * session,
143
const char * clientKey,
144
nsCacheAccessMode accessRequested,
146
nsICacheListener * listener,
147
nsCacheRequest ** request);
149
nsresult DoomEntry_Internal(nsCacheEntry * entry);
151
nsresult EvictEntriesForClient(const char * clientID,
152
nsCacheStoragePolicy storagePolicy);
154
nsresult NotifyListener(nsCacheRequest * request,
155
nsICacheEntryDescriptor * descriptor,
156
nsCacheAccessMode accessGranted,
159
nsresult ActivateEntry(nsCacheRequest * request, nsCacheEntry ** entry);
161
nsCacheDevice * EnsureEntryHasDevice(nsCacheEntry * entry);
163
nsCacheEntry * SearchCacheDevices(nsCString * key, nsCacheStoragePolicy policy);
165
void DeactivateEntry(nsCacheEntry * entry);
167
nsresult ProcessRequest(nsCacheRequest * request,
168
PRBool calledFromOpenCacheEntry,
169
nsICacheEntryDescriptor ** result);
171
nsresult ProcessPendingRequests(nsCacheEntry * entry);
173
void ClearPendingRequests(nsCacheEntry * entry);
174
void ClearDoomList(void);
175
void ClearActiveEntries(void);
176
void DoomActiveEntries(void);
178
PRInt32 CacheMemoryAvailable();
181
PLDHashOperator PR_CALLBACK DeactivateAndClearEntry(PLDHashTable * table,
182
PLDHashEntryHdr * hdr,
186
PLDHashOperator PR_CALLBACK RemoveActiveEntry(PLDHashTable * table,
187
PLDHashEntryHdr * hdr,
190
#if defined(PR_LOGGING)
191
void LogCacheStatistics();
198
static nsCacheService * gService; // there can be only one...
199
nsCOMPtr<nsIEventQueueService> mEventQService;
200
nsCOMPtr<nsIProxyObjectManager> mProxyObjectManager;
202
nsCacheProfilePrefObserver * mObserver;
204
PRLock * mCacheServiceLock;
208
PRBool mEnableMemoryDevice;
209
PRBool mEnableDiskDevice;
211
nsMemoryCacheDevice * mMemoryDevice;
212
nsDiskCacheDevice * mDiskDevice;
214
nsCacheEntryHashTable mActiveEntries;
215
PRCList mDoomedEntries;
219
PRUint32 mTotalEntries;
221
PRUint32 mCacheMisses;
222
PRUint32 mMaxKeyLength;
223
PRUint32 mMaxDataSize;
224
PRUint32 mMaxMetaSize;
226
// Unexpected error totals
227
PRUint32 mDeactivateFailures;
228
PRUint32 mDeactivatedUnboundEntries;
232
#endif // _nsCacheService_h_