OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ |
7 | 7 |
8 #include "base/metrics/histogram.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/threading/non_thread_safe.h" |
| 10 #include "content/common/content_export.h" |
9 | 11 |
10 namespace content { | 12 namespace content { |
11 | 13 |
12 // Helper enum used for histogramming calls to WebRTC APIs from JavaScript. | 14 // Helper enum used for histogramming calls to WebRTC APIs from JavaScript. |
13 enum JavaScriptAPIName { | 15 enum JavaScriptAPIName { |
14 WEBKIT_GET_USER_MEDIA, | 16 WEBKIT_GET_USER_MEDIA, |
15 WEBKIT_PEER_CONNECTION, | 17 WEBKIT_PEER_CONNECTION, |
16 WEBKIT_DEPRECATED_PEER_CONNECTION, | 18 WEBKIT_DEPRECATED_PEER_CONNECTION, |
17 WEBKIT_RTC_PEER_CONNECTION, | 19 WEBKIT_RTC_PEER_CONNECTION, |
18 INVALID_NAME | 20 INVALID_NAME |
19 }; | 21 }; |
20 | 22 |
21 // Helper method used to collect information about the number of times | 23 // Helper method used to collect information about the number of times |
22 // different WebRTC API:s are called from JavaScript. | 24 // different WebRTC APIs are called from JavaScript. |
23 // The histogram can be viewed at chrome://histograms/WebRTC.webkitApiCount. | 25 // |
24 inline void UpdateWebRTCMethodCount(JavaScriptAPIName api_name) { | 26 // This contributes to two histograms; the former is a raw count of |
25 UMA_HISTOGRAM_ENUMERATION("WebRTC.webkitApiCount", api_name, INVALID_NAME); | 27 // the number of times the APIs are called, and be viewed at |
26 } | 28 // chrome://histograms/WebRTC.webkitApiCount. |
| 29 // |
| 30 // The latter is a count of the number of times the APIs are called |
| 31 // that gets incremented only once per "session" as established by the |
| 32 // PerSessionWebRTCAPIMetrics singleton below. It can be viewed at |
| 33 // chrome://histograms/WebRTC.webkitApiCountPerSession. |
| 34 void UpdateWebRTCMethodCount(JavaScriptAPIName api_name); |
| 35 |
| 36 // A singleton that keeps track of the number of MediaStreams being |
| 37 // sent over PeerConnections. It uses the transition to zero such |
| 38 // streams to demarcate the start of a new "session". Note that this |
| 39 // is a rough approximation of sessions, as you could conceivably have |
| 40 // multiple tabs using this renderer process, and each of them using |
| 41 // PeerConnections. |
| 42 // |
| 43 // The UpdateWebRTCMethodCount function above uses this class to log a |
| 44 // metric at most once per session. |
| 45 class CONTENT_EXPORT PerSessionWebRTCAPIMetrics : public base::NonThreadSafe { |
| 46 public: |
| 47 virtual ~PerSessionWebRTCAPIMetrics(); |
| 48 |
| 49 static PerSessionWebRTCAPIMetrics* GetInstance(); |
| 50 |
| 51 // Increment/decrement the number of streams being sent or received |
| 52 // over any current PeerConnection. |
| 53 void IncrementStreamCounter(); |
| 54 void DecrementStreamCounter(); |
| 55 |
| 56 protected: |
| 57 friend struct DefaultSingletonTraits<PerSessionWebRTCAPIMetrics>; |
| 58 friend void UpdateWebRTCMethodCount(JavaScriptAPIName); |
| 59 |
| 60 // Protected so that unit tests can test without this being a |
| 61 // singleton. |
| 62 PerSessionWebRTCAPIMetrics(); |
| 63 |
| 64 // Overridable by unit tests. |
| 65 virtual void LogUsage(JavaScriptAPIName api_name); |
| 66 |
| 67 // Called by UpdateWebRTCMethodCount above. Protected rather than |
| 68 // private so that unit tests can call it. |
| 69 void LogUsageOnlyOnce(JavaScriptAPIName api_name); |
| 70 |
| 71 private: |
| 72 void ResetUsage(); |
| 73 |
| 74 int num_streams_; |
| 75 bool has_used_api_[INVALID_NAME]; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(PerSessionWebRTCAPIMetrics); |
| 78 }; |
27 | 79 |
28 } // namespace content | 80 } // namespace content |
29 | 81 |
30 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ | 82 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_ |
OLD | NEW |