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

Side by Side Diff: ash/common/shelf/shelf_application_menu_model.cc

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Fix tests; cleanup. 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 2017 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 "ash/common/shelf/shelf_application_menu_model.h"
6
7 #include <stddef.h>
8
9 #include <utility>
10
11 #include "ash/public/cpp/shelf_application_menu_item.h"
12 #include "base/metrics/histogram_macros.h"
13
14 namespace {
15
16 const int kInvalidCommandId = std::numeric_limits<int>::max();
James Cook 2017/02/06 17:30:21 nit: #include <limits> or use -1
msw 2017/02/07 09:12:00 I included <limits>, negative values sadly doesn't
James Cook 2017/02/07 16:32:24 Acknowledged.
17
18 const char kNumItemsEnabledHistogramName[] =
19 "Ash.Shelf.Menu.NumItemsEnabledUponSelection";
James Cook 2017/02/06 17:30:21 I would just inline these histogram names below.
msw 2017/02/07 09:12:00 Done.
20
21 const char kSelectedMenuItemIndexHistogramName[] =
22 "Ash.Shelf.Menu.SelectedMenuItemIndex";
23
24 } // namespace
25
26 namespace ash {
27
28 ShelfApplicationMenuModel::ShelfApplicationMenuModel(
29 const base::string16& title,
30 ShelfApplicationMenuItems items)
31 : ui::SimpleMenuModel(this), items_(std::move(items)) {
32 AddSeparator(ui::SPACING_SEPARATOR);
James Cook 2017/02/06 17:30:21 Do we want this if items_ is empty? In the old cod
msw 2017/02/07 09:12:00 Hmm, there are tests for application menus without
James Cook 2017/02/07 16:32:24 I would just add a comment somewhere in here that
msw 2017/02/07 18:19:15 Done.
33 AddItem(kInvalidCommandId, title);
34 AddSeparator(ui::SPACING_SEPARATOR);
35
36 for (size_t i = 0; i < items_.size(); i++) {
37 ShelfApplicationMenuItem* item = items_[i].get();
38 AddItem(i, item->title());
39 if (!item->icon().IsEmpty())
40 SetIcon(GetIndexOfCommandId(i), item->icon());
41 }
42
43 if (!items_.empty())
44 AddSeparator(ui::SPACING_SEPARATOR);
45 }
46
47 ShelfApplicationMenuModel::~ShelfApplicationMenuModel() {}
48
49 bool ShelfApplicationMenuModel::IsCommandIdChecked(int command_id) const {
50 return false;
51 }
52
53 bool ShelfApplicationMenuModel::IsCommandIdEnabled(int command_id) const {
54 return command_id >= 0 && static_cast<size_t>(command_id) < items_.size();
James Cook 2017/02/06 17:30:21 optional fyi: size_t{foo} or int{bar} is acceptabl
msw 2017/02/07 09:12:00 Interesting, but I don't see any uses of that cast
55 }
56
57 void ShelfApplicationMenuModel::ExecuteCommand(int command_id,
58 int event_flags) {
59 DCHECK(IsCommandIdEnabled(command_id));
60 items_[command_id]->Execute(event_flags);
61 RecordMenuItemSelectedMetrics(command_id, items_.size());
62 }
63
64 void ShelfApplicationMenuModel::RecordMenuItemSelectedMetrics(
65 int command_id,
66 int num_menu_items_enabled) {
67 UMA_HISTOGRAM_COUNTS_100(kSelectedMenuItemIndexHistogramName, command_id);
68 UMA_HISTOGRAM_COUNTS_100(kNumItemsEnabledHistogramName,
69 num_menu_items_enabled);
70 }
71
72 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698