Index: chrome/browser/app_controller_mac.mm |
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm |
index 137a0605b44a98a3251cb5844cc57e5e4fcc572e..b8ffff86cbe91867096ade06e6a3d07720eb7da3 100644 |
--- a/chrome/browser/app_controller_mac.mm |
+++ b/chrome/browser/app_controller_mac.mm |
@@ -1580,22 +1580,31 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
if (historyMenuBridge_) |
historyMenuBridge_->ResetMenu(); |
- // Rebuild the menus with the new profile. |
+ // Rebuild the menus with the new profile. The bookmarks submenu is cached to |
+ // avoid slowdowns when switching between profiles with large numbers of |
+ // bookmarks. Before caching, store whether it is hidden, make the menu item |
+ // visible, and restore its original hidden state after resetting the submenu. |
+ // This works around an apparent AppKit bug where setting a *different* NSMenu |
+ // submenu on a *hidden* menu item forces the item to become visible. |
+ // See http://crbug/497813 for more details. |
Robert Sesek
2015/09/04 17:33:06
nit: https://crbug.com is the proper hostname to u
dominickn
2015/09/05 00:34:02
Done.
|
+ NSMenuItem* item = [[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU]; |
Robert Sesek
2015/09/04 17:33:06
naming: item is a bit vague. bookmarkItem is bette
dominickn
2015/09/05 00:34:02
Done.
|
+ BOOL hidden = [item isHidden]; |
+ [item setHidden:NO]; |
lastProfile_ = profile; |
auto it = profileBookmarkMenuBridgeMap_.find(profile->GetPath()); |
if (it == profileBookmarkMenuBridgeMap_.end()) { |
- base::scoped_nsobject<NSMenu> submenu( |
- [[[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu] copy]); |
+ base::scoped_nsobject<NSMenu> submenu([[item submenu] copy]); |
bookmarkMenuBridge_ = new BookmarkMenuBridge(profile, submenu); |
profileBookmarkMenuBridgeMap_[profile->GetPath()] = bookmarkMenuBridge_; |
} else { |
bookmarkMenuBridge_ = it->second; |
} |
- [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] setSubmenu: |
- bookmarkMenuBridge_->BookmarkMenu()]; |
// No need to |BuildMenu| here. It is done lazily upon menu access. |
+ [item setSubmenu:bookmarkMenuBridge_->BookmarkMenu()]; |
+ // Reset the hidden state to the previously saved value. |
Robert Sesek
2015/09/04 17:33:06
Remove this comment, since it's obvious from the c
dominickn
2015/09/05 00:34:02
Done.
|
+ [item setHidden:hidden]; |
historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); |
historyMenuBridge_->BuildMenu(); |