Bug 1546761 - Consolidate IPC calls to nsISHistory inside of nsDocShell::OnNewURI, r=peterv, r=nika for adding sync IPC messages
authorAnny Gakhokidze <agakhokidze@mozilla.com>
Tue, 07 May 2019 15:23:08 -0400
changeset 500498 ed6458f398494a144429b694e5960dac94d0751c
parent 500497 82c30a27597ec427282fcfd0285dec4aa23de362
child 500499 0f25a3d302734de4abeaf80a692987fc2c6df124
push id114165
push userpvanderbeken@mozilla.com
push dateWed, 06 Nov 2019 09:18:40 +0000
treeherdermozilla-inbound@db1ddab2985d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv, nika
bugs1546761
milestone72.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 1546761 - Consolidate IPC calls to nsISHistory inside of nsDocShell::OnNewURI, r=peterv, r=nika for adding sync IPC messages Inside of nsDocShell::OnNewURI there are 4 sync IPC calls to nsSHistory that can be replaced with 1 sync IPC call by adding a new method EnsureCorrectEntryAtCurrIndex to nsSHistory. Differential Revision: https://phabricator.services.mozilla.com/D31539
docshell/base/nsDocShell.cpp
docshell/shistory/PSHistory.ipdl
docshell/shistory/SHistoryChild.cpp
docshell/shistory/SHistoryParent.cpp
docshell/shistory/SHistoryParent.h
docshell/shistory/nsISHistory.idl
docshell/shistory/nsSHistory.cpp
ipc/ipdl/sync-messages.ini
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -10850,26 +10850,18 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, 
        */
       (void)AddToSessionHistory(aURI, aChannel, aTriggeringPrincipal,
                                 aPrincipalToInherit, aStoragePrincipalToInherit,
                                 aCsp, aCloneSHChildren, getter_AddRefs(mLSHE));
     }
   } else if (mSessionHistory && mLSHE && mURIResultedInDocument) {
     // Even if we don't add anything to SHistory, ensure the current index
     // points to the same SHEntry as our mLSHE.
-    int32_t index = mSessionHistory->LegacySHistory()->GetRequestedIndex();
-    if (index == -1) {
-      index = mSessionHistory->Index();
-    }
-    nsCOMPtr<nsISHEntry> currentSH;
-    mSessionHistory->LegacySHistory()->GetEntryAtIndex(
-        index, getter_AddRefs(currentSH));
-    if (currentSH != mLSHE) {
-      mSessionHistory->LegacySHistory()->ReplaceEntry(index, mLSHE);
-    }
+
+    mSessionHistory->LegacySHistory()->EnsureCorrectEntryAtCurrIndex(mLSHE);
   }
 
   // If this is a POST request, we do not want to include this in global
   // history.
   if (updateGHistory && aAddToGlobalHistory && !ChannelIsPost(aChannel)) {
     nsCOMPtr<nsIURI> previousURI;
     uint32_t previousFlags = 0;
 
--- a/docshell/shistory/PSHistory.ipdl
+++ b/docshell/shistory/PSHistory.ipdl
@@ -51,14 +51,15 @@ parent:
   sync EvictAllContentViewers();
   sync RemoveDynEntries(int32_t index, PSHEntry entry);
   sync RemoveEntries(nsID[] ids, int32_t index) returns (bool didRemove);
   sync RemoveFrameEntries(PSHEntry entry);
   sync Reload(uint32_t reloadFlags) returns (LoadSHEntryResult load);
   sync GetAllEntries() returns (MaybeNewPSHEntry[] entries);
   sync FindEntryForBFCache(uint64_t sharedID, bool includeCurrentEntry) returns (MaybeNewPSHEntry entries, int32_t startIndex);
   sync Evict(PSHEntry[] entry);
+  sync EnsureCorrectEntryAtCurrIndex(PSHEntry entry);
 
   async __delete__();
 };
 
 } // namespace dom
 } // namespace mozilla
--- a/docshell/shistory/SHistoryChild.cpp
+++ b/docshell/shistory/SHistoryChild.cpp
@@ -300,16 +300,21 @@ SHistoryChild::RemoveFromExpirationTrack
 }
 
 NS_IMETHODIMP_(void)
 SHistoryChild::RemoveDynEntries(int32_t aIndex, nsISHEntry* aEntry) {
   SendRemoveDynEntries(aIndex, static_cast<SHEntryChild*>(aEntry));
 }
 
 NS_IMETHODIMP_(void)
+SHistoryChild::EnsureCorrectEntryAtCurrIndex(nsISHEntry* aEntry) {
+  SendEnsureCorrectEntryAtCurrIndex(static_cast<SHEntryChild*>(aEntry));
+}
+
+NS_IMETHODIMP_(void)
 SHistoryChild::RemoveDynEntriesForBFCacheEntry(nsIBFCacheEntry* aBFEntry) {
   MaybeNewPSHEntry entry;
   int32_t index;
   if (!SendFindEntryForBFCache(
           static_cast<SHEntryChildShared*>(aBFEntry)->GetID(), true, &entry,
           &index)) {
     return;
   }
--- a/docshell/shistory/SHistoryParent.cpp
+++ b/docshell/shistory/SHistoryParent.cpp
@@ -135,16 +135,22 @@ bool SHistoryParent::RecvEvictAllContent
 bool SHistoryParent::RecvRemoveDynEntries(int32_t aIndex,
                                           PSHEntryParent* aEntry) {
   MOZ_ASSERT(Manager() == aEntry->Manager());
   mHistory->RemoveDynEntries(aIndex,
                              static_cast<SHEntryParent*>(aEntry)->mEntry);
   return true;
 }
 
+bool SHistoryParent::RecvEnsureCorrectEntryAtCurrIndex(PSHEntryParent* aEntry) {
+  mHistory->EnsureCorrectEntryAtCurrIndex(
+      static_cast<SHEntryParent*>(aEntry)->mEntry);
+  return true;
+}
+
 bool SHistoryParent::RecvRemoveEntries(nsTArray<nsID>&& aIds, int32_t aIndex,
                                        bool* aDidRemove) {
   mHistory->RemoveEntries(aIds, aIndex, aDidRemove);
   return true;
 }
 
 bool SHistoryParent::RecvRemoveFrameEntries(PSHEntryParent* aEntry) {
   mHistory->RemoveFrameEntries(
--- a/docshell/shistory/SHistoryParent.h
+++ b/docshell/shistory/SHistoryParent.h
@@ -74,16 +74,17 @@ class SHistoryParent final : public PSHi
                          bool* aDidRemove);
   bool RecvRemoveFrameEntries(PSHEntryParent* aEntry);
   bool RecvReload(const uint32_t& aReloadFlags, LoadSHEntryResult* aLoadResult);
   bool RecvGetAllEntries(nsTArray<MaybeNewPSHEntry>* aEntries);
   bool RecvFindEntryForBFCache(const uint64_t& aSharedID,
                                const bool& aIncludeCurrentEntry,
                                MaybeNewPSHEntry* aEntry, int32_t* aIndex);
   bool RecvEvict(nsTArray<PSHEntryParent*>&& aEntries);
+  bool RecvEnsureCorrectEntryAtCurrIndex(PSHEntryParent* aEntry);
 
   RefPtr<CanonicalBrowsingContext> mContext;
   RefPtr<LegacySHistory> mHistory;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
--- a/docshell/shistory/nsISHistory.idl
+++ b/docshell/shistory/nsISHistory.idl
@@ -255,9 +255,11 @@ interface nsISHistory: nsISupports
    * @param aEntry           Children docshellID's will be collected from 
    *                         this entry and passed to RemoveEntries as aIDs.
   */
   [noscript, notxpcom]
   void RemoveFrameEntries(in nsISHEntry aEntry);
 
   [noscript]
   void Reload(in unsigned long aReloadFlags);
+
+  [notxpcom] void EnsureCorrectEntryAtCurrIndex(in nsISHEntry aEntry);
 };
--- a/docshell/shistory/nsSHistory.cpp
+++ b/docshell/shistory/nsSHistory.cpp
@@ -1353,16 +1353,25 @@ NS_IMETHODIMP
 nsSHistory::GotoIndex(int32_t aIndex) {
   LoadEntryResult loadResult;
   nsresult rv = GotoIndex(aIndex, loadResult);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return LoadURI(loadResult);
 }
 
+NS_IMETHODIMP_(void)
+nsSHistory::EnsureCorrectEntryAtCurrIndex(nsISHEntry* aEntry) {
+  int index = mRequestedIndex == -1 ? mIndex : mRequestedIndex;
+  MOZ_ASSERT(mIndex > -1);
+  if (mEntries[index] != aEntry) {
+    ReplaceEntry(index, aEntry);
+  }
+}
+
 nsresult nsSHistory::GotoIndex(int32_t aIndex, LoadEntryResult& aLoadResult) {
   return LoadEntry(aIndex, LOAD_HISTORY, HIST_CMD_GOTOINDEX, aLoadResult);
 }
 
 nsresult nsSHistory::LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType,
                                            uint32_t aHistCmd,
                                            LoadEntryResult& aLoadResult) {
   mRequestedIndex = -1;
--- a/ipc/ipdl/sync-messages.ini
+++ b/ipc/ipdl/sync-messages.ini
@@ -847,16 +847,18 @@ description = Standing up Fission
 [PSHistory::Reload]
 description = Standing up Fission
 [PSHistory::GetAllEntries]
 description = Standing up Fission
 [PSHistory::FindEntryForBFCache]
 description = Standing up Fission
 [PSHistory::Evict]
 description = Standing up Fission
+[PSHistory::EnsureCorrectEntryAtCurrIndex]
+description = Standing up Fission
 [PContent::PSHEntry]
 description = Standing up Fission
 [PSHEntry::GetURI]
 description = Standing up Fission
 [PSHEntry::SetURI]
 description = Standing up Fission
 [PSHEntry::GetOriginalURI]
 description = Standing up Fission