Backed out changeset 749816a9c3fb (bug 1020416) for causing merge conflicts on a CLOSED TREE

This commit is contained in:
Carsten "Tomcat" Book 2014-07-22 16:20:39 +02:00
parent 97ba8f5c4f
commit f6abf41f8b
10 changed files with 17 additions and 260 deletions

View File

@ -960,38 +960,6 @@ NS_IMETHODIMP CacheEntry::GetExpirationTime(uint32_t *aExpirationTime)
return mFile->GetExpirationTime(aExpirationTime);
}
NS_IMETHODIMP CacheEntry::GetIsForcedValid(bool *aIsForcedValid)
{
NS_ENSURE_ARG(aIsForcedValid);
nsAutoCString key;
nsresult rv = HashingKeyWithStorage(key);
if (NS_FAILED(rv)) {
return rv;
}
*aIsForcedValid = CacheStorageService::Self()->IsForcedValidEntry(key);
LOG(("CacheEntry::GetIsForcedValid [this=%p, IsForcedValid=%d]", this, *aIsForcedValid));
return NS_OK;
}
NS_IMETHODIMP CacheEntry::ForceValidFor(uint32_t aSecondsToTheFuture)
{
LOG(("CacheEntry::ForceValidFor [this=%p, aSecondsToTheFuture=%d]", this, aSecondsToTheFuture));
nsAutoCString key;
nsresult rv = HashingKeyWithStorage(key);
if (NS_FAILED(rv)) {
return rv;
}
CacheStorageService::Self()->ForceEntryValidFor(key, aSecondsToTheFuture);
return NS_OK;
}
NS_IMETHODIMP CacheEntry::SetExpirationTime(uint32_t aExpirationTime)
{
NS_ENSURE_SUCCESS(mFileStatus, NS_ERROR_NOT_AVAILABLE);

View File

@ -1148,8 +1148,6 @@ CacheIndex::GetEntryForEviction(SHA1Sum::Hash *aHash, uint32_t *aCnt)
if (!index)
return NS_ERROR_NOT_INITIALIZED;
MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
CacheIndexAutoLock lock(index);
if (!index->IsIndexUsable()) {
@ -1162,86 +1160,29 @@ CacheIndex::GetEntryForEviction(SHA1Sum::Hash *aHash, uint32_t *aCnt)
if (index->mExpirationArray.Length() == 0)
return NS_ERROR_NOT_AVAILABLE;
SHA1Sum::Hash hash;
bool foundEntry = false;
uint32_t i = 0, j = 0;
uint32_t now = PR_Now() / PR_USEC_PER_SEC;
// find the first expired, non-forced valid entry
for (i = 0; i < index->mExpirationArray.Length(); i++) {
if (index->mExpirationArray[i]->mExpirationTime < now) {
memcpy(&hash, &index->mExpirationArray[i]->mHash, sizeof(SHA1Sum::Hash));
if (!IsForcedValidEntry(&hash)) {
foundEntry = true;
break;
}
} else {
// all further entries have not expired yet
break;
}
}
if (foundEntry) {
*aCnt = index->mExpirationArray.Length() - i;
if (index->mExpirationArray[0]->mExpirationTime < now) {
memcpy(aHash, &index->mExpirationArray[0]->mHash, sizeof(SHA1Sum::Hash));
*aCnt = index->mExpirationArray.Length();
LOG(("CacheIndex::GetEntryForEviction() - returning entry from expiration "
"array [hash=%08x%08x%08x%08x%08x, cnt=%u, expTime=%u, now=%u, "
"frecency=%u]", LOGSHA1(&hash), *aCnt,
index->mExpirationArray[i]->mExpirationTime, now,
index->mExpirationArray[i]->mFrecency));
"frecency=%u]", LOGSHA1(aHash), *aCnt,
index->mExpirationArray[0]->mExpirationTime, now,
index->mExpirationArray[0]->mFrecency));
}
else {
// check if we've already tried all the entries
if (i == index->mExpirationArray.Length())
return NS_ERROR_NOT_AVAILABLE;
// find first non-forced valid entry with the lowest frecency
for (j = 0; j < index->mFrecencyArray.Length(); j++) {
memcpy(&hash, &index->mFrecencyArray[j]->mHash, sizeof(SHA1Sum::Hash));
if (!IsForcedValidEntry(&hash)) {
foundEntry = true;
break;
}
}
if (!foundEntry)
return NS_ERROR_NOT_AVAILABLE;
// forced valid entries skipped in both arrays could overlap, just use max
*aCnt = index->mFrecencyArray.Length() - std::max(i, j);
memcpy(aHash, &index->mFrecencyArray[0]->mHash, sizeof(SHA1Sum::Hash));
*aCnt = index->mFrecencyArray.Length();
LOG(("CacheIndex::GetEntryForEviction() - returning entry from frecency "
"array [hash=%08x%08x%08x%08x%08x, cnt=%u, expTime=%u, now=%u, "
"frecency=%u]", LOGSHA1(&hash), *aCnt,
index->mFrecencyArray[j]->mExpirationTime, now,
index->mFrecencyArray[j]->mFrecency));
"frecency=%u]", LOGSHA1(aHash), *aCnt,
index->mExpirationArray[0]->mExpirationTime, now,
index->mExpirationArray[0]->mFrecency));
}
memcpy(aHash, &hash, sizeof(SHA1Sum::Hash));
return NS_OK;
}
// static
bool CacheIndex::IsForcedValidEntry(const SHA1Sum::Hash *aHash)
{
nsRefPtr<CacheFileHandle> handle;
CacheFileIOManager::gInstance->mHandles.GetHandle(
aHash, false, getter_AddRefs(handle));
if (!handle)
return false;
nsCString hashKey = handle->Key();
return CacheStorageService::Self()->IsForcedValidEntry(hashKey);
}
// static
nsresult
CacheIndex::GetCacheSize(uint32_t *_retval)

View File

@ -561,15 +561,9 @@ public:
// Returns a hash of the least important entry that should be evicted if the
// cache size is over limit and also returns a total number of all entries in
// the index minus the number of forced valid entries that we encounter
// when searching (see below)
// the index.
static nsresult GetEntryForEviction(SHA1Sum::Hash *aHash, uint32_t *aCnt);
// Checks if a cache entry is currently forced valid. Used to prevent an entry
// (that has been forced valid) from being evicted when the cache size reaches
// its limit.
static bool IsForcedValidEntry(const SHA1Sum::Hash *aHash);
// Returns cache size in kB.
static nsresult GetCacheSize(uint32_t *_retval);

View File

@ -957,16 +957,9 @@ CacheStorageService::RemoveEntry(CacheEntry* aEntry, bool aOnlyUnreferenced)
return false;
}
if (aOnlyUnreferenced) {
if (aEntry->IsReferenced()) {
LOG((" still referenced, not removing"));
return false;
}
if (!aEntry->IsUsingDisk() && IsForcedValidEntry(entryKey)) {
LOG((" forced valid, not removing"));
return false;
}
if (aOnlyUnreferenced && aEntry->IsReferenced()) {
LOG((" still referenced, not removing"));
return false;
}
CacheEntryTable* entries;
@ -1034,46 +1027,6 @@ CacheStorageService::RecordMemoryOnlyEntry(CacheEntry* aEntry,
}
}
// Checks if a cache entry is forced valid (will be loaded directly from cache
// without further validation) - see nsICacheEntry.idl for further details
bool CacheStorageService::IsForcedValidEntry(nsACString &aCacheEntryKey)
{
TimeStamp validUntil;
mozilla::MutexAutoLock lock(mLock);
if (!mForcedValidEntries.Get(aCacheEntryKey, &validUntil)) {
return false;
}
if (validUntil.IsNull()) {
return false;
}
// Entry timeout not reached yet
if (TimeStamp::NowLoRes() <= validUntil) {
return true;
}
// Entry timeout has been reached
mForcedValidEntries.Remove(aCacheEntryKey);
return false;
}
// Allows a cache entry to be loaded directly from cache without further
// validation - see nsICacheEntry.idl for further details
void CacheStorageService::ForceEntryValidFor(nsACString &aCacheEntryKey,
uint32_t aSecondsToTheFuture)
{
mozilla::MutexAutoLock lock(mLock);
// This will be the timeout
TimeStamp validUntil = TimeStamp::NowLoRes() +
TimeDuration::FromSeconds(aSecondsToTheFuture);
mForcedValidEntries.Put(aCacheEntryKey, validUntil);
}
void
CacheStorageService::OnMemoryConsumptionChange(CacheMemoryConsumer* aConsumer,
uint32_t aCurrentMemoryConsumption)

View File

@ -146,26 +146,6 @@ private:
bool aOnlyInMemory,
bool aOverwrite);
/**
* Sets a cache entry valid (overrides the default loading behavior by loading
* directly from cache) for the given number of seconds
* See nsICacheEntry.idl for more details
*/
void ForceEntryValidFor(nsACString &aCacheEntryKey,
uint32_t aSecondsToTheFuture);
private:
friend class CacheIndex;
/**
* Retrieves the status of the cache entry to see if it has been forced valid
* (so it will loaded directly from cache without further validation)
* CacheIndex uses this to prevent a cache entry from being prememptively
* thrown away when forced valid
* See nsICacheEntry.idl for more details
*/
bool IsForcedValidEntry(nsACString &aCacheEntryKey);
private:
// These are helpers for telemetry monitorying of the memory pools.
void TelemetryPrune(TimeStamp &now);
@ -284,9 +264,6 @@ private:
mozilla::Mutex mLock;
// Tracks entries that may be forced valid.
nsDataHashtable<nsCStringHashKey, TimeStamp> mForcedValidEntries;
bool mShutdown;
// Accessible only on the service thread

View File

@ -366,18 +366,6 @@ _OldCacheEntryWrapper::~_OldCacheEntryWrapper()
LOG(("Destroying _OldCacheEntryWrapper %p for descriptor %p", this, mOldInfo.get()));
}
NS_IMETHODIMP _OldCacheEntryWrapper::GetIsForcedValid(bool *aIsForcedValid)
{
// Unused stub
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP _OldCacheEntryWrapper::ForceValidFor(uint32_t aSecondsToTheFuture)
{
// Unused stub
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMPL_ISUPPORTS(_OldCacheEntryWrapper, nsICacheEntry)
NS_IMETHODIMP _OldCacheEntryWrapper::AsyncDoom(nsICacheEntryDoomCallback* listener)

View File

@ -33,8 +33,6 @@ public:
NS_IMETHOD AsyncDoom(nsICacheEntryDoomCallback* listener);
NS_IMETHOD GetPersistent(bool *aPersistToDisk);
NS_IMETHOD GetIsForcedValid(bool *aIsForcedValid);
NS_IMETHOD ForceValidFor(uint32_t aSecondsToTheFuture);
NS_IMETHOD SetValid() { return NS_OK; }
NS_IMETHOD MetaDataReady() { return NS_OK; }
NS_IMETHOD Recreate(bool, nsICacheEntry**);

View File

@ -16,7 +16,7 @@ interface nsICacheListener;
interface nsIFile;
interface nsICacheEntryMetaDataVisitor;
[scriptable, uuid(607c2a2c-0a48-40b9-a956-8cf2bb9857cf)]
[scriptable, uuid(972dc51d-df01-4b1e-b7f3-76dbcc603b1e)]
interface nsICacheEntry : nsISupports
{
/**
@ -62,28 +62,6 @@ interface nsICacheEntry : nsISupports
*/
void setExpirationTime(in uint32_t expirationTime);
/**
* This method is intended to override the per-spec cache validation
* decisions for a duration specified in seconds. The current state can
* be examined with isForcedValid (see below). This value is not persisted,
* so it will not survive session restart. Cache entries that are forced valid
* will not be evicted from the cache for the duration of forced validity.
* This means that there is a potential problem if the number of forced valid
* entries grows to take up more space than the cache size allows.
*
* @param aSecondsToTheFuture
* the number of seconds the default cache validation behavior will be
* overridden before it returns to normal
*/
void forceValidFor(in unsigned long aSecondsToTheFuture);
/**
* The state variable for whether this entry is currently forced valid.
* Defaults to false for normal cache validation behavior, and will return
* true if the number of seconds set by forceValidFor() has yet to be reached.
*/
readonly attribute boolean isForcedValid;
/**
* Open blocking input stream to cache data. Use the stream transport
* service to asynchronously read this stream on a background thread.

View File

@ -1,37 +0,0 @@
Components.utils.import('resource://gre/modules/LoadContextInfo.jsm');
function run_test()
{
do_get_profile();
if (!newCacheBackEndUsed()) {
do_check_true(true, "This test checks only cache2 specific behavior.");
return;
}
var mc = new MultipleCallbacks(2, function() {
finish_cache2_test();
});
asyncOpenCacheEntry("http://m1/", "memory", Ci.nsICacheStorage.OPEN_NORMALLY, LoadContextInfo.default,
new OpenCallback(NEW, "meta", "data", function(entry) {
// Check the default
equal(entry.isForcedValid, false);
// Forced valid and confirm
entry.forceValidFor(2);
do_timeout(1000, function() {
equal(entry.isForcedValid, true);
mc.fired();
});
// Confirm the timeout occurs
do_timeout(3000, function() {
equal(entry.isForcedValid, false);
mc.fired();
});
})
);
do_test_pending();
}

View File

@ -67,10 +67,7 @@ skip-if = os == "android"
skip-if = os == "android"
[test_cache2-25-chunk-memory-limit.js]
[test_cache2-26-no-outputstream-open.js]
# GC, that this patch is dependent on, doesn't work well on Android.
skip-if = os == "android"
[test_cache2-27-force-valid-for.js]
# Bug 675039, comment 6: "The difference is that the memory cache is disabled in Armv6 builds."
# GC, that this patch is depenedent on, doesn't work well on Android."
skip-if = os == "android"
[test_304_responses.js]
# Bug 675039: test hangs on Android-armv6