summaryrefslogtreecommitdiffstats
path: root/toolkit/components/telemetry/WebrtcTelemetry.cpp
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /toolkit/components/telemetry/WebrtcTelemetry.cpp
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/telemetry/WebrtcTelemetry.cpp')
-rw-r--r--toolkit/components/telemetry/WebrtcTelemetry.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/toolkit/components/telemetry/WebrtcTelemetry.cpp b/toolkit/components/telemetry/WebrtcTelemetry.cpp
new file mode 100644
index 000000000..29c22be23
--- /dev/null
+++ b/toolkit/components/telemetry/WebrtcTelemetry.cpp
@@ -0,0 +1,112 @@
+/* -*- 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 "Telemetry.h"
+#include "TelemetryCommon.h"
+#include "WebrtcTelemetry.h"
+#include "jsapi.h"
+#include "nsPrintfCString.h"
+#include "nsTHashtable.h"
+
+using mozilla::Telemetry::Common::AutoHashtable;
+
+void
+WebrtcTelemetry::RecordIceCandidateMask(const uint32_t iceCandidateBitmask,
+ const bool success)
+{
+ WebrtcIceCandidateType *entry = mWebrtcIceCandidates.GetEntry(iceCandidateBitmask);
+ if (!entry) {
+ entry = mWebrtcIceCandidates.PutEntry(iceCandidateBitmask);
+ if (MOZ_UNLIKELY(!entry))
+ return;
+ }
+
+ if (success) {
+ entry->mData.webrtc.successCount++;
+ } else {
+ entry->mData.webrtc.failureCount++;
+ }
+}
+
+bool
+ReflectIceEntry(const WebrtcTelemetry::WebrtcIceCandidateType *entry,
+ const WebrtcTelemetry::WebrtcIceCandidateStats *stat, JSContext *cx,
+ JS::Handle<JSObject*> obj)
+{
+ if ((stat->successCount == 0) && (stat->failureCount == 0))
+ return true;
+
+ const uint32_t &bitmask = entry->GetKey();
+
+ JS::Rooted<JSObject*> statsObj(cx, JS_NewPlainObject(cx));
+ if (!statsObj)
+ return false;
+ if (!JS_DefineProperty(cx, obj,
+ nsPrintfCString("%lu", bitmask).BeginReading(),
+ statsObj, JSPROP_ENUMERATE)) {
+ return false;
+ }
+ if (stat->successCount && !JS_DefineProperty(cx, statsObj, "successCount",
+ stat->successCount,
+ JSPROP_ENUMERATE)) {
+ return false;
+ }
+ if (stat->failureCount && !JS_DefineProperty(cx, statsObj, "failureCount",
+ stat->failureCount,
+ JSPROP_ENUMERATE)) {
+ return false;
+ }
+ return true;
+}
+
+bool
+ReflectIceWebrtc(WebrtcTelemetry::WebrtcIceCandidateType *entry, JSContext *cx,
+ JS::Handle<JSObject*> obj)
+{
+ return ReflectIceEntry(entry, &entry->mData.webrtc, cx, obj);
+}
+
+bool
+WebrtcTelemetry::AddIceInfo(JSContext *cx, JS::Handle<JSObject*> iceObj)
+{
+ JS::Rooted<JSObject*> statsObj(cx, JS_NewPlainObject(cx));
+ if (!statsObj)
+ return false;
+
+ if (!mWebrtcIceCandidates.ReflectIntoJS(ReflectIceWebrtc, cx, statsObj)) {
+ return false;
+ }
+
+ return JS_DefineProperty(cx, iceObj, "webrtc",
+ statsObj, JSPROP_ENUMERATE);
+}
+
+bool
+WebrtcTelemetry::GetWebrtcStats(JSContext *cx, JS::MutableHandle<JS::Value> ret)
+{
+ JS::Rooted<JSObject*> root_obj(cx, JS_NewPlainObject(cx));
+ if (!root_obj)
+ return false;
+ ret.setObject(*root_obj);
+
+ JS::Rooted<JSObject*> ice_obj(cx, JS_NewPlainObject(cx));
+ if (!ice_obj)
+ return false;
+ JS_DefineProperty(cx, root_obj, "IceCandidatesStats", ice_obj,
+ JSPROP_ENUMERATE);
+
+ if (!AddIceInfo(cx, ice_obj))
+ return false;
+
+ return true;
+}
+
+size_t
+WebrtcTelemetry::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+{
+ return mWebrtcIceCandidates.ShallowSizeOfExcludingThis(aMallocSizeOf);
+}