| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/app_controller_mac.h" | 5 #import "chrome/browser/app_controller_mac.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 // Checks with the TabRestoreService to see if there's anything there to | 886 // Checks with the TabRestoreService to see if there's anything there to |
| 887 // restore and returns YES if so. | 887 // restore and returns YES if so. |
| 888 - (BOOL)canRestoreTab { | 888 - (BOOL)canRestoreTab { |
| 889 TabRestoreService* service = | 889 TabRestoreService* service = |
| 890 TabRestoreServiceFactory::GetForProfile([self lastProfile]); | 890 TabRestoreServiceFactory::GetForProfile([self lastProfile]); |
| 891 return service && !service->entries().empty(); | 891 return service && !service->entries().empty(); |
| 892 } | 892 } |
| 893 | 893 |
| 894 // Called from the AppControllerProfileObserver every time a profile is deleted. | 894 // Called from the AppControllerProfileObserver every time a profile is deleted. |
| 895 - (void)profileWasRemoved:(const base::FilePath&)profilePath { | 895 - (void)profileWasRemoved:(const base::FilePath&)profilePath { |
| 896 Profile* lastProfile = [self lastProfile]; | |
| 897 | |
| 898 // If the lastProfile has been deleted, the profile manager has | 896 // If the lastProfile has been deleted, the profile manager has |
| 899 // already loaded a new one, so the pointer needs to be updated; | 897 // already loaded a new one, so the pointer needs to be updated; |
| 900 // otherwise we will try to start up a browser window with a pointer | 898 // otherwise we will try to start up a browser window with a pointer |
| 901 // to the old profile. | 899 // to the old profile. |
| 902 if (profilePath == lastProfile->GetPath()) | 900 if (lastProfile_ && profilePath == lastProfile_->GetPath()) |
| 903 lastProfile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); | 901 lastProfile_ = g_browser_process->profile_manager()->GetLastUsedProfile(); |
| 904 | 902 |
| 905 Profile* profile = | 903 auto it = profileBookmarkMenuBridgeMap_.find(profilePath); |
| 906 g_browser_process->profile_manager()->GetProfile(profilePath); | |
| 907 auto it = profileBookmarkMenuBridgeMap_.find(profile); | |
| 908 if (it != profileBookmarkMenuBridgeMap_.end()) { | 904 if (it != profileBookmarkMenuBridgeMap_.end()) { |
| 909 delete it->second; | 905 delete it->second; |
| 910 profileBookmarkMenuBridgeMap_.erase(it); | 906 profileBookmarkMenuBridgeMap_.erase(it); |
| 911 } | 907 } |
| 912 } | 908 } |
| 913 | 909 |
| 914 // Returns true if there is a modal window (either window- or application- | 910 // Returns true if there is a modal window (either window- or application- |
| 915 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth | 911 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth |
| 916 // sheets) will not count as blocking the browser. But things like open/save | 912 // sheets) will not count as blocking the browser. But things like open/save |
| 917 // dialogs that are window modal will block the browser. | 913 // dialogs that are window modal will block the browser. |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 return; | 1571 return; |
| 1576 | 1572 |
| 1577 // Before tearing down the menu controller bridges, return the history menu to | 1573 // Before tearing down the menu controller bridges, return the history menu to |
| 1578 // its initial state. | 1574 // its initial state. |
| 1579 if (historyMenuBridge_) | 1575 if (historyMenuBridge_) |
| 1580 historyMenuBridge_->ResetMenu(); | 1576 historyMenuBridge_->ResetMenu(); |
| 1581 | 1577 |
| 1582 // Rebuild the menus with the new profile. | 1578 // Rebuild the menus with the new profile. |
| 1583 lastProfile_ = profile; | 1579 lastProfile_ = profile; |
| 1584 | 1580 |
| 1585 auto it = profileBookmarkMenuBridgeMap_.find(profile); | 1581 auto it = profileBookmarkMenuBridgeMap_.find(profile->GetPath()); |
| 1586 if (it == profileBookmarkMenuBridgeMap_.end()) { | 1582 if (it == profileBookmarkMenuBridgeMap_.end()) { |
| 1587 base::scoped_nsobject<NSMenu> submenu( | 1583 base::scoped_nsobject<NSMenu> submenu( |
| 1588 [[[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu] copy]); | 1584 [[[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu] copy]); |
| 1589 bookmarkMenuBridge_ = new BookmarkMenuBridge(lastProfile_, submenu); | 1585 bookmarkMenuBridge_ = new BookmarkMenuBridge(profile, submenu); |
| 1590 profileBookmarkMenuBridgeMap_[profile] = bookmarkMenuBridge_; | 1586 profileBookmarkMenuBridgeMap_[profile->GetPath()] = bookmarkMenuBridge_; |
| 1591 } else { | 1587 } else { |
| 1592 bookmarkMenuBridge_ = it->second; | 1588 bookmarkMenuBridge_ = it->second; |
| 1593 } | 1589 } |
| 1594 | 1590 |
| 1595 [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] setSubmenu: | 1591 [[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] setSubmenu: |
| 1596 bookmarkMenuBridge_->BookmarkMenu()]; | 1592 bookmarkMenuBridge_->BookmarkMenu()]; |
| 1597 // No need to |BuildMenu| here. It is done lazily upon menu access. | 1593 // No need to |BuildMenu| here. It is done lazily upon menu access. |
| 1598 | 1594 |
| 1599 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); | 1595 historyMenuBridge_.reset(new HistoryMenuBridge(lastProfile_)); |
| 1600 historyMenuBridge_->BuildMenu(); | 1596 historyMenuBridge_->BuildMenu(); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 | 1707 |
| 1712 //--------------------------------------------------------------------------- | 1708 //--------------------------------------------------------------------------- |
| 1713 | 1709 |
| 1714 namespace app_controller_mac { | 1710 namespace app_controller_mac { |
| 1715 | 1711 |
| 1716 bool IsOpeningNewWindow() { | 1712 bool IsOpeningNewWindow() { |
| 1717 return g_is_opening_new_window; | 1713 return g_is_opening_new_window; |
| 1718 } | 1714 } |
| 1719 | 1715 |
| 1720 } // namespace app_controller_mac | 1716 } // namespace app_controller_mac |
| OLD | NEW |