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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_menu_controller.mm

Issue 1100763002: Inject CanAddURLToHistory into TopSitesImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prefs
Patch Set: Fix error introduced during rebase Created 5 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 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
31 // Used in UMA histogram macros, shouldn't be reordered or renumbered
32 enum ValidateMenuItemSelector {
33 UNKNOWN_SELECTOR = 0,
34 NEW_PROFILE,
35 EDIT_PROFILE,
36 SWITCH_PROFILE_MENU,
37 SWITCH_PROFILE_DOCK,
38 MAX_VALIDATE_MENU_SELECTOR,
39 };
40
41 } // namespace
42
28 @interface ProfileMenuController (Private) 43 @interface ProfileMenuController (Private)
29 - (void)initializeMenu; 44 - (void)initializeMenu;
30 @end 45 @end
31 46
32 namespace ProfileMenuControllerInternal { 47 namespace ProfileMenuControllerInternal {
33 48
34 class Observer : public chrome::BrowserListObserver, 49 class Observer : public chrome::BrowserListObserver,
35 public AvatarMenuObserver { 50 public AvatarMenuObserver {
36 public: 51 public:
37 Observer(ProfileMenuController* controller) : controller_(controller) { 52 Observer(ProfileMenuController* controller) : controller_(controller) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 177
163 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { 178 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
164 // In guest mode, chrome://settings isn't available, so disallow creating 179 // In guest mode, chrome://settings isn't available, so disallow creating
165 // or editing a profile. 180 // or editing a profile.
166 Profile* activeProfile = ProfileManager::GetLastUsedProfile(); 181 Profile* activeProfile = ProfileManager::GetLastUsedProfile();
167 if (activeProfile->IsGuestSession()) { 182 if (activeProfile->IsGuestSession()) {
168 return [menuItem action] != @selector(newProfile:) && 183 return [menuItem action] != @selector(newProfile:) &&
169 [menuItem action] != @selector(editProfile:); 184 [menuItem action] != @selector(editProfile:);
170 } 185 }
171 186
172 const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt( 187 size_t index = avatarMenu_->GetActiveProfileIndex();
173 avatarMenu_->GetActiveProfileIndex()); 188 if (avatarMenu_->GetNumberOfItems() <= index) {
189 ValidateMenuItemSelector currentSelector = UNKNOWN_SELECTOR;
190 if ([menuItem action] == @selector(newProfile:))
191 currentSelector = NEW_PROFILE;
192 else if ([menuItem action] == @selector(editProfile:))
193 currentSelector = EDIT_PROFILE;
194 else if ([menuItem action] == @selector(switchToProfileFromMenu:))
195 currentSelector = SWITCH_PROFILE_MENU;
196 else if ([menuItem action] == @selector(switchToProfileFromDock:))
197 currentSelector = SWITCH_PROFILE_DOCK;
198 UMA_HISTOGRAM_BOOLEAN("Profile.ValidateMenuItemInvalidIndex.IsGuest",
199 activeProfile->IsGuestSession());
200 UMA_HISTOGRAM_CUSTOM_COUNTS(
201 "Profile.ValidateMenuItemInvalidIndex.ProfileCount",
202 avatarMenu_->GetNumberOfItems(),
203 1, 20, 20);
204 UMA_HISTOGRAM_ENUMERATION("Profile.ValidateMenuItemInvalidIndex.Selector",
205 currentSelector,
206 MAX_VALIDATE_MENU_SELECTOR);
207
208 return NO;
209 }
210
211 const AvatarMenu::Item& itemData = avatarMenu_->GetItemAt(index);
174 if ([menuItem action] == @selector(switchToProfileFromDock:) || 212 if ([menuItem action] == @selector(switchToProfileFromDock:) ||
175 [menuItem action] == @selector(switchToProfileFromMenu:)) { 213 [menuItem action] == @selector(switchToProfileFromMenu:)) {
176 if (!itemData.legacy_supervised) 214 if (!itemData.legacy_supervised)
177 return YES; 215 return YES;
178 216
179 return [menuItem tag] == static_cast<NSInteger>(itemData.menu_index); 217 return [menuItem tag] == static_cast<NSInteger>(itemData.menu_index);
180 } 218 }
181 219
182 if ([menuItem action] == @selector(newProfile:)) 220 if ([menuItem action] == @selector(newProfile:))
183 return !itemData.legacy_supervised; 221 return !itemData.legacy_supervised;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 } 301 }
264 302
265 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { 303 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel {
266 base::scoped_nsobject<NSMenuItem> item( 304 base::scoped_nsobject<NSMenuItem> item(
267 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); 305 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]);
268 [item setTarget:self]; 306 [item setTarget:self];
269 return [item.release() autorelease]; 307 return [item.release() autorelease];
270 } 308 }
271 309
272 @end 310 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698