Bug 722845 - Part 0: Add private flag for cache entries/sessions/requests. r=michal.novotny

This commit is contained in:
Josh Matthews 2012-05-24 16:31:53 +01:00
parent 917eb08db2
commit c45b403049
7 changed files with 47 additions and 5 deletions

View File

@ -41,6 +41,8 @@ nsCacheEntry::nsCacheEntry(nsCString * key,
if (streamBased) MarkStreamBased();
SetStoragePolicy(storagePolicy);
MarkPublic();
}

View File

@ -113,7 +113,8 @@ public:
eActiveMask = 0x00002000,
eInitializedMask = 0x00004000,
eValidMask = 0x00008000,
eBindingMask = 0x00010000
eBindingMask = 0x00010000,
ePrivateMask = 0x00020000
};
void MarkBinding() { mFlags |= eBindingMask; }
@ -129,6 +130,8 @@ public:
void MarkStreamData() { mFlags |= eStreamDataMask; }
void MarkValid() { mFlags |= eValidMask; }
void MarkInvalid() { mFlags &= ~eValidMask; }
void MarkPrivate() { mFlags |= ePrivateMask; }
void MarkPublic() { mFlags &= ~ePrivateMask; }
// void MarkAllowedInMemory() { mFlags |= eAllowedInMemoryMask; }
// void MarkAllowedOnDisk() { mFlags |= eAllowedOnDiskMask; }
@ -145,6 +148,7 @@ public:
!(PR_CLIST_IS_EMPTY(&mRequestQ) &&
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
bool IsNotInUse() { return !IsInUse(); }
bool IsPrivate() { return (mFlags & ePrivateMask) != 0; }
bool IsAllowedInMemory()
@ -155,9 +159,9 @@ public:
bool IsAllowedOnDisk()
{
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
return !IsPrivate() && ((StoragePolicy() == nsICache::STORE_ANYWHERE) ||
(StoragePolicy() == nsICache::STORE_ON_DISK) ||
(StoragePolicy() == nsICache::STORE_ON_DISK_AS_FILE);
(StoragePolicy() == nsICache::STORE_ON_DISK_AS_FILE));
}
bool IsAllowedOffline()

View File

@ -45,6 +45,7 @@ private:
SetStoragePolicy(session->StoragePolicy());
if (session->IsStreamBased()) MarkStreamBased();
if (session->WillDoomEntriesIfExpired()) MarkDoomEntriesIfExpired();
if (session->IsPrivate()) MarkPrivate();
if (blockingMode == nsICache::BLOCKING) MarkBlockingMode();
MarkWaitingForValidation();
NS_IF_ADDREF(mListener);
@ -66,6 +67,7 @@ private:
enum CacheRequestInfo {
eStoragePolicyMask = 0x000000FF,
eStreamBasedMask = 0x00000100,
ePrivateMask = 0x00000200,
eDoomEntriesIfExpiredMask = 0x00001000,
eBlockingModeMask = 0x00010000,
eWaitingForValidationMask = 0x00100000,
@ -104,9 +106,13 @@ private:
nsCacheStoragePolicy StoragePolicy()
{
return (nsCacheStoragePolicy)(mInfo & 0xFF);
return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask);
}
void MarkPrivate() { mInfo |= ePrivateMask; }
void MarkPublic() { mInfo &= ~ePrivateMask; }
bool IsPrivate() { return (mInfo & ePrivateMask) != 0; }
void MarkWaitingForValidation() { mInfo |= eWaitingForValidationMask; }
void DoneWaitingForValidation() { mInfo &= ~eWaitingForValidationMask; }
bool WaitingForValidation()

View File

@ -1941,6 +1941,9 @@ nsCacheService::ActivateEntry(nsCacheRequest * request,
request->StoragePolicy());
if (!entry)
return NS_ERROR_OUT_OF_MEMORY;
if (request->IsPrivate())
entry->MarkPrivate();
entry->Fetched();
++mTotalEntries;

View File

@ -21,6 +21,8 @@ nsCacheSession::nsCacheSession(const char * clientID,
if (streamBased) MarkStreamBased();
else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
MarkPublic();
MarkDoomEntriesIfExpired();
}
@ -98,3 +100,18 @@ NS_IMETHODIMP nsCacheSession::DoomEntry(const nsACString &key,
{
return nsCacheService::DoomEntry(this, key, listener);
}
NS_IMETHODIMP nsCacheSession::GetIsPrivate(bool* aPrivate)
{
*aPrivate = IsPrivate();
return NS_OK;
}
NS_IMETHODIMP nsCacheSession::SetIsPrivate(bool aPrivate)
{
if (aPrivate)
MarkPrivate();
else
MarkPublic();
return NS_OK;
}

View File

@ -26,7 +26,8 @@ public:
enum SessionInfo {
eStoragePolicyMask = 0x000000FF,
eStreamBasedMask = 0x00000100,
eDoomEntriesIfExpiredMask = 0x00001000
eDoomEntriesIfExpiredMask = 0x00001000,
ePrivateMask = 0x00010000
};
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
@ -37,6 +38,9 @@ public:
void ClearDoomEntriesIfExpired() { mInfo &= ~eDoomEntriesIfExpiredMask; }
bool WillDoomEntriesIfExpired() { return (0 != (mInfo & eDoomEntriesIfExpiredMask)); }
void MarkPrivate() { mInfo |= ePrivateMask; }
void MarkPublic() { mInfo &= ~ePrivateMask; }
bool IsPrivate() { return (mInfo & ePrivateMask) != 0; }
nsCacheStoragePolicy StoragePolicy()
{
return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask);

View File

@ -69,4 +69,10 @@ interface nsICacheSession : nsISupports
* doesn't care about the result.
*/
void doomEntry(in ACString key, in nsICacheListener listener);
/**
* Private entries will be doomed when the last private browsing session
* finishes.
*/
attribute boolean isPrivate;
};