void CacheStorageService::RemoveEntry(CacheEntry* aEntry) { LOG(("CacheStorageService::RemoveEntry [entry=%p]", aEntry)); nsAutoCString entryKey; nsresult rv = aEntry->HashingKey(entryKey); if (NS_FAILED(rv)) { NS_ERROR("aEntry->HashingKey() failed?"); return; } mozilla::MutexAutoLock lock(mLock); if (mShutdown) { LOG((" after shutdown")); return; } CacheEntryTable* entries; if (sGlobalEntryTables->Get(aEntry->GetStorageID(), &entries)) RemoveExactEntry(entries, entryKey, aEntry, false /* don't overwrite */); nsAutoCString memoryStorageID(aEntry->GetStorageID()); AppendMemoryStorageID(memoryStorageID); if (sGlobalEntryTables->Get(memoryStorageID, &entries)) RemoveExactEntry(entries, entryKey, aEntry, false /* don't overwrite */); }
void CacheStorageService::CacheFileDoomed(nsILoadContextInfo* aLoadContextInfo, const nsACString & aIdExtension, const nsACString & aURISpec) { nsAutoCString contextKey; CacheFileUtils::AppendKeyPrefix(aLoadContextInfo, contextKey); nsAutoCString entryKey; CacheEntry::HashingKey(EmptyCString(), aIdExtension, aURISpec, entryKey); mozilla::MutexAutoLock lock(mLock); if (mShutdown) return; CacheEntryTable* entries; if (!sGlobalEntryTables->Get(contextKey, &entries)) return; nsRefPtr<CacheEntry> entry; if (!entries->Get(entryKey, getter_AddRefs(entry))) return; if (!entry->IsFileDoomed()) return; if (entry->IsReferenced()) return; // Need to remove under the lock to avoid possible race leading // to duplication of the entry per its key. RemoveExactEntry(entries, entryKey, entry, false); entry->DoomAlreadyRemoved(); }
static PLDHashOperator EvictEntry(const nsACString& aKey, CacheEntry* aEntry, void* aClosure) { CacheEntryTable* entries = static_cast<CacheEntryTable*>(aClosure); nsCString key(aKey); RemoveExactEntry(entries, key, aEntry, false); return PL_DHASH_NEXT; }
void CacheStorageService::RecordMemoryOnlyEntry(CacheEntry* aEntry, bool aOnlyInMemory, bool aOverwrite) { LOG(("CacheStorageService::RecordMemoryOnlyEntry [entry=%p, memory=%d, overwrite=%d]", aEntry, aOnlyInMemory, aOverwrite)); // This method is responsible to put this entry to a special record hashtable // that contains only entries that are stored in memory. // Keep in mind that every entry, regardless of whether is in-memory-only or not // is always recorded in the storage master hash table, the one identified by // CacheEntry.StorageID(). mLock.AssertCurrentThreadOwns(); if (mShutdown) { LOG((" after shutdown")); return; } nsresult rv; nsAutoCString entryKey; rv = aEntry->HashingKey(entryKey); if (NS_FAILED(rv)) { NS_ERROR("aEntry->HashingKey() failed?"); return; } CacheEntryTable* entries = nullptr; nsAutoCString memoryStorageID(aEntry->GetStorageID()); AppendMemoryStorageID(memoryStorageID); if (!sGlobalEntryTables->Get(memoryStorageID, &entries)) { if (!aOnlyInMemory) { LOG((" not recorded as memory only")); return; } entries = new CacheEntryTable(CacheEntryTable::MEMORY_ONLY); sGlobalEntryTables->Put(memoryStorageID, entries); LOG((" new memory-only storage table for %s", memoryStorageID.get())); } if (aOnlyInMemory) { AddExactEntry(entries, entryKey, aEntry, aOverwrite); } else { RemoveExactEntry(entries, entryKey, aEntry, aOverwrite); } }