Index: chrome/browser/app_controller_mac.mm |
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm |
index feb0f95f782cfa782706dee63350095316590490..e72226d010455757d73531d27cfb3f01d8190d69 100644 |
--- a/chrome/browser/app_controller_mac.mm |
+++ b/chrome/browser/app_controller_mac.mm |
@@ -28,6 +28,7 @@ |
#include "chrome/browser/first_run/first_run.h" |
#include "chrome/browser/lifetime/application_lifetime.h" |
#include "chrome/browser/printing/print_dialog_cloud.h" |
+#include "chrome/browser/profiles/profile_info_cache_observer.h" |
#include "chrome/browser/profiles/profile_manager.h" |
#include "chrome/browser/service/service_process_control.h" |
#include "chrome/browser/sessions/session_restore.h" |
@@ -190,8 +191,56 @@ void RecordLastRunAppBundlePath() { |
- (BOOL)userWillWaitForInProgressDownloads:(int)downloadCount; |
- (BOOL)shouldQuitWithInProgressDownloads; |
- (void)executeApplication:(id)sender; |
+- (void)profileWasRemoved:(const string16&)profileName; |
@end |
+class AppControllerProfileObserver : public ProfileInfoCacheObserver { |
+ public: |
+ AppControllerProfileObserver( |
+ ProfileManager* profile_manager, AppController* app_controller) |
+ : profile_manager_(profile_manager), |
+ app_controller_(app_controller) { |
+ DCHECK(profile_manager_); |
Roger Tawa OOO till Jul 10th
2013/05/14 14:38:40
Add dcheck for app_controller_ too? From code seem
noms (inactive)
2013/05/14 15:06:48
Done.
|
+ profile_manager_->GetProfileInfoCache().AddObserver(this); |
+ } |
+ |
+ virtual ~AppControllerProfileObserver() { |
+ DCHECK(profile_manager_); |
+ profile_manager_->GetProfileInfoCache().RemoveObserver(this); |
+ } |
+ |
+ private: |
+ // ProfileInfoCacheObserver implementation: |
+ |
+ virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE { |
+ } |
+ |
+ virtual void OnProfileWasRemoved(const base::FilePath& profile_path, |
+ const string16& profile_name) OVERRIDE { |
+ // When a profile is deleted we need to notify the AppController, |
+ // so that it can correctly update its pointer to the last used profile. |
+ [app_controller_ profileWasRemoved:profile_name]; |
+ } |
+ |
+ virtual void OnProfileWillBeRemoved( |
+ const base::FilePath& profile_path) OVERRIDE { |
+ } |
+ |
+ virtual void OnProfileNameChanged(const base::FilePath& profile_path, |
+ const string16& old_profile_name) OVERRIDE { |
+ } |
+ |
+ virtual void OnProfileAvatarChanged( |
+ const base::FilePath& profile_path) OVERRIDE { |
+ } |
+ |
+ ProfileManager* profile_manager_; |
+ |
+ AppController* app_controller_; // Weak; owns us. |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver); |
+}; |
+ |
@implementation AppController |
@synthesize startupComplete = startupComplete_; |
@@ -505,7 +554,7 @@ void RecordLastRunAppBundlePath() { |
// no-op if the new profile is the same as the current one. This will always be |
// the original profile and never incognito. |
- (void)windowChangedToProfile:(Profile*)profile { |
- if (lastProfile_ == profile) |
+ if (lastProfile_ == profile && !lastProfileWasDeleted) |
return; |
// Before tearing down the menu controller bridges, return the Cocoa menus to |
@@ -518,6 +567,9 @@ void RecordLastRunAppBundlePath() { |
// Rebuild the menus with the new profile. |
lastProfile_ = profile; |
+ if (lastProfileWasDeleted) |
+ lastProfileWasDeleted = NO; |
Roger Tawa OOO till Jul 10th
2013/05/14 14:38:40
Is there a ctor where this is initialized?
noms (inactive)
2013/05/14 14:49:38
There is no constructor per se, but this is initia
|
+ |
bookmarkMenuBridge_.reset(new BookmarkMenuBridge(lastProfile_, |
[[[NSApp mainMenu] itemWithTag:IDC_BOOKMARKS_MENU] submenu])); |
// No need to |BuildMenu| here. It is done lazily upon menu access. |
@@ -585,6 +637,12 @@ void RecordLastRunAppBundlePath() { |
EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], |
encodingMenu); |
+ // Instantiate the ProfileInfoCache observer so that we can get |
+ // notified when a profile is deleted. |
+ lastProfileWasDeleted = NO; |
+ profileInfoCacheObserver_.reset(new AppControllerProfileObserver( |
+ g_browser_process->profile_manager(), self)); |
+ |
// Since Chrome is localized to more languages than the OS, tell Cocoa which |
// menu is the Help so it can add the search item to it. |
[NSApp setHelpMenu:helpMenu_]; |
@@ -714,6 +772,21 @@ void RecordLastRunAppBundlePath() { |
return service && !service->entries().empty(); |
} |
+// Called from the AppControllerProfileObserver every time a profile is deleted. |
+- (void)profileWasRemoved:(const string16&)profileName { |
+ Profile* lastProfile = [self lastProfile]; |
+ string16 lastProfileName = UTF8ToUTF16(lastProfile->GetPrefs()->GetString( |
+ prefs::kProfileName)); |
+ |
+ // If the last profile has been deleted, we must NULL out our pointer |
+ // otherwise we will try to start up a browser window with a pointer |
+ // to the old profile. |
+ if (profileName == lastProfileName) { |
+ lastProfileWasDeleted = YES; |
+ lastProfile_ = NULL; |
+ } |
+} |
+ |
// Returns true if there is a modal window (either window- or application- |
// modal) blocking the active browser. Note that tab modal dialogs (HTTP auth |
// sheets) will not count as blocking the browser. But things like open/save |
@@ -1091,11 +1164,22 @@ void RecordLastRunAppBundlePath() { |
if (lastProfile_) |
return lastProfile_; |
+ if (!g_browser_process->profile_manager()) |
+ return NULL; |
+ |
// On first launch, no profile will be stored, so use last from Local State. |
- if (g_browser_process->profile_manager()) |
- return g_browser_process->profile_manager()->GetLastUsedProfile(); |
+ Profile* lastUsedProfile = |
+ g_browser_process->profile_manager()->GetLastUsedProfile(); |
+ |
+ // If the last profile was deleted, we've already loaded the next active one, |
+ // so we should update the pointer; otherwise we will try to open the old one. |
+ // We unset lastProfileWasDeleted when the window is actually loaded, so that |
+ // all the profile preferences/menus are re-created. |
+ if (lastProfileWasDeleted) { |
+ lastProfile_ = lastUsedProfile; |
+ } |
Roger Tawa OOO till Jul 10th
2013/05/14 14:38:40
Don't need { and }.
noms (inactive)
2013/05/14 15:06:48
Done.
|
- return NULL; |
+ return lastUsedProfile; |
} |
// Various methods to open URLs that we get in a native fashion. We use |