Bug 847656: Change ContentParent::GetNewOrUsed to return an already_AddRefed value. r=khuey
☠☠ backed out by 164abd8f727d ☠ ☠
authorJim Blandy <jimb@mozilla.com>
Wed, 20 Mar 2013 10:30:09 -0700
changeset 136880 42d5d3080bc4a6ca6eb35167dfc82ad462d0e5e2
parent 136879 61555788d72f4e1a57b7da9705742b8359d6777d
child 136881 9b73525e34f41e6dbe9926c33e12b50689a369e0
push id336
push userakeybl@mozilla.com
push dateMon, 17 Jun 2013 22:53:19 +0000
treeherdermozilla-release@574a39cdf657 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs847656
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 847656: Change ContentParent::GetNewOrUsed to return an already_AddRefed value. r=khuey
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsEmbedFunctions.cpp
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -365,17 +365,17 @@ ContentParent::JoinAllSubprocesses()
         while (!done) {
             lock.Wait();
         }
     }
 
     sCanLaunchSubprocesses = false;
 }
 
-/*static*/ ContentParent*
+/*static*/ already_AddRefed<ContentParent>
 ContentParent::GetNewOrUsed(bool aForBrowserElement)
 {
     if (!gNonAppContentParents)
         gNonAppContentParents = new nsTArray<ContentParent*>();
 
     int32_t maxContentProcesses = Preferences::GetInt("dom.ipc.processCount", 1);
     if (maxContentProcesses < 1)
         maxContentProcesses = 1;
@@ -389,17 +389,17 @@ ContentParent::GetNewOrUsed(bool aForBro
 
     nsRefPtr<ContentParent> p =
         new ContentParent(/* appManifestURL = */ EmptyString(),
                           aForBrowserElement,
                           base::PRIVILEGES_DEFAULT,
                           PROCESS_PRIORITY_FOREGROUND);
     p->Init();
     gNonAppContentParents->AppendElement(p);
-    return p;
+    return p.forget();
 }
 
 namespace {
 struct SpecialPermission {
     const char* perm;           // an app permission
     ChildPrivileges privs;      // the OS privilege it requires
 };
 }
@@ -460,17 +460,17 @@ ContentParent::GetInitialProcessPriority
 ContentParent::CreateBrowserOrApp(const TabContext& aContext,
                                   nsIDOMElement* aFrameElement)
 {
     if (!sCanLaunchSubprocesses) {
         return nullptr;
     }
 
     if (aContext.IsBrowserElement() || !aContext.HasOwnApp()) {
-        if (ContentParent* cp = GetNewOrUsed(aContext.IsBrowserElement())) {
+        if (nsRefPtr<ContentParent> cp = GetNewOrUsed(aContext.IsBrowserElement())) {
             nsRefPtr<TabParent> tp(new TabParent(aContext));
             tp->SetOwnerElement(aFrameElement);
             PBrowserParent* browser = cp->SendPBrowserConstructor(
                 tp.forget().get(), // DeallocPBrowserParent() releases this ref.
                 aContext.AsIPCTabContext(),
                 /* chromeFlags */ 0);
             return static_cast<TabParent*>(browser);
         }
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -76,17 +76,18 @@ public:
     /**
      * Ensure that all subprocesses are terminated and their OS
      * resources have been reaped.  This is synchronous and can be
      * very expensive in general.  It also bypasses the normal
      * shutdown process.
      */
     static void JoinAllSubprocesses();
 
-    static ContentParent* GetNewOrUsed(bool aForBrowserElement = false);
+    static already_AddRefed<ContentParent>
+    GetNewOrUsed(bool aForBrowserElement = false);
 
     /**
      * Get or create a content process for the given TabContext.  aFrameElement
      * should be the frame/iframe element with which this process will
      * associated.
      */
     static TabParent*
     CreateBrowserOrApp(const TabContext& aContext,
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -775,17 +775,17 @@ nsXULAppInfo::GetProcessType(uint32_t* a
 }
 
 NS_IMETHODIMP
 nsXULAppInfo::EnsureContentProcess()
 {
   if (XRE_GetProcessType() != GeckoProcessType_Default)
     return NS_ERROR_NOT_AVAILABLE;
 
-  unused << ContentParent::GetNewOrUsed();
+  nsRefPtr<ContentParent> unused = ContentParent::GetNewOrUsed();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsXULAppInfo::InvalidateCachesOnRestart()
 {
   nsCOMPtr<nsIFile> file;
   nsresult rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DIR_STARTUP, 
--- a/toolkit/xre/nsEmbedFunctions.cpp
+++ b/toolkit/xre/nsEmbedFunctions.cpp
@@ -690,17 +690,18 @@ XRE_ShutdownChildProcess()
 #endif // XP_MACOSX
 }
 
 namespace {
 ContentParent* gContentParent; //long-lived, manually refcounted
 TestShellParent* GetOrCreateTestShellParent()
 {
     if (!gContentParent) {
-        NS_ADDREF(gContentParent = ContentParent::GetNewOrUsed());
+        nsRefPtr<ContentParent> parent = ContentParent::GetNewOrUsed().get();
+        parent.forget(&gContentParent);
     } else if (!gContentParent->IsAlive()) {
         return nullptr;
     }
     TestShellParent* tsp = gContentParent->GetTestShellSingleton();
     if (!tsp) {
         tsp = gContentParent->CreateTestShell();
     }
     return tsp;