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

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 6901031: Profile shouldn't own Session/TabRestore services. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase again and hope upload works this time Created 9 years, 8 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 #include "chrome/browser/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <shellapi.h> 8 #include <shellapi.h>
9 #include <windows.h> 9 #include <windows.h>
10 #endif // OS_WIN 10 #endif // OS_WIN
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #include "chrome/browser/instant/instant_unload_handler.h" 55 #include "chrome/browser/instant/instant_unload_handler.h"
56 #include "chrome/browser/net/browser_url_util.h" 56 #include "chrome/browser/net/browser_url_util.h"
57 #include "chrome/browser/net/url_fixer_upper.h" 57 #include "chrome/browser/net/url_fixer_upper.h"
58 #include "chrome/browser/notifications/notification_ui_manager.h" 58 #include "chrome/browser/notifications/notification_ui_manager.h"
59 #include "chrome/browser/platform_util.h" 59 #include "chrome/browser/platform_util.h"
60 #include "chrome/browser/prefs/pref_service.h" 60 #include "chrome/browser/prefs/pref_service.h"
61 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h" 61 #include "chrome/browser/printing/cloud_print/cloud_print_setup_flow.h"
62 #include "chrome/browser/printing/print_preview_tab_controller.h" 62 #include "chrome/browser/printing/print_preview_tab_controller.h"
63 #include "chrome/browser/profiles/profile.h" 63 #include "chrome/browser/profiles/profile.h"
64 #include "chrome/browser/sessions/session_service.h" 64 #include "chrome/browser/sessions/session_service.h"
65 #include "chrome/browser/sessions/session_service_factory.h"
65 #include "chrome/browser/sessions/session_types.h" 66 #include "chrome/browser/sessions/session_types.h"
66 #include "chrome/browser/sessions/tab_restore_service.h" 67 #include "chrome/browser/sessions/tab_restore_service.h"
68 #include "chrome/browser/sessions/tab_restore_service_factory.h"
67 #include "chrome/browser/sync/profile_sync_service.h" 69 #include "chrome/browser/sync/profile_sync_service.h"
68 #include "chrome/browser/sync/sync_ui_util.h" 70 #include "chrome/browser/sync/sync_ui_util.h"
69 #include "chrome/browser/tab_closeable_state_watcher.h" 71 #include "chrome/browser/tab_closeable_state_watcher.h"
70 #include "chrome/browser/tab_contents/background_contents.h" 72 #include "chrome/browser/tab_contents/background_contents.h"
71 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" 73 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h"
72 #include "chrome/browser/tabs/tab_finder.h" 74 #include "chrome/browser/tabs/tab_finder.h"
73 #include "chrome/browser/tabs/tab_strip_model.h" 75 #include "chrome/browser/tabs/tab_strip_model.h"
74 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" 76 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
75 #include "chrome/browser/ui/browser_list.h" 77 #include "chrome/browser/ui/browser_list.h"
76 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h" 78 #include "chrome/browser/ui/browser_tab_restore_service_delegate.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 profile_->GetPrefs(), NULL); 259 profile_->GetPrefs(), NULL);
258 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this); 260 use_vertical_tabs_.Init(prefs::kUseVerticalTabs, profile_->GetPrefs(), this);
259 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this); 261 instant_enabled_.Init(prefs::kInstantEnabled, profile_->GetPrefs(), this);
260 if (!TabMenuModel::AreVerticalTabsEnabled()) { 262 if (!TabMenuModel::AreVerticalTabsEnabled()) {
261 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we 263 // If vertical tabs aren't enabled, explicitly turn them off. Otherwise we
262 // might show vertical tabs but not show an option to turn them off. 264 // might show vertical tabs but not show an option to turn them off.
263 use_vertical_tabs_.SetValue(false); 265 use_vertical_tabs_.SetValue(false);
264 } 266 }
265 UpdateTabStripModelInsertionPolicy(); 267 UpdateTabStripModelInsertionPolicy();
266 268
267 tab_restore_service_ = profile->GetTabRestoreService(); 269 tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile);
268 if (tab_restore_service_) { 270 if (tab_restore_service_) {
269 tab_restore_service_->AddObserver(this); 271 tab_restore_service_->AddObserver(this);
270 TabRestoreServiceChanged(tab_restore_service_); 272 TabRestoreServiceChanged(tab_restore_service_);
271 } 273 }
272 274
273 if (profile_->GetProfileSyncService()) 275 if (profile_->GetProfileSyncService())
274 profile_->GetProfileSyncService()->AddObserver(this); 276 profile_->GetProfileSyncService()->AddObserver(this);
275 277
276 CreateInstantIfNecessary(); 278 CreateInstantIfNecessary();
277 279
(...skipping 16 matching lines...) Expand all
294 if (!BrowserList::HasBrowserWithProfile(profile_)) { 296 if (!BrowserList::HasBrowserWithProfile(profile_)) {
295 // We're the last browser window with this profile. We need to nuke the 297 // We're the last browser window with this profile. We need to nuke the
296 // TabRestoreService, which will start the shutdown of the 298 // TabRestoreService, which will start the shutdown of the
297 // NavigationControllers and allow for proper shutdown. If we don't do this 299 // NavigationControllers and allow for proper shutdown. If we don't do this
298 // chrome won't shutdown cleanly, and may end up crashing when some 300 // chrome won't shutdown cleanly, and may end up crashing when some
299 // thread tries to use the IO thread (or another thread) that is no longer 301 // thread tries to use the IO thread (or another thread) that is no longer
300 // valid. 302 // valid.
301 // This isn't a valid assumption for Mac OS, as it stays running after 303 // This isn't a valid assumption for Mac OS, as it stays running after
302 // the last browser has closed. The Mac equivalent is in its app 304 // the last browser has closed. The Mac equivalent is in its app
303 // controller. 305 // controller.
304 profile_->ResetTabRestoreService(); 306 TabRestoreServiceFactory::ResetForProfile(profile_);
305 } 307 }
306 #endif 308 #endif
307 309
308 SessionService* session_service = profile_->GetSessionService(); 310 SessionService* session_service =
311 SessionServiceFactory::GetForProfile(profile_);
309 if (session_service) 312 if (session_service)
310 session_service->WindowClosed(session_id_); 313 session_service->WindowClosed(session_id_);
311 314
312 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); 315 TabRestoreService* tab_restore_service =
316 TabRestoreServiceFactory::GetForProfile(profile());
313 if (tab_restore_service) 317 if (tab_restore_service)
314 tab_restore_service->BrowserClosed(tab_restore_service_delegate()); 318 tab_restore_service->BrowserClosed(tab_restore_service_delegate());
315 319
316 encoding_auto_detect_.Destroy(); 320 encoding_auto_detect_.Destroy();
317 printing_enabled_.Destroy(); 321 printing_enabled_.Destroy();
318 dev_tools_disabled_.Destroy(); 322 dev_tools_disabled_.Destroy();
319 incognito_mode_allowed_.Destroy(); 323 incognito_mode_allowed_.Destroy();
320 instant_enabled_.Destroy(); 324 instant_enabled_.Destroy();
321 use_vertical_tabs_.Destroy(); 325 use_vertical_tabs_.Destroy();
322 edit_bookmarks_enabled_.Destroy(); 326 edit_bookmarks_enabled_.Destroy();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 496
493 // static 497 // static
494 void Browser::OpenEmptyWindow(Profile* profile) { 498 void Browser::OpenEmptyWindow(Profile* profile) {
495 Browser* browser = Browser::Create(profile); 499 Browser* browser = Browser::Create(profile);
496 browser->AddBlankTab(true); 500 browser->AddBlankTab(true);
497 browser->window()->Show(); 501 browser->window()->Show();
498 } 502 }
499 503
500 // static 504 // static
501 void Browser::OpenWindowWithRestoredTabs(Profile* profile) { 505 void Browser::OpenWindowWithRestoredTabs(Profile* profile) {
502 TabRestoreService* service = profile->GetTabRestoreService(); 506 TabRestoreService* service = TabRestoreServiceFactory::GetForProfile(profile);
503 if (service) 507 if (service)
504 service->RestoreMostRecentEntry(NULL); 508 service->RestoreMostRecentEntry(NULL);
505 } 509 }
506 510
507 // static 511 // static
508 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) { 512 void Browser::OpenURLOffTheRecord(Profile* profile, const GURL& url) {
509 Browser* browser = GetOrCreateTabbedBrowser( 513 Browser* browser = GetOrCreateTabbedBrowser(
510 profile->GetOffTheRecordProfile()); 514 profile->GetOffTheRecordProfile());
511 browser->AddSelectedTabWithURL(url, PageTransition::LINK); 515 browser->AddSelectedTabWithURL(url, PageTransition::LINK);
512 browser->window()->Show(); 516 browser->window()->Show();
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 void Browser::OpenExtensionsWindow(Profile* profile) { 753 void Browser::OpenExtensionsWindow(Profile* profile) {
750 Browser* browser = Browser::Create(profile); 754 Browser* browser = Browser::Create(profile);
751 browser->ShowExtensionsTab(); 755 browser->ShowExtensionsTab();
752 browser->window()->Show(); 756 browser->window()->Show();
753 } 757 }
754 758
755 // static 759 // static
756 void Browser::NewWindowWithProfile(Profile* profile) { 760 void Browser::NewWindowWithProfile(Profile* profile) {
757 UserMetrics::RecordAction(UserMetricsAction("NewWindow")); 761 UserMetrics::RecordAction(UserMetricsAction("NewWindow"));
758 SessionService* session_service = 762 SessionService* session_service =
759 profile->GetOriginalProfile()->GetSessionService(); 763 SessionServiceFactory::GetForProfile(profile->GetOriginalProfile());
760 if (!session_service || 764 if (!session_service ||
761 !session_service->RestoreIfNecessary(std::vector<GURL>())) { 765 !session_service->RestoreIfNecessary(std::vector<GURL>())) {
762 Browser::OpenEmptyWindow(profile->GetOriginalProfile()); 766 Browser::OpenEmptyWindow(profile->GetOriginalProfile());
763 } 767 }
764 } 768 }
765 769
766 /////////////////////////////////////////////////////////////////////////////// 770 ///////////////////////////////////////////////////////////////////////////////
767 // Browser, State Storage and Retrieval for UI: 771 // Browser, State Storage and Retrieval for UI:
768 772
769 std::string Browser::GetWindowPlacementKey() const { 773 std::string Browser::GetWindowPlacementKey() const {
770 std::string name(prefs::kBrowserWindowPlacement); 774 std::string name(prefs::kBrowserWindowPlacement);
771 if (!app_name_.empty()) { 775 if (!app_name_.empty()) {
772 name.append("_"); 776 name.append("_");
773 name.append(app_name_); 777 name.append(app_name_);
774 } 778 }
775 return name; 779 return name;
776 } 780 }
777 781
778 bool Browser::ShouldSaveWindowPlacement() const { 782 bool Browser::ShouldSaveWindowPlacement() const {
779 // Only save the window placement of popups if they are restored. 783 // Only save the window placement of popups if they are restored.
780 return (type() & TYPE_POPUP) == 0 || browser_defaults::kRestorePopups; 784 return (type() & TYPE_POPUP) == 0 || browser_defaults::kRestorePopups;
781 } 785 }
782 786
783 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) { 787 void Browser::SaveWindowPlacement(const gfx::Rect& bounds, bool maximized) {
784 // Save to the session storage service, used when reloading a past session. 788 // Save to the session storage service, used when reloading a past session.
785 // Note that we don't want to be the ones who cause lazy initialization of 789 // Note that we don't want to be the ones who cause lazy initialization of
786 // the session service. This function gets called during initial window 790 // the session service. This function gets called during initial window
787 // showing, and we don't want to bring in the session service this early. 791 // showing, and we don't want to bring in the session service this early.
788 if (profile()->HasSessionService()) { 792 SessionService* session_service =
789 SessionService* session_service = profile()->GetSessionService(); 793 SessionServiceFactory::GetForProfileIfExisting(profile());
790 if (session_service) 794 if (session_service)
791 session_service->SetWindowBounds(session_id_, bounds, maximized); 795 session_service->SetWindowBounds(session_id_, bounds, maximized);
792 }
793 } 796 }
794 797
795 gfx::Rect Browser::GetSavedWindowBounds() const { 798 gfx::Rect Browser::GetSavedWindowBounds() const {
796 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); 799 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess();
797 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode); 800 bool record_mode = parsed_command_line.HasSwitch(switches::kRecordMode);
798 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode); 801 bool playback_mode = parsed_command_line.HasSwitch(switches::kPlaybackMode);
799 if (record_mode || playback_mode) { 802 if (record_mode || playback_mode) {
800 // In playback/record mode we always fix the size of the browser and 803 // In playback/record mode we always fix the size of the browser and
801 // move it to (0,0). The reason for this is two reasons: First we want 804 // move it to (0,0). The reason for this is two reasons: First we want
802 // resize/moves in the playback to still work, and Second we want 805 // resize/moves in the playback to still work, and Second we want
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 // AppController on the Mac, or BackgroundContentsService for background 918 // AppController on the Mac, or BackgroundContentsService for background
916 // pages). 919 // pages).
917 bool should_quit_if_last_browser = 920 bool should_quit_if_last_browser =
918 browser_shutdown::IsTryingToQuit() || !BrowserList::WillKeepAlive(); 921 browser_shutdown::IsTryingToQuit() || !BrowserList::WillKeepAlive();
919 922
920 if (should_quit_if_last_browser && BrowserList::size() == 1) { 923 if (should_quit_if_last_browser && BrowserList::size() == 1) {
921 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE); 924 browser_shutdown::OnShutdownStarting(browser_shutdown::WINDOW_CLOSE);
922 exiting = true; 925 exiting = true;
923 } 926 }
924 927
925 // Don't use HasSessionService here, we want to force creation of the 928 // Don't use GetForProfileIfExisting here, we want to force creation of the
926 // session service so that user can restore what was open. 929 // session service so that user can restore what was open.
927 SessionService* session_service = profile()->GetSessionService(); 930 SessionService* session_service =
931 SessionServiceFactory::GetForProfile(profile());
928 if (session_service) 932 if (session_service)
929 session_service->WindowClosing(session_id()); 933 session_service->WindowClosing(session_id());
930 934
931 TabRestoreService* tab_restore_service = profile()->GetTabRestoreService(); 935 TabRestoreService* tab_restore_service =
936 TabRestoreServiceFactory::GetForProfile(profile());
932 if (tab_restore_service && type() == TYPE_NORMAL && tab_count()) 937 if (tab_restore_service && type() == TYPE_NORMAL && tab_count())
933 tab_restore_service->BrowserClosing(tab_restore_service_delegate()); 938 tab_restore_service->BrowserClosing(tab_restore_service_delegate());
934 939
935 // TODO(sky): convert session/tab restore to use notification. 940 // TODO(sky): convert session/tab restore to use notification.
936 NotificationService::current()->Notify( 941 NotificationService::current()->Notify(
937 NotificationType::BROWSER_CLOSING, 942 NotificationType::BROWSER_CLOSING,
938 Source<Browser>(this), 943 Source<Browser>(this),
939 Details<bool>(&exiting)); 944 Details<bool>(&exiting));
940 945
941 CloseAllTabs(); 946 CloseAllTabs();
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 } else { 1096 } else {
1092 // We set the size of the view here, before WebKit does its initial 1097 // We set the size of the view here, before WebKit does its initial
1093 // layout. If we don't, the initial layout of background tabs will be 1098 // layout. If we don't, the initial layout of background tabs will be
1094 // performed with a view width of 0, which may cause script outputs and 1099 // performed with a view width of 0, which may cause script outputs and
1095 // anchor link location calculations to be incorrect even after a new 1100 // anchor link location calculations to be incorrect even after a new
1096 // layout with proper view dimensions. TabStripModel::AddTabContents() 1101 // layout with proper view dimensions. TabStripModel::AddTabContents()
1097 // contains similar logic. 1102 // contains similar logic.
1098 new_tab->view()->SizeContents(window_->GetRestoredBounds().size()); 1103 new_tab->view()->SizeContents(window_->GetRestoredBounds().size());
1099 new_tab->HideContents(); 1104 new_tab->HideContents();
1100 } 1105 }
1101 if (profile_->HasSessionService()) { 1106 SessionService* session_service =
1102 SessionService* session_service = profile_->GetSessionService(); 1107 SessionServiceFactory::GetForProfileIfExisting(profile_);
1103 if (session_service) 1108 if (session_service)
1104 session_service->TabRestored(&new_tab->controller(), pin); 1109 session_service->TabRestored(&new_tab->controller(), pin);
1105 }
1106 return new_tab; 1110 return new_tab;
1107 } 1111 }
1108 1112
1109 void Browser::ReplaceRestoredTab( 1113 void Browser::ReplaceRestoredTab(
1110 const std::vector<TabNavigation>& navigations, 1114 const std::vector<TabNavigation>& navigations,
1111 int selected_navigation, 1115 int selected_navigation,
1112 bool from_last_session, 1116 bool from_last_session,
1113 const std::string& extension_app_id, 1117 const std::string& extension_app_id,
1114 SessionStorageNamespace* session_storage_namespace) { 1118 SessionStorageNamespace* session_storage_namespace) {
1115 TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL, 1119 TabContentsWrapper* wrapper = TabContentsFactory(profile(), NULL,
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 1393
1390 void Browser::NewWindow() { 1394 void Browser::NewWindow() {
1391 if (browser_defaults::kAlwaysOpenIncognitoWindow && 1395 if (browser_defaults::kAlwaysOpenIncognitoWindow &&
1392 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) && 1396 CommandLine::ForCurrentProcess()->HasSwitch(switches::kIncognito) &&
1393 incognito_mode_allowed_.GetValue()) { 1397 incognito_mode_allowed_.GetValue()) {
1394 NewIncognitoWindow(); 1398 NewIncognitoWindow();
1395 return; 1399 return;
1396 } 1400 }
1397 UserMetrics::RecordAction(UserMetricsAction("NewWindow")); 1401 UserMetrics::RecordAction(UserMetricsAction("NewWindow"));
1398 SessionService* session_service = 1402 SessionService* session_service =
1399 profile_->GetOriginalProfile()->GetSessionService(); 1403 SessionServiceFactory::GetForProfile(profile_->GetOriginalProfile());
1400 if (!session_service || 1404 if (!session_service ||
1401 !session_service->RestoreIfNecessary(std::vector<GURL>())) { 1405 !session_service->RestoreIfNecessary(std::vector<GURL>())) {
1402 Browser::OpenEmptyWindow(profile_->GetOriginalProfile()); 1406 Browser::OpenEmptyWindow(profile_->GetOriginalProfile());
1403 } 1407 }
1404 } 1408 }
1405 1409
1406 void Browser::NewIncognitoWindow() { 1410 void Browser::NewIncognitoWindow() {
1407 if (!incognito_mode_allowed_.GetValue()) { 1411 if (!incognito_mode_allowed_.GetValue()) {
1408 NewWindow(); 1412 NewWindow();
1409 return; 1413 return;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 tab_handler_->GetTabStripModel()->SelectLastTab(); 1491 tab_handler_->GetTabStripModel()->SelectLastTab();
1488 } 1492 }
1489 1493
1490 void Browser::DuplicateTab() { 1494 void Browser::DuplicateTab() {
1491 UserMetrics::RecordAction(UserMetricsAction("Duplicate")); 1495 UserMetrics::RecordAction(UserMetricsAction("Duplicate"));
1492 DuplicateContentsAt(active_index()); 1496 DuplicateContentsAt(active_index());
1493 } 1497 }
1494 1498
1495 void Browser::RestoreTab() { 1499 void Browser::RestoreTab() {
1496 UserMetrics::RecordAction(UserMetricsAction("RestoreTab")); 1500 UserMetrics::RecordAction(UserMetricsAction("RestoreTab"));
1497 TabRestoreService* service = profile_->GetTabRestoreService(); 1501 TabRestoreService* service =
1502 TabRestoreServiceFactory::GetForProfile(profile_);
1498 if (!service) 1503 if (!service)
1499 return; 1504 return;
1500 1505
1501 service->RestoreMostRecentEntry(tab_restore_service_delegate()); 1506 service->RestoreMostRecentEntry(tab_restore_service_delegate());
1502 } 1507 }
1503 1508
1504 void Browser::WriteCurrentURLToClipboard() { 1509 void Browser::WriteCurrentURLToClipboard() {
1505 // TODO(ericu): There isn't currently a metric for this. Should there be? 1510 // TODO(ericu): There isn't currently a metric for this. Should there be?
1506 // We don't appear to track the action when it comes from the 1511 // We don't appear to track the action when it comes from the
1507 // RenderContextViewMenu. 1512 // RenderContextViewMenu.
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after
2587 window()->GetRestoredBounds().size())); 2592 window()->GetRestoredBounds().size()));
2588 2593
2589 // We need to show the browser now. Otherwise ContainerWin assumes the 2594 // We need to show the browser now. Otherwise ContainerWin assumes the
2590 // TabContents is invisible and won't size it. 2595 // TabContents is invisible and won't size it.
2591 browser->window()->Show(); 2596 browser->window()->Show();
2592 2597
2593 // The page transition below is only for the purpose of inserting the tab. 2598 // The page transition below is only for the purpose of inserting the tab.
2594 browser->AddTab(contents_dupe, PageTransition::LINK); 2599 browser->AddTab(contents_dupe, PageTransition::LINK);
2595 } 2600 }
2596 2601
2597 if (profile_->HasSessionService()) { 2602 SessionService* session_service =
2598 SessionService* session_service = profile_->GetSessionService(); 2603 SessionServiceFactory::GetForProfileIfExisting(profile_);
2599 if (session_service) 2604 if (session_service)
2600 session_service->TabRestored(&new_contents->controller(), pinned); 2605 session_service->TabRestored(&new_contents->controller(), pinned);
2601 }
2602 } 2606 }
2603 2607
2604 void Browser::CloseFrameAfterDragSession() { 2608 void Browser::CloseFrameAfterDragSession() {
2605 #if defined(OS_WIN) || defined(OS_LINUX) 2609 #if defined(OS_WIN) || defined(OS_LINUX)
2606 // This is scheduled to run after we return to the message loop because 2610 // This is scheduled to run after we return to the message loop because
2607 // otherwise the frame will think the drag session is still active and ignore 2611 // otherwise the frame will think the drag session is still active and ignore
2608 // the request. 2612 // the request.
2609 // TODO(port): figure out what is required here in a cross-platform world 2613 // TODO(port): figure out what is required here in a cross-platform world
2610 MessageLoop::current()->PostTask( 2614 MessageLoop::current()->PostTask(
2611 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame)); 2615 FROM_HERE, method_factory_.NewRunnableMethod(&Browser::CloseFrame));
2612 #endif 2616 #endif
2613 } 2617 }
2614 2618
2615 void Browser::CreateHistoricalTab(TabContentsWrapper* contents) { 2619 void Browser::CreateHistoricalTab(TabContentsWrapper* contents) {
2616 // We don't create historical tabs for incognito windows or windows without 2620 // We don't create historical tabs for incognito windows or windows without
2617 // profiles. 2621 // profiles.
2618 if (!profile() || profile()->IsOffTheRecord() || 2622 if (!profile() || profile()->IsOffTheRecord())
2619 !profile()->GetTabRestoreService()) {
2620 return; 2623 return;
2621 } 2624
2625 TabRestoreService* service =
2626 TabRestoreServiceFactory::GetForProfile(profile());
2622 2627
2623 // We only create historical tab entries for tabbed browser windows. 2628 // We only create historical tab entries for tabbed browser windows.
2624 if (CanSupportWindowFeature(FEATURE_TABSTRIP)) { 2629 if (service && CanSupportWindowFeature(FEATURE_TABSTRIP)) {
2625 profile()->GetTabRestoreService()->CreateHistoricalTab( 2630 service->CreateHistoricalTab(&contents->controller(),
2626 &contents->controller(),
2627 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents)); 2631 tab_handler_->GetTabStripModel()->GetIndexOfTabContents(contents));
2628 } 2632 }
2629 } 2633 }
2630 2634
2631 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) { 2635 bool Browser::RunUnloadListenerBeforeClosing(TabContentsWrapper* contents) {
2632 return Browser::RunUnloadEventsHelper(contents->tab_contents()); 2636 return Browser::RunUnloadEventsHelper(contents->tab_contents());
2633 } 2637 }
2634 2638
2635 bool Browser::CanReloadContents(TabContents* source) const { 2639 bool Browser::CanReloadContents(TabContents* source) const {
2636 return type() != TYPE_DEVTOOLS; 2640 return type() != TYPE_DEVTOOLS;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 status_bubble->SetStatus(GetSelectedTabContentsWrapper()->GetStatusText()); 2791 status_bubble->SetStatus(GetSelectedTabContentsWrapper()->GetStatusText());
2788 } 2792 }
2789 2793
2790 if (HasFindBarController()) { 2794 if (HasFindBarController()) {
2791 find_bar_controller_->ChangeTabContents(new_contents); 2795 find_bar_controller_->ChangeTabContents(new_contents);
2792 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true); 2796 find_bar_controller_->find_bar()->MoveWindowIfNecessary(gfx::Rect(), true);
2793 } 2797 }
2794 2798
2795 // Update sessions. Don't force creation of sessions. If sessions doesn't 2799 // Update sessions. Don't force creation of sessions. If sessions doesn't
2796 // exist, the change will be picked up by sessions when created. 2800 // exist, the change will be picked up by sessions when created.
2797 if (profile_->HasSessionService()) { 2801 SessionService* session_service =
2798 SessionService* session_service = profile_->GetSessionService(); 2802 SessionServiceFactory::GetForProfileIfExisting(profile_);
2799 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) { 2803 if (session_service && !tab_handler_->GetTabStripModel()->closing_all()) {
2800 session_service->SetSelectedTabInWindow( 2804 session_service->SetSelectedTabInWindow(
2801 session_id(), tab_handler_->GetTabStripModel()->active_index()); 2805 session_id(), tab_handler_->GetTabStripModel()->active_index());
2802 }
2803 } 2806 }
2804 } 2807 }
2805 2808
2806 void Browser::TabMoved(TabContentsWrapper* contents, 2809 void Browser::TabMoved(TabContentsWrapper* contents,
2807 int from_index, 2810 int from_index,
2808 int to_index) { 2811 int to_index) {
2809 DCHECK(from_index >= 0 && to_index >= 0); 2812 DCHECK(from_index >= 0 && to_index >= 0);
2810 // Notify the history service. 2813 // Notify the history service.
2811 SyncHistoryWithTabs(std::min(from_index, to_index)); 2814 SyncHistoryWithTabs(std::min(from_index, to_index));
2812 } 2815 }
2813 2816
2814 void Browser::TabReplacedAt(TabStripModel* tab_strip_model, 2817 void Browser::TabReplacedAt(TabStripModel* tab_strip_model,
2815 TabContentsWrapper* old_contents, 2818 TabContentsWrapper* old_contents,
2816 TabContentsWrapper* new_contents, 2819 TabContentsWrapper* new_contents,
2817 int index) { 2820 int index) {
2818 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE); 2821 TabDetachedAtImpl(old_contents, index, DETACH_TYPE_REPLACE);
2819 TabInsertedAt(new_contents, index, 2822 TabInsertedAt(new_contents, index,
2820 (index == tab_handler_->GetTabStripModel()->active_index())); 2823 (index == tab_handler_->GetTabStripModel()->active_index()));
2821 2824
2822 int entry_count = new_contents->controller().entry_count(); 2825 int entry_count = new_contents->controller().entry_count();
2823 if (entry_count > 0) { 2826 if (entry_count > 0) {
2824 // Send out notification so that observers are updated appropriately. 2827 // Send out notification so that observers are updated appropriately.
2825 new_contents->controller().NotifyEntryChanged( 2828 new_contents->controller().NotifyEntryChanged(
2826 new_contents->controller().GetEntryAtIndex(entry_count - 1), 2829 new_contents->controller().GetEntryAtIndex(entry_count - 1),
2827 entry_count - 1); 2830 entry_count - 1);
2828 } 2831 }
2829 2832
2830 SessionService* session_service = profile()->GetSessionService(); 2833 SessionService* session_service =
2834 SessionServiceFactory::GetForProfile(profile());
2831 if (session_service) { 2835 if (session_service) {
2832 // The new_contents may end up with a different navigation stack. Force 2836 // The new_contents may end up with a different navigation stack. Force
2833 // the session service to update itself. 2837 // the session service to update itself.
2834 session_service->TabRestored( 2838 session_service->TabRestored(
2835 &new_contents->controller(), 2839 &new_contents->controller(),
2836 tab_handler_->GetTabStripModel()->IsTabPinned(index)); 2840 tab_handler_->GetTabStripModel()->IsTabPinned(index));
2837 } 2841 }
2838 2842
2839 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); 2843 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
2840 if (devtools_manager) // NULL in unit tests. 2844 if (devtools_manager) // NULL in unit tests.
2841 devtools_manager->TabReplaced(old_contents, new_contents); 2845 devtools_manager->TabReplaced(old_contents, new_contents);
2842 } 2846 }
2843 2847
2844 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) { 2848 void Browser::TabPinnedStateChanged(TabContentsWrapper* contents, int index) {
2845 if (!profile()->HasSessionService()) 2849 SessionService* session_service =
2846 return; 2850 SessionServiceFactory::GetForProfileIfExisting(profile());
2847 SessionService* session_service = profile()->GetSessionService();
2848 if (session_service) { 2851 if (session_service) {
2849 session_service->SetPinnedState( 2852 session_service->SetPinnedState(
2850 session_id(), 2853 session_id(),
2851 GetTabContentsAt(index)->controller().session_id(), 2854 GetTabContentsAt(index)->controller().session_id(),
2852 tab_handler_->GetTabStripModel()->IsTabPinned(index)); 2855 tab_handler_->GetTabStripModel()->IsTabPinned(index));
2853 } 2856 }
2854 } 2857 }
2855 2858
2856 void Browser::TabStripEmpty() { 2859 void Browser::TabStripEmpty() {
2857 // Close the frame after we return to the message loop (not immediately, 2860 // Close the frame after we return to the message loop (not immediately,
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
4006 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 4009 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
4007 return NULL; 4010 return NULL;
4008 #endif 4011 #endif
4009 return window_ ? window_->GetStatusBubble() : NULL; 4012 return window_ ? window_->GetStatusBubble() : NULL;
4010 } 4013 }
4011 4014
4012 /////////////////////////////////////////////////////////////////////////////// 4015 ///////////////////////////////////////////////////////////////////////////////
4013 // Browser, Session restore functions (private): 4016 // Browser, Session restore functions (private):
4014 4017
4015 void Browser::SyncHistoryWithTabs(int index) { 4018 void Browser::SyncHistoryWithTabs(int index) {
4016 if (!profile()->HasSessionService()) 4019 SessionService* session_service =
4017 return; 4020 SessionServiceFactory::GetForProfileIfExisting(profile());
4018 SessionService* session_service = profile()->GetSessionService();
4019 if (session_service) { 4021 if (session_service) {
4020 for (int i = index; i < tab_count(); ++i) { 4022 for (int i = index; i < tab_count(); ++i) {
4021 TabContents* contents = GetTabContentsAt(i); 4023 TabContents* contents = GetTabContentsAt(i);
4022 if (contents) { 4024 if (contents) {
4023 session_service->SetTabIndexInWindow( 4025 session_service->SetTabIndexInWindow(
4024 session_id(), contents->controller().session_id(), i); 4026 session_id(), contents->controller().session_id(), i);
4025 session_service->SetPinnedState( 4027 session_service->SetPinnedState(
4026 session_id(), 4028 session_id(),
4027 contents->controller().session_id(), 4029 contents->controller().session_id(),
4028 tab_handler_->GetTabStripModel()->IsTabPinned(i)); 4030 tab_handler_->GetTabStripModel()->IsTabPinned(i));
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
4462 window()->GetRestoredBounds().size())); 4464 window()->GetRestoredBounds().size()));
4463 4465
4464 // We need to show the browser now. Otherwise ContainerWin assumes the 4466 // We need to show the browser now. Otherwise ContainerWin assumes the
4465 // TabContents is invisible and won't size it. 4467 // TabContents is invisible and won't size it.
4466 browser->window()->Show(); 4468 browser->window()->Show();
4467 4469
4468 // The page transition below is only for the purpose of inserting the tab. 4470 // The page transition below is only for the purpose of inserting the tab.
4469 browser->AddTab(view_source_contents, PageTransition::LINK); 4471 browser->AddTab(view_source_contents, PageTransition::LINK);
4470 } 4472 }
4471 4473
4472 if (profile_->HasSessionService()) { 4474 SessionService* session_service =
4473 SessionService* session_service = profile_->GetSessionService(); 4475 SessionServiceFactory::GetForProfileIfExisting(profile_);
4474 if (session_service) 4476 if (session_service)
4475 session_service->TabRestored(&view_source_contents->controller(), false); 4477 session_service->TabRestored(&view_source_contents->controller(), false);
4476 }
4477 } 4478 }
4478 4479
4479 int Browser::GetContentRestrictionsForSelectedTab() { 4480 int Browser::GetContentRestrictionsForSelectedTab() {
4480 int content_restrictions = 0; 4481 int content_restrictions = 0;
4481 TabContents* current_tab = GetSelectedTabContents(); 4482 TabContents* current_tab = GetSelectedTabContents();
4482 if (current_tab) { 4483 if (current_tab) {
4483 content_restrictions = current_tab->content_restrictions(); 4484 content_restrictions = current_tab->content_restrictions();
4484 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry(); 4485 NavigationEntry* active_entry = current_tab->controller().GetActiveEntry();
4485 // See comment in UpdateCommandsForTabState about why we call url(). 4486 // See comment in UpdateCommandsForTabState about why we call url().
4486 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL())) 4487 if (!SavePackage::IsSavableURL(active_entry ? active_entry->url() : GURL()))
4487 content_restrictions |= CONTENT_RESTRICTION_SAVE; 4488 content_restrictions |= CONTENT_RESTRICTION_SAVE;
4488 } 4489 }
4489 return content_restrictions; 4490 return content_restrictions;
4490 } 4491 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_session_unittest.cc ('k') | chrome/browser/ui/browser_init.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698