capture_mode_metrics.cc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // Copyright 2020 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. #include "ash/capture_mode/capture_mode_metrics.h"
  5. #include "ash/shell.h"
  6. #include "base/metrics/histogram_functions.h"
  7. namespace ash {
  8. namespace {
  9. constexpr char kEndRecordingReasonHistogramName[] =
  10. "Ash.CaptureModeController.EndRecordingReason";
  11. constexpr char kBarButtonHistogramName[] =
  12. "Ash.CaptureModeController.BarButtons";
  13. constexpr char kCaptureAudioOnHistogramName[] =
  14. "Ash.CaptureModeController.CaptureAudioOnMetric";
  15. constexpr char kCaptureConfigurationHistogramName[] =
  16. "Ash.CaptureModeController.CaptureConfiguration";
  17. constexpr char kCaptureRegionAdjustmentHistogramName[] =
  18. "Ash.CaptureModeController.CaptureRegionAdjusted";
  19. constexpr char kConsecutiveScreenshotHistogramName[] =
  20. "Ash.CaptureModeController.ConsecutiveScreenshots";
  21. constexpr char kEntryHistogramName[] = "Ash.CaptureModeController.EntryPoint";
  22. constexpr char kQuickActionHistogramName[] =
  23. "Ash.CaptureModeController.QuickAction";
  24. constexpr char kRecordTimeHistogramName[] =
  25. "Ash.CaptureModeController.ScreenRecordingLength";
  26. constexpr char kSaveToLocationHistogramName[] =
  27. "Ash.CaptureModeController.SaveLocation";
  28. constexpr char kScreenshotsPerDayHistogramName[] =
  29. "Ash.CaptureModeController.ScreenshotsPerDay";
  30. constexpr char kScreenshotsPerWeekHistogramName[] =
  31. "Ash.CaptureModeController.ScreenshotsPerWeek";
  32. constexpr char kSwitchesFromInitialModeHistogramName[] =
  33. "Ash.CaptureModeController.SwitchesFromInitialCaptureMode";
  34. constexpr char kSwitchToDefaultFolderReasonHistogramName[] =
  35. "Ash.CaptureModeController.SwitchToDefaultReason";
  36. constexpr char kProjectorCaptureConfigurationHistogramName[] =
  37. "Ash.CaptureModeController.Projector.CaptureConfiguration";
  38. constexpr char kProjectorCaptureRegionAdjustmentHistogramName[] =
  39. "Ash.CaptureModeController.Projector.CaptureRegionAdjusted";
  40. constexpr char kProjectorRecordTimeHistogramName[] =
  41. "Ash.CaptureModeController.Projector.ScreenRecordingLength";
  42. constexpr char kRecordingStartsWithCamera[] =
  43. "Ash.CaptureModeController.RecordingStartsWithCamera";
  44. constexpr char kProjectorRecordingStartsWithCamera[] =
  45. "Ash.CaptureModeController.Projector.RecordingStartsWithCamera";
  46. constexpr char kCameraDisconnectionsDuringRecordings[] =
  47. "Ash.CaptureModeController.CameraDisconnectionsDuringRecordings";
  48. constexpr char kCameraReconnectDuration[] =
  49. "Ash.CaptureModeController.CameraReconnectDuration";
  50. constexpr char kRecordingCameraSizeOnStart[] =
  51. "Ash.CaptureModeController.RecordingCameraSizeOnStart";
  52. constexpr char kRecordingCameraPositionOnStart[] =
  53. "Ash.CaptureModeController.RecordingCameraPositionOnStart";
  54. constexpr char kNumberOfConnectedCameras[] =
  55. "Ash.CaptureModeController.NumberOfConnectedCameras";
  56. } // namespace
  57. void RecordEndRecordingReason(EndRecordingReason reason) {
  58. base::UmaHistogramEnumeration(
  59. GetCaptureModeHistogramName(kEndRecordingReasonHistogramName), reason);
  60. }
  61. void RecordCaptureModeBarButtonType(CaptureModeBarButtonType button_type) {
  62. base::UmaHistogramEnumeration(
  63. GetCaptureModeHistogramName(kBarButtonHistogramName), button_type);
  64. }
  65. void RecordCaptureModeConfiguration(CaptureModeType type,
  66. CaptureModeSource source,
  67. bool audio_on,
  68. bool is_in_projector_mode) {
  69. const std::string histogram_name = GetCaptureModeHistogramName(
  70. is_in_projector_mode ? kProjectorCaptureConfigurationHistogramName
  71. : kCaptureConfigurationHistogramName);
  72. base::UmaHistogramEnumeration(histogram_name, GetConfiguration(type, source));
  73. if (type == CaptureModeType::kVideo) {
  74. base::UmaHistogramBoolean(
  75. GetCaptureModeHistogramName(kCaptureAudioOnHistogramName), audio_on);
  76. }
  77. }
  78. void RecordCaptureModeEntryType(CaptureModeEntryType entry_type) {
  79. base::UmaHistogramEnumeration(
  80. GetCaptureModeHistogramName(kEntryHistogramName), entry_type);
  81. }
  82. void RecordCaptureModeRecordTime(int64_t length_in_seconds,
  83. bool is_in_projector_mode) {
  84. const std::string histogram_name = GetCaptureModeHistogramName(
  85. is_in_projector_mode ? kProjectorRecordTimeHistogramName
  86. : kRecordTimeHistogramName);
  87. // Use custom counts macro instead of custom times so we can record in
  88. // seconds instead of milliseconds. The max bucket is 3 hours.
  89. base::UmaHistogramCustomCounts(histogram_name, length_in_seconds,
  90. /*min=*/1,
  91. /*max=*/base::Hours(3).InSeconds(),
  92. /*bucket_count=*/50);
  93. }
  94. void RecordCaptureModeSwitchesFromInitialMode(bool switched) {
  95. base::UmaHistogramBoolean(kSwitchesFromInitialModeHistogramName, switched);
  96. }
  97. void RecordNumberOfCaptureRegionAdjustments(int num_adjustments,
  98. bool is_in_projector_mode) {
  99. const std::string histogram_name = GetCaptureModeHistogramName(
  100. is_in_projector_mode ? kProjectorCaptureRegionAdjustmentHistogramName
  101. : kCaptureRegionAdjustmentHistogramName);
  102. base::UmaHistogramCounts100(histogram_name, num_adjustments);
  103. }
  104. void RecordNumberOfConsecutiveScreenshots(int num_consecutive_screenshots) {
  105. if (num_consecutive_screenshots > 1) {
  106. base::UmaHistogramCounts100(kConsecutiveScreenshotHistogramName,
  107. num_consecutive_screenshots);
  108. }
  109. }
  110. void RecordNumberOfScreenshotsTakenInLastDay(
  111. int num_screenshots_taken_in_last_day) {
  112. base::UmaHistogramCounts100(kScreenshotsPerDayHistogramName,
  113. num_screenshots_taken_in_last_day);
  114. }
  115. void RecordNumberOfScreenshotsTakenInLastWeek(
  116. int num_screenshots_taken_in_last_week) {
  117. base::UmaHistogramCounts100(kScreenshotsPerWeekHistogramName,
  118. num_screenshots_taken_in_last_week);
  119. }
  120. void RecordScreenshotNotificationQuickAction(CaptureQuickAction action) {
  121. base::UmaHistogramEnumeration(kQuickActionHistogramName, action);
  122. }
  123. void RecordSaveToLocation(CaptureModeSaveToLocation save_location) {
  124. base::UmaHistogramEnumeration(
  125. GetCaptureModeHistogramName(kSaveToLocationHistogramName), save_location);
  126. }
  127. void RecordSwitchToDefaultFolderReason(
  128. CaptureModeSwitchToDefaultReason reason) {
  129. base::UmaHistogramEnumeration(
  130. GetCaptureModeHistogramName(kSwitchToDefaultFolderReasonHistogramName),
  131. reason);
  132. }
  133. CaptureModeConfiguration GetConfiguration(CaptureModeType type,
  134. CaptureModeSource source) {
  135. switch (source) {
  136. case CaptureModeSource::kFullscreen:
  137. return type == CaptureModeType::kImage
  138. ? CaptureModeConfiguration::kFullscreenScreenshot
  139. : CaptureModeConfiguration::kFullscreenRecording;
  140. case CaptureModeSource::kRegion:
  141. return type == CaptureModeType::kImage
  142. ? CaptureModeConfiguration::kRegionScreenshot
  143. : CaptureModeConfiguration::kRegionRecording;
  144. case CaptureModeSource::kWindow:
  145. return type == CaptureModeType::kImage
  146. ? CaptureModeConfiguration::kWindowScreenshot
  147. : CaptureModeConfiguration::kWindowRecording;
  148. }
  149. }
  150. void RecordRecordingStartsWithCamera(bool starts_with_camera,
  151. bool is_in_projector_mode) {
  152. const std::string histogram_name = is_in_projector_mode
  153. ? kProjectorRecordingStartsWithCamera
  154. : kRecordingStartsWithCamera;
  155. base::UmaHistogramBoolean(GetCaptureModeHistogramName(histogram_name),
  156. starts_with_camera);
  157. }
  158. void RecordCameraDisconnectionsDuringRecordings(int num_camera_disconnections) {
  159. base::UmaHistogramCounts100(
  160. GetCaptureModeHistogramName(kCameraDisconnectionsDuringRecordings),
  161. num_camera_disconnections);
  162. }
  163. void RecordNumberOfConnectedCameras(int num_camera_connected) {
  164. base::UmaHistogramCounts100(kNumberOfConnectedCameras, num_camera_connected);
  165. }
  166. void RecordCameraReconnectDuration(int length_in_seconds,
  167. int grace_period_in_seconds) {
  168. base::UmaHistogramCustomCounts(
  169. GetCaptureModeHistogramName(kCameraReconnectDuration), length_in_seconds,
  170. 0, grace_period_in_seconds, grace_period_in_seconds);
  171. }
  172. void RecordCameraSizeOnStart(CaptureModeCameraSize camera_size) {
  173. base::UmaHistogramEnumeration(
  174. GetCaptureModeHistogramName(kRecordingCameraSizeOnStart), camera_size);
  175. }
  176. void RecordCameraPositionOnStart(CameraPreviewSnapPosition camera_position) {
  177. base::UmaHistogramEnumeration(
  178. GetCaptureModeHistogramName(kRecordingCameraPositionOnStart),
  179. camera_position);
  180. }
  181. std::string GetCaptureModeHistogramName(std::string prefix) {
  182. prefix.append(Shell::Get()->IsInTabletMode() ? ".TabletMode"
  183. : ".ClamshellMode");
  184. return prefix;
  185. }
  186. } // namespace ash