Add a global limit to the number of cached content viewers that scales with the amount of physical memory. Patch by Marria Nazif <marria@gmail.com>. Bug 292965, r=biesi, sr=me.

git-svn-id: svn://10.0.0.236/trunk@180171 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
bryner%brianryner.com
2005-09-14 03:38:40 +00:00
parent fbaa0a2917
commit ffbf79b866
15 changed files with 494 additions and 77 deletions

View File

@@ -259,6 +259,8 @@ nsDocShell::nsDocShell():
mMarginHeight(0),
mItemType(typeContent),
mDefaultScrollbarPref(Scrollbar_Auto, Scrollbar_Auto),
mPreviousTransIndex(-1),
mLoadedTransIndex(-1),
mEditorData(nsnull),
mTreeOwner(nsnull),
mChromeEventHandler(nsnull)
@@ -1707,6 +1709,20 @@ nsDocShell::SetUseErrorPages(PRBool aUseErrorPages)
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetPreviousTransIndex(PRInt32 *aPreviousTransIndex)
{
*aPreviousTransIndex = mPreviousTransIndex;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetLoadedTransIndex(PRInt32 *aLoadedTransIndex)
{
*aLoadedTransIndex = mLoadedTransIndex;
return NS_OK;
}
//*****************************************************************************
// nsDocShell::nsIDocShellTreeItem
//*****************************************************************************
@@ -2634,6 +2650,19 @@ nsDocShell::DoAddChildSHEntry(nsISHEntry* aNewEntry, PRInt32 aChildOffset)
* for this subframe in the CloneAndReplace function.
*/
// In this case, we will end up calling AddEntry, which increases the
// current index by 1
nsCOMPtr<nsISHistory> rootSH;
GetRootSessionHistory(getter_AddRefs(rootSH));
if (rootSH) {
rootSH->GetIndex(&mPreviousTransIndex);
mLoadedTransIndex = mPreviousTransIndex + 1;
#ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n", mPreviousTransIndex,
mLoadedTransIndex);
#endif
}
nsresult rv;
nsCOMPtr<nsIDocShellHistory> parent =
do_QueryInterface(GetAsSupports(mParent), &rv);
@@ -4854,10 +4883,15 @@ nsDocShell::CanSavePresentation(PRUint32 aLoadType,
// Avoid doing the work of saving the presentation state in the case where
// the content viewer cache is disabled.
PRInt32 maxViewers = 0;
mPrefs->GetIntPref("browser.sessionhistory.max_viewers", &maxViewers);
if (maxViewers == 0)
nsCOMPtr<nsISHistory> rootSH;
GetRootSessionHistory(getter_AddRefs(rootSH));
if (rootSH) {
nsCOMPtr<nsISHistoryInternal> shistInt(do_QueryInterface(rootSH));
PRInt32 maxViewers;
shistInt->GetHistoryMaxTotalViewers(&maxViewers);
if (maxViewers == 0)
return PR_FALSE;
}
// Don't cache the content viewer if we're in a subframe and the subframe
// pref is disabled.
@@ -5210,7 +5244,13 @@ nsDocShell::RestoreFromHistory()
GetRootSessionHistory(getter_AddRefs(rootSH));
if (rootSH) {
nsCOMPtr<nsISHistoryInternal> hist = do_QueryInterface(rootSH);
rootSH->GetIndex(&mPreviousTransIndex);
hist->UpdateIndex();
rootSH->GetIndex(&mLoadedTransIndex);
#ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n", mPreviousTransIndex,
mLoadedTransIndex);
#endif
}
// Rather than call Embed(), we will retrieve the viewer from the session
@@ -5278,7 +5318,7 @@ nsDocShell::RestoreFromHistory()
if (mContentViewer) {
mContentViewer->Close(mSavingOldViewer ? mOSHE.get() : nsnull);
mContentViewer->Destroy();
viewer->SetPreviousViewer(mContentViewer);
}
mContentViewer.swap(viewer);
@@ -7213,8 +7253,15 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel,
// SH.
if (rootSH && (mLoadType & LOAD_CMD_HISTORY)) {
nsCOMPtr<nsISHistoryInternal> shInternal(do_QueryInterface(rootSH));
if (shInternal)
if (shInternal) {
rootSH->GetIndex(&mPreviousTransIndex);
shInternal->UpdateIndex();
rootSH->GetIndex(&mLoadedTransIndex);
#ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n",
mPreviousTransIndex, mLoadedTransIndex);
#endif
}
}
PRBool onLocationChangeNeeded = SetCurrentURI(aURI, aChannel,
aFireOnLocationChange);
@@ -7424,7 +7471,13 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI,
nsCOMPtr<nsISHistoryInternal>
shPrivate(do_QueryInterface(mSessionHistory));
NS_ENSURE_TRUE(shPrivate, NS_ERROR_FAILURE);
mSessionHistory->GetIndex(&mPreviousTransIndex);
rv = shPrivate->AddEntry(entry, shouldPersist);
mSessionHistory->GetIndex(&mLoadedTransIndex);
#ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n",
mPreviousTransIndex, mLoadedTransIndex);
#endif
}
}
else {