Bug 1173756 - Part 2: Merge MainProcessRunnable and ParentProcessRunnable; r=luke
authorJan Varga <jan.varga@gmail.com>
Sat, 29 Aug 2015 07:45:12 +0200
changeset 259964 23d5ef182400250b989411323106f9ae61832381
parent 259963 154ab5d65f79200b833e33e6eb1d8c4024be2ff7
child 259965 1f1422d84e9dc9d24c0257709dfcd28d2d74c933
push id29296
push userryanvm@gmail.com
push dateSun, 30 Aug 2015 19:45:10 +0000
treeherdermozilla-central@2ad5077d86ba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1173756
milestone43.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 1173756 - Part 2: Merge MainProcessRunnable and ParentProcessRunnable; r=luke
dom/asmjscache/AsmJSCache.cpp
--- a/dom/asmjscache/AsmJSCache.cpp
+++ b/dom/asmjscache/AsmJSCache.cpp
@@ -48,16 +48,17 @@
 using mozilla::dom::quota::AssertIsOnIOThread;
 using mozilla::dom::quota::DirectoryLock;
 using mozilla::dom::quota::PersistenceType;
 using mozilla::dom::quota::QuotaManager;
 using mozilla::dom::quota::QuotaObject;
 using mozilla::dom::quota::UsageInfo;
 using mozilla::ipc::AssertIsOnBackgroundThread;
 using mozilla::ipc::BackgroundChild;
+using mozilla::ipc::IsOnBackgroundThread;
 using mozilla::ipc::PBackgroundChild;
 using mozilla::ipc::PrincipalInfo;
 using mozilla::unused;
 using mozilla::HashString;
 
 namespace mozilla {
 
 MOZ_TYPE_SPECIFIC_SCOPED_POINTER_TEMPLATE(ScopedPRFileDesc, PRFileDesc, PR_Close);
@@ -231,19 +232,19 @@ EvictEntries(nsIFile* aDirectory, const 
     }
 
     entry.clear();
   }
 }
 
 // FileDescriptorHolder owns a file descriptor and its memory mapping.
 // FileDescriptorHolder is derived by two runnable classes (that is,
-// (Parent|Child)ProcessRunnable. FileDescriptorHolder is derived by File and
-// MainProcessRunnable. Since File and MainProcessRunnable both need to be
-// runnables, FileDescriptorHolder also derives nsRunnable.
+// (Parent|Child)Runnable. FileDescriptorHolder is derived by File and
+// ParentRunnable. Since File and ParentRunnable both need to be runnables
+// FileDescriptorHolder also derives nsRunnable.
 class FileDescriptorHolder : public nsRunnable
 {
 public:
   FileDescriptorHolder()
   : mQuotaObject(nullptr),
     mFileSize(INT64_MIN),
     mFileDesc(nullptr),
     mFileMap(nullptr),
@@ -325,17 +326,17 @@ protected:
 
   nsRefPtr<QuotaObject> mQuotaObject;
   int64_t mFileSize;
   PRFileDesc* mFileDesc;
   PRFileMap* mFileMap;
   void* mMappedMemory;
 };
 
-// File is a base class derived by ChildProcessRunnable that presents a single
+// File is a base class derived by ChildRunnable that presents a single
 // interface to the AsmJSCache ops which need to wait until the file is open.
 class File : public FileDescriptorHolder
 {
 public:
   class AutoClose
   {
     File* mFile;
 
@@ -501,78 +502,85 @@ private:
     MOZ_ASSERT(mDirectoryLock);
 
     mDirectoryLock = nullptr;
 
     return NS_OK;
   }
 };
 
-// MainProcessRunnable is a base class derived by ParentProcessRunnable
-// that factors out the runnable state machine required to open a cache entry
-// that runs in the main process.
-class MainProcessRunnable
+// A runnable that implements a state machine required to open a cache entry.
+// It executes in the parent for a cache access originating in the child.
+// This runnable gets registered as an IPDL subprotocol actor so that it
+// can communicate with the corresponding ChildRunnable.
+class ParentRunnable final
   : public FileDescriptorHolder
   , public quota::OpenDirectoryListener
+  , public PAsmJSCacheEntryParent
 {
 public:
+  NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIRUNNABLE
 
-  MainProcessRunnable(const PrincipalInfo& aPrincipalInfo,
-                      OpenMode aOpenMode,
-                      WriteParams aWriteParams)
+  ParentRunnable(const PrincipalInfo& aPrincipalInfo,
+                 OpenMode aOpenMode,
+                 WriteParams aWriteParams)
   : mOwningThread(NS_GetCurrentThread()),
     mPrincipalInfo(aPrincipalInfo),
     mOpenMode(aOpenMode),
     mWriteParams(aWriteParams),
     mPersistence(quota::PERSISTENCE_TYPE_INVALID),
     mState(eInitial),
     mResult(JS::AsmJSCache_InternalError),
     mIsApp(false),
-    mEnforcingQuota(true)
+    mEnforcingQuota(true),
+    mActorDestroyed(false),
+    mOpened(false)
   {
     MOZ_ASSERT(XRE_IsParentProcess());
     AssertIsOnOwningThread();
+    MOZ_COUNT_CTOR(ParentRunnable);
   }
 
-  virtual ~MainProcessRunnable()
+private:
+  ~ParentRunnable()
   {
     MOZ_ASSERT(mState == eFinished);
     MOZ_ASSERT(!mDirectoryLock);
+    MOZ_ASSERT(mActorDestroyed);
+    MOZ_COUNT_DTOR(ParentRunnable);
   }
 
-protected:
+  bool
+  IsOnOwningThread() const
+  {
+    MOZ_ASSERT(mOwningThread);
+
+    bool current;
+    return NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)) && current;
+  }
+
   void
   AssertIsOnOwningThread() const
   {
-    AssertIsOnBackgroundThread();
-    MOZ_ASSERT(mOwningThread);
-    DebugOnly<bool> current;
-    MOZ_ASSERT(NS_SUCCEEDED(mOwningThread->IsOnCurrentThread(&current)));
-    MOZ_ASSERT(current);
+    MOZ_ASSERT(IsOnBackgroundThread());
+    MOZ_ASSERT(IsOnOwningThread());
   }
 
-  // This method is called by the derived class on the main thread when a
-  // cache entry has been selected to open.
   void
-  OpenForRead(unsigned aModuleIndex)
+  AssertIsOnNonOwningThread() const
   {
-    AssertIsOnOwningThread();
-    MOZ_ASSERT(mState == eWaitingToOpenCacheFileForRead);
-    MOZ_ASSERT(mOpenMode == eOpenForRead);
-
-    mModuleIndex = aModuleIndex;
-    mState = eDispatchToMainThread;
-    NS_DispatchToMainThread(this);
+    MOZ_ASSERT(!IsOnBackgroundThread());
+    MOZ_ASSERT(!IsOnOwningThread());
   }
 
-  // This method is called by the derived class on the main thread when no cache
-  // entry was found to open. If we just tried a lookup in persistent storage
-  // then we might still get a hit in temporary storage (for an asm.js module
-  // that wasn't compiled at install-time).
+  // This method is called on the owning thread when no cache entry was found
+  // to open. If we just tried a lookup in persistent storage then we might
+  // still get a hit in temporary storage (for an asm.js module that wasn't
+  // compiled at install-time).
   void
   CacheMiss()
   {
     AssertIsOnOwningThread();
     MOZ_ASSERT(mState == eFailedToReadMetadata ||
                mState == eWaitingToOpenCacheFileForRead);
     MOZ_ASSERT(mOpenMode == eOpenForRead);
 
@@ -584,68 +592,65 @@ protected:
     // Try again with a clean slate. InitOnMainThread will see that mPersistence
     // is initialized and switch to temporary storage.
     MOZ_ASSERT(mPersistence == quota::PERSISTENCE_TYPE_PERSISTENT);
     FinishOnOwningThread();
     mState = eInitial;
     NS_DispatchToMainThread(this);
   }
 
-  // This method is called by the derived class (either on the JS compilation
-  // thread or the main thread) when the JS engine is finished reading/writing
-  // the cache entry.
+  // This method is called on the owning thread when the JS engine is finished
+  // reading/writing the cache entry.
   void
   Close()
   {
+    AssertIsOnOwningThread();
     MOZ_ASSERT(mState == eOpened);
-    mState = eClosing;
-    MOZ_ALWAYS_TRUE(NS_SUCCEEDED(mOwningThread->Dispatch(this,
-                                                         NS_DISPATCH_NORMAL)));
+
+    mState = eFinished;
+
+    MOZ_ASSERT(mOpened);
+
+    FinishOnOwningThread();
   }
 
-  // This method is called both internally and by derived classes upon any
-  // failure that prevents the eventual opening of the cache entry.
+  // This method is called upon any failure that prevents the eventual opening
+  // of the cache entry.
   void
   Fail()
   {
+    AssertIsOnOwningThread();
+    MOZ_ASSERT(mState != eFinished);
+
+    mState = eFinished;
+
+    MOZ_ASSERT(!mOpened);
+
+    FinishOnOwningThread();
+
+    if (!mActorDestroyed) {
+      unused << Send__delete__(this, mResult);
+    }
+  }
+
+  // The same as method above but is intended to be called off the owning
+  // thread.
+  void
+  FailOnNonOwningThread()
+  {
+    AssertIsOnNonOwningThread();
     MOZ_ASSERT(mState != eOpened &&
-               mState != eClosing &&
                mState != eFailing &&
                mState != eFinished);
 
     mState = eFailing;
     MOZ_ALWAYS_TRUE(NS_SUCCEEDED(mOwningThread->Dispatch(this,
                                                          NS_DISPATCH_NORMAL)));
   }
 
-  // Called by MainProcessRunnable on the main thread after metadata is open:
-  virtual void
-  OnOpenMetadataForRead(const Metadata& aMetadata) = 0;
-
-  // Called by MainProcessRunnable on the main thread after the entry is open:
-  virtual void
-  OnOpenCacheFile() = 0;
-
-  // This method may be overridden, but it must be called from the overrider.
-  // Called by MainProcessRunnable on the main thread after a call to Fail():
-  virtual void
-  OnFailure(JS::AsmJSCacheResult aResult)
-  {
-    FinishOnOwningThread();
-  }
-
-  // This method may be overridden, but it must be called from the overrider.
-  // Called by MainProcessRunnable on the main thread after a call to Close():
-  virtual void
-  OnClose()
-  {
-    FinishOnOwningThread();
-  }
-
-private:
   void
   InitPersistenceType();
 
   nsresult
   InitOnMainThread();
 
   nsresult
   ReadMetadata();
@@ -662,34 +667,102 @@ private:
   void
   DispatchToIOThread()
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     // If shutdown just started, the QuotaManager may have been deleted.
     QuotaManager* qm = QuotaManager::Get();
     if (!qm) {
-      Fail();
+      FailOnNonOwningThread();
       return;
     }
 
     nsresult rv = qm->IOThread()->Dispatch(this, NS_DISPATCH_NORMAL);
     if (NS_FAILED(rv)) {
-      Fail();
+      FailOnNonOwningThread();
       return;
     }
   }
 
   // OpenDirectoryListener overrides.
   virtual void
   DirectoryLockAcquired(DirectoryLock* aLock) override;
 
   virtual void
   DirectoryLockFailed() override;
 
+  // IPDL methods.
+  bool
+  Recv__delete__(const JS::AsmJSCacheResult& aResult) override
+  {
+    AssertIsOnOwningThread();
+    MOZ_ASSERT(mState != eFinished);
+
+    if (mOpened) {
+      Close();
+    } else {
+      Fail();
+    }
+
+    MOZ_ASSERT(mState == eFinished);
+
+    return true;
+  }
+
+  void
+  ActorDestroy(ActorDestroyReason why) override
+  {
+    AssertIsOnOwningThread();
+    MOZ_ASSERT(!mActorDestroyed);
+
+    mActorDestroyed = true;
+
+    // Assume ActorDestroy can happen at any time, so probe the current state to
+    // determine what needs to happen.
+
+    if (mState == eFinished) {
+      return;
+    }
+
+    if (mOpened) {
+      Close();
+    } else {
+      Fail();
+    }
+
+    MOZ_ASSERT(mState == eFinished);
+  }
+
+  bool
+  RecvSelectCacheFileToRead(const uint32_t& aModuleIndex) override
+  {
+    AssertIsOnOwningThread();
+    MOZ_ASSERT(mState == eWaitingToOpenCacheFileForRead);
+    MOZ_ASSERT(mOpenMode == eOpenForRead);
+
+    // A cache entry has been selected to open.
+
+    mModuleIndex = aModuleIndex;
+    mState = eDispatchToMainThread;
+    NS_DispatchToMainThread(this);
+
+    return true;
+  }
+
+  bool
+  RecvCacheMiss() override
+  {
+    AssertIsOnOwningThread();
+
+    CacheMiss();
+
+    return true;
+  }
+
   nsCOMPtr<nsIEventTarget> mOwningThread;
   const PrincipalInfo mPrincipalInfo;
   const OpenMode mOpenMode;
   const WriteParams mWriteParams;
 
   // State initialized during eInitial:
   quota::PersistenceType mPersistence;
   nsCString mGroup;
@@ -710,29 +783,30 @@ private:
     eReadyToReadMetadata, // Waiting to read the metadata file on the IO thread
     eFailedToReadMetadata, // Waiting to be dispatched to owning thread after fail
     eSendingMetadataForRead, // Waiting to send OnOpenMetadataForRead
     eWaitingToOpenCacheFileForRead, // Waiting to hear back from child
     eDispatchToMainThread, // IO thread dispatch allowed from main thread only
     eReadyToOpenCacheFileForRead, // Waiting to open cache file for read
     eSendingCacheFile, // Waiting to send OnOpenCacheFile on the owning thread
     eOpened, // Finished calling OnOpenCacheFile, waiting to be closed
-    eClosing, // Waiting to be dispatched to owning thread again
     eFailing, // Just failed, waiting to be dispatched to the owning thread
     eFinished, // Terminal state
   };
   State mState;
   JS::AsmJSCacheResult mResult;
 
   bool mIsApp;
   bool mEnforcingQuota;
+  bool mActorDestroyed;
+  bool mOpened;
 };
 
 void
-MainProcessRunnable::InitPersistenceType()
+ParentRunnable::InitPersistenceType()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mState == eInitial);
 
   if (mOpenMode == eOpenForWrite) {
     MOZ_ASSERT(mPersistence == quota::PERSISTENCE_TYPE_INVALID);
 
     // If we are performing install-time caching of an app, we'd like to store
@@ -768,17 +842,17 @@ MainProcessRunnable::InitPersistenceType
   if (mPersistence == quota::PERSISTENCE_TYPE_INVALID && mIsApp) {
     mPersistence = quota::PERSISTENCE_TYPE_PERSISTENT;
   } else {
     mPersistence = quota::PERSISTENCE_TYPE_TEMPORARY;
   }
 }
 
 nsresult
-MainProcessRunnable::InitOnMainThread()
+ParentRunnable::InitOnMainThread()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mState == eInitial);
   MOZ_ASSERT(mPrincipalInfo.type() != PrincipalInfo::TNullPrincipalInfo);
 
   nsresult rv;
   nsCOMPtr<nsIPrincipal> principal =
     PrincipalInfoToPrincipal(mPrincipalInfo, &rv);
@@ -797,17 +871,17 @@ MainProcessRunnable::InitOnMainThread()
 
   mEnforcingQuota =
     QuotaManager::IsQuotaEnforced(mPersistence, mOrigin, mIsApp);
 
   return NS_OK;
 }
 
 nsresult
-MainProcessRunnable::ReadMetadata()
+ParentRunnable::ReadMetadata()
 {
   AssertIsOnIOThread();
   MOZ_ASSERT(mState == eReadyToReadMetadata);
 
   QuotaManager* qm = QuotaManager::Get();
   MOZ_ASSERT(qm, "We are on the QuotaManager's IO thread");
 
   nsresult rv =
@@ -860,17 +934,17 @@ MainProcessRunnable::ReadMetadata()
       entry.clear();
     }
   }
 
   return NS_OK;
 }
 
 nsresult
-MainProcessRunnable::OpenCacheFileForWrite()
+ParentRunnable::OpenCacheFileForWrite()
 {
   AssertIsOnIOThread();
   MOZ_ASSERT(mState == eReadyToReadMetadata);
   MOZ_ASSERT(mOpenMode == eOpenForWrite);
 
   mFileSize = mWriteParams.mSize;
 
   // Kick out the oldest entry in the LRU queue in the metadata.
@@ -919,17 +993,17 @@ MainProcessRunnable::OpenCacheFileForWri
 
   rv = WriteMetadataFile(mMetadataFile, mMetadata);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
-MainProcessRunnable::OpenCacheFileForRead()
+ParentRunnable::OpenCacheFileForRead()
 {
   AssertIsOnIOThread();
   MOZ_ASSERT(mState == eReadyToOpenCacheFileForRead);
   MOZ_ASSERT(mOpenMode == eOpenForRead);
 
   nsCOMPtr<nsIFile> file;
   nsresult rv = GetCacheFile(mDirectory, mModuleIndex, getter_AddRefs(file));
   NS_ENSURE_SUCCESS(rv, rv);
@@ -965,46 +1039,46 @@ MainProcessRunnable::OpenCacheFileForRea
 
   rv = WriteMetadataFile(mMetadataFile, mMetadata);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 void
-MainProcessRunnable::FinishOnOwningThread()
+ParentRunnable::FinishOnOwningThread()
 {
   AssertIsOnOwningThread();
 
   // Per FileDescriptorHolder::Finish()'s comment, call before
   // releasing the directory lock.
   FileDescriptorHolder::Finish();
 
   if (mDirectoryLock) {
     nsRefPtr<UnlockDirectoryRunnable> runnable =
       new UnlockDirectoryRunnable(mDirectoryLock.forget());
 
     NS_DispatchToMainThread(runnable);
   }
 }
 
 NS_IMETHODIMP
-MainProcessRunnable::Run()
+ParentRunnable::Run()
 {
   nsresult rv;
 
   // All success/failure paths must eventually call Finish() to avoid leaving
   // the parser hanging.
   switch (mState) {
     case eInitial: {
       MOZ_ASSERT(NS_IsMainThread());
 
       rv = InitOnMainThread();
       if (NS_FAILED(rv)) {
-        Fail();
+        FailOnNonOwningThread();
         return NS_OK;
       }
 
       mState = eWaitingToOpenMetadata;
 
       // XXX The exclusive lock shouldn't be needed for read operations.
       QuotaManager::Get()->OpenDirectory(mPersistence,
                                          mGroup,
@@ -1033,17 +1107,17 @@ MainProcessRunnable::Run()
         MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
           mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL)));
 
         return NS_OK;
       }
 
       rv = OpenCacheFileForWrite();
       if (NS_FAILED(rv)) {
-        Fail();
+        FailOnNonOwningThread();
         return NS_OK;
       }
 
       mState = eSendingCacheFile;
       MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
         mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL)));
       return NS_OK;
     }
@@ -1060,17 +1134,22 @@ MainProcessRunnable::Run()
       return NS_OK;
     }
 
     case eSendingMetadataForRead: {
       AssertIsOnOwningThread();
       MOZ_ASSERT(mOpenMode == eOpenForRead);
 
       mState = eWaitingToOpenCacheFileForRead;
-      OnOpenMetadataForRead(mMetadata);
+
+      // Metadata is now open.
+      if (!SendOnOpenMetadataForRead(mMetadata)) {
+        unused << Send__delete__(this, JS::AsmJSCache_InternalError);
+      }
+
       return NS_OK;
     }
 
     case eDispatchToMainThread: {
       MOZ_ASSERT(NS_IsMainThread());
 
       mState = eReadyToOpenCacheFileForRead;
       DispatchToIOThread();
@@ -1078,85 +1157,89 @@ MainProcessRunnable::Run()
     }
 
     case eReadyToOpenCacheFileForRead: {
       AssertIsOnIOThread();
       MOZ_ASSERT(mOpenMode == eOpenForRead);
 
       rv = OpenCacheFileForRead();
       if (NS_FAILED(rv)) {
-        Fail();
+        FailOnNonOwningThread();
         return NS_OK;
       }
 
       mState = eSendingCacheFile;
       MOZ_ALWAYS_TRUE(NS_SUCCEEDED(
         mOwningThread->Dispatch(this, NS_DISPATCH_NORMAL)));
       return NS_OK;
     }
 
     case eSendingCacheFile: {
       AssertIsOnOwningThread();
 
       mState = eOpened;
-      OnOpenCacheFile();
+
+      // The entry is now open.
+      MOZ_ASSERT(!mOpened);
+      mOpened = true;
+
+      FileDescriptor::PlatformHandleType handle =
+        FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(mFileDesc));
+      if (!SendOnOpenCacheFile(mFileSize, FileDescriptor(handle))) {
+        unused << Send__delete__(this, JS::AsmJSCache_InternalError);
+      }
+
       return NS_OK;
     }
 
     case eFailing: {
       AssertIsOnOwningThread();
 
-      mState = eFinished;
-      OnFailure(mResult);
-      return NS_OK;
-    }
+      Fail();
 
-    case eClosing: {
-      AssertIsOnOwningThread();
-
-      mState = eFinished;
-      OnClose();
       return NS_OK;
     }
 
     case eWaitingToOpenMetadata:
     case eWaitingToOpenCacheFileForRead:
     case eOpened:
     case eFinished: {
       MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Shouldn't Run() in this state");
     }
   }
 
   MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Corrupt state");
   return NS_OK;
 }
 
 void
-MainProcessRunnable::DirectoryLockAcquired(DirectoryLock* aLock)
+ParentRunnable::DirectoryLockAcquired(DirectoryLock* aLock)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mState == eWaitingToOpenMetadata);
   MOZ_ASSERT(!mDirectoryLock);
 
   mDirectoryLock = aLock;
 
   mState = eReadyToReadMetadata;
   DispatchToIOThread();
 }
 
 void
-MainProcessRunnable::DirectoryLockFailed()
+ParentRunnable::DirectoryLockFailed()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mState == eWaitingToOpenMetadata);
   MOZ_ASSERT(!mDirectoryLock);
 
-  Fail();
+  FailOnNonOwningThread();
 }
 
+NS_IMPL_ISUPPORTS_INHERITED0(ParentRunnable, FileDescriptorHolder)
+
 bool
 FindHashMatch(const Metadata& aMetadata, const ReadParams& aReadParams,
               unsigned* aModuleIndex)
 {
   // Perform a fast hash of the first sNumFastHashChars chars. Each cache entry
   // also stores an mFastHash of its first sNumFastHashChars so this gives us a
   // fast way to probabilistically determine whether we have a cache hit. We
   // still do a full hash of all the chars before returning the cache file to
@@ -1191,223 +1274,83 @@ FindHashMatch(const Metadata& aMetadata,
 
     *aModuleIndex = entry.mModuleIndex;
     return true;
   }
 
   return false;
 }
 
-// A runnable that executes in a parent process for a cache access originating
-// in the content process. This runnable gets registered as an IPDL subprotocol
-// actor so that it can communicate with the corresponding ChildProcessRunnable.
-class ParentProcessRunnable final : public PAsmJSCacheEntryParent,
-                                    public MainProcessRunnable
-{
-public:
-  NS_DECL_ISUPPORTS_INHERITED
-
-  ParentProcessRunnable(const PrincipalInfo& aPrincipalInfo,
-                        OpenMode aOpenMode,
-                        WriteParams aWriteParams)
-  : MainProcessRunnable(aPrincipalInfo, aOpenMode, aWriteParams),
-    mActorDestroyed(false),
-    mOpened(false),
-    mFinished(false)
-  {
-    MOZ_ASSERT(XRE_IsParentProcess());
-    AssertIsOnOwningThread();
-    MOZ_COUNT_CTOR(ParentProcessRunnable);
-  }
-
-private:
-  ~ParentProcessRunnable()
-  {
-    MOZ_ASSERT(mActorDestroyed);
-    MOZ_ASSERT(mFinished);
-    MOZ_COUNT_DTOR(ParentProcessRunnable);
-  }
-
-  bool
-  Recv__delete__(const JS::AsmJSCacheResult& aResult) override
-  {
-    MOZ_ASSERT(!mFinished);
-    mFinished = true;
-
-    if (mOpened) {
-      MainProcessRunnable::Close();
-    } else {
-      MainProcessRunnable::Fail();
-    }
-
-    return true;
-  }
-
-  void
-  ActorDestroy(ActorDestroyReason why) override
-  {
-    MOZ_ASSERT(!mActorDestroyed);
-    mActorDestroyed = true;
-
-    // Assume ActorDestroy can happen at any time, so probe the current state to
-    // determine what needs to happen.
-
-    if (mFinished) {
-      return;
-    }
-
-    mFinished = true;
-
-    if (mOpened) {
-      MainProcessRunnable::Close();
-    } else {
-      MainProcessRunnable::Fail();
-    }
-  }
-
-  void
-  OnOpenMetadataForRead(const Metadata& aMetadata) override
-  {
-    AssertIsOnOwningThread();
-
-    if (!SendOnOpenMetadataForRead(aMetadata)) {
-      unused << Send__delete__(this, JS::AsmJSCache_InternalError);
-    }
-  }
-
-  bool
-  RecvSelectCacheFileToRead(const uint32_t& aModuleIndex) override
-  {
-    MainProcessRunnable::OpenForRead(aModuleIndex);
-    return true;
-  }
-
-  bool
-  RecvCacheMiss() override
-  {
-    MainProcessRunnable::CacheMiss();
-    return true;
-  }
-
-  void
-  OnOpenCacheFile() override
-  {
-    AssertIsOnOwningThread();
-
-    MOZ_ASSERT(!mOpened);
-    mOpened = true;
-
-    FileDescriptor::PlatformHandleType handle =
-      FileDescriptor::PlatformHandleType(PR_FileDesc2NativeHandle(mFileDesc));
-    if (!SendOnOpenCacheFile(mFileSize, FileDescriptor(handle))) {
-      unused << Send__delete__(this, JS::AsmJSCache_InternalError);
-    }
-  }
-
-  void
-  OnClose() override final
-  {
-    AssertIsOnOwningThread();
-    MOZ_ASSERT(mOpened);
-
-    mFinished = true;
-
-    MainProcessRunnable::OnClose();
-
-    MOZ_ASSERT(mActorDestroyed);
-  }
-
-  void
-  OnFailure(JS::AsmJSCacheResult aResult) override
-  {
-    AssertIsOnOwningThread();
-    MOZ_ASSERT(!mOpened);
-
-    mFinished = true;
-
-    MainProcessRunnable::OnFailure(aResult);
-
-    if (!mActorDestroyed) {
-      unused << Send__delete__(this, aResult);
-    }
-  }
-
-  bool mActorDestroyed;
-  bool mOpened;
-  bool mFinished;
-};
-
-NS_IMPL_ISUPPORTS_INHERITED0(ParentProcessRunnable, FileDescriptorHolder)
-
 } // unnamed namespace
 
 PAsmJSCacheEntryParent*
 AllocEntryParent(OpenMode aOpenMode,
                  WriteParams aWriteParams,
                  const PrincipalInfo& aPrincipalInfo)
 {
   AssertIsOnBackgroundThread();
 
   if (NS_WARN_IF(aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo)) {
     MOZ_ASSERT(false);
     return nullptr;
   }
 
-  nsRefPtr<ParentProcessRunnable> runnable =
-    new ParentProcessRunnable(aPrincipalInfo, aOpenMode, aWriteParams);
+  nsRefPtr<ParentRunnable> runnable =
+    new ParentRunnable(aPrincipalInfo, aOpenMode, aWriteParams);
 
   nsresult rv = NS_DispatchToMainThread(runnable);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
   // Transfer ownership to IPDL.
   return runnable.forget().take();
 }
 
 void
 DeallocEntryParent(PAsmJSCacheEntryParent* aActor)
 {
   // Transfer ownership back from IPDL.
-  nsRefPtr<ParentProcessRunnable> op =
-    dont_AddRef(static_cast<ParentProcessRunnable*>(aActor));
+  nsRefPtr<ParentRunnable> op =
+    dont_AddRef(static_cast<ParentRunnable*>(aActor));
 }
 
 namespace {
 
-class ChildProcessRunnable final : public File,
-                                   public PAsmJSCacheEntryChild,
-                                   public nsIIPCBackgroundChildCreateCallback
+class ChildRunnable final
+  : public File
+  , public PAsmJSCacheEntryChild
+  , public nsIIPCBackgroundChildCreateCallback
 {
   typedef mozilla::ipc::PBackgroundChild PBackgroundChild;
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIRUNNABLE
   NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
 
-  ChildProcessRunnable(nsIPrincipal* aPrincipal,
-                       OpenMode aOpenMode,
-                       WriteParams aWriteParams,
-                       ReadParams aReadParams)
+  ChildRunnable(nsIPrincipal* aPrincipal,
+                OpenMode aOpenMode,
+                WriteParams aWriteParams,
+                ReadParams aReadParams)
   : mPrincipal(aPrincipal),
     mOpenMode(aOpenMode),
     mWriteParams(aWriteParams),
     mReadParams(aReadParams),
     mActorDestroyed(false),
     mState(eInitial)
   {
     MOZ_ASSERT(!NS_IsMainThread());
-    MOZ_COUNT_CTOR(ChildProcessRunnable);
+    MOZ_COUNT_CTOR(ChildRunnable);
   }
 
 protected:
-  ~ChildProcessRunnable()
+  ~ChildRunnable()
   {
     MOZ_ASSERT(mState == eFinished);
     MOZ_ASSERT(mActorDestroyed);
-    MOZ_COUNT_DTOR(ChildProcessRunnable);
+    MOZ_COUNT_DTOR(ChildRunnable);
   }
 
 private:
   bool
   RecvOnOpenMetadataForRead(const Metadata& aMetadata) override
   {
     MOZ_ASSERT(NS_IsMainThread());
     MOZ_ASSERT(mState == eOpening);
@@ -1490,17 +1433,17 @@ private:
     eOpened, // Parent process opened the entry and sent it back
     eClosing, // Waiting to be dispatched to the main thread to Send__delete__
     eFinished // Terminal state
   };
   State mState;
 };
 
 NS_IMETHODIMP
-ChildProcessRunnable::Run()
+ChildRunnable::Run()
 {
   switch (mState) {
     case eInitial: {
       MOZ_ASSERT(NS_IsMainThread());
 
       bool nullPrincipal;
       nsresult rv = mPrincipal->GetIsNullPrincipal(&nullPrincipal);
       if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -1562,17 +1505,17 @@ ChildProcessRunnable::Run()
     }
   }
 
   MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("Corrupt state");
   return NS_OK;
 }
 
 void
-ChildProcessRunnable::ActorCreated(PBackgroundChild* aActor)
+ChildRunnable::ActorCreated(PBackgroundChild* aActor)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (!aActor->SendPAsmJSCacheEntryConstructor(this, mOpenMode, mWriteParams,
                                                *mPrincipalInfo)) {
     // Unblock the parsing thread with a failure.
 
     Fail(JS::AsmJSCache_InternalError);
@@ -1583,35 +1526,35 @@ ChildProcessRunnable::ActorCreated(PBack
   // AddRef to keep this runnable alive until IPDL deallocates the
   // subprotocol (DeallocEntryChild).
   AddRef();
 
   mState = eOpening;
 }
 
 void
-ChildProcessRunnable::ActorFailed()
+ChildRunnable::ActorFailed()
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(mState == eBackgroundChildPending);
 
   Fail(JS::AsmJSCache_InternalError);
 }
 
-NS_IMPL_ISUPPORTS_INHERITED(ChildProcessRunnable,
+NS_IMPL_ISUPPORTS_INHERITED(ChildRunnable,
                             FileDescriptorHolder,
                             nsIIPCBackgroundChildCreateCallback)
 
 } // unnamed namespace
 
 void
 DeallocEntryChild(PAsmJSCacheEntryChild* aActor)
 {
   // Match the AddRef before SendPAsmJSCacheEntryConstructor.
-  static_cast<ChildProcessRunnable*>(aActor)->Release();
+  static_cast<ChildRunnable*>(aActor)->Release();
 }
 
 namespace {
 
 JS::AsmJSCacheResult
 OpenFile(nsIPrincipal* aPrincipal,
          OpenMode aOpenMode,
          WriteParams aWriteParams,
@@ -1632,21 +1575,21 @@ OpenFile(nsIPrincipal* aPrincipal,
   //     occasional janks on the main thread.
   // We could use a nested event loop to address 1 and 2, but we're potentially
   // in the middle of running JS (eval()) and nested event loops can be
   // semantically observable.
   if (NS_IsMainThread()) {
     return JS::AsmJSCache_SynchronousScript;
   }
 
-  // If we are in a child process, we need to synchronously call into the
-  // parent process to open the file and interact with the QuotaManager. The
-  // child can then map the file into its address space to perform I/O.
+  // We need to synchronously call into the parent to open the file and
+  // interact with the QuotaManager. The child can then map the file into its
+  // address space to perform I/O.
   nsRefPtr<File> file =
-    new ChildProcessRunnable(aPrincipal, aOpenMode, aWriteParams, aReadParams);
+    new ChildRunnable(aPrincipal, aOpenMode, aWriteParams, aReadParams);
 
   JS::AsmJSCacheResult openResult = file->BlockUntilOpen(aFile);
   if (openResult != JS::AsmJSCache_Success) {
     return openResult;
   }
 
   if (!file->MapMemory(aOpenMode)) {
     return JS::AsmJSCache_InternalError;