Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / ash / launcher / launcher_application_menu_item_model.cc
blob26a4d24ceca7b85ff9a4bba22e91c08af95086bd
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"
10 namespace {
12 const char kNumItemsEnabledHistogramName[] =
13 "Ash.Shelf.Menu.NumItemsEnabledUponSelection";
15 const char kSelectedMenuItemIndexHistogramName[] =
16 "Ash.Shelf.Menu.SelectedMenuItemIndex";
18 } // namespace
20 LauncherApplicationMenuItemModel::LauncherApplicationMenuItemModel(
21 ChromeLauncherAppMenuItems item_list)
22 : ash::ShelfMenuModel(this),
23 launcher_items_(item_list.Pass()) {
24 Build();
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 {
38 return false;
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(
48 int command_id,
49 ui::Accelerator* accelerator) {
50 return false;
53 void LauncherApplicationMenuItemModel::ExecuteCommand(int command_id,
54 int event_flags) {
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())
62 return;
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(
91 int command_id,
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);