app_list_menu_model_adapter.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef ASH_APP_LIST_VIEWS_APP_LIST_MENU_MODEL_ADAPTER_H_
  5. #define ASH_APP_LIST_VIEWS_APP_LIST_MENU_MODEL_ADAPTER_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "ash/app_list/app_list_metrics.h"
  10. #include "ash/app_menu/app_menu_model_adapter.h"
  11. #include "ash/ash_export.h"
  12. #include "ui/base/models/simple_menu_model.h"
  13. #include "ui/base/ui_base_types.h"
  14. #include "ui/views/controls/menu/menu_types.h"
  15. namespace ash {
  16. // A class wrapping menu operations for apps in AppListView. Responsible for
  17. // building, running, and recording histograms.
  18. class ASH_EXPORT AppListMenuModelAdapter : public AppMenuModelAdapter {
  19. public:
  20. // The kinds of apps which show menus. This enum is used to record
  21. // metrics, if a new value is added make sure to modify
  22. // RecordHistogramOnMenuClosed().
  23. enum AppListViewAppType {
  24. FULLSCREEN_SEARCH_RESULT = 0,
  25. FULLSCREEN_SUGGESTED = 1,
  26. FULLSCREEN_APP_GRID = 2,
  27. PEEKING_SUGGESTED = 3,
  28. HALF_SEARCH_RESULT = 4,
  29. // Usage removed.
  30. // SEARCH_RESULT = 5,
  31. PRODUCTIVITY_LAUNCHER_RECENT_APP = 6,
  32. PRODUCTIVITY_LAUNCHER_APP_GRID = 7,
  33. APP_LIST_APP_TYPE_LAST = 8
  34. };
  35. AppListMenuModelAdapter(const std::string& app_id,
  36. std::unique_ptr<ui::SimpleMenuModel> menu_model,
  37. views::Widget* widget_owner,
  38. ui::MenuSourceType source_type,
  39. const AppLaunchedMetricParams& metric_params,
  40. AppListViewAppType type,
  41. base::OnceClosure on_menu_closed_callback,
  42. bool is_tablet_mode);
  43. AppListMenuModelAdapter(const AppListMenuModelAdapter&) = delete;
  44. AppListMenuModelAdapter& operator=(const AppListMenuModelAdapter&) = delete;
  45. ~AppListMenuModelAdapter() override;
  46. // Overridden from AppMenuModelAdapter:
  47. void RecordHistogramOnMenuClosed() override;
  48. // Overridden from views::MenuModelAdapter:
  49. bool IsCommandEnabled(int id) const override;
  50. void ExecuteCommand(int id, int mouse_event_flags) override;
  51. private:
  52. // Calls RecordAppListAppLaunched() to record app launch related metrics if
  53. // conditions are met.
  54. void MaybeRecordAppLaunched(int command_id);
  55. const AppLaunchedMetricParams metric_params_;
  56. // The type of app which is using this object to show a menu.
  57. const AppListViewAppType type_;
  58. };
  59. } // namespace ash
  60. #endif // ASH_APP_LIST_VIEWS_APP_LIST_MENU_MODEL_ADAPTER_H_