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

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: 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
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 enum ValidateMenuItemSelector {
Alexei Svitkine (slow) 2015/04/22 16:55:25 Don't indent within namespace. Add a comment that
anthonyvd 2015/04/23 14:49:01 Done.
31 UNKNOWN_SELECTOR,
32 NEW_PROFILE,
33 EDIT_PROFILE,
34 SWITCH_PROFILE_MENU,
35 SWITCH_PROFILE_DOCK,
36 MAX_VALIDATE_MENU_SELECTOR,
37 };
38 }
39
28 @interface ProfileMenuController (Private) 40 @interface ProfileMenuController (Private)
29 - (void)initializeMenu; 41 - (void)initializeMenu;
30 @end 42 @end
31 43
32 namespace ProfileMenuControllerInternal { 44 namespace ProfileMenuControllerInternal {
33 45
34 class Observer : public chrome::BrowserListObserver, 46 class Observer : public chrome::BrowserListObserver,
35 public AvatarMenuObserver { 47 public AvatarMenuObserver {
36 public: 48 public:
37 Observer(ProfileMenuController* controller) : controller_(controller) { 49 Observer(ProfileMenuController* controller) : controller_(controller) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 174
163 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { 175 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
164 // In guest mode, chrome://settings isn't available, so disallow creating 176 // In guest mode, chrome://settings isn't available, so disallow creating
165 // or editing a profile. 177 // or editing a profile.
166 Profile* activeProfile = ProfileManager::GetLastUsedProfile(); 178 Profile* activeProfile = ProfileManager::GetLastUsedProfile();
167 if (activeProfile->IsGuestSession()) { 179 if (activeProfile->IsGuestSession()) {
168 return [menuItem action] != @selector(newProfile:) && 180 return [menuItem action] != @selector(newProfile:) &&
169 [menuItem action] != @selector(editProfile:); 181 [menuItem action] != @selector(editProfile:);
170 } 182 }
171 183
172 const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt( 184 size_t index = avatarMenu_->GetActiveProfileIndex();
173 avatarMenu_->GetActiveProfileIndex()); 185 if (avatarMenu_->GetNumberOfItems() <= index) {
186 ValidateMenuItemSelector current_selector = UNKNOWN_SELECTOR;
187 if ([menuItem action] == @selector(newProfile:))
188 current_selector = NEW_PROFILE;
189 else if ([menuItem action] == @selector(editProfile:))
190 current_selector = EDIT_PROFILE;
191 else if ([menuItem action] == @selector(switchToProfileFromMenu:))
192 current_selector = SWITCH_PROFILE_MENU;
193 else if ([menuItem action] == @selector(switchToProfileFromDock:))
194 current_selector = SWITCH_PROFILE_DOCK;
195 UMA_HISTOGRAM_ENUMERATION("ValidateMenuItemInvalidIndexSelector",
Alexei Svitkine (slow) 2015/04/22 16:55:25 Histograms use a dotted naming notation - e.g. Foo
anthonyvd 2015/04/23 14:49:01 Done.
196 current_selector,
197 MAX_VALIDATE_MENU_SELECTOR);
198 UMA_HISTOGRAM_CUSTOM_COUNTS("ValidateMenuItemInvalidIndexProfileCount",
199 avatarMenu_->GetNumberOfItems(),
200 1, 20, 20);
201 UMA_HISTOGRAM_BOOLEAN("ValidateMenuItemInvalidIndexIsGuest",
202 activeProfile->IsGuestSession());
203
204 return NO;
205 }
206
207 const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt(index);
174 if ([menuItem action] == @selector(switchToProfileFromDock:) || 208 if ([menuItem action] == @selector(switchToProfileFromDock:) ||
175 [menuItem action] == @selector(switchToProfileFromMenu:)) { 209 [menuItem action] == @selector(switchToProfileFromMenu:)) {
176 if (!itemData.legacy_supervised) 210 if (!itemData.legacy_supervised)
177 return YES; 211 return YES;
178 212
179 return [menuItem tag] == static_cast<NSInteger>(itemData.menu_index); 213 return [menuItem tag] == static_cast<NSInteger>(itemData.menu_index);
180 } 214 }
181 215
182 if ([menuItem action] == @selector(newProfile:)) 216 if ([menuItem action] == @selector(newProfile:))
183 return !itemData.legacy_supervised; 217 return !itemData.legacy_supervised;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 297 }
264 298
265 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { 299 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel {
266 base::scoped_nsobject<NSMenuItem> item( 300 base::scoped_nsobject<NSMenuItem> item(
267 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); 301 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]);
268 [item setTarget:self]; 302 [item setTarget:self];
269 return [item.release() autorelease]; 303 return [item.release() autorelease];
270 } 304 }
271 305
272 @end 306 @end
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698