Bug 1395202 - Part 1: Create nsICacheEntry::CacheEntryId. r=michal, f=junior,mayhemer
☠☠ backed out by e1b5e17e5973 ☠ ☠
authorHo-Pang Hsu <hopang.hsu@gmail.com>
Tue, 10 Oct 2017 04:09:00 -0400
changeset 385439 0e548491460993bb141a68c596c186ef80dc0e68
parent 385438 8912a9d63a5c7f9b75c5740ff8be7835cba07747
child 385440 92e3c67a38722cd58b70da2dbadc877d66ab8db6
push id32656
push userarchaeopteryx@coole-files.de
push dateWed, 11 Oct 2017 09:50:40 +0000
treeherdermozilla-central@20d9ad08dd36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmichal
bugs1395202
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1395202 - Part 1: Create nsICacheEntry::CacheEntryId. r=michal, f=junior,mayhemer
netwerk/cache2/CacheEntry.cpp
netwerk/cache2/CacheEntry.h
netwerk/cache2/OldWrappers.cpp
netwerk/cache2/OldWrappers.h
netwerk/cache2/nsICacheEntry.idl
--- a/netwerk/cache2/CacheEntry.cpp
+++ b/netwerk/cache2/CacheEntry.cpp
@@ -186,16 +186,23 @@ nsresult CacheEntry::Callback::OnAvailTh
 
 // CacheEntry
 
 NS_IMPL_ISUPPORTS(CacheEntry,
                   nsICacheEntry,
                   nsIRunnable,
                   CacheFileListener)
 
+/* static */
+uint64_t CacheEntry::GetNextId()
+{
+  static Atomic<uint64_t, Relaxed> id(0);
+  return ++id;
+}
+
 CacheEntry::CacheEntry(const nsACString& aStorageID,
                        const nsACString& aURI,
                        const nsACString& aEnhanceID,
                        bool aUseDisk,
                        bool aSkipSizeCheck,
                        bool aPin)
 : mFrecency(0)
 , mSortingExpirationTime(uint32_t(-1))
@@ -212,16 +219,17 @@ CacheEntry::CacheEntry(const nsACString&
 , mHasData(false)
 , mPinned(aPin)
 , mPinningKnown(false)
 , mState(NOTLOADED)
 , mRegistration(NEVERREGISTERED)
 , mWriter(nullptr)
 , mPredictedDataSize(0)
 , mUseCount(0)
+, mCacheEntryId(GetNextId())
 {
   LOG(("CacheEntry::CacheEntry [this=%p]", this));
 
   mService = CacheStorageService::Self();
 
   CacheStorageService::Self()->RecordMemoryOnlyEntry(
     this, !aUseDisk, true /* overwrite */);
 }
@@ -1043,16 +1051,22 @@ NS_IMETHODIMP CacheEntry::GetPersistent(
 }
 
 NS_IMETHODIMP CacheEntry::GetKey(nsACString & aKey)
 {
   aKey.Assign(mURI);
   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);
 
   return mFile->GetFetchCount(reinterpret_cast<uint32_t*>(aFetchCount));
 }
 
 NS_IMETHODIMP CacheEntry::GetLastFetched(uint32_t *aLastFetched)
--- a/netwerk/cache2/CacheEntry.h
+++ b/netwerk/cache2/CacheEntry.h
@@ -49,16 +49,18 @@ class CacheEntry final : public nsICache
                        , public nsIRunnable
                        , public CacheFileListener
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   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);
 
   void AsyncOpen(nsICacheEntryOpenCallback* aCallback, uint32_t aFlags);
 
   CacheEntryHandle* NewHandle();
   // For a new and recreated entry w/o a callback, we need to wrap it
   // with a handle to detect writing consumer is gone.
@@ -378,16 +380,18 @@ private:
   private:
     uint32_t mFlags;
   } mBackgroundOperations;
 
   nsCOMPtr<nsISupports> mSecurityInfo;
   int64_t mPredictedDataSize;
   mozilla::TimeStamp mLoadStart;
   uint32_t mUseCount;
+
+  const uint64_t mCacheEntryId;
 };
 
 
 class CacheEntryHandle : public nsICacheEntry
 {
 public:
   explicit CacheEntryHandle(CacheEntry* aEntry);
   CacheEntry* Entry() const { return mEntry; }
--- a/netwerk/cache2/OldWrappers.cpp
+++ b/netwerk/cache2/OldWrappers.cpp
@@ -341,23 +341,23 @@ NS_IMETHODIMP
   MOZ_CRASH("Unexpected");
   return NS_OK;
 }
 
 
 // _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));
 }
 
 _OldCacheEntryWrapper::~_OldCacheEntryWrapper()
 {
   LOG(("Destroying _OldCacheEntryWrapper %p for descriptor %p", this, mOldInfo.get()));
 }
--- a/netwerk/cache2/OldWrappers.h
+++ b/netwerk/cache2/OldWrappers.h
@@ -110,16 +110,21 @@ public:
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   // nsICacheEntryInfo
   NS_IMETHOD GetKey(nsACString & aKey) override
   {
     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);
   }
   NS_IMETHOD GetLastFetched(uint32_t *aLastFetched) override
   {
     return mOldInfo->GetLastFetched(aLastFetched);
   }
@@ -171,16 +176,18 @@ public:
   explicit _OldCacheEntryWrapper(nsICacheEntryInfo* info);
 
 private:
   virtual ~_OldCacheEntryWrapper();
 
   _OldCacheEntryWrapper() = delete;
   nsICacheEntryDescriptor* mOldDesc; // ref holded in mOldInfo
   nsCOMPtr<nsICacheEntryInfo> mOldInfo;
+
+  const uint64_t mCacheEntryId;
 };
 
 
 class _OldCacheLoad : public Runnable
                     , public nsICacheListener
 {
 public:
   NS_DECL_ISUPPORTS_INHERITED
--- a/netwerk/cache2/nsICacheEntry.idl
+++ b/netwerk/cache2/nsICacheEntry.idl
@@ -23,16 +23,22 @@ interface nsICacheEntry : nsISupports
   const unsigned long NO_EXPIRATION_TIME = 0xFFFFFFFF;
 
   /**
    * Get the key identifying the cache entry.
    */
   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
    * while are not actually persisted to disk.
    */
   readonly attribute boolean persistent;
 
   /**
    * Get the number of times the cache entry has been opened.