Skip to content

Commit 30be843

Browse files
committed
Bug 1032254 - Provide a way to pin resources in the http cache r=honzab
--HG-- rename : netwerk/test/unit/test_cache2-28-concurrent_read_resumable_entry_size_zero.js => netwerk/test/unit/test_cache2-29a-concurrent_read_resumable_entry_size_zero.js rename : netwerk/test/unit/test_cache2-29-concurrent_read_non-resumable_entry_size_zero.js => netwerk/test/unit/test_cache2-29b-concurrent_read_non-resumable_entry_size_zero.js
1 parent c1d6404 commit 30be843

27 files changed

+707
-163
lines changed

netwerk/base/nsICachingChannel.idl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface nsIFile;
1717
* 3) Support for uniquely identifying cached data in cases when the URL
1818
* is insufficient (e.g., HTTP form submission).
1919
*/
20-
[scriptable, uuid(436b939d-e391-48e5-ba64-ab0e496e3400)]
20+
[scriptable, uuid(dd1d6122-5ecf-4fe4-8f0f-995e7ab3121a)]
2121
interface nsICachingChannel : nsICacheInfoChannel
2222
{
2323
/**
@@ -53,6 +53,11 @@ interface nsICachingChannel : nsICacheInfoChannel
5353
*/
5454
attribute boolean cacheOnlyMetadata;
5555

56+
/**
57+
* Tells the channel to use the pinning storage.
58+
*/
59+
attribute boolean pin;
60+
5661
/**************************************************************************
5762
* Caching channel specific load flags:
5863
*/

netwerk/cache2/CacheEntry.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ NS_IMPL_ISUPPORTS(CacheEntry,
163163
CacheEntry::CacheEntry(const nsACString& aStorageID,
164164
nsIURI* aURI,
165165
const nsACString& aEnhanceID,
166-
bool aUseDisk)
166+
bool aUseDisk,
167+
uint32_t aPinningAppId)
167168
: mFrecency(0)
168169
, mSortingExpirationTime(uint32_t(-1))
169170
, mLock("CacheEntry")
@@ -172,6 +173,7 @@ CacheEntry::CacheEntry(const nsACString& aStorageID,
172173
, mEnhanceID(aEnhanceID)
173174
, mStorageID(aStorageID)
174175
, mUseDisk(aUseDisk)
176+
, mPinningAppId(aPinningAppId)
175177
, mIsDoomed(false)
176178
, mSecurityInfoLoaded(false)
177179
, mPreventCallbacks(false)
@@ -341,7 +343,8 @@ bool CacheEntry::Load(bool aTruncate, bool aPriority)
341343
// as a new one.
342344
// 2. When this is a memory-only entry, check there is a disk file.
343345
// If there is or could be, doom that file.
344-
if ((!aTruncate || !mUseDisk) && NS_SUCCEEDED(rv)) {
346+
if ((!aTruncate || !mUseDisk) && NS_SUCCEEDED(rv) &&
347+
!mPinningAppId) {
345348
// Check the index right now to know we have or have not the entry
346349
// as soon as possible.
347350
CacheIndex::EntryStatus status;
@@ -391,6 +394,7 @@ bool CacheEntry::Load(bool aTruncate, bool aPriority)
391394
rv = mFile->Init(fileKey,
392395
aTruncate,
393396
!mUseDisk,
397+
mPinningAppId,
394398
aPriority,
395399
directLoad ? nullptr : this);
396400
}
@@ -486,6 +490,7 @@ already_AddRefed<CacheEntryHandle> CacheEntry::ReopenTruncated(bool aMemoryOnly,
486490
nsresult rv = CacheStorageService::Self()->AddStorageEntry(
487491
GetStorageID(), GetURI(), GetEnhanceID(),
488492
mUseDisk && !aMemoryOnly,
493+
mPinningAppId,
489494
true, // always create
490495
true, // truncate existing (this one)
491496
getter_AddRefs(handle));

netwerk/cache2/CacheEntry.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class CacheEntry final : public nsICacheEntry
5555
NS_DECL_NSIRUNNABLE
5656

5757
CacheEntry(const nsACString& aStorageID, nsIURI* aURI, const nsACString& aEnhanceID,
58-
bool aUseDisk);
58+
bool aUseDisk, uint32_t aPinningAppId);
5959

6060
void AsyncOpen(nsICacheEntryOpenCallback* aCallback, uint32_t aFlags);
6161

@@ -276,6 +276,9 @@ class CacheEntry final : public nsICacheEntry
276276
// Whether it's allowed to persist the data to disk
277277
bool const mUseDisk;
278278

279+
// AppId of an app that wants this entry be pinned
280+
uint32_t const mPinningAppId;
281+
279282
// Set when entry is doomed with AsyncDoom() or DoomAlreadyRemoved().
280283
// Left as a standalone flag to not bother with locking (there is no need).
281284
bool mIsDoomed;

netwerk/cache2/CacheFile.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ nsresult
212212
CacheFile::Init(const nsACString &aKey,
213213
bool aCreateNew,
214214
bool aMemoryOnly,
215+
uint32_t aPinningAppID,
215216
bool aPriority,
216217
CacheFileListener *aCallback)
217218
{
@@ -266,7 +267,7 @@ CacheFile::Init(const nsACString &aKey,
266267

267268
mOpeningFile = true;
268269
mListener = aCallback;
269-
rv = CacheFileIOManager::OpenFile(mKey, flags, this);
270+
rv = CacheFileIOManager::OpenFile(mKey, aPinningAppID, flags, this);
270271
if (NS_FAILED(rv)) {
271272
mListener = nullptr;
272273
mOpeningFile = false;

netwerk/cache2/CacheFile.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class CacheFile final : public CacheFileChunkListener
5656
nsresult Init(const nsACString &aKey,
5757
bool aCreateNew,
5858
bool aMemoryOnly,
59+
uint32_t aPinningAppID,
5960
bool aPriority,
6061
CacheFileListener *aCallback);
6162

@@ -103,6 +104,10 @@ class CacheFile final : public CacheFileChunkListener
103104
void Key(nsACString& aKey) { aKey = mKey; }
104105
bool IsDoomed();
105106
bool IsWriteInProgress();
107+
CacheFileIOManager* Manager()
108+
{
109+
return mHandle ? mHandle->Manager() : nullptr;
110+
}
106111

107112
// Memory reporting
108113
size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;

netwerk/cache2/CacheFileContextEvictor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ CacheFileContextEvictor::GetContextFile(nsILoadContextInfo *aLoadContextInfo,
398398
leafName.AssignLiteral(CONTEXT_EVICTION_PREFIX);
399399

400400
nsAutoCString keyPrefix;
401-
CacheFileUtils::AppendKeyPrefix(aLoadContextInfo, keyPrefix);
401+
CacheFileUtils::AppendKeyPrefix(aLoadContextInfo, false, keyPrefix);
402402

403403
nsAutoCString data64;
404404
rv = Base64Encode(keyPrefix, data64);

0 commit comments

Comments
 (0)