Bug 1268213 - BlobImplFile::GetTypeRunnable can be a WorkerMainThreadRunnable, r=khuey
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 03 May 2016 09:09:47 +0200
changeset 320289 1da0860325328fa27135f3d849be916d481c306d
parent 320288 08f3c7a9f5a8204488c263a24e582012bc5a8da1
child 320290 914eba686417f7a2d82098c8e3026902671298f4
push id9671
push userraliiev@mozilla.com
push dateMon, 06 Jun 2016 20:27:52 +0000
treeherdermozilla-aurora@cea65ca3d0bd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs1268213
milestone49.0a1
Bug 1268213 - BlobImplFile::GetTypeRunnable can be a WorkerMainThreadRunnable, r=khuey
dom/base/File.cpp
--- a/dom/base/File.cpp
+++ b/dom/base/File.cpp
@@ -861,53 +861,43 @@ BlobImplFile::GetSize(ErrorResult& aRv)
     mLength = fileSize;
   }
 
   return mLength;
 }
 
 namespace {
 
-class GetTypeRunnable final : public Runnable
+class GetTypeRunnable final : public WorkerMainThreadRunnable
 {
 public:
   GetTypeRunnable(WorkerPrivate* aWorkerPrivate,
-                  nsIEventTarget* aSyncLoopTarget,
                   BlobImpl* aBlobImpl)
-    : mWorkerPrivate(aWorkerPrivate)
-    , mSyncLoopTarget(aSyncLoopTarget)
+    : WorkerMainThreadRunnable(aWorkerPrivate,
+                               NS_LITERAL_CSTRING("BlobImplFile :: GetType"))
     , mBlobImpl(aBlobImpl)
   {
-    MOZ_ASSERT(aWorkerPrivate);
-    MOZ_ASSERT(aSyncLoopTarget);
     MOZ_ASSERT(aBlobImpl);
     aWorkerPrivate->AssertIsOnWorkerThread();
   }
 
-  NS_IMETHOD
-  Run() override
+  bool
+  MainThreadRun() override
   {
     MOZ_ASSERT(NS_IsMainThread());
 
     nsAutoString type;
     mBlobImpl->GetType(type);
-
-    RefPtr<MainThreadStopSyncLoopRunnable> runnable =
-      new MainThreadStopSyncLoopRunnable(mWorkerPrivate,
-                                         mSyncLoopTarget.forget(), true);
-    NS_WARN_IF(!runnable->Dispatch());
-    return NS_OK;
+    return true;
   }
 
 private:
   ~GetTypeRunnable()
   {}
 
-  WorkerPrivate* mWorkerPrivate;
-  nsCOMPtr<nsIEventTarget> mSyncLoopTarget;
   RefPtr<BlobImpl> mBlobImpl;
 };
 
 } // anonymous namespace
 
 void
 BlobImplFile::GetType(nsAString& aType)
 {
@@ -920,24 +910,22 @@ BlobImplFile::GetType(nsAString& aType)
     if (!NS_IsMainThread()) {
       WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
       if (!workerPrivate) {
         // I have no idea in which thread this method is called. We cannot
         // return any valid value.
         return;
       }
 
-      AutoSyncLoopHolder syncLoop(workerPrivate);
+      RefPtr<GetTypeRunnable> runnable =
+        new GetTypeRunnable(workerPrivate, this);
 
-      RefPtr<GetTypeRunnable> runnable =
-        new GetTypeRunnable(workerPrivate, syncLoop.EventTarget(), this);
-      nsresult rv = NS_DispatchToMainThread(runnable);
-      NS_WARN_IF(NS_FAILED(rv));
-
-      NS_WARN_IF(!syncLoop.Run());
+      ErrorResult rv;
+      runnable->Dispatch(rv);
+      NS_WARN_IF(rv.Failed());
       return;
     }
 
     nsresult rv;
     nsCOMPtr<nsIMIMEService> mimeService =
       do_GetService(NS_MIMESERVICE_CONTRACTID, &rv);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return;