app_list_menu_model_adapter.cc 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // Copyright 2018 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/app_list/views/app_list_menu_model_adapter.h"
  5. #include <utility>
  6. #include "ash/app_list/app_list_metrics.h"
  7. #include "ash/constants/ash_features.h"
  8. #include "ash/public/cpp/app_list/app_list_types.h"
  9. #include "ash/public/cpp/app_menu_constants.h"
  10. #include "base/metrics/histogram_macros.h"
  11. #include "ui/views/controls/menu/menu_runner.h"
  12. namespace ash {
  13. AppListMenuModelAdapter::AppListMenuModelAdapter(
  14. const std::string& app_id,
  15. std::unique_ptr<ui::SimpleMenuModel> menu_model,
  16. views::Widget* widget_owner,
  17. ui::MenuSourceType source_type,
  18. const AppLaunchedMetricParams& metric_params,
  19. AppListViewAppType type,
  20. base::OnceClosure on_menu_closed_callback,
  21. bool is_tablet_mode)
  22. : AppMenuModelAdapter(app_id,
  23. std::move(menu_model),
  24. widget_owner,
  25. source_type,
  26. std::move(on_menu_closed_callback),
  27. is_tablet_mode),
  28. metric_params_(metric_params),
  29. type_(type) {
  30. DCHECK_NE(AppListViewAppType::APP_LIST_APP_TYPE_LAST, type);
  31. }
  32. AppListMenuModelAdapter::~AppListMenuModelAdapter() = default;
  33. void AppListMenuModelAdapter::RecordHistogramOnMenuClosed() {
  34. const base::TimeDelta user_journey_time =
  35. base::TimeTicks::Now() - menu_open_time();
  36. switch (type_) {
  37. case FULLSCREEN_SUGGESTED:
  38. UMA_HISTOGRAM_ENUMERATION(
  39. "Apps.ContextMenuShowSourceV2.SuggestedAppFullscreen", source_type(),
  40. ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  41. UMA_HISTOGRAM_TIMES(
  42. "Apps.ContextMenuUserJourneyTimeV2.SuggestedAppFullscreen",
  43. user_journey_time);
  44. if (is_tablet_mode()) {
  45. UMA_HISTOGRAM_ENUMERATION(
  46. "Apps.ContextMenuShowSourceV2.SuggestedAppFullscreen.TabletMode",
  47. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  48. UMA_HISTOGRAM_TIMES(
  49. "Apps.ContextMenuUserJourneyTimeV2.SuggestedAppFullscreen."
  50. "TabletMode",
  51. user_journey_time);
  52. } else {
  53. UMA_HISTOGRAM_ENUMERATION(
  54. "Apps.ContextMenuShowSourceV2.SuggestedAppFullscreen.ClamshellMode",
  55. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  56. UMA_HISTOGRAM_TIMES(
  57. "Apps.ContextMenuUserJourneyTimeV2.SuggestedAppFullscreen."
  58. "ClamshellMode",
  59. user_journey_time);
  60. }
  61. break;
  62. case FULLSCREEN_APP_GRID:
  63. UMA_HISTOGRAM_ENUMERATION("Apps.ContextMenuShowSourceV2.AppGrid",
  64. source_type(), ui::MENU_SOURCE_TYPE_LAST);
  65. UMA_HISTOGRAM_TIMES("Apps.ContextMenuUserJourneyTimeV2.AppGrid",
  66. user_journey_time);
  67. if (is_tablet_mode()) {
  68. UMA_HISTOGRAM_ENUMERATION(
  69. "Apps.ContextMenuShowSourceV2.AppGrid.TabletMode", source_type(),
  70. ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  71. UMA_HISTOGRAM_TIMES(
  72. "Apps.ContextMenuUserJourneyTimeV2.AppGrid.TabletMode",
  73. user_journey_time);
  74. } else {
  75. UMA_HISTOGRAM_ENUMERATION(
  76. "Apps.ContextMenuShowSourceV2.AppGrid.ClamshellMode", source_type(),
  77. ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  78. UMA_HISTOGRAM_TIMES(
  79. "Apps.ContextMenuUserJourneyTimeV2.AppGrid.ClamshellMode",
  80. user_journey_time);
  81. }
  82. break;
  83. case PEEKING_SUGGESTED:
  84. UMA_HISTOGRAM_ENUMERATION(
  85. "Apps.ContextMenuShowSourceV2.SuggestedAppPeeking", source_type(),
  86. ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  87. UMA_HISTOGRAM_TIMES(
  88. "Apps.ContextMenuUserJourneyTimeV2.SuggestedAppPeeking",
  89. user_journey_time);
  90. if (is_tablet_mode()) {
  91. UMA_HISTOGRAM_ENUMERATION(
  92. "Apps.ContextMenuShowSourceV2.SuggestedAppPeeking.TabletMode",
  93. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  94. UMA_HISTOGRAM_TIMES(
  95. "Apps.ContextMenuUserJourneyTimeV2.SuggestedAppPeeking.TabletMode",
  96. user_journey_time);
  97. } else {
  98. UMA_HISTOGRAM_ENUMERATION(
  99. "Apps.ContextMenuShowSourceV2.SuggestedAppPeeking.ClamshellMode",
  100. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  101. UMA_HISTOGRAM_TIMES(
  102. "Apps.ContextMenuUserJourneyTimeV2.SuggestedAppPeeking."
  103. "ClamshellMode",
  104. user_journey_time);
  105. }
  106. break;
  107. case PRODUCTIVITY_LAUNCHER_RECENT_APP:
  108. DCHECK(features::IsProductivityLauncherEnabled());
  109. if (is_tablet_mode()) {
  110. UMA_HISTOGRAM_ENUMERATION(
  111. "Apps.ContextMenuShowSourceV2.ProductivityLauncherRecentApp."
  112. "TabletMode",
  113. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  114. UMA_HISTOGRAM_TIMES(
  115. "Apps.ContextMenuUserJourneyTimeV2.ProductivityLauncherRecentApp."
  116. "TabletMode",
  117. user_journey_time);
  118. } else {
  119. UMA_HISTOGRAM_ENUMERATION(
  120. "Apps.ContextMenuShowSourceV2.ProductivityLauncherRecentApp."
  121. "ClamshellMode",
  122. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  123. UMA_HISTOGRAM_TIMES(
  124. "Apps.ContextMenuUserJourneyTimeV2.ProductivityLauncherRecentApp."
  125. "ClamshellMode",
  126. user_journey_time);
  127. }
  128. break;
  129. case PRODUCTIVITY_LAUNCHER_APP_GRID:
  130. DCHECK(features::IsProductivityLauncherEnabled());
  131. if (is_tablet_mode()) {
  132. UMA_HISTOGRAM_ENUMERATION(
  133. "Apps.ContextMenuShowSourceV2.ProductivityLauncherAppGrid."
  134. "TabletMode",
  135. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  136. UMA_HISTOGRAM_TIMES(
  137. "Apps.ContextMenuUserJourneyTimeV2.ProductivityLauncherAppGrid."
  138. "TabletMode",
  139. user_journey_time);
  140. } else {
  141. UMA_HISTOGRAM_ENUMERATION(
  142. "Apps.ContextMenuShowSourceV2.ProductivityLauncherAppGrid."
  143. "ClamshellMode",
  144. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  145. UMA_HISTOGRAM_TIMES(
  146. "Apps.ContextMenuUserJourneyTimeV2.ProductivityLauncherAppGrid."
  147. "ClamshellMode",
  148. user_journey_time);
  149. }
  150. break;
  151. case HALF_SEARCH_RESULT:
  152. case FULLSCREEN_SEARCH_RESULT:
  153. UMA_HISTOGRAM_ENUMERATION("Apps.ContextMenuShowSourceV2.SearchResult",
  154. source_type(),
  155. ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  156. UMA_HISTOGRAM_TIMES("Apps.ContextMenuUserJourneyTimeV2.SearchResult",
  157. user_journey_time);
  158. if (is_tablet_mode()) {
  159. UMA_HISTOGRAM_ENUMERATION(
  160. "Apps.ContextMenuShowSourceV2.SearchResult.TabletMode",
  161. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  162. UMA_HISTOGRAM_TIMES(
  163. "Apps.ContextMenuUserJourneyTimeV2.SearchResult.TabletMode",
  164. user_journey_time);
  165. } else {
  166. UMA_HISTOGRAM_ENUMERATION(
  167. "Apps.ContextMenuShowSourceV2.SearchResult.ClamshellMode",
  168. source_type(), ui::MenuSourceType::MENU_SOURCE_TYPE_LAST);
  169. UMA_HISTOGRAM_TIMES(
  170. "Apps.ContextMenuUserJourneyTimeV2.SearchResult.ClamshellMode",
  171. user_journey_time);
  172. }
  173. break;
  174. case APP_LIST_APP_TYPE_LAST:
  175. NOTREACHED();
  176. break;
  177. }
  178. }
  179. bool AppListMenuModelAdapter::IsCommandEnabled(int id) const {
  180. // NOTIFICATION_CONTAINER is always enabled. It is added to this model by
  181. // NotificationMenuController. It is not known by model()'s delegate (i.e.
  182. // an instance of AppContextMenu). Check for it first.
  183. if (id == NOTIFICATION_CONTAINER)
  184. return true;
  185. return AppMenuModelAdapter::IsCommandEnabled(id);
  186. }
  187. void AppListMenuModelAdapter::ExecuteCommand(int id, int mouse_event_flags) {
  188. MaybeRecordAppLaunched(id);
  189. // Note that ExecuteCommand might delete us.
  190. AppMenuModelAdapter::ExecuteCommand(id, mouse_event_flags);
  191. }
  192. void AppListMenuModelAdapter::MaybeRecordAppLaunched(int command_id) {
  193. // Early out if |command_id| is not considered as app launch.
  194. if (!IsCommandIdAnAppLaunch(command_id))
  195. return;
  196. switch (metric_params_.launch_type) {
  197. case AppListLaunchType::kSearchResult:
  198. break;
  199. case AppListLaunchType::kAppSearchResult:
  200. case AppListLaunchType::kApp:
  201. RecordAppListAppLaunched(
  202. metric_params_.launched_from, metric_params_.app_list_view_state,
  203. metric_params_.is_tablet_mode, metric_params_.app_list_shown);
  204. switch (metric_params_.launched_from) {
  205. case AppListLaunchedFrom::kLaunchedFromGrid:
  206. RecordLauncherWorkflowMetrics(
  207. AppListUserAction::kAppLaunchFromAppsGrid,
  208. metric_params_.is_tablet_mode,
  209. metric_params_.launcher_show_timestamp);
  210. break;
  211. case AppListLaunchedFrom::kLaunchedFromRecentApps:
  212. RecordLauncherWorkflowMetrics(
  213. AppListUserAction::kAppLaunchFromRecentApps,
  214. metric_params_.is_tablet_mode,
  215. metric_params_.launcher_show_timestamp);
  216. break;
  217. case AppListLaunchedFrom::kLaunchedFromSearchBox:
  218. RecordLauncherWorkflowMetrics(AppListUserAction::kOpenAppSearchResult,
  219. metric_params_.is_tablet_mode,
  220. metric_params_.launcher_show_timestamp);
  221. break;
  222. case AppListLaunchedFrom::kLaunchedFromSuggestionChip:
  223. case AppListLaunchedFrom::kLaunchedFromContinueTask:
  224. case AppListLaunchedFrom::kLaunchedFromShelf:
  225. NOTREACHED();
  226. break;
  227. }
  228. break;
  229. }
  230. }
  231. } // namespace ash