netwerk/cache2/AppCacheStorage.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/cache2/AppCacheStorage.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,160 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "CacheLog.h"
     1.9 +#include "AppCacheStorage.h"
    1.10 +#include "CacheStorageService.h"
    1.11 +
    1.12 +#include "OldWrappers.h"
    1.13 +
    1.14 +#include "nsICacheEntryDoomCallback.h"
    1.15 +
    1.16 +#include "nsICacheService.h"
    1.17 +#include "nsIApplicationCache.h"
    1.18 +#include "nsIApplicationCacheService.h"
    1.19 +#include "nsIURI.h"
    1.20 +#include "nsNetCID.h"
    1.21 +#include "nsServiceManagerUtils.h"
    1.22 +#include "nsThreadUtils.h"
    1.23 +
    1.24 +namespace mozilla {
    1.25 +namespace net {
    1.26 +
    1.27 +NS_IMPL_ISUPPORTS_INHERITED0(AppCacheStorage, CacheStorage)
    1.28 +
    1.29 +AppCacheStorage::AppCacheStorage(nsILoadContextInfo* aInfo,
    1.30 +                                 nsIApplicationCache* aAppCache)
    1.31 +: CacheStorage(aInfo, true /* disk */, false /* lookup app cache */)
    1.32 +, mAppCache(aAppCache)
    1.33 +{
    1.34 +  MOZ_COUNT_CTOR(AppCacheStorage);
    1.35 +}
    1.36 +
    1.37 +AppCacheStorage::~AppCacheStorage()
    1.38 +{
    1.39 +  ProxyReleaseMainThread(mAppCache);
    1.40 +  MOZ_COUNT_DTOR(AppCacheStorage);
    1.41 +}
    1.42 +
    1.43 +NS_IMETHODIMP AppCacheStorage::AsyncOpenURI(nsIURI *aURI,
    1.44 +                                            const nsACString & aIdExtension,
    1.45 +                                            uint32_t aFlags,
    1.46 +                                            nsICacheEntryOpenCallback *aCallback)
    1.47 +{
    1.48 +  if (!CacheStorageService::Self())
    1.49 +    return NS_ERROR_NOT_INITIALIZED;
    1.50 +
    1.51 +  NS_ENSURE_ARG(aURI);
    1.52 +  NS_ENSURE_ARG(aCallback);
    1.53 +
    1.54 +  nsresult rv;
    1.55 +
    1.56 +  nsCOMPtr<nsIApplicationCache> appCache = mAppCache;
    1.57 +
    1.58 +  if (!appCache) {
    1.59 +    rv = ChooseApplicationCache(aURI, getter_AddRefs(appCache));
    1.60 +    NS_ENSURE_SUCCESS(rv, rv);
    1.61 +  }
    1.62 +
    1.63 +  if (!appCache) {
    1.64 +    LOG(("AppCacheStorage::AsyncOpenURI entry not found in any appcache, giving up"));
    1.65 +    aCallback->OnCacheEntryAvailable(nullptr, false, nullptr, NS_ERROR_CACHE_KEY_NOT_FOUND);
    1.66 +    return NS_OK;
    1.67 +  }
    1.68 +
    1.69 +  nsCOMPtr<nsIURI> noRefURI;
    1.70 +  rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
    1.71 +  NS_ENSURE_SUCCESS(rv, rv);
    1.72 +
    1.73 +  nsAutoCString cacheKey;
    1.74 +  rv = noRefURI->GetAsciiSpec(cacheKey);
    1.75 +  NS_ENSURE_SUCCESS(rv, rv);
    1.76 +
    1.77 +  nsAutoCString scheme;
    1.78 +  rv = noRefURI->GetScheme(scheme);
    1.79 +  NS_ENSURE_SUCCESS(rv, rv);
    1.80 +
    1.81 +  nsRefPtr<_OldCacheLoad> appCacheLoad =
    1.82 +    new _OldCacheLoad(scheme, cacheKey, aCallback, appCache,
    1.83 +                      LoadInfo(), WriteToDisk(), aFlags);
    1.84 +  rv = appCacheLoad->Start();
    1.85 +  NS_ENSURE_SUCCESS(rv, rv);
    1.86 +
    1.87 +  return NS_OK;
    1.88 +}
    1.89 +
    1.90 +NS_IMETHODIMP AppCacheStorage::AsyncDoomURI(nsIURI *aURI, const nsACString & aIdExtension,
    1.91 +                                            nsICacheEntryDoomCallback* aCallback)
    1.92 +{
    1.93 +  if (!CacheStorageService::Self())
    1.94 +    return NS_ERROR_NOT_INITIALIZED;
    1.95 +
    1.96 +  if (!mAppCache) {
    1.97 +    return NS_ERROR_NOT_AVAILABLE;
    1.98 +  }
    1.99 +
   1.100 +  // TODO - remove entry from app cache
   1.101 +  // I think no one is using this...
   1.102 +  return NS_ERROR_NOT_IMPLEMENTED;
   1.103 +}
   1.104 +
   1.105 +NS_IMETHODIMP AppCacheStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallback)
   1.106 +{
   1.107 +  if (!CacheStorageService::Self())
   1.108 +    return NS_ERROR_NOT_INITIALIZED;
   1.109 +
   1.110 +  nsresult rv;
   1.111 +
   1.112 +  nsCOMPtr<nsIApplicationCacheService> appCacheService =
   1.113 +    do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
   1.114 +  NS_ENSURE_SUCCESS(rv, rv);
   1.115 +
   1.116 +  if (!mAppCache) {
   1.117 +    if (LoadInfo()->AppId() == nsILoadContextInfo::NO_APP_ID &&
   1.118 +        !LoadInfo()->IsInBrowserElement()) {
   1.119 +
   1.120 +      // Clear everything.
   1.121 +      nsCOMPtr<nsICacheService> serv =
   1.122 +          do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
   1.123 +      NS_ENSURE_SUCCESS(rv, rv);
   1.124 +
   1.125 +      rv = serv->EvictEntries(nsICache::STORE_OFFLINE);
   1.126 +      NS_ENSURE_SUCCESS(rv, rv);
   1.127 +    }
   1.128 +    else {
   1.129 +      // Clear app or inbrowser staff.
   1.130 +      rv = appCacheService->DiscardByAppId(LoadInfo()->AppId(),
   1.131 +                                           LoadInfo()->IsInBrowserElement());
   1.132 +      NS_ENSURE_SUCCESS(rv, rv);
   1.133 +    }
   1.134 +  }
   1.135 +  else {
   1.136 +    // Discard the group
   1.137 +    nsAutoCString groupID;
   1.138 +    rv = mAppCache->GetGroupID(groupID);
   1.139 +    NS_ENSURE_SUCCESS(rv, rv);
   1.140 +
   1.141 +    rv = appCacheService->DeactivateGroup(groupID);
   1.142 +    NS_ENSURE_SUCCESS(rv, rv);
   1.143 +  }
   1.144 +
   1.145 +  if (aCallback)
   1.146 +    aCallback->OnCacheEntryDoomed(NS_OK);
   1.147 +
   1.148 +  return NS_OK;
   1.149 +}
   1.150 +
   1.151 +NS_IMETHODIMP AppCacheStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisitor,
   1.152 +                                                 bool aVisitEntries)
   1.153 +{
   1.154 +  if (!CacheStorageService::Self())
   1.155 +    return NS_ERROR_NOT_INITIALIZED;
   1.156 +
   1.157 +  LOG(("AppCacheStorage::AsyncVisitStorage [this=%p, cb=%p]", this, aVisitor));
   1.158 +
   1.159 +  return NS_ERROR_NOT_IMPLEMENTED;
   1.160 +}
   1.161 +
   1.162 +} // net
   1.163 +} // mozilla

mercurial