Bug 853632 - Cache own and containing apps in TabContext. r=jlebar

This commit is contained in:
Jon Hylands 2013-04-16 15:34:11 +02:00
parent 28167a9306
commit 18136e92bd
2 changed files with 45 additions and 1 deletions

View File

@ -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<mozIApplication> ownApp = mOwnApp;
return ownApp.forget();
}
if (aAppId == mContainingAppId) {
if (!mContainingApp) {
mContainingApp = GetAppForIdNoCache(mContainingAppId);
}
nsCOMPtr<mozIApplication> 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<mozIApplication>
TabContext::GetAppForIdNoCache(uint32_t aAppId) const
{
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
NS_ENSURE_TRUE(appsService, nullptr);

View File

@ -159,10 +159,15 @@ protected:
private:
/**
* Translate an appId into a mozIApplication.
* Translate an appId into a mozIApplication, using lazy caching.
*/
already_AddRefed<mozIApplication> GetAppForId(uint32_t aAppId) const;
/**
* Translate an appId into a mozIApplication.
*/
already_AddRefed<mozIApplication> 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<mozIApplication> 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<mozIApplication> mContainingApp;
/**
* The requested scrolling behavior for this frame.
*/