DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (5350524bb654)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
// Stuff to link the old imp to the new api - will go away!

#ifndef OLDWRAPPERS__H__
#define OLDWRAPPERS__H__

#include "nsICacheEntry.h"
#include "nsICacheListener.h"
#include "nsICacheStorage.h"

#include "nsCOMPtr.h"
#include "nsICacheEntryOpenCallback.h"
#include "nsICacheEntryDescriptor.h"
#include "nsICacheStorageVisitor.h"
#include "nsThreadUtils.h"
#include "mozilla/TimeStamp.h"

class nsIURI;
class nsICacheEntryOpenCallback;
class nsICacheStorageConsumptionObserver;
class nsIApplicationCache;
class nsILoadContextInfo;

namespace mozilla { namespace net {

class CacheStorage;

class _OldCacheEntryWrapper : public nsICacheEntry
{
public:
  NS_DECL_THREADSAFE_ISUPPORTS

  // nsICacheEntryDescriptor
  NS_IMETHOD SetExpirationTime(uint32_t expirationTime) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->SetExpirationTime(expirationTime);
  }
  nsresult OpenInputStream(uint32_t offset, nsIInputStream * *_retval)
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->OpenInputStream(offset, _retval);
  }
  nsresult OpenOutputStream(uint32_t offset, nsIOutputStream * *_retval)
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->OpenOutputStream(offset, _retval);
  }
  NS_IMETHOD OpenAlternativeOutputStream(const nsACString & type, nsIOutputStream * *_retval) override
  {
    return NS_ERROR_NOT_IMPLEMENTED;
  }
  NS_IMETHOD OpenAlternativeInputStream(const nsACString & type, nsIInputStream * *_retval) override
  {
    return NS_ERROR_NOT_IMPLEMENTED;
  }

  NS_IMETHOD GetPredictedDataSize(int64_t *aPredictedDataSize) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->GetPredictedDataSize(aPredictedDataSize);
  }
  NS_IMETHOD SetPredictedDataSize(int64_t aPredictedDataSize) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->SetPredictedDataSize(aPredictedDataSize);
  }
  NS_IMETHOD GetSecurityInfo(nsISupports * *aSecurityInfo) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->GetSecurityInfo(aSecurityInfo);
  }
  NS_IMETHOD SetSecurityInfo(nsISupports *aSecurityInfo) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->SetSecurityInfo(aSecurityInfo);
  }
  NS_IMETHOD GetStorageDataSize(uint32_t *aStorageDataSize) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->GetStorageDataSize(aStorageDataSize);
  }
  nsresult AsyncDoom(nsICacheListener *listener)
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->AsyncDoom(listener);
  }
  NS_IMETHOD MarkValid(void) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->MarkValid();
  }
  NS_IMETHOD Close(void) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->Close();
  }
  NS_IMETHOD GetMetaDataElement(const char * key, char * *_retval) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->GetMetaDataElement(key, _retval);
  }
  NS_IMETHOD SetMetaDataElement(const char * key, const char * value) override
  {
    return !mOldDesc ? NS_ERROR_NULL_POINTER :
                       mOldDesc->SetMetaDataElement(key, value);
  }

  NS_IMETHOD GetDiskStorageSizeInKB(uint32_t *aDiskStorageSize) override
  {
    return NS_ERROR_NOT_IMPLEMENTED;
  }

  // nsICacheEntryInfo
  NS_IMETHOD GetKey(nsACString & aKey) override
  {
    return mOldInfo->GetKey(aKey);
  }
  NS_IMETHOD GetFetchCount(int32_t *aFetchCount) override
  {
    return mOldInfo->GetFetchCount(aFetchCount);
  }
  NS_IMETHOD GetLastFetched(uint32_t *aLastFetched) override
  {
    return mOldInfo->GetLastFetched(aLastFetched);
  }
  NS_IMETHOD GetLastModified(uint32_t *aLastModified) override
  {
    return mOldInfo->GetLastModified(aLastModified);
  }
  NS_IMETHOD GetExpirationTime(uint32_t *aExpirationTime) override
  {
    return mOldInfo->GetExpirationTime(aExpirationTime);
  }
  nsresult GetDataSize(uint32_t *aDataSize)
  {
    return mOldInfo->GetDataSize(aDataSize);
  }

  NS_IMETHOD AsyncDoom(nsICacheEntryDoomCallback* listener) override;
  NS_IMETHOD GetPersistent(bool *aPersistToDisk) override;
  NS_IMETHOD GetIsForcedValid(bool *aIsForcedValid) override;
  NS_IMETHOD ForceValidFor(uint32_t aSecondsToTheFuture) override;
  NS_IMETHOD SetValid() override { return NS_OK; }
  NS_IMETHOD MetaDataReady() override { return NS_OK; }
  NS_IMETHOD Recreate(bool, nsICacheEntry**) override;
  NS_IMETHOD GetDataSize(int64_t *size) override;
  NS_IMETHOD GetAltDataSize(int64_t *size) override;
  NS_IMETHOD OpenInputStream(int64_t offset, nsIInputStream * *_retval) override;
  NS_IMETHOD OpenOutputStream(int64_t offset, nsIOutputStream * *_retval) override;
  NS_IMETHOD MaybeMarkValid() override;
  NS_IMETHOD HasWriteAccess(bool aWriteOnly, bool *aWriteAccess) override;
  NS_IMETHOD VisitMetaData(nsICacheEntryMetaDataVisitor*) override;

  explicit _OldCacheEntryWrapper(nsICacheEntryDescriptor* desc);
  explicit _OldCacheEntryWrapper(nsICacheEntryInfo* info);

private:
  virtual ~_OldCacheEntryWrapper();

  _OldCacheEntryWrapper() = delete;
  nsICacheEntryDescriptor* mOldDesc; // ref holded in mOldInfo
  nsCOMPtr<nsICacheEntryInfo> mOldInfo;
};


class _OldCacheLoad : public Runnable
                    , public nsICacheListener
{
public:
  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_NSIRUNNABLE
  NS_DECL_NSICACHELISTENER

  _OldCacheLoad(nsCSubstring const& aScheme,
                nsCSubstring const& aCacheKey,
                nsICacheEntryOpenCallback* aCallback,
                nsIApplicationCache* aAppCache,
                nsILoadContextInfo* aLoadInfo,
                bool aWriteToDisk,
                uint32_t aFlags);

  nsresult Start();

protected:
  virtual ~_OldCacheLoad();

private:
  void Check();

  nsCOMPtr<nsIEventTarget> mCacheThread;

  nsCString const mScheme;
  nsCString const mCacheKey;
  nsCOMPtr<nsICacheEntryOpenCallback> mCallback;
  nsCOMPtr<nsILoadContextInfo> mLoadInfo;
  uint32_t const mFlags;

  bool const mWriteToDisk : 1;
  bool mNew : 1;
  bool mOpening : 1;
  bool mSync : 1;

  nsCOMPtr<nsICacheEntry> mCacheEntry;
  nsresult mStatus;
  uint32_t mRunCount;
  nsCOMPtr<nsIApplicationCache> mAppCache;

  mozilla::TimeStamp mLoadStart;
};


class _OldStorage : public nsICacheStorage
{
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSICACHESTORAGE

public:
  _OldStorage(nsILoadContextInfo* aInfo,
              bool aAllowDisk,
              bool aLookupAppCache,
              bool aOfflineStorage,
              nsIApplicationCache* aAppCache);

private:
  virtual ~_OldStorage();
  nsresult AssembleCacheKey(nsIURI *aURI, nsACString const & aIdExtension,
                            nsACString & aCacheKey, nsACString & aScheme);
  nsresult ChooseApplicationCache(nsCSubstring const &cacheKey, nsIApplicationCache** aCache);

  nsCOMPtr<nsILoadContextInfo> mLoadInfo;
  nsCOMPtr<nsIApplicationCache> mAppCache;
  bool const mWriteToDisk : 1;
  bool const mLookupAppCache : 1;
  bool const mOfflineStorage : 1;
};

class _OldVisitCallbackWrapper : public nsICacheVisitor
{
  NS_DECL_THREADSAFE_ISUPPORTS
  NS_DECL_NSICACHEVISITOR

  _OldVisitCallbackWrapper(char const * deviceID,
                           nsICacheStorageVisitor * cb,
                           bool visitEntries,
                           nsILoadContextInfo * aInfo)
  : mCB(cb)
  , mVisitEntries(visitEntries)
  , mDeviceID(deviceID)
  , mLoadInfo(aInfo)
  , mHit(false)
  {
    MOZ_COUNT_CTOR(_OldVisitCallbackWrapper);
  }

private:
  virtual ~_OldVisitCallbackWrapper();
  nsCOMPtr<nsICacheStorageVisitor> mCB;
  bool mVisitEntries;
  char const * mDeviceID;
  nsCOMPtr<nsILoadContextInfo> mLoadInfo;
  bool mHit; // set to true when the device was found
};

class _OldGetDiskConsumption : public Runnable,
                               public nsICacheVisitor
{
public:
  static nsresult Get(nsICacheStorageConsumptionObserver* aCallback);

private:
  explicit _OldGetDiskConsumption(nsICacheStorageConsumptionObserver* aCallback);
  virtual ~_OldGetDiskConsumption() {}
  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_NSICACHEVISITOR
  NS_DECL_NSIRUNNABLE

  nsCOMPtr<nsICacheStorageConsumptionObserver> mCallback;
  int64_t mSize;
};

} // namespace net
} // namespace mozilla

#endif