Bug 1366975 - MediaCacheStatusImpl. draft
authorbechen <bechen@mozilla.com>
Tue, 13 Jun 2017 18:36:04 +0800
changeset 593223 a8235bd9cda7c9cba50eec19167220b9466d594c
parent 593222 6310d46acc9291cf6b3235216cd318e60e48f589
child 593224 7479b5db416a7f9d638c30a8a0a8b27aa5aa6b3d
child 593227 8ffe2cd238115bff718f86a6c889853665048301
push id63641
push userbechen@mozilla.com
push dateTue, 13 Jun 2017 10:43:09 +0000
bugs1366975
milestone55.0a1
Bug 1366975 - MediaCacheStatusImpl. MozReview-Commit-ID: Acj32qwN7gW
dom/media/MediaCacheStatus.cpp
dom/media/MediaCacheStatus.h
dom/media/moz.build
modules/libpref/init/all.js
new file mode 100644
--- /dev/null
+++ b/dom/media/MediaCacheStatus.cpp
@@ -0,0 +1,52 @@
+/* -*- 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 "MediaCacheStatus.h"
+
+#include "mozilla/dom/HTMLMediaElement.h"
+#include "mozilla/dom/MediaCacheStatusBinding.h"
+#include "nsCycleCollectionParticipant.h"
+#include "nsWrapperCache.h"
+
+namespace mozilla {
+namespace dom {
+
+MediaCacheStatus::MediaCacheStatus(HTMLMediaElement* aElement,
+                                   uint32_t aBlockSize,
+                                   uint32_t aTotalBlocks,
+                                   uint32_t mOccupiedBlocks)
+  : mElement(aElement)
+  , mBlockSize(aBlockSize)
+  , mTotalBlocks(aTotalBlocks)
+  , mOccupiedBlocks(aOccupiedBlocks)
+{
+}
+
+HTMLMediaElement*
+MediaCacheStatus::GetParentObject() const
+{
+  return mElement;
+}
+
+JSObject*
+MediaCacheStatus::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
+{
+  return MediaCacheStatusBinding::Wrap(aCx, this, aGivenProto);
+}
+
+/* static */ bool
+MediaCacheStatus::Enabled(JSContext* cx, JSObject* aGlobal)
+{
+  return Preferences::GetBool("media.mediaCacheStatus.enabled");
+}
+
+NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(MediaCacheStatus, AddRef)
+NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(MediaCacheStatus, Release)
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(MediaCacheStatus, mElement)
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/MediaCacheStatus.h
@@ -0,0 +1,61 @@
+/* -*- 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_dom_MediaCacheStatus_h_
+#define mozilla_dom_MediaCacheStatus_h_
+
+#include "mozilla/dom/HTMLMediaElement.h"
+#include "nsCycleCollectionParticipant.h"
+#include "nsWrapperCache.h"
+
+namespace mozilla {
+namespace dom {
+
+class MediaCacheStatus final : public nsWrapperCache
+{
+public:
+  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(MediaCacheStatus)
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(MediaCacheStatus)
+
+  MediaCacheStatus(HTMLMediaElement* aElement,
+                   uint32_t aBlockSize,
+                   uint32_t aTotalBlocks,
+                   uint32_t mOccupiedBlocks);
+
+  HTMLMediaElement* GetParentObject() const;
+
+  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
+
+  uint32_t BlockSize() const
+  {
+    return mBlockSize;
+  }
+
+  uint32_t TotalBlocks() const
+  {
+    return mTotalBlocks;
+  }
+
+  uint32_t OccupiedBlocks() const
+  {
+    return mOccupiedBlocks;
+  }
+
+  static bool Enabled(JSContext* cx, JSObject* aGlobal);
+
+private:
+  ~MediaCacheStatus() {}
+
+  RefPtr<HTMLMediaElement> mElement;
+  uint32_t mBlockSize;
+  uint32_t mTotalBlocks;
+  uint32_t mOccupiedBlocks;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif // mozilla_dom_MediaCacheStatus_h_
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -172,16 +172,17 @@ IPDL_SOURCES += [
 ]
 
 EXPORTS.mozilla.dom += [
     'AudioStreamTrack.h',
     'AudioTrack.h',
     'AudioTrackList.h',
     'CanvasCaptureMediaStream.h',
     'GetUserMediaRequest.h',
+    'MediaCacheStatus.h',
     'MediaDeviceInfo.h',
     'MediaDevices.h',
     'MediaStreamError.h',
     'MediaStreamTrack.h',
     'TextTrack.h',
     'TextTrackCue.h',
     'TextTrackCueList.h',
     'TextTrackList.h',
@@ -210,16 +211,17 @@ UNIFIED_SOURCES += [
     'DecoderDoctorDiagnostics.cpp',
     'DOMMediaStream.cpp',
     'EncodedBufferCache.cpp',
     'FileBlockCache.cpp',
     'GetUserMediaRequest.cpp',
     'GraphDriver.cpp',
     'Latency.cpp',
     'MediaCache.cpp',
+    'MediaCacheStatus.cpp',
     'MediaContainerType.cpp',
     'MediaData.cpp',
     'MediaDecoder.cpp',
     'MediaDecoderReader.cpp',
     'MediaDecoderReaderWrapper.cpp',
     'MediaDecoderStateMachine.cpp',
     'MediaDeviceInfo.cpp',
     'MediaDevices.cpp',
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5621,16 +5621,22 @@ pref("media.default_volume", "1.0");
 // Once bug 1276272 is resolved, we will trun this preference to default ON in
 // non-release channels.
 #ifdef RELEASE_OR_BETA
 pref("media.seekToNextFrame.enabled", false);
 #else
 pref("media.seekToNextFrame.enabled", true);
 #endif
 
+#ifdef RELEASE_OR_BETA
+pref("media.mediaCacheStatus.enabled", false);
+#else
+pref("media.mediaCacheStatus.enabled", true);
+#endif
+
 // return the maximum number of cores that navigator.hardwareCurrency returns
 pref("dom.maxHardwareConcurrency", 16);
 
 // Shutdown the osfile worker if its no longer needed.
 #if !defined(RELEASE_OR_BETA)
 pref("osfile.reset_worker_delay", 30000);
 #endif