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

Side by Side 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: Virtual functions should be marked virtual Created 7 years, 7 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/app_controller_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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);
205 }
206
207 virtual ~AppControllerProfileObserver() {
208 DCHECK(profile_manager_);
209 profile_manager_->GetProfileInfoCache().RemoveObserver(this);
210 }
211
212 private:
213 // ProfileInfoCacheObserver implementation:
214
215 virtual void OnProfileAdded(const base::FilePath& profile_path) OVERRIDE {
216 }
217
218 virtual void OnProfileWasRemoved(const base::FilePath& profile_path,
219 const string16& profile_name) OVERRIDE {
220 // When a profile is deleted we need to notify the AppController,
221 // so that it can correctly update its pointer to the last used profile.
222 [app_controller_ profileWasRemoved:profile_name];
223 }
224
225 virtual void OnProfileWillBeRemoved(
226 const base::FilePath& profile_path) OVERRIDE {
227 }
228
229 virtual void OnProfileNameChanged(const base::FilePath& profile_path,
230 const string16& old_profile_name) OVERRIDE {
231 }
232
233 virtual void OnProfileAvatarChanged(
234 const base::FilePath& profile_path) OVERRIDE {
235 }
236
237 ProfileManager* profile_manager_;
238
239 AppController* app_controller_; // Weak; owns us.
240
241 DISALLOW_COPY_AND_ASSIGN(AppControllerProfileObserver);
242 };
243
195 @implementation AppController 244 @implementation AppController
196 245
197 @synthesize startupComplete = startupComplete_; 246 @synthesize startupComplete = startupComplete_;
198 247
199 // This method is called very early in application startup (ie, before 248 // This method is called very early in application startup (ie, before
200 // the profile is loaded or any preferences have been registered). Defer any 249 // the profile is loaded or any preferences have been registered). Defer any
201 // user-data initialization until -applicationDidFinishLaunching:. 250 // user-data initialization until -applicationDidFinishLaunching:.
202 - (void)awakeFromNib { 251 - (void)awakeFromNib {
203 // We need to register the handlers early to catch events fired on launch. 252 // We need to register the handlers early to catch events fired on launch.
204 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager]; 253 NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 526
478 // If the window changed to a new BrowserWindowController, update the profile. 527 // If the window changed to a new BrowserWindowController, update the profile.
479 id windowController = [[notify object] windowController]; 528 id windowController = [[notify object] windowController];
480 if ([notify name] == NSWindowDidBecomeMainNotification && 529 if ([notify name] == NSWindowDidBecomeMainNotification &&
481 [windowController isKindOfClass:[BrowserWindowController class]]) { 530 [windowController isKindOfClass:[BrowserWindowController class]]) {
482 // If the profile is incognito, use the original profile. 531 // If the profile is incognito, use the original profile.
483 Profile* newProfile = [windowController profile]->GetOriginalProfile(); 532 Profile* newProfile = [windowController profile]->GetOriginalProfile();
484 [self windowChangedToProfile:newProfile]; 533 [self windowChangedToProfile:newProfile];
485 } else if (chrome::GetTotalBrowserCount() == 0) { 534 } else if (chrome::GetTotalBrowserCount() == 0) {
486 [self windowChangedToProfile: 535 [self windowChangedToProfile:
487 g_browser_process->profile_manager()->GetLastUsedProfile()]; 536 g_browser_process->profile_manager()->GetLastUsedProfile()];
Alexei Svitkine (slow) 2013/05/08 19:19:11 Wouldn't this still be a problem? i.e. I think cal
noms (inactive) 2013/05/14 03:34:17 And how! However, fixed. On 2013/05/08 19:19:11,
488 } 537 }
489 } 538 }
490 539
491 // Called on Lion and later when a popover (e.g. dictionary) is shown. 540 // Called on Lion and later when a popover (e.g. dictionary) is shown.
492 - (void)popoverDidShow:(NSNotification*)notify { 541 - (void)popoverDidShow:(NSNotification*)notify {
493 hasPopover_ = YES; 542 hasPopover_ = YES;
494 [self fixCloseMenuItemKeyEquivalents]; 543 [self fixCloseMenuItemKeyEquivalents];
495 } 544 }
496 545
497 // Called on Lion and later when a popover (e.g. dictionary) is closed. 546 // Called on Lion and later when a popover (e.g. dictionary) is closed.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // Build up the encoding menu, the order of the items differs based on the 627 // Build up the encoding menu, the order of the items differs based on the
579 // current locale (see http://crbug.com/7647 for details). 628 // 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 629 // We need a valid g_browser_process to get the profile which is why we can't
581 // call this from awakeFromNib. 630 // call this from awakeFromNib.
582 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu]; 631 NSMenu* viewMenu = [[[NSApp mainMenu] itemWithTag:IDC_VIEW_MENU] submenu];
583 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU]; 632 NSMenuItem* encodingMenuItem = [viewMenu itemWithTag:IDC_ENCODING_MENU];
584 NSMenu* encodingMenu = [encodingMenuItem submenu]; 633 NSMenu* encodingMenu = [encodingMenuItem submenu];
585 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile], 634 EncodingMenuControllerDelegate::BuildEncodingMenu([self lastProfile],
586 encodingMenu); 635 encodingMenu);
587 636
637 // Instantiate the ProfileInfoCache observer so that we can get
638 // notified when a profile is deleted.
639 profileInfoCacheObserver_.reset(new AppControllerProfileObserver(
640 g_browser_process->profile_manager(), self));
641
588 // Since Chrome is localized to more languages than the OS, tell Cocoa which 642 // 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. 643 // menu is the Help so it can add the search item to it.
590 [NSApp setHelpMenu:helpMenu_]; 644 [NSApp setHelpMenu:helpMenu_];
591 645
592 // Record the path to the (browser) app bundle; this is used by the app mode 646 // Record the path to the (browser) app bundle; this is used by the app mode
593 // shim. 647 // shim.
594 RecordLastRunAppBundlePath(); 648 RecordLastRunAppBundlePath();
595 649
596 // Makes "Services" menu items available. 650 // Makes "Services" menu items available.
597 [self registerServicesMenuTypesTo:[notify object]]; 651 [self registerServicesMenuTypesTo:[notify object]];
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 761
708 // Called to determine if we should enable the "restore tab" menu item. 762 // 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 763 // Checks with the TabRestoreService to see if there's anything there to
710 // restore and returns YES if so. 764 // restore and returns YES if so.
711 - (BOOL)canRestoreTab { 765 - (BOOL)canRestoreTab {
712 TabRestoreService* service = 766 TabRestoreService* service =
713 TabRestoreServiceFactory::GetForProfile([self lastProfile]); 767 TabRestoreServiceFactory::GetForProfile([self lastProfile]);
714 return service && !service->entries().empty(); 768 return service && !service->entries().empty();
715 } 769 }
716 770
771 // Called from the AppControllerProfileObserver every time a profile is deleted.
772 - (void)profileWasRemoved:(const string16&)profileName {
773 Profile* lastProfile = [self lastProfile];
774 string16 lastProfileName = UTF8ToUTF16(lastProfile->GetPrefs()->GetString(
Alexei Svitkine (slow) 2013/05/08 19:19:11 Instead of calling stuff on a profile that may be
noms (inactive) 2013/05/14 03:34:17 Ideally, lastProfile_ and lastProfilePath_ would b
775 prefs::kProfileName));
776
777 // If the last profile has been deleted, we must NULL out our pointer
778 // otherwise we will try to start up a browser window with a pointer
779 // to the old profile.
780 if (profileName == lastProfileName)
781 lastProfile_ = NULL;
Alexei Svitkine (slow) 2013/05/08 19:19:11 Wouldn't all the state that's set up by -windowCha
noms (inactive) 2013/05/14 03:34:17 Done.
782 }
783
717 // Returns true if there is a modal window (either window- or application- 784 // 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 785 // 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 786 // sheets) will not count as blocking the browser. But things like open/save
720 // dialogs that are window modal will block the browser. 787 // dialogs that are window modal will block the browser.
721 - (BOOL)keyWindowIsModal { 788 - (BOOL)keyWindowIsModal {
722 if ([NSApp modalWindow]) 789 if ([NSApp modalWindow])
723 return YES; 790 return YES;
724 791
725 Browser* browser = chrome::GetLastActiveBrowser(); 792 Browser* browser = chrome::GetLastActiveBrowser();
726 return browser && 793 return browser &&
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 1383
1317 //--------------------------------------------------------------------------- 1384 //---------------------------------------------------------------------------
1318 1385
1319 namespace app_controller_mac { 1386 namespace app_controller_mac {
1320 1387
1321 bool IsOpeningNewWindow() { 1388 bool IsOpeningNewWindow() {
1322 return g_is_opening_new_window; 1389 return g_is_opening_new_window;
1323 } 1390 }
1324 1391
1325 } // namespace app_controller_mac 1392 } // namespace app_controller_mac
OLDNEW
« no previous file with comments | « chrome/browser/app_controller_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698