Bug 1366975 - MediaCacheStatusImpl.
MozReview-Commit-ID: Acj32qwN7gW
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