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