Commit b0a8f8d7 authored by Anny Gakhokidze's avatar Anny Gakhokidze
Browse files

Bug 1536471 - Consolidate calls to nsISHEntry::GetChildAt in...

Bug 1536471 - Consolidate calls to nsISHEntry::GetChildAt in nsDocShell::AddToSessionHistory by adding nsSHEntry::ClearEntry method, r=peterv, r=nika for adding sync IPC messages

Currently, nsDocShell repeatedly calls nsISHEntry::GetChildAt and
nsISHEntry::RemoveChild  in nsDocShell::AddToSessionHistory,
which results in twice as many IPC calls as the number of children
a session history entry has. Additionally, there is one extra
IPC sync call to nsISHEntry::AbandonBFCacheEntry after the loop.

With the proposed solution, there will only be 1 sync IPC call.

Differential Revision: https://phabricator.services.mozilla.com/D24978

--HG--
extra : rebase_source : ab98af417bcb28fdfcb1a115473b505fa8a70aa1
extra : source : 0270d6b952ffa1704690c777c55fcaed30125b38
extra : histedit_source : 9a031cb921ad8efa1bd96f7342e08337f3c0ca8a
parent d4a3299b
......@@ -11388,14 +11388,7 @@ nsresult nsDocShell::AddToSessionHistory(
// This is a subframe
entry = mOSHE;
if (entry) {
int32_t childCount = entry->GetChildCount();
// Remove all children of this entry
for (int32_t i = childCount - 1; i >= 0; i--) {
nsCOMPtr<nsISHEntry> child;
entry->GetChildAt(i, getter_AddRefs(child));
entry->RemoveChild(child);
}
entry->AbandonBFCacheEntry();
entry->ClearEntry();
}
}
......
......@@ -99,6 +99,7 @@ parent:
sync RemoveChild(PSHEntry childEntry) returns (nsresult result);
sync GetChildAt(int32_t index) returns (MaybeNewPSHEntry childEntry);
sync ReplaceChild(PSHEntry newChildEntry) returns (nsresult result);
sync ClearEntry(uint64_t aNewSharedID);
sync __delete__();
};
......
......@@ -798,6 +798,15 @@ SHEntryChild::ReplaceChild(nsISHEntry* aNewEntry) {
: NS_ERROR_FAILURE;
}
NS_IMETHODIMP_(void)
SHEntryChild::ClearEntry() {
// We want to call AbandonBFCacheEntry in SHEntryParent,
// hence the need for duplciating the shared entry here
RefPtr<SHEntryChildShared> shared = mShared->Duplicate();
SendClearEntry(shared->GetID());
shared.swap(mShared);
}
NS_IMETHODIMP_(void)
SHEntryChild::AddChildShell(nsIDocShellTreeItem* aShell) {
mShared->mChildShells.AppendObject(aShell);
......
......@@ -526,5 +526,11 @@ void SHEntryParent::GetOrCreate(PContentParent* aManager, nsISHEntry* aSHEntry,
}
}
bool SHEntryParent::RecvClearEntry(const uint64_t& aNewSharedID) {
mEntry->ClearEntry();
mEntry->AbandonBFCacheEntry(aNewSharedID);
return true;
}
} // namespace dom
} // namespace mozilla
......@@ -172,6 +172,7 @@ class SHEntryParent final : public PSHEntryParent {
bool RecvRemoveChild(PSHEntryParent* aChild, nsresult* aResult);
bool RecvGetChildAt(const int32_t& aIndex, MaybeNewPSHEntry* aChild);
bool RecvReplaceChild(PSHEntryParent* aNewChild, nsresult* aResult);
bool RecvClearEntry(const uint64_t& aNewSharedID);
void GetOrCreate(nsISHEntry* aSHEntry, MaybeNewPSHEntry* aResult) {
GetOrCreate(Manager(), aSHEntry, *aResult);
......
......@@ -393,5 +393,10 @@ interface nsISHEntry : nsISupports
* @throw if nothing was replaced.
*/
[noscript] void ReplaceChild(in nsISHEntry aNewChild);
/**
* Remove all children of this entry and call abandonBFCacheEntry.
*/
[notxpcom] void ClearEntry();
};
......@@ -755,6 +755,16 @@ nsSHEntry::ReplaceChild(nsISHEntry* aNewEntry) {
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP_(void) nsSHEntry::ClearEntry() {
int32_t childCount = GetChildCount();
// Remove all children of this entry
for (int32_t i = childCount - 1; i >= 0; i--) {
nsCOMPtr<nsISHEntry> child;
GetChildAt(i, getter_AddRefs(child));
RemoveChild(child);
}
}
NS_IMETHODIMP_(void)
nsSHEntry::AddChildShell(nsIDocShellTreeItem* aShell) {
MOZ_CRASH(
......
......@@ -1000,6 +1000,8 @@ description = Standing up Fission
description = Standing up Fission
[PSHEntry::ReplaceChild]
description = Standing up Fission
[PSHEntry::ClearEntry]
description = Standing up Fission
[PSHEntry::__delete__]
description = Standing up Fission
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment