Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1665)

Unified Diff: chrome/browser/app_controller_mac.mm

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
Patch Set: rebase & fixed comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/app_controller_mac.mm
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 4aae313ffe21df569dc4fbb8ea3301bc7bc50127..12eb74f9f2f0ea58407e330c41b7bfd6e3de22a1 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,57 @@ 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_);
+ DCHECK(app_controller_);
+ 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];
sail 2013/06/12 21:16:49 It would be more direct to use profile_path to ref
noms (inactive) 2013/06/13 20:56:25 Done.
+ }
+
+ 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_;
@@ -585,6 +635,11 @@ void RecordLastRunAppBundlePath() {
EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile],
encodingMenu);
+ // Instantiate the ProfileInfoCache observer so that we can get
+ // notified when a profile is deleted.
+ 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 +769,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 lastProfile has been deleted, the profile manager has
+ // already loaded a new one, so the pointer needs to be updated;
+ // otherwise we will try to start up a browser window with a pointer
+ // to the old profile.
+ if (profileName == lastProfileName) {
Alexei Svitkine (slow) 2013/06/12 21:02:31 Nit: No {}'s
noms (inactive) 2013/06/13 20:56:25 Done.
+ lastProfile_ = g_browser_process->profile_manager()->GetLastUsedProfile();
+ }
+}
+
// 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
@@ -1097,11 +1167,14 @@ 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 =
Alexei Svitkine (slow) 2013/06/12 21:02:31 Nit: Just return it directly.
noms (inactive) 2013/06/13 20:56:25 Done.
+ g_browser_process->profile_manager()->GetLastUsedProfile();
- return NULL;
+ return lastUsedProfile;
}
// Various methods to open URLs that we get in a native fashion. We use

Powered by Google App Engine
This is Rietveld 408576698