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..ee90df6ee1cfe4a513f4dcc3605df5de943db7c6 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. |
+ NSMenuItem* item = [[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU]; |
+ 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. |
+ // Reset the hidden state to the previously saved value. |
jackhou1
2015/09/04 07:39:48
Move this comment between -setSubmenu: and -setHid
dominickn
2015/09/04 07:54:02
Done.
|
+ [item setSubmenu:bookmarkMenuBridge_->BookmarkMenu()]; |
+ [item setHidden:hidden]; |
historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); |
historyMenuBridge_->BuildMenu(); |