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

Side by Side Diff: chrome/browser/sessions/session_restore.cc

Issue 2644663003: Offer to open the startup pages after a crash. (Closed)
Patch Set: Rebase Created 3 years, 11 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 #include "chrome/browser/sessions/session_restore.h" 5 #include "chrome/browser/sessions/session_restore.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 13 matching lines...) Expand all
24 #include "base/metrics/histogram_macros.h" 24 #include "base/metrics/histogram_macros.h"
25 #include "base/run_loop.h" 25 #include "base/run_loop.h"
26 #include "base/single_thread_task_runner.h" 26 #include "base/single_thread_task_runner.h"
27 #include "base/task/cancelable_task_tracker.h" 27 #include "base/task/cancelable_task_tracker.h"
28 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
29 #include "build/build_config.h" 29 #include "build/build_config.h"
30 #include "chrome/browser/browser_process.h" 30 #include "chrome/browser/browser_process.h"
31 #include "chrome/browser/chrome_notification_types.h" 31 #include "chrome/browser/chrome_notification_types.h"
32 #include "chrome/browser/lifetime/keep_alive_types.h" 32 #include "chrome/browser/lifetime/keep_alive_types.h"
33 #include "chrome/browser/lifetime/scoped_keep_alive.h" 33 #include "chrome/browser/lifetime/scoped_keep_alive.h"
34 #include "chrome/browser/prefs/session_startup_pref.h"
34 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
35 #include "chrome/browser/search/search.h" 36 #include "chrome/browser/search/search.h"
36 #include "chrome/browser/sessions/session_restore_delegate.h" 37 #include "chrome/browser/sessions/session_restore_delegate.h"
37 #include "chrome/browser/sessions/session_service.h" 38 #include "chrome/browser/sessions/session_service.h"
38 #include "chrome/browser/sessions/session_service_factory.h" 39 #include "chrome/browser/sessions/session_service_factory.h"
39 #include "chrome/browser/sessions/session_service_utils.h" 40 #include "chrome/browser/sessions/session_service_utils.h"
40 #include "chrome/browser/sessions/tab_loader.h" 41 #include "chrome/browser/sessions/tab_loader.h"
41 #include "chrome/browser/ui/browser.h" 42 #include "chrome/browser/ui/browser.h"
42 #include "chrome/browser/ui/browser_finder.h" 43 #include "chrome/browser/ui/browser_finder.h"
43 #include "chrome/browser/ui/browser_navigator.h" 44 #include "chrome/browser/ui/browser_navigator.h"
44 #include "chrome/browser/ui/browser_navigator_params.h" 45 #include "chrome/browser/ui/browser_navigator_params.h"
45 #include "chrome/browser/ui/browser_tabrestore.h" 46 #include "chrome/browser/ui/browser_tabrestore.h"
46 #include "chrome/browser/ui/browser_tabstrip.h" 47 #include "chrome/browser/ui/browser_tabstrip.h"
47 #include "chrome/browser/ui/browser_window.h" 48 #include "chrome/browser/ui/browser_window.h"
49 #include "chrome/browser/ui/startup/startup_browser_creator.h"
48 #include "chrome/browser/ui/tabs/tab_strip_model.h" 50 #include "chrome/browser/ui/tabs/tab_strip_model.h"
49 #include "chrome/common/extensions/extension_metrics.h" 51 #include "chrome/common/extensions/extension_metrics.h"
50 #include "chrome/common/url_constants.h" 52 #include "chrome/common/url_constants.h"
51 #include "components/sessions/core/session_types.h" 53 #include "components/sessions/core/session_types.h"
52 #include "content/public/browser/child_process_security_policy.h" 54 #include "content/public/browser/child_process_security_policy.h"
53 #include "content/public/browser/dom_storage_context.h" 55 #include "content/public/browser/dom_storage_context.h"
54 #include "content/public/browser/navigation_controller.h" 56 #include "content/public/browser/navigation_controller.h"
55 #include "content/public/browser/notification_registrar.h" 57 #include "content/public/browser/notification_registrar.h"
56 #include "content/public/browser/notification_service.h" 58 #include "content/public/browser/notification_service.h"
57 #include "content/public/browser/render_process_host.h" 59 #include "content/public/browser/render_process_host.h"
(...skipping 10 matching lines...) Expand all
68 #include "chrome/browser/chromeos/boot_times_recorder.h" 70 #include "chrome/browser/chromeos/boot_times_recorder.h"
69 #endif 71 #endif
70 72
71 using content::NavigationController; 73 using content::NavigationController;
72 using content::RenderWidgetHost; 74 using content::RenderWidgetHost;
73 using content::WebContents; 75 using content::WebContents;
74 using RestoredTab = SessionRestoreDelegate::RestoredTab; 76 using RestoredTab = SessionRestoreDelegate::RestoredTab;
75 77
76 namespace { 78 namespace {
77 79
80 bool HasSingleNewTabPage(Browser* browser) {
81 if (browser->tab_strip_model()->count() != 1)
82 return false;
83 const content::WebContents* active_tab =
84 browser->tab_strip_model()->GetWebContentsAt(0);
85 return active_tab->GetURL() == chrome::kChromeUINewTabURL ||
86 search::IsInstantNTP(active_tab);
87 }
88
78 class SessionRestoreImpl; 89 class SessionRestoreImpl;
79 90
80 // Pointers to SessionRestoreImpls which are currently restoring the session. 91 // Pointers to SessionRestoreImpls which are currently restoring the session.
81 std::set<SessionRestoreImpl*>* active_session_restorers = nullptr; 92 std::set<SessionRestoreImpl*>* active_session_restorers = nullptr;
82 93
83 // SessionRestoreImpl --------------------------------------------------------- 94 // SessionRestoreImpl ---------------------------------------------------------
84 95
85 // SessionRestoreImpl is responsible for fetching the set of tabs to create 96 // SessionRestoreImpl is responsible for fetching the set of tabs to create
86 // from SessionService. SessionRestoreImpl deletes itself when done. 97 // from SessionService. SessionRestoreImpl deletes itself when done.
87 98
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 SessionRestoreImpl* restorer = new SessionRestoreImpl( 768 SessionRestoreImpl* restorer = new SessionRestoreImpl(
758 profile, browser, (behavior & SYNCHRONOUS) != 0, 769 profile, browser, (behavior & SYNCHRONOUS) != 0,
759 (behavior & CLOBBER_CURRENT_TAB) != 0, 770 (behavior & CLOBBER_CURRENT_TAB) != 0,
760 (behavior & ALWAYS_CREATE_TABBED_BROWSER) != 0, urls_to_open, 771 (behavior & ALWAYS_CREATE_TABBED_BROWSER) != 0, urls_to_open,
761 SessionRestore::on_session_restored_callbacks()); 772 SessionRestore::on_session_restored_callbacks());
762 return restorer->Restore(); 773 return restorer->Restore();
763 } 774 }
764 775
765 // static 776 // static
766 void SessionRestore::RestoreSessionAfterCrash(Browser* browser) { 777 void SessionRestore::RestoreSessionAfterCrash(Browser* browser) {
767 uint32_t behavior = 0; 778 uint32_t behavior =
768 if (browser->tab_strip_model()->count() == 1) { 779 HasSingleNewTabPage(browser) ? SessionRestore::CLOBBER_CURRENT_TAB : 0;
769 const content::WebContents* active_tab =
770 browser->tab_strip_model()->GetWebContentsAt(0);
771 if (active_tab->GetURL() == chrome::kChromeUINewTabURL ||
772 search::IsInstantNTP(active_tab)) {
773 // There is only one tab and its the new tab page, make session restore
774 // clobber it.
775 behavior = SessionRestore::CLOBBER_CURRENT_TAB;
776 }
777 }
778 SessionRestore::RestoreSession(browser->profile(), browser, behavior, 780 SessionRestore::RestoreSession(browser->profile(), browser, behavior,
779 std::vector<GURL>()); 781 std::vector<GURL>());
780 } 782 }
781 783
782 // static 784 // static
785 void SessionRestore::OpenStartupPagesAfterCrash(Browser* browser) {
786 WebContents* tab_to_clobber = nullptr;
787 if (HasSingleNewTabPage(browser))
788 tab_to_clobber = browser->tab_strip_model()->GetActiveWebContents();
789
790 StartupBrowserCreator::OpenStartupPages(browser, true);
791 if (tab_to_clobber && browser->tab_strip_model()->count() > 1)
792 chrome::CloseWebContents(browser, tab_to_clobber, true);
793 }
794
795 // static
783 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows( 796 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows(
784 Profile* profile, 797 Profile* profile,
785 std::vector<const sessions::SessionWindow*>::const_iterator begin, 798 std::vector<const sessions::SessionWindow*>::const_iterator begin,
786 std::vector<const sessions::SessionWindow*>::const_iterator end) { 799 std::vector<const sessions::SessionWindow*>::const_iterator end) {
787 std::vector<GURL> gurls; 800 std::vector<GURL> gurls;
788 SessionRestoreImpl restorer(profile, static_cast<Browser*>(nullptr), true, 801 SessionRestoreImpl restorer(profile, static_cast<Browser*>(nullptr), true,
789 false, true, gurls, 802 false, true, gurls,
790 on_session_restored_callbacks()); 803 on_session_restored_callbacks());
791 return restorer.RestoreForeignSession(begin, end); 804 return restorer.RestoreForeignSession(begin, end);
792 } 805 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 // static 846 // static
834 SessionRestore::CallbackSubscription 847 SessionRestore::CallbackSubscription
835 SessionRestore::RegisterOnSessionRestoredCallback( 848 SessionRestore::RegisterOnSessionRestoredCallback(
836 const base::Callback<void(int)>& callback) { 849 const base::Callback<void(int)>& callback) {
837 return on_session_restored_callbacks()->Add(callback); 850 return on_session_restored_callbacks()->Add(callback);
838 } 851 }
839 852
840 // static 853 // static
841 base::CallbackList<void(int)>* 854 base::CallbackList<void(int)>*
842 SessionRestore::on_session_restored_callbacks_ = nullptr; 855 SessionRestore::on_session_restored_callbacks_ = nullptr;
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore.h ('k') | chrome/browser/sessions/session_restore_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698