From c43df3d447e611bc5a4fdfd8aa9db990ab36e14d Mon Sep 17 00:00:00 2001 From: Anny Gakhokidze Date: Thu, 18 Apr 2019 15:18:00 -0400 Subject: [PATCH] Bug 1545474 - Part 1: Consolidate sync IPC calls inside of nsDocShell::UpdateURLAndHistory, r=peterv, r=nika for adding sync IPC messages Inside of nsDocShell::UpdateURLAndHistory, there are 4 sync IPC calls to nsSHistory plus 1 static call, which contains at least one nsSHEntry::GetParent sync IPC call. All of these calls can be moved inside of a new method EvictContentViewersOrReplaceEntry on nsSHEntry, resulting in just 1 sync IPC call. Differential Revision: https://phabricator.services.mozilla.com/D32729 --HG-- extra : rebase_source : ad09a9061cd6fe8eb6796b2809ea191aceb3ac73 extra : source : 2cd5cd24763ff320719aedb2142a79822efd6de4 extra : histedit_source : fdc4f80cfd8807e46c2dc02e6ab82f2bd3acc391 --- docshell/base/nsDocShell.cpp | 15 ++------------- docshell/shistory/PSHistory.ipdl | 1 + docshell/shistory/SHistoryChild.cpp | 6 ++++++ docshell/shistory/SHistoryParent.cpp | 9 +++++++++ docshell/shistory/SHistoryParent.h | 1 + docshell/shistory/nsISHistory.idl | 2 ++ docshell/shistory/nsSHistory.cpp | 19 +++++++++++++++++++ ipc/ipdl/sync-messages.ini | 2 ++ 8 files changed, 42 insertions(+), 13 deletions(-) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 787398917e9e..7b7671413a28 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -11181,19 +11181,8 @@ nsresult nsDocShell::UpdateURLAndHistory(Document* aDocument, nsIURI* aNewURI, // subtree that disables session history. RefPtr rootSH = GetRootSessionHistory(); if (rootSH) { - if (!aReplace) { - int32_t curIndex = rootSH->Index(); - if (curIndex > -1) { - rootSH->LegacySHistory()->EvictOutOfRangeContentViewers(curIndex); - } - } else { - nsCOMPtr rootSHEntry = nsSHistory::GetRootSHEntry(newSHEntry); - - int32_t index = rootSH->LegacySHistory()->GetIndexOfEntry(rootSHEntry); - if (index > -1) { - rootSH->LegacySHistory()->ReplaceEntry(index, rootSHEntry); - } - } + rootSH->LegacySHistory()->EvictContentViewersOrReplaceEntry(newSHEntry, + aReplace); } // Step 4: If the document's URI changed, update document's URI and update diff --git a/docshell/shistory/PSHistory.ipdl b/docshell/shistory/PSHistory.ipdl index 8a371aecf90b..a7cbe5f4c7a0 100644 --- a/docshell/shistory/PSHistory.ipdl +++ b/docshell/shistory/PSHistory.ipdl @@ -57,6 +57,7 @@ parent: sync FindEntryForBFCache(uint64_t sharedID, bool includeCurrentEntry) returns (MaybeNewPSHEntry entries, int32_t startIndex); sync Evict(PSHEntry[] entry); sync EnsureCorrectEntryAtCurrIndex(PSHEntry entry); + sync EvictContentViewersOrReplaceEntry(nullable PSHEntry newSHEntry, bool replace); async __delete__(); }; diff --git a/docshell/shistory/SHistoryChild.cpp b/docshell/shistory/SHistoryChild.cpp index cfe24bc429a0..626280179328 100644 --- a/docshell/shistory/SHistoryChild.cpp +++ b/docshell/shistory/SHistoryChild.cpp @@ -282,6 +282,12 @@ SHistoryChild::EvictAllContentViewers(void) { return NS_OK; } +NS_IMETHODIMP_(void) +SHistoryChild::EvictContentViewersOrReplaceEntry(nsISHEntry* aNewSHEntry, bool aReplace) { + SendEvictContentViewersOrReplaceEntry( + static_cast(aNewSHEntry), aReplace); +} + NS_IMETHODIMP_(void) SHistoryChild::AddToExpirationTracker(nsIBFCacheEntry* aBFEntry) { RefPtr entry = static_cast(aBFEntry); diff --git a/docshell/shistory/SHistoryParent.cpp b/docshell/shistory/SHistoryParent.cpp index 8d6b78a3cd4a..f9e3c4c218bf 100644 --- a/docshell/shistory/SHistoryParent.cpp +++ b/docshell/shistory/SHistoryParent.cpp @@ -139,6 +139,15 @@ bool SHistoryParent::RecvEvictAllContentViewers() { return NS_SUCCEEDED(mHistory->EvictAllContentViewers()); } +bool SHistoryParent::RecvEvictContentViewersOrReplaceEntry( + PSHEntryParent* aNewSHEntry, bool aReplace) { + mHistory->EvictContentViewersOrReplaceEntry( + aNewSHEntry ? static_cast(aNewSHEntry)->mEntry.get() + : nullptr, + aReplace); + return true; +} + bool SHistoryParent::RecvRemoveDynEntries(int32_t aIndex, PSHEntryParent* aEntry) { MOZ_ASSERT(Manager() == aEntry->Manager()); diff --git a/docshell/shistory/SHistoryParent.h b/docshell/shistory/SHistoryParent.h index 3b098a74884e..3156d0914b21 100644 --- a/docshell/shistory/SHistoryParent.h +++ b/docshell/shistory/SHistoryParent.h @@ -77,6 +77,7 @@ class SHistoryParent final : public PSHistoryParent { MaybeNewPSHEntry* aEntry, int32_t* aIndex); bool RecvEvict(nsTArray&& aEntries); bool RecvEnsureCorrectEntryAtCurrIndex(PSHEntryParent* aEntry); + bool RecvEvictContentViewersOrReplaceEntry(PSHEntryParent* aNewSHEntry, bool aReplace); RefPtr mContext; RefPtr mHistory; diff --git a/docshell/shistory/nsISHistory.idl b/docshell/shistory/nsISHistory.idl index a6015774affa..8f65fab30570 100644 --- a/docshell/shistory/nsISHistory.idl +++ b/docshell/shistory/nsISHistory.idl @@ -262,4 +262,6 @@ interface nsISHistory: nsISupports void Reload(in unsigned long aReloadFlags); [notxpcom] void EnsureCorrectEntryAtCurrIndex(in nsISHEntry aEntry); + + [notxpcom] void EvictContentViewersOrReplaceEntry(in nsISHEntry aNewSHEntry, in bool aReplace); }; diff --git a/docshell/shistory/nsSHistory.cpp b/docshell/shistory/nsSHistory.cpp index 435a0f0e70c9..93518c5e5d5c 100644 --- a/docshell/shistory/nsSHistory.cpp +++ b/docshell/shistory/nsSHistory.cpp @@ -799,6 +799,25 @@ nsSHistory::EvictOutOfRangeContentViewers(int32_t aIndex) { return NS_OK; } +NS_IMETHODIMP_(void) +nsSHistory::EvictContentViewersOrReplaceEntry(nsISHEntry* aNewSHEntry, + bool aReplace) { + if (!aReplace) { + int32_t curIndex; + GetIndex(&curIndex); + if (curIndex > -1) { + EvictOutOfRangeContentViewers(curIndex); + } + } else { + nsCOMPtr rootSHEntry = nsSHistory::GetRootSHEntry(aNewSHEntry); + + int32_t index = GetIndexOfEntry(rootSHEntry); + if (index > -1) { + ReplaceEntry(index, rootSHEntry); + } + } +} + NS_IMETHODIMP nsSHistory::EvictAllContentViewers() { // XXXbz we don't actually do a good job of evicting things as we should, so diff --git a/ipc/ipdl/sync-messages.ini b/ipc/ipdl/sync-messages.ini index e02f60c6a48f..d57199f9c71b 100644 --- a/ipc/ipdl/sync-messages.ini +++ b/ipc/ipdl/sync-messages.ini @@ -838,6 +838,8 @@ description = Standing up Fission description = Standing up Fission [PSHistory::EvictAllContentViewers] description = Standing up Fission +[PSHistory::EvictContentViewersOrReplaceEntry] +description = Standing up Fission [PSHistory::RemoveDynEntries] description = Standing up Fission [PSHistory::RemoveEntries]