Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / renderer / media / webrtc_uma_histograms.h
blob2ab6f6d65366821cf1fbec4108b465942ba7d10d
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_
8 #include "base/memory/singleton.h"
9 #include "base/threading/non_thread_safe.h"
10 #include "content/common/content_export.h"
11 #include "content/public/common/media_stream_request.h"
13 namespace content {
15 // Used to investigate where UserMediaRequests end up.
16 // Only UserMediaRequests that do not log with LogUserMediaRequestResult
17 // should call LogUserMediaRequestWithNoResult.
19 // Elements in this enum should not be deleted or rearranged; the only
20 // permitted operation is to add new elements before
21 // NUM_MEDIA_STREAM_REQUEST_WITH_NO_RESULT.
22 enum MediaStreamRequestState {
23 MEDIA_STREAM_REQUEST_EXPLICITLY_CANCELLED = 0,
24 MEDIA_STREAM_REQUEST_NOT_GENERATED = 1,
25 MEDIA_STREAM_REQUEST_PENDING_MEDIA_TRACKS = 2,
26 NUM_MEDIA_STREAM_REQUEST_WITH_NO_RESULT
29 void LogUserMediaRequestWithNoResult(MediaStreamRequestState state);
30 void LogUserMediaRequestResult(MediaStreamRequestResult result);
32 // Helper enum used for histogramming calls to WebRTC APIs from JavaScript.
33 enum JavaScriptAPIName {
34 WEBKIT_GET_USER_MEDIA,
35 WEBKIT_PEER_CONNECTION,
36 WEBKIT_DEPRECATED_PEER_CONNECTION,
37 WEBKIT_RTC_PEER_CONNECTION,
38 WEBKIT_GET_MEDIA_DEVICES,
39 INVALID_NAME
42 // Helper method used to collect information about the number of times
43 // different WebRTC APIs are called from JavaScript.
45 // This contributes to two histograms; the former is a raw count of
46 // the number of times the APIs are called, and be viewed at
47 // chrome://histograms/WebRTC.webkitApiCount.
49 // The latter is a count of the number of times the APIs are called
50 // that gets incremented only once per "session" as established by the
51 // PerSessionWebRTCAPIMetrics singleton below. It can be viewed at
52 // chrome://histograms/WebRTC.webkitApiCountPerSession.
53 void UpdateWebRTCMethodCount(JavaScriptAPIName api_name);
55 // A singleton that keeps track of the number of MediaStreams being
56 // sent over PeerConnections. It uses the transition to zero such
57 // streams to demarcate the start of a new "session". Note that this
58 // is a rough approximation of sessions, as you could conceivably have
59 // multiple tabs using this renderer process, and each of them using
60 // PeerConnections.
62 // The UpdateWebRTCMethodCount function above uses this class to log a
63 // metric at most once per session.
64 class CONTENT_EXPORT PerSessionWebRTCAPIMetrics : public base::NonThreadSafe {
65 public:
66 virtual ~PerSessionWebRTCAPIMetrics();
68 static PerSessionWebRTCAPIMetrics* GetInstance();
70 // Increment/decrement the number of streams being sent or received
71 // over any current PeerConnection.
72 void IncrementStreamCounter();
73 void DecrementStreamCounter();
75 protected:
76 friend struct DefaultSingletonTraits<PerSessionWebRTCAPIMetrics>;
77 friend void UpdateWebRTCMethodCount(JavaScriptAPIName);
79 // Protected so that unit tests can test without this being a
80 // singleton.
81 PerSessionWebRTCAPIMetrics();
83 // Overridable by unit tests.
84 virtual void LogUsage(JavaScriptAPIName api_name);
86 // Called by UpdateWebRTCMethodCount above. Protected rather than
87 // private so that unit tests can call it.
88 void LogUsageOnlyOnce(JavaScriptAPIName api_name);
90 private:
91 void ResetUsage();
93 int num_streams_;
94 bool has_used_api_[INVALID_NAME];
96 DISALLOW_COPY_AND_ASSIGN(PerSessionWebRTCAPIMetrics);
99 } // namespace content
101 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_UMA_HISTOGRAMS_H_