1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/renderer/media/webrtc_uma_histograms.h"
6
7#include "base/metrics/histogram.h"
8
9namespace content {
10
11void LogUserMediaRequestWithNoResult(MediaStreamRequestState state) {
12  UMA_HISTOGRAM_ENUMERATION("WebRTC.UserMediaRequest.NoResultState",
13                            state,
14                            NUM_MEDIA_STREAM_REQUEST_WITH_NO_RESULT);
15}
16
17void LogUserMediaRequestResult(MediaStreamRequestResult result) {
18  UMA_HISTOGRAM_ENUMERATION(
19      "WebRTC.UserMediaRequest.Result", result, NUM_MEDIA_REQUEST_RESULTS);
20}
21
22void UpdateWebRTCMethodCount(JavaScriptAPIName api_name) {
23  DVLOG(3) << "Incrementing WebRTC.webkitApiCount for " << api_name;
24  UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCount", api_name, INVALID_NAME);
25  PerSessionWebRTCAPIMetrics::GetInstance()->LogUsageOnlyOnce(api_name);
26}
27
28PerSessionWebRTCAPIMetrics::~PerSessionWebRTCAPIMetrics() {
29}
30
31// static
32PerSessionWebRTCAPIMetrics* PerSessionWebRTCAPIMetrics::GetInstance() {
33  return Singleton<PerSessionWebRTCAPIMetrics>::get();
34}
35
36void PerSessionWebRTCAPIMetrics::IncrementStreamCounter() {
37  DCHECK(CalledOnValidThread());
38  ++num_streams_;
39}
40
41void PerSessionWebRTCAPIMetrics::DecrementStreamCounter() {
42  DCHECK(CalledOnValidThread());
43  if (--num_streams_ == 0) {
44    ResetUsage();
45  }
46}
47
48PerSessionWebRTCAPIMetrics::PerSessionWebRTCAPIMetrics() : num_streams_(0) {
49  ResetUsage();
50}
51
52void PerSessionWebRTCAPIMetrics::LogUsage(JavaScriptAPIName api_name) {
53  DVLOG(3) << "Incrementing WebRTC.webkitApiCountPerSession for " << api_name;
54  UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCountPerSession",
55                            api_name, INVALID_NAME);
56}
57
58void PerSessionWebRTCAPIMetrics::LogUsageOnlyOnce(JavaScriptAPIName api_name) {
59  DCHECK(CalledOnValidThread());
60  if (!has_used_api_[api_name]) {
61    has_used_api_[api_name] = true;
62    LogUsage(api_name);
63  }
64}
65
66void PerSessionWebRTCAPIMetrics::ResetUsage() {
67  for (size_t i = 0; i < arraysize(has_used_api_); ++i)
68    has_used_api_[i] = false;
69}
70
71}  // namespace content
72