Bug 995730 - Convert xpcom/threads/ to Gecko style. r=froydnj
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 27 May 2014 10:15:35 +0300
changeset 185145 747dc2140460792408f3a799fd00fd5b1a4e6741
parent 185144 eb3b772bac41bcc5d684bdf10a12d12e5ccbf54f
child 185146 59eefc86501af9789931aed1672dfa9461375316
push id26844
push userryanvm@gmail.com
push dateTue, 27 May 2014 20:23:53 +0000
treeherdermozilla-central@448f2153d6d3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs995730
milestone32.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 995730 - Convert xpcom/threads/ to Gecko style. r=froydnj
xpcom/threads/BackgroundHangMonitor.cpp
xpcom/threads/HangMonitor.cpp
xpcom/threads/HangMonitor.h
xpcom/threads/LazyIdleThread.cpp
xpcom/threads/LazyIdleThread.h
xpcom/threads/SyncRunnable.h
xpcom/threads/ThreadStackHelper.cpp
xpcom/threads/TimerThread.cpp
xpcom/threads/TimerThread.h
xpcom/threads/nsEnvironment.cpp
xpcom/threads/nsEnvironment.h
xpcom/threads/nsEventQueue.cpp
xpcom/threads/nsEventQueue.h
xpcom/threads/nsMemoryPressure.cpp
xpcom/threads/nsMemoryPressure.h
xpcom/threads/nsProcess.h
xpcom/threads/nsProcessCommon.cpp
xpcom/threads/nsThread.cpp
xpcom/threads/nsThread.h
xpcom/threads/nsThreadManager.cpp
xpcom/threads/nsThreadManager.h
xpcom/threads/nsThreadPool.cpp
xpcom/threads/nsThreadPool.h
xpcom/threads/nsTimerImpl.cpp
xpcom/threads/nsTimerImpl.h
--- a/xpcom/threads/BackgroundHangMonitor.cpp
+++ b/xpcom/threads/BackgroundHangMonitor.cpp
@@ -33,17 +33,17 @@ class BackgroundHangManager
 private:
   // Background hang monitor thread function
   static void MonitorThread(void* aData)
   {
     PR_SetCurrentThreadName("BgHangManager");
 
 #ifdef MOZ_NUWA_PROCESS
     if (IsNuwaProcess()) {
-      NS_ASSERTION(NuwaMarkCurrentThread != nullptr,
+      NS_ASSERTION(NuwaMarkCurrentThread,
                    "NuwaMarkCurrentThread is undefined!");
       NuwaMarkCurrentThread(nullptr, nullptr);
     }
 #endif
 
     /* We do not hold a reference to BackgroundHangManager here
        because the monitor thread only exists as long as the
        BackgroundHangManager instance exists. We stop the monitor
@@ -112,19 +112,18 @@ private:
   const PRThread* mThreadID;
 
 public:
   NS_INLINE_DECL_REFCOUNTING(BackgroundHangThread)
   static BackgroundHangThread* FindThread();
 
   static void Startup()
   {
-    /* We can tolerate init() failing.
-       The if block turns off warn_unused_result. */
-    if (!sTlsKey.init()) {}
+    /* We can tolerate init() failing. */
+    (void)!sTlsKey.init();
   }
 
   // Hang timeout in ticks
   const PRIntervalTime mTimeout;
   // PermaHang timeout in ticks
   const PRIntervalTime mMaxTimeout;
   // Time at last activity
   PRIntervalTime mInterval;
@@ -171,28 +170,24 @@ BackgroundHangManager::BackgroundHangMan
   , mIntervalNow(0)
 {
   // Lock so we don't race against the new monitor thread
   MonitorAutoLock autoLock(mLock);
   mHangMonitorThread = PR_CreateThread(
     PR_USER_THREAD, MonitorThread, this,
     PR_PRIORITY_LOW, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
 
-  MOZ_ASSERT(mHangMonitorThread,
-    "Failed to create monitor thread");
+  MOZ_ASSERT(mHangMonitorThread, "Failed to create monitor thread");
 }
 
 BackgroundHangManager::~BackgroundHangManager()
 {
-  MOZ_ASSERT(mShutdown,
-    "Destruction without Shutdown call");
-  MOZ_ASSERT(mHangThreads.isEmpty(),
-    "Destruction with outstanding monitors");
-  MOZ_ASSERT(mHangMonitorThread,
-    "No monitor thread");
+  MOZ_ASSERT(mShutdown, "Destruction without Shutdown call");
+  MOZ_ASSERT(mHangThreads.isEmpty(), "Destruction with outstanding monitors");
+  MOZ_ASSERT(mHangMonitorThread, "No monitor thread");
 
   // PR_CreateThread could have failed above due to resource limitation
   if (mHangMonitorThread) {
     // The monitor thread can only live as long as the instance lives
     PR_JoinThread(mHangMonitorThread);
   }
 }
 
--- a/xpcom/threads/HangMonitor.cpp
+++ b/xpcom/threads/HangMonitor.cpp
@@ -21,17 +21,18 @@
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
 #if defined(MOZ_ENABLE_PROFILER_SPS) && defined(MOZ_PROFILING) && defined(XP_WIN)
   #define REPORT_CHROME_HANGS
 #endif
 
-namespace mozilla { namespace HangMonitor {
+namespace mozilla {
+namespace HangMonitor {
 
 /**
  * A flag which may be set from within a debugger to disable the hang
  * monitor.
  */
 volatile bool gDebugDisableHangMonitor = false;
 
 const char kHangMonitorPrefName[] = "hangmonitor.timeout";
@@ -107,47 +108,50 @@ Crash()
                                      NS_LITERAL_CSTRING("1"));
 #endif
 
   NS_RUNTIMEABORT("HangMonitor triggered");
 }
 
 #ifdef REPORT_CHROME_HANGS
 static void
-ChromeStackWalker(void *aPC, void *aSP, void *aClosure)
+ChromeStackWalker(void* aPC, void* aSP, void* aClosure)
 {
   MOZ_ASSERT(aClosure);
-  std::vector<uintptr_t> *stack =
+  std::vector<uintptr_t>* stack =
     static_cast<std::vector<uintptr_t>*>(aClosure);
-  if (stack->size() == MAX_CALL_STACK_PCS)
+  if (stack->size() == MAX_CALL_STACK_PCS) {
     return;
+  }
   MOZ_ASSERT(stack->size() < MAX_CALL_STACK_PCS);
   stack->push_back(reinterpret_cast<uintptr_t>(aPC));
 }
 
 static void
-GetChromeHangReport(Telemetry::ProcessedStack &aStack,
-                    int32_t &aSystemUptime,
-                    int32_t &aFirefoxUptime)
+GetChromeHangReport(Telemetry::ProcessedStack& aStack,
+                    int32_t& aSystemUptime,
+                    int32_t& aFirefoxUptime)
 {
   MOZ_ASSERT(winMainThreadHandle);
 
   // The thread we're about to suspend might have the alloc lock
   // so allocate ahead of time
   std::vector<uintptr_t> rawStack;
   rawStack.reserve(MAX_CALL_STACK_PCS);
   DWORD ret = ::SuspendThread(winMainThreadHandle);
-  if (ret == -1)
+  if (ret == -1) {
     return;
+  }
   NS_StackWalk(ChromeStackWalker, /* skipFrames */ 0, /* maxFrames */ 0,
                reinterpret_cast<void*>(&rawStack),
                reinterpret_cast<uintptr_t>(winMainThreadHandle), nullptr);
   ret = ::ResumeThread(winMainThreadHandle);
-  if (ret == -1)
+  if (ret == -1) {
     return;
+  }
   aStack = Telemetry::GetStackAndModules(rawStack);
 
   // Record system uptime (in minutes) at the time of the hang
   aSystemUptime = ((GetTickCount() / 1000) - (gTimeout * 2)) / 60;
 
   // Record Firefox uptime (in minutes) at the time of the hang
   bool error;
   TimeStamp processCreation = TimeStamp::ProcessCreation(error);
@@ -212,62 +216,62 @@ ThreadMain(void*)
         int32_t delay =
           int32_t(PR_IntervalToSeconds(now - timestamp));
         if (delay >= gTimeout) {
           MonitorAutoUnlock unlock(*gMonitor);
           Crash();
         }
       }
 #endif
-    }
-    else {
+    } else {
 #ifdef REPORT_CHROME_HANGS
       if (waitCount >= 2) {
         uint32_t hangDuration = PR_IntervalToSeconds(now - lastTimestamp);
         Telemetry::RecordChromeHang(hangDuration, stack,
                                     systemUptime, firefoxUptime);
         stack.Clear();
       }
 #endif
       lastTimestamp = timestamp;
       waitCount = 0;
     }
 
     PRIntervalTime timeout;
     if (gTimeout <= 0) {
       timeout = PR_INTERVAL_NO_TIMEOUT;
-    }
-    else {
+    } else {
       timeout = PR_MillisecondsToInterval(gTimeout * 500);
     }
     lock.Wait(timeout);
   }
 }
 
 void
 Startup()
 {
   // The hang detector only runs in chrome processes. If you change this,
   // you must also deal with the threadsafety of AnnotateCrashReport in
   // non-chrome processes!
-  if (GeckoProcessType_Default != XRE_GetProcessType())
+  if (GeckoProcessType_Default != XRE_GetProcessType()) {
     return;
+  }
 
   MOZ_ASSERT(!gMonitor, "Hang monitor already initialized");
   gMonitor = new Monitor("HangMonitor");
 
   Preferences::RegisterCallback(PrefChanged, kHangMonitorPrefName, nullptr);
   PrefChanged(nullptr, nullptr);
 
 #ifdef REPORT_CHROME_HANGS
   Preferences::RegisterCallback(PrefChanged, kTelemetryPrefName, nullptr);
   winMainThreadHandle =
     OpenThread(THREAD_ALL_ACCESS, FALSE, GetCurrentThreadId());
-  if (!winMainThreadHandle)
+  if (!winMainThreadHandle) {
     return;
+  }
 #endif
 
   // Don't actually start measuring hangs until we hit the main event loop.
   // This potentially misses a small class of really early startup hangs,
   // but avoids dealing with some xpcshell tests and other situations which
   // start XPCOM but don't ever start the event loop.
   Suspend();
 
@@ -275,22 +279,24 @@ Startup()
                             ThreadMain,
                             nullptr, PR_PRIORITY_LOW, PR_GLOBAL_THREAD,
                             PR_JOINABLE_THREAD, 0);
 }
 
 void
 Shutdown()
 {
-  if (GeckoProcessType_Default != XRE_GetProcessType())
+  if (GeckoProcessType_Default != XRE_GetProcessType()) {
     return;
+  }
 
   MOZ_ASSERT(gMonitor, "Hang monitor not started");
 
-  { // Scope the lock we're going to delete later
+  {
+    // Scope the lock we're going to delete later
     MonitorAutoLock lock(*gMonitor);
     gShutdown = true;
     lock.Notify();
   }
 
   // thread creation could theoretically fail
   if (gThread) {
     PR_JoinThread(gThread);
@@ -302,67 +308,67 @@ Shutdown()
 }
 
 static bool
 IsUIMessageWaiting()
 {
 #ifndef XP_WIN
   return false;
 #else
-  #define NS_WM_IMEFIRST WM_IME_SETCONTEXT
-  #define NS_WM_IMELAST  WM_IME_KEYUP
+#define NS_WM_IMEFIRST WM_IME_SETCONTEXT
+#define NS_WM_IMELAST  WM_IME_KEYUP
   BOOL haveUIMessageWaiting = FALSE;
   MSG msg;
-  haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, WM_KEYFIRST, 
+  haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, WM_KEYFIRST,
                                          WM_IME_KEYLAST, PM_NOREMOVE);
   haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, NS_WM_IMEFIRST,
                                          NS_WM_IMELAST, PM_NOREMOVE);
   haveUIMessageWaiting |= ::PeekMessageW(&msg, nullptr, WM_MOUSEFIRST,
                                          WM_MOUSELAST, PM_NOREMOVE);
   return haveUIMessageWaiting;
 #endif
 }
 
 void
-NotifyActivity(ActivityType activityType)
+NotifyActivity(ActivityType aActivityType)
 {
   MOZ_ASSERT(NS_IsMainThread(),
              "HangMonitor::Notify called from off the main thread.");
 
   // Determine the activity type more specifically
-  if (activityType == kGeneralActivity) {
-    activityType = IsUIMessageWaiting() ? kActivityUIAVail : 
-                                          kActivityNoUIAVail;
+  if (aActivityType == kGeneralActivity) {
+    aActivityType = IsUIMessageWaiting() ? kActivityUIAVail :
+                                           kActivityNoUIAVail;
   }
 
   // Calculate the cumulative amount of lag time since the last UI message
   static uint32_t cumulativeUILagMS = 0;
-  switch(activityType) {
-  case kActivityNoUIAVail:
-    cumulativeUILagMS = 0;
-    break;
-  case kActivityUIAVail:
-  case kUIActivity:
-    if (gTimestamp != PR_INTERVAL_NO_WAIT) {
-      cumulativeUILagMS += PR_IntervalToMilliseconds(PR_IntervalNow() -
-                                                     gTimestamp);
-    }
-    break;
-  default:
-    break;
+  switch (aActivityType) {
+    case kActivityNoUIAVail:
+      cumulativeUILagMS = 0;
+      break;
+    case kActivityUIAVail:
+    case kUIActivity:
+      if (gTimestamp != PR_INTERVAL_NO_WAIT) {
+        cumulativeUILagMS += PR_IntervalToMilliseconds(PR_IntervalNow() -
+                                                       gTimestamp);
+      }
+      break;
+    default:
+      break;
   }
 
   // This is not a locked activity because PRTimeStamp is a 32-bit quantity
   // which can be read/written atomically, and we don't want to pay locking
   // penalties here.
   gTimestamp = PR_IntervalNow();
 
   // If we have UI activity we should reset the timer and report it if it is
   // significant enough.
-  if (activityType == kUIActivity) {
+  if (aActivityType == kUIActivity) {
     // The minimum amount of lag time that we should report for telemetry data.
     // Mozilla's UI responsiveness goal is 50ms
     static const uint32_t kUIResponsivenessThresholdMS = 50;
     if (cumulativeUILagMS > kUIResponsivenessThresholdMS) {
       mozilla::Telemetry::Accumulate(mozilla::Telemetry::EVENTLOOP_UI_LAG_EXP_MS,
                                      cumulativeUILagMS);
     }
     cumulativeUILagMS = 0;
@@ -382,9 +388,10 @@ Suspend()
   // Because gTimestamp changes this resets the wait count.
   gTimestamp = PR_INTERVAL_NO_WAIT;
 
   if (gThread && !gShutdown) {
     mozilla::BackgroundHangMonitor().NotifyWait();
   }
 }
 
-} } // namespace mozilla::HangMonitor
+} // namespace HangMonitor
+} // namespace mozilla
--- a/xpcom/threads/HangMonitor.h
+++ b/xpcom/threads/HangMonitor.h
@@ -1,22 +1,25 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_HangMonitor_h
 #define mozilla_HangMonitor_h
 
-namespace mozilla { namespace HangMonitor {
+namespace mozilla {
+namespace HangMonitor {
 
 /**
  * Signifies the type of activity in question
 */
-enum ActivityType {
+enum ActivityType
+{
   /* There is activity and it is known to be UI related activity. */
   kUIActivity,
 
   /* There is non UI activity and no UI activity is pending */
   kActivityNoUIAVail,
 
   /* There is non UI activity and UI activity is known to be pending */
   kActivityUIAVail,
@@ -44,11 +47,12 @@ void Shutdown();
 void NotifyActivity(ActivityType activityType = kGeneralActivity);
 
 /*
  * Notify the hang monitor that the browser is now idle and no detection should
  * be done.
  */
 void Suspend();
 
-} } // namespace mozilla::HangMonitor
+} // namespace HangMonitor
+} // namespace mozilla
 
 #endif // mozilla_HangMonitor_h
--- a/xpcom/threads/LazyIdleThread.cpp
+++ b/xpcom/threads/LazyIdleThread.cpp
@@ -29,28 +29,28 @@
 #endif
 
 namespace mozilla {
 
 LazyIdleThread::LazyIdleThread(uint32_t aIdleTimeoutMS,
                                const nsCSubstring& aName,
                                ShutdownMethod aShutdownMethod,
                                nsIObserver* aIdleObserver)
-: mMutex("LazyIdleThread::mMutex"),
-  mOwningThread(NS_GetCurrentThread()),
-  mIdleObserver(aIdleObserver),
-  mQueuedRunnables(nullptr),
-  mIdleTimeoutMS(aIdleTimeoutMS),
-  mPendingEventCount(0),
-  mIdleNotificationCount(0),
-  mShutdownMethod(aShutdownMethod),
-  mShutdown(false),
-  mThreadIsShuttingDown(false),
-  mIdleTimeoutEnabled(true),
-  mName(aName)
+  : mMutex("LazyIdleThread::mMutex")
+  , mOwningThread(NS_GetCurrentThread())
+  , mIdleObserver(aIdleObserver)
+  , mQueuedRunnables(nullptr)
+  , mIdleTimeoutMS(aIdleTimeoutMS)
+  , mPendingEventCount(0)
+  , mIdleNotificationCount(0)
+  , mShutdownMethod(aShutdownMethod)
+  , mShutdown(false)
+  , mThreadIsShuttingDown(false)
+  , mIdleTimeoutEnabled(true)
+  , mName(aName)
 {
   MOZ_ASSERT(mOwningThread, "Need owning thread!");
 }
 
 LazyIdleThread::~LazyIdleThread()
 {
   ASSERT_OWNING_THREAD();
 
@@ -142,36 +142,41 @@ LazyIdleThread::EnsureThread()
   MOZ_ASSERT(!mIdleTimer, "Should have killed this long ago!");
   MOZ_ASSERT(!mThreadIsShuttingDown, "Should have cleared that!");
 
   nsresult rv;
 
   if (mShutdownMethod == AutomaticShutdown && NS_IsMainThread()) {
     nsCOMPtr<nsIObserverService> obs =
       do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv);
-    if (NS_WARN_IF(NS_FAILED(rv)))
+    if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
+    }
 
     rv = obs->AddObserver(this, "xpcom-shutdown-threads", false);
-    if (NS_WARN_IF(NS_FAILED(rv)))
+    if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
+    }
   }
 
   mIdleTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv);
-  if (NS_WARN_IF(!mIdleTimer))
+  if (NS_WARN_IF(!mIdleTimer)) {
     return NS_ERROR_UNEXPECTED;
+  }
 
   nsCOMPtr<nsIRunnable> runnable =
     NS_NewRunnableMethod(this, &LazyIdleThread::InitThread);
-  if (NS_WARN_IF(!runnable))
+  if (NS_WARN_IF(!runnable)) {
     return NS_ERROR_UNEXPECTED;
+  }
 
   rv = NS_NewThread(getter_AddRefs(mThread), runnable);
-  if (NS_WARN_IF(NS_FAILED(rv)))
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
+  }
 
   return NS_OK;
 }
 
 void
 LazyIdleThread::InitThread()
 {
   char aLocal;
@@ -268,24 +273,26 @@ LazyIdleThread::ShutdownThread()
     {
       MutexAutoLock lock(mMutex);
       MOZ_ASSERT(!mThreadIsShuttingDown, "Huh?!");
     }
 #endif
 
     nsCOMPtr<nsIRunnable> runnable =
       NS_NewRunnableMethod(this, &LazyIdleThread::CleanupThread);
-    if (NS_WARN_IF(!runnable))
+    if (NS_WARN_IF(!runnable)) {
       return NS_ERROR_UNEXPECTED;
+    }
 
     PreDispatch();
 
     rv = mThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
-    if (NS_WARN_IF(NS_FAILED(rv)))
+    if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
+    }
 
     // Put the temporary queue in place before calling Shutdown().
     mQueuedRunnables = &queuedRunnables;
 
     if (NS_FAILED(mThread->Shutdown())) {
       NS_ERROR("Failed to shutdown the thread!");
     }
 
@@ -301,18 +308,19 @@ LazyIdleThread::ShutdownThread()
       MOZ_ASSERT(!mIdleNotificationCount, "Huh?!");
       MOZ_ASSERT(mThreadIsShuttingDown, "Huh?!");
       mThreadIsShuttingDown = false;
     }
   }
 
   if (mIdleTimer) {
     rv = mIdleTimer->Cancel();
-    if (NS_WARN_IF(NS_FAILED(rv)))
+    if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
+    }
 
     mIdleTimer = nullptr;
   }
 
   // If our temporary queue has any runnables then we need to dispatch them.
   if (queuedRunnables.Length()) {
     // If the thread manager has gone away then these runnables will never run.
     if (mShutdown) {
@@ -379,29 +387,31 @@ NS_IMPL_QUERY_INTERFACE(LazyIdleThread, 
 
 NS_IMETHODIMP
 LazyIdleThread::Dispatch(nsIRunnable* aEvent,
                          uint32_t aFlags)
 {
   ASSERT_OWNING_THREAD();
 
   // LazyIdleThread can't always support synchronous dispatch currently.
-  if (NS_WARN_IF(aFlags != NS_DISPATCH_NORMAL))
+  if (NS_WARN_IF(aFlags != NS_DISPATCH_NORMAL)) {
     return NS_ERROR_NOT_IMPLEMENTED;
+  }
 
   // If our thread is shutting down then we can't actually dispatch right now.
   // Queue this runnable for later.
   if (UseRunnableQueue()) {
     mQueuedRunnables->AppendElement(aEvent);
     return NS_OK;
   }
 
   nsresult rv = EnsureThread();
-  if (NS_WARN_IF(NS_FAILED(rv)))
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
+  }
 
   PreDispatch();
 
   return mThread->Dispatch(aEvent, aFlags);
 }
 
 NS_IMETHODIMP
 LazyIdleThread::IsOnCurrentThread(bool* aIsOnCurrentThread)
@@ -432,18 +442,19 @@ LazyIdleThread::Shutdown()
 
   mShutdown = true;
 
   nsresult rv = ShutdownThread();
   MOZ_ASSERT(!mThread, "Should have destroyed this by now!");
 
   mIdleObserver = nullptr;
 
-  if (NS_WARN_IF(NS_FAILED(rv)))
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
+  }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 LazyIdleThread::HasPendingEvents(bool* aHasPendingEvents)
 {
   // This is only supposed to be called from the thread itself so it's not
@@ -473,18 +484,19 @@ LazyIdleThread::Notify(nsITimer* aTimer)
     if (mPendingEventCount || mIdleNotificationCount) {
       // Another event was scheduled since this timer was set. Don't do
       // anything and wait for the timer to fire again.
       return NS_OK;
     }
   }
 
   nsresult rv = ShutdownThread();
-  if (NS_WARN_IF(NS_FAILED(rv)))
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
+  }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 LazyIdleThread::OnDispatchedEvent(nsIThreadInternal* /*aThread */)
 {
   MOZ_ASSERT(NS_GetCurrentThread() == mOwningThread, "Wrong thread!");
@@ -523,22 +535,24 @@ LazyIdleThread::AfterProcessNextEvent(ns
       MOZ_ASSERT(mIdleNotificationCount < UINT32_MAX, "Way too many!");
       mIdleNotificationCount++;
     }
   }
 
   if (shouldNotifyIdle) {
     nsCOMPtr<nsIRunnable> runnable =
       NS_NewRunnableMethod(this, &LazyIdleThread::ScheduleTimer);
-    if (NS_WARN_IF(!runnable))
+    if (NS_WARN_IF(!runnable)) {
       return NS_ERROR_UNEXPECTED;
+    }
 
     nsresult rv = mOwningThread->Dispatch(runnable, NS_DISPATCH_NORMAL);
-    if (NS_WARN_IF(NS_FAILED(rv)))
+    if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
+    }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 LazyIdleThread::Observe(nsISupports* /* aSubject */,
                         const char*  aTopic,
--- a/xpcom/threads/LazyIdleThread.h
+++ b/xpcom/threads/LazyIdleThread.h
@@ -27,30 +27,32 @@ namespace mozilla {
 
 /**
  * This class provides a basic event target that creates its thread lazily and
  * destroys its thread after a period of inactivity. It may be created on any
  * thread but it may only be used from the thread on which it is created. If it
  * is created on the main thread then it will automatically join its thread on
  * XPCOM shutdown using the Observer Service.
  */
-class LazyIdleThread MOZ_FINAL : public nsIThread,
-                                 public nsITimerCallback,
-                                 public nsIThreadObserver,
-                                 public nsIObserver
+class LazyIdleThread MOZ_FINAL
+  : public nsIThread
+  , public nsITimerCallback
+  , public nsIThreadObserver
+  , public nsIObserver
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIEVENTTARGET
   NS_DECL_NSITHREAD
   NS_DECL_NSITIMERCALLBACK
   NS_DECL_NSITHREADOBSERVER
   NS_DECL_NSIOBSERVER
 
-  enum ShutdownMethod {
+  enum ShutdownMethod
+  {
     AutomaticShutdown = 0,
     ManualShutdown
   };
 
   /**
    * Create a new LazyIdleThread that will destroy its thread after the given
    * number of milliseconds.
    */
@@ -123,17 +125,18 @@ private:
    * final release (during a GC, for instance).
    */
   void SelfDestruct();
 
   /**
    * Returns true if events should be queued rather than immediately dispatched
    * to mThread. Currently only happens when the thread is shutting down.
    */
-  bool UseRunnableQueue() {
+  bool UseRunnableQueue()
+  {
     return !!mQueuedRunnables;
   }
 
   /**
    * Protects data that is accessed on both threads.
    */
   mozilla::Mutex mMutex;
 
@@ -160,17 +163,17 @@ private:
    * only when Shutdown() is called.
    */
   nsIObserver* mIdleObserver;
 
   /**
    * Temporary storage for events that happen to be dispatched while we're in
    * the process of shutting down our real thread.
    */
-  nsTArray<nsCOMPtr<nsIRunnable> >* mQueuedRunnables;
+  nsTArray<nsCOMPtr<nsIRunnable>>* mQueuedRunnables;
 
   /**
    * The number of milliseconds a thread should be idle before dying.
    */
   const uint32_t mIdleTimeoutMS;
 
   /**
    * The number of events that are pending on mThread. A nonzero value means
--- a/xpcom/threads/SyncRunnable.h
+++ b/xpcom/threads/SyncRunnable.h
@@ -25,52 +25,52 @@ namespace mozilla {
  *
  * We also provide a convenience wrapper:
  * SyncRunnable::DispatchToThread(new myrunnable...());
  *
  */
 class SyncRunnable : public nsRunnable
 {
 public:
-  SyncRunnable(nsIRunnable* r)
-    : mRunnable(r)
+  SyncRunnable(nsIRunnable* aRunnable)
+    : mRunnable(aRunnable)
     , mMonitor("SyncRunnable")
     , mDone(false)
-  { }
+  {
+  }
 
-  void DispatchToThread(nsIEventTarget* thread,
-                        bool forceDispatch = false)
+  void DispatchToThread(nsIEventTarget* aThread, bool aForceDispatch = false)
   {
     nsresult rv;
     bool on;
 
-    if (!forceDispatch) {
-      rv = thread->IsOnCurrentThread(&on);
+    if (!aForceDispatch) {
+      rv = aThread->IsOnCurrentThread(&on);
       MOZ_ASSERT(NS_SUCCEEDED(rv));
       if (NS_SUCCEEDED(rv) && on) {
         mRunnable->Run();
         return;
       }
     }
 
-    rv = thread->Dispatch(this, NS_DISPATCH_NORMAL);
+    rv = aThread->Dispatch(this, NS_DISPATCH_NORMAL);
     if (NS_SUCCEEDED(rv)) {
       mozilla::MonitorAutoLock lock(mMonitor);
       while (!mDone) {
         lock.Wait();
       }
     }
   }
 
-  static void DispatchToThread(nsIEventTarget* thread,
-                               nsIRunnable* r,
-                               bool forceDispatch = false)
+  static void DispatchToThread(nsIEventTarget* aThread,
+                               nsIRunnable* aRunnable,
+                               bool aForceDispatch = false)
   {
-    nsRefPtr<SyncRunnable> s(new SyncRunnable(r));
-    s->DispatchToThread(thread, forceDispatch);
+    nsRefPtr<SyncRunnable> s(new SyncRunnable(aRunnable));
+    s->DispatchToThread(aThread, aForceDispatch);
   }
 
 protected:
   NS_IMETHODIMP Run()
   {
     mRunnable->Run();
 
     mozilla::MonitorAutoLock lock(mMonitor);
--- a/xpcom/threads/ThreadStackHelper.cpp
+++ b/xpcom/threads/ThreadStackHelper.cpp
@@ -179,17 +179,18 @@ ThreadStackHelper::SigAction(int aSignal
   sCurrent->FillStackBuffer();
   sCurrent = nullptr;
   ::sem_post(&sSem);
 }
 
 #endif // XP_LINUX
 
 bool
-ThreadStackHelper::PrepareStackBuffer(Stack& aStack) {
+ThreadStackHelper::PrepareStackBuffer(Stack& aStack)
+{
   // Return false to skip getting the stack and return an empty stack
   aStack.clear();
 #ifdef MOZ_ENABLE_PROFILER_SPS
   /* Normally, provided the profiler is enabled, it would be an error if we
      don't have a pseudostack here (the thread probably forgot to call
      profiler_register_thread). However, on B2G, profiling secondary threads
      may be disabled despite profiler being enabled. This is by-design and
      is not an error. */
@@ -203,17 +204,18 @@ ThreadStackHelper::PrepareStackBuffer(St
   MOZ_ALWAYS_TRUE(mStackBuffer.reserve(mMaxStackSize));
   return true;
 #else
   return false;
 #endif
 }
 
 void
-ThreadStackHelper::FillStackBuffer() {
+ThreadStackHelper::FillStackBuffer()
+{
 #ifdef MOZ_ENABLE_PROFILER_SPS
   size_t reservedSize = mMaxStackSize;
 
   // Go from front to back
   const volatile StackEntry* entry = mPseudoStack->mStack;
   const volatile StackEntry* end = entry + mPseudoStack->stackSize();
   // Deduplicate identical, consecutive frames
   const char* prevLabel = nullptr;
--- a/xpcom/threads/TimerThread.cpp
+++ b/xpcom/threads/TimerThread.cpp
@@ -45,19 +45,20 @@ TimerThread::InitLocks()
   return NS_OK;
 }
 
 namespace {
 
 class TimerObserverRunnable : public nsRunnable
 {
 public:
-  TimerObserverRunnable(nsIObserver* observer)
-    : mObserver(observer)
-  { }
+  TimerObserverRunnable(nsIObserver* aObserver)
+    : mObserver(aObserver)
+  {
+  }
 
   NS_DECL_NSIRUNNABLE
 
 private:
   nsCOMPtr<nsIObserver> mObserver;
 };
 
 NS_IMETHODIMP
@@ -71,71 +72,75 @@ TimerObserverRunnable::Run()
     observerService->AddObserver(mObserver, "suspend_process_notification", false);
     observerService->AddObserver(mObserver, "resume_process_notification", false);
   }
   return NS_OK;
 }
 
 } // anonymous namespace
 
-nsresult TimerThread::Init()
+nsresult
+TimerThread::Init()
 {
-  PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("TimerThread::Init [%d]\n", mInitialized));
+  PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
+         ("TimerThread::Init [%d]\n", mInitialized));
 
   if (mInitialized) {
-    if (!mThread)
+    if (!mThread) {
       return NS_ERROR_FAILURE;
+    }
 
     return NS_OK;
   }
 
   if (mInitInProgress.exchange(true) == false) {
     // We hold on to mThread to keep the thread alive.
     nsresult rv = NS_NewThread(getter_AddRefs(mThread), this);
     if (NS_FAILED(rv)) {
       mThread = nullptr;
-    }
-    else {
+    } else {
       nsRefPtr<TimerObserverRunnable> r = new TimerObserverRunnable(this);
       if (NS_IsMainThread()) {
         r->Run();
-      }
-      else {
+      } else {
         NS_DispatchToMainThread(r);
       }
     }
 
     {
       MonitorAutoLock lock(mMonitor);
       mInitialized = true;
       mMonitor.NotifyAll();
     }
-  }
-  else {
+  } else {
     MonitorAutoLock lock(mMonitor);
     while (!mInitialized) {
       mMonitor.Wait();
     }
   }
 
-  if (!mThread)
+  if (!mThread) {
     return NS_ERROR_FAILURE;
+  }
 
   return NS_OK;
 }
 
-nsresult TimerThread::Shutdown()
+nsresult
+TimerThread::Shutdown()
 {
   PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("TimerThread::Shutdown begin\n"));
 
-  if (!mThread)
+  if (!mThread) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
   nsTArray<nsTimerImpl*> timers;
-  {   // lock scope
+  {
+    // lock scope
     MonitorAutoLock lock(mMonitor);
 
     mShutdown = true;
 
     // notify the cond var so that Run() can return
     if (mWaiting) {
       mNotified = true;
       mMonitor.Notify();
@@ -148,62 +153,65 @@ nsresult TimerThread::Shutdown()
     // that leads to unexpected behavior or deadlock.
     // See bug 422472.
     timers.AppendElements(mTimers);
     mTimers.Clear();
   }
 
   uint32_t timersCount = timers.Length();
   for (uint32_t i = 0; i < timersCount; i++) {
-    nsTimerImpl *timer = timers[i];
+    nsTimerImpl* timer = timers[i];
     timer->ReleaseCallback();
     ReleaseTimerInternal(timer);
   }
 
   mThread->Shutdown();    // wait for the thread to die
 
   PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("TimerThread::Shutdown end\n"));
   return NS_OK;
 }
 
 #ifdef MOZ_NUWA_PROCESS
 #include "ipc/Nuwa.h"
 #endif
 
 /* void Run(); */
-NS_IMETHODIMP TimerThread::Run()
+NS_IMETHODIMP
+TimerThread::Run()
 {
   PR_SetCurrentThreadName("Timer");
 
 #ifdef MOZ_NUWA_PROCESS
   if (IsNuwaProcess()) {
-    NS_ASSERTION(NuwaMarkCurrentThread != nullptr,
+    NS_ASSERTION(NuwaMarkCurrentThread,
                  "NuwaMarkCurrentThread is undefined!");
     NuwaMarkCurrentThread(nullptr, nullptr);
   }
 #endif
 
   MonitorAutoLock lock(mMonitor);
 
   // We need to know how many microseconds give a positive PRIntervalTime. This
   // is platform-dependent, we calculate it at runtime now.
   // First we find a value such that PR_MicrosecondsToInterval(high) = 1
   int32_t low = 0, high = 1;
-  while (PR_MicrosecondsToInterval(high) == 0)
+  while (PR_MicrosecondsToInterval(high) == 0) {
     high <<= 1;
+  }
   // We now have
   //    PR_MicrosecondsToInterval(low)  = 0
   //    PR_MicrosecondsToInterval(high) = 1
   // and we can proceed to find the critical value using binary search
-  while (high-low > 1) {
-    int32_t mid = (high+low) >> 1;
-    if (PR_MicrosecondsToInterval(mid) == 0)
+  while (high - low > 1) {
+    int32_t mid = (high + low) >> 1;
+    if (PR_MicrosecondsToInterval(mid) == 0) {
       low = mid;
-    else
+    } else {
       high = mid;
+    }
   }
 
   // Half of the amount of microseconds needed to get positive PRIntervalTime.
   // We use this to decide how to round our wait times later
   int32_t halfMicrosecondsIntervalResolution = high >> 1;
   bool forceRunNextTimer = false;
 
   while (!mShutdown) {
@@ -217,17 +225,17 @@ NS_IMETHODIMP TimerThread::Run()
       uint32_t milliseconds = 100;
       if (ChaosMode::isActive()) {
         milliseconds = ChaosMode::randomUint32LessThan(200);
       }
       waitFor = PR_MillisecondsToInterval(milliseconds);
     } else {
       waitFor = PR_INTERVAL_NO_TIMEOUT;
       TimeStamp now = TimeStamp::Now();
-      nsTimerImpl *timer = nullptr;
+      nsTimerImpl* timer = nullptr;
 
       if (!mTimers.IsEmpty()) {
         timer = mTimers[0];
 
         if (now >= timer->mTimeout || forceRunThisTimer) {
     next:
           // NB: AddRef before the Release under RemoveTimerInternal to avoid
           // mRefCnt passing through zero, in case all other refs than the one
@@ -268,18 +276,19 @@ NS_IMETHODIMP TimerThread::Run()
               // is from the timer thread) and when it hits this will remove the
               // timer from the timer thread and thus destroy the last reference,
               // preventing this situation from occurring.
               MOZ_ASSERT(rc != 0, "destroyed timer off its target thread!");
             }
             timer = nullptr;
           }
 
-          if (mShutdown)
+          if (mShutdown) {
             break;
+          }
 
           // Update now, as PostTimerEvent plus the locking may have taken a
           // tick or two, and we may goto next below.
           now = TimeStamp::Now();
         }
       }
 
       if (!mTimers.IsEmpty()) {
@@ -289,36 +298,39 @@ NS_IMETHODIMP TimerThread::Run()
 
         // Don't wait at all (even for PR_INTERVAL_NO_WAIT) if the next timer
         // is due now or overdue.
         //
         // Note that we can only sleep for integer values of a certain
         // resolution. We use halfMicrosecondsIntervalResolution, calculated
         // before, to do the optimal rounding (i.e., of how to decide what
         // interval is so small we should not wait at all).
-        double microseconds = (timeout - now).ToMilliseconds()*1000;
+        double microseconds = (timeout - now).ToMilliseconds() * 1000;
 
         if (ChaosMode::isActive()) {
           // The mean value of sFractions must be 1 to ensure that
           // the average of a long sequence of timeouts converges to the
           // actual sum of their times.
           static const float sFractions[] = {
             0.0f, 0.25f, 0.5f, 0.75f, 1.0f, 1.75f, 2.75f
           };
-          microseconds *= sFractions[ChaosMode::randomUint32LessThan(ArrayLength(sFractions))];
+          microseconds *=
+            sFractions[ChaosMode::randomUint32LessThan(ArrayLength(sFractions))];
           forceRunNextTimer = true;
         }
 
         if (microseconds < halfMicrosecondsIntervalResolution) {
           forceRunNextTimer = false;
           goto next; // round down; execute event now
         }
-        waitFor = PR_MicrosecondsToInterval(static_cast<uint32_t>(microseconds)); // Floor is accurate enough.
-        if (waitFor == 0)
-          waitFor = 1; // round up, wait the minimum time we can wait
+        waitFor = PR_MicrosecondsToInterval(
+          static_cast<uint32_t>(microseconds)); // Floor is accurate enough.
+        if (waitFor == 0) {
+          waitFor = 1;  // round up, wait the minimum time we can wait
+        }
       }
 
 #ifdef DEBUG_TIMERS
       if (PR_LOG_TEST(GetTimerLog(), PR_LOG_DEBUG)) {
         if (waitFor == PR_INTERVAL_NO_TIMEOUT)
           PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
                  ("waiting for PR_INTERVAL_NO_TIMEOUT\n"));
         else
@@ -335,143 +347,159 @@ NS_IMETHODIMP TimerThread::Run()
       forceRunNextTimer = false;
     }
     mWaiting = false;
   }
 
   return NS_OK;
 }
 
-nsresult TimerThread::AddTimer(nsTimerImpl *aTimer)
+nsresult
+TimerThread::AddTimer(nsTimerImpl* aTimer)
 {
   MonitorAutoLock lock(mMonitor);
 
   // Add the timer to our list.
   int32_t i = AddTimerInternal(aTimer);
-  if (i < 0)
+  if (i < 0) {
     return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   // Awaken the timer thread.
   if (mWaiting && i == 0) {
     mNotified = true;
     mMonitor.Notify();
   }
 
   return NS_OK;
 }
 
-nsresult TimerThread::TimerDelayChanged(nsTimerImpl *aTimer)
+nsresult
+TimerThread::TimerDelayChanged(nsTimerImpl* aTimer)
 {
   MonitorAutoLock lock(mMonitor);
 
   // Our caller has a strong ref to aTimer, so it can't go away here under
   // ReleaseTimerInternal.
   RemoveTimerInternal(aTimer);
 
   int32_t i = AddTimerInternal(aTimer);
-  if (i < 0)
+  if (i < 0) {
     return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   // Awaken the timer thread.
   if (mWaiting && i == 0) {
     mNotified = true;
     mMonitor.Notify();
   }
 
   return NS_OK;
 }
 
-nsresult TimerThread::RemoveTimer(nsTimerImpl *aTimer)
+nsresult
+TimerThread::RemoveTimer(nsTimerImpl* aTimer)
 {
   MonitorAutoLock lock(mMonitor);
 
   // Remove the timer from our array.  Tell callers that aTimer was not found
   // by returning NS_ERROR_NOT_AVAILABLE.  Unlike the TimerDelayChanged case
   // immediately above, our caller may be passing a (now-)weak ref in via the
   // aTimer param, specifically when nsTimerImpl::Release loses a race with
   // TimerThread::Run, must wait for the mMonitor auto-lock here, and during the
   // wait Run drops the only remaining ref to aTimer via RemoveTimerInternal.
 
-  if (!RemoveTimerInternal(aTimer))
+  if (!RemoveTimerInternal(aTimer)) {
     return NS_ERROR_NOT_AVAILABLE;
+  }
 
   // Awaken the timer thread.
   if (mWaiting) {
     mNotified = true;
     mMonitor.Notify();
   }
 
   return NS_OK;
 }
 
 // This function must be called from within a lock
-int32_t TimerThread::AddTimerInternal(nsTimerImpl *aTimer)
+int32_t
+TimerThread::AddTimerInternal(nsTimerImpl* aTimer)
 {
-  if (mShutdown)
+  if (mShutdown) {
     return -1;
+  }
 
   TimeStamp now = TimeStamp::Now();
 
   TimerAdditionComparator c(now, aTimer);
   nsTimerImpl** insertSlot = mTimers.InsertElementSorted(aTimer, c);
 
-  if (!insertSlot)
+  if (!insertSlot) {
     return -1;
+  }
 
   aTimer->mArmed = true;
   NS_ADDREF(aTimer);
 
 #ifdef MOZ_TASK_TRACER
   aTimer->DispatchTracedTask();
 #endif
 
   return insertSlot - mTimers.Elements();
 }
 
-bool TimerThread::RemoveTimerInternal(nsTimerImpl *aTimer)
+bool
+TimerThread::RemoveTimerInternal(nsTimerImpl* aTimer)
 {
-  if (!mTimers.RemoveElement(aTimer))
+  if (!mTimers.RemoveElement(aTimer)) {
     return false;
+  }
 
   ReleaseTimerInternal(aTimer);
   return true;
 }
 
-void TimerThread::ReleaseTimerInternal(nsTimerImpl *aTimer)
+void
+TimerThread::ReleaseTimerInternal(nsTimerImpl* aTimer)
 {
   // Order is crucial here -- see nsTimerImpl::Release.
   aTimer->mArmed = false;
   NS_RELEASE(aTimer);
 }
 
-void TimerThread::DoBeforeSleep()
+void
+TimerThread::DoBeforeSleep()
 {
   mSleeping = true;
 }
 
-void TimerThread::DoAfterSleep()
+void
+TimerThread::DoAfterSleep()
 {
   mSleeping = true; // wake may be notified without preceding sleep notification
   for (uint32_t i = 0; i < mTimers.Length(); i ++) {
-    nsTimerImpl *timer = mTimers[i];
+    nsTimerImpl* timer = mTimers[i];
     // get and set the delay to cause its timeout to be recomputed
     uint32_t delay;
     timer->GetDelay(&delay);
     timer->SetDelay(delay);
   }
 
   mSleeping = false;
 }
 
 
 /* void observe (in nsISupports aSubject, in string aTopic, in wstring aData); */
 NS_IMETHODIMP
-TimerThread::Observe(nsISupports* /* aSubject */, const char *aTopic, const char16_t* /* aData */)
+TimerThread::Observe(nsISupports* /* aSubject */, const char* aTopic,
+                     const char16_t* /* aData */)
 {
   if (strcmp(aTopic, "sleep_notification") == 0 ||
-      strcmp(aTopic, "suspend_process_notification") == 0)
+      strcmp(aTopic, "suspend_process_notification") == 0) {
     DoBeforeSleep();
-  else if (strcmp(aTopic, "wake_notification") == 0 ||
-           strcmp(aTopic, "resume_process_notification") == 0)
+  } else if (strcmp(aTopic, "wake_notification") == 0 ||
+             strcmp(aTopic, "resume_process_notification") == 0) {
     DoAfterSleep();
+  }
 
   return NS_OK;
 }
--- a/xpcom/threads/TimerThread.h
+++ b/xpcom/threads/TimerThread.h
@@ -18,37 +18,38 @@
 #include "mozilla/Atomics.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Monitor.h"
 
 namespace mozilla {
 class TimeStamp;
 }
 
-class TimerThread MOZ_FINAL : public nsIRunnable,
-                              public nsIObserver
+class TimerThread MOZ_FINAL
+  : public nsIRunnable
+  , public nsIObserver
 {
 public:
   typedef mozilla::Monitor Monitor;
   typedef mozilla::TimeStamp TimeStamp;
   typedef mozilla::TimeDuration TimeDuration;
 
   TimerThread();
   NS_HIDDEN_(nsresult) InitLocks();
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIRUNNABLE
   NS_DECL_NSIOBSERVER
 
   NS_HIDDEN_(nsresult) Init();
   NS_HIDDEN_(nsresult) Shutdown();
 
-  nsresult AddTimer(nsTimerImpl *aTimer);
-  nsresult TimerDelayChanged(nsTimerImpl *aTimer);
-  nsresult RemoveTimer(nsTimerImpl *aTimer);
+  nsresult AddTimer(nsTimerImpl* aTimer);
+  nsresult TimerDelayChanged(nsTimerImpl* aTimer);
+  nsresult RemoveTimer(nsTimerImpl* aTimer);
 
   void DoBeforeSleep();
   void DoAfterSleep();
 
   bool IsOnTimerThread() const
   {
     return mThread == NS_GetCurrentThread();
   }
@@ -57,52 +58,56 @@ private:
   ~TimerThread();
 
   mozilla::Atomic<bool> mInitInProgress;
   bool    mInitialized;
 
   // These two internal helper methods must be called while mLock is held.
   // AddTimerInternal returns the position where the timer was added in the
   // list, or -1 if it failed.
-  int32_t AddTimerInternal(nsTimerImpl *aTimer);
-  bool    RemoveTimerInternal(nsTimerImpl *aTimer);
-  void    ReleaseTimerInternal(nsTimerImpl *aTimer);
+  int32_t AddTimerInternal(nsTimerImpl* aTimer);
+  bool    RemoveTimerInternal(nsTimerImpl* aTimer);
+  void    ReleaseTimerInternal(nsTimerImpl* aTimer);
 
   nsCOMPtr<nsIThread> mThread;
   Monitor mMonitor;
 
   bool mShutdown;
   bool mWaiting;
   bool mNotified;
   bool mSleeping;
 
   nsTArray<nsTimerImpl*> mTimers;
 };
 
-struct TimerAdditionComparator {
-  TimerAdditionComparator(const mozilla::TimeStamp &aNow,
-                          nsTimerImpl *aTimerToInsert) :
+struct TimerAdditionComparator
+{
+  TimerAdditionComparator(const mozilla::TimeStamp& aNow,
+                          nsTimerImpl* aTimerToInsert) :
     now(aNow)
 #ifdef DEBUG
     , timerToInsert(aTimerToInsert)
 #endif
-  {}
+  {
+  }
 
-  bool LessThan(nsTimerImpl *fromArray, nsTimerImpl *newTimer) const {
-    NS_ABORT_IF_FALSE(newTimer == timerToInsert, "Unexpected timer ordering");
+  bool LessThan(nsTimerImpl* aFromArray, nsTimerImpl* aNewTimer) const
+  {
+    NS_ABORT_IF_FALSE(aNewTimer == timerToInsert, "Unexpected timer ordering");
 
     // Skip any overdue timers.
-    return fromArray->mTimeout <= now ||
-           fromArray->mTimeout <= newTimer->mTimeout;
+    return aFromArray->mTimeout <= now ||
+           aFromArray->mTimeout <= aNewTimer->mTimeout;
   }
 
-  bool Equals(nsTimerImpl* fromArray, nsTimerImpl* newTimer) const {
+  bool Equals(nsTimerImpl* aFromArray, nsTimerImpl* aNewTimer) const
+  {
     return false;
   }
 
 private:
-  const mozilla::TimeStamp &now;
+  const mozilla::TimeStamp& now;
 #ifdef DEBUG
-  const nsTimerImpl * const timerToInsert;
+  const nsTimerImpl* const timerToInsert;
 #endif
 };
 
 #endif /* TimerThread_h___ */
--- a/xpcom/threads/nsEnvironment.cpp
+++ b/xpcom/threads/nsEnvironment.cpp
@@ -1,9 +1,10 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsEnvironment.h"
 #include "prenv.h"
 #include "prprf.h"
 #include "nsBaseHashtable.h"
@@ -12,149 +13,154 @@
 #include "nsDependentString.h"
 #include "nsNativeCharsetUtils.h"
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS(nsEnvironment, nsIEnvironment)
 
 nsresult
-nsEnvironment::Create(nsISupports *aOuter, REFNSIID aIID,
-                      void **aResult)
+nsEnvironment::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 {
-    nsresult rv;
-    *aResult = nullptr;
+  nsresult rv;
+  *aResult = nullptr;
 
-    if (aOuter != nullptr) {
-        return NS_ERROR_NO_AGGREGATION;
-    }
+  if (aOuter) {
+    return NS_ERROR_NO_AGGREGATION;
+  }
 
-    nsEnvironment* obj = new nsEnvironment();
-    if (!obj) {
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
+  nsEnvironment* obj = new nsEnvironment();
+  if (!obj) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
-    rv = obj->QueryInterface(aIID, aResult);
-    if (NS_FAILED(rv)) {
-      delete obj;
-    }
-    return rv;
+  rv = obj->QueryInterface(aIID, aResult);
+  if (NS_FAILED(rv)) {
+    delete obj;
+  }
+  return rv;
 }
 
 nsEnvironment::~nsEnvironment()
 {
 }
 
 NS_IMETHODIMP
-nsEnvironment::Exists(const nsAString& aName, bool *aOutValue)
+nsEnvironment::Exists(const nsAString& aName, bool* aOutValue)
 {
-    nsAutoCString nativeName;
-    nsresult rv = NS_CopyUnicodeToNative(aName, nativeName);
-    if (NS_WARN_IF(NS_FAILED(rv)))
-        return rv;
+  nsAutoCString nativeName;
+  nsresult rv = NS_CopyUnicodeToNative(aName, nativeName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
 
-    nsAutoCString nativeVal;
+  nsAutoCString nativeVal;
 #if defined(XP_UNIX)
-    /* For Unix/Linux platforms we follow the Unix definition:
-     * An environment variable exists when |getenv()| returns a non-nullptr
-     * value. An environment variable does not exist when |getenv()| returns
-     * nullptr.
-     */
-    const char *value = PR_GetEnv(nativeName.get());
-    *aOutValue = value && *value;
+  /* For Unix/Linux platforms we follow the Unix definition:
+   * An environment variable exists when |getenv()| returns a non-nullptr
+   * value. An environment variable does not exist when |getenv()| returns
+   * nullptr.
+   */
+  const char* value = PR_GetEnv(nativeName.get());
+  *aOutValue = value && *value;
 #else
-    /* For non-Unix/Linux platforms we have to fall back to a 
-     * "portable" definition (which is incorrect for Unix/Linux!!!!)
-     * which simply checks whether the string returned by |Get()| is empty
-     * or not.
-     */
-    nsAutoString value;
-    Get(aName, value);
-    *aOutValue = !value.IsEmpty();
+  /* For non-Unix/Linux platforms we have to fall back to a
+   * "portable" definition (which is incorrect for Unix/Linux!!!!)
+   * which simply checks whether the string returned by |Get()| is empty
+   * or not.
+   */
+  nsAutoString value;
+  Get(aName, value);
+  *aOutValue = !value.IsEmpty();
 #endif /* XP_UNIX */
 
-    return NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsEnvironment::Get(const nsAString& aName, nsAString& aOutValue)
 {
-    nsAutoCString nativeName;
-    nsresult rv = NS_CopyUnicodeToNative(aName, nativeName);
-    if (NS_WARN_IF(NS_FAILED(rv)))
-        return rv;
+  nsAutoCString nativeName;
+  nsresult rv = NS_CopyUnicodeToNative(aName, nativeName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
 
-    nsAutoCString nativeVal;
-    const char *value = PR_GetEnv(nativeName.get());
-    if (value && *value) {
-        rv = NS_CopyNativeToUnicode(nsDependentCString(value), aOutValue);
-    } else {
-        aOutValue.Truncate();
-        rv = NS_OK;
-    }
+  nsAutoCString nativeVal;
+  const char* value = PR_GetEnv(nativeName.get());
+  if (value && *value) {
+    rv = NS_CopyNativeToUnicode(nsDependentCString(value), aOutValue);
+  } else {
+    aOutValue.Truncate();
+    rv = NS_OK;
+  }
 
-    return rv;
+  return rv;
 }
 
 /* Environment strings must have static duration; We're gonna leak all of this
  * at shutdown: this is by design, caused how Unix/Linux implement environment
- * vars. 
+ * vars.
  */
 
-typedef nsBaseHashtableET<nsCharPtrHashKey,char*> EnvEntryType;
+typedef nsBaseHashtableET<nsCharPtrHashKey, char*> EnvEntryType;
 typedef nsTHashtable<EnvEntryType> EnvHashType;
 
-static EnvHashType *gEnvHash = nullptr;
+static EnvHashType* gEnvHash = nullptr;
 
 static bool
 EnsureEnvHash()
 {
-    if (gEnvHash)
-        return true;
+  if (gEnvHash) {
+    return true;
+  }
 
-    gEnvHash = new EnvHashType;
-    if (!gEnvHash)
-        return false;
+  gEnvHash = new EnvHashType;
+  if (!gEnvHash) {
+    return false;
+  }
 
-    return true;
+  return true;
 }
 
 NS_IMETHODIMP
 nsEnvironment::Set(const nsAString& aName, const nsAString& aValue)
 {
-    nsAutoCString nativeName;
-    nsAutoCString nativeVal;
+  nsAutoCString nativeName;
+  nsAutoCString nativeVal;
 
-    nsresult rv = NS_CopyUnicodeToNative(aName, nativeName);
-    if (NS_WARN_IF(NS_FAILED(rv)))
-        return rv;
+  nsresult rv = NS_CopyUnicodeToNative(aName, nativeName);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
 
-    rv = NS_CopyUnicodeToNative(aValue, nativeVal);
-    if (NS_WARN_IF(NS_FAILED(rv)))
-        return rv;
+  rv = NS_CopyUnicodeToNative(aValue, nativeVal);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
 
-    MutexAutoLock lock(mLock);
+  MutexAutoLock lock(mLock);
 
-    if (!EnsureEnvHash()){
-        return NS_ERROR_UNEXPECTED;
-    }
+  if (!EnsureEnvHash()) {
+    return NS_ERROR_UNEXPECTED;
+  }
 
-    EnvEntryType* entry = gEnvHash->PutEntry(nativeName.get());
-    if (!entry) {
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
-    
-    char* newData = PR_smprintf("%s=%s",
-                                nativeName.get(),
-                                nativeVal.get());
-    if (!newData) {
-        return NS_ERROR_OUT_OF_MEMORY;
-    } 
-    
-    PR_SetEnv(newData);
-    if (entry->mData) {
-        PR_smprintf_free(entry->mData);
-    }
-    entry->mData = newData;
-    return NS_OK;
+  EnvEntryType* entry = gEnvHash->PutEntry(nativeName.get());
+  if (!entry) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  char* newData = PR_smprintf("%s=%s",
+                              nativeName.get(),
+                              nativeVal.get());
+  if (!newData) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+
+  PR_SetEnv(newData);
+  if (entry->mData) {
+    PR_smprintf_free(entry->mData);
+  }
+  entry->mData = newData;
+  return NS_OK;
 }
 
 
--- a/xpcom/threads/nsEnvironment.h
+++ b/xpcom/threads/nsEnvironment.h
@@ -1,9 +1,10 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsEnvironment_h__
 #define nsEnvironment_h__
 
 #include "mozilla/Attributes.h"
@@ -13,22 +14,23 @@
 #define NS_ENVIRONMENT_CID \
   { 0X3D68F92UL, 0X9513, 0X4E25, \
   { 0X9B, 0XE9, 0X7C, 0XB2, 0X39, 0X87, 0X41, 0X72 } }
 #define NS_ENVIRONMENT_CONTRACTID "@mozilla.org/process/environment;1"
 
 class nsEnvironment MOZ_FINAL : public nsIEnvironment
 {
 public:
-    NS_DECL_THREADSAFE_ISUPPORTS
-    NS_DECL_NSIENVIRONMENT
+  NS_DECL_THREADSAFE_ISUPPORTS
+  NS_DECL_NSIENVIRONMENT
 
-    static nsresult Create(nsISupports *aOuter, REFNSIID aIID,
-                           void **aResult);
+  static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
 
 private:
-    nsEnvironment() : mLock("nsEnvironment.mLock") { }
-    ~nsEnvironment();
+  nsEnvironment() : mLock("nsEnvironment.mLock")
+  {
+  }
+  ~nsEnvironment();
 
-    mozilla::Mutex mLock;
+  mozilla::Mutex mLock;
 };
 
 #endif /* !nsEnvironment_h__ */
--- a/xpcom/threads/nsEventQueue.cpp
+++ b/xpcom/threads/nsEventQueue.cpp
@@ -9,22 +9,23 @@
 #include "prlog.h"
 #include "nsThreadUtils.h"
 #include "prthread.h"
 #include "mozilla/ChaosMode.h"
 
 using namespace mozilla;
 
 #ifdef PR_LOGGING
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetLog()
 {
-  static PRLogModuleInfo *sLog;
-  if (!sLog)
+  static PRLogModuleInfo* sLog;
+  if (!sLog) {
     sLog = PR_NewLogModule("nsEventQueue");
+  }
   return sLog;
 }
 #endif
 #ifdef LOG
 #undef LOG
 #endif
 #define LOG(args) PR_LOG(GetLog(), PR_LOG_DEBUG, args)
 
@@ -36,45 +37,48 @@ nsEventQueue::nsEventQueue()
   , mOffsetTail(0)
 {
 }
 
 nsEventQueue::~nsEventQueue()
 {
   // It'd be nice to be able to assert that no one else is holding the monitor,
   // but NSPR doesn't really expose APIs for it.
-  NS_ASSERTION(IsEmpty(), "Non-empty event queue being destroyed; events being leaked.");
+  NS_ASSERTION(IsEmpty(),
+               "Non-empty event queue being destroyed; events being leaked.");
 
-  if (mHead)
+  if (mHead) {
     FreePage(mHead);
+  }
 }
 
 bool
-nsEventQueue::GetEvent(bool mayWait, nsIRunnable **result)
+nsEventQueue::GetEvent(bool aMayWait, nsIRunnable** aResult)
 {
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
-    
+
     while (IsEmpty()) {
-      if (!mayWait) {
-        if (result)
-          *result = nullptr;
+      if (!aMayWait) {
+        if (aResult) {
+          *aResult = nullptr;
+        }
         return false;
       }
-      LOG(("EVENTQ(%p): wait begin\n", this)); 
+      LOG(("EVENTQ(%p): wait begin\n", this));
       mon.Wait();
-      LOG(("EVENTQ(%p): wait end\n", this)); 
+      LOG(("EVENTQ(%p): wait end\n", this));
     }
-    
-    if (result) {
-      *result = mHead->mEvents[mOffsetHead++];
-      
+
+    if (aResult) {
+      *aResult = mHead->mEvents[mOffsetHead++];
+
       // Check if mHead points to empty Page
       if (mOffsetHead == EVENTS_PER_PAGE) {
-        Page *dead = mHead;
+        Page* dead = mHead;
         mHead = mHead->mNext;
         FreePage(dead);
         mOffsetHead = 0;
       }
     }
   }
 
   return true;
--- a/xpcom/threads/nsEventQueue.h
+++ b/xpcom/threads/nsEventQueue.h
@@ -18,69 +18,79 @@ class nsEventQueue
 
 public:
   nsEventQueue();
   ~nsEventQueue();
 
   // This method adds a new event to the pending event queue.  The queue holds
   // a strong reference to the event after this method returns.  This method
   // cannot fail.
-  void PutEvent(nsIRunnable *event);
+  void PutEvent(nsIRunnable* aEvent);
 
   // This method gets an event from the event queue.  If mayWait is true, then
   // the method will block the calling thread until an event is available.  If
   // the event is null, then the method returns immediately indicating whether
   // or not an event is pending.  When the resulting event is non-null, the
   // caller is responsible for releasing the event object.  This method does
   // not alter the reference count of the resulting event.
-  bool GetEvent(bool mayWait, nsIRunnable **event);
+  bool GetEvent(bool aMayWait, nsIRunnable** aEvent);
 
   // This method returns true if there is a pending event.
-  bool HasPendingEvent() {
+  bool HasPendingEvent()
+  {
     return GetEvent(false, nullptr);
   }
 
   // This method returns the next pending event or null.
-  bool GetPendingEvent(nsIRunnable **runnable) {
+  bool GetPendingEvent(nsIRunnable** runnable)
+  {
     return GetEvent(false, runnable);
   }
 
   // Expose the event queue's monitor for "power users"
-  ReentrantMonitor& GetReentrantMonitor() {
+  ReentrantMonitor& GetReentrantMonitor()
+  {
     return mReentrantMonitor;
   }
 
 private:
 
-  bool IsEmpty() {
+  bool IsEmpty()
+  {
     return !mHead || (mHead == mTail && mOffsetHead == mOffsetTail);
   }
 
-  enum { EVENTS_PER_PAGE = 255 };
+  enum
+  {
+    EVENTS_PER_PAGE = 255
+  };
 
   // Page objects are linked together to form a simple deque.
 
-  struct Page {
-    struct Page *mNext;
-    nsIRunnable *mEvents[EVENTS_PER_PAGE];
+  struct Page
+  {
+    struct Page* mNext;
+    nsIRunnable* mEvents[EVENTS_PER_PAGE];
   };
 
   static_assert((sizeof(Page) & (sizeof(Page) - 1)) == 0,
                 "sizeof(Page) should be a power of two to avoid heap slop.");
 
-  static Page *NewPage() {
-    return static_cast<Page *>(moz_xcalloc(1, sizeof(Page)));
+  static Page* NewPage()
+  {
+    return static_cast<Page*>(moz_xcalloc(1, sizeof(Page)));
   }
 
-  static void FreePage(Page *p) {
-    free(p);
+  static void FreePage(Page* aPage)
+  {
+    free(aPage);
   }
 
   ReentrantMonitor mReentrantMonitor;
 
-  Page *mHead;
-  Page *mTail;
+  Page* mHead;
+  Page* mTail;
 
   uint16_t mOffsetHead;  // offset into mHead where next item is removed
   uint16_t mOffsetTail;  // offset into mTail where next item is added
 };
 
 #endif  // nsEventQueue_h__
--- a/xpcom/threads/nsMemoryPressure.cpp
+++ b/xpcom/threads/nsMemoryPressure.cpp
@@ -19,35 +19,36 @@ static_assert(MemPressure_None == 0,
 MemoryPressureState
 NS_GetPendingMemoryPressure()
 {
   int32_t value = sMemoryPressurePending.exchange(MemPressure_None);
   return MemoryPressureState(value);
 }
 
 void
-NS_DispatchEventualMemoryPressure(MemoryPressureState state)
+NS_DispatchEventualMemoryPressure(MemoryPressureState aState)
 {
   /*
    * A new memory pressure event erases an ongoing memory pressure, but an
    * existing "new" memory pressure event takes precedence over a new "ongoing"
    * memory pressure event.
    */
-  switch (state) {
+  switch (aState) {
     case MemPressure_None:
       sMemoryPressurePending = MemPressure_None;
       break;
     case MemPressure_New:
       sMemoryPressurePending = MemPressure_New;
       break;
     case MemPressure_Ongoing:
-      sMemoryPressurePending.compareExchange(MemPressure_None, MemPressure_Ongoing);
+      sMemoryPressurePending.compareExchange(MemPressure_None,
+                                             MemPressure_Ongoing);
       break;
   }
 }
 
 nsresult
-NS_DispatchMemoryPressure(MemoryPressureState state)
+NS_DispatchMemoryPressure(MemoryPressureState aState)
 {
-  NS_DispatchEventualMemoryPressure(state);
+  NS_DispatchEventualMemoryPressure(aState);
   nsCOMPtr<nsIRunnable> event = new nsRunnable;
   return NS_DispatchToMainThread(event);
 }
--- a/xpcom/threads/nsMemoryPressure.h
+++ b/xpcom/threads/nsMemoryPressure.h
@@ -4,17 +4,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsMemoryPressure_h__
 #define nsMemoryPressure_h__
 
 #include "nscore.h"
 
-enum MemoryPressureState {
+enum MemoryPressureState
+{
   /*
    * No memory pressure.
    */
   MemPressure_None = 0,
 
   /*
    * New memory pressure deteced.
    *
@@ -54,23 +55,23 @@ NS_GetPendingMemoryPressure();
  * before processing the next event, but if there are no events pending in
  * the main thread's event queue, the memory pressure event would not be
  * dispatched until one is enqueued. It is infallible and does not allocate
  * any memory.
  *
  * You may call this function from any thread.
  */
 void
-NS_DispatchEventualMemoryPressure(MemoryPressureState state);
+NS_DispatchEventualMemoryPressure(MemoryPressureState aState);
 
 /**
  * This function causes the main thread to fire a memory pressure event
  * before processing the next event. We wake up the main thread by adding a
  * dummy event to its event loop, so, unlike with
  * NS_DispatchEventualMemoryPressure, this memory-pressure event is always
  * fired relatively quickly, even if the event loop is otherwise empty.
  *
  * You may call this function from any thread.
  */
 nsresult
-NS_DispatchMemoryPressure(MemoryPressureState state);
+NS_DispatchMemoryPressure(MemoryPressureState aState);
 
 #endif // nsMemoryPressure_h__
--- a/xpcom/threads/nsProcess.h
+++ b/xpcom/threads/nsProcess.h
@@ -26,40 +26,41 @@
 #include <windows.h>
 #include <shellapi.h>
 #endif
 
 #define NS_PROCESS_CID \
 {0x7b4eeb20, 0xd781, 0x11d4, \
    {0x8A, 0x83, 0x00, 0x10, 0xa4, 0xe0, 0xc9, 0xca}}
 
-class nsProcess MOZ_FINAL : public nsIProcess,
-                            public nsIObserver
+class nsProcess MOZ_FINAL
+  : public nsIProcess
+  , public nsIObserver
 {
 public:
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIPROCESS
   NS_DECL_NSIOBSERVER
 
   nsProcess();
 
 private:
   ~nsProcess();
-  static void Monitor(void *arg);
+  static void Monitor(void* aArg);
   void ProcessComplete();
-  nsresult CopyArgsAndRunProcess(bool blocking, const char** args,
-                                 uint32_t count, nsIObserver* observer,
-                                 bool holdWeak);
-  nsresult CopyArgsAndRunProcessw(bool blocking, const char16_t** args,
-                                  uint32_t count, nsIObserver* observer,
-                                  bool holdWeak);
+  nsresult CopyArgsAndRunProcess(bool aBlocking, const char** aArgs,
+                                 uint32_t aCount, nsIObserver* aObserver,
+                                 bool aHoldWeak);
+  nsresult CopyArgsAndRunProcessw(bool aBlocking, const char16_t** aArgs,
+                                  uint32_t aCount, nsIObserver* aObserver,
+                                  bool aHoldWeak);
   // The 'args' array is null-terminated.
-  nsresult RunProcess(bool blocking, char **args, nsIObserver* observer,
-                      bool holdWeak, bool argsUTF8);
+  nsresult RunProcess(bool aBlocking, char** aArgs, nsIObserver* aObserver,
+                      bool aHoldWeak, bool aArgsUTF8);
 
   PRThread* mThread;
   mozilla::Mutex mLock;
   bool mShutdown;
   bool mBlocking;
 
   nsCOMPtr<nsIFile> mExecutable;
   nsString mTargetPath;
@@ -68,13 +69,13 @@ private:
   nsWeakPtr mWeakObserver;
 
   // These members are modified by multiple threads, any accesses should be
   // protected with mLock.
   int32_t mExitValue;
 #if defined(PROCESSMODEL_WINAPI)
   HANDLE mProcess;
 #elif !defined(XP_MACOSX)
-  PRProcess *mProcess;
+  PRProcess* mProcess;
 #endif
 };
 
 #endif
--- a/xpcom/threads/nsProcessCommon.cpp
+++ b/xpcom/threads/nsProcessCommon.cpp
@@ -1,15 +1,16 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*****************************************************************************
- * 
+ *
  * nsProcess is used to execute new processes and specify if you want to
  * wait (blocking) or continue (non-blocking).
  *
  *****************************************************************************
  */
 
 #include "mozilla/ArrayUtils.h"
 
@@ -41,578 +42,615 @@
 #include <signal.h>
 #endif
 
 using namespace mozilla;
 
 #ifdef XP_MACOSX
 cpu_type_t pref_cpu_types[2] = {
 #if defined(__i386__)
-                                 CPU_TYPE_X86,
+  CPU_TYPE_X86,
 #elif defined(__x86_64__)
-                                 CPU_TYPE_X86_64,
+  CPU_TYPE_X86_64,
 #elif defined(__ppc__)
-                                 CPU_TYPE_POWERPC,
+  CPU_TYPE_POWERPC,
 #endif
-                                 CPU_TYPE_ANY };
+  CPU_TYPE_ANY
+};
 #endif
 
 //-------------------------------------------------------------------//
 // nsIProcess implementation
 //-------------------------------------------------------------------//
 NS_IMPL_ISUPPORTS(nsProcess, nsIProcess,
                   nsIObserver)
 
 //Constructor
 nsProcess::nsProcess()
-    : mThread(nullptr)
-    , mLock("nsProcess.mLock")
-    , mShutdown(false)
-    , mBlocking(false)
-    , mPid(-1)
-    , mObserver(nullptr)
-    , mWeakObserver(nullptr)
-    , mExitValue(-1)
+  : mThread(nullptr)
+  , mLock("nsProcess.mLock")
+  , mShutdown(false)
+  , mBlocking(false)
+  , mPid(-1)
+  , mObserver(nullptr)
+  , mWeakObserver(nullptr)
+  , mExitValue(-1)
 #if !defined(XP_MACOSX)
-    , mProcess(nullptr)
+  , mProcess(nullptr)
 #endif
 {
 }
 
 //Destructor
 nsProcess::~nsProcess()
 {
 }
 
 NS_IMETHODIMP
-nsProcess::Init(nsIFile* executable)
+nsProcess::Init(nsIFile* aExecutable)
 {
-    if (mExecutable)
-        return NS_ERROR_ALREADY_INITIALIZED;
+  if (mExecutable) {
+    return NS_ERROR_ALREADY_INITIALIZED;
+  }
 
-    if (NS_WARN_IF(!executable))
-        return NS_ERROR_INVALID_ARG;
-    bool isFile;
+  if (NS_WARN_IF(!aExecutable)) {
+    return NS_ERROR_INVALID_ARG;
+  }
+  bool isFile;
 
-    //First make sure the file exists
-    nsresult rv = executable->IsFile(&isFile);
-    if (NS_FAILED(rv)) return rv;
-    if (!isFile)
-        return NS_ERROR_FAILURE;
+  //First make sure the file exists
+  nsresult rv = aExecutable->IsFile(&isFile);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  if (!isFile) {
+    return NS_ERROR_FAILURE;
+  }
 
-    //Store the nsIFile in mExecutable
-    mExecutable = executable;
-    //Get the path because it is needed by the NSPR process creation
-#ifdef XP_WIN 
-    rv = mExecutable->GetTarget(mTargetPath);
-    if (NS_FAILED(rv) || mTargetPath.IsEmpty() )
+  //Store the nsIFile in mExecutable
+  mExecutable = aExecutable;
+  //Get the path because it is needed by the NSPR process creation
+#ifdef XP_WIN
+  rv = mExecutable->GetTarget(mTargetPath);
+  if (NS_FAILED(rv) || mTargetPath.IsEmpty())
 #endif
-        rv = mExecutable->GetPath(mTargetPath);
+    rv = mExecutable->GetPath(mTargetPath);
 
-    return rv;
+  return rv;
 }
 
 
 #if defined(XP_WIN)
-// Out param `wideCmdLine` must be PR_Freed by the caller.
-static int assembleCmdLine(char *const *argv, wchar_t **wideCmdLine,
-                           UINT codePage)
+// Out param `aWideCmdLine` must be PR_Freed by the caller.
+static int
+assembleCmdLine(char* const* aArgv, wchar_t** aWideCmdLine, UINT aCodePage)
 {
-    char *const *arg;
-    char *p, *q, *cmdLine;
-    int cmdLineSize;
-    int numBackslashes;
-    int i;
-    int argNeedQuotes;
+  char* const* arg;
+  char* p;
+  char* q;
+  char* cmdLine;
+  int cmdLineSize;
+  int numBackslashes;
+  int i;
+  int argNeedQuotes;
 
+  /*
+   * Find out how large the command line buffer should be.
+   */
+  cmdLineSize = 0;
+  for (arg = aArgv; *arg; ++arg) {
     /*
-     * Find out how large the command line buffer should be.
+     * \ and " need to be escaped by a \.  In the worst case,
+     * every character is a \ or ", so the string of length
+     * may double.  If we quote an argument, that needs two ".
+     * Finally, we need a space between arguments, and
+     * a null byte at the end of command line.
      */
-    cmdLineSize = 0;
-    for (arg = argv; *arg; arg++) {
-        /*
-         * \ and " need to be escaped by a \.  In the worst case,
-         * every character is a \ or ", so the string of length
-         * may double.  If we quote an argument, that needs two ".
-         * Finally, we need a space between arguments, and
-         * a null byte at the end of command line.
-         */
-        cmdLineSize += 2 * strlen(*arg)  /* \ and " need to be escaped */
-                + 2                      /* we quote every argument */
-                + 1;                     /* space in between, or final null */
+    cmdLineSize += 2 * strlen(*arg)  /* \ and " need to be escaped */
+                   + 2               /* we quote every argument */
+                   + 1;              /* space in between, or final null */
+  }
+  p = cmdLine = (char*)PR_MALLOC(cmdLineSize * sizeof(char));
+  if (!p) {
+    return -1;
+  }
+
+  for (arg = aArgv; *arg; ++arg) {
+    /* Add a space to separates the arguments */
+    if (arg != aArgv) {
+      *p++ = ' ';
     }
-    p = cmdLine = (char *) PR_MALLOC(cmdLineSize*sizeof(char));
-    if (p == nullptr) {
-        return -1;
+    q = *arg;
+    numBackslashes = 0;
+    argNeedQuotes = 0;
+
+    /* If the argument contains white space, it needs to be quoted. */
+    if (strpbrk(*arg, " \f\n\r\t\v")) {
+      argNeedQuotes = 1;
     }
 
-    for (arg = argv; *arg; arg++) {
-        /* Add a space to separates the arguments */
-        if (arg != argv) {
-            *p++ = ' '; 
-        }
-        q = *arg;
-        numBackslashes = 0;
-        argNeedQuotes = 0;
-
-        /* If the argument contains white space, it needs to be quoted. */
-        if (strpbrk(*arg, " \f\n\r\t\v")) {
-            argNeedQuotes = 1;
-        }
-
-        if (argNeedQuotes) {
-            *p++ = '"';
+    if (argNeedQuotes) {
+      *p++ = '"';
+    }
+    while (*q) {
+      if (*q == '\\') {
+        numBackslashes++;
+        q++;
+      } else if (*q == '"') {
+        if (numBackslashes) {
+          /*
+           * Double the backslashes since they are followed
+           * by a quote
+           */
+          for (i = 0; i < 2 * numBackslashes; i++) {
+            *p++ = '\\';
+          }
+          numBackslashes = 0;
         }
-        while (*q) {
-            if (*q == '\\') {
-                numBackslashes++;
-                q++;
-            } else if (*q == '"') {
-                if (numBackslashes) {
-                    /*
-                     * Double the backslashes since they are followed
-                     * by a quote
-                     */
-                    for (i = 0; i < 2 * numBackslashes; i++) {
-                        *p++ = '\\';
-                    }
-                    numBackslashes = 0;
-                }
-                /* To escape the quote */
-                *p++ = '\\';
-                *p++ = *q++;
-            } else {
-                if (numBackslashes) {
-                    /*
-                     * Backslashes are not followed by a quote, so
-                     * don't need to double the backslashes.
-                     */
-                    for (i = 0; i < numBackslashes; i++) {
-                        *p++ = '\\';
-                    }
-                    numBackslashes = 0;
-                }
-                *p++ = *q++;
-            }
+        /* To escape the quote */
+        *p++ = '\\';
+        *p++ = *q++;
+      } else {
+        if (numBackslashes) {
+          /*
+           * Backslashes are not followed by a quote, so
+           * don't need to double the backslashes.
+           */
+          for (i = 0; i < numBackslashes; i++) {
+            *p++ = '\\';
+          }
+          numBackslashes = 0;
         }
+        *p++ = *q++;
+      }
+    }
 
-        /* Now we are at the end of this argument */
-        if (numBackslashes) {
-            /*
-             * Double the backslashes if we have a quote string
-             * delimiter at the end.
-             */
-            if (argNeedQuotes) {
-                numBackslashes *= 2;
-            }
-            for (i = 0; i < numBackslashes; i++) {
-                *p++ = '\\';
-            }
-        }
-        if (argNeedQuotes) {
-            *p++ = '"';
-        }
-    } 
+    /* Now we are at the end of this argument */
+    if (numBackslashes) {
+      /*
+       * Double the backslashes if we have a quote string
+       * delimiter at the end.
+       */
+      if (argNeedQuotes) {
+        numBackslashes *= 2;
+      }
+      for (i = 0; i < numBackslashes; i++) {
+        *p++ = '\\';
+      }
+    }
+    if (argNeedQuotes) {
+      *p++ = '"';
+    }
+  }
 
-    *p = '\0';
-    int32_t numChars = MultiByteToWideChar(codePage, 0, cmdLine, -1, nullptr, 0);
-    *wideCmdLine = (wchar_t *) PR_MALLOC(numChars*sizeof(wchar_t));
-    MultiByteToWideChar(codePage, 0, cmdLine, -1, *wideCmdLine, numChars); 
-    PR_Free(cmdLine);
-    return 0;
+  *p = '\0';
+  int32_t numChars = MultiByteToWideChar(aCodePage, 0, cmdLine, -1, nullptr, 0);
+  *aWideCmdLine = (wchar_t*)PR_MALLOC(numChars * sizeof(wchar_t));
+  MultiByteToWideChar(aCodePage, 0, cmdLine, -1, *aWideCmdLine, numChars);
+  PR_Free(cmdLine);
+  return 0;
 }
 #endif
 
-void nsProcess::Monitor(void *arg)
+void
+nsProcess::Monitor(void* aArg)
 {
-    nsRefPtr<nsProcess> process = dont_AddRef(static_cast<nsProcess*>(arg));
+  nsRefPtr<nsProcess> process = dont_AddRef(static_cast<nsProcess*>(aArg));
 
-    if (!process->mBlocking)
-        PR_SetCurrentThreadName("RunProcess");
+  if (!process->mBlocking) {
+    PR_SetCurrentThreadName("RunProcess");
+  }
 
 #if defined(PROCESSMODEL_WINAPI)
-    DWORD dwRetVal;
-    unsigned long exitCode = -1;
+  DWORD dwRetVal;
+  unsigned long exitCode = -1;
 
-    dwRetVal = WaitForSingleObject(process->mProcess, INFINITE);
-    if (dwRetVal != WAIT_FAILED) {
-        if (GetExitCodeProcess(process->mProcess, &exitCode) == FALSE)
-            exitCode = -1;
+  dwRetVal = WaitForSingleObject(process->mProcess, INFINITE);
+  if (dwRetVal != WAIT_FAILED) {
+    if (GetExitCodeProcess(process->mProcess, &exitCode) == FALSE) {
+      exitCode = -1;
     }
+  }
 
-    // Lock in case Kill or GetExitCode are called during this
-    {
-        MutexAutoLock lock(process->mLock);
-        CloseHandle(process->mProcess);
-        process->mProcess = nullptr;
-        process->mExitValue = exitCode;
-        if (process->mShutdown)
-            return;
+  // Lock in case Kill or GetExitCode are called during this
+  {
+    MutexAutoLock lock(process->mLock);
+    CloseHandle(process->mProcess);
+    process->mProcess = nullptr;
+    process->mExitValue = exitCode;
+    if (process->mShutdown) {
+      return;
     }
+  }
 #else
 #ifdef XP_MACOSX
-    int exitCode = -1;
-    int status = 0;
-    if (waitpid(process->mPid, &status, 0) == process->mPid) {
-        if (WIFEXITED(status)) {
-            exitCode = WEXITSTATUS(status);
-        }
-        else if(WIFSIGNALED(status)) {
-            exitCode = 256; // match NSPR's signal exit status
-        }
+  int exitCode = -1;
+  int status = 0;
+  if (waitpid(process->mPid, &status, 0) == process->mPid) {
+    if (WIFEXITED(status)) {
+      exitCode = WEXITSTATUS(status);
+    } else if (WIFSIGNALED(status)) {
+      exitCode = 256; // match NSPR's signal exit status
     }
+  }
 #else
-    int32_t exitCode = -1;
-    if (PR_WaitProcess(process->mProcess, &exitCode) != PR_SUCCESS)
-        exitCode = -1;
-#endif
-
-    // Lock in case Kill or GetExitCode are called during this
-    {
-        MutexAutoLock lock(process->mLock);
-#if !defined(XP_MACOSX)
-        process->mProcess = nullptr;
-#endif
-        process->mExitValue = exitCode;
-        if (process->mShutdown)
-            return;
-    }
+  int32_t exitCode = -1;
+  if (PR_WaitProcess(process->mProcess, &exitCode) != PR_SUCCESS) {
+    exitCode = -1;
+  }
 #endif
 
-    // If we ran a background thread for the monitor then notify on the main
-    // thread
-    if (NS_IsMainThread()) {
-        process->ProcessComplete();
+  // Lock in case Kill or GetExitCode are called during this
+  {
+    MutexAutoLock lock(process->mLock);
+#if !defined(XP_MACOSX)
+    process->mProcess = nullptr;
+#endif
+    process->mExitValue = exitCode;
+    if (process->mShutdown) {
+      return;
     }
-    else {
-        nsCOMPtr<nsIRunnable> event =
-            NS_NewRunnableMethod(process, &nsProcess::ProcessComplete);
-        NS_DispatchToMainThread(event);
-    }
+  }
+#endif
+
+  // If we ran a background thread for the monitor then notify on the main
+  // thread
+  if (NS_IsMainThread()) {
+    process->ProcessComplete();
+  } else {
+    nsCOMPtr<nsIRunnable> event =
+      NS_NewRunnableMethod(process, &nsProcess::ProcessComplete);
+    NS_DispatchToMainThread(event);
+  }
 }
 
-void nsProcess::ProcessComplete()
+void
+nsProcess::ProcessComplete()
 {
-    if (mThread) {
-        nsCOMPtr<nsIObserverService> os =
-            mozilla::services::GetObserverService();
-        if (os)
-            os->RemoveObserver(this, "xpcom-shutdown");
-        PR_JoinThread(mThread);
-        mThread = nullptr;
+  if (mThread) {
+    nsCOMPtr<nsIObserverService> os =
+      mozilla::services::GetObserverService();
+    if (os) {
+      os->RemoveObserver(this, "xpcom-shutdown");
     }
+    PR_JoinThread(mThread);
+    mThread = nullptr;
+  }
 
-    const char* topic;
-    if (mExitValue < 0)
-        topic = "process-failed";
-    else
-        topic = "process-finished";
+  const char* topic;
+  if (mExitValue < 0) {
+    topic = "process-failed";
+  } else {
+    topic = "process-finished";
+  }
 
-    mPid = -1;
-    nsCOMPtr<nsIObserver> observer;
-    if (mWeakObserver)
-        observer = do_QueryReferent(mWeakObserver);
-    else if (mObserver)
-        observer = mObserver;
-    mObserver = nullptr;
-    mWeakObserver = nullptr;
+  mPid = -1;
+  nsCOMPtr<nsIObserver> observer;
+  if (mWeakObserver) {
+    observer = do_QueryReferent(mWeakObserver);
+  } else if (mObserver) {
+    observer = mObserver;
+  }
+  mObserver = nullptr;
+  mWeakObserver = nullptr;
 
-    if (observer)
-        observer->Observe(NS_ISUPPORTS_CAST(nsIProcess*, this), topic, nullptr);
+  if (observer) {
+    observer->Observe(NS_ISUPPORTS_CAST(nsIProcess*, this), topic, nullptr);
+  }
 }
 
-// XXXldb |args| has the wrong const-ness
-NS_IMETHODIMP  
-nsProcess::Run(bool blocking, const char **args, uint32_t count)
+// XXXldb |aArgs| has the wrong const-ness
+NS_IMETHODIMP
+nsProcess::Run(bool aBlocking, const char** aArgs, uint32_t aCount)
 {
-    return CopyArgsAndRunProcess(blocking, args, count, nullptr, false);
+  return CopyArgsAndRunProcess(aBlocking, aArgs, aCount, nullptr, false);
 }
 
-// XXXldb |args| has the wrong const-ness
-NS_IMETHODIMP  
-nsProcess::RunAsync(const char **args, uint32_t count,
-                    nsIObserver* observer, bool holdWeak)
+// XXXldb |aArgs| has the wrong const-ness
+NS_IMETHODIMP
+nsProcess::RunAsync(const char** aArgs, uint32_t aCount,
+                    nsIObserver* aObserver, bool aHoldWeak)
 {
-    return CopyArgsAndRunProcess(false, args, count, observer, holdWeak);
+  return CopyArgsAndRunProcess(false, aArgs, aCount, aObserver, aHoldWeak);
 }
 
 nsresult
-nsProcess::CopyArgsAndRunProcess(bool blocking, const char** args,
-                                 uint32_t count, nsIObserver* observer,
-                                 bool holdWeak)
+nsProcess::CopyArgsAndRunProcess(bool aBlocking, const char** aArgs,
+                                 uint32_t aCount, nsIObserver* aObserver,
+                                 bool aHoldWeak)
 {
-    // Add one to the count for the program name and one for null termination.
-    char **my_argv = nullptr;
-    my_argv = (char**)NS_Alloc(sizeof(char*) * (count + 2));
-    if (!my_argv) {
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
+  // Add one to the aCount for the program name and one for null termination.
+  char** my_argv = nullptr;
+  my_argv = (char**)NS_Alloc(sizeof(char*) * (aCount + 2));
+  if (!my_argv) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
-    my_argv[0] = ToNewUTF8String(mTargetPath);
+  my_argv[0] = ToNewUTF8String(mTargetPath);
 
-    for (uint32_t i = 0; i < count; i++) {
-        my_argv[i + 1] = const_cast<char*>(args[i]);
-    }
+  for (uint32_t i = 0; i < aCount; ++i) {
+    my_argv[i + 1] = const_cast<char*>(aArgs[i]);
+  }
 
-    my_argv[count + 1] = nullptr;
+  my_argv[aCount + 1] = nullptr;
 
-    nsresult rv = RunProcess(blocking, my_argv, observer, holdWeak, false);
+  nsresult rv = RunProcess(aBlocking, my_argv, aObserver, aHoldWeak, false);
 
-    NS_Free(my_argv[0]);
-    NS_Free(my_argv);
-    return rv;
+  NS_Free(my_argv[0]);
+  NS_Free(my_argv);
+  return rv;
 }
 
-// XXXldb |args| has the wrong const-ness
-NS_IMETHODIMP  
-nsProcess::Runw(bool blocking, const char16_t **args, uint32_t count)
+// XXXldb |aArgs| has the wrong const-ness
+NS_IMETHODIMP
+nsProcess::Runw(bool aBlocking, const char16_t** aArgs, uint32_t aCount)
 {
-    return CopyArgsAndRunProcessw(blocking, args, count, nullptr, false);
+  return CopyArgsAndRunProcessw(aBlocking, aArgs, aCount, nullptr, false);
 }
 
-// XXXldb |args| has the wrong const-ness
-NS_IMETHODIMP  
-nsProcess::RunwAsync(const char16_t **args, uint32_t count,
-                    nsIObserver* observer, bool holdWeak)
+// XXXldb |aArgs| has the wrong const-ness
+NS_IMETHODIMP
+nsProcess::RunwAsync(const char16_t** aArgs, uint32_t aCount,
+                     nsIObserver* aObserver, bool aHoldWeak)
 {
-    return CopyArgsAndRunProcessw(false, args, count, observer, holdWeak);
+  return CopyArgsAndRunProcessw(false, aArgs, aCount, aObserver, aHoldWeak);
 }
 
 nsresult
-nsProcess::CopyArgsAndRunProcessw(bool blocking, const char16_t** args,
-                                  uint32_t count, nsIObserver* observer,
-                                  bool holdWeak)
+nsProcess::CopyArgsAndRunProcessw(bool aBlocking, const char16_t** aArgs,
+                                  uint32_t aCount, nsIObserver* aObserver,
+                                  bool aHoldWeak)
 {
-    // Add one to the count for the program name and one for null termination.
-    char **my_argv = nullptr;
-    my_argv = (char**)NS_Alloc(sizeof(char*) * (count + 2));
-    if (!my_argv) {
-        return NS_ERROR_OUT_OF_MEMORY;
-    }
+  // Add one to the aCount for the program name and one for null termination.
+  char** my_argv = nullptr;
+  my_argv = (char**)NS_Alloc(sizeof(char*) * (aCount + 2));
+  if (!my_argv) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
-    my_argv[0] = ToNewUTF8String(mTargetPath);
+  my_argv[0] = ToNewUTF8String(mTargetPath);
 
-    for (uint32_t i = 0; i < count; i++) {
-        my_argv[i + 1] = ToNewUTF8String(nsDependentString(args[i]));
-    }
+  for (uint32_t i = 0; i < aCount; i++) {
+    my_argv[i + 1] = ToNewUTF8String(nsDependentString(aArgs[i]));
+  }
 
-    my_argv[count + 1] = nullptr;
+  my_argv[aCount + 1] = nullptr;
 
-    nsresult rv = RunProcess(blocking, my_argv, observer, holdWeak, true);
+  nsresult rv = RunProcess(aBlocking, my_argv, aObserver, aHoldWeak, true);
 
-    for (uint32_t i = 0; i <= count; i++) {
-        NS_Free(my_argv[i]);
-    }
-    NS_Free(my_argv);
-    return rv;
+  for (uint32_t i = 0; i <= aCount; ++i) {
+    NS_Free(my_argv[i]);
+  }
+  NS_Free(my_argv);
+  return rv;
 }
 
-nsresult  
-nsProcess::RunProcess(bool blocking, char **my_argv, nsIObserver* observer,
-                      bool holdWeak, bool argsUTF8)
+nsresult
+nsProcess::RunProcess(bool aBlocking, char** aMyArgv, nsIObserver* aObserver,
+                      bool aHoldWeak, bool aArgsUTF8)
 {
-    if (NS_WARN_IF(!mExecutable))
-        return NS_ERROR_NOT_INITIALIZED;
-    if (NS_WARN_IF(mThread))
-        return NS_ERROR_ALREADY_INITIALIZED;
+  if (NS_WARN_IF(!mExecutable)) {
+    return NS_ERROR_NOT_INITIALIZED;
+  }
+  if (NS_WARN_IF(mThread)) {
+    return NS_ERROR_ALREADY_INITIALIZED;
+  }
 
-    if (observer) {
-        if (holdWeak) {
-            mWeakObserver = do_GetWeakReference(observer);
-            if (!mWeakObserver)
-                return NS_NOINTERFACE;
-        }
-        else {
-            mObserver = observer;
-        }
+  if (aObserver) {
+    if (aHoldWeak) {
+      mWeakObserver = do_GetWeakReference(aObserver);
+      if (!mWeakObserver) {
+        return NS_NOINTERFACE;
+      }
+    } else {
+      mObserver = aObserver;
     }
+  }
 
-    mExitValue = -1;
-    mPid = -1;
+  mExitValue = -1;
+  mPid = -1;
 
 #if defined(PROCESSMODEL_WINAPI)
-    BOOL retVal;
-    wchar_t *cmdLine = nullptr;
+  BOOL retVal;
+  wchar_t* cmdLine = nullptr;
+
+  // |aMyArgv| is null-terminated and always starts with the program path. If
+  // the second slot is non-null then arguments are being passed.
+  if (aMyArgv[1] && assembleCmdLine(aMyArgv + 1, &cmdLine,
+                                    aArgsUTF8 ? CP_UTF8 : CP_ACP) == -1) {
+    return NS_ERROR_FILE_EXECUTION_FAILED;
+  }
+
+  /* The SEE_MASK_NO_CONSOLE flag is important to prevent console windows
+   * from appearing. This makes behavior the same on all platforms. The flag
+   * will not have any effect on non-console applications.
+   */
+
+  // The program name in aMyArgv[0] is always UTF-8
+  NS_ConvertUTF8toUTF16 wideFile(aMyArgv[0]);
+
+  SHELLEXECUTEINFOW sinfo;
+  memset(&sinfo, 0, sizeof(SHELLEXECUTEINFOW));
+  sinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
+  sinfo.hwnd   = nullptr;
+  sinfo.lpFile = wideFile.get();
+  sinfo.nShow  = SW_SHOWNORMAL;
+  sinfo.fMask  = SEE_MASK_FLAG_DDEWAIT |
+                 SEE_MASK_NO_CONSOLE |
+                 SEE_MASK_NOCLOSEPROCESS;
+
+  if (cmdLine) {
+    sinfo.lpParameters = cmdLine;
+  }
+
+  retVal = ShellExecuteExW(&sinfo);
+  if (!retVal) {
+    return NS_ERROR_FILE_EXECUTION_FAILED;
+  }
+
+  mProcess = sinfo.hProcess;
+
+  if (cmdLine) {
+    PR_Free(cmdLine);
+  }
 
-    // The 'argv' array is null-terminated and always starts with the program path.
-    // If the second slot is non-null then arguments are being passed.
-    if (my_argv[1] != nullptr &&
-        assembleCmdLine(my_argv + 1, &cmdLine, argsUTF8 ? CP_UTF8 : CP_ACP) == -1) {
-        return NS_ERROR_FILE_EXECUTION_FAILED;    
+  mPid = GetProcessId(mProcess);
+#elif defined(XP_MACOSX)
+  // Initialize spawn attributes.
+  posix_spawnattr_t spawnattr;
+  if (posix_spawnattr_init(&spawnattr) != 0) {
+    return NS_ERROR_FAILURE;
+  }
+
+  // Set spawn attributes.
+  size_t attr_count = ArrayLength(pref_cpu_types);
+  size_t attr_ocount = 0;
+  if (posix_spawnattr_setbinpref_np(&spawnattr, attr_count, pref_cpu_types,
+                                    &attr_ocount) != 0 ||
+      attr_ocount != attr_count) {
+    posix_spawnattr_destroy(&spawnattr);
+    return NS_ERROR_FAILURE;
+  }
+
+  // Note: |aMyArgv| is already null-terminated as required by posix_spawnp.
+  pid_t newPid = 0;
+  int result = posix_spawnp(&newPid, aMyArgv[0], nullptr, &spawnattr, aMyArgv,
+                            *_NSGetEnviron());
+  mPid = static_cast<int32_t>(newPid);
+
+  posix_spawnattr_destroy(&spawnattr);
+
+  if (result != 0) {
+    return NS_ERROR_FAILURE;
+  }
+#else
+  mProcess = PR_CreateProcess(aMyArgv[0], aMyArgv, nullptr, nullptr);
+  if (!mProcess) {
+    return NS_ERROR_FAILURE;
+  }
+  struct MYProcess
+  {
+    uint32_t pid;
+  };
+  MYProcess* ptrProc = (MYProcess*)mProcess;
+  mPid = ptrProc->pid;
+#endif
+
+  NS_ADDREF_THIS();
+  mBlocking = aBlocking;
+  if (aBlocking) {
+    Monitor(this);
+    if (mExitValue < 0) {
+      return NS_ERROR_FILE_EXECUTION_FAILED;
+    }
+  } else {
+    mThread = PR_CreateThread(PR_SYSTEM_THREAD, Monitor, this,
+                              PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+                              PR_JOINABLE_THREAD, 0);
+    if (!mThread) {
+      NS_RELEASE_THIS();
+      return NS_ERROR_FAILURE;
     }
 
-    /* The SEE_MASK_NO_CONSOLE flag is important to prevent console windows
-     * from appearing. This makes behavior the same on all platforms. The flag
-     * will not have any effect on non-console applications.
-     */
-
-    // The program name in my_argv[0] is always UTF-8
-    NS_ConvertUTF8toUTF16 wideFile(my_argv[0]);
-
-    SHELLEXECUTEINFOW sinfo;
-    memset(&sinfo, 0, sizeof(SHELLEXECUTEINFOW));
-    sinfo.cbSize = sizeof(SHELLEXECUTEINFOW);
-    sinfo.hwnd   = nullptr;
-    sinfo.lpFile = wideFile.get();
-    sinfo.nShow  = SW_SHOWNORMAL;
-    sinfo.fMask  = SEE_MASK_FLAG_DDEWAIT |
-                   SEE_MASK_NO_CONSOLE |
-                   SEE_MASK_NOCLOSEPROCESS;
-
-    if (cmdLine)
-        sinfo.lpParameters = cmdLine;
-
-    retVal = ShellExecuteExW(&sinfo);
-    if (!retVal) {
-        return NS_ERROR_FILE_EXECUTION_FAILED;
+    // It isn't a failure if we just can't watch for shutdown
+    nsCOMPtr<nsIObserverService> os =
+      mozilla::services::GetObserverService();
+    if (os) {
+      os->AddObserver(this, "xpcom-shutdown", false);
     }
-
-    mProcess = sinfo.hProcess;
-
-    if (cmdLine)
-        PR_Free(cmdLine);
-
-    mPid = GetProcessId(mProcess);
-#elif defined(XP_MACOSX)
-    // Initialize spawn attributes.
-    posix_spawnattr_t spawnattr;
-    if (posix_spawnattr_init(&spawnattr) != 0) {
-        return NS_ERROR_FAILURE;
-    }
-
-    // Set spawn attributes.
-    size_t attr_count = ArrayLength(pref_cpu_types);
-    size_t attr_ocount = 0;
-    if (posix_spawnattr_setbinpref_np(&spawnattr, attr_count, pref_cpu_types, &attr_ocount) != 0 ||
-        attr_ocount != attr_count) {
-        posix_spawnattr_destroy(&spawnattr);
-        return NS_ERROR_FAILURE;
-    }
+  }
 
-    // Note that the 'argv' array is already null-terminated, which 'posix_spawnp' requires.
-    pid_t newPid = 0;
-    int result = posix_spawnp(&newPid, my_argv[0], nullptr, &spawnattr, my_argv, *_NSGetEnviron());
-    mPid = static_cast<int32_t>(newPid);
-
-    posix_spawnattr_destroy(&spawnattr);
-
-    if (result != 0) {
-        return NS_ERROR_FAILURE;
-    }
-#else
-    mProcess = PR_CreateProcess(my_argv[0], my_argv, nullptr, nullptr);
-    if (!mProcess)
-        return NS_ERROR_FAILURE;
-    struct MYProcess {
-        uint32_t pid;
-    };
-    MYProcess* ptrProc = (MYProcess *) mProcess;
-    mPid = ptrProc->pid;
-#endif
-
-    NS_ADDREF_THIS();
-    mBlocking = blocking;
-    if (blocking) {
-        Monitor(this);
-        if (mExitValue < 0)
-            return NS_ERROR_FILE_EXECUTION_FAILED;
-    }
-    else {
-        mThread = PR_CreateThread(PR_SYSTEM_THREAD, Monitor, this,
-                                  PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
-                                  PR_JOINABLE_THREAD, 0);
-        if (!mThread) {
-            NS_RELEASE_THIS();
-            return NS_ERROR_FAILURE;
-        }
-
-        // It isn't a failure if we just can't watch for shutdown
-        nsCOMPtr<nsIObserverService> os =
-          mozilla::services::GetObserverService();
-        if (os)
-            os->AddObserver(this, "xpcom-shutdown", false);
-    }
-
-    return NS_OK;
-}
-
-NS_IMETHODIMP nsProcess::GetIsRunning(bool *aIsRunning)
-{
-    if (mThread)
-        *aIsRunning = true;
-    else
-        *aIsRunning = false;
-
-    return NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsProcess::GetPid(uint32_t *aPid)
+nsProcess::GetIsRunning(bool* aIsRunning)
 {
-    if (!mThread)
-        return NS_ERROR_FAILURE;
-    if (mPid < 0)
-        return NS_ERROR_NOT_IMPLEMENTED;
-    *aPid = mPid;
-    return NS_OK;
+  if (mThread) {
+    *aIsRunning = true;
+  } else {
+    *aIsRunning = false;
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsProcess::GetPid(uint32_t* aPid)
+{
+  if (!mThread) {
+    return NS_ERROR_FAILURE;
+  }
+  if (mPid < 0) {
+    return NS_ERROR_NOT_IMPLEMENTED;
+  }
+  *aPid = mPid;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 nsProcess::Kill()
 {
-    if (!mThread)
-        return NS_ERROR_FAILURE;
+  if (!mThread) {
+    return NS_ERROR_FAILURE;
+  }
 
-    {
-        MutexAutoLock lock(mLock);
+  {
+    MutexAutoLock lock(mLock);
 #if defined(PROCESSMODEL_WINAPI)
-        if (TerminateProcess(mProcess, 0) == 0)
-            return NS_ERROR_FAILURE;
+    if (TerminateProcess(mProcess, 0) == 0) {
+      return NS_ERROR_FAILURE;
+    }
 #elif defined(XP_MACOSX)
-        if (kill(mPid, SIGKILL) != 0)
-            return NS_ERROR_FAILURE;
+    if (kill(mPid, SIGKILL) != 0) {
+      return NS_ERROR_FAILURE;
+    }
 #else
-        if (!mProcess || (PR_KillProcess(mProcess) != PR_SUCCESS))
-            return NS_ERROR_FAILURE;
+    if (!mProcess || (PR_KillProcess(mProcess) != PR_SUCCESS)) {
+      return NS_ERROR_FAILURE;
+    }
 #endif
-    }
+  }
 
-    // We must null out mThread if we want IsRunning to return false immediately
-    // after this call.
-    nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
-    if (os)
-        os->RemoveObserver(this, "xpcom-shutdown");
-    PR_JoinThread(mThread);
-    mThread = nullptr;
+  // We must null out mThread if we want IsRunning to return false immediately
+  // after this call.
+  nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+  if (os) {
+    os->RemoveObserver(this, "xpcom-shutdown");
+  }
+  PR_JoinThread(mThread);
+  mThread = nullptr;
 
-    return NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsProcess::GetExitValue(int32_t *aExitValue)
+nsProcess::GetExitValue(int32_t* aExitValue)
 {
-    MutexAutoLock lock(mLock);
+  MutexAutoLock lock(mLock);
 
-    *aExitValue = mExitValue;
-    
-    return NS_OK;
+  *aExitValue = mExitValue;
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-nsProcess::Observe(nsISupports* subject, const char* topic, const char16_t* data)
+nsProcess::Observe(nsISupports* aSubject, const char* aTopic,
+                   const char16_t* aData)
 {
-    // Shutting down, drop all references
-    if (mThread) {
-        nsCOMPtr<nsIObserverService> os =
-          mozilla::services::GetObserverService();
-        if (os)
-            os->RemoveObserver(this, "xpcom-shutdown");
-        mThread = nullptr;
+  // Shutting down, drop all references
+  if (mThread) {
+    nsCOMPtr<nsIObserverService> os =
+      mozilla::services::GetObserverService();
+    if (os) {
+      os->RemoveObserver(this, "xpcom-shutdown");
     }
+    mThread = nullptr;
+  }
 
-    mObserver = nullptr;
-    mWeakObserver = nullptr;
+  mObserver = nullptr;
+  mWeakObserver = nullptr;
 
-    MutexAutoLock lock(mLock);
-    mShutdown = true;
+  MutexAutoLock lock(mLock);
+  mShutdown = true;
 
-    return NS_OK;
+  return NS_OK;
 }
--- a/xpcom/threads/nsThread.cpp
+++ b/xpcom/threads/nsThread.cpp
@@ -62,100 +62,112 @@
 #ifdef MOZ_TASK_TRACER
 #include "GeckoTaskTracer.h"
 using namespace mozilla::tasktracer;
 #endif
 
 using namespace mozilla;
 
 #ifdef PR_LOGGING
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetThreadLog()
 {
-  static PRLogModuleInfo *sLog;
-  if (!sLog)
+  static PRLogModuleInfo* sLog;
+  if (!sLog) {
     sLog = PR_NewLogModule("nsThread");
+  }
   return sLog;
 }
 #endif
 #ifdef LOG
 #undef LOG
 #endif
 #define LOG(args) PR_LOG(GetThreadLog(), PR_LOG_DEBUG, args)
 
 NS_DECL_CI_INTERFACE_GETTER(nsThread)
 
 nsIThreadObserver* nsThread::sMainThreadObserver = nullptr;
 
 //-----------------------------------------------------------------------------
 // Because we do not have our own nsIFactory, we have to implement nsIClassInfo
 // somewhat manually.
 
-class nsThreadClassInfo : public nsIClassInfo {
+class nsThreadClassInfo : public nsIClassInfo
+{
 public:
   NS_DECL_ISUPPORTS_INHERITED  // no mRefCnt
   NS_DECL_NSICLASSINFO
 
-  nsThreadClassInfo() {}
+  nsThreadClassInfo()
+  {
+  }
 };
 
-NS_IMETHODIMP_(MozExternalRefCountType) nsThreadClassInfo::AddRef() { return 2; }
-NS_IMETHODIMP_(MozExternalRefCountType) nsThreadClassInfo::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType)
+nsThreadClassInfo::AddRef()
+{
+  return 2;
+}
+NS_IMETHODIMP_(MozExternalRefCountType)
+nsThreadClassInfo::Release()
+{
+  return 1;
+}
 NS_IMPL_QUERY_INTERFACE(nsThreadClassInfo, nsIClassInfo)
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetInterfaces(uint32_t *count, nsIID ***array)
+nsThreadClassInfo::GetInterfaces(uint32_t* aCount, nsIID*** aArray)
 {
-  return NS_CI_INTERFACE_GETTER_NAME(nsThread)(count, array);
+  return NS_CI_INTERFACE_GETTER_NAME(nsThread)(aCount, aArray);
 }
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetHelperForLanguage(uint32_t lang, nsISupports **result)
+nsThreadClassInfo::GetHelperForLanguage(uint32_t aLang, nsISupports** aResult)
 {
-  *result = nullptr;
+  *aResult = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetContractID(char **result)
+nsThreadClassInfo::GetContractID(char** aResult)
 {
-  *result = nullptr;
+  *aResult = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetClassDescription(char **result)
+nsThreadClassInfo::GetClassDescription(char** aResult)
 {
-  *result = nullptr;
+  *aResult = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetClassID(nsCID **result)
+nsThreadClassInfo::GetClassID(nsCID** aResult)
 {
-  *result = nullptr;
+  *aResult = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetImplementationLanguage(uint32_t *result)
+nsThreadClassInfo::GetImplementationLanguage(uint32_t* aResult)
 {
-  *result = nsIProgrammingLanguage::CPLUSPLUS;
+  *aResult = nsIProgrammingLanguage::CPLUSPLUS;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetFlags(uint32_t *result)
+nsThreadClassInfo::GetFlags(uint32_t* aResult)
 {
-  *result = THREADSAFE;
+  *aResult = THREADSAFE;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadClassInfo::GetClassIDNoAlloc(nsCID *result)
+nsThreadClassInfo::GetClassIDNoAlloc(nsCID* aResult)
 {
   return NS_ERROR_NOT_AVAILABLE;
 }
 
 //-----------------------------------------------------------------------------
 
 NS_IMPL_ADDREF(nsThread)
 NS_IMPL_RELEASE(nsThread)
@@ -170,86 +182,103 @@ NS_INTERFACE_MAP_BEGIN(nsThread)
     foundInterface = static_cast<nsIClassInfo*>(&sThreadClassInfo);
   } else
 NS_INTERFACE_MAP_END
 NS_IMPL_CI_INTERFACE_GETTER(nsThread, nsIThread, nsIThreadInternal,
                             nsIEventTarget, nsISupportsPriority)
 
 //-----------------------------------------------------------------------------
 
-class nsThreadStartupEvent : public nsRunnable {
+class nsThreadStartupEvent : public nsRunnable
+{
 public:
   nsThreadStartupEvent()
     : mMon("nsThreadStartupEvent.mMon")
-    , mInitialized(false) {
+    , mInitialized(false)
+  {
   }
 
   // This method does not return until the thread startup object is in the
   // completion state.
-  void Wait() {
-    if (mInitialized)  // Maybe avoid locking...
+  void Wait()
+  {
+    if (mInitialized) {
+      // Maybe avoid locking...
       return;
+    }
+
     ReentrantMonitorAutoEnter mon(mMon);
-    while (!mInitialized)
+    while (!mInitialized) {
       mon.Wait();
+    }
   }
 
   // This method needs to be public to support older compilers (xlC_r on AIX).
   // It should be called directly as this class type is reference counted.
-  virtual ~nsThreadStartupEvent() {
+  virtual ~nsThreadStartupEvent()
+  {
   }
 
 private:
-  NS_IMETHOD Run() {
+  NS_IMETHOD Run()
+  {
     ReentrantMonitorAutoEnter mon(mMon);
     mInitialized = true;
     mon.Notify();
     return NS_OK;
   }
 
   ReentrantMonitor mMon;
-  bool       mInitialized;
+  bool mInitialized;
 };
 
 //-----------------------------------------------------------------------------
 
-struct nsThreadShutdownContext {
-  nsThread *joiningThread;
+struct nsThreadShutdownContext
+{
+  nsThread* joiningThread;
   bool      shutdownAck;
 };
 
 // This event is responsible for notifying nsThread::Shutdown that it is time
 // to call PR_JoinThread.
-class nsThreadShutdownAckEvent : public nsRunnable {
+class nsThreadShutdownAckEvent : public nsRunnable
+{
 public:
-  nsThreadShutdownAckEvent(nsThreadShutdownContext *ctx)
-    : mShutdownContext(ctx) {
+  nsThreadShutdownAckEvent(nsThreadShutdownContext* aCtx)
+    : mShutdownContext(aCtx)
+  {
   }
-  NS_IMETHOD Run() {
+  NS_IMETHOD Run()
+  {
     mShutdownContext->shutdownAck = true;
     return NS_OK;
   }
 private:
-  nsThreadShutdownContext *mShutdownContext;
+  nsThreadShutdownContext* mShutdownContext;
 };
 
 // This event is responsible for setting mShutdownContext
-class nsThreadShutdownEvent : public nsRunnable {
+class nsThreadShutdownEvent : public nsRunnable
+{
 public:
-  nsThreadShutdownEvent(nsThread *thr, nsThreadShutdownContext *ctx)
-    : mThread(thr), mShutdownContext(ctx) {
-  } 
-  NS_IMETHOD Run() {
+  nsThreadShutdownEvent(nsThread* aThr, nsThreadShutdownContext* aCtx)
+    : mThread(aThr)
+    , mShutdownContext(aCtx)
+  {
+  }
+  NS_IMETHOD Run()
+  {
     mThread->mShutdownContext = mShutdownContext;
     MessageLoop::current()->Quit();
     return NS_OK;
   }
 private:
   nsRefPtr<nsThread>       mThread;
-  nsThreadShutdownContext *mShutdownContext;
+  nsThreadShutdownContext* mShutdownContext;
 };
 
 //-----------------------------------------------------------------------------
 
 static void
 SetupCurrentThreadForChaosMode()
 {
   if (!ChaosMode::isActive()) {
@@ -267,35 +296,35 @@ SetupCurrentThreadForChaosMode()
   // This makes it hard to have non-main threads with higher priority than the
   // main thread, but that's hard to fix. Tools like rr can choose to honor the
   // requested values anyway.
   // Use just 4 priorities so there's a reasonable chance of any two threads
   // having equal priority.
   setpriority(PRIO_PROCESS, 0, ChaosMode::randomUint32LessThan(4));
 #else
   // We should set the affinity here but NSPR doesn't provide a way to expose it.
-  PR_SetThreadPriority(PR_GetCurrentThread(),
-    PRThreadPriority(ChaosMode::randomUint32LessThan(PR_PRIORITY_LAST + 1)));
+  uint32_t priority = ChaosMode::randomUint32LessThan(PR_PRIORITY_LAST + 1);
+  PR_SetThreadPriority(PR_GetCurrentThread(), PRThreadPriority(priority));
 #endif
 
 #ifdef HAVE_SCHED_SETAFFINITY
   // Force half the threads to CPU 0 so they compete for CPU
   if (ChaosMode::randomUint32LessThan(2)) {
     cpu_set_t cpus;
     CPU_ZERO(&cpus);
     CPU_SET(0, &cpus);
     sched_setaffinity(0, sizeof(cpus), &cpus);
   }
 #endif
 }
 
 /*static*/ void
-nsThread::ThreadFunc(void *arg)
+nsThread::ThreadFunc(void* aArg)
 {
-  nsThread *self = static_cast<nsThread *>(arg);  // strong reference
+  nsThread* self = static_cast<nsThread*>(aArg);  // strong reference
   self->mThread = PR_GetCurrentThread();
   SetupCurrentThreadForChaosMode();
 
   // Inform the ThreadManager
   nsThreadManager::get()->RegisterCurrentThread(self);
 
   mozilla::IOInterposer::RegisterCurrentThread();
 
@@ -303,17 +332,18 @@ nsThread::ThreadFunc(void *arg)
   nsCOMPtr<nsIRunnable> event;
   if (!self->GetEvent(true, getter_AddRefs(event))) {
     NS_WARNING("failed waiting for thread startup event");
     return;
   }
   event->Run();  // unblocks nsThread::Init
   event = nullptr;
 
-  { // Scope for MessageLoop.
+  {
+    // Scope for MessageLoop.
     nsAutoPtr<MessageLoop> loop(
       new MessageLoop(MessageLoop::TYPE_MOZILLA_NONMAINTHREAD));
 
     // Now, process incoming events...
     loop->Run();
 
     // Do NS_ProcessPendingEvents but with special handling to set
     // mEventsAreDoomed atomically with the removal of the last event. The key
@@ -379,23 +409,23 @@ nsThread::~nsThread()
 {
 }
 
 nsresult
 nsThread::Init()
 {
   // spawn thread and wait until it is fully setup
   nsRefPtr<nsThreadStartupEvent> startup = new nsThreadStartupEvent();
- 
+
   NS_ADDREF_THIS();
- 
+
   mShutdownRequired = true;
 
   // ThreadFunc is responsible for setting mThread
-  PRThread *thr = PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
+  PRThread* thr = PR_CreateThread(PR_USER_THREAD, ThreadFunc, this,
                                   PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
                                   PR_JOINABLE_THREAD, mStackSize);
   if (!thr) {
     NS_RELEASE_THIS();
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   // ThreadFunc will wait for this event to be run before it tries to access
@@ -418,149 +448,160 @@ nsThread::InitCurrentThread()
   mThread = PR_GetCurrentThread();
   SetupCurrentThreadForChaosMode();
 
   nsThreadManager::get()->RegisterCurrentThread(this);
   return NS_OK;
 }
 
 nsresult
-nsThread::PutEvent(nsIRunnable *event, nsNestedEventTarget *target)
+nsThread::PutEvent(nsIRunnable* aEvent, nsNestedEventTarget* aTarget)
 {
   {
     MutexAutoLock lock(mLock);
-    nsChainedEventQueue *queue = target ? target->mQueue : &mEventsRoot;
+    nsChainedEventQueue* queue = aTarget ? aTarget->mQueue : &mEventsRoot;
     if (!queue || (queue == &mEventsRoot && mEventsAreDoomed)) {
       NS_WARNING("An event was posted to a thread that will never run it (rejected)");
       return NS_ERROR_UNEXPECTED;
     }
-    queue->PutEvent(event);
+    queue->PutEvent(aEvent);
   }
 
   nsCOMPtr<nsIThreadObserver> obs = GetObserver();
-  if (obs)
+  if (obs) {
     obs->OnDispatchedEvent(this);
+  }
 
   return NS_OK;
 }
 
 nsresult
-nsThread::DispatchInternal(nsIRunnable *event, uint32_t flags,
-                           nsNestedEventTarget *target)
+nsThread::DispatchInternal(nsIRunnable* aEvent, uint32_t aFlags,
+                           nsNestedEventTarget* aTarget)
 {
-  if (NS_WARN_IF(!event))
+  if (NS_WARN_IF(!aEvent)) {
     return NS_ERROR_INVALID_ARG;
+  }
 
-  if (gXPCOMThreadsShutDown && MAIN_THREAD != mIsMainThread && !target) {
+  if (gXPCOMThreadsShutDown && MAIN_THREAD != mIsMainThread && !aTarget) {
     return NS_ERROR_ILLEGAL_DURING_SHUTDOWN;
   }
 
 #ifdef MOZ_TASK_TRACER
-  nsRefPtr<nsIRunnable> tracedRunnable = CreateTracedRunnable(event);
-  event = tracedRunnable;
+  nsRefPtr<nsIRunnable> tracedRunnable = CreateTracedRunnable(aEvent);
+  aEvent = tracedRunnable;
 #endif
 
-  if (flags & DISPATCH_SYNC) {
-    nsThread *thread = nsThreadManager::get()->GetCurrentThread();
-    if (NS_WARN_IF(!thread))
+  if (aFlags & DISPATCH_SYNC) {
+    nsThread* thread = nsThreadManager::get()->GetCurrentThread();
+    if (NS_WARN_IF(!thread)) {
       return NS_ERROR_NOT_AVAILABLE;
+    }
 
     // XXX we should be able to do something better here... we should
     //     be able to monitor the slot occupied by this event and use
     //     that to tell us when the event has been processed.
 
     nsRefPtr<nsThreadSyncDispatch> wrapper =
-        new nsThreadSyncDispatch(thread, event);
-    if (!wrapper)
+      new nsThreadSyncDispatch(thread, aEvent);
+    if (!wrapper) {
       return NS_ERROR_OUT_OF_MEMORY;
-    nsresult rv = PutEvent(wrapper, target);
+    }
+    nsresult rv = PutEvent(wrapper, aTarget);
     // Don't wait for the event to finish if we didn't dispatch it...
-    if (NS_FAILED(rv))
+    if (NS_FAILED(rv)) {
       return rv;
+    }
 
     // Allows waiting; ensure no locks are held that would deadlock us!
-    while (wrapper->IsPending())
+    while (wrapper->IsPending()) {
       NS_ProcessNextEvent(thread, true);
+    }
     return wrapper->Result();
   }
 
-  NS_ASSERTION(flags == NS_DISPATCH_NORMAL, "unexpected dispatch flags");
-  return PutEvent(event, target);
+  NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL, "unexpected dispatch flags");
+  return PutEvent(aEvent, aTarget);
 }
 
 //-----------------------------------------------------------------------------
 // nsIEventTarget
 
 NS_IMETHODIMP
-nsThread::Dispatch(nsIRunnable *event, uint32_t flags)
+nsThread::Dispatch(nsIRunnable* aEvent, uint32_t aFlags)
 {
-  LOG(("THRD(%p) Dispatch [%p %x]\n", this, event, flags));
+  LOG(("THRD(%p) Dispatch [%p %x]\n", this, aEvent, aFlags));
 
-  return DispatchInternal(event, flags, nullptr);
+  return DispatchInternal(aEvent, aFlags, nullptr);
 }
 
 NS_IMETHODIMP
-nsThread::IsOnCurrentThread(bool *result)
+nsThread::IsOnCurrentThread(bool* aResult)
 {
-  *result = (PR_GetCurrentThread() == mThread);
+  *aResult = (PR_GetCurrentThread() == mThread);
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 // nsIThread
 
 NS_IMETHODIMP
-nsThread::GetPRThread(PRThread **result)
+nsThread::GetPRThread(PRThread** aResult)
 {
-  *result = mThread;
+  *aResult = mThread;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThread::Shutdown()
 {
   LOG(("THRD(%p) shutdown\n", this));
 
   // XXX If we make this warn, then we hit that warning at xpcom shutdown while
   //     shutting down a thread in a thread pool.  That happens b/c the thread
   //     in the thread pool is already shutdown by the thread manager.
-  if (!mThread)
+  if (!mThread) {
     return NS_OK;
+  }
 
-  if (NS_WARN_IF(mThread == PR_GetCurrentThread()))
+  if (NS_WARN_IF(mThread == PR_GetCurrentThread())) {
     return NS_ERROR_UNEXPECTED;
+  }
 
   // Prevent multiple calls to this method
   {
     MutexAutoLock lock(mLock);
-    if (!mShutdownRequired)
+    if (!mShutdownRequired) {
       return NS_ERROR_UNEXPECTED;
+    }
     mShutdownRequired = false;
   }
 
   nsThreadShutdownContext context;
   context.joiningThread = nsThreadManager::get()->GetCurrentThread();
   context.shutdownAck = false;
 
   // Set mShutdownContext and wake up the thread in case it is waiting for
   // events to process.
   nsCOMPtr<nsIRunnable> event = new nsThreadShutdownEvent(this, &context);
-  if (!event)
+  if (!event) {
     return NS_ERROR_OUT_OF_MEMORY;
+  }
   // XXXroc What if posting the event fails due to OOM?
   PutEvent(event, nullptr);
 
   // We could still end up with other events being added after the shutdown
   // task, but that's okay because we process pending events in ThreadFunc
   // after setting mShutdownContext just before exiting.
-  
+
   // Process events on the current thread until we receive a shutdown ACK.
   // Allows waiting; ensure no locks are held that would deadlock us!
-  while (!context.shutdownAck)
+  while (!context.shutdownAck) {
     NS_ProcessNextEvent(context.joiningThread, true);
+  }
 
   // Now, it should be safe to join without fear of dead-locking.
 
   PR_JoinThread(mThread);
   mThread = nullptr;
 
   // We hold strong references to our event observers, and once the thread is
   // shut down the observers can't easily unregister themselves. Do it here
@@ -573,54 +614,60 @@ nsThread::Shutdown()
     MOZ_ASSERT(!mObserver, "Should have been cleared at shutdown!");
   }
 #endif
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::HasPendingEvents(bool *result)
+nsThread::HasPendingEvents(bool* aResult)
 {
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
-  *result = mEvents->GetEvent(false, nullptr);
+  *aResult = mEvents->GetEvent(false, nullptr);
   return NS_OK;
 }
 
 #ifdef MOZ_CANARY
-void canary_alarm_handler (int signum);
+void canary_alarm_handler(int signum);
 
-class Canary {
-//XXX ToDo: support nested loops
+class Canary
+{
+  //XXX ToDo: support nested loops
 public:
-  Canary() {
+  Canary()
+  {
     if (sCanaryOutputFD > 0 && EventLatencyIsImportant()) {
       signal(SIGALRM, canary_alarm_handler);
-      ualarm(15000, 0);      
+      ualarm(15000, 0);
     }
   }
 
-  ~Canary() {
-    if (sCanaryOutputFD != 0 && EventLatencyIsImportant())
+  ~Canary()
+  {
+    if (sCanaryOutputFD != 0 && EventLatencyIsImportant()) {
       ualarm(0, 0);
+    }
   }
 
-  static bool EventLatencyIsImportant() {
+  static bool EventLatencyIsImportant()
+  {
     return NS_IsMainThread() && XRE_GetProcessType() == GeckoProcessType_Default;
   }
 };
 
-void canary_alarm_handler (int signum)
+void canary_alarm_handler(int signum)
 {
-  void *array[30];
+  void* array[30];
   const char msg[29] = "event took too long to run:\n";
   // use write to be safe in the signal handler
-  write(sCanaryOutputFD, msg, sizeof(msg)); 
+  write(sCanaryOutputFD, msg, sizeof(msg));
   backtrace_symbols_fd(array, backtrace(array, 30), sCanaryOutputFD);
 }
 
 #endif
 
 #define NOTIFY_EVENT_OBSERVERS(func_, params_)                                 \
   PR_BEGIN_MACRO                                                               \
     if (!mEventObservers.IsEmpty()) {                                          \
@@ -630,66 +677,70 @@ void canary_alarm_handler (int signum)
       while (iter_.HasMore()) {                                                \
         obs_ = iter_.GetNext();                                                \
         obs_ -> func_ params_ ;                                                \
       }                                                                        \
     }                                                                          \
   PR_END_MACRO
 
 NS_IMETHODIMP
-nsThread::ProcessNextEvent(bool mayWait, bool *result)
+nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
 {
-  LOG(("THRD(%p) ProcessNextEvent [%u %u]\n", this, mayWait, mRunningEvent));
+  LOG(("THRD(%p) ProcessNextEvent [%u %u]\n", this, aMayWait, mRunningEvent));
 
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
   // The toplevel event loop normally blocks waiting for the next event, but
   // if we're trying to shut this thread down, we must exit the event loop when
   // the event queue is empty.
   // This only applys to the toplevel event loop! Nested event loops (e.g.
   // during sync dispatch) are waiting for some state change and must be able
   // to block even if something has requested shutdown of the thread. Otherwise
   // we'll just busywait as we endlessly look for an event, fail to find one,
   // and repeat the nested event loop since its state change hasn't happened yet.
-  bool reallyWait = mayWait && (mRunningEvent > 0 || !ShuttingDown());
+  bool reallyWait = aMayWait && (mRunningEvent > 0 || !ShuttingDown());
 
-  if (MAIN_THREAD == mIsMainThread && reallyWait)
+  if (MAIN_THREAD == mIsMainThread && reallyWait) {
     HangMonitor::Suspend();
+  }
 
   // Fire a memory pressure notification, if we're the main thread and one is
   // pending.
   if (MAIN_THREAD == mIsMainThread && !ShuttingDown()) {
     MemoryPressureState mpPending = NS_GetPendingMemoryPressure();
     if (mpPending != MemPressure_None) {
       nsCOMPtr<nsIObserverService> os = services::GetObserverService();
 
       // Use no-forward to prevent the notifications from being transferred to
       // the children of this process.
       NS_NAMED_LITERAL_STRING(lowMem, "low-memory-no-forward");
       NS_NAMED_LITERAL_STRING(lowMemOngoing, "low-memory-ongoing-no-forward");
 
       if (os) {
         os->NotifyObservers(nullptr, "memory-pressure",
                             mpPending == MemPressure_New ? lowMem.get() :
-                                                           lowMemOngoing.get());
+                            lowMemOngoing.get());
       } else {
         NS_WARNING("Can't get observer service!");
       }
     }
   }
 
   bool notifyMainThreadObserver =
     (MAIN_THREAD == mIsMainThread) && sMainThreadObserver;
-  if (notifyMainThreadObserver) 
-   sMainThreadObserver->OnProcessNextEvent(this, reallyWait, mRunningEvent);
+  if (notifyMainThreadObserver) {
+    sMainThreadObserver->OnProcessNextEvent(this, reallyWait, mRunningEvent);
+  }
 
   nsCOMPtr<nsIThreadObserver> obs = mObserver;
-  if (obs)
+  if (obs) {
     obs->OnProcessNextEvent(this, reallyWait, mRunningEvent);
+  }
 
   NOTIFY_EVENT_OBSERVERS(OnProcessNextEvent,
                          (this, reallyWait, mRunningEvent));
 
   ++mRunningEvent;
 
 #ifdef MOZ_CANARY
   Canary canary;
@@ -700,68 +751,72 @@ nsThread::ProcessNextEvent(bool mayWait,
     // Scope for |event| to make sure that its destructor fires while
     // mRunningEvent has been incremented, since that destructor can
     // also do work.
 
     // If we are shutting down, then do not wait for new events.
     nsCOMPtr<nsIRunnable> event;
     mEvents->GetEvent(reallyWait, getter_AddRefs(event));
 
-    *result = (event.get() != nullptr);
+    *aResult = (event.get() != nullptr);
 
     if (event) {
       LOG(("THRD(%p) running [%p]\n", this, event.get()));
-      if (MAIN_THREAD == mIsMainThread)
+      if (MAIN_THREAD == mIsMainThread) {
         HangMonitor::NotifyActivity();
+      }
       event->Run();
-    } else if (mayWait) {
+    } else if (aMayWait) {
       MOZ_ASSERT(ShuttingDown(),
                  "This should only happen when shutting down");
       rv = NS_ERROR_UNEXPECTED;
     }
   }
 
   --mRunningEvent;
 
   NOTIFY_EVENT_OBSERVERS(AfterProcessNextEvent,
-                         (this, mRunningEvent, *result));
+                         (this, mRunningEvent, *aResult));
 
-  if (obs)
-    obs->AfterProcessNextEvent(this, mRunningEvent, *result);
+  if (obs) {
+    obs->AfterProcessNextEvent(this, mRunningEvent, *aResult);
+  }
 
-  if (notifyMainThreadObserver && sMainThreadObserver)
-    sMainThreadObserver->AfterProcessNextEvent(this, mRunningEvent, *result);
+  if (notifyMainThreadObserver && sMainThreadObserver) {
+    sMainThreadObserver->AfterProcessNextEvent(this, mRunningEvent, *aResult);
+  }
 
   return rv;
 }
 
 //-----------------------------------------------------------------------------
 // nsISupportsPriority
 
 NS_IMETHODIMP
-nsThread::GetPriority(int32_t *priority)
+nsThread::GetPriority(int32_t* aPriority)
 {
-  *priority = mPriority;
+  *aPriority = mPriority;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::SetPriority(int32_t priority)
+nsThread::SetPriority(int32_t aPriority)
 {
-  if (NS_WARN_IF(!mThread))
+  if (NS_WARN_IF(!mThread)) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
   // NSPR defines the following four thread priorities:
   //   PR_PRIORITY_LOW
   //   PR_PRIORITY_NORMAL
   //   PR_PRIORITY_HIGH
   //   PR_PRIORITY_URGENT
   // We map the priority values defined on nsISupportsPriority to these values.
 
-  mPriority = priority;
+  mPriority = aPriority;
 
   PRThreadPriority pri;
   if (mPriority <= PRIORITY_HIGHEST) {
     pri = PR_PRIORITY_URGENT;
   } else if (mPriority < PRIORITY_NORMAL) {
     pri = PR_PRIORITY_HIGH;
   } else if (mPriority > PRIORITY_NORMAL) {
     pri = PR_PRIORITY_LOW;
@@ -772,132 +827,142 @@ nsThread::SetPriority(int32_t priority)
   if (!ChaosMode::isActive()) {
     PR_SetThreadPriority(mThread, pri);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::AdjustPriority(int32_t delta)
+nsThread::AdjustPriority(int32_t aDelta)
 {
-  return SetPriority(mPriority + delta);
+  return SetPriority(mPriority + aDelta);
 }
 
 //-----------------------------------------------------------------------------
 // nsIThreadInternal
 
 NS_IMETHODIMP
-nsThread::GetObserver(nsIThreadObserver **obs)
+nsThread::GetObserver(nsIThreadObserver** aObs)
 {
   MutexAutoLock lock(mLock);
-  NS_IF_ADDREF(*obs = mObserver);
+  NS_IF_ADDREF(*aObs = mObserver);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::SetObserver(nsIThreadObserver *obs)
+nsThread::SetObserver(nsIThreadObserver* aObs)
 {
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
   MutexAutoLock lock(mLock);
-  mObserver = obs;
+  mObserver = aObs;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::GetRecursionDepth(uint32_t *depth)
+nsThread::GetRecursionDepth(uint32_t* aDepth)
 {
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
-  *depth = mRunningEvent;
+  *aDepth = mRunningEvent;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::AddObserver(nsIThreadObserver *observer)
+nsThread::AddObserver(nsIThreadObserver* aObserver)
 {
-  if (NS_WARN_IF(!observer))
+  if (NS_WARN_IF(!aObserver)) {
     return NS_ERROR_INVALID_ARG;
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  }
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
-  NS_WARN_IF_FALSE(!mEventObservers.Contains(observer),
+  NS_WARN_IF_FALSE(!mEventObservers.Contains(aObserver),
                    "Adding an observer twice!");
 
-  if (!mEventObservers.AppendElement(observer)) {
+  if (!mEventObservers.AppendElement(aObserver)) {
     NS_WARNING("Out of memory!");
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::RemoveObserver(nsIThreadObserver *observer)
+nsThread::RemoveObserver(nsIThreadObserver* aObserver)
 {
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
-  if (observer && !mEventObservers.RemoveElement(observer)) {
+  if (aObserver && !mEventObservers.RemoveElement(aObserver)) {
     NS_WARNING("Removing an observer that was never added!");
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::PushEventQueue(nsIEventTarget **result)
+nsThread::PushEventQueue(nsIEventTarget** aResult)
 {
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
-  nsChainedEventQueue *queue = new nsChainedEventQueue();
+  nsChainedEventQueue* queue = new nsChainedEventQueue();
   queue->mEventTarget = new nsNestedEventTarget(this, queue);
 
   {
     MutexAutoLock lock(mLock);
     queue->mNext = mEvents;
     mEvents = queue;
   }
 
-  NS_ADDREF(*result = queue->mEventTarget);
+  NS_ADDREF(*aResult = queue->mEventTarget);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThread::PopEventQueue(nsIEventTarget *innermostTarget)
+nsThread::PopEventQueue(nsIEventTarget* aInnermostTarget)
 {
-  if (NS_WARN_IF(PR_GetCurrentThread() != mThread))
+  if (NS_WARN_IF(PR_GetCurrentThread() != mThread)) {
     return NS_ERROR_NOT_SAME_THREAD;
+  }
 
-  if (NS_WARN_IF(!innermostTarget))
+  if (NS_WARN_IF(!aInnermostTarget)) {
     return NS_ERROR_NULL_POINTER;
+  }
 
   // Don't delete or release anything while holding the lock.
   nsAutoPtr<nsChainedEventQueue> queue;
   nsRefPtr<nsNestedEventTarget> target;
 
   {
     MutexAutoLock lock(mLock);
 
     // Make sure we're popping the innermost event target.
-    if (NS_WARN_IF(mEvents->mEventTarget != innermostTarget))
+    if (NS_WARN_IF(mEvents->mEventTarget != aInnermostTarget)) {
       return NS_ERROR_UNEXPECTED;
+    }
 
     MOZ_ASSERT(mEvents != &mEventsRoot);
 
     queue = mEvents;
     mEvents = mEvents->mNext;
 
     nsCOMPtr<nsIRunnable> event;
-    while (queue->GetEvent(false, getter_AddRefs(event)))
+    while (queue->GetEvent(false, getter_AddRefs(event))) {
       mEvents->PutEvent(event);
+    }
 
     // Don't let the event target post any more events.
     queue->mEventTarget.swap(target);
     target->mQueue = nullptr;
   }
 
   return NS_OK;
 }
@@ -931,21 +996,21 @@ nsThreadSyncDispatch::Run()
   return NS_OK;
 }
 
 //-----------------------------------------------------------------------------
 
 NS_IMPL_ISUPPORTS(nsThread::nsNestedEventTarget, nsIEventTarget)
 
 NS_IMETHODIMP
-nsThread::nsNestedEventTarget::Dispatch(nsIRunnable *event, uint32_t flags)
+nsThread::nsNestedEventTarget::Dispatch(nsIRunnable* aEvent, uint32_t aFlags)
 {
-  LOG(("THRD(%p) Dispatch [%p %x] to nested loop %p\n", mThread.get(), event,
-       flags, this));
+  LOG(("THRD(%p) Dispatch [%p %x] to nested loop %p\n", mThread.get(), aEvent,
+       aFlags, this));
 
-  return mThread->DispatchInternal(event, flags, this);
+  return mThread->DispatchInternal(aEvent, aFlags, this);
 }
 
 NS_IMETHODIMP
-nsThread::nsNestedEventTarget::IsOnCurrentThread(bool *result)
+nsThread::nsNestedEventTarget::IsOnCurrentThread(bool* aResult)
 {
-  return mThread->IsOnCurrentThread(result);
+  return mThread->IsOnCurrentThread(aResult);
 }
--- a/xpcom/threads/nsThread.h
+++ b/xpcom/threads/nsThread.h
@@ -13,169 +13,201 @@
 #include "nsEventQueue.h"
 #include "nsThreadUtils.h"
 #include "nsString.h"
 #include "nsTObserverArray.h"
 #include "mozilla/Attributes.h"
 #include "nsAutoPtr.h"
 
 // A native thread
-class nsThread : public nsIThreadInternal,
-                 public nsISupportsPriority
+class nsThread
+  : public nsIThreadInternal
+  , public nsISupportsPriority
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIEVENTTARGET
   NS_DECL_NSITHREAD
   NS_DECL_NSITHREADINTERNAL
   NS_DECL_NSISUPPORTSPRIORITY
 
-  enum MainThreadFlag {
+  enum MainThreadFlag
+  {
     MAIN_THREAD,
     NOT_MAIN_THREAD
   };
 
   nsThread(MainThreadFlag aMainThread, uint32_t aStackSize);
 
   // Initialize this as a wrapper for a new PRThread.
   nsresult Init();
 
   // Initialize this as a wrapper for the current PRThread.
   nsresult InitCurrentThread();
 
   // The PRThread corresponding to this thread.
-  PRThread *GetPRThread() { return mThread; }
+  PRThread* GetPRThread()
+  {
+    return mThread;
+  }
 
   // If this flag is true, then the nsThread was created using
   // nsIThreadManager::NewThread.
-  bool ShutdownRequired() { return mShutdownRequired; }
+  bool ShutdownRequired()
+  {
+    return mShutdownRequired;
+  }
 
   // Clear the observer list.
-  void ClearObservers() { mEventObservers.Clear(); }
+  void ClearObservers()
+  {
+    mEventObservers.Clear();
+  }
 
   static nsresult
   SetMainThreadObserver(nsIThreadObserver* aObserver);
 
 protected:
   static nsIThreadObserver* sMainThreadObserver;
 
   class nsChainedEventQueue;
 
   class nsNestedEventTarget;
   friend class nsNestedEventTarget;
 
   friend class nsThreadShutdownEvent;
 
   virtual ~nsThread();
 
-  bool ShuttingDown() { return mShutdownContext != nullptr; }
+  bool ShuttingDown()
+  {
+    return mShutdownContext != nullptr;
+  }
 
-  static void ThreadFunc(void *arg);
+  static void ThreadFunc(void* aArg);
 
   // Helper
-  already_AddRefed<nsIThreadObserver> GetObserver() {
-    nsIThreadObserver *obs;
+  already_AddRefed<nsIThreadObserver> GetObserver()
+  {
+    nsIThreadObserver* obs;
     nsThread::GetObserver(&obs);
     return already_AddRefed<nsIThreadObserver>(obs);
   }
 
   // Wrappers for event queue methods:
-  bool GetEvent(bool mayWait, nsIRunnable **event) {
-    return mEvents->GetEvent(mayWait, event);
+  bool GetEvent(bool aMayWait, nsIRunnable** aEvent)
+  {
+    return mEvents->GetEvent(aMayWait, aEvent);
   }
-  nsresult PutEvent(nsIRunnable *event, nsNestedEventTarget *target);
+  nsresult PutEvent(nsIRunnable* aEvent, nsNestedEventTarget* aTarget);
 
-  nsresult DispatchInternal(nsIRunnable *event, uint32_t flags,
-                            nsNestedEventTarget *target);
+  nsresult DispatchInternal(nsIRunnable* aEvent, uint32_t aFlags,
+                            nsNestedEventTarget* aTarget);
 
   // Wrapper for nsEventQueue that supports chaining.
-  class nsChainedEventQueue {
+  class nsChainedEventQueue
+  {
   public:
     nsChainedEventQueue()
-      : mNext(nullptr) {
+      : mNext(nullptr)
+    {
     }
 
-    bool GetEvent(bool mayWait, nsIRunnable **event) {
-      return mQueue.GetEvent(mayWait, event);
+    bool GetEvent(bool aMayWait, nsIRunnable** aEvent)
+    {
+      return mQueue.GetEvent(aMayWait, aEvent);
     }
 
-    void PutEvent(nsIRunnable *event) {
-      mQueue.PutEvent(event);
+    void PutEvent(nsIRunnable* aEvent)
+    {
+      mQueue.PutEvent(aEvent);
     }
 
-    bool HasPendingEvent() {
+    bool HasPendingEvent()
+    {
       return mQueue.HasPendingEvent();
     }
 
-    nsChainedEventQueue *mNext;
+    nsChainedEventQueue* mNext;
     nsRefPtr<nsNestedEventTarget> mEventTarget;
 
   private:
     nsEventQueue mQueue;
   };
 
-  class nsNestedEventTarget MOZ_FINAL : public nsIEventTarget {
+  class nsNestedEventTarget MOZ_FINAL : public nsIEventTarget
+  {
   public:
     NS_DECL_THREADSAFE_ISUPPORTS
     NS_DECL_NSIEVENTTARGET
 
-    nsNestedEventTarget(nsThread *thread, nsChainedEventQueue *queue)
-      : mThread(thread), mQueue(queue) {
+    nsNestedEventTarget(nsThread* aThread, nsChainedEventQueue* aQueue)
+      : mThread(aThread)
+      , mQueue(aQueue)
+    {
     }
 
     nsRefPtr<nsThread> mThread;
 
     // This is protected by mThread->mLock.
     nsChainedEventQueue* mQueue;
 
   private:
-    ~nsNestedEventTarget() {}
+    ~nsNestedEventTarget()
+    {
+    }
   };
 
   // This lock protects access to mObserver, mEvents and mEventsAreDoomed.
   // All of those fields are only modified on the thread itself (never from
   // another thread).  This means that we can avoid holding the lock while
   // using mObserver and mEvents on the thread itself.  When calling PutEvent
   // on mEvents, we have to hold the lock to synchronize with PopEventQueue.
   mozilla::Mutex mLock;
 
   nsCOMPtr<nsIThreadObserver> mObserver;
 
   // Only accessed on the target thread.
   nsAutoTObserverArray<nsCOMPtr<nsIThreadObserver>, 2> mEventObservers;
 
-  nsChainedEventQueue *mEvents;   // never null
+  nsChainedEventQueue* mEvents;  // never null
   nsChainedEventQueue  mEventsRoot;
 
   int32_t   mPriority;
-  PRThread *mThread;
+  PRThread* mThread;
   uint32_t  mRunningEvent;  // counter
   uint32_t  mStackSize;
 
-  struct nsThreadShutdownContext *mShutdownContext;
+  struct nsThreadShutdownContext* mShutdownContext;
 
   bool mShutdownRequired;
   // Set to true when events posted to this thread will never run.
   bool mEventsAreDoomed;
   MainThreadFlag mIsMainThread;
 };
 
 //-----------------------------------------------------------------------------
 
-class nsThreadSyncDispatch : public nsRunnable {
+class nsThreadSyncDispatch : public nsRunnable
+{
 public:
-  nsThreadSyncDispatch(nsIThread *origin, nsIRunnable *task)
-    : mOrigin(origin), mSyncTask(task), mResult(NS_ERROR_NOT_INITIALIZED) {
+  nsThreadSyncDispatch(nsIThread* aOrigin, nsIRunnable* aTask)
+    : mOrigin(aOrigin)
+    , mSyncTask(aTask)
+    , mResult(NS_ERROR_NOT_INITIALIZED)
+  {
   }
 
-  bool IsPending() {
+  bool IsPending()
+  {
     return mSyncTask != nullptr;
   }
 
-  nsresult Result() {
+  nsresult Result()
+  {
     return mResult;
   }
 
 private:
   NS_DECL_NSIRUNNABLE
 
   nsCOMPtr<nsIThread> mOrigin;
   nsCOMPtr<nsIRunnable> mSyncTask;
--- a/xpcom/threads/nsThreadManager.cpp
+++ b/xpcom/threads/nsThreadManager.cpp
@@ -19,83 +19,94 @@ using namespace mozilla;
 
 #ifdef XP_WIN
 #include <windows.h>
 DWORD gTLSThreadIDIndex = TlsAlloc();
 #elif defined(NS_TLS)
 NS_TLS mozilla::threads::ID gTLSThreadID = mozilla::threads::Generic;
 #endif
 
-typedef nsTArray< nsRefPtr<nsThread> > nsThreadArray;
+typedef nsTArray<nsRefPtr<nsThread>> nsThreadArray;
 
 //-----------------------------------------------------------------------------
 
 static void
-ReleaseObject(void *data)
+ReleaseObject(void* aData)
 {
-  static_cast<nsISupports *>(data)->Release();
+  static_cast<nsISupports*>(aData)->Release();
 }
 
 static PLDHashOperator
-AppendAndRemoveThread(PRThread *key, nsRefPtr<nsThread> &thread, void *arg)
+AppendAndRemoveThread(PRThread* aKey, nsRefPtr<nsThread>& aThread, void* aArg)
 {
-  nsThreadArray *threads = static_cast<nsThreadArray *>(arg);
-  threads->AppendElement(thread);
+  nsThreadArray* threads = static_cast<nsThreadArray*>(aArg);
+  threads->AppendElement(aThread);
   return PL_DHASH_REMOVE;
 }
 
 // statically allocated instance
-NS_IMETHODIMP_(MozExternalRefCountType) nsThreadManager::AddRef() { return 2; }
-NS_IMETHODIMP_(MozExternalRefCountType) nsThreadManager::Release() { return 1; }
+NS_IMETHODIMP_(MozExternalRefCountType)
+nsThreadManager::AddRef()
+{
+  return 2;
+}
+NS_IMETHODIMP_(MozExternalRefCountType)
+nsThreadManager::Release()
+{
+  return 1;
+}
 NS_IMPL_CLASSINFO(nsThreadManager, nullptr,
                   nsIClassInfo::THREADSAFE | nsIClassInfo::SINGLETON,
                   NS_THREADMANAGER_CID)
 NS_IMPL_QUERY_INTERFACE_CI(nsThreadManager, nsIThreadManager)
 NS_IMPL_CI_INTERFACE_GETTER(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)
+  if (mInitialized) {
     return NS_OK;
+  }
 
-  if (PR_NewThreadPrivateIndex(&mCurThreadIndex, ReleaseObject) == PR_FAILURE)
+  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;
+  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);
 
   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
   // GetIsMainThread calls that occur post-Shutdown.
   mMainThread->GetPRThread(&mMainPRThread);
 
 #ifdef XP_WIN
-  TlsSetValue(gTLSThreadIDIndex, (void*) mozilla::threads::Main);
+  TlsSetValue(gTLSThreadIDIndex, (void*)mozilla::threads::Main);
 #elif defined(NS_TLS)
   gTLSThreadID = mozilla::threads::Main;
 #endif
 
   mInitialized = true;
   return NS_OK;
 }
 
@@ -121,26 +132,27 @@ nsThreadManager::Shutdown()
     MutexAutoLock lock(*mLock);
     mThreadsByPRThread.Enumerate(AppendAndRemoveThread, &threads);
   }
 
   // It's tempting to walk the list of threads here and tell them each to stop
   // accepting new events, but that could lead to badness if one of those
   // threads is stuck waiting for a response from another thread.  To do it
   // right, we'd need some way to interrupt the threads.
-  // 
+  //
   // Instead, we process events on the current thread while waiting for threads
   // to shutdown.  This means that we have to preserve a mostly functioning
   // world until such time as the threads exit.
 
   // Shutdown all threads that require it (join with threads that we created).
   for (uint32_t i = 0; i < threads.Length(); ++i) {
-    nsThread *thread = threads[i];
-    if (thread->ShutdownRequired())
+    nsThread* thread = threads[i];
+    if (thread->ShutdownRequired()) {
       thread->Shutdown();
+    }
   }
 
   // In case there are any more events somehow...
   NS_ProcessPendingEvents(mMainThread);
 
   // There are no more background threads at this point.
 
   // Clear the table of threads.
@@ -159,143 +171,152 @@ nsThreadManager::Shutdown()
   mMainThread = nullptr;
   mLock = nullptr;
 
   // Remove the TLS entry for the main thread.
   PR_SetThreadPrivate(mCurThreadIndex, nullptr);
 }
 
 void
-nsThreadManager::RegisterCurrentThread(nsThread *thread)
+nsThreadManager::RegisterCurrentThread(nsThread* aThread)
 {
-  MOZ_ASSERT(thread->GetPRThread() == PR_GetCurrentThread(), "bad thread");
+  MOZ_ASSERT(aThread->GetPRThread() == PR_GetCurrentThread(), "bad aThread");
 
   MutexAutoLock lock(*mLock);
 
   ++mCurrentNumberOfThreads;
   if (mCurrentNumberOfThreads > mHighestNumberOfThreads) {
     mHighestNumberOfThreads = mCurrentNumberOfThreads;
   }
 
-  mThreadsByPRThread.Put(thread->GetPRThread(), thread);  // XXX check OOM?
+  mThreadsByPRThread.Put(aThread->GetPRThread(), aThread);  // XXX check OOM?
 
-  NS_ADDREF(thread);  // for TLS entry
-  PR_SetThreadPrivate(mCurThreadIndex, thread);
+  NS_ADDREF(aThread);  // for TLS entry
+  PR_SetThreadPrivate(mCurThreadIndex, aThread);
 }
 
 void
-nsThreadManager::UnregisterCurrentThread(nsThread *thread)
+nsThreadManager::UnregisterCurrentThread(nsThread* aThread)
 {
-  MOZ_ASSERT(thread->GetPRThread() == PR_GetCurrentThread(), "bad thread");
+  MOZ_ASSERT(aThread->GetPRThread() == PR_GetCurrentThread(), "bad aThread");
 
   MutexAutoLock lock(*mLock);
 
   --mCurrentNumberOfThreads;
-  mThreadsByPRThread.Remove(thread->GetPRThread());
+  mThreadsByPRThread.Remove(aThread->GetPRThread());
 
   PR_SetThreadPrivate(mCurThreadIndex, nullptr);
   // Ref-count balanced via ReleaseObject
 }
 
-nsThread *
+nsThread*
 nsThreadManager::GetCurrentThread()
 {
   // read thread local storage
-  void *data = PR_GetThreadPrivate(mCurThreadIndex);
-  if (data)
-    return static_cast<nsThread *>(data);
+  void* data = PR_GetThreadPrivate(mCurThreadIndex);
+  if (data) {
+    return static_cast<nsThread*>(data);
+  }
 
   if (!mInitialized) {
     return nullptr;
   }
 
   // OK, that's fine.  We'll dynamically create one :-)
   nsRefPtr<nsThread> thread = new nsThread(nsThread::NOT_MAIN_THREAD, 0);
-  if (!thread || NS_FAILED(thread->InitCurrentThread()))
+  if (!thread || NS_FAILED(thread->InitCurrentThread())) {
     return nullptr;
+  }
 
   return thread.get();  // reference held in TLS
 }
 
 NS_IMETHODIMP
-nsThreadManager::NewThread(uint32_t creationFlags,
-                           uint32_t stackSize,
-                           nsIThread **result)
+nsThreadManager::NewThread(uint32_t aCreationFlags,
+                           uint32_t aStackSize,
+                           nsIThread** aResult)
 {
   // No new threads during Shutdown
-  if (NS_WARN_IF(!mInitialized))
+  if (NS_WARN_IF(!mInitialized)) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
 
-  nsThread *thr = new nsThread(nsThread::NOT_MAIN_THREAD, stackSize);
-  if (!thr)
+  nsThread* thr = new nsThread(nsThread::NOT_MAIN_THREAD, aStackSize);
+  if (!thr) {
     return NS_ERROR_OUT_OF_MEMORY;
+  }
   NS_ADDREF(thr);
 
   nsresult rv = thr->Init();
   if (NS_FAILED(rv)) {
     NS_RELEASE(thr);
     return rv;
   }
 
   // At this point, we expect that the thread has been registered in mThread;
   // however, it is possible that it could have also been replaced by now, so
   // we cannot really assert that it was added.
 
-  *result = thr;
+  *aResult = thr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadManager::GetThreadFromPRThread(PRThread *thread, nsIThread **result)
+nsThreadManager::GetThreadFromPRThread(PRThread* aThread, nsIThread** aResult)
 {
   // Keep this functioning during Shutdown
-  if (NS_WARN_IF(!mMainThread))
+  if (NS_WARN_IF(!mMainThread)) {
     return NS_ERROR_NOT_INITIALIZED;
-  if (NS_WARN_IF(!thread))
+  }
+  if (NS_WARN_IF(!aThread)) {
     return NS_ERROR_INVALID_ARG;
+  }
 
   nsRefPtr<nsThread> temp;
   {
     MutexAutoLock lock(*mLock);
-    mThreadsByPRThread.Get(thread, getter_AddRefs(temp));
+    mThreadsByPRThread.Get(aThread, getter_AddRefs(temp));
   }
 
-  NS_IF_ADDREF(*result = temp);
+  NS_IF_ADDREF(*aResult = temp);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadManager::GetMainThread(nsIThread **result)
+nsThreadManager::GetMainThread(nsIThread** aResult)
 {
   // Keep this functioning during Shutdown
-  if (NS_WARN_IF(!mMainThread))
+  if (NS_WARN_IF(!mMainThread)) {
     return NS_ERROR_NOT_INITIALIZED;
-  NS_ADDREF(*result = mMainThread);
+  }
+  NS_ADDREF(*aResult = mMainThread);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadManager::GetCurrentThread(nsIThread **result)
+nsThreadManager::GetCurrentThread(nsIThread** aResult)
 {
   // Keep this functioning during Shutdown
-  if (NS_WARN_IF(!mMainThread))
+  if (NS_WARN_IF(!mMainThread)) {
     return NS_ERROR_NOT_INITIALIZED;
-  *result = GetCurrentThread();
-  if (!*result)
+  }
+  *aResult = GetCurrentThread();
+  if (!*aResult) {
     return NS_ERROR_OUT_OF_MEMORY;
-  NS_ADDREF(*result);
+  }
+  NS_ADDREF(*aResult);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadManager::GetIsMainThread(bool *result)
+nsThreadManager::GetIsMainThread(bool* aResult)
 {
   // This method may be called post-Shutdown
 
-  *result = (PR_GetCurrentThread() == mMainPRThread);
+  *aResult = (PR_GetCurrentThread() == mMainPRThread);
   return NS_OK;
 }
 
 uint32_t
 nsThreadManager::GetHighestNumberOfThreads()
 {
   MutexAutoLock lock(*mLock);
   return mHighestNumberOfThreads;
--- a/xpcom/threads/nsThreadManager.h
+++ b/xpcom/threads/nsThreadManager.h
@@ -15,70 +15,74 @@
 class nsIRunnable;
 
 class nsThreadManager : public nsIThreadManager
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSITHREADMANAGER
 
-  static nsThreadManager *get() {
+  static nsThreadManager* get()
+  {
     static nsThreadManager sInstance;
     return &sInstance;
   }
 
   nsresult Init();
 
   // Shutdown all threads.  This function should only be called on the main
   // thread of the application process.
   void Shutdown();
 
   // Called by nsThread to inform the ThreadManager it exists.  This method
   // must be called when the given thread is the current thread.
-  void RegisterCurrentThread(nsThread *thread);
+  void RegisterCurrentThread(nsThread* aThread);
 
   // Called by nsThread to inform the ThreadManager it is going away.  This
   // method must be called when the given thread is the current thread.
-  void UnregisterCurrentThread(nsThread *thread);
+  void UnregisterCurrentThread(nsThread* aThread);
 
   // Returns the current thread.  Returns null if OOM or if ThreadManager isn't
   // initialized.
-  nsThread *GetCurrentThread();
+  nsThread* GetCurrentThread();
 
   // Returns the maximal number of threads that have been in existence
   // simultaneously during the execution of the thread manager.
   uint32_t GetHighestNumberOfThreads();
 
   // This needs to be public in order to support static instantiation of this
   // class with older compilers (e.g., egcs-2.91.66).
-  ~nsThreadManager() {}
+  ~nsThreadManager()
+  {
+  }
 
 private:
   nsThreadManager()
     : mCurThreadIndex(0)
     , mMainPRThread(nullptr)
     , mLock(nullptr)
     , mInitialized(false)
     , mCurrentNumberOfThreads(1)
-    , mHighestNumberOfThreads(1) {
+    , mHighestNumberOfThreads(1)
+  {
   }
 
   nsRefPtrHashtable<nsPtrHashKey<PRThread>, nsThread> mThreadsByPRThread;
   unsigned             mCurThreadIndex;  // thread-local-storage index
   nsRefPtr<nsThread>  mMainThread;
-  PRThread           *mMainPRThread;
+  PRThread*           mMainPRThread;
   // This is a pointer in order to allow creating nsThreadManager from
   // the static context in debug builds.
   nsAutoPtr<mozilla::Mutex> mLock;  // protects tables
   bool                mInitialized;
 
-   // The current number of threads
-   uint32_t           mCurrentNumberOfThreads;
-   // The highest number of threads encountered so far during the session
-   uint32_t           mHighestNumberOfThreads;
+  // The current number of threads
+  uint32_t            mCurrentNumberOfThreads;
+  // The highest number of threads encountered so far during the session
+  uint32_t            mHighestNumberOfThreads;
 };
 
 #define NS_THREADMANAGER_CID                       \
 { /* 7a4204c6-e45a-4c37-8ebb-6709a22c917c */       \
   0x7a4204c6,                                      \
   0xe45a,                                          \
   0x4c37,                                          \
   {0x8e, 0xbb, 0x67, 0x09, 0xa2, 0x2c, 0x91, 0x7c} \
--- a/xpcom/threads/nsThreadPool.cpp
+++ b/xpcom/threads/nsThreadPool.cpp
@@ -11,22 +11,23 @@
 #include "nsMemory.h"
 #include "nsAutoPtr.h"
 #include "prinrval.h"
 #include "prlog.h"
 
 using namespace mozilla;
 
 #ifdef PR_LOGGING
-static PRLogModuleInfo *
+static PRLogModuleInfo*
 GetThreadPoolLog()
 {
-  static PRLogModuleInfo *sLog;
-  if (!sLog)
+  static PRLogModuleInfo* sLog;
+  if (!sLog) {
     sLog = PR_NewLogModule("nsThreadPool");
+  }
   return sLog;
 }
 #endif
 #ifdef LOG
 #undef LOG
 #endif
 #define LOG(args) PR_LOG(GetThreadPoolLog(), PR_LOG_DEBUG, args)
 
@@ -61,52 +62,55 @@ nsThreadPool::nsThreadPool()
 nsThreadPool::~nsThreadPool()
 {
   // Threads keep a reference to the nsThreadPool until they return from Run()
   // after removing themselves from mThreads.
   MOZ_ASSERT(mThreads.IsEmpty());
 }
 
 nsresult
-nsThreadPool::PutEvent(nsIRunnable *event)
+nsThreadPool::PutEvent(nsIRunnable* aEvent)
 {
   // Avoid spawning a new thread while holding the event queue lock...
 
   bool spawnThread = false;
   uint32_t stackSize = 0;
   {
     ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
 
     LOG(("THRD-P(%p) put [%d %d %d]\n", this, mIdleCount, mThreads.Count(),
          mThreadLimit));
-    MOZ_ASSERT(mIdleCount <= (uint32_t) mThreads.Count(), "oops");
+    MOZ_ASSERT(mIdleCount <= (uint32_t)mThreads.Count(), "oops");
 
     // Make sure we have a thread to service this event.
-    if (mIdleCount == 0 && mThreads.Count() < (int32_t) mThreadLimit)
+    if (mIdleCount == 0 && mThreads.Count() < (int32_t)mThreadLimit) {
       spawnThread = true;
+    }
 
-    mEvents.PutEvent(event);
+    mEvents.PutEvent(aEvent);
     stackSize = mStackSize;
   }
 
   LOG(("THRD-P(%p) put [spawn=%d]\n", this, spawnThread));
-  if (!spawnThread)
+  if (!spawnThread) {
     return NS_OK;
+  }
 
   nsCOMPtr<nsIThread> thread;
   nsThreadManager::get()->NewThread(0,
                                     stackSize,
                                     getter_AddRefs(thread));
-  if (NS_WARN_IF(!thread))
+  if (NS_WARN_IF(!thread)) {
     return NS_ERROR_UNEXPECTED;
+  }
 
   bool killThread = false;
   {
     ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
-    if (mThreads.Count() < (int32_t) mThreadLimit) {
+    if (mThreads.Count() < (int32_t)mThreadLimit) {
       mThreads.AppendObject(thread);
     } else {
       killThread = true;  // okay, we don't need this thread anymore
     }
   }
   LOG(("THRD-P(%p) put [%p kill=%d]\n", this, thread.get(), killThread));
   if (killThread) {
     // Pending events are processed on the current thread during
@@ -121,26 +125,26 @@ nsThreadPool::PutEvent(nsIRunnable *even
   } else {
     thread->Dispatch(this, NS_DISPATCH_NORMAL);
   }
 
   return NS_OK;
 }
 
 void
-nsThreadPool::ShutdownThread(nsIThread *thread)
+nsThreadPool::ShutdownThread(nsIThread* aThread)
 {
-  LOG(("THRD-P(%p) shutdown async [%p]\n", this, thread));
+  LOG(("THRD-P(%p) shutdown async [%p]\n", this, aThread));
 
-  // This method is responsible for calling Shutdown on |thread|.  This must be
+  // This method is responsible for calling Shutdown on |aThread|.  This must be
   // done from some other thread, so we use the main thread of the application.
 
   MOZ_ASSERT(!NS_IsMainThread(), "wrong thread");
 
-  nsRefPtr<nsIRunnable> r = NS_NewRunnableMethod(thread, &nsIThread::Shutdown);
+  nsRefPtr<nsIRunnable> r = NS_NewRunnableMethod(aThread, &nsIThread::Shutdown);
   NS_DispatchToMainThread(r);
 }
 
 NS_IMETHODIMP
 nsThreadPool::Run()
 {
   LOG(("THRD-P(%p) enter\n", this));
 
@@ -173,33 +177,35 @@ nsThreadPool::Run()
         PRIntervalTime timeout = PR_MillisecondsToInterval(mIdleThreadTimeout);
 
         // If we are shutting down, then don't keep any idle threads
         if (mShutdown) {
           exitThread = true;
         } else {
           if (wasIdle) {
             // if too many idle threads or idle for too long, then bail.
-            if (mIdleCount > mIdleThreadLimit || (now - idleSince) >= timeout)
+            if (mIdleCount > mIdleThreadLimit || (now - idleSince) >= timeout) {
               exitThread = true;
+            }
           } else {
             // if would be too many idle threads...
             if (mIdleCount == mIdleThreadLimit) {
               exitThread = true;
             } else {
               ++mIdleCount;
               idleSince = now;
               wasIdle = true;
             }
           }
         }
 
         if (exitThread) {
-          if (wasIdle)
+          if (wasIdle) {
             --mIdleCount;
+          }
           shutdownThreadOnExit = mThreads.RemoveObject(current);
         } else {
           PRIntervalTime delta = timeout - (now - idleSince);
           LOG(("THRD-P(%p) waiting [%d]\n", this, delta));
           mon.Wait(delta);
         }
       } else if (wasIdle) {
         wasIdle = false;
@@ -220,54 +226,57 @@ nsThreadPool::Run()
     ShutdownThread(current);
   }
 
   LOG(("THRD-P(%p) leave\n", this));
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::Dispatch(nsIRunnable *event, uint32_t flags)
+nsThreadPool::Dispatch(nsIRunnable* aEvent, uint32_t aFlags)
 {
-  LOG(("THRD-P(%p) dispatch [%p %x]\n", this, event, flags));
+  LOG(("THRD-P(%p) dispatch [%p %x]\n", this, aEvent, aFlags));
 
-  if (NS_WARN_IF(mShutdown))
+  if (NS_WARN_IF(mShutdown)) {
     return NS_ERROR_NOT_AVAILABLE;
+  }
 
-  if (flags & DISPATCH_SYNC) {
+  if (aFlags & DISPATCH_SYNC) {
     nsCOMPtr<nsIThread> thread;
     nsThreadManager::get()->GetCurrentThread(getter_AddRefs(thread));
-    if (NS_WARN_IF(!thread))
+    if (NS_WARN_IF(!thread)) {
       return NS_ERROR_NOT_AVAILABLE;
+    }
 
     nsRefPtr<nsThreadSyncDispatch> wrapper =
-        new nsThreadSyncDispatch(thread, event);
+      new nsThreadSyncDispatch(thread, aEvent);
     PutEvent(wrapper);
 
-    while (wrapper->IsPending())
+    while (wrapper->IsPending()) {
       NS_ProcessNextEvent(thread);
+    }
   } else {
-    NS_ASSERTION(flags == NS_DISPATCH_NORMAL, "unexpected dispatch flags");
-    PutEvent(event);
+    NS_ASSERTION(aFlags == NS_DISPATCH_NORMAL, "unexpected dispatch flags");
+    PutEvent(aEvent);
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::IsOnCurrentThread(bool *result)
+nsThreadPool::IsOnCurrentThread(bool* aResult)
 {
   ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
   nsIThread* thread = NS_GetCurrentThread();
   for (uint32_t i = 0; i < static_cast<uint32_t>(mThreads.Count()); ++i) {
     if (mThreads[i] == thread) {
-      *result = true;
+      *aResult = true;
       return NS_OK;
     }
   }
-  *result = false;
+  *aResult = false;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThreadPool::Shutdown()
 {
   nsCOMArray<nsIThread> threads;
   nsCOMPtr<nsIThreadPoolListener> listener;
@@ -283,99 +292,102 @@ nsThreadPool::Shutdown()
     // this method. The listener will be kept alive as long as the other threads
     // that were created when it was set.
     mListener.swap(listener);
   }
 
   // It's important that we shutdown the threads while outside the event queue
   // monitor.  Otherwise, we could end up dead-locking.
 
-  for (int32_t i = 0; i < threads.Count(); ++i)
+  for (int32_t i = 0; i < threads.Count(); ++i) {
     threads[i]->Shutdown();
+  }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::GetThreadLimit(uint32_t *value)
+nsThreadPool::GetThreadLimit(uint32_t* aValue)
 {
-  *value = mThreadLimit;
+  *aValue = mThreadLimit;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::SetThreadLimit(uint32_t value)
+nsThreadPool::SetThreadLimit(uint32_t aValue)
 {
   ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
-  mThreadLimit = value;
-  if (mIdleThreadLimit > mThreadLimit)
+  mThreadLimit = aValue;
+  if (mIdleThreadLimit > mThreadLimit) {
     mIdleThreadLimit = mThreadLimit;
+  }
 
   if (static_cast<uint32_t>(mThreads.Count()) > mThreadLimit) {
     mon.NotifyAll();  // wake up threads so they observe this change
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::GetIdleThreadLimit(uint32_t *value)
+nsThreadPool::GetIdleThreadLimit(uint32_t* aValue)
 {
-  *value = mIdleThreadLimit;
+  *aValue = mIdleThreadLimit;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::SetIdleThreadLimit(uint32_t value)
+nsThreadPool::SetIdleThreadLimit(uint32_t aValue)
 {
   ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
-  mIdleThreadLimit = value;
-  if (mIdleThreadLimit > mThreadLimit)
+  mIdleThreadLimit = aValue;
+  if (mIdleThreadLimit > mThreadLimit) {
     mIdleThreadLimit = mThreadLimit;
+  }
 
   // Do we need to kill some idle threads?
   if (mIdleCount > mIdleThreadLimit) {
     mon.NotifyAll();  // wake up threads so they observe this change
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::GetIdleThreadTimeout(uint32_t *value)
+nsThreadPool::GetIdleThreadTimeout(uint32_t* aValue)
 {
-  *value = mIdleThreadTimeout;
+  *aValue = mIdleThreadTimeout;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::SetIdleThreadTimeout(uint32_t value)
+nsThreadPool::SetIdleThreadTimeout(uint32_t aValue)
 {
   ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
   uint32_t oldTimeout = mIdleThreadTimeout;
-  mIdleThreadTimeout = value;
+  mIdleThreadTimeout = aValue;
 
   // Do we need to notify any idle threads that their sleep time has shortened?
   if (mIdleThreadTimeout < oldTimeout && mIdleCount > 0) {
     mon.NotifyAll();  // wake up threads so they observe this change
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::GetThreadStackSize(uint32_t* value)
+nsThreadPool::GetThreadStackSize(uint32_t* aValue)
 {
   ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
-  *value = mStackSize;
+  *aValue = mStackSize;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsThreadPool::SetThreadStackSize(uint32_t value)
+nsThreadPool::SetThreadStackSize(uint32_t aValue)
 {
   ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
-  mStackSize = value;
+  mStackSize = aValue;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThreadPool::GetListener(nsIThreadPoolListener** aListener)
 {
   ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
   NS_IF_ADDREF(*aListener = mListener);
@@ -393,15 +405,16 @@ nsThreadPool::SetListener(nsIThreadPoolL
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsThreadPool::SetName(const nsACString& aName)
 {
   {
     ReentrantMonitorAutoEnter mon(mEvents.GetReentrantMonitor());
-    if (mThreads.Count())
+    if (mThreads.Count()) {
       return NS_ERROR_NOT_AVAILABLE;
+    }
   }
 
   mName = aName;
   return NS_OK;
 }
--- a/xpcom/threads/nsThreadPool.h
+++ b/xpcom/threads/nsThreadPool.h
@@ -11,32 +11,33 @@
 #include "nsIThread.h"
 #include "nsIRunnable.h"
 #include "nsEventQueue.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Attributes.h"
 
-class nsThreadPool MOZ_FINAL : public nsIThreadPool,
-                               public nsIRunnable
+class nsThreadPool MOZ_FINAL
+  : public nsIThreadPool
+  , public nsIRunnable
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIEVENTTARGET
   NS_DECL_NSITHREADPOOL
   NS_DECL_NSIRUNNABLE
 
   nsThreadPool();
 
 private:
   ~nsThreadPool();
 
-  void ShutdownThread(nsIThread *thread);
-  nsresult PutEvent(nsIRunnable *event);
+  void ShutdownThread(nsIThread* aThread);
+  nsresult PutEvent(nsIRunnable* aEvent);
 
   nsCOMArray<nsIThread> mThreads;
   nsEventQueue          mEvents;
   uint32_t              mThreadLimit;
   uint32_t              mIdleThreadLimit;
   uint32_t              mIdleThreadTimeout;
   uint32_t              mIdleCount;
   uint32_t              mStackSize;
--- a/xpcom/threads/nsTimerImpl.cpp
+++ b/xpcom/threads/nsTimerImpl.cpp
@@ -21,40 +21,42 @@ using mozilla::TimeStamp;
 static Atomic<int32_t>  gGenerator;
 static TimerThread*     gThread = nullptr;
 
 #ifdef DEBUG_TIMERS
 
 PRLogModuleInfo*
 GetTimerLog()
 {
-  static PRLogModuleInfo *sLog;
-  if (!sLog)
+  static PRLogModuleInfo* sLog;
+  if (!sLog) {
     sLog = PR_NewLogModule("nsTimerImpl");
+  }
   return sLog;
 }
 
 #include <math.h>
 
 double nsTimerImpl::sDeltaSumSquared = 0;
 double nsTimerImpl::sDeltaSum = 0;
 double nsTimerImpl::sDeltaNum = 0;
 
 static void
 myNS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues,
-                   double *meanResult, double *stdDevResult)
+                   double* meanResult, double* stdDevResult)
 {
   double mean = 0.0, var = 0.0, stdDev = 0.0;
   if (n > 0.0 && sumOfValues >= 0) {
     mean = sumOfValues / n;
     double temp = (n * sumOfSquaredValues) - (sumOfValues * sumOfValues);
-    if (temp < 0.0 || n <= 1)
+    if (temp < 0.0 || n <= 1) {
       var = 0.0;
-    else
+    } else {
       var = temp / (n * (n - 1));
+    }
     // for some reason, Windows says sqrt(0.0) is "-1.#J" (?!) so do this:
     stdDev = var != 0.0 ? sqrt(var) : 0.0;
   }
   *meanResult = mean;
   *stdDevResult = stdDev;
 }
 #endif
 
@@ -72,77 +74,84 @@ namespace {
 // for later recycling.  So the amount of memory consumed will always be equal
 // to the high-water mark consumption.  But nsTimerEvents are small and it's
 // unusual to have more than a few hundred of them, so this shouldn't be a
 // problem in practice.
 
 class TimerEventAllocator
 {
 private:
-  struct FreeEntry {
+  struct FreeEntry
+  {
     FreeEntry* mNext;
   };
 
   PLArenaPool mPool;
   FreeEntry* mFirstFree;
   mozilla::Monitor mMonitor;
 
 public:
   TimerEventAllocator()
-    : mFirstFree(nullptr),
-      mMonitor("TimerEventAllocator")
+    : mFirstFree(nullptr)
+    , mMonitor("TimerEventAllocator")
   {
     PL_InitArenaPool(&mPool, "TimerEventPool", 4096, /* align = */ 0);
   }
 
   ~TimerEventAllocator()
   {
     PL_FinishArenaPool(&mPool);
   }
 
   void* Alloc(size_t aSize);
   void Free(void* aPtr);
 };
 
 } // anonymous namespace
 
-class nsTimerEvent : public nsRunnable {
+class nsTimerEvent : public nsRunnable
+{
 public:
   NS_IMETHOD Run();
 
-  nsTimerEvent(nsTimerImpl *timer, int32_t generation)
-    : mTimer(dont_AddRef(timer)), mGeneration(generation) {
-    // timer is already addref'd for us
+  nsTimerEvent(nsTimerImpl* aTimer, int32_t aGeneration)
+    : mTimer(dont_AddRef(aTimer))
+    , mGeneration(aGeneration)
+  {
+    // aTimer is already addref'd for us
     MOZ_COUNT_CTOR(nsTimerEvent);
 
     MOZ_ASSERT(gThread->IsOnTimerThread(),
                "nsTimer must always be allocated on the timer thread");
 
     sAllocatorUsers++;
   }
 
 #ifdef DEBUG_TIMERS
   TimeStamp mInitTime;
 #endif
 
   static void Init();
   static void Shutdown();
   static void DeleteAllocatorIfNeeded();
 
-  static void* operator new(size_t size) CPP_THROW_NEW {
-    return sAllocator->Alloc(size);
+  static void* operator new(size_t aSize) CPP_THROW_NEW
+  {
+    return sAllocator->Alloc(aSize);
   }
-  void operator delete(void* p) {
-    sAllocator->Free(p);
+  void operator delete(void* aPtr)
+  {
+    sAllocator->Free(aPtr);
     DeleteAllocatorIfNeeded();
   }
 
 private:
   nsTimerEvent(); // Not implemented
-  ~nsTimerEvent() {
+  ~nsTimerEvent()
+  {
     MOZ_COUNT_DTOR(nsTimerEvent);
 
     MOZ_ASSERT(!sCanDeleteAllocator || sAllocatorUsers > 0,
                "This will result in us attempting to deallocate the nsTimerEvent allocator twice");
     sAllocatorUsers--;
   }
 
   nsRefPtr<nsTimerImpl> mTimer;
@@ -154,52 +163,55 @@ private:
 };
 
 TimerEventAllocator* nsTimerEvent::sAllocator = nullptr;
 Atomic<int32_t> nsTimerEvent::sAllocatorUsers;
 bool nsTimerEvent::sCanDeleteAllocator = false;
 
 namespace {
 
-void* TimerEventAllocator::Alloc(size_t aSize)
+void*
+TimerEventAllocator::Alloc(size_t aSize)
 {
   MOZ_ASSERT(aSize == sizeof(nsTimerEvent));
 
   mozilla::MonitorAutoLock lock(mMonitor);
 
   void* p;
   if (mFirstFree) {
     p = mFirstFree;
     mFirstFree = mFirstFree->mNext;
-  }
-  else {
+  } else {
     PL_ARENA_ALLOCATE(p, &mPool, aSize);
-    if (!p)
+    if (!p) {
       return nullptr;
+    }
   }
 
   return p;
 }
 
-void TimerEventAllocator::Free(void* aPtr)
+void
+TimerEventAllocator::Free(void* aPtr)
 {
   mozilla::MonitorAutoLock lock(mMonitor);
 
   FreeEntry* entry = reinterpret_cast<FreeEntry*>(aPtr);
 
   entry->mNext = mFirstFree;
   mFirstFree = entry;
 }
 
 } // anonymous namespace
 
 NS_IMPL_QUERY_INTERFACE(nsTimerImpl, nsITimer)
 NS_IMPL_ADDREF(nsTimerImpl)
 
-NS_IMETHODIMP_(MozExternalRefCountType) nsTimerImpl::Release(void)
+NS_IMETHODIMP_(MozExternalRefCountType)
+nsTimerImpl::Release(void)
 {
   nsrefcnt count;
 
   MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release");
   count = --mRefCnt;
   NS_LOG_RELEASE(this, count, "nsTimerImpl");
   if (count == 0) {
     mRefCnt = 1; /* stabilize */
@@ -238,18 +250,19 @@ NS_IMETHODIMP_(MozExternalRefCountType) 
   // except the TimerThread who might have a strong ref, from dropping all
   // their strong refs without implicitly canceling the timer.  Timers need
   // non-mTimers-element strong refs to stay alive.
 
   if (count == 1 && mArmed) {
     mCanceled = true;
 
     MOZ_ASSERT(gThread, "Armed timer exists after the thread timer stopped.");
-    if (NS_SUCCEEDED(gThread->RemoveTimer(this)))
+    if (NS_SUCCEEDED(gThread->RemoveTimer(this))) {
       return 0;
+    }
   }
 
   return count;
 }
 
 nsTimerImpl::nsTimerImpl() :
   mClosure(nullptr),
   mCallbackType(CALLBACK_TYPE_UNKNOWN),
@@ -274,238 +287,270 @@ nsTimerImpl::~nsTimerImpl()
 nsresult
 nsTimerImpl::Startup()
 {
   nsresult rv;
 
   nsTimerEvent::Init();
 
   gThread = new TimerThread();
-  if (!gThread) return NS_ERROR_OUT_OF_MEMORY;
+  if (!gThread) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
 
   NS_ADDREF(gThread);
   rv = gThread->InitLocks();
 
   if (NS_FAILED(rv)) {
     NS_RELEASE(gThread);
   }
 
   return rv;
 }
 
-void nsTimerImpl::Shutdown()
+void
+nsTimerImpl::Shutdown()
 {
 #ifdef DEBUG_TIMERS
   if (PR_LOG_TEST(GetTimerLog(), PR_LOG_DEBUG)) {
     double mean = 0, stddev = 0;
     myNS_MeanAndStdDev(sDeltaNum, sDeltaSum, sDeltaSumSquared, &mean, &stddev);
 
-    PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("sDeltaNum = %f, sDeltaSum = %f, sDeltaSumSquared = %f\n", sDeltaNum, sDeltaSum, sDeltaSumSquared));
-    PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("mean: %fms, stddev: %fms\n", mean, stddev));
+    PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
+           ("sDeltaNum = %f, sDeltaSum = %f, sDeltaSumSquared = %f\n",
+            sDeltaNum, sDeltaSum, sDeltaSumSquared));
+    PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
+           ("mean: %fms, stddev: %fms\n", mean, stddev));
   }
 #endif
 
-  if (!gThread)
+  if (!gThread) {
     return;
+  }
 
   gThread->Shutdown();
   NS_RELEASE(gThread);
 
   nsTimerEvent::Shutdown();
 }
 
 
-nsresult nsTimerImpl::InitCommon(uint32_t aType, uint32_t aDelay)
+nsresult
+nsTimerImpl::InitCommon(uint32_t aType, uint32_t aDelay)
 {
   nsresult rv;
 
-  if (NS_WARN_IF(!gThread))
+  if (NS_WARN_IF(!gThread)) {
     return NS_ERROR_NOT_INITIALIZED;
+  }
   if (!mEventTarget) {
     NS_ERROR("mEventTarget is NULL");
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   rv = gThread->Init();
-  if (NS_WARN_IF(NS_FAILED(rv)))
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
+  }
 
   /**
    * In case of re-Init, both with and without a preceding Cancel, clear the
    * mCanceled flag and assign a new mGeneration.  But first, remove any armed
    * timer from the timer thread's list.
    *
    * If we are racing with the timer thread to remove this timer and we lose,
    * the RemoveTimer call made here will fail to find this timer in the timer
    * thread's list, and will return false harmlessly.  We test mArmed here to
    * avoid the small overhead in RemoveTimer of locking the timer thread and
    * checking its list for this timer.  It's safe to test mArmed even though
    * it might be cleared on another thread in the next cycle (or even already
    * be cleared by another CPU whose store hasn't reached our CPU's cache),
    * because RemoveTimer is idempotent.
    */
-  if (mArmed)
+  if (mArmed) {
     gThread->RemoveTimer(this);
+  }
   mCanceled = false;
   mTimeout = TimeStamp();
   mGeneration = gGenerator++;
 
   mType = (uint8_t)aType;
   SetDelayInternal(aDelay);
 
   return gThread->AddTimer(this);
 }
 
-NS_IMETHODIMP nsTimerImpl::InitWithFuncCallback(nsTimerCallbackFunc aFunc,
-                                                void *aClosure,
-                                                uint32_t aDelay,
-                                                uint32_t aType)
+NS_IMETHODIMP
+nsTimerImpl::InitWithFuncCallback(nsTimerCallbackFunc aFunc,
+                                  void* aClosure,
+                                  uint32_t aDelay,
+                                  uint32_t aType)
 {
-  if (NS_WARN_IF(!aFunc))
+  if (NS_WARN_IF(!aFunc)) {
     return NS_ERROR_INVALID_ARG;
-  
+  }
+
   ReleaseCallback();
   mCallbackType = CALLBACK_TYPE_FUNC;
   mCallback.c = aFunc;
   mClosure = aClosure;
 
   return InitCommon(aType, aDelay);
 }
 
-NS_IMETHODIMP nsTimerImpl::InitWithCallback(nsITimerCallback *aCallback,
-                                            uint32_t aDelay,
-                                            uint32_t aType)
+NS_IMETHODIMP
+nsTimerImpl::InitWithCallback(nsITimerCallback* aCallback,
+                              uint32_t aDelay,
+                              uint32_t aType)
 {
-  if (NS_WARN_IF(!aCallback))
+  if (NS_WARN_IF(!aCallback)) {
     return NS_ERROR_INVALID_ARG;
+  }
 
   ReleaseCallback();
   mCallbackType = CALLBACK_TYPE_INTERFACE;
   mCallback.i = aCallback;
   NS_ADDREF(mCallback.i);
 
   return InitCommon(aType, aDelay);
 }
 
-NS_IMETHODIMP nsTimerImpl::Init(nsIObserver *aObserver,
-                                uint32_t aDelay,
-                                uint32_t aType)
+NS_IMETHODIMP
+nsTimerImpl::Init(nsIObserver* aObserver, uint32_t aDelay, uint32_t aType)
 {
-  if (NS_WARN_IF(!aObserver))
+  if (NS_WARN_IF(!aObserver)) {
     return NS_ERROR_INVALID_ARG;
+  }
 
   ReleaseCallback();
   mCallbackType = CALLBACK_TYPE_OBSERVER;
   mCallback.o = aObserver;
   NS_ADDREF(mCallback.o);
 
   return InitCommon(aType, aDelay);
 }
 
-NS_IMETHODIMP nsTimerImpl::Cancel()
+NS_IMETHODIMP
+nsTimerImpl::Cancel()
 {
   mCanceled = true;
 
-  if (gThread)
+  if (gThread) {
     gThread->RemoveTimer(this);
+  }
 
   ReleaseCallback();
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsTimerImpl::SetDelay(uint32_t aDelay)
+NS_IMETHODIMP
+nsTimerImpl::SetDelay(uint32_t aDelay)
 {
   if (mCallbackType == CALLBACK_TYPE_UNKNOWN && mType == TYPE_ONE_SHOT) {
     // This may happen if someone tries to re-use a one-shot timer
     // by re-setting delay instead of reinitializing the timer.
     NS_ERROR("nsITimer->SetDelay() called when the "
              "one-shot timer is not set up.");
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // If we're already repeating precisely, update mTimeout now so that the
   // new delay takes effect in the future.
-  if (!mTimeout.IsNull() && mType == TYPE_REPEATING_PRECISE)
+  if (!mTimeout.IsNull() && mType == TYPE_REPEATING_PRECISE) {
     mTimeout = TimeStamp::Now();
+  }
 
   SetDelayInternal(aDelay);
 
-  if (!mFiring && gThread)
+  if (!mFiring && gThread) {
     gThread->TimerDelayChanged(this);
+  }
 
   return NS_OK;
 }
 
-NS_IMETHODIMP nsTimerImpl::GetDelay(uint32_t* aDelay)
+NS_IMETHODIMP
+nsTimerImpl::GetDelay(uint32_t* aDelay)
 {
   *aDelay = mDelay;
   return NS_OK;
 }
 
-NS_IMETHODIMP nsTimerImpl::SetType(uint32_t aType)
+NS_IMETHODIMP
+nsTimerImpl::SetType(uint32_t aType)
 {
   mType = (uint8_t)aType;
   // XXX if this is called, we should change the actual type.. this could effect
   // repeating timers.  we need to ensure in Fire() that if mType has changed
   // during the callback that we don't end up with the timer in the queue twice.
   return NS_OK;
 }
 
-NS_IMETHODIMP nsTimerImpl::GetType(uint32_t* aType)
+NS_IMETHODIMP
+nsTimerImpl::GetType(uint32_t* aType)
 {
   *aType = mType;
   return NS_OK;
 }
 
 
-NS_IMETHODIMP nsTimerImpl::GetClosure(void** aClosure)
+NS_IMETHODIMP
+nsTimerImpl::GetClosure(void** aClosure)
 {
   *aClosure = mClosure;
   return NS_OK;
 }
 
 
-NS_IMETHODIMP nsTimerImpl::GetCallback(nsITimerCallback **aCallback)
+NS_IMETHODIMP
+nsTimerImpl::GetCallback(nsITimerCallback** aCallback)
 {
-  if (mCallbackType == CALLBACK_TYPE_INTERFACE)
+  if (mCallbackType == CALLBACK_TYPE_INTERFACE) {
     NS_IF_ADDREF(*aCallback = mCallback.i);
-  else if (mTimerCallbackWhileFiring)
+  } else if (mTimerCallbackWhileFiring) {
     NS_ADDREF(*aCallback = mTimerCallbackWhileFiring);
-  else
+  } else {
     *aCallback = nullptr;
+  }
 
   return NS_OK;
 }
 
 
-NS_IMETHODIMP nsTimerImpl::GetTarget(nsIEventTarget** aTarget)
+NS_IMETHODIMP
+nsTimerImpl::GetTarget(nsIEventTarget** aTarget)
 {
   NS_IF_ADDREF(*aTarget = mEventTarget);
   return NS_OK;
 }
 
 
-NS_IMETHODIMP nsTimerImpl::SetTarget(nsIEventTarget* aTarget)
+NS_IMETHODIMP
+nsTimerImpl::SetTarget(nsIEventTarget* aTarget)
 {
-  if (NS_WARN_IF(mCallbackType != CALLBACK_TYPE_UNKNOWN))
+  if (NS_WARN_IF(mCallbackType != CALLBACK_TYPE_UNKNOWN)) {
     return NS_ERROR_ALREADY_INITIALIZED;
+  }
 
-  if (aTarget)
+  if (aTarget) {
     mEventTarget = aTarget;
-  else
+  } else {
     mEventTarget = static_cast<nsIEventTarget*>(NS_GetCurrentThread());
+  }
   return NS_OK;
 }
 
 
-void nsTimerImpl::Fire()
+void
+nsTimerImpl::Fire()
 {
-  if (mCanceled)
+  if (mCanceled) {
     return;
+  }
 
   PROFILER_LABEL("Timer", "Fire");
 
 #ifdef MOZ_TASK_TRACER
   mozilla::tasktracer::AutoRunFakeTracedTask runTracedTask(mTracedTask);
 #endif
 
 #ifdef DEBUG_TIMERS
@@ -514,74 +559,84 @@ void nsTimerImpl::Fire()
     TimeDuration   a = now - mStart; // actual delay in intervals
     TimeDuration   b = TimeDuration::FromMilliseconds(mDelay); // expected delay in intervals
     TimeDuration   delta = (a > b) ? a - b : b - a;
     uint32_t       d = delta.ToMilliseconds(); // delta in ms
     sDeltaSum += d;
     sDeltaSumSquared += double(d) * double(d);
     sDeltaNum++;
 
-    PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("[this=%p] expected delay time %4ums\n", this, mDelay));
-    PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("[this=%p] actual delay time   %fms\n", this, a.ToMilliseconds()));
-    PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("[this=%p] (mType is %d)       -------\n", this, mType));
-    PR_LOG(GetTimerLog(), PR_LOG_DEBUG, ("[this=%p]     delta           %4dms\n", this, (a > b) ? (int32_t)d : -(int32_t)d));
+    PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
+           ("[this=%p] expected delay time %4ums\n", this, mDelay));
+    PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
+           ("[this=%p] actual delay time   %fms\n", this,
+            a.ToMilliseconds()));
+    PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
+           ("[this=%p] (mType is %d)       -------\n", this, mType));
+    PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
+           ("[this=%p]     delta           %4dms\n",
+            this, (a > b) ? (int32_t)d : -(int32_t)d));
 
     mStart = mStart2;
     mStart2 = TimeStamp();
   }
 #endif
 
   TimeStamp timeout = mTimeout;
   if (IsRepeatingPrecisely()) {
     // Precise repeating timers advance mTimeout by mDelay without fail before
     // calling Fire().
     timeout -= TimeDuration::FromMilliseconds(mDelay);
   }
 
-  if (mCallbackType == CALLBACK_TYPE_INTERFACE)
+  if (mCallbackType == CALLBACK_TYPE_INTERFACE) {
     mTimerCallbackWhileFiring = mCallback.i;
+  }
   mFiring = true;
 
   // Handle callbacks that re-init the timer, but avoid leaking.
   // See bug 330128.
   CallbackUnion callback = mCallback;
   unsigned callbackType = mCallbackType;
-  if (callbackType == CALLBACK_TYPE_INTERFACE)
+  if (callbackType == CALLBACK_TYPE_INTERFACE) {
     NS_ADDREF(callback.i);
-  else if (callbackType == CALLBACK_TYPE_OBSERVER)
+  } else if (callbackType == CALLBACK_TYPE_OBSERVER) {
     NS_ADDREF(callback.o);
+  }
   ReleaseCallback();
 
   switch (callbackType) {
     case CALLBACK_TYPE_FUNC:
       callback.c(this, mClosure);
       break;
     case CALLBACK_TYPE_INTERFACE:
       callback.i->Notify(this);
       break;
     case CALLBACK_TYPE_OBSERVER:
       callback.o->Observe(static_cast<nsITimer*>(this),
                           NS_TIMER_CALLBACK_TOPIC,
                           nullptr);
       break;
-    default:;
+    default:
+      ;
   }
 
   // If the callback didn't re-init the timer, and it's not a one-shot timer,
   // restore the callback state.
   if (mCallbackType == CALLBACK_TYPE_UNKNOWN &&
       mType != TYPE_ONE_SHOT && !mCanceled) {
     mCallback = callback;
     mCallbackType = callbackType;
   } else {
     // The timer was a one-shot, or the callback was reinitialized.
-    if (callbackType == CALLBACK_TYPE_INTERFACE)
+    if (callbackType == CALLBACK_TYPE_INTERFACE) {
       NS_RELEASE(callback.i);
-    else if (callbackType == CALLBACK_TYPE_OBSERVER)
+    } else if (callbackType == CALLBACK_TYPE_OBSERVER) {
       NS_RELEASE(callback.o);
+    }
   }
 
   mFiring = false;
   mTimerCallbackWhileFiring = nullptr;
 
 #ifdef DEBUG_TIMERS
   if (PR_LOG_TEST(GetTimerLog(), PR_LOG_DEBUG)) {
     PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
@@ -589,140 +644,155 @@ void nsTimerImpl::Fire()
             this, (TimeStamp::Now() - now).ToMilliseconds()));
   }
 #endif
 
   // Reschedule repeating timers, except REPEATING_PRECISE which already did
   // that in PostTimerEvent, but make sure that we aren't armed already (which
   // can happen if the callback reinitialized the timer).
   if (IsRepeating() && mType != TYPE_REPEATING_PRECISE && !mArmed) {
-    if (mType == TYPE_REPEATING_SLACK)
-      SetDelayInternal(mDelay); // force mTimeout to be recomputed.  For
-                                // REPEATING_PRECISE_CAN_SKIP timers this has
-                                // already happened.
-    if (gThread)
+    if (mType == TYPE_REPEATING_SLACK) {
+      SetDelayInternal(mDelay);  // force mTimeout to be recomputed.  For
+    }
+    // REPEATING_PRECISE_CAN_SKIP timers this has
+    // already happened.
+    if (gThread) {
       gThread->AddTimer(this);
+    }
   }
 }
 
-void nsTimerEvent::Init()
+void
+nsTimerEvent::Init()
 {
   sAllocator = new TimerEventAllocator();
 }
 
-void nsTimerEvent::Shutdown()
+void
+nsTimerEvent::Shutdown()
 {
   sCanDeleteAllocator = true;
   DeleteAllocatorIfNeeded();
 }
 
-void nsTimerEvent::DeleteAllocatorIfNeeded()
+void
+nsTimerEvent::DeleteAllocatorIfNeeded()
 {
   if (sCanDeleteAllocator && sAllocatorUsers == 0) {
     delete sAllocator;
     sAllocator = nullptr;
   }
 }
 
-NS_IMETHODIMP nsTimerEvent::Run()
+NS_IMETHODIMP
+nsTimerEvent::Run()
 {
-  if (mGeneration != mTimer->GetGeneration())
+  if (mGeneration != mTimer->GetGeneration()) {
     return NS_OK;
+  }
 
 #ifdef DEBUG_TIMERS
   if (PR_LOG_TEST(GetTimerLog(), PR_LOG_DEBUG)) {
     TimeStamp now = TimeStamp::Now();
     PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
            ("[this=%p] time between PostTimerEvent() and Fire(): %fms\n",
             this, (now - mInitTime).ToMilliseconds()));
   }
 #endif
 
   mTimer->Fire();
 
   return NS_OK;
 }
 
-nsresult nsTimerImpl::PostTimerEvent()
+nsresult
+nsTimerImpl::PostTimerEvent()
 {
   if (!mEventTarget) {
     NS_ERROR("Attempt to post timer event to NULL event target");
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   // XXX we may want to reuse this nsTimerEvent in the case of repeating timers.
 
   // Since TimerThread addref'd 'this' for us, we don't need to addref here.
   // We will release in destroyMyEvent.  We need to copy the generation number
   // from this timer into the event, so we can avoid firing a timer that was
   // re-initialized after being canceled.
 
   nsRefPtr<nsTimerEvent> event = new nsTimerEvent(this, mGeneration);
-  if (!event)
+  if (!event) {
     return NS_ERROR_OUT_OF_MEMORY;
+  }
 
 #ifdef DEBUG_TIMERS
   if (PR_LOG_TEST(GetTimerLog(), PR_LOG_DEBUG)) {
     event->mInitTime = TimeStamp::Now();
   }
 #endif
 
   // If this is a repeating precise timer, we need to calculate the time for
   // the next timer to fire before we make the callback.
   if (IsRepeatingPrecisely()) {
     SetDelayInternal(mDelay);
 
     // But only re-arm REPEATING_PRECISE timers.
     if (gThread && mType == TYPE_REPEATING_PRECISE) {
       nsresult rv = gThread->AddTimer(this);
-      if (NS_FAILED(rv))
+      if (NS_FAILED(rv)) {
         return rv;
+      }
     }
   }
 
   nsresult rv = mEventTarget->Dispatch(event, NS_DISPATCH_NORMAL);
-  if (NS_FAILED(rv) && gThread)
+  if (NS_FAILED(rv) && gThread) {
     gThread->RemoveTimer(this);
+  }
   return rv;
 }
 
-void nsTimerImpl::SetDelayInternal(uint32_t aDelay)
+void
+nsTimerImpl::SetDelayInternal(uint32_t aDelay)
 {
   TimeDuration delayInterval = TimeDuration::FromMilliseconds(aDelay);
 
   mDelay = aDelay;
 
   TimeStamp now = TimeStamp::Now();
-  if (mTimeout.IsNull() || mType != TYPE_REPEATING_PRECISE)
+  if (mTimeout.IsNull() || mType != TYPE_REPEATING_PRECISE) {
     mTimeout = now;
+  }
 
   mTimeout += delayInterval;
 
 #ifdef DEBUG_TIMERS
   if (PR_LOG_TEST(GetTimerLog(), PR_LOG_DEBUG)) {
-    if (mStart.IsNull())
+    if (mStart.IsNull()) {
       mStart = now;
-    else
+    } else {
       mStart2 = now;
+    }
   }
 #endif
 }
 
 // NOT FOR PUBLIC CONSUMPTION!
 nsresult
-NS_NewTimer(nsITimer* *aResult, nsTimerCallbackFunc aCallback, void *aClosure,
+NS_NewTimer(nsITimer** aResult, nsTimerCallbackFunc aCallback, void* aClosure,
             uint32_t aDelay, uint32_t aType)
 {
-    nsTimerImpl* timer = new nsTimerImpl();
-    if (timer == nullptr)
-        return NS_ERROR_OUT_OF_MEMORY;
-    NS_ADDREF(timer);
+  nsTimerImpl* timer = new nsTimerImpl();
+  if (!timer) {
+    return NS_ERROR_OUT_OF_MEMORY;
+  }
+  NS_ADDREF(timer);
 
-    nsresult rv = timer->InitWithFuncCallback(aCallback, aClosure, 
-                                              aDelay, aType);
-    if (NS_FAILED(rv)) {
-        NS_RELEASE(timer);
-        return rv;
-    }
+  nsresult rv = timer->InitWithFuncCallback(aCallback, aClosure,
+                                            aDelay, aType);
+  if (NS_FAILED(rv)) {
+    NS_RELEASE(timer);
+    return rv;
+  }
 
-    *aResult = timer;
-    return NS_OK;
+  *aResult = timer;
+  return NS_OK;
 }
--- a/xpcom/threads/nsTimerImpl.h
+++ b/xpcom/threads/nsTimerImpl.h
@@ -18,31 +18,32 @@
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Attributes.h"
 
 #ifdef MOZ_TASK_TRACER
 #include "TracedTaskCommon.h"
 #endif
 
 #if defined(PR_LOGGING)
-extern PRLogModuleInfo *GetTimerLog();
+extern PRLogModuleInfo* GetTimerLog();
 #define DEBUG_TIMERS 1
 #else
 #undef DEBUG_TIMERS
 #endif
 
 #define NS_TIMER_CID \
 { /* 5ff24248-1dd2-11b2-8427-fbab44f29bc8 */         \
      0x5ff24248,                                     \
      0x1dd2,                                         \
      0x11b2,                                         \
     {0x84, 0x27, 0xfb, 0xab, 0x44, 0xf2, 0x9b, 0xc8} \
 }
 
-enum {
+enum
+{
   CALLBACK_TYPE_UNKNOWN   = 0,
   CALLBACK_TYPE_INTERFACE = 1,
   CALLBACK_TYPE_FUNC      = 2,
   CALLBACK_TYPE_OBSERVER  = 3
 };
 
 class nsTimerImpl MOZ_FINAL : public nsITimer
 {
@@ -59,17 +60,20 @@ public:
 
   void Fire();
   nsresult PostTimerEvent();
   void SetDelayInternal(uint32_t aDelay);
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSITIMER
 
-  int32_t GetGeneration() { return mGeneration; }
+  int32_t GetGeneration()
+  {
+    return mGeneration;
+  }
 
 #ifdef MOZ_TASK_TRACER
   void DispatchTracedTask()
   {
     mTracedTask = mozilla::tasktracer::CreateFakeTracedTask(*(int**)(this));
   }
 #endif
 
@@ -78,43 +82,47 @@ private:
   nsresult InitCommon(uint32_t aType, uint32_t aDelay);
 
   void ReleaseCallback()
   {
     // if we're the last owner of the callback object, make
     // sure that we don't recurse into ReleaseCallback in case
     // the callback's destructor calls Cancel() or similar.
     uint8_t cbType = mCallbackType;
-    mCallbackType = CALLBACK_TYPE_UNKNOWN; 
+    mCallbackType = CALLBACK_TYPE_UNKNOWN;
 
-    if (cbType == CALLBACK_TYPE_INTERFACE)
+    if (cbType == CALLBACK_TYPE_INTERFACE) {
       NS_RELEASE(mCallback.i);
-    else if (cbType == CALLBACK_TYPE_OBSERVER)
+    } else if (cbType == CALLBACK_TYPE_OBSERVER) {
       NS_RELEASE(mCallback.o);
+    }
   }
 
-  bool IsRepeating() const {
+  bool IsRepeating() const
+  {
     PR_STATIC_ASSERT(TYPE_ONE_SHOT < TYPE_REPEATING_SLACK);
     PR_STATIC_ASSERT(TYPE_REPEATING_SLACK < TYPE_REPEATING_PRECISE);
     PR_STATIC_ASSERT(TYPE_REPEATING_PRECISE < TYPE_REPEATING_PRECISE_CAN_SKIP);
     return mType >= TYPE_REPEATING_SLACK;
   }
 
-  bool IsRepeatingPrecisely() const {
+  bool IsRepeatingPrecisely() const
+  {
     return mType >= TYPE_REPEATING_PRECISE;
   }
 
   nsCOMPtr<nsIEventTarget> mEventTarget;
 
-  void *                mClosure;
+  void*                 mClosure;
 
-  union CallbackUnion {
+  union CallbackUnion
+  {
     nsTimerCallbackFunc c;
-    nsITimerCallback *  i;
-    nsIObserver *       o;
+    nsITimerCallback*   i;
+    nsIObserver*        o;
   } mCallback;
 
   // Some callers expect to be able to access the callback while the
   // timer is firing.
   nsCOMPtr<nsITimerCallback> mTimerCallbackWhileFiring;
 
   // These members are set by Init (called from NS_NewTimer) and never reset.
   uint8_t               mCallbackType;