summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-25 05:38:00 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-25 05:38:00 +0000
commit1214b853e84214f7e908a61272eefebe82b7303d (patch)
tree8951272bbc414d9e5b11c2d27d462468044ae385
parent9f52e70e4449ace53751bbf8988e37be65ad01c2 (diff)
downloadchromium_src-1214b853e84214f7e908a61272eefebe82b7303d.zip
chromium_src-1214b853e84214f7e908a61272eefebe82b7303d.tar.gz
chromium_src-1214b853e84214f7e908a61272eefebe82b7303d.tar.bz2
Add UMA stat to count unique origins using getUserMedia and RTCPeerConnection.
BUG=none Review URL: https://codereview.chromium.org/174013003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253087 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/content_renderer.gypi2
-rw-r--r--content/renderer/media/media_stream_impl.cc8
-rw-r--r--content/renderer/media/webrtc_uma_histograms.cc36
-rw-r--r--content/renderer/media/webrtc_uma_histograms.h26
-rw-r--r--content/renderer/render_frame_impl.cc9
-rw-r--r--tools/metrics/histograms/histograms.xml8
6 files changed, 82 insertions, 7 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index 3ba5f96..2bf4e49 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -688,6 +688,8 @@
'renderer/media/webrtc_local_audio_track.h',
'renderer/media/webrtc_logging.cc',
'renderer/media/webrtc_logging.h',
+ 'renderer/media/webrtc_uma_histograms.cc',
+ 'renderer/media/webrtc_uma_histograms.h',
'renderer/media/webrtc/webrtc_local_audio_track_adapter.cc',
'renderer/media/webrtc/webrtc_local_audio_track_adapter.h',
'renderer/media/webrtc/webrtc_video_sink_adapter.cc',
diff --git a/content/renderer/media/media_stream_impl.cc b/content/renderer/media/media_stream_impl.cc
index 3867bed..ddbbc15 100644
--- a/content/renderer/media/media_stream_impl.cc
+++ b/content/renderer/media/media_stream_impl.cc
@@ -128,7 +128,13 @@ void MediaStreamImpl::requestUserMedia(
&options.optional_video);
}
- security_origin = GURL(user_media_request.securityOrigin().toString());
+ base::string16 security_origin_string =
+ user_media_request.securityOrigin().toString();
+ security_origin = GURL(security_origin_string);
+
+ UpdateWebRTCUniqueOriginMethodCount(WEBKIT_GET_USER_MEDIA,
+ security_origin_string);
+
// Get the WebFrame that requested a MediaStream.
// The frame is needed to tell the MediaStreamDispatcher when a stream goes
// out of scope.
diff --git a/content/renderer/media/webrtc_uma_histograms.cc b/content/renderer/media/webrtc_uma_histograms.cc
new file mode 100644
index 0000000..4cf8b98
--- /dev/null
+++ b/content/renderer/media/webrtc_uma_histograms.cc
@@ -0,0 +1,36 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/media/webrtc_uma_histograms.h"
+
+#include <set>
+
+#include "base/lazy_instance.h"
+
+namespace content {
+
+namespace {
+
+typedef std::set<base::string16> OriginSet;
+base::LazyInstance<OriginSet>::Leaky counted_security_origins;
+
+} // namespace
+
+void UpdateWebRTCMethodCount(JavaScriptAPIName api_name) {
+ UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCount", api_name, INVALID_NAME);
+}
+
+void UpdateWebRTCUniqueOriginMethodCount(
+ JavaScriptAPIName api_name,
+ const base::string16& security_origin) {
+ OriginSet* origins = counted_security_origins.Pointer();
+
+ if (origins->find(security_origin) == origins->end()) {
+ UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCountUniqueByOrigin",
+ api_name, INVALID_NAME);
+ origins->insert(security_origin);
+ }
+}
+
+} // namespace content
diff --git a/content/renderer/media/webrtc_uma_histograms.h b/content/renderer/media/webrtc_uma_histograms.h
index de358f4..06b94d3 100644
--- a/content/renderer/media/webrtc_uma_histograms.h
+++ b/content/renderer/media/webrtc_uma_histograms.h
@@ -6,6 +6,7 @@
#define CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_
#include "base/metrics/histogram.h"
+#include "base/strings/string16.h"
namespace content {
@@ -18,12 +19,25 @@ enum JavaScriptAPIName {
INVALID_NAME
};
-// Helper method used to collect information about the number of times
-// different WebRTC API:s are called from JavaScript.
-// The histogram can be viewed at chrome://histograms/WebRTC.webkitApiCount.
-inline void UpdateWebRTCMethodCount(JavaScriptAPIName api_name) {
- UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCount", api_name, INVALID_NAME);
-}
+// Helper method used to collect information about the raw count of
+// the number of times different WebRTC APIs are called from
+// JavaScript.
+//
+// The histogram can be viewed at
+// chrome://histograms/WebRTC.webkitApiCount.
+void UpdateWebRTCMethodCount(JavaScriptAPIName api_name);
+
+// Helper method used to collect information about the number of
+// unique security origins that call different WebRTC APIs within the
+// current browser session. For example, if abc.com calls getUserMedia
+// 100 times and RTCPeerConnection 10 times, and xyz.com calls
+// getUserMedia 50 times, RTCPeerConnection will have a count of 1 and
+// getUserMedia will have a count of 2.
+//
+// The histogram can be viewed at
+// chrome://histograms/WebRTC.webkitApiCountUniqueByOrigin.
+void UpdateWebRTCUniqueOriginMethodCount(JavaScriptAPIName api_name,
+ const base::string16& security_origin);
} // namespace content
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
index 75b6afb..142ca2b 100644
--- a/content/renderer/render_frame_impl.cc
+++ b/content/renderer/render_frame_impl.cc
@@ -42,6 +42,7 @@
#include "content/renderer/context_menu_params_builder.h"
#include "content/renderer/dom_automation_controller.h"
#include "content/renderer/internal_document_state_data.h"
+#include "content/renderer/media/webrtc_uma_histograms.h"
#include "content/renderer/npapi/plugin_channel_host.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/render_view_impl.h"
@@ -1702,6 +1703,14 @@ void RenderFrameImpl::willStartUsingPeerConnectionHandler(
DCHECK(!frame_ || frame_ == frame);
#if defined(ENABLE_WEBRTC)
static_cast<RTCPeerConnectionHandler*>(handler)->associateWithFrame(frame);
+
+ // This is triggered by Blink right after it creates
+ // RTCPeerConnection, and at this point we have the origin (via
+ // |frame|). Increment the UMA stat that counts the number of unique
+ // origins calling RTCPeerConnection.
+ UpdateWebRTCUniqueOriginMethodCount(
+ WEBKIT_RTC_PEER_CONNECTION,
+ frame->document().securityOrigin().toString());
#endif
}
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 8f5d71af..d437cdc 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -23128,6 +23128,14 @@ other types of suffix sets.
<summary>Counts number of calls to WebRTC APIs from JavaScript.</summary>
</histogram>
+<histogram name="WebRTC.webkitApiCountUniqueByOrigin" enum="JavaScriptAPIName">
+ <summary>
+ Counts calls to WebRTC APIs from JavaScript, once per security origin per
+ browsing session. Contrast with WebRTC.webkitApiCount, which is a raw count
+ of all calls made to these APIs.
+ </summary>
+</histogram>
+
<histogram name="Webstore.ExtensionInstallResult" enum="BooleanSuccess">
<summary>
The success or failure of all extension installs from the webstore. This