LCOV - code coverage report
Current view: top level - netwerk/cache2 - AppCacheStorage.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 75 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* This Source Code Form is subject to the terms of the Mozilla Public
       2             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       3             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       4             : 
       5             : #include "CacheLog.h"
       6             : #include "AppCacheStorage.h"
       7             : #include "CacheStorageService.h"
       8             : 
       9             : #include "OldWrappers.h"
      10             : 
      11             : #include "nsICacheEntryDoomCallback.h"
      12             : 
      13             : #include "nsCacheService.h"
      14             : #include "nsIApplicationCache.h"
      15             : #include "nsIApplicationCacheService.h"
      16             : #include "nsIURI.h"
      17             : #include "nsNetCID.h"
      18             : #include "nsServiceManagerUtils.h"
      19             : #include "nsThreadUtils.h"
      20             : 
      21             : namespace mozilla {
      22             : namespace net {
      23             : 
      24           0 : NS_IMPL_ISUPPORTS_INHERITED0(AppCacheStorage, CacheStorage)
      25             : 
      26           0 : AppCacheStorage::AppCacheStorage(nsILoadContextInfo* aInfo,
      27           0 :                                  nsIApplicationCache* aAppCache)
      28             : : CacheStorage(aInfo, true /* disk */, false /* lookup app cache */, false /* skip size check */, false /* pin */)
      29           0 : , mAppCache(aAppCache)
      30             : {
      31           0 : }
      32             : 
      33           0 : AppCacheStorage::~AppCacheStorage()
      34             : {
      35           0 :   ProxyReleaseMainThread("AppCacheStorage::mAppCache", mAppCache);
      36           0 : }
      37             : 
      38           0 : NS_IMETHODIMP AppCacheStorage::AsyncOpenURI(nsIURI *aURI,
      39             :                                             const nsACString & aIdExtension,
      40             :                                             uint32_t aFlags,
      41             :                                             nsICacheEntryOpenCallback *aCallback)
      42             : {
      43           0 :   if (!CacheStorageService::Self())
      44           0 :     return NS_ERROR_NOT_INITIALIZED;
      45             : 
      46           0 :   NS_ENSURE_ARG(aURI);
      47           0 :   NS_ENSURE_ARG(aCallback);
      48             : 
      49             :   nsresult rv;
      50             : 
      51           0 :   nsCOMPtr<nsIApplicationCache> appCache = mAppCache;
      52             : 
      53           0 :   if (!appCache) {
      54           0 :     rv = ChooseApplicationCache(aURI, getter_AddRefs(appCache));
      55           0 :     NS_ENSURE_SUCCESS(rv, rv);
      56             :   }
      57             : 
      58           0 :   if (!appCache) {
      59           0 :     LOG(("AppCacheStorage::AsyncOpenURI entry not found in any appcache, giving up"));
      60           0 :     aCallback->OnCacheEntryAvailable(nullptr, false, nullptr, NS_ERROR_CACHE_KEY_NOT_FOUND);
      61           0 :     return NS_OK;
      62             :   }
      63             : 
      64           0 :   nsCOMPtr<nsIURI> noRefURI;
      65           0 :   rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI));
      66           0 :   NS_ENSURE_SUCCESS(rv, rv);
      67             : 
      68           0 :   nsAutoCString cacheKey;
      69           0 :   rv = noRefURI->GetAsciiSpec(cacheKey);
      70           0 :   NS_ENSURE_SUCCESS(rv, rv);
      71             : 
      72             :   // This is the only way how to recognize appcache data by the anonymous
      73             :   // flag.  There is no way to switch to e.g. a different session, because
      74             :   // there is just a single session for an appcache version (identified
      75             :   // by the client id).
      76           0 :   if (LoadInfo()->IsAnonymous()) {
      77           0 :     cacheKey = NS_LITERAL_CSTRING("anon&") + cacheKey;
      78             :   }
      79             : 
      80           0 :   nsAutoCString scheme;
      81           0 :   rv = noRefURI->GetScheme(scheme);
      82           0 :   NS_ENSURE_SUCCESS(rv, rv);
      83             : 
      84             :   RefPtr<_OldCacheLoad> appCacheLoad =
      85             :     new _OldCacheLoad(scheme, cacheKey, aCallback, appCache,
      86           0 :                       LoadInfo(), WriteToDisk(), aFlags);
      87           0 :   rv = appCacheLoad->Start();
      88           0 :   NS_ENSURE_SUCCESS(rv, rv);
      89             : 
      90           0 :   return NS_OK;
      91             : }
      92             : 
      93           0 : NS_IMETHODIMP AppCacheStorage::OpenTruncate(nsIURI *aURI, const nsACString & aIdExtension,
      94             :                                             nsICacheEntry **aCacheEntry)
      95             : {
      96           0 :   return NS_ERROR_NOT_IMPLEMENTED;
      97             : }
      98             : 
      99           0 : NS_IMETHODIMP AppCacheStorage::Exists(nsIURI *aURI, const nsACString & aIdExtension,
     100             :                                       bool *aResult)
     101             : {
     102           0 :   *aResult = false;
     103           0 :   return NS_ERROR_NOT_AVAILABLE;
     104             : }
     105             : 
     106           0 : NS_IMETHODIMP AppCacheStorage::AsyncDoomURI(nsIURI *aURI, const nsACString & aIdExtension,
     107             :                                             nsICacheEntryDoomCallback* aCallback)
     108             : {
     109           0 :   if (!CacheStorageService::Self())
     110           0 :     return NS_ERROR_NOT_INITIALIZED;
     111             : 
     112           0 :   if (!mAppCache) {
     113           0 :     return NS_ERROR_NOT_AVAILABLE;
     114             :   }
     115             : 
     116             :   RefPtr<_OldStorage> old = new _OldStorage(
     117           0 :     LoadInfo(), WriteToDisk(), LookupAppCache(), true, mAppCache);
     118           0 :   return old->AsyncDoomURI(aURI, aIdExtension, aCallback);
     119             : }
     120             : 
     121           0 : NS_IMETHODIMP AppCacheStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallback)
     122             : {
     123           0 :   if (!CacheStorageService::Self())
     124           0 :     return NS_ERROR_NOT_INITIALIZED;
     125             : 
     126             :   nsresult rv;
     127             : 
     128           0 :   if (!mAppCache) {
     129             :     // Discard everything under this storage context
     130             :     nsCOMPtr<nsIApplicationCacheService> appCacheService =
     131           0 :       do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
     132           0 :     NS_ENSURE_SUCCESS(rv, rv);
     133             : 
     134           0 :     rv = appCacheService->Evict(LoadInfo());
     135           0 :     NS_ENSURE_SUCCESS(rv, rv);
     136             :   } else {
     137             :     // Discard the group
     138             :     RefPtr<_OldStorage> old = new _OldStorage(
     139           0 :       LoadInfo(), WriteToDisk(), LookupAppCache(), true, mAppCache);
     140           0 :     rv = old->AsyncEvictStorage(aCallback);
     141           0 :     NS_ENSURE_SUCCESS(rv, rv);
     142             : 
     143           0 :     return NS_OK;
     144             :   }
     145             : 
     146           0 :   if (aCallback)
     147           0 :     aCallback->OnCacheEntryDoomed(NS_OK);
     148             : 
     149           0 :   return NS_OK;
     150             : }
     151             : 
     152           0 : NS_IMETHODIMP AppCacheStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisitor,
     153             :                                                  bool aVisitEntries)
     154             : {
     155           0 :   if (!CacheStorageService::Self())
     156           0 :     return NS_ERROR_NOT_INITIALIZED;
     157             : 
     158           0 :   LOG(("AppCacheStorage::AsyncVisitStorage [this=%p, cb=%p]", this, aVisitor));
     159             : 
     160             :   nsresult rv;
     161             : 
     162             :   nsCOMPtr<nsICacheService> serv =
     163           0 :     do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
     164           0 :   NS_ENSURE_SUCCESS(rv, rv);
     165             : 
     166             :   RefPtr<_OldVisitCallbackWrapper> cb = new _OldVisitCallbackWrapper(
     167           0 :     "offline", aVisitor, aVisitEntries, LoadInfo());
     168           0 :   rv = nsCacheService::GlobalInstance()->VisitEntriesInternal(cb);
     169           0 :   NS_ENSURE_SUCCESS(rv, rv);
     170             : 
     171           0 :   return NS_OK;
     172             : }
     173             : 
     174           0 : NS_IMETHODIMP AppCacheStorage::GetCacheIndexEntryAttrs(nsIURI *aURI,
     175             :                                                        const nsACString &aIdExtension,
     176             :                                                        bool *aHasAltData,
     177             :                                                        uint32_t *aSizeInKB)
     178             : {
     179           0 :   return NS_ERROR_NOT_IMPLEMENTED;
     180             : }
     181             : 
     182             : } // namespace net
     183             : } // namespace mozilla

Generated by: LCOV version 1.13