Line data Source code
1 : // Stuff to link the old imp to the new api - will go away!
2 :
3 : #ifndef OLDWRAPPERS__H__
4 : #define OLDWRAPPERS__H__
5 :
6 : #include "nsICacheEntry.h"
7 : #include "nsICacheListener.h"
8 : #include "nsICacheStorage.h"
9 :
10 : #include "nsCOMPtr.h"
11 : #include "nsICacheEntryOpenCallback.h"
12 : #include "nsICacheEntryDescriptor.h"
13 : #include "nsICacheStorageVisitor.h"
14 : #include "nsThreadUtils.h"
15 : #include "mozilla/TimeStamp.h"
16 :
17 : class nsIURI;
18 : class nsICacheEntryOpenCallback;
19 : class nsICacheStorageConsumptionObserver;
20 : class nsIApplicationCache;
21 : class nsILoadContextInfo;
22 :
23 : namespace mozilla { namespace net {
24 :
25 : class CacheStorage;
26 :
27 : class _OldCacheEntryWrapper : public nsICacheEntry
28 : {
29 : public:
30 : NS_DECL_THREADSAFE_ISUPPORTS
31 :
32 : // nsICacheEntryDescriptor
33 0 : NS_IMETHOD SetExpirationTime(uint32_t expirationTime) override
34 : {
35 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
36 0 : mOldDesc->SetExpirationTime(expirationTime);
37 : }
38 0 : nsresult OpenInputStream(uint32_t offset, nsIInputStream * *_retval)
39 : {
40 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
41 0 : mOldDesc->OpenInputStream(offset, _retval);
42 : }
43 0 : nsresult OpenOutputStream(uint32_t offset, nsIOutputStream * *_retval)
44 : {
45 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
46 0 : mOldDesc->OpenOutputStream(offset, _retval);
47 : }
48 0 : NS_IMETHOD OpenAlternativeOutputStream(const nsACString & type, nsIOutputStream * *_retval) override
49 : {
50 0 : return NS_ERROR_NOT_IMPLEMENTED;
51 : }
52 0 : NS_IMETHOD OpenAlternativeInputStream(const nsACString & type, nsIInputStream * *_retval) override
53 : {
54 0 : return NS_ERROR_NOT_IMPLEMENTED;
55 : }
56 :
57 0 : NS_IMETHOD GetPredictedDataSize(int64_t *aPredictedDataSize) override
58 : {
59 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
60 0 : mOldDesc->GetPredictedDataSize(aPredictedDataSize);
61 : }
62 0 : NS_IMETHOD SetPredictedDataSize(int64_t aPredictedDataSize) override
63 : {
64 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
65 0 : mOldDesc->SetPredictedDataSize(aPredictedDataSize);
66 : }
67 0 : NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) override
68 : {
69 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
70 0 : mOldDesc->GetSecurityInfo(aSecurityInfo);
71 : }
72 0 : NS_IMETHOD SetSecurityInfo(nsISupports *aSecurityInfo) override
73 : {
74 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
75 0 : mOldDesc->SetSecurityInfo(aSecurityInfo);
76 : }
77 0 : NS_IMETHOD GetStorageDataSize(uint32_t *aStorageDataSize) override
78 : {
79 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
80 0 : mOldDesc->GetStorageDataSize(aStorageDataSize);
81 : }
82 0 : nsresult AsyncDoom(nsICacheListener *listener)
83 : {
84 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
85 0 : mOldDesc->AsyncDoom(listener);
86 : }
87 0 : NS_IMETHOD MarkValid(void) override
88 : {
89 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
90 0 : mOldDesc->MarkValid();
91 : }
92 0 : NS_IMETHOD Close(void) override
93 : {
94 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
95 0 : mOldDesc->Close();
96 : }
97 0 : NS_IMETHOD GetMetaDataElement(const char * key, char * *_retval) override
98 : {
99 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
100 0 : mOldDesc->GetMetaDataElement(key, _retval);
101 : }
102 0 : NS_IMETHOD SetMetaDataElement(const char * key, const char * value) override
103 : {
104 0 : return !mOldDesc ? NS_ERROR_NULL_POINTER :
105 0 : mOldDesc->SetMetaDataElement(key, value);
106 : }
107 :
108 0 : NS_IMETHOD GetDiskStorageSizeInKB(uint32_t *aDiskStorageSize) override
109 : {
110 0 : return NS_ERROR_NOT_IMPLEMENTED;
111 : }
112 :
113 : // nsICacheEntryInfo
114 0 : NS_IMETHOD GetKey(nsACString & aKey) override
115 : {
116 0 : return mOldInfo->GetKey(aKey);
117 : }
118 0 : NS_IMETHOD GetFetchCount(int32_t *aFetchCount) override
119 : {
120 0 : return mOldInfo->GetFetchCount(aFetchCount);
121 : }
122 0 : NS_IMETHOD GetLastFetched(uint32_t *aLastFetched) override
123 : {
124 0 : return mOldInfo->GetLastFetched(aLastFetched);
125 : }
126 0 : NS_IMETHOD GetLastModified(uint32_t *aLastModified) override
127 : {
128 0 : return mOldInfo->GetLastModified(aLastModified);
129 : }
130 0 : NS_IMETHOD GetExpirationTime(uint32_t *aExpirationTime) override
131 : {
132 0 : return mOldInfo->GetExpirationTime(aExpirationTime);
133 : }
134 0 : nsresult GetDataSize(uint32_t *aDataSize)
135 : {
136 0 : return mOldInfo->GetDataSize(aDataSize);
137 : }
138 0 : NS_IMETHOD GetOnStartTime(uint64_t *aTime) override
139 : {
140 0 : return NS_ERROR_NOT_IMPLEMENTED;
141 : }
142 0 : NS_IMETHOD GetOnStopTime(uint64_t *aTime) override
143 : {
144 0 : return NS_ERROR_NOT_IMPLEMENTED;
145 : }
146 0 : NS_IMETHOD SetNetworkTimes(uint64_t aOnStartTime, uint64_t aOnStopTime) override
147 : {
148 0 : return NS_ERROR_NOT_IMPLEMENTED;
149 : }
150 0 : NS_IMETHOD GetLoadContextInfo(nsILoadContextInfo** aInfo) override
151 : {
152 0 : return NS_ERROR_NOT_IMPLEMENTED;
153 : }
154 :
155 : NS_IMETHOD AsyncDoom(nsICacheEntryDoomCallback* listener) override;
156 : NS_IMETHOD GetPersistent(bool *aPersistToDisk) override;
157 : NS_IMETHOD GetIsForcedValid(bool *aIsForcedValid) override;
158 : NS_IMETHOD ForceValidFor(uint32_t aSecondsToTheFuture) override;
159 0 : NS_IMETHOD SetValid() override { return NS_OK; }
160 0 : NS_IMETHOD MetaDataReady() override { return NS_OK; }
161 : NS_IMETHOD Recreate(bool, nsICacheEntry**) override;
162 : NS_IMETHOD GetDataSize(int64_t *size) override;
163 : NS_IMETHOD GetAltDataSize(int64_t *size) override;
164 : NS_IMETHOD OpenInputStream(int64_t offset, nsIInputStream * *_retval) override;
165 : NS_IMETHOD OpenOutputStream(int64_t offset, nsIOutputStream * *_retval) override;
166 : NS_IMETHOD MaybeMarkValid() override;
167 : NS_IMETHOD HasWriteAccess(bool aWriteOnly, bool *aWriteAccess) override;
168 : NS_IMETHOD VisitMetaData(nsICacheEntryMetaDataVisitor*) override;
169 :
170 : explicit _OldCacheEntryWrapper(nsICacheEntryDescriptor* desc);
171 : explicit _OldCacheEntryWrapper(nsICacheEntryInfo* info);
172 :
173 : private:
174 : virtual ~_OldCacheEntryWrapper();
175 :
176 : _OldCacheEntryWrapper() = delete;
177 : nsICacheEntryDescriptor* mOldDesc; // ref holded in mOldInfo
178 : nsCOMPtr<nsICacheEntryInfo> mOldInfo;
179 : };
180 :
181 :
182 : class _OldCacheLoad : public Runnable
183 : , public nsICacheListener
184 : {
185 : public:
186 : NS_DECL_ISUPPORTS_INHERITED
187 : NS_DECL_NSIRUNNABLE
188 : NS_DECL_NSICACHELISTENER
189 :
190 : _OldCacheLoad(const nsACString& aScheme,
191 : const nsACString& aCacheKey,
192 : nsICacheEntryOpenCallback* aCallback,
193 : nsIApplicationCache* aAppCache,
194 : nsILoadContextInfo* aLoadInfo,
195 : bool aWriteToDisk,
196 : uint32_t aFlags);
197 :
198 : nsresult Start();
199 :
200 : protected:
201 : virtual ~_OldCacheLoad();
202 :
203 : private:
204 : void Check();
205 :
206 : nsCOMPtr<nsIEventTarget> mCacheThread;
207 :
208 : nsCString const mScheme;
209 : nsCString const mCacheKey;
210 : nsCOMPtr<nsICacheEntryOpenCallback> mCallback;
211 : nsCOMPtr<nsILoadContextInfo> mLoadInfo;
212 : uint32_t const mFlags;
213 :
214 : bool const mWriteToDisk : 1;
215 : bool mNew : 1;
216 : bool mOpening : 1;
217 : bool mSync : 1;
218 :
219 : nsCOMPtr<nsICacheEntry> mCacheEntry;
220 : nsresult mStatus;
221 : uint32_t mRunCount;
222 : nsCOMPtr<nsIApplicationCache> mAppCache;
223 :
224 : mozilla::TimeStamp mLoadStart;
225 : };
226 :
227 :
228 : class _OldStorage : public nsICacheStorage
229 : {
230 : NS_DECL_THREADSAFE_ISUPPORTS
231 : NS_DECL_NSICACHESTORAGE
232 :
233 : public:
234 : _OldStorage(nsILoadContextInfo* aInfo,
235 : bool aAllowDisk,
236 : bool aLookupAppCache,
237 : bool aOfflineStorage,
238 : nsIApplicationCache* aAppCache);
239 :
240 : private:
241 : virtual ~_OldStorage();
242 : nsresult AssembleCacheKey(nsIURI *aURI, nsACString const & aIdExtension,
243 : nsACString & aCacheKey, nsACString & aScheme);
244 : nsresult ChooseApplicationCache(const nsACString& cacheKey, nsIApplicationCache** aCache);
245 :
246 : nsCOMPtr<nsILoadContextInfo> mLoadInfo;
247 : nsCOMPtr<nsIApplicationCache> mAppCache;
248 : bool const mWriteToDisk : 1;
249 : bool const mLookupAppCache : 1;
250 : bool const mOfflineStorage : 1;
251 : };
252 :
253 : class _OldVisitCallbackWrapper : public nsICacheVisitor
254 : {
255 : NS_DECL_THREADSAFE_ISUPPORTS
256 : NS_DECL_NSICACHEVISITOR
257 :
258 0 : _OldVisitCallbackWrapper(char const * deviceID,
259 : nsICacheStorageVisitor * cb,
260 : bool visitEntries,
261 : nsILoadContextInfo * aInfo)
262 0 : : mCB(cb)
263 : , mVisitEntries(visitEntries)
264 : , mDeviceID(deviceID)
265 : , mLoadInfo(aInfo)
266 0 : , mHit(false)
267 : {
268 0 : }
269 :
270 : private:
271 : virtual ~_OldVisitCallbackWrapper();
272 : nsCOMPtr<nsICacheStorageVisitor> mCB;
273 : bool mVisitEntries;
274 : char const * mDeviceID;
275 : nsCOMPtr<nsILoadContextInfo> mLoadInfo;
276 : bool mHit; // set to true when the device was found
277 : };
278 :
279 : class _OldGetDiskConsumption : public Runnable,
280 : public nsICacheVisitor
281 : {
282 : public:
283 : static nsresult Get(nsICacheStorageConsumptionObserver* aCallback);
284 :
285 : private:
286 : explicit _OldGetDiskConsumption(nsICacheStorageConsumptionObserver* aCallback);
287 0 : virtual ~_OldGetDiskConsumption() {}
288 : NS_DECL_ISUPPORTS_INHERITED
289 : NS_DECL_NSICACHEVISITOR
290 : NS_DECL_NSIRUNNABLE
291 :
292 : nsCOMPtr<nsICacheStorageConsumptionObserver> mCallback;
293 : int64_t mSize;
294 : };
295 :
296 : } // namespace net
297 : } // namespace mozilla
298 :
299 : #endif
|