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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/profile_menu_controller.h"
6 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
8 #include "base/metrics/histogram_macros.h"
8 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/avatar_menu.h" 11 #include "chrome/browser/profiles/avatar_menu.h"
11 #include "chrome/browser/profiles/avatar_menu_observer.h" 12 #include "chrome/browser/profiles/avatar_menu_observer.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 14 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
14 #include "chrome/browser/profiles/profile_info_cache.h" 15 #include "chrome/browser/profiles/profile_info_cache.h"
15 #include "chrome/browser/profiles/profile_info_interface.h" 16 #include "chrome/browser/profiles/profile_info_interface.h"
16 #include "chrome/browser/profiles/profile_manager.h" 17 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/profiles/profile_metrics.h" 18 #include "chrome/browser/profiles/profile_metrics.h"
18 #include "chrome/browser/profiles/profile_window.h" 19 #include "chrome/browser/profiles/profile_window.h"
19 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 21 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/browser_list_observer.h" 22 #include "chrome/browser/ui/browser_list_observer.h"
22 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 23 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
23 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
24 #include "components/signin/core/common/profile_management_switches.h" 25 #include "components/signin/core/common/profile_management_switches.h"
25 #include "ui/base/l10n/l10n_util_mac.h" 26 #include "ui/base/l10n/l10n_util_mac.h"
26 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
27 28
29 namespace {
30 // Used in UMA histogram macros, shouldn't be reordered or renumbered
31 enum ValidateMenuItemSelector {
32 UNKNOWN_SELECTOR = 0,
33 NEW_PROFILE,
34 EDIT_PROFILE,
35 SWITCH_PROFILE_MENU,
36 SWITCH_PROFILE_DOCK,
37 MAX_VALIDATE_MENU_SELECTOR,
38 };
39 }
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.
40
28 @interface ProfileMenuController (Private) 41 @interface ProfileMenuController (Private)
29 - (void)initializeMenu; 42 - (void)initializeMenu;
30 @end 43 @end
31 44
32 namespace ProfileMenuControllerInternal { 45 namespace ProfileMenuControllerInternal {
33 46
34 class Observer : public chrome::BrowserListObserver, 47 class Observer : public chrome::BrowserListObserver,
35 public AvatarMenuObserver { 48 public AvatarMenuObserver {
36 public: 49 public:
37 Observer(ProfileMenuController* controller) : controller_(controller) { 50 Observer(ProfileMenuController* controller) : controller_(controller) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 175
163 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { 176 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
164 // In guest mode, chrome://settings isn't available, so disallow creating 177 // In guest mode, chrome://settings isn't available, so disallow creating
165 // or editing a profile. 178 // or editing a profile.
166 Profile* activeProfile = ProfileManager::GetLastUsedProfile(); 179 Profile* activeProfile = ProfileManager::GetLastUsedProfile();
167 if (activeProfile->IsGuestSession()) { 180 if (activeProfile->IsGuestSession()) {
168 return [menuItem action] != @selector(newProfile:) && 181 return [menuItem action] != @selector(newProfile:) &&
169 [menuItem action] != @selector(editProfile:); 182 [menuItem action] != @selector(editProfile:);
170 } 183 }
171 184
172 const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt( 185 size_t index = avatarMenu_->GetActiveProfileIndex();
173 avatarMenu_->GetActiveProfileIndex()); 186 if (avatarMenu_->GetNumberOfItems() <= index) {
187 ValidateMenuItemSelector current_selector = UNKNOWN_SELECTOR;
Alexei Svitkine (slow) 2015/04/23 15:02:54 Use camelCase.
anthonyvd 2015/04/23 19:04:57 Done.
188 if ([menuItem action] == @selector(newProfile:))
189 current_selector = NEW_PROFILE;
190 else if ([menuItem action] == @selector(editProfile:))
191 current_selector = EDIT_PROFILE;
192 else if ([menuItem action] == @selector(switchToProfileFromMenu:))
193 current_selector = SWITCH_PROFILE_MENU;
194 else if ([menuItem action] == @selector(switchToProfileFromDock:))
195 current_selector = SWITCH_PROFILE_DOCK;
196 UMA_HISTOGRAM_BOOLEAN("Profile.ValidateMenuItemInvalidIndex.IsGuest",
197 activeProfile->IsGuestSession());
198 UMA_HISTOGRAM_CUSTOM_COUNTS(
199 "Profile.ValidateMenuItemInvalidIndex.ProfileCount",
200 avatarMenu_->GetNumberOfItems(),
201 1, 20, 20);
202 UMA_HISTOGRAM_ENUMERATION("Profile.ValidateMenuItemInvalidIndex.Selector",
203 current_selector,
204 MAX_VALIDATE_MENU_SELECTOR);
205
206 return NO;
207 }
208
209 const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt(index);
174 if ([menuItem action] == @selector(switchToProfileFromDock:) || 210 if ([menuItem action] == @selector(switchToProfileFromDock:) ||
175 [menuItem action] == @selector(switchToProfileFromMenu:)) { 211 [menuItem action] == @selector(switchToProfileFromMenu:)) {
176 if (!itemData.legacy_supervised) 212 if (!itemData.legacy_supervised)
177 return YES; 213 return YES;
178 214
179 return [menuItem tag] == static_cast<NSInteger>(itemData.menu_index); 215 return [menuItem tag] == static_cast<NSInteger>(itemData.menu_index);
180 } 216 }
181 217
182 if ([menuItem action] == @selector(newProfile:)) 218 if ([menuItem action] == @selector(newProfile:))
183 return !itemData.legacy_supervised; 219 return !itemData.legacy_supervised;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 299 }
264 300
265 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { 301 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel {
266 base::scoped_nsobject<NSMenuItem> item( 302 base::scoped_nsobject<NSMenuItem> item(
267 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); 303 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]);
268 [item setTarget:self]; 304 [item setTarget:self];
269 return [item.release() autorelease]; 305 return [item.release() autorelease];
270 } 306 }
271 307
272 @end 308 @end
OLDNEW
« 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