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

Side by Side Diff: chrome/browser/app_controller_mac.mm

Issue 6901031: Profile shouldn't own Session/TabRestore services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix mac build Created 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
11 #include "base/mac/mac_util.h" 11 #include "base/mac/mac_util.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/background_application_list_model.h" 16 #include "chrome/browser/background_application_list_model.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/browser_shutdown.h" 18 #include "chrome/browser/browser_shutdown.h"
19 #include "chrome/browser/command_updater.h" 19 #include "chrome/browser/command_updater.h"
20 #include "chrome/browser/download/download_manager.h" 20 #include "chrome/browser/download/download_manager.h"
21 #include "chrome/browser/instant/instant_confirm_dialog.h" 21 #include "chrome/browser/instant/instant_confirm_dialog.h"
22 #include "chrome/browser/metrics/user_metrics.h" 22 #include "chrome/browser/metrics/user_metrics.h"
23 #include "chrome/browser/prefs/pref_service.h" 23 #include "chrome/browser/prefs/pref_service.h"
24 #include "chrome/browser/printing/print_job_manager.h" 24 #include "chrome/browser/printing/print_job_manager.h"
25 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/browser/sessions/session_service.h" 26 #include "chrome/browser/sessions/session_service.h"
27 #include "chrome/browser/sessions/session_service_factory.h"
27 #include "chrome/browser/sessions/tab_restore_service.h" 28 #include "chrome/browser/sessions/tab_restore_service.h"
29 #include "chrome/browser/sessions/tab_restore_service_factory.h"
28 #include "chrome/browser/sync/profile_sync_service.h" 30 #include "chrome/browser/sync/profile_sync_service.h"
29 #include "chrome/browser/sync/sync_ui_util.h" 31 #include "chrome/browser/sync/sync_ui_util.h"
30 #include "chrome/browser/sync/sync_ui_util_mac.h" 32 #include "chrome/browser/sync/sync_ui_util_mac.h"
31 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_init.h" 34 #include "chrome/browser/ui/browser_init.h"
33 #include "chrome/browser/ui/browser_list.h" 35 #include "chrome/browser/ui/browser_list.h"
34 #include "chrome/browser/ui/browser_window.h" 36 #include "chrome/browser/ui/browser_window.h"
35 #import "chrome/browser/ui/cocoa/about_window_controller.h" 37 #import "chrome/browser/ui/cocoa/about_window_controller.h"
36 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h" 38 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_bridge.h"
37 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" 39 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 324 }
323 325
324 - (void)didEndMainMessageLoop { 326 - (void)didEndMainMessageLoop {
325 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile])); 327 DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile]));
326 if (!BrowserList::HasBrowserWithProfile([self defaultProfile])) { 328 if (!BrowserList::HasBrowserWithProfile([self defaultProfile])) {
327 // As we're shutting down, we need to nuke the TabRestoreService, which 329 // As we're shutting down, we need to nuke the TabRestoreService, which
328 // will start the shutdown of the NavigationControllers and allow for 330 // will start the shutdown of the NavigationControllers and allow for
329 // proper shutdown. If we don't do this, Chrome won't shut down cleanly, 331 // proper shutdown. If we don't do this, Chrome won't shut down cleanly,
330 // and may end up crashing when some thread tries to use the IO thread (or 332 // and may end up crashing when some thread tries to use the IO thread (or
331 // another thread) that is no longer valid. 333 // another thread) that is no longer valid.
332 [self defaultProfile]->ResetTabRestoreService(); 334 TabRestoreServiceFactory::ResetForProfile([self defaultProfile]);
333 } 335 }
334 } 336 }
335 337
336 // Helper routine to get the window controller if the key window is a tabbed 338 // Helper routine to get the window controller if the key window is a tabbed
337 // window, or nil if not. Examples of non-tabbed windows are "about" or 339 // window, or nil if not. Examples of non-tabbed windows are "about" or
338 // "preferences". 340 // "preferences".
339 - (TabWindowController*)keyWindowTabController { 341 - (TabWindowController*)keyWindowTabController {
340 NSWindowController* keyWindowController = 342 NSWindowController* keyWindowController =
341 [[NSApp keyWindow] windowController]; 343 [[NSApp keyWindow] windowController];
342 if ([keyWindowController isKindOfClass:[TabWindowController class]]) 344 if ([keyWindowController isKindOfClass:[TabWindowController class]])
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 } 631 }
630 632
631 // No profiles or active downloads found, okay to exit. 633 // No profiles or active downloads found, okay to exit.
632 return YES; 634 return YES;
633 } 635 }
634 636
635 // Called to determine if we should enable the "restore tab" menu item. 637 // Called to determine if we should enable the "restore tab" menu item.
636 // Checks with the TabRestoreService to see if there's anything there to 638 // Checks with the TabRestoreService to see if there's anything there to
637 // restore and returns YES if so. 639 // restore and returns YES if so.
638 - (BOOL)canRestoreTab { 640 - (BOOL)canRestoreTab {
639 TabRestoreService* service = [self defaultProfile]->GetTabRestoreService(); 641 TabRestoreService* service =
642 TabRestoreServiceFactory::GetForProfile([self defaultProfile]);
640 return service && !service->entries().empty(); 643 return service && !service->entries().empty();
641 } 644 }
642 645
643 // Returns true if there is not a modal window (either window- or application- 646 // Returns true if there is not a modal window (either window- or application-
644 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth 647 // modal) blocking the active browser. Note that tab modal dialogs (HTTP auth
645 // sheets) will not count as blocking the browser. But things like open/save 648 // sheets) will not count as blocking the browser. But things like open/save
646 // dialogs that are window modal will block the browser. 649 // dialogs that are window modal will block the browser.
647 - (BOOL)keyWindowIsNotModal { 650 - (BOOL)keyWindowIsNotModal {
648 Browser* browser = BrowserList::GetLastActive(); 651 Browser* browser = BrowserList::GetLastActive();
649 return [NSApp modalWindow] == nil && (!browser || 652 return [NSApp modalWindow] == nil && (!browser ||
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 // If launched as a hidden login item (due to installation of a persistent app 923 // If launched as a hidden login item (due to installation of a persistent app
921 // or by the user, for example in System Preferenecs->Accounts->Login Items), 924 // or by the user, for example in System Preferenecs->Accounts->Login Items),
922 // allow session to be restored first time the user clicks on a Dock icon. 925 // allow session to be restored first time the user clicks on a Dock icon.
923 // Normally, it'd just open a new empty page. 926 // Normally, it'd just open a new empty page.
924 { 927 {
925 static BOOL doneOnce = NO; 928 static BOOL doneOnce = NO;
926 if (!doneOnce) { 929 if (!doneOnce) {
927 doneOnce = YES; 930 doneOnce = YES;
928 if (base::mac::WasLaunchedAsHiddenLoginItem()) { 931 if (base::mac::WasLaunchedAsHiddenLoginItem()) {
929 SessionService* sessionService = 932 SessionService* sessionService =
930 [self defaultProfile]->GetSessionService(); 933 SessionServiceFactory::GetForProfile([self defaultProfile]);
931 if (sessionService && 934 if (sessionService &&
932 sessionService->RestoreIfNecessary(std::vector<GURL>())) 935 sessionService->RestoreIfNecessary(std::vector<GURL>()))
933 return NO; 936 return NO;
934 } 937 }
935 } 938 }
936 } 939 }
937 // Otherwise open a new window. 940 // Otherwise open a new window.
938 { 941 {
939 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true); 942 AutoReset<bool> auto_reset_in_run(&g_is_opening_new_window, true);
940 Browser::OpenEmptyWindow([self defaultProfile]); 943 Browser::OpenEmptyWindow([self defaultProfile]);
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1188
1186 } // namespace browser 1189 } // namespace browser
1187 1190
1188 namespace app_controller_mac { 1191 namespace app_controller_mac {
1189 1192
1190 bool IsOpeningNewWindow() { 1193 bool IsOpeningNewWindow() {
1191 return g_is_opening_new_window; 1194 return g_is_opening_new_window;
1192 } 1195 }
1193 1196
1194 } // namespace app_controller_mac 1197 } // namespace app_controller_mac
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698