Bug 966102 - Squelch a bunch of warnings starting child processes. r=bsmedberg
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 31 Jan 2014 15:02:30 -0800
changeset 166319 5cf89fb575c4eb060d90d799502082706aae745d
parent 166318 fc3d3be15c0ce1c237f4014379f5bfdbc93bc311
child 166320 4cae03e1c434bd2e8b97deb1d8965a58fb05a203
push id39178
push usermrbkap@mozilla.com
push dateFri, 31 Jan 2014 23:03:55 +0000
treeherdermozilla-inbound@ee15873640b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs966102
milestone29.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 966102 - Squelch a bunch of warnings starting child processes. r=bsmedberg
dom/ipc/ContentChild.cpp
dom/ipc/moz.build
xpcom/threads/nsThreadManager.cpp
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -49,16 +49,17 @@
 #include "nsIScriptError.h"
 #include "nsIConsoleService.h"
 #include "nsJSEnvironment.h"
 #include "SandboxHal.h"
 #include "nsDebugImpl.h"
 #include "nsHashPropertyBag.h"
 #include "nsLayoutStylesheetCache.h"
 #include "nsIJSRuntimeService.h"
+#include "nsThreadManager.h"
 
 #include "IHistory.h"
 #include "nsNetUtil.h"
 
 #include "base/message_loop.h"
 #include "base/process_util.h"
 #include "base/task.h"
 
@@ -335,16 +336,24 @@ ContentChild::Init(MessageLoop* aIOLoop,
 #endif
 
 #ifdef MOZ_NUWA_PROCESS
     SetTransport(aChannel);
 #endif
 
     NS_ASSERTION(!sSingleton, "only one ContentChild per child");
 
+    // Once we start sending IPC messages, we need the thread manager to be
+    // initialized so we can deal with the responses. Do that here before we
+    // try to construct the crash reporter.
+    nsresult rv = nsThreadManager::get()->Init();
+    if (NS_WARN_IF(NS_FAILED(rv))) {
+        return false;
+    }
+
     Open(aChannel, aParentHandle, aIOLoop);
     sSingleton = this;
 
 #ifdef MOZ_CRASHREPORTER
     SendPCrashReporterConstructor(CrashReporter::CurrentThreadId(),
                                   XRE_GetProcessType());
 #endif
 
--- a/dom/ipc/moz.build
+++ b/dom/ipc/moz.build
@@ -101,16 +101,17 @@ LOCAL_INCLUDES += [
     '/hal/sandbox',
     '/js/ipc',
     '/layout/base',
     '/netwerk/base/src',
     '/toolkit/xre',
     '/uriloader/exthandler',
     '/widget/xpwidgets',
     '/xpcom/base',
+    '/xpcom/threads',
 ]
 
 DEFINES['BIN_SUFFIX'] = '"%s"' % CONFIG['BIN_SUFFIX']
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('android', 'gtk2', 'gonk', 'qt'):
     DEFINES['MOZ_ENABLE_FREETYPE'] = True
 
 for var in ('MOZ_PERMISSIONS', 'MOZ_CHILD_PERMISSIONS'):
--- a/xpcom/threads/nsThreadManager.cpp
+++ b/xpcom/threads/nsThreadManager.cpp
@@ -51,34 +51,38 @@ NS_IMPL_CLASSINFO(nsThreadManager, nullp
 NS_IMPL_QUERY_INTERFACE1_CI(nsThreadManager, nsIThreadManager)
 NS_IMPL_CI_INTERFACE_GETTER1(nsThreadManager, nsIThreadManager)
 
 //-----------------------------------------------------------------------------
 
 nsresult
 nsThreadManager::Init()
 {
+  // Child processes need to initialize the thread manager before they
+  // initialize XPCOM in order to set up the crash reporter. This leads to
+  // situations where we get initialized twice.
+  if (mInitialized)
+    return NS_OK;
+
   if (PR_NewThreadPrivateIndex(&mCurThreadIndex, ReleaseObject) == PR_FAILURE)
     return NS_ERROR_FAILURE;
 
   mLock = new Mutex("nsThreadManager.mLock");
 
 #ifdef MOZ_CANARY
   const int flags = O_WRONLY | O_APPEND | O_CREAT | O_NONBLOCK;
   const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
   char* env_var_flag = getenv("MOZ_KILL_CANARIES");
   sCanaryOutputFD = env_var_flag ? (env_var_flag[0] ?
       open(env_var_flag, flags, mode) :
       STDERR_FILENO) : 0;
 #endif
 
   // Setup "main" thread
   mMainThread = new nsThread(nsThread::MAIN_THREAD, 0);
-  if (!mMainThread)
-    return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv = mMainThread->InitCurrentThread();
   if (NS_FAILED(rv)) {
     mMainThread = nullptr;
     return rv;
   }
 
   // We need to keep a pointer to the current thread, so we can satisfy