From 18136e92bdffbdda5b3df856c454437fd778e1b4 Mon Sep 17 00:00:00 2001 From: Jon Hylands Date: Tue, 16 Apr 2013 15:34:11 +0200 Subject: [PATCH] Bug 853632 - Cache own and containing apps in TabContext. r=jlebar --- dom/ipc/TabContext.cpp | 26 ++++++++++++++++++++++++++ dom/ipc/TabContext.h | 20 +++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/dom/ipc/TabContext.cpp b/dom/ipc/TabContext.cpp index f0975f5bf87..4f5e44f5aa3 100644 --- a/dom/ipc/TabContext.cpp +++ b/dom/ipc/TabContext.cpp @@ -294,6 +294,32 @@ TabContext::GetAppForId(uint32_t aAppId) const return nullptr; } + // This application caching is needed to avoid numerous unecessary application clones. + // See Bug 853632 for details. + + if (aAppId == mOwnAppId) { + if (!mOwnApp) { + mOwnApp = GetAppForIdNoCache(aAppId); + } + nsCOMPtr ownApp = mOwnApp; + return ownApp.forget(); + } + + if (aAppId == mContainingAppId) { + if (!mContainingApp) { + mContainingApp = GetAppForIdNoCache(mContainingAppId); + } + nsCOMPtr containingApp = mContainingApp; + return containingApp.forget(); + } + // We need the fallthrough here because mOwnAppId/mContainingAppId aren't always + // set before calling GetAppForId(). + return GetAppForIdNoCache(aAppId); +} + +already_AddRefed +TabContext::GetAppForIdNoCache(uint32_t aAppId) const +{ nsCOMPtr appsService = do_GetService(APPS_SERVICE_CONTRACTID); NS_ENSURE_TRUE(appsService, nullptr); diff --git a/dom/ipc/TabContext.h b/dom/ipc/TabContext.h index b9ecd44865c..cf45018f51e 100644 --- a/dom/ipc/TabContext.h +++ b/dom/ipc/TabContext.h @@ -159,10 +159,15 @@ protected: private: /** - * Translate an appId into a mozIApplication. + * Translate an appId into a mozIApplication, using lazy caching. */ already_AddRefed GetAppForId(uint32_t aAppId) const; + /** + * Translate an appId into a mozIApplication. + */ + already_AddRefed GetAppForIdNoCache(uint32_t aAppId) const; + /** * Has this TabContext been initialized? If so, mutator methods will fail. */ @@ -174,6 +179,12 @@ private: */ uint32_t mOwnAppId; + /** + * Cache of this TabContext's own app. If mOwnAppId is NO_APP_ID, this is + * guaranteed to be nullptr. Otherwise, it may or may not be null. + */ + mutable nsCOMPtr mOwnApp; + /** * The id of the app which contains this TabContext's frame. If mIsBrowser, * this corresponds to the ID of the app which contains the browser frame; @@ -182,6 +193,13 @@ private: */ uint32_t mContainingAppId; + /** + * Cache of the app that contains this TabContext's frame. If mContainingAppId + * is NO_APP_ID, this is guaranteed to be nullptr. Otherwise, it may or may not + * be null. + */ + mutable nsCOMPtr mContainingApp; + /** * The requested scrolling behavior for this frame. */