Bug 1108767 - Stop including MediaTaskQueue.h from MediaPromise.h. r=cpearce
authorBobby Holley <bobbyholley@gmail.com>
Mon, 08 Dec 2014 17:19:05 -0800
changeset 218785 6d526469e5a0dc6b7a09470de58d523e0e86c8b6
parent 218784 8c25427adcac6126ddb63662ae451c0e352312ca
child 218786 85fafca2167441e1efe8e2acd0e1465e120e7380
push id27944
push usercbook@mozilla.com
push dateTue, 09 Dec 2014 11:54:28 +0000
treeherdermozilla-central@acf5660d2048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1108767
milestone37.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 1108767 - Stop including MediaTaskQueue.h from MediaPromise.h. r=cpearce We need this so that MediaTaskQueue can use promises.
dom/media/MediaPromise.cpp
dom/media/MediaPromise.h
dom/media/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/media/MediaPromise.cpp
@@ -0,0 +1,27 @@
+/* -*- 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 "MediaPromise.h"
+#include "MediaTaskQueue.h"
+#include "nsThreadUtils.h"
+
+namespace mozilla {
+namespace detail {
+
+nsresult
+DispatchMediaPromiseRunnable(MediaTaskQueue* aTaskQueue, nsIRunnable* aRunnable)
+{
+  return aTaskQueue->ForceDispatch(aRunnable);
+}
+
+nsresult
+DispatchMediaPromiseRunnable(nsIEventTarget* aEventTarget, nsIRunnable* aRunnable)
+{
+  return aEventTarget->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
+}
+
+}
+} // namespace mozilla
--- a/dom/media/MediaPromise.h
+++ b/dom/media/MediaPromise.h
@@ -4,38 +4,47 @@
  * 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/. */
 
 #if !defined(MediaPromise_h_)
 #define MediaPromise_h_
 
 #include "prlog.h"
 
+#include "nsTArray.h"
+#include "nsThreadUtils.h"
+
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Monitor.h"
 
-#include "MediaTaskQueue.h"
-#include "nsIEventTarget.h"
-
 /* Polyfill __func__ on MSVC for consumers to pass to the MediaPromise API. */
 #ifdef _MSC_VER
 #define __func__ __FUNCTION__
 #endif
 
+class nsIEventTarget;
 namespace mozilla {
 
 extern PRLogModuleInfo* gMediaPromiseLog;
 void EnsureMediaPromiseLog();
 
 #define PROMISE_LOG(x, ...) \
   MOZ_ASSERT(gMediaPromiseLog); \
   PR_LOG(gMediaPromiseLog, PR_LOG_DEBUG, (x, ##__VA_ARGS__))
 
+class MediaTaskQueue;
+namespace detail {
+
+nsresult DispatchMediaPromiseRunnable(MediaTaskQueue* aQueue, nsIRunnable* aRunnable);
+nsresult DispatchMediaPromiseRunnable(nsIEventTarget* aTarget, nsIRunnable* aRunnable);
+
+} // namespace detail
+
 /*
  * A promise manages an asynchronous request that may or may not be able to be
  * fulfilled immediately. When an API returns a promise, the consumer may attach
  * callbacks to be invoked (asynchronously, on a specified thread) when the
  * request is either completed (resolved) or cannot be completed (rejected).
  *
  * By default, resolve and reject callbacks are always invoked on the same thread
  * where Then() was invoked.
@@ -167,41 +176,31 @@ protected:
       MOZ_ASSERT(!aPromise->IsPending());
       bool resolved = aPromise->mResolveValue.isSome();
       nsRefPtr<nsRunnable> runnable =
         resolved ? static_cast<nsRunnable*>(new (typename ThenValueBase::ResolveRunnable)(this, aPromise->mResolveValue.ref()))
                  : static_cast<nsRunnable*>(new (typename ThenValueBase::RejectRunnable)(this, aPromise->mRejectValue.ref()));
       PROMISE_LOG("%s Then() call made from %s [Runnable=%p, Promise=%p, ThenValue=%p]",
                   resolved ? "Resolving" : "Rejecting", ThenValueBase::mCallSite,
                   runnable.get(), aPromise, this);
-      DebugOnly<nsresult> rv = DoDispatch(mResponseTarget, runnable);
+      DebugOnly<nsresult> rv = detail::DispatchMediaPromiseRunnable(mResponseTarget, runnable);
       MOZ_ASSERT(NS_SUCCEEDED(rv));
     }
 
   protected:
     virtual void DoResolve(ResolveValueType aResolveValue)
     {
       ((*mThisVal).*mResolveMethod)(aResolveValue);
     }
 
     virtual void DoReject(RejectValueType aRejectValue)
     {
       ((*mThisVal).*mRejectMethod)(aRejectValue);
     }
 
-    static nsresult DoDispatch(MediaTaskQueue* aTaskQueue, nsIRunnable* aRunnable)
-    {
-      return aTaskQueue->ForceDispatch(aRunnable);
-    }
-
-    static nsresult DoDispatch(nsIEventTarget* aEventTarget, nsIRunnable* aRunnable)
-    {
-      return aEventTarget->Dispatch(aRunnable, NS_DISPATCH_NORMAL);
-    }
-
     virtual ~ThenValue() {}
 
   private:
     nsRefPtr<TargetType> mResponseTarget;
     nsRefPtr<ThisType> mThisVal;
     ResolveMethodType mResolveMethod;
     RejectMethodType mRejectMethod;
   };
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -177,16 +177,17 @@ UNIFIED_SOURCES += [
     'MediaCache.cpp',
     'MediaData.cpp',
     'MediaDecoder.cpp',
     'MediaDecoderReader.cpp',
     'MediaDecoderStateMachine.cpp',
     'MediaDecoderStateMachineScheduler.cpp',
     'MediaDevices.cpp',
     'MediaManager.cpp',
+    'MediaPromise.cpp',
     'MediaRecorder.cpp',
     'MediaResource.cpp',
     'MediaShutdownManager.cpp',
     'MediaStreamError.cpp',
     'MediaStreamGraph.cpp',
     'MediaStreamTrack.cpp',
     'MediaTaskQueue.cpp',
     'MediaTrack.cpp',