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

Unified Diff: chrome/browser/ui/cocoa/profiles/profile_menu_controller.mm

Issue 1054113004: Fix crash in ProfileMenuController::validateMenuItem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review feedback Created 5 years, 8 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 | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/profiles/profile_menu_controller.mm
diff --git a/chrome/browser/ui/cocoa/profiles/profile_menu_controller.mm b/chrome/browser/ui/cocoa/profiles/profile_menu_controller.mm
index 437bed15fe87fef70434fae95bd5058c3048dc8a..69af96ecebeb898fafc6f05dd064809d77924f7f 100644
--- a/chrome/browser/ui/cocoa/profiles/profile_menu_controller.mm
+++ b/chrome/browser/ui/cocoa/profiles/profile_menu_controller.mm
@@ -5,6 +5,7 @@
#import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h"
#include "base/mac/scoped_nsobject.h"
+#include "base/metrics/histogram_macros.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/avatar_menu.h"
@@ -25,6 +26,18 @@
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/gfx/image/image.h"
+namespace {
+// Used in UMA histogram macros, shouldn't be reordered or renumbered
+enum ValidateMenuItemSelector {
+ UNKNOWN_SELECTOR = 0,
+ NEW_PROFILE,
+ EDIT_PROFILE,
+ SWITCH_PROFILE_MENU,
+ SWITCH_PROFILE_DOCK,
+ MAX_VALIDATE_MENU_SELECTOR,
+};
+}
Alexei Svitkine (slow) 2015/04/23 15:02:54 Nit: // namespace Also, put empty lines around th
anthonyvd 2015/04/23 19:04:57 Done.
+
@interface ProfileMenuController (Private)
- (void)initializeMenu;
@end
@@ -169,8 +182,31 @@ class Observer : public chrome::BrowserListObserver,
[menuItem action] != @selector(editProfile:);
}
- const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt(
- avatarMenu_->GetActiveProfileIndex());
+ size_t index = avatarMenu_->GetActiveProfileIndex();
+ if (avatarMenu_->GetNumberOfItems() <= index) {
+ ValidateMenuItemSelector current_selector = UNKNOWN_SELECTOR;
Alexei Svitkine (slow) 2015/04/23 15:02:54 Use camelCase.
anthonyvd 2015/04/23 19:04:57 Done.
+ if ([menuItem action] == @selector(newProfile:))
+ current_selector = NEW_PROFILE;
+ else if ([menuItem action] == @selector(editProfile:))
+ current_selector = EDIT_PROFILE;
+ else if ([menuItem action] == @selector(switchToProfileFromMenu:))
+ current_selector = SWITCH_PROFILE_MENU;
+ else if ([menuItem action] == @selector(switchToProfileFromDock:))
+ current_selector = SWITCH_PROFILE_DOCK;
+ UMA_HISTOGRAM_BOOLEAN("Profile.ValidateMenuItemInvalidIndex.IsGuest",
+ activeProfile->IsGuestSession());
+ UMA_HISTOGRAM_CUSTOM_COUNTS(
+ "Profile.ValidateMenuItemInvalidIndex.ProfileCount",
+ avatarMenu_->GetNumberOfItems(),
+ 1, 20, 20);
+ UMA_HISTOGRAM_ENUMERATION("Profile.ValidateMenuItemInvalidIndex.Selector",
+ current_selector,
+ MAX_VALIDATE_MENU_SELECTOR);
+
+ return NO;
+ }
+
+ const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt(index);
if ([menuItem action] == @selector(switchToProfileFromDock:) ||
[menuItem action] == @selector(switchToProfileFromMenu:)) {
if (!itemData.legacy_supervised)
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698