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