media_router_metrics.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. // Copyright 2015 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. #ifndef COMPONENTS_MEDIA_ROUTER_BROWSER_MEDIA_ROUTER_METRICS_H_
  5. #define COMPONENTS_MEDIA_ROUTER_BROWSER_MEDIA_ROUTER_METRICS_H_
  6. #include "base/gtest_prod_util.h"
  7. #include "base/time/time.h"
  8. #include "components/media_router/common/media_route_provider_helper.h"
  9. #include "components/media_router/common/media_source.h"
  10. #include "components/media_router/common/mojom/media_router.mojom-forward.h"
  11. #include "components/media_router/common/route_request_result.h"
  12. #include "media/base/container_names.h"
  13. #include "third_party/abseil-cpp/absl/types/optional.h"
  14. class GURL;
  15. namespace media_router {
  16. enum class SinkIconType;
  17. // These values are persisted to logs. Entries should not be renumbered and
  18. // numeric values should never be reused. When making changes, also update the
  19. // enum list in tools/metrics/histograms/enums.xml to keep it in sync.
  20. // NOTE: For metrics specific to the Media Router component extension, see
  21. // mojo/media_router_mojo_metrics.h.
  22. // This enum is a cartesian product of dialog activation locations and Cast
  23. // modes. Per tools/metrics/histograms/README.md, a multidimensional histogram
  24. // must be flattened into one dimension.
  25. enum class DialogActivationLocationAndCastMode {
  26. kPinnedIconAndPresentation,
  27. kPinnedIconAndTabMirror,
  28. kPinnedIconAndDesktopMirror,
  29. kPinnedIconAndLocalFile, // Obsolete.
  30. // One can start casting from an ephemeral icon by stopping a session, then
  31. // starting another from the same dialog.
  32. kEphemeralIconAndPresentation,
  33. kEphemeralIconAndTabMirror,
  34. kEphemeralIconAndDesktopMirror,
  35. kEphemeralIconAndLocalFile, // Obsolete.
  36. kContextMenuAndPresentation,
  37. kContextMenuAndTabMirror,
  38. kContextMenuAndDesktopMirror,
  39. kContextMenuAndLocalFile, // Obsolete.
  40. kPageAndPresentation,
  41. kPageAndTabMirror,
  42. kPageAndDesktopMirror,
  43. kPageAndLocalFile, // Obsolete.
  44. kAppMenuAndPresentation,
  45. kAppMenuAndTabMirror,
  46. kAppMenuAndDesktopMirror,
  47. kAppMenuAndLocalFile, // Obsolete.
  48. kSharingHubAndPresentation,
  49. kSharingHubAndTabMirror,
  50. kSharingHubAndDesktopMirror,
  51. // NOTE: Do not reorder existing entries, and add entries only immediately
  52. // above this line. Remember to also update
  53. // tools/metrics/histograms/enums.xml.
  54. kMaxValue = kSharingHubAndDesktopMirror
  55. };
  56. // These values are persisted to logs. Entries should not be renumbered and
  57. // numeric values should never be reused.
  58. // Where the user clicked to open the Media Router dialog.
  59. enum class MediaRouterDialogActivationLocation {
  60. TOOLBAR = 0,
  61. OVERFLOW_MENU = 1,
  62. CONTEXTUAL_MENU = 2,
  63. PAGE = 3,
  64. APP_MENU = 4,
  65. SYSTEM_TRAY = 5,
  66. SHARING_HUB = 6,
  67. // NOTE: Add entries only immediately above this line. Remember to also update
  68. // tools/metrics/histograms/enums.xml.
  69. TOTAL_COUNT = 7
  70. };
  71. // The possible outcomes from a route creation response.
  72. enum class MediaRouterRouteCreationOutcome {
  73. SUCCESS = 0,
  74. FAILURE_NO_ROUTE = 1,
  75. FAILURE_INVALID_SINK = 2,
  76. // Note: Add entries only immediately above this line. Remember to also update
  77. // tools/metrics/histograms/enums.xml.
  78. TOTAL_COUNT = 3,
  79. };
  80. // The possible actions a user can take while interacting with the Media Router
  81. // dialog.
  82. enum class MediaRouterUserAction {
  83. CHANGE_MODE = 0,
  84. START_LOCAL = 1,
  85. STOP_LOCAL = 2,
  86. CLOSE = 3,
  87. STATUS_REMOTE = 4,
  88. REPLACE_LOCAL_ROUTE = 5,
  89. STOP_REMOTE = 6,
  90. // Note: Add entries only immediately above this line. Remember to also update
  91. // tools/metrics/histograms/enums.xml.
  92. TOTAL_COUNT = 7
  93. };
  94. enum class PresentationUrlType {
  95. kOther,
  96. kCast, // cast:
  97. kCastDial, // cast-dial:
  98. kCastLegacy, // URLs that start with |kLegacyCastPresentationUrlPrefix|.
  99. kDial, // dial:
  100. kHttp, // http:
  101. kHttps, // https:
  102. kRemotePlayback, // remote-playback:
  103. // Add new types only immediately above this line. Remember to also update
  104. // tools/metrics/histograms/enums.xml.
  105. kPresentationUrlTypeCount
  106. };
  107. enum class UiType {
  108. kCastDialog,
  109. kGlobalMediaControls,
  110. };
  111. enum class MediaRouterAndroidDialogType {
  112. kRouteController = 0,
  113. kRouteChooser = 1,
  114. kMaxValue = kRouteChooser,
  115. };
  116. enum class MediaRouterAndroidDialogAction {
  117. kTerminateRoute = 0,
  118. kStartRoute = 1,
  119. kMaxValue = kStartRoute,
  120. };
  121. class MediaRouterMetrics {
  122. public:
  123. MediaRouterMetrics();
  124. ~MediaRouterMetrics();
  125. // UMA histogram names.
  126. static const char kHistogramCloseLatency[];
  127. static const char kHistogramIconClickLocation[];
  128. static const char kHistogramMediaRouterFileFormat[];
  129. static const char kHistogramMediaRouterFileSize[];
  130. static const char kHistogramMediaSinkType[];
  131. static const char kHistogramPresentationUrlType[];
  132. static const char kHistogramRouteCreationOutcome[];
  133. static const char kHistogramStartLocalLatency[];
  134. static const char kHistogramStartLocalPosition[];
  135. static const char kHistogramStartLocalSessionSuccessful[];
  136. static const char kHistogramStopRoute[];
  137. static const char kHistogramUiDeviceCount[];
  138. static const char kHistogramUiDialogActivationLocationAndCastMode[];
  139. static const char kHistogramUiDialogIconStateAtOpen[];
  140. static const char kHistogramUiDialogLoadedWithData[];
  141. static const char kHistogramUiDialogPaint[];
  142. static const char kHistogramUiFirstAction[];
  143. static const char kHistogramUiIconStateAtInit[];
  144. static const char kHistogramUiAndroidDialogType[];
  145. static const char kHistogramUiAndroidDialogAction[];
  146. // When recording the number of devices shown in UI we record after a delay
  147. // because discovering devices can take some time after the UI is shown.
  148. static const base::TimeDelta kDeviceCountMetricDelay;
  149. // Records where the user clicked to open the Media Router dialog.
  150. static void RecordMediaRouterDialogActivationLocation(
  151. MediaRouterDialogActivationLocation activation_location);
  152. // Records the duration it takes for the Media Router dialog to open and
  153. // finish painting after a user clicks to open the dialog.
  154. static void RecordMediaRouterDialogPaint(const base::TimeDelta& delta);
  155. // Records the duration it takes for the Media Router dialog to load its
  156. // initial data after a user clicks to open the dialog.
  157. static void RecordMediaRouterDialogLoaded(const base::TimeDelta& delta);
  158. // Records the duration it takes from the user opening the Media Router dialog
  159. // to the user closing the dialog. This is only called if closing the dialog
  160. // is the first action the user takes.
  161. static void RecordCloseDialogLatency(const base::TimeDelta& delta);
  162. // Records the first action the user took after the Media Router dialog
  163. // opened.
  164. static void RecordMediaRouterInitialUserAction(MediaRouterUserAction action);
  165. // Records the outcome in a create route response.
  166. static void RecordRouteCreationOutcome(
  167. MediaRouterRouteCreationOutcome outcome);
  168. // Records the format of a cast file.
  169. static void RecordMediaRouterFileFormat(
  170. media::container_names::MediaContainerName format);
  171. // Records the size of a cast file.
  172. static void RecordMediaRouterFileSize(int64_t size);
  173. // Records the type of Presentation URL used by a web page.
  174. static void RecordPresentationUrlType(const GURL& url);
  175. // Records the type of the sink that media is being Cast to.
  176. static void RecordMediaSinkType(SinkIconType sink_icon_type);
  177. static void RecordMediaSinkTypeForGlobalMediaControls(
  178. SinkIconType sink_icon_type);
  179. static void RecordMediaSinkTypeForCastDialog(SinkIconType sink_icon_type);
  180. static void RecordMediaSinkTypeWhenCastAndDialPresent(
  181. SinkIconType sink_icon_type,
  182. UiType ui);
  183. // Records the number of devices shown in the Cast dialog. The device count
  184. // may be 0.
  185. static void RecordDeviceCount(int device_count);
  186. // Records the number of sinks in |is_available| state, provided by |provider|
  187. // that was opened via |activation_location|. Recorded for the global media
  188. // controls and the Cast dialog, respectively.
  189. static void RecordGmcDeviceCount(
  190. MediaRouterDialogActivationLocation activation_location,
  191. mojom::MediaRouteProviderId provider,
  192. bool is_available,
  193. int count);
  194. static void RecordCastDialogDeviceCount(
  195. MediaRouterDialogActivationLocation activation_location,
  196. mojom::MediaRouteProviderId provider,
  197. bool is_available,
  198. int count);
  199. // Records the index of the device the user has started casting to on the
  200. // devices list. The index starts at 0.
  201. static void RecordStartRouteDeviceIndex(int index);
  202. // Records the time it takes from the Media Router dialog showing at least one
  203. // device to the user starting to cast. This is called only if casting is the
  204. // first action taken by the user, aside from selecting the sink to cast to.
  205. static void RecordStartLocalSessionLatency(const base::TimeDelta& delta);
  206. // Records whether or not an attempt to start casting was successful.
  207. static void RecordStartLocalSessionSuccessful(bool success);
  208. // Records the user stopping a route in the UI.
  209. static void RecordStopLocalRoute();
  210. static void RecordStopRemoteRoute();
  211. // Records whether the toolbar icon is pinned by the user pref / admin policy.
  212. // Recorded whenever the Cast dialog is opened.
  213. static void RecordIconStateAtDialogOpen(bool is_pinned);
  214. // Records whether the toolbar icon is pinned by the user pref / admin policy.
  215. // Recorded whenever the browser is initialized.
  216. static void RecordIconStateAtInit(bool is_pinned);
  217. // Records the outcome of a create route request to a Media Route Provider.
  218. // This and the following methods that record ResultCode use per-provider
  219. // histograms.
  220. static void RecordCreateRouteResultCode(
  221. mojom::RouteRequestResultCode result_code,
  222. absl::optional<mojom::MediaRouteProviderId> provider_id = absl::nullopt);
  223. // Records the outcome of a join route request to a Media Route Provider.
  224. static void RecordJoinRouteResultCode(
  225. mojom::RouteRequestResultCode result_code,
  226. absl::optional<mojom::MediaRouteProviderId> provider_id = absl::nullopt);
  227. // Records the outcome of a call to terminateRoute() on a Media Route
  228. // Provider.
  229. static void RecordMediaRouteProviderTerminateRoute(
  230. mojom::RouteRequestResultCode result_code,
  231. absl::optional<mojom::MediaRouteProviderId> provider_id = absl::nullopt);
  232. // Records the type of the MediaRouter dialog opened. Android only.
  233. static void RecordMediaRouterAndroidDialogType(
  234. MediaRouterAndroidDialogType type);
  235. // Records the action taken on the MediaRouter dialog. Android only.
  236. static void RecordMediaRouterAndroidDialogAction(
  237. MediaRouterAndroidDialogAction action);
  238. };
  239. } // namespace media_router
  240. #endif // COMPONENTS_MEDIA_ROUTER_BROWSER_MEDIA_ROUTER_METRICS_H_