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

Unified Diff: ui/base/models/simple_menu_model.cc

Issue 10458045: Cleanup: Remove vector::at() calls in SimpleMenuModel. Do CHECKs instead. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/models/simple_menu_model.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/models/simple_menu_model.cc
===================================================================
--- ui/base/models/simple_menu_model.cc (revision 139648)
+++ ui/base/models/simple_menu_model.cc (working copy)
@@ -185,7 +185,7 @@
}
void SimpleMenuModel::SetIcon(int index, const gfx::ImageSkia& icon) {
- items_[index].icon = icon;
+ items_[ValidateItemIndex(index)].icon = icon;
}
void SimpleMenuModel::Clear() {
@@ -194,7 +194,7 @@
int SimpleMenuModel::GetIndexOfCommandId(int command_id) {
for (ItemVector::iterator i = items_.begin(); i != items_.end(); ++i) {
- if ((*i).command_id == command_id) {
+ if (i->command_id == command_id) {
return FlipIndex(static_cast<int>(std::distance(items_.begin(), i)));
}
}
@@ -218,17 +218,17 @@
}
MenuModel::ItemType SimpleMenuModel::GetTypeAt(int index) const {
- return items_.at(FlipIndex(index)).type;
+ return items_[ValidateItemIndex(FlipIndex(index))].type;
}
int SimpleMenuModel::GetCommandIdAt(int index) const {
- return items_.at(FlipIndex(index)).command_id;
+ return items_[ValidateItemIndex(FlipIndex(index))].command_id;
}
string16 SimpleMenuModel::GetLabelAt(int index) const {
if (IsItemDynamicAt(index))
return delegate_->GetLabelForCommandId(GetCommandIdAt(index));
- return items_.at(FlipIndex(index)).label;
+ return items_[ValidateItemIndex(FlipIndex(index))].label;
}
bool SimpleMenuModel::IsItemDynamicAt(int index) const {
@@ -249,20 +249,20 @@
bool SimpleMenuModel::IsItemCheckedAt(int index) const {
if (!delegate_)
return false;
- int item_index = FlipIndex(index);
- MenuModel::ItemType item_type = items_[item_index].type;
+ MenuModel::ItemType item_type = GetTypeAt(index);
return (item_type == TYPE_CHECK || item_type == TYPE_RADIO) ?
delegate_->IsCommandIdChecked(GetCommandIdAt(index)) : false;
}
int SimpleMenuModel::GetGroupIdAt(int index) const {
- return items_.at(FlipIndex(index)).group_id;
+ return items_[ValidateItemIndex(FlipIndex(index))].group_id;
}
bool SimpleMenuModel::GetIconAt(int index, gfx::ImageSkia* icon) {
if (IsItemDynamicAt(index))
return delegate_->GetIconForCommandId(GetCommandIdAt(index), icon);
+ ValidateItemIndex(index);
if (items_[index].icon.isNull())
return false;
@@ -271,21 +271,19 @@
}
ButtonMenuItemModel* SimpleMenuModel::GetButtonMenuItemAt(int index) const {
- return items_.at(FlipIndex(index)).button_model;
+ return items_[ValidateItemIndex(FlipIndex(index))].button_model;
}
bool SimpleMenuModel::IsEnabledAt(int index) const {
int command_id = GetCommandIdAt(index);
- if (!delegate_ || command_id == kSeparatorId ||
- items_.at(FlipIndex(index)).button_model)
+ if (!delegate_ || command_id == kSeparatorId || GetButtonMenuItemAt(index))
return true;
return delegate_->IsCommandIdEnabled(command_id);
}
bool SimpleMenuModel::IsVisibleAt(int index) const {
int command_id = GetCommandIdAt(index);
- if (!delegate_ || command_id == kSeparatorId ||
- items_.at(FlipIndex(index)).button_model)
+ if (!delegate_ || command_id == kSeparatorId || GetButtonMenuItemAt(index))
return true;
return delegate_->IsCommandIdVisible(command_id);
}
@@ -306,7 +304,7 @@
}
MenuModel* SimpleMenuModel::GetSubmenuModelAt(int index) const {
- return items_.at(FlipIndex(index)).submenu;
+ return items_[ValidateItemIndex(FlipIndex(index))].submenu;
}
void SimpleMenuModel::MenuWillShow() {
@@ -340,6 +338,12 @@
////////////////////////////////////////////////////////////////////////////////
// SimpleMenuModel, Private:
+int SimpleMenuModel::ValidateItemIndex(int index) const {
+ CHECK_GE(index, 0);
+ CHECK_LT(static_cast<size_t>(index), items_.size());
+ return index;
+}
+
void SimpleMenuModel::AppendItem(const Item& item) {
ValidateItem(item);
items_.push_back(item);
« no previous file with comments | « ui/base/models/simple_menu_model.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698