Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/toolkit/components/telemetry/other/WebrtcTelemetry.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
8
#include "mozilla/Telemetry.h"
9
#include "WebrtcTelemetry.h"
10
#include "jsapi.h"
11
#include "nsPrintfCString.h"
12
#include "nsTHashtable.h"
13
14
void
15
WebrtcTelemetry::RecordIceCandidateMask(const uint32_t iceCandidateBitmask,
16
                                        const bool success)
17
0
{
18
0
  WebrtcIceCandidateType *entry = mWebrtcIceCandidates.GetEntry(iceCandidateBitmask);
19
0
  if (!entry) {
20
0
    entry = mWebrtcIceCandidates.PutEntry(iceCandidateBitmask);
21
0
    if (MOZ_UNLIKELY(!entry))
22
0
      return;
23
0
  }
24
0
25
0
  if (success) {
26
0
    entry->mData.webrtc.successCount++;
27
0
  } else {
28
0
    entry->mData.webrtc.failureCount++;
29
0
  }
30
0
}
31
32
bool
33
ReflectIceEntry(const WebrtcTelemetry::WebrtcIceCandidateType *entry,
34
                const WebrtcTelemetry::WebrtcIceCandidateStats *stat, JSContext *cx,
35
                JS::Handle<JSObject*> obj)
36
0
{
37
0
  if ((stat->successCount == 0) && (stat->failureCount == 0))
38
0
    return true;
39
0
40
0
  const uint32_t &bitmask = entry->GetKey();
41
0
42
0
  JS::Rooted<JSObject*> statsObj(cx, JS_NewPlainObject(cx));
43
0
  if (!statsObj)
44
0
    return false;
45
0
  if (!JS_DefineProperty(cx, obj,
46
0
                         nsPrintfCString("%" PRIu32, bitmask).BeginReading(),
47
0
                         statsObj, JSPROP_ENUMERATE)) {
48
0
    return false;
49
0
  }
50
0
  if (stat->successCount && !JS_DefineProperty(cx, statsObj, "successCount",
51
0
                                               stat->successCount,
52
0
                                               JSPROP_ENUMERATE)) {
53
0
    return false;
54
0
  }
55
0
  if (stat->failureCount && !JS_DefineProperty(cx, statsObj, "failureCount",
56
0
                                               stat->failureCount,
57
0
                                               JSPROP_ENUMERATE)) {
58
0
    return false;
59
0
  }
60
0
  return true;
61
0
}
62
63
bool
64
ReflectIceWebrtc(WebrtcTelemetry::WebrtcIceCandidateType *entry, JSContext *cx,
65
                 JS::Handle<JSObject*> obj)
66
0
{
67
0
  return ReflectIceEntry(entry, &entry->mData.webrtc, cx, obj);
68
0
}
69
70
bool
71
WebrtcTelemetry::AddIceInfo(JSContext *cx, JS::Handle<JSObject*> iceObj)
72
0
{
73
0
  JS::Rooted<JSObject*> statsObj(cx, JS_NewPlainObject(cx));
74
0
  if (!statsObj)
75
0
    return false;
76
0
77
0
  if (!mWebrtcIceCandidates.ReflectIntoJS(ReflectIceWebrtc, cx, statsObj)) {
78
0
    return false;
79
0
  }
80
0
81
0
  return JS_DefineProperty(cx, iceObj, "webrtc",
82
0
                           statsObj, JSPROP_ENUMERATE);
83
0
}
84
85
bool
86
WebrtcTelemetry::GetWebrtcStats(JSContext *cx, JS::MutableHandle<JS::Value> ret)
87
0
{
88
0
  JS::Rooted<JSObject*> root_obj(cx, JS_NewPlainObject(cx));
89
0
  if (!root_obj)
90
0
    return false;
91
0
  ret.setObject(*root_obj);
92
0
93
0
  JS::Rooted<JSObject*> ice_obj(cx, JS_NewPlainObject(cx));
94
0
  if (!ice_obj)
95
0
    return false;
96
0
  JS_DefineProperty(cx, root_obj, "IceCandidatesStats", ice_obj,
97
0
                    JSPROP_ENUMERATE);
98
0
99
0
  if (!AddIceInfo(cx, ice_obj))
100
0
    return false;
101
0
102
0
  return true;
103
0
}
104
105
size_t
106
WebrtcTelemetry::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
107
0
{
108
0
  return mWebrtcIceCandidates.ShallowSizeOfExcludingThis(aMallocSizeOf);
109
0
}