diff --git a/netwerk/cache2/CacheEntry.cpp b/netwerk/cache2/CacheEntry.cpp index db6daee1d538..43a573910246 100644 --- a/netwerk/cache2/CacheEntry.cpp +++ b/netwerk/cache2/CacheEntry.cpp @@ -191,6 +191,13 @@ NS_IMPL_ISUPPORTS(CacheEntry, nsIRunnable, CacheFileListener) +/* static */ +uint64_t CacheEntry::GetNextId() +{ + static Atomic id(0); + return ++id; +} + CacheEntry::CacheEntry(const nsACString& aStorageID, const nsACString& aURI, const nsACString& aEnhanceID, @@ -217,6 +224,7 @@ CacheEntry::CacheEntry(const nsACString& aStorageID, , mWriter(nullptr) , mPredictedDataSize(0) , mUseCount(0) +, mCacheEntryId(GetNextId()) { LOG(("CacheEntry::CacheEntry [this=%p]", this)); @@ -1048,6 +1056,12 @@ NS_IMETHODIMP CacheEntry::GetKey(nsACString & aKey) return NS_OK; } +NS_IMETHODIMP CacheEntry::GetCacheEntryId(uint64_t *aCacheEntryId) +{ + *aCacheEntryId = mCacheEntryId; + return NS_OK; +} + NS_IMETHODIMP CacheEntry::GetFetchCount(int32_t *aFetchCount) { NS_ENSURE_SUCCESS(mFileStatus, NS_ERROR_NOT_AVAILABLE); diff --git a/netwerk/cache2/CacheEntry.h b/netwerk/cache2/CacheEntry.h index a13030aa0ea8..dbd8275bf808 100644 --- a/netwerk/cache2/CacheEntry.h +++ b/netwerk/cache2/CacheEntry.h @@ -54,6 +54,8 @@ public: NS_DECL_NSICACHEENTRY NS_DECL_NSIRUNNABLE + static uint64_t GetNextId(); + CacheEntry(const nsACString& aStorageID, const nsACString& aURI, const nsACString& aEnhanceID, bool aUseDisk, bool aSkipSizeCheck, bool aPin); @@ -383,6 +385,8 @@ private: int64_t mPredictedDataSize; mozilla::TimeStamp mLoadStart; uint32_t mUseCount; + + const uint64_t mCacheEntryId; }; diff --git a/netwerk/cache2/OldWrappers.cpp b/netwerk/cache2/OldWrappers.cpp index 66d16a8935c4..698c7af6526b 100644 --- a/netwerk/cache2/OldWrappers.cpp +++ b/netwerk/cache2/OldWrappers.cpp @@ -346,13 +346,13 @@ _OldGetDiskConsumption::VisitEntry(const char * deviceID, // _OldCacheEntryWrapper _OldCacheEntryWrapper::_OldCacheEntryWrapper(nsICacheEntryDescriptor* desc) -: mOldDesc(desc), mOldInfo(desc) +: mOldDesc(desc), mOldInfo(desc), mCacheEntryId(CacheEntry::GetNextId()) { LOG(("Creating _OldCacheEntryWrapper %p for descriptor %p", this, desc)); } _OldCacheEntryWrapper::_OldCacheEntryWrapper(nsICacheEntryInfo* info) -: mOldDesc(nullptr), mOldInfo(info) +: mOldDesc(nullptr), mOldInfo(info), mCacheEntryId(CacheEntry::GetNextId()) { LOG(("Creating _OldCacheEntryWrapper %p for info %p", this, info)); } diff --git a/netwerk/cache2/OldWrappers.h b/netwerk/cache2/OldWrappers.h index 651633e6017f..56433278d119 100644 --- a/netwerk/cache2/OldWrappers.h +++ b/netwerk/cache2/OldWrappers.h @@ -115,6 +115,11 @@ public: { return mOldInfo->GetKey(aKey); } + NS_IMETHOD GetCacheEntryId(uint64_t *aCacheEntryId) override + { + *aCacheEntryId = mCacheEntryId; + return NS_OK; + } NS_IMETHOD GetFetchCount(int32_t *aFetchCount) override { return mOldInfo->GetFetchCount(aFetchCount); @@ -176,6 +181,8 @@ private: _OldCacheEntryWrapper() = delete; nsICacheEntryDescriptor* mOldDesc; // ref holded in mOldInfo nsCOMPtr mOldInfo; + + const uint64_t mCacheEntryId; }; diff --git a/netwerk/cache2/nsICacheEntry.idl b/netwerk/cache2/nsICacheEntry.idl index e2322279ecbc..38e41d056f84 100644 --- a/netwerk/cache2/nsICacheEntry.idl +++ b/netwerk/cache2/nsICacheEntry.idl @@ -27,6 +27,12 @@ interface nsICacheEntry : nsISupports */ readonly attribute ACString key; + /** + * The unique ID for every nsICacheEntry instance, which can be used to check + * whether two pieces of information are from the same nsICacheEntry instance. + */ + readonly attribute uint64_t cacheEntryId; + /** * Whether the entry is memory/only or persisted to disk. * Note: private browsing entries are reported as persistent for consistency