Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.cc

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Add comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
6
7 #include <stddef.h>
8
9 #include <utility>
10
11 #include "base/metrics/histogram_macros.h"
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
13
14 namespace {
15
16 const char kNumItemsEnabledHistogramName[] =
17 "Ash.Shelf.Menu.NumItemsEnabledUponSelection";
18
19 const char kSelectedMenuItemIndexHistogramName[] =
20 "Ash.Shelf.Menu.SelectedMenuItemIndex";
21
22 } // namespace
23
24 LauncherApplicationMenuItemModel::LauncherApplicationMenuItemModel(
25 ChromeLauncherAppMenuItems item_list)
26 : ui::SimpleMenuModel(this), launcher_items_(std::move(item_list)) {
27 Build();
28 }
29
30 LauncherApplicationMenuItemModel::~LauncherApplicationMenuItemModel() {}
31
32 bool LauncherApplicationMenuItemModel::IsCommandIdChecked(
33 int command_id) const {
34 return false;
35 }
36
37 bool LauncherApplicationMenuItemModel::IsCommandIdEnabled(
38 int command_id) const {
39 DCHECK(command_id < static_cast<int>(launcher_items_.size()));
40 return launcher_items_[command_id]->IsEnabled();
41 }
42
43 void LauncherApplicationMenuItemModel::ExecuteCommand(int command_id,
44 int event_flags) {
45 DCHECK(command_id < static_cast<int>(launcher_items_.size()));
46 launcher_items_[command_id]->Execute(event_flags);
47 RecordMenuItemSelectedMetrics(command_id, GetNumMenuItemsEnabled());
48 }
49
50 void LauncherApplicationMenuItemModel::Build() {
51 if (launcher_items_.empty())
52 return;
53
54 AddSeparator(ui::SPACING_SEPARATOR);
55 for (size_t i = 0; i < launcher_items_.size(); i++) {
56 ChromeLauncherAppMenuItem* item = launcher_items_[i].get();
57
58 // Check for a separator requirement in front of this item.
59 if (item->HasLeadingSeparator())
60 AddSeparator(ui::SPACING_SEPARATOR);
61
62 // The first item is the context menu, the others are the running apps.
63 AddItem(i, item->title());
64
65 if (!item->icon().IsEmpty())
66 SetIcon(GetIndexOfCommandId(i), item->icon());
67 }
68 AddSeparator(ui::SPACING_SEPARATOR);
69 }
70
71 int LauncherApplicationMenuItemModel::GetNumMenuItemsEnabled() const {
72 int num_menu_items_enabled = 0;
73 for (const auto& menu_item : launcher_items_) {
74 if (menu_item->IsEnabled())
75 ++num_menu_items_enabled;
76 }
77 return num_menu_items_enabled;
78 }
79
80 void LauncherApplicationMenuItemModel::RecordMenuItemSelectedMetrics(
81 int command_id,
82 int num_menu_items_enabled) {
83 UMA_HISTOGRAM_COUNTS_100(kSelectedMenuItemIndexHistogramName, command_id);
84 UMA_HISTOGRAM_COUNTS_100(kNumItemsEnabledHistogramName,
85 num_menu_items_enabled);
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698