~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/netwerk/cache/src/nsCacheService.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
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/
 
7
 * 
 
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.
 
12
 * 
 
13
 * The Original Code is nsCacheService.h, released February 10, 2001.
 
14
 * 
 
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
 
18
 * Rights Reserved.
 
19
 * 
 
20
 * Contributor(s): 
 
21
 *    Gordon Sheridan  <gordon@netscape.com>
 
22
 *    Patrick C. Beard <beard@netscape.com>
 
23
 *    Darin Fisher     <darin@netscape.com>
 
24
 */
 
25
 
 
26
 
 
27
#ifndef _nsCacheService_h_
 
28
#define _nsCacheService_h_
 
29
 
 
30
#include "nsICacheService.h"
 
31
#include "nsCacheSession.h"
 
32
#include "nsCacheDevice.h"
 
33
#include "nsCacheEntry.h"
 
34
 
 
35
#include "nspr.h"
 
36
#include "nsIObserver.h"
 
37
#include "nsString.h"
 
38
#include "nsIEventQueueService.h"
 
39
#include "nsProxiedService.h"
 
40
 
 
41
class nsCacheRequest;
 
42
class nsCacheProfilePrefObserver;
 
43
class nsDiskCacheDevice;
 
44
class nsMemoryCacheDevice;
 
45
 
 
46
 
 
47
/******************************************************************************
 
48
 *  nsCacheService
 
49
 ******************************************************************************/
 
50
 
 
51
class nsCacheService : public nsICacheService
 
52
{
 
53
public:
 
54
    NS_DECL_ISUPPORTS
 
55
    NS_DECL_NSICACHESERVICE
 
56
    
 
57
    nsCacheService();
 
58
    virtual ~nsCacheService();
 
59
 
 
60
    // Define a Create method to be used with a factory:
 
61
    static NS_METHOD
 
62
    Create(nsISupports* outer, const nsIID& iid, void* *result);
 
63
 
 
64
 
 
65
    /**
 
66
     * Methods called by nsCacheSession
 
67
     */
 
68
    static nsresult  OpenCacheEntry(nsCacheSession *           session,
 
69
                                    const char *               key,
 
70
                                    nsCacheAccessMode          accessRequested,
 
71
                                    PRBool                     blockingMode,
 
72
                                    nsICacheListener *         listener,
 
73
                                    nsICacheEntryDescriptor ** result);
 
74
 
 
75
    static nsresult  EvictEntriesForSession(nsCacheSession *   session);
 
76
 
 
77
    static nsresult  IsStorageEnabledForPolicy(nsCacheStoragePolicy  storagePolicy,
 
78
                                               PRBool *              result);
 
79
 
 
80
    /**
 
81
     * Methods called by nsCacheEntryDescriptor
 
82
     */
 
83
 
 
84
    static void      CloseDescriptor(nsCacheEntryDescriptor * descriptor);
 
85
 
 
86
    static nsresult  GetFileForEntry(nsCacheEntry *         entry,
 
87
                                     nsIFile **             result);
 
88
 
 
89
    static nsresult  OpenInputStreamForEntry(nsCacheEntry *     entry,
 
90
                                             nsCacheAccessMode  mode,
 
91
                                             PRUint32           offset,
 
92
                                             nsIInputStream **  result);
 
93
 
 
94
    static nsresult  OpenOutputStreamForEntry(nsCacheEntry *     entry,
 
95
                                              nsCacheAccessMode  mode,
 
96
                                              PRUint32           offset,
 
97
                                              nsIOutputStream ** result);
 
98
 
 
99
    static nsresult  OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
 
100
 
 
101
    static PRLock *  ServiceLock();
 
102
    
 
103
    static nsresult  SetCacheElement(nsCacheEntry * entry, nsISupports * element);
 
104
 
 
105
    static nsresult  ValidateEntry(nsCacheEntry * entry);
 
106
 
 
107
 
 
108
    /**
 
109
     * Methods called by any cache classes
 
110
     */
 
111
 
 
112
    static
 
113
    nsCacheService * GlobalInstance()   { return gService; }
 
114
    
 
115
    static nsresult  DoomEntry(nsCacheEntry * entry);
 
116
 
 
117
    static void      ProxyObjectRelease(nsISupports * object, PRThread * thread);
 
118
 
 
119
    static PRBool    IsStorageEnabledForPolicy_Locked(nsCacheStoragePolicy policy);
 
120
 
 
121
    /**
 
122
     * Methods called by nsCacheProfilePrefObserver
 
123
     */
 
124
    static void      OnProfileShutdown(PRBool cleanse);
 
125
    static void      OnProfileChanged();
 
126
 
 
127
    static void      SetDiskCacheEnabled(PRBool  enabled);
 
128
    static void      SetDiskCacheCapacity(PRInt32  capacity);
 
129
 
 
130
    static void      SetMemoryCacheEnabled(PRBool  enabled);
 
131
    static void      SetMemoryCacheCapacity(PRInt32  capacity);
 
132
 
 
133
private:
 
134
 
 
135
    /**
 
136
     * Internal Methods
 
137
     */
 
138
 
 
139
    nsresult         CreateDiskDevice();
 
140
    nsresult         CreateMemoryDevice();
 
141
 
 
142
    nsresult         CreateRequest(nsCacheSession *   session,
 
143
                                   const char *       clientKey,
 
144
                                   nsCacheAccessMode  accessRequested,
 
145
                                   PRBool             blockingMode,
 
146
                                   nsICacheListener * listener,
 
147
                                   nsCacheRequest **  request);
 
148
 
 
149
    nsresult         DoomEntry_Internal(nsCacheEntry * entry);
 
150
 
 
151
    nsresult         EvictEntriesForClient(const char *          clientID,
 
152
                                           nsCacheStoragePolicy  storagePolicy);
 
153
 
 
154
    nsresult         NotifyListener(nsCacheRequest *          request,
 
155
                                    nsICacheEntryDescriptor * descriptor,
 
156
                                    nsCacheAccessMode         accessGranted,
 
157
                                    nsresult                  error);
 
158
 
 
159
    nsresult         ActivateEntry(nsCacheRequest * request, nsCacheEntry ** entry);
 
160
 
 
161
    nsCacheDevice *  EnsureEntryHasDevice(nsCacheEntry * entry);
 
162
 
 
163
    nsCacheEntry *   SearchCacheDevices(nsCString * key, nsCacheStoragePolicy policy);
 
164
 
 
165
    void             DeactivateEntry(nsCacheEntry * entry);
 
166
 
 
167
    nsresult         ProcessRequest(nsCacheRequest *           request,
 
168
                                    PRBool                     calledFromOpenCacheEntry,
 
169
                                    nsICacheEntryDescriptor ** result);
 
170
 
 
171
    nsresult         ProcessPendingRequests(nsCacheEntry * entry);
 
172
 
 
173
    void             ClearPendingRequests(nsCacheEntry * entry);
 
174
    void             ClearDoomList(void);
 
175
    void             ClearActiveEntries(void);
 
176
    void             DoomActiveEntries(void);
 
177
 
 
178
    PRInt32         CacheMemoryAvailable();
 
179
 
 
180
    static
 
181
    PLDHashOperator PR_CALLBACK  DeactivateAndClearEntry(PLDHashTable *    table,
 
182
                                                         PLDHashEntryHdr * hdr,
 
183
                                                         PRUint32          number,
 
184
                                                         void *            arg);
 
185
    static
 
186
    PLDHashOperator PR_CALLBACK  RemoveActiveEntry(PLDHashTable *    table,
 
187
                                                   PLDHashEntryHdr * hdr,
 
188
                                                   PRUint32          number,
 
189
                                                   void *            arg);
 
190
#if defined(PR_LOGGING)
 
191
    void LogCacheStatistics();
 
192
#endif
 
193
 
 
194
    /**
 
195
     *  Data Members
 
196
     */
 
197
 
 
198
    static nsCacheService *         gService;  // there can be only one...
 
199
    nsCOMPtr<nsIEventQueueService>  mEventQService;
 
200
    nsCOMPtr<nsIProxyObjectManager> mProxyObjectManager;
 
201
    
 
202
    nsCacheProfilePrefObserver *    mObserver;
 
203
    
 
204
    PRLock *                        mCacheServiceLock;
 
205
    
 
206
    PRBool                          mInitialized;
 
207
    
 
208
    PRBool                          mEnableMemoryDevice;
 
209
    PRBool                          mEnableDiskDevice;
 
210
 
 
211
    nsMemoryCacheDevice *           mMemoryDevice;
 
212
    nsDiskCacheDevice *             mDiskDevice;
 
213
 
 
214
    nsCacheEntryHashTable           mActiveEntries;
 
215
    PRCList                         mDoomedEntries;
 
216
 
 
217
    // stats
 
218
    
 
219
    PRUint32                        mTotalEntries;
 
220
    PRUint32                        mCacheHits;
 
221
    PRUint32                        mCacheMisses;
 
222
    PRUint32                        mMaxKeyLength;
 
223
    PRUint32                        mMaxDataSize;
 
224
    PRUint32                        mMaxMetaSize;
 
225
 
 
226
    // Unexpected error totals
 
227
    PRUint32                        mDeactivateFailures;
 
228
    PRUint32                        mDeactivatedUnboundEntries;
 
229
};
 
230
 
 
231
 
 
232
#endif // _nsCacheService_h_