Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "CacheLog.h" |
michael@0 | 6 | #include "AppCacheStorage.h" |
michael@0 | 7 | #include "CacheStorageService.h" |
michael@0 | 8 | |
michael@0 | 9 | #include "OldWrappers.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "nsICacheEntryDoomCallback.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsICacheService.h" |
michael@0 | 14 | #include "nsIApplicationCache.h" |
michael@0 | 15 | #include "nsIApplicationCacheService.h" |
michael@0 | 16 | #include "nsIURI.h" |
michael@0 | 17 | #include "nsNetCID.h" |
michael@0 | 18 | #include "nsServiceManagerUtils.h" |
michael@0 | 19 | #include "nsThreadUtils.h" |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { |
michael@0 | 22 | namespace net { |
michael@0 | 23 | |
michael@0 | 24 | NS_IMPL_ISUPPORTS_INHERITED0(AppCacheStorage, CacheStorage) |
michael@0 | 25 | |
michael@0 | 26 | AppCacheStorage::AppCacheStorage(nsILoadContextInfo* aInfo, |
michael@0 | 27 | nsIApplicationCache* aAppCache) |
michael@0 | 28 | : CacheStorage(aInfo, true /* disk */, false /* lookup app cache */) |
michael@0 | 29 | , mAppCache(aAppCache) |
michael@0 | 30 | { |
michael@0 | 31 | MOZ_COUNT_CTOR(AppCacheStorage); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | AppCacheStorage::~AppCacheStorage() |
michael@0 | 35 | { |
michael@0 | 36 | ProxyReleaseMainThread(mAppCache); |
michael@0 | 37 | MOZ_COUNT_DTOR(AppCacheStorage); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | NS_IMETHODIMP AppCacheStorage::AsyncOpenURI(nsIURI *aURI, |
michael@0 | 41 | const nsACString & aIdExtension, |
michael@0 | 42 | uint32_t aFlags, |
michael@0 | 43 | nsICacheEntryOpenCallback *aCallback) |
michael@0 | 44 | { |
michael@0 | 45 | if (!CacheStorageService::Self()) |
michael@0 | 46 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 47 | |
michael@0 | 48 | NS_ENSURE_ARG(aURI); |
michael@0 | 49 | NS_ENSURE_ARG(aCallback); |
michael@0 | 50 | |
michael@0 | 51 | nsresult rv; |
michael@0 | 52 | |
michael@0 | 53 | nsCOMPtr<nsIApplicationCache> appCache = mAppCache; |
michael@0 | 54 | |
michael@0 | 55 | if (!appCache) { |
michael@0 | 56 | rv = ChooseApplicationCache(aURI, getter_AddRefs(appCache)); |
michael@0 | 57 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | if (!appCache) { |
michael@0 | 61 | LOG(("AppCacheStorage::AsyncOpenURI entry not found in any appcache, giving up")); |
michael@0 | 62 | aCallback->OnCacheEntryAvailable(nullptr, false, nullptr, NS_ERROR_CACHE_KEY_NOT_FOUND); |
michael@0 | 63 | return NS_OK; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | nsCOMPtr<nsIURI> noRefURI; |
michael@0 | 67 | rv = aURI->CloneIgnoringRef(getter_AddRefs(noRefURI)); |
michael@0 | 68 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 69 | |
michael@0 | 70 | nsAutoCString cacheKey; |
michael@0 | 71 | rv = noRefURI->GetAsciiSpec(cacheKey); |
michael@0 | 72 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 73 | |
michael@0 | 74 | nsAutoCString scheme; |
michael@0 | 75 | rv = noRefURI->GetScheme(scheme); |
michael@0 | 76 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 77 | |
michael@0 | 78 | nsRefPtr<_OldCacheLoad> appCacheLoad = |
michael@0 | 79 | new _OldCacheLoad(scheme, cacheKey, aCallback, appCache, |
michael@0 | 80 | LoadInfo(), WriteToDisk(), aFlags); |
michael@0 | 81 | rv = appCacheLoad->Start(); |
michael@0 | 82 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 83 | |
michael@0 | 84 | return NS_OK; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | NS_IMETHODIMP AppCacheStorage::AsyncDoomURI(nsIURI *aURI, const nsACString & aIdExtension, |
michael@0 | 88 | nsICacheEntryDoomCallback* aCallback) |
michael@0 | 89 | { |
michael@0 | 90 | if (!CacheStorageService::Self()) |
michael@0 | 91 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 92 | |
michael@0 | 93 | if (!mAppCache) { |
michael@0 | 94 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | // TODO - remove entry from app cache |
michael@0 | 98 | // I think no one is using this... |
michael@0 | 99 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | NS_IMETHODIMP AppCacheStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallback) |
michael@0 | 103 | { |
michael@0 | 104 | if (!CacheStorageService::Self()) |
michael@0 | 105 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 106 | |
michael@0 | 107 | nsresult rv; |
michael@0 | 108 | |
michael@0 | 109 | nsCOMPtr<nsIApplicationCacheService> appCacheService = |
michael@0 | 110 | do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv); |
michael@0 | 111 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 112 | |
michael@0 | 113 | if (!mAppCache) { |
michael@0 | 114 | if (LoadInfo()->AppId() == nsILoadContextInfo::NO_APP_ID && |
michael@0 | 115 | !LoadInfo()->IsInBrowserElement()) { |
michael@0 | 116 | |
michael@0 | 117 | // Clear everything. |
michael@0 | 118 | nsCOMPtr<nsICacheService> serv = |
michael@0 | 119 | do_GetService(NS_CACHESERVICE_CONTRACTID, &rv); |
michael@0 | 120 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 121 | |
michael@0 | 122 | rv = serv->EvictEntries(nsICache::STORE_OFFLINE); |
michael@0 | 123 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 124 | } |
michael@0 | 125 | else { |
michael@0 | 126 | // Clear app or inbrowser staff. |
michael@0 | 127 | rv = appCacheService->DiscardByAppId(LoadInfo()->AppId(), |
michael@0 | 128 | LoadInfo()->IsInBrowserElement()); |
michael@0 | 129 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | else { |
michael@0 | 133 | // Discard the group |
michael@0 | 134 | nsAutoCString groupID; |
michael@0 | 135 | rv = mAppCache->GetGroupID(groupID); |
michael@0 | 136 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 137 | |
michael@0 | 138 | rv = appCacheService->DeactivateGroup(groupID); |
michael@0 | 139 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | if (aCallback) |
michael@0 | 143 | aCallback->OnCacheEntryDoomed(NS_OK); |
michael@0 | 144 | |
michael@0 | 145 | return NS_OK; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | NS_IMETHODIMP AppCacheStorage::AsyncVisitStorage(nsICacheStorageVisitor* aVisitor, |
michael@0 | 149 | bool aVisitEntries) |
michael@0 | 150 | { |
michael@0 | 151 | if (!CacheStorageService::Self()) |
michael@0 | 152 | return NS_ERROR_NOT_INITIALIZED; |
michael@0 | 153 | |
michael@0 | 154 | LOG(("AppCacheStorage::AsyncVisitStorage [this=%p, cb=%p]", this, aVisitor)); |
michael@0 | 155 | |
michael@0 | 156 | return NS_ERROR_NOT_IMPLEMENTED; |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | } // net |
michael@0 | 160 | } // mozilla |