Bug 1201042 - Update HTTP cache index format to work with OriginAttributes' suffix, r=honzab
authorMichal Novotny <michal.novotny@gmail.com>
Tue, 08 Nov 2016 21:11:30 +0100
changeset 351783 e6992502f673232fe03419e7cdcbeb551adfb381
parent 351782 d2098e1d1f2ddf408152ba14ad75e68566b7bc68
child 351784 4975b2d475fbda30526ec997abd00f94b4fef55a
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs1201042
milestone52.0a1
Bug 1201042 - Update HTTP cache index format to work with OriginAttributes' suffix, r=honzab
browser/components/originattributes/test/browser/browser_cache.js
netwerk/cache2/CacheFile.cpp
netwerk/cache2/CacheFileIOManager.cpp
netwerk/cache2/CacheFileIOManager.h
netwerk/cache2/CacheHashUtils.cpp
netwerk/cache2/CacheHashUtils.h
netwerk/cache2/CacheIndex.cpp
netwerk/cache2/CacheIndex.h
--- a/browser/components/originattributes/test/browser/browser_cache.js
+++ b/browser/components/originattributes/test/browser/browser_cache.js
@@ -216,16 +216,24 @@ function* doTest(aBrowser) {
 
 // The check function, which checks the number of cache entries.
 function* doCheck(aShouldIsolate, aInputA, aInputB) {
   let expectedEntryCount = 1;
   let data = [];
   data = data.concat(yield cacheDataForContext(LoadContextInfo.default));
   data = data.concat(yield cacheDataForContext(LoadContextInfo.private));
   data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(true, {})));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(false, { userContextId: 1 })));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(true, { userContextId: 1 })));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(false, { userContextId: 2 })));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(true, { userContextId: 2 })));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(false, { firstPartyDomain: "example.com" })));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(true, { firstPartyDomain: "example.com" })));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(false, { firstPartyDomain: "example.org" })));
+  data = data.concat(yield cacheDataForContext(LoadContextInfo.custom(true, { firstPartyDomain: "example.org" })));
 
   if (aShouldIsolate) {
     expectedEntryCount = 2;
   }
 
   for (let suffix of suffixes) {
     let foundEntryCount = countMatchingCacheEntries(data, "example.net", suffix);
     let result = (expectedEntryCount === foundEntryCount);
--- a/netwerk/cache2/CacheFile.cpp
+++ b/netwerk/cache2/CacheFile.cpp
@@ -2295,22 +2295,19 @@ CacheFile::InitIndexEntry()
 {
   MOZ_ASSERT(mHandle);
 
   if (mHandle->IsDoomed())
     return NS_OK;
 
   nsresult rv;
 
-  // Bug 1201042 - will pass OriginAttributes directly.
-  rv = CacheFileIOManager::InitIndexEntry(mHandle,
-                                          mMetadata->OriginAttributes().mAppId,
-                                          mMetadata->IsAnonymous(),
-                                          mMetadata->OriginAttributes().mInIsolatedMozBrowser,
-                                          mPinned);
+  rv = CacheFileIOManager::InitIndexEntry(
+         mHandle, GetOriginAttrsHash(mMetadata->OriginAttributes()),
+         mMetadata->IsAnonymous(), mPinned);
   NS_ENSURE_SUCCESS(rv, rv);
 
   uint32_t expTime;
   mMetadata->GetExpirationTime(&expTime);
 
   uint32_t frecency;
   mMetadata->GetFrecency(&frecency);
 
--- a/netwerk/cache2/CacheFileIOManager.cpp
+++ b/netwerk/cache2/CacheFileIOManager.cpp
@@ -960,22 +960,22 @@ public:
 protected:
   RefPtr<CacheFileHandle>       mHandle;
   nsCString                     mNewName;
   nsCOMPtr<CacheFileIOListener> mCallback;
 };
 
 class InitIndexEntryEvent : public Runnable {
 public:
-  InitIndexEntryEvent(CacheFileHandle *aHandle, uint32_t aAppId,
-                      bool aAnonymous, bool aInIsolatedMozBrowser, bool aPinning)
+  InitIndexEntryEvent(CacheFileHandle *aHandle,
+                      OriginAttrsHash aOriginAttrsHash, bool aAnonymous,
+                      bool aPinning)
     : mHandle(aHandle)
-    , mAppId(aAppId)
+    , mOriginAttrsHash(aOriginAttrsHash)
     , mAnonymous(aAnonymous)
-    , mInIsolatedMozBrowser(aInIsolatedMozBrowser)
     , mPinning(aPinning)
   {
     MOZ_COUNT_CTOR(InitIndexEntryEvent);
   }
 
 protected:
   ~InitIndexEntryEvent()
   {
@@ -984,34 +984,34 @@ protected:
 
 public:
   NS_IMETHOD Run() override
   {
     if (mHandle->IsClosed() || mHandle->IsDoomed()) {
       return NS_OK;
     }
 
-    CacheIndex::InitEntry(mHandle->Hash(), mAppId, mAnonymous, mInIsolatedMozBrowser, mPinning);
+    CacheIndex::InitEntry(mHandle->Hash(), mOriginAttrsHash, mAnonymous,
+                          mPinning);
 
     // We cannot set the filesize before we init the entry. If we're opening
     // an existing entry file, frecency and expiration time will be set after
     // parsing the entry file, but we must set the filesize here since nobody is
     // going to set it if there is no write to the file.
     uint32_t sizeInK = mHandle->FileSizeInK();
     CacheIndex::UpdateEntry(mHandle->Hash(), nullptr, nullptr, &sizeInK);
 
     return NS_OK;
   }
 
 protected:
   RefPtr<CacheFileHandle> mHandle;
-  uint32_t                  mAppId;
-  bool                      mAnonymous;
-  bool                      mInIsolatedMozBrowser;
-  bool                      mPinning;
+  OriginAttrsHash         mOriginAttrsHash;
+  bool                    mAnonymous;
+  bool                    mPinning;
 };
 
 class UpdateIndexEntryEvent : public Runnable {
 public:
   UpdateIndexEntryEvent(CacheFileHandle *aHandle, const uint32_t *aFrecency,
                         const uint32_t *aExpirationTime)
     : mHandle(aHandle)
     , mHasFrecency(false)
@@ -3484,38 +3484,37 @@ CacheFileIOManager::FindTrashDirToRemove
   // trash directories next time.
   mFailedTrashDirs.Clear();
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 // static
 nsresult
 CacheFileIOManager::InitIndexEntry(CacheFileHandle *aHandle,
-                                   uint32_t         aAppId,
+                                   OriginAttrsHash  aOriginAttrsHash,
                                    bool             aAnonymous,
-                                   bool             aInIsolatedMozBrowser,
                                    bool             aPinning)
 {
-  LOG(("CacheFileIOManager::InitIndexEntry() [handle=%p, appId=%u, anonymous=%d"
-       ", inIsolatedMozBrowser=%d, pinned=%d]", aHandle, aAppId, aAnonymous,
-       aInIsolatedMozBrowser, aPinning));
+  LOG(("CacheFileIOManager::InitIndexEntry() [handle=%p, originAttrsHash=%llx, "
+       "anonymous=%d, pinning=%d]", aHandle, aOriginAttrsHash, aAnonymous,
+       aPinning));
 
   nsresult rv;
   RefPtr<CacheFileIOManager> ioMan = gInstance;
 
   if (aHandle->IsClosed() || !ioMan) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   if (aHandle->IsSpecialFile()) {
     return NS_ERROR_UNEXPECTED;
   }
 
   RefPtr<InitIndexEntryEvent> ev =
-    new InitIndexEntryEvent(aHandle, aAppId, aAnonymous, aInIsolatedMozBrowser, aPinning);
+    new InitIndexEntryEvent(aHandle, aOriginAttrsHash, aAnonymous, aPinning);
   rv = ioMan->mIOThread->Dispatch(ev, aHandle->mPriority
                                   ? CacheIOThread::WRITE_PRIORITY
                                   : CacheIOThread::WRITE);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
--- a/netwerk/cache2/CacheFileIOManager.h
+++ b/netwerk/cache2/CacheFileIOManager.h
@@ -2,16 +2,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef CacheFileIOManager__h__
 #define CacheFileIOManager__h__
 
 #include "CacheIOThread.h"
 #include "CacheStorageService.h"
+#include "CacheHashUtils.h"
 #include "nsIEventTarget.h"
 #include "nsITimer.h"
 #include "nsCOMPtr.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/SHA1.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/TimeStamp.h"
 #include "nsTArray.h"
@@ -325,19 +326,18 @@ public:
                              const nsACString &aNewName,
                              CacheFileIOListener *aCallback);
   static nsresult EvictIfOverLimit();
   static nsresult EvictAll();
   static nsresult EvictByContext(nsILoadContextInfo *aLoadContextInfo,
                                  bool aPinning);
 
   static nsresult InitIndexEntry(CacheFileHandle *aHandle,
-                                 uint32_t         aAppId,
+                                 OriginAttrsHash  aOriginAttrsHash,
                                  bool             aAnonymous,
-                                 bool             aInIsolatedMozBrowser,
                                  bool             aPinning);
   static nsresult UpdateIndexEntry(CacheFileHandle *aHandle,
                                    const uint32_t  *aFrecency,
                                    const uint32_t  *aExpirationTime);
 
   static nsresult UpdateIndexEntry();
 
   enum EEnumerateMode {
--- a/netwerk/cache2/CacheHashUtils.cpp
+++ b/netwerk/cache2/CacheHashUtils.cpp
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CacheHashUtils.h"
 
+#include "mozilla/BasePrincipal.h"
 #include "plstr.h"
 
 namespace mozilla {
 namespace net {
 
 /**
  *  CacheHash::Hash(const char * key, uint32_t initval)
  *
@@ -182,10 +183,24 @@ CacheHash::GetHash()
 
 CacheHash::Hash16_t
 CacheHash::GetHash16()
 {
   Hash32_t hash = GetHash();
   return (hash & 0xFFFF);
 }
 
+OriginAttrsHash
+GetOriginAttrsHash(const mozilla::OriginAttributes &aOA)
+{
+  nsAutoCString suffix;
+  aOA.CreateSuffix(suffix);
+
+  SHA1Sum sum;
+  SHA1Sum::Hash hash;
+  sum.update(suffix.BeginReading(), suffix.Length());
+  sum.finish(hash);
+
+  return BigEndian::readUint64(&hash);
+}
+
 } // namespace net
 } // namespace mozilla
--- a/netwerk/cache2/CacheHashUtils.h
+++ b/netwerk/cache2/CacheHashUtils.h
@@ -16,16 +16,19 @@
     PR_htonl((reinterpret_cast<const uint32_t *>(x))[2]), \
     PR_htonl((reinterpret_cast<const uint32_t *>(x))[3]), \
     PR_htonl((reinterpret_cast<const uint32_t *>(x))[4])
 
 #define SHA1STRING(x) \
     (nsPrintfCString("%08x%08x%08x%08x%08x", LOGSHA1(x)).get())
 
 namespace mozilla {
+
+class OriginAttributes;
+
 namespace net {
 
 class CacheHash : public nsISupports
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
 
   typedef uint16_t Hash16_t;
@@ -49,13 +52,16 @@ private:
   uint32_t mA, mB, mC;
   uint8_t  mPos;
   uint32_t mBuf;
   uint8_t  mBufPos;
   uint32_t mLength;
   bool     mFinalized;
 };
 
+typedef uint64_t OriginAttrsHash;
+
+OriginAttrsHash GetOriginAttrsHash(const mozilla::OriginAttributes &aOA);
 
 } // namespace net
 } // namespace mozilla
 
 #endif
--- a/netwerk/cache2/CacheIndex.cpp
+++ b/netwerk/cache2/CacheIndex.cpp
@@ -22,17 +22,17 @@
 #include <algorithm>
 #include "mozilla/Telemetry.h"
 #include "mozilla/Unused.h"
 
 
 #define kMinUnwrittenChanges   300
 #define kMinDumpInterval       20000 // in milliseconds
 #define kMaxBufSize            16384
-#define kIndexVersion          0x00000001
+#define kIndexVersion          0x00000002
 #define kUpdateIndexStartDelay 50000 // in milliseconds
 
 #define INDEX_NAME      "index"
 #define TEMP_INDEX_NAME "index.tmp"
 #define JOURNAL_NAME    "index.log"
 
 namespace mozilla {
 namespace net {
@@ -704,24 +704,23 @@ CacheIndex::EnsureEntryExists(const SHA1
   index->WriteIndexToDiskIfNeeded();
 
   return NS_OK;
 }
 
 // static
 nsresult
 CacheIndex::InitEntry(const SHA1Sum::Hash *aHash,
-                      uint32_t             aAppId,
+                      OriginAttrsHash      aOriginAttrsHash,
                       bool                 aAnonymous,
-                      bool                 aInIsolatedMozBrowser,
                       bool                 aPinned)
 {
-  LOG(("CacheIndex::InitEntry() [hash=%08x%08x%08x%08x%08x, appId=%u, "
-       "anonymous=%d, inIsolatedMozBrowser=%d, pinned=%d]", LOGSHA1(aHash),
-       aAppId, aAnonymous, aInIsolatedMozBrowser, aPinned));
+  LOG(("CacheIndex::InitEntry() [hash=%08x%08x%08x%08x%08x, "
+       "originAttrsHash=%llx, anonymous=%d, pinned=%d]", LOGSHA1(aHash),
+       aOriginAttrsHash, aAnonymous, aPinned));
 
   MOZ_ASSERT(CacheFileIOManager::IsOnIOThread());
 
   StaticMutexAutoLock lock(sLock);
 
   RefPtr<CacheIndex> index = gInstance;
 
   if (!index) {
@@ -744,17 +743,17 @@ CacheIndex::InitEntry(const SHA1Sum::Has
     }
 
     if (index->mState == READY || index->mState == UPDATING ||
         index->mState == BUILDING) {
       MOZ_ASSERT(index->mPendingUpdates.Count() == 0);
       MOZ_ASSERT(entry);
       MOZ_ASSERT(entry->IsFresh());
 
-      if (IsCollision(entry, aAppId, aAnonymous, aInIsolatedMozBrowser)) {
+      if (IsCollision(entry, aOriginAttrsHash, aAnonymous)) {
         index->mIndexNeedsUpdate = true; // TODO Does this really help in case of collision?
         reinitEntry = true;
       } else {
         if (entry->IsInitialized()) {
           return NS_OK;
         }
       }
     } else {
@@ -762,28 +761,28 @@ CacheIndex::InitEntry(const SHA1Sum::Has
       DebugOnly<bool> removed = updated && updated->IsRemoved();
 
       MOZ_ASSERT(updated || !removed);
       MOZ_ASSERT(updated || entry);
 
       if (updated) {
         MOZ_ASSERT(updated->IsFresh());
 
-        if (IsCollision(updated, aAppId, aAnonymous, aInIsolatedMozBrowser)) {
+        if (IsCollision(updated, aOriginAttrsHash, aAnonymous)) {
           index->mIndexNeedsUpdate = true;
           reinitEntry = true;
         } else {
           if (updated->IsInitialized()) {
             return NS_OK;
           }
         }
       } else {
         MOZ_ASSERT(entry->IsFresh());
 
-        if (IsCollision(entry, aAppId, aAnonymous, aInIsolatedMozBrowser)) {
+        if (IsCollision(entry, aOriginAttrsHash, aAnonymous)) {
           index->mIndexNeedsUpdate = true;
           reinitEntry = true;
         } else {
           if (entry->IsInitialized()) {
             return NS_OK;
           }
         }
 
@@ -801,20 +800,20 @@ CacheIndex::InitEntry(const SHA1Sum::Has
         updated->MarkFresh();
       } else {
         entry->InitNew();
         entry->MarkFresh();
       }
     }
 
     if (updated) {
-      updated->Init(aAppId, aAnonymous, aInIsolatedMozBrowser, aPinned);
+      updated->Init(aOriginAttrsHash, aAnonymous, aPinned);
       updated->MarkDirty();
     } else {
-      entry->Init(aAppId, aAnonymous, aInIsolatedMozBrowser, aPinned);
+      entry->Init(aOriginAttrsHash, aAnonymous, aPinned);
       entry->MarkDirty();
     }
   }
 
   index->StartUpdatingIndexIfNeeded();
   index->WriteIndexToDiskIfNeeded();
 
   return NS_OK;
@@ -1488,32 +1487,30 @@ CacheIndex::IsIndexUsable()
   }
 
   return true;
 }
 
 // static
 bool
 CacheIndex::IsCollision(CacheIndexEntry *aEntry,
-                        uint32_t         aAppId,
-                        bool             aAnonymous,
-                        bool             aInIsolatedMozBrowser)
+                        OriginAttrsHash  aOriginAttrsHash,
+                        bool             aAnonymous)
 {
   if (!aEntry->IsInitialized()) {
     return false;
   }
 
-  if (aEntry->AppId() != aAppId || aEntry->Anonymous() != aAnonymous ||
-      aEntry->InIsolatedMozBrowser() != aInIsolatedMozBrowser) {
+  if (aEntry->Anonymous() != aAnonymous ||
+      aEntry->OriginAttrsHash() != aOriginAttrsHash) {
     LOG(("CacheIndex::IsCollision() - Collision detected for entry hash=%08x"
-         "%08x%08x%08x%08x, expected values: appId=%u, anonymous=%d, "
-         "inIsolatedMozBrowser=%d; actual values: appId=%u, anonymous=%d, "
-         "inIsolatedMozBrowser=%d]",
-         LOGSHA1(aEntry->Hash()), aAppId, aAnonymous, aInIsolatedMozBrowser,
-         aEntry->AppId(), aEntry->Anonymous(), aEntry->InIsolatedMozBrowser()));
+         "%08x%08x%08x%08x, expected values: originAttrsHash=%llx, "
+         "anonymous=%d; actual values: originAttrsHash=%llx, anonymous=%d]",
+         LOGSHA1(aEntry->Hash()), aOriginAttrsHash, aAnonymous,
+         aEntry->OriginAttrsHash(), aEntry->Anonymous()));
     return true;
   }
 
   return false;
 }
 
 // static
 bool
@@ -2652,20 +2649,18 @@ void
 CacheIndex::InitEntryFromDiskData(CacheIndexEntry *aEntry,
                                   CacheFileMetadata *aMetaData,
                                   int64_t aFileSize)
 {
   aEntry->InitNew();
   aEntry->MarkDirty();
   aEntry->MarkFresh();
 
-  // Bug 1201042 - will pass OriginAttributes directly.
-  aEntry->Init(aMetaData->OriginAttributes().mAppId,
+  aEntry->Init(GetOriginAttrsHash(aMetaData->OriginAttributes()),
                aMetaData->IsAnonymous(),
-               aMetaData->OriginAttributes().mInIsolatedMozBrowser,
                aMetaData->Pinned());
 
   uint32_t expirationTime;
   aMetaData->GetExpirationTime(&expirationTime);
   aEntry->SetExpirationTime(expirationTime);
 
   uint32_t frecency;
   aMetaData->GetFrecency(&frecency);
--- a/netwerk/cache2/CacheIndex.h
+++ b/netwerk/cache2/CacheIndex.h
@@ -52,37 +52,37 @@ typedef struct {
   // We set this flag as soon as possible after parsing index during startup
   // and clean it after we write journal to disk during shutdown. We ignore the
   // journal and start update process whenever this flag is set during index
   // parsing.
   uint32_t mIsDirty;
 } CacheIndexHeader;
 
 struct CacheIndexRecord {
-  SHA1Sum::Hash mHash;
-  uint32_t      mFrecency;
-  uint32_t      mExpirationTime;
-  uint32_t      mAppId;
+  SHA1Sum::Hash   mHash;
+  uint32_t        mFrecency;
+  uint32_t        mExpirationTime;
+  OriginAttrsHash mOriginAttrsHash;
 
   /*
    *    1000 0000 0000 0000 0000 0000 0000 0000 : initialized
    *    0100 0000 0000 0000 0000 0000 0000 0000 : anonymous
-   *    0010 0000 0000 0000 0000 0000 0000 0000 : inIsolatedMozBrowser
-   *    0001 0000 0000 0000 0000 0000 0000 0000 : removed
-   *    0000 1000 0000 0000 0000 0000 0000 0000 : dirty
-   *    0000 0100 0000 0000 0000 0000 0000 0000 : fresh
+   *    0010 0000 0000 0000 0000 0000 0000 0000 : removed
+   *    0001 0000 0000 0000 0000 0000 0000 0000 : dirty
+   *    0000 1000 0000 0000 0000 0000 0000 0000 : fresh
+   *    0000 0100 0000 0000 0000 0000 0000 0000 : pinned
    *    0000 0011 0000 0000 0000 0000 0000 0000 : reserved
    *    0000 0000 1111 1111 1111 1111 1111 1111 : file size (in kB)
    */
   uint32_t      mFlags;
 
   CacheIndexRecord()
     : mFrecency(0)
     , mExpirationTime(nsICacheEntry::NO_EXPIRATION_TIME)
-    , mAppId(nsILoadContextInfo::NO_APP_ID)
+    , mOriginAttrsHash(0)
     , mFlags(0)
   {}
 };
 
 class CacheIndexEntry : public PLDHashEntryHdr
 {
 public:
   typedef const SHA1Sum::Hash& KeyType;
@@ -131,60 +131,54 @@ public:
   }
 
   CacheIndexEntry& operator=(const CacheIndexEntry& aOther)
   {
     MOZ_ASSERT(memcmp(&mRec->mHash, &aOther.mRec->mHash,
                sizeof(SHA1Sum::Hash)) == 0);
     mRec->mFrecency = aOther.mRec->mFrecency;
     mRec->mExpirationTime = aOther.mRec->mExpirationTime;
-    mRec->mAppId = aOther.mRec->mAppId;
+    mRec->mOriginAttrsHash = aOther.mRec->mOriginAttrsHash;
     mRec->mFlags = aOther.mRec->mFlags;
     return *this;
   }
 
   void InitNew()
   {
     mRec->mFrecency = 0;
     mRec->mExpirationTime = nsICacheEntry::NO_EXPIRATION_TIME;
-    mRec->mAppId = nsILoadContextInfo::NO_APP_ID;
+    mRec->mOriginAttrsHash = 0;
     mRec->mFlags = 0;
   }
 
-  void Init(uint32_t aAppId, bool aAnonymous, bool aInIsolatedMozBrowser, bool aPinned)
+  void Init(OriginAttrsHash aOriginAttrsHash, bool aAnonymous, bool aPinned)
   {
     MOZ_ASSERT(mRec->mFrecency == 0);
     MOZ_ASSERT(mRec->mExpirationTime == nsICacheEntry::NO_EXPIRATION_TIME);
-    MOZ_ASSERT(mRec->mAppId == nsILoadContextInfo::NO_APP_ID);
+    MOZ_ASSERT(mRec->mOriginAttrsHash == 0);
     // When we init the entry it must be fresh and may be dirty
     MOZ_ASSERT((mRec->mFlags & ~kDirtyMask) == kFreshMask);
 
-    mRec->mAppId = aAppId;
+    mRec->mOriginAttrsHash = aOriginAttrsHash;
     mRec->mFlags |= kInitializedMask;
     if (aAnonymous) {
       mRec->mFlags |= kAnonymousMask;
     }
-    if (aInIsolatedMozBrowser) {
-      mRec->mFlags |= kInIsolatedMozBrowserMask;
-    }
     if (aPinned) {
       mRec->mFlags |= kPinnedMask;
     }
   }
 
   const SHA1Sum::Hash * Hash() const { return &mRec->mHash; }
 
   bool IsInitialized() const { return !!(mRec->mFlags & kInitializedMask); }
 
-  uint32_t AppId() const { return mRec->mAppId; }
-  bool     Anonymous() const { return !!(mRec->mFlags & kAnonymousMask); }
-  bool     InIsolatedMozBrowser() const
-  {
-    return !!(mRec->mFlags & kInIsolatedMozBrowserMask);
-  }
+  mozilla::net::OriginAttrsHash OriginAttrsHash() const { return mRec->mOriginAttrsHash; }
+
+  bool Anonymous() const { return !!(mRec->mFlags & kAnonymousMask); }
 
   bool IsRemoved() const { return !!(mRec->mFlags & kRemovedMask); }
   void MarkRemoved() { mRec->mFlags |= kRemovedMask; }
 
   bool IsDirty() const { return !!(mRec->mFlags & kDirtyMask); }
   void MarkDirty() { mRec->mFlags |= kDirtyMask; }
   void ClearDirty() { mRec->mFlags &= ~kDirtyMask; }
 
@@ -237,50 +231,48 @@ public:
     dst->mFlags &= ~kDirtyMask;
     dst->mFlags &= ~kFreshMask;
 
 #if defined(IS_LITTLE_ENDIAN)
     // Data in the buffer are in machine byte order and we want them in network
     // byte order.
     NetworkEndian::writeUint32(&dst->mFrecency, dst->mFrecency);
     NetworkEndian::writeUint32(&dst->mExpirationTime, dst->mExpirationTime);
-    NetworkEndian::writeUint32(&dst->mAppId, dst->mAppId);
+    NetworkEndian::writeUint64(&dst->mOriginAttrsHash, dst->mOriginAttrsHash);
     NetworkEndian::writeUint32(&dst->mFlags, dst->mFlags);
 #endif
   }
 
   void ReadFromBuf(void *aBuf)
   {
     CacheIndexRecord *src= reinterpret_cast<CacheIndexRecord *>(aBuf);
     MOZ_ASSERT(memcmp(&mRec->mHash, &src->mHash,
                sizeof(SHA1Sum::Hash)) == 0);
 
     mRec->mFrecency = NetworkEndian::readUint32(&src->mFrecency);
     mRec->mExpirationTime = NetworkEndian::readUint32(&src->mExpirationTime);
-    mRec->mAppId = NetworkEndian::readUint32(&src->mAppId);
+    mRec->mOriginAttrsHash = NetworkEndian::readUint64(&src->mOriginAttrsHash);
     mRec->mFlags = NetworkEndian::readUint32(&src->mFlags);
   }
 
   void Log() const {
-    LOG(("CacheIndexEntry::Log() [this=%p, hash=%08x%08x%08x%08x%08x, "
-         "fresh=%u, initialized=%u, removed=%u, dirty=%u, anonymous=%u, "
-         "inIsolatedMozBrowser=%u, appId=%u, frecency=%u, expirationTime=%u, "
-         "size=%u]",
+    LOG(("CacheIndexEntry::Log() [this=%p, hash=%08x%08x%08x%08x%08x, fresh=%u,"
+         " initialized=%u, removed=%u, dirty=%u, anonymous=%u, "
+         "originAttrsHash=%llx, frecency=%u, expirationTime=%u, size=%u]",
          this, LOGSHA1(mRec->mHash), IsFresh(), IsInitialized(), IsRemoved(),
-         IsDirty(), Anonymous(), InIsolatedMozBrowser(), AppId(), GetFrecency(),
+         IsDirty(), Anonymous(), OriginAttrsHash(), GetFrecency(),
          GetExpirationTime(), GetFileSize()));
   }
 
   static bool RecordMatchesLoadContextInfo(CacheIndexRecord *aRec,
                                            nsILoadContextInfo *aInfo)
   {
     if (!aInfo->IsPrivate() &&
-        aInfo->OriginAttributesPtr()->mAppId == aRec->mAppId &&
-        aInfo->IsAnonymous() == !!(aRec->mFlags & kAnonymousMask) &&
-        aInfo->OriginAttributesPtr()->mInIsolatedMozBrowser == !!(aRec->mFlags & kInIsolatedMozBrowserMask)) {
+        GetOriginAttrsHash(*aInfo->OriginAttributesPtr()) == aRec->mOriginAttrsHash &&
+        aInfo->IsAnonymous() == !!(aRec->mFlags & kAnonymousMask)) {
       return true;
     }
 
     return false;
   }
 
   // Memory reporting
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const
@@ -295,35 +287,34 @@ public:
 
 private:
   friend class CacheIndexEntryUpdate;
   friend class CacheIndex;
   friend class CacheIndexEntryAutoManage;
 
   static const uint32_t kInitializedMask = 0x80000000;
   static const uint32_t kAnonymousMask   = 0x40000000;
-  static const uint32_t kInIsolatedMozBrowserMask   = 0x20000000;
 
   // This flag is set when the entry was removed. We need to keep this
   // information in memory until we write the index file.
-  static const uint32_t kRemovedMask     = 0x10000000;
+  static const uint32_t kRemovedMask     = 0x20000000;
 
   // This flag is set when the information in memory is not in sync with the
   // information in index file on disk.
-  static const uint32_t kDirtyMask       = 0x08000000;
+  static const uint32_t kDirtyMask       = 0x10000000;
 
   // This flag is set when the information about the entry is fresh, i.e.
   // we've created or opened this entry during this session, or we've seen
   // this entry during update or build process.
-  static const uint32_t kFreshMask       = 0x04000000;
+  static const uint32_t kFreshMask       = 0x08000000;
 
   // Indicates a pinned entry.
-  static const uint32_t kPinnedMask      = 0x02000000;
+  static const uint32_t kPinnedMask      = 0x04000000;
 
-  static const uint32_t kReservedMask    = 0x01000000;
+  static const uint32_t kReservedMask    = 0x03000000;
 
   // FileSize in kilobytes
   static const uint32_t kFileSizeMask    = 0x00FFFFFF;
 
   nsAutoPtr<CacheIndexRecord> mRec;
 };
 
 class CacheIndexEntryUpdate : public CacheIndexEntry
@@ -380,17 +371,17 @@ public:
     MOZ_ASSERT(memcmp(&mRec->mHash, &aDst->mRec->mHash,
                sizeof(SHA1Sum::Hash)) == 0);
     if (mUpdateFlags & kFrecencyUpdatedMask) {
       aDst->mRec->mFrecency = mRec->mFrecency;
     }
     if (mUpdateFlags & kExpirationUpdatedMask) {
       aDst->mRec->mExpirationTime = mRec->mExpirationTime;
     }
-    aDst->mRec->mAppId = mRec->mAppId;
+    aDst->mRec->mOriginAttrsHash = mRec->mOriginAttrsHash;
     if (mUpdateFlags & kFileSizeUpdatedMask) {
       aDst->mRec->mFlags = mRec->mFlags;
     } else {
       // Copy all flags except file size.
       aDst->mRec->mFlags &= kFileSizeMask;
       aDst->mRec->mFlags |= (mRec->mFlags & ~kFileSizeMask);
     }
   }
@@ -620,19 +611,18 @@ public:
   // created. Like in case of AddEntry(), either InitEntry() or RemoveEntry()
   // must be called on the entry, since the entry is not initizlized if the
   // index is outdated.
   static nsresult EnsureEntryExists(const SHA1Sum::Hash *aHash);
 
   // Initialize the entry. It MUST be present in index. Call to AddEntry() or
   // EnsureEntryExists() must precede the call to this method.
   static nsresult InitEntry(const SHA1Sum::Hash *aHash,
-                            uint32_t             aAppId,
+                            OriginAttrsHash      aOriginAttrsHash,
                             bool                 aAnonymous,
-                            bool                 aInIsolatedMozBrowser,
                             bool                 aPinned);
 
   // Remove entry from index. The entry should be present in index.
   static nsresult RemoveEntry(const SHA1Sum::Hash *aHash);
 
   // Update some information in entry. The entry MUST be present in index and
   // MUST be initialized. Call to AddEntry() or EnsureEntryExists() and to
   // InitEntry() must precede the call to this method.
@@ -721,24 +711,23 @@ private:
   NS_IMETHOD OnFileRenamed(CacheFileHandle *aHandle, nsresult aResult) override;
 
   nsresult InitInternal(nsIFile *aCacheDirectory);
   void     PreShutdownInternal();
 
   // This method returns false when index is not initialized or is shut down.
   bool IsIndexUsable();
 
-  // This method checks whether the entry has the same values of appId,
-  // isAnonymous and isInBrowser. We don't expect to find a collision since
-  // these values are part of the key that we hash and we use a strong hash
-  // function.
+  // This method checks whether the entry has the same values of
+  // originAttributes and isAnonymous. We don't expect to find a collision
+  // since these values are part of the key that we hash and we use a strong
+  // hash function.
   static bool IsCollision(CacheIndexEntry *aEntry,
-                          uint32_t         aAppId,
-                          bool             aAnonymous,
-                          bool             aInIsolatedMozBrowser);
+                          OriginAttrsHash  aOriginAttrsHash,
+                          bool             aAnonymous);
 
   // Checks whether any of the information about the entry has changed.
   static bool HasEntryChanged(CacheIndexEntry *aEntry,
                               const uint32_t  *aFrecency,
                               const uint32_t  *aExpirationTime,
                               const uint32_t  *aSize);
 
   // Merge all pending operations from mPendingUpdates into mIndex.