OldWrappers.h 8.2 KB

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