Index: content/renderer/media/webrtc_uma_histograms.h |
diff --git a/content/renderer/media/webrtc_uma_histograms.h b/content/renderer/media/webrtc_uma_histograms.h |
index de358f4c8d7bddeb037a3fa3ecfd446a768b2e36..453e1c695f5ed618f47b8248354aa693c7f318d1 100644 |
--- a/content/renderer/media/webrtc_uma_histograms.h |
+++ b/content/renderer/media/webrtc_uma_histograms.h |
@@ -5,7 +5,9 @@ |
#ifndef CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ |
#define CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ |
-#include "base/metrics/histogram.h" |
+#include "base/memory/singleton.h" |
+#include "base/threading/non_thread_safe.h" |
+#include "content/common/content_export.h" |
namespace content { |
@@ -19,11 +21,61 @@ enum JavaScriptAPIName { |
}; |
// 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); |
-} |
+// different WebRTC APIs are called from JavaScript. |
+// |
+// This contributes to two histograms; the former is a raw count of |
+// the number of times the APIs are called, and be viewed at |
+// chrome://histograms/WebRTC.webkitApiCount. |
+// |
+// The latter is a count of the number of times the APIs are called |
+// that gets incremented only once per "session" as established by the |
+// PerSessionWebRTCAPIMetrics singleton below. It can be viewed at |
+// chrome://histograms/WebRTC.webkitApiCountPerSession. |
+void UpdateWebRTCMethodCount(JavaScriptAPIName api_name); |
+ |
+// A singleton that keeps track of the number of MediaStreams being |
+// sent over PeerConnections. It uses the transition to zero such |
+// streams to demarcate the start of a new "session". Note that this |
+// is a rough approximation of sessions, as you could conceivably have |
+// multiple tabs using this renderer process, and each of them using |
+// PeerConnections. |
+// |
+// The UpdateWebRTCMethodCount function above uses this class to log a |
+// metric at most once per session. |
+class CONTENT_EXPORT PerSessionWebRTCAPIMetrics : public base::NonThreadSafe { |
+ public: |
+ virtual ~PerSessionWebRTCAPIMetrics(); |
+ |
+ static PerSessionWebRTCAPIMetrics* GetInstance(); |
+ |
+ // Increment/decrement the number of streams being sent or received |
+ // over any current PeerConnection. |
+ void IncrementStreamCounter(); |
+ void DecrementStreamCounter(); |
+ |
+ protected: |
+ friend struct DefaultSingletonTraits<PerSessionWebRTCAPIMetrics>; |
+ friend void UpdateWebRTCMethodCount(JavaScriptAPIName); |
+ |
+ // Protected so that unit tests can test without this being a |
+ // singleton. |
+ PerSessionWebRTCAPIMetrics(); |
+ |
+ // Overridable by unit tests. |
+ virtual void LogUsage(JavaScriptAPIName api_name); |
+ |
+ // Called by UpdateWebRTCMethodCount above. Protected rather than |
+ // private so that unit tests can call it. |
+ void LogUsageOnlyOnce(JavaScriptAPIName api_name); |
+ |
+ private: |
+ void ResetUsage(); |
+ |
+ int num_streams_; |
+ bool has_used_api_[INVALID_NAME]; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PerSessionWebRTCAPIMetrics); |
+}; |
} // namespace content |