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.
5 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
7 #include "base/metrics/histogram_macros.h"
8 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
12 const char kNumItemsEnabledHistogramName
[] =
13 "Ash.Shelf.Menu.NumItemsEnabledUponSelection";
15 const char kSelectedMenuItemIndexHistogramName
[] =
16 "Ash.Shelf.Menu.SelectedMenuItemIndex";
20 LauncherApplicationMenuItemModel::LauncherApplicationMenuItemModel(
21 ChromeLauncherAppMenuItems item_list
)
22 : ash::ShelfMenuModel(this),
23 launcher_items_(item_list
.Pass()) {
27 LauncherApplicationMenuItemModel::~LauncherApplicationMenuItemModel() {
30 bool LauncherApplicationMenuItemModel::IsCommandActive(int command_id
) const {
31 DCHECK(command_id
>= 0);
32 DCHECK(static_cast<size_t>(command_id
) < launcher_items_
.size());
33 return launcher_items_
[command_id
]->IsActive();
36 bool LauncherApplicationMenuItemModel::IsCommandIdChecked(
37 int command_id
) const {
41 bool LauncherApplicationMenuItemModel::IsCommandIdEnabled(
42 int command_id
) const {
43 DCHECK(command_id
< static_cast<int>(launcher_items_
.size()));
44 return launcher_items_
[command_id
]->IsEnabled();
47 bool LauncherApplicationMenuItemModel::GetAcceleratorForCommandId(
49 ui::Accelerator
* accelerator
) {
53 void LauncherApplicationMenuItemModel::ExecuteCommand(int command_id
,
55 DCHECK(command_id
< static_cast<int>(launcher_items_
.size()));
56 launcher_items_
[command_id
]->Execute(event_flags
);
57 RecordMenuItemSelectedMetrics(command_id
, GetNumMenuItemsEnabled());
60 void LauncherApplicationMenuItemModel::Build() {
61 if (launcher_items_
.empty())
64 AddSeparator(ui::SPACING_SEPARATOR
);
65 for (size_t i
= 0; i
< launcher_items_
.size(); i
++) {
66 ChromeLauncherAppMenuItem
* item
= launcher_items_
[i
];
68 // Check for a separator requirement in front of this item.
69 if (item
->HasLeadingSeparator())
70 AddSeparator(ui::SPACING_SEPARATOR
);
72 // The first item is the context menu, the others are the running apps.
73 AddItem(i
, item
->title());
75 if (!item
->icon().IsEmpty())
76 SetIcon(GetIndexOfCommandId(i
), item
->icon());
78 AddSeparator(ui::SPACING_SEPARATOR
);
81 int LauncherApplicationMenuItemModel::GetNumMenuItemsEnabled() const {
82 int num_menu_items_enabled
= 0;
83 for (const ChromeLauncherAppMenuItem
* menu_item
: launcher_items_
) {
84 if (menu_item
->IsEnabled())
85 ++num_menu_items_enabled
;
87 return num_menu_items_enabled
;
90 void LauncherApplicationMenuItemModel::RecordMenuItemSelectedMetrics(
92 int num_menu_items_enabled
) {
93 UMA_HISTOGRAM_COUNTS_100(kSelectedMenuItemIndexHistogramName
, command_id
);
94 UMA_HISTOGRAM_COUNTS_100(kNumItemsEnabledHistogramName
,
95 num_menu_items_enabled
);