 Chromium Code Reviews
 Chromium Code Reviews Issue 14923004:
  [Mac] AppController needs to update its "last profile" pointer when the active profile is deleted  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 14923004:
  [Mac] AppController needs to update its "last profile" pointer when the active profile is deleted  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 10 matching lines...) Expand all Loading... | |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" | 
| 22 #include "chrome/browser/browser_shutdown.h" | 22 #include "chrome/browser/browser_shutdown.h" | 
| 23 #include "chrome/browser/command_updater.h" | 23 #include "chrome/browser/command_updater.h" | 
| 24 #include "chrome/browser/download/download_service.h" | 24 #include "chrome/browser/download/download_service.h" | 
| 25 #include "chrome/browser/download/download_service_factory.h" | 25 #include "chrome/browser/download/download_service_factory.h" | 
| 26 #include "chrome/browser/extensions/extension_service.h" | 26 #include "chrome/browser/extensions/extension_service.h" | 
| 27 #include "chrome/browser/extensions/extension_system.h" | 27 #include "chrome/browser/extensions/extension_system.h" | 
| 28 #include "chrome/browser/first_run/first_run.h" | 28 #include "chrome/browser/first_run/first_run.h" | 
| 29 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" | 
| 30 #include "chrome/browser/printing/print_dialog_cloud.h" | 30 #include "chrome/browser/printing/print_dialog_cloud.h" | 
| 31 #include "chrome/browser/profiles/profile_info_cache_observer.h" | |
| 31 #include "chrome/browser/profiles/profile_manager.h" | 32 #include "chrome/browser/profiles/profile_manager.h" | 
| 32 #include "chrome/browser/service/service_process_control.h" | 33 #include "chrome/browser/service/service_process_control.h" | 
| 33 #include "chrome/browser/sessions/session_restore.h" | 34 #include "chrome/browser/sessions/session_restore.h" | 
| 34 #include "chrome/browser/sessions/session_service.h" | 35 #include "chrome/browser/sessions/session_service.h" | 
| 35 #include "chrome/browser/sessions/session_service_factory.h" | 36 #include "chrome/browser/sessions/session_service_factory.h" | 
| 36 #include "chrome/browser/sessions/tab_restore_service.h" | 37 #include "chrome/browser/sessions/tab_restore_service.h" | 
| 37 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 38 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 
| 38 #include "chrome/browser/signin/signin_manager.h" | 39 #include "chrome/browser/signin/signin_manager.h" | 
| 39 #include "chrome/browser/signin/signin_manager_factory.h" | 40 #include "chrome/browser/signin/signin_manager_factory.h" | 
| 40 #include "chrome/browser/sync/profile_sync_service.h" | 41 #include "chrome/browser/sync/profile_sync_service.h" | 
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 - (void)openUrls:(const std::vector<GURL>&)urls; | 184 - (void)openUrls:(const std::vector<GURL>&)urls; | 
| 184 - (void)getUrl:(NSAppleEventDescriptor*)event | 185 - (void)getUrl:(NSAppleEventDescriptor*)event | 
| 185 withReply:(NSAppleEventDescriptor*)reply; | 186 withReply:(NSAppleEventDescriptor*)reply; | 
| 186 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; | 187 - (void)submitCloudPrintJob:(NSAppleEventDescriptor*)event; | 
| 187 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 188 - (void)windowLayeringDidChange:(NSNotification*)inNotification; | 
| 188 - (void)windowChangedToProfile:(Profile*)profile; | 189 - (void)windowChangedToProfile:(Profile*)profile; | 
| 189 - (void)checkForAnyKeyWindows; | 190 - (void)checkForAnyKeyWindows; | 
| 190 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 191 - (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; | 
| 191 - (BOOL)shouldQuitWithInProgressDownloads; | 192 - (BOOL)shouldQuitWithInProgressDownloads; | 
| 192 - (void)executeApplication:(id)sender; | 193 - (void)executeApplication:(id)sender; | 
| 194 - (void)profileWasRemoved:(const string16&)profileName; | |
| 193 @end | 195 @end | 
| 194 | 196 | 
| 197 class AppControllerProfileObserver : public ProfileInfoCacheObserver { | |
| 198 public: | |
| 199 AppControllerProfileObserver( | |
| 200 ProfileManager* profile_manager, AppController* app_controller) | |
| 201 : profile_manager_(profile_manager), | |
| 202 app_controller_(app_controller) { | |
| 203 DCHECK(profile_manager_); | |
| 204 profile_manager_->GetProfileInfoCache().AddObserver(this); | |
| 
Alexei Svitkine (slow)
2013/05/08 15:25:06
I don't think you need the DCHECK() if the followi
 
noms (inactive)
2013/05/08 15:56:53
I originally had an if (profile_manager_) check, a
 
Alexei Svitkine (slow)
2013/05/08 16:32:07
Don't have an if check unless there's a scenario w
 | |
| 205 } | |
| 206 | |
| 207 virtual ~AppControllerProfileObserver() { | |
| 208 DCHECK(profile_manager_); | |
| 209 profile_manager_->GetProfileInfoCache().RemoveObserver(this); | |
| 210 } | |
| 211 | |
| 212 private: | |
| 213 ProfileManager* profile_manager_; | |
| 
Alexei Svitkine (slow)
2013/05/08 15:25:06
These should be below the methods.
 
noms (inactive)
2013/05/08 19:10:35
Done.
 | |
| 214 | |
| 215 AppController* app_controller_; // Weak; owns us. | |
| 216 | |
| 217 // ProfileInfoCacheObserver implementation: | |
| 218 | |
| 219 void OnProfileAdded(const base::FilePath& profile_path) { | |
| 
Alexei Svitkine (slow)
2013/05/08 15:25:06
All of these should be marked "virtual" and "OVERR
 
noms (inactive)
2013/05/08 19:10:35
Done.
 | |
| 220 } | |
| 221 | |
| 222 void OnProfileWasRemoved(const base::FilePath& profile_path, | |
| 223 const string16& profile_name) { | |
| 224 // When a profile is deleted we need to notify the AppController, | |
| 225 // so that it can correctly update its pointer to the last used profile. | |
| 226 [app_controller_ profileWasRemoved:profile_name]; | |
| 227 } | |
| 228 | |
| 229 void OnProfileWillBeRemoved(const base::FilePath& profile_path) { | |
| 230 } | |
| 231 | |
| 232 void OnProfileNameChanged(const base::FilePath& profile_path, | |
| 233 const string16& old_profile_name) { | |
| 234 } | |
| 235 | |
| 236 void OnProfileAvatarChanged(const base::FilePath& profile_path) { | |
| 237 } | |
| 238 | |
| 239 DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver); | |
| 240 }; | |
| 241 | |
| 195 @implementation AppController | 242 @implementation AppController | 
| 196 | 243 | 
| 197 @synthesize startupComplete = startupComplete_; | 244 @synthesize startupComplete = startupComplete_; | 
| 198 | 245 | 
| 199 // This method is called very early in application startup (ie, before | 246 // This method is called very early in application startup (ie, before | 
| 200 // the profile is loaded or any preferences have been registered). Defer any | 247 // the profile is loaded or any preferences have been registered). Defer any | 
| 201 // user-data initialization until -applicationDidFinishLaunching:. | 248 // user-data initialization until -applicationDidFinishLaunching:. | 
| 202 - (void)awakeFromNib { | 249 - (void)awakeFromNib { | 
| 203 // We need to register the handlers early to catch events fired on launch. | 250 // We need to register the handlers early to catch events fired on launch. | 
| 204 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 251 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; | 
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 // Build up the encoding menu, the order of the items differs based on the | 625 // Build up the encoding menu, the order of the items differs based on the | 
| 579 // current locale (see http://crbug.com/7647 for details). | 626 // current locale (see http://crbug.com/7647 for details). | 
| 580 // We need a valid g_browser_process to get the profile which is why we can't | 627 // We need a valid g_browser_process to get the profile which is why we can't | 
| 581 // call this from awakeFromNib. | 628 // call this from awakeFromNib. | 
| 582 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; | 629 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; | 
| 583 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; | 630 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; | 
| 584 NSMenu* encodingMenu = [encodingMenuItem submenu]; | 631 NSMenu* encodingMenu = [encodingMenuItem submenu]; | 
| 585 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], | 632 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], | 
| 586 encodingMenu); | 633 encodingMenu); | 
| 587 | 634 | 
| 635 // Instantiate the ProfileInfoCache observer so that we can get | |
| 636 // notified when a profile is deleted. | |
| 637 profileInfoCacheObserver_.reset(new AppControllerProfileObserver( | |
| 638 g_browser_process->profile_manager(), self)); | |
| 639 | |
| 588 // Since Chrome is localized to more languages than the OS, tell Cocoa which | 640 // Since Chrome is localized to more languages than the OS, tell Cocoa which | 
| 589 // menu is the Help so it can add the search item to it. | 641 // menu is the Help so it can add the search item to it. | 
| 590 [NSApp setHelpMenu:helpMenu_]; | 642 [NSApp setHelpMenu:helpMenu_]; | 
| 591 | 643 | 
| 592 // Record the path to the (browser) app bundle; this is used by the app mode | 644 // Record the path to the (browser) app bundle; this is used by the app mode | 
| 593 // shim. | 645 // shim. | 
| 594 RecordLastRunAppBundlePath(); | 646 RecordLastRunAppBundlePath(); | 
| 595 | 647 | 
| 596 // Makes "Services" menu items available. | 648 // Makes "Services" menu items available. | 
| 597 [self registerServicesMenuTypesTo:[notify object]]; | 649 [self registerServicesMenuTypesTo:[notify object]]; | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 | 759 | 
| 708 // Called to determine if we should enable the "restore tab" menu item. | 760 // Called to determine if we should enable the "restore tab" menu item. | 
| 709 // Checks with the TabRestoreService to see if there's anything there to | 761 // Checks with the TabRestoreService to see if there's anything there to | 
| 710 // restore and returns YES if so. | 762 // restore and returns YES if so. | 
| 711 - (BOOL)canRestoreTab { | 763 - (BOOL)canRestoreTab { | 
| 712 TabRestoreService* service = | 764 TabRestoreService* service = | 
| 713 TabRestoreServiceFactory::GetForProfile([self lastProfile]); | 765 TabRestoreServiceFactory::GetForProfile([self lastProfile]); | 
| 714 return service && !service->entries().empty(); | 766 return service && !service->entries().empty(); | 
| 715 } | 767 } | 
| 716 | 768 | 
| 769 // Called from the AppControllerProfileObserver every time a profile is deleted. | |
| 770 - (void)profileWasRemoved:(const string16&)profileName { | |
| 771 Profile* lastProfile = [self lastProfile]; | |
| 772 string16 lastProfileName = UTF8ToUTF16(lastProfile->GetPrefs()->GetString( | |
| 773 prefs::kProfileName)); | |
| 774 | |
| 775 // If the last profile has been deleted, we must NULL out our pointer | |
| 776 // otherwise we will try to start up a browser window with a pointer | |
| 777 // to the old profile. | |
| 778 if (profileName == lastProfileName) | |
| 779 lastProfile_ = NULL; | |
| 780 } | |
| 781 | |
| 717 // Returns true if there is a modal window (either window- or application- | 782 // Returns true if there is a modal window (either window- or application- | 
| 718 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth | 783 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth | 
| 719 // sheets) will not count as blocking the browser. But things like open/save | 784 // sheets) will not count as blocking the browser. But things like open/save | 
| 720 // dialogs that are window modal will block the browser. | 785 // dialogs that are window modal will block the browser. | 
| 721 - (BOOL)keyWindowIsModal { | 786 - (BOOL)keyWindowIsModal { | 
| 722 if ([NSApp modalWindow]) | 787 if ([NSApp modalWindow]) | 
| 723 return YES; | 788 return YES; | 
| 724 | 789 | 
| 725 Browser* browser = chrome::GetLastActiveBrowser(); | 790 Browser* browser = chrome::GetLastActiveBrowser(); | 
| 726 return browser && | 791 return browser && | 
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1316 | 1381 | 
| 1317 //--------------------------------------------------------------------------- | 1382 //--------------------------------------------------------------------------- | 
| 1318 | 1383 | 
| 1319 namespace app_controller_mac { | 1384 namespace app_controller_mac { | 
| 1320 | 1385 | 
| 1321 bool IsOpeningNewWindow() { | 1386 bool IsOpeningNewWindow() { | 
| 1322 return g_is_opening_new_window; | 1387 return g_is_opening_new_window; | 
| 1323 } | 1388 } | 
| 1324 | 1389 | 
| 1325 } // namespace app_controller_mac | 1390 } // namespace app_controller_mac | 
| OLD | NEW |