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

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

Issue 1662783002: Remove HostDesktopType from Browser::CreateParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@metro-mode-12
Patch Set: remove desktop_type_ in bookmark_bubble_sign_in_delegate Created 4 years, 10 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // SessionRestoreImpl --------------------------------------------------------- 79 // SessionRestoreImpl ---------------------------------------------------------
80 80
81 // SessionRestoreImpl is responsible for fetching the set of tabs to create 81 // SessionRestoreImpl is responsible for fetching the set of tabs to create
82 // from SessionService. SessionRestoreImpl deletes itself when done. 82 // from SessionService. SessionRestoreImpl deletes itself when done.
83 83
84 class SessionRestoreImpl : public content::NotificationObserver { 84 class SessionRestoreImpl : public content::NotificationObserver {
85 public: 85 public:
86 SessionRestoreImpl(Profile* profile, 86 SessionRestoreImpl(Profile* profile,
87 Browser* browser, 87 Browser* browser,
88 chrome::HostDesktopType host_desktop_type,
89 bool synchronous, 88 bool synchronous,
90 bool clobber_existing_tab, 89 bool clobber_existing_tab,
91 bool always_create_tabbed_browser, 90 bool always_create_tabbed_browser,
92 const std::vector<GURL>& urls_to_open, 91 const std::vector<GURL>& urls_to_open,
93 SessionRestore::CallbackList* callbacks) 92 SessionRestore::CallbackList* callbacks)
94 : profile_(profile), 93 : profile_(profile),
95 browser_(browser), 94 browser_(browser),
96 host_desktop_type_(host_desktop_type),
97 synchronous_(synchronous), 95 synchronous_(synchronous),
98 clobber_existing_tab_(clobber_existing_tab), 96 clobber_existing_tab_(clobber_existing_tab),
99 always_create_tabbed_browser_(always_create_tabbed_browser), 97 always_create_tabbed_browser_(always_create_tabbed_browser),
100 urls_to_open_(urls_to_open), 98 urls_to_open_(urls_to_open),
101 active_window_id_(0), 99 active_window_id_(0),
102 restore_started_(base::TimeTicks::Now()), 100 restore_started_(base::TimeTicks::Now()),
103 on_session_restored_callbacks_(callbacks) { 101 on_session_restored_callbacks_(callbacks) {
104 // For sanity's sake, if |browser| is non-null: force |host_desktop_type| to
105 // be the same as |browser|'s desktop type.
106 DCHECK(!browser || browser->host_desktop_type() == host_desktop_type);
107
108 if (active_session_restorers == nullptr) 102 if (active_session_restorers == nullptr)
109 active_session_restorers = new std::set<SessionRestoreImpl*>(); 103 active_session_restorers = new std::set<SessionRestoreImpl*>();
110 104
111 // Only one SessionRestoreImpl should be operating on the profile at the 105 // Only one SessionRestoreImpl should be operating on the profile at the
112 // same time. 106 // same time.
113 std::set<SessionRestoreImpl*>::const_iterator it; 107 std::set<SessionRestoreImpl*>::const_iterator it;
114 for (it = active_session_restorers->begin(); 108 for (it = active_session_restorers->begin();
115 it != active_session_restorers->end(); ++it) { 109 it != active_session_restorers->end(); ++it) {
116 if ((*it)->profile_ == profile) 110 if ((*it)->profile_ == profile)
117 break; 111 break;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 DCHECK(!tab.navigations.empty()); 195 DCHECK(!tab.navigations.empty());
202 int selected_index = tab.current_navigation_index; 196 int selected_index = tab.current_navigation_index;
203 selected_index = std::max( 197 selected_index = std::max(
204 0, 198 0,
205 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1))); 199 std::min(selected_index, static_cast<int>(tab.navigations.size() - 1)));
206 200
207 bool use_new_window = disposition == NEW_WINDOW; 201 bool use_new_window = disposition == NEW_WINDOW;
208 202
209 Browser* browser = 203 Browser* browser =
210 use_new_window 204 use_new_window
211 ? new Browser(Browser::CreateParams(profile_, host_desktop_type_)) 205 ? new Browser(Browser::CreateParams(profile_))
212 : browser_; 206 : browser_;
213 207
214 RecordAppLaunchForTab(browser, tab, selected_index); 208 RecordAppLaunchForTab(browser, tab, selected_index);
215 209
216 WebContents* web_contents; 210 WebContents* web_contents;
217 if (disposition == CURRENT_TAB) { 211 if (disposition == CURRENT_TAB) {
218 DCHECK(!use_new_window); 212 DCHECK(!use_new_window);
219 web_contents = chrome::ReplaceRestoredTab( 213 web_contents = chrome::ReplaceRestoredTab(
220 browser, tab.navigations, selected_index, true, tab.extension_app_id, 214 browser, tab.navigations, selected_index, true, tab.extension_app_id,
221 nullptr, tab.user_agent_override); 215 nullptr, tab.user_agent_override);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // 277 //
284 // If successful, this begins loading tabs and deletes itself when all tabs 278 // If successful, this begins loading tabs and deletes itself when all tabs
285 // have been loaded. 279 // have been loaded.
286 // 280 //
287 // Returns the Browser that was created, if any. 281 // Returns the Browser that was created, if any.
288 Browser* FinishedTabCreation(bool succeeded, 282 Browser* FinishedTabCreation(bool succeeded,
289 bool created_tabbed_browser, 283 bool created_tabbed_browser,
290 std::vector<RestoredTab>* contents_created) { 284 std::vector<RestoredTab>* contents_created) {
291 Browser* browser = nullptr; 285 Browser* browser = nullptr;
292 if (!created_tabbed_browser && always_create_tabbed_browser_) { 286 if (!created_tabbed_browser && always_create_tabbed_browser_) {
293 browser = 287 browser = new Browser(Browser::CreateParams(profile_));
294 new Browser(Browser::CreateParams(profile_, host_desktop_type_));
295 if (urls_to_open_.empty()) { 288 if (urls_to_open_.empty()) {
296 // No tab browsers were created and no URLs were supplied on the command 289 // No tab browsers were created and no URLs were supplied on the command
297 // line. Open the new tab page. 290 // line. Open the new tab page.
298 urls_to_open_.push_back(GURL(chrome::kChromeUINewTabURL)); 291 urls_to_open_.push_back(GURL(chrome::kChromeUINewTabURL));
299 } 292 }
300 AppendURLsToBrowser(browser, urls_to_open_); 293 AppendURLsToBrowser(browser, urls_to_open_);
301 browser->window()->Show(); 294 browser->window()->Show();
302 } 295 }
303 296
304 if (succeeded) { 297 if (succeeded) {
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 // focused tab will be loaded by Browser, and TabLoader will load the rest. 616 // focused tab will be loaded by Browser, and TabLoader will load the rest.
624 DCHECK(web_contents->GetController().NeedsReload()); 617 DCHECK(web_contents->GetController().NeedsReload());
625 618
626 return web_contents; 619 return web_contents;
627 } 620 }
628 621
629 Browser* CreateRestoredBrowser(Browser::Type type, 622 Browser* CreateRestoredBrowser(Browser::Type type,
630 gfx::Rect bounds, 623 gfx::Rect bounds,
631 ui::WindowShowState show_state, 624 ui::WindowShowState show_state,
632 const std::string& app_name) { 625 const std::string& app_name) {
633 Browser::CreateParams params(type, profile_, host_desktop_type_); 626 Browser::CreateParams params(type, profile_);
634 if (!app_name.empty()) { 627 if (!app_name.empty()) {
635 const bool trusted_source = true; // We only store trusted app windows. 628 const bool trusted_source = true; // We only store trusted app windows.
636 params = Browser::CreateParams::CreateForApp( 629 params = Browser::CreateParams::CreateForApp(app_name, trusted_source,
637 app_name, trusted_source, bounds, profile_, host_desktop_type_); 630 bounds, profile_);
638 } else { 631 } else {
639 params.initial_bounds = bounds; 632 params.initial_bounds = bounds;
640 } 633 }
641 params.initial_show_state = show_state; 634 params.initial_show_state = show_state;
642 params.is_session_restore = true; 635 params.is_session_restore = true;
643 return new Browser(params); 636 return new Browser(params);
644 } 637 }
645 638
646 void ShowBrowser(Browser* browser, int selected_tab_index) { 639 void ShowBrowser(Browser* browser, int selected_tab_index) {
647 DCHECK(browser); 640 DCHECK(browser);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 session_service->TabRestored(tab_strip->GetWebContentsAt(i), 678 session_service->TabRestored(tab_strip->GetWebContentsAt(i),
686 tab_strip->IsTabPinned(i)); 679 tab_strip->IsTabPinned(i));
687 } 680 }
688 681
689 // The profile to create the sessions for. 682 // The profile to create the sessions for.
690 Profile* profile_; 683 Profile* profile_;
691 684
692 // The first browser to restore to, may be null. 685 // The first browser to restore to, may be null.
693 Browser* browser_; 686 Browser* browser_;
694 687
695 // The desktop on which all new browsers should be created (browser_, if it is
696 // not NULL, must be of this desktop type as well).
697 chrome::HostDesktopType host_desktop_type_;
698
699 // Whether or not restore is synchronous. 688 // Whether or not restore is synchronous.
700 const bool synchronous_; 689 const bool synchronous_;
701 690
702 // The quit-closure to terminate the nested message-loop started for 691 // The quit-closure to terminate the nested message-loop started for
703 // synchronous session-restore. 692 // synchronous session-restore.
704 base::Closure quit_closure_for_sync_restore_; 693 base::Closure quit_closure_for_sync_restore_;
705 694
706 // See description of CLOBBER_CURRENT_TAB. 695 // See description of CLOBBER_CURRENT_TAB.
707 const bool clobber_existing_tab_; 696 const bool clobber_existing_tab_;
708 697
(...skipping 30 matching lines...) Expand all
739 }; 728 };
740 729
741 } // namespace 730 } // namespace
742 731
743 // SessionRestore ------------------------------------------------------------- 732 // SessionRestore -------------------------------------------------------------
744 733
745 // static 734 // static
746 Browser* SessionRestore::RestoreSession( 735 Browser* SessionRestore::RestoreSession(
747 Profile* profile, 736 Profile* profile,
748 Browser* browser, 737 Browser* browser,
749 chrome::HostDesktopType host_desktop_type,
750 uint32_t behavior, 738 uint32_t behavior,
751 const std::vector<GURL>& urls_to_open) { 739 const std::vector<GURL>& urls_to_open) {
752 #if defined(OS_CHROMEOS) 740 #if defined(OS_CHROMEOS)
753 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker( 741 chromeos::BootTimesRecorder::Get()->AddLoginTimeMarker(
754 "SessionRestore-Start", false); 742 "SessionRestore-Start", false);
755 #endif 743 #endif
756 DCHECK(profile); 744 DCHECK(profile);
757 // Always restore from the original profile (incognito profiles have no 745 // Always restore from the original profile (incognito profiles have no
758 // session service). 746 // session service).
759 profile = profile->GetOriginalProfile(); 747 profile = profile->GetOriginalProfile();
760 if (!SessionServiceFactory::GetForProfile(profile)) { 748 if (!SessionServiceFactory::GetForProfile(profile)) {
761 NOTREACHED(); 749 NOTREACHED();
762 return nullptr; 750 return nullptr;
763 } 751 }
764 profile->set_restored_last_session(true); 752 profile->set_restored_last_session(true);
765 // SessionRestoreImpl takes care of deleting itself when done. 753 // SessionRestoreImpl takes care of deleting itself when done.
766 SessionRestoreImpl* restorer = new SessionRestoreImpl( 754 SessionRestoreImpl* restorer = new SessionRestoreImpl(
767 profile, browser, host_desktop_type, (behavior & SYNCHRONOUS) != 0, 755 profile, browser, (behavior & SYNCHRONOUS) != 0,
768 (behavior & CLOBBER_CURRENT_TAB) != 0, 756 (behavior & CLOBBER_CURRENT_TAB) != 0,
769 (behavior & ALWAYS_CREATE_TABBED_BROWSER) != 0, 757 (behavior & ALWAYS_CREATE_TABBED_BROWSER) != 0, urls_to_open,
770 urls_to_open,
771 SessionRestore::on_session_restored_callbacks()); 758 SessionRestore::on_session_restored_callbacks());
772 return restorer->Restore(); 759 return restorer->Restore();
773 } 760 }
774 761
775 // static 762 // static
776 void SessionRestore::RestoreSessionAfterCrash(Browser* browser) { 763 void SessionRestore::RestoreSessionAfterCrash(Browser* browser) {
777 uint32_t behavior = 0; 764 uint32_t behavior = 0;
778 if (browser->tab_strip_model()->count() == 1) { 765 if (browser->tab_strip_model()->count() == 1) {
779 const content::WebContents* active_tab = 766 const content::WebContents* active_tab =
780 browser->tab_strip_model()->GetWebContentsAt(0); 767 browser->tab_strip_model()->GetWebContentsAt(0);
781 if (active_tab->GetURL() == GURL(chrome::kChromeUINewTabURL) || 768 if (active_tab->GetURL() == GURL(chrome::kChromeUINewTabURL) ||
782 search::IsInstantNTP(active_tab)) { 769 search::IsInstantNTP(active_tab)) {
783 // There is only one tab and its the new tab page, make session restore 770 // There is only one tab and its the new tab page, make session restore
784 // clobber it. 771 // clobber it.
785 behavior = SessionRestore::CLOBBER_CURRENT_TAB; 772 behavior = SessionRestore::CLOBBER_CURRENT_TAB;
786 } 773 }
787 } 774 }
788 SessionRestore::RestoreSession(browser->profile(), browser, 775 SessionRestore::RestoreSession(browser->profile(), browser, behavior,
789 browser->host_desktop_type(), behavior,
790 std::vector<GURL>()); 776 std::vector<GURL>());
791 } 777 }
792 778
793 // static 779 // static
794 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows( 780 std::vector<Browser*> SessionRestore::RestoreForeignSessionWindows(
795 Profile* profile, 781 Profile* profile,
796 chrome::HostDesktopType host_desktop_type,
797 std::vector<const sessions::SessionWindow*>::const_iterator begin, 782 std::vector<const sessions::SessionWindow*>::const_iterator begin,
798 std::vector<const sessions::SessionWindow*>::const_iterator end) { 783 std::vector<const sessions::SessionWindow*>::const_iterator end) {
799 std::vector<GURL> gurls; 784 std::vector<GURL> gurls;
800 SessionRestoreImpl restorer(profile, static_cast<Browser*>(nullptr), 785 SessionRestoreImpl restorer(profile, static_cast<Browser*>(nullptr), true,
801 host_desktop_type, true, false, true, gurls, 786 false, true, gurls,
802 on_session_restored_callbacks()); 787 on_session_restored_callbacks());
803 return restorer.RestoreForeignSession(begin, end); 788 return restorer.RestoreForeignSession(begin, end);
804 } 789 }
805 790
806 // static 791 // static
807 WebContents* SessionRestore::RestoreForeignSessionTab( 792 WebContents* SessionRestore::RestoreForeignSessionTab(
808 content::WebContents* source_web_contents, 793 content::WebContents* source_web_contents,
809 const sessions::SessionTab& tab, 794 const sessions::SessionTab& tab,
810 WindowOpenDisposition disposition) { 795 WindowOpenDisposition disposition) {
811 Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents); 796 Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents);
812 Profile* profile = browser->profile(); 797 Profile* profile = browser->profile();
813 std::vector<GURL> gurls; 798 std::vector<GURL> gurls;
814 SessionRestoreImpl restorer(profile, browser, browser->host_desktop_type(), 799 SessionRestoreImpl restorer(profile, browser, true, false, false, gurls,
815 true, false, false, gurls,
816 on_session_restored_callbacks()); 800 on_session_restored_callbacks());
817 return restorer.RestoreForeignTab(tab, disposition); 801 return restorer.RestoreForeignTab(tab, disposition);
818 } 802 }
819 803
820 // static 804 // static
821 bool SessionRestore::IsRestoring(const Profile* profile) { 805 bool SessionRestore::IsRestoring(const Profile* profile) {
822 if (active_session_restorers == nullptr) 806 if (active_session_restorers == nullptr)
823 return false; 807 return false;
824 for (std::set<SessionRestoreImpl*>::const_iterator it = 808 for (std::set<SessionRestoreImpl*>::const_iterator it =
825 active_session_restorers->begin(); 809 active_session_restorers->begin();
(...skipping 20 matching lines...) Expand all
846 // static 830 // static
847 SessionRestore::CallbackSubscription 831 SessionRestore::CallbackSubscription
848 SessionRestore::RegisterOnSessionRestoredCallback( 832 SessionRestore::RegisterOnSessionRestoredCallback(
849 const base::Callback<void(int)>& callback) { 833 const base::Callback<void(int)>& callback) {
850 return on_session_restored_callbacks()->Add(callback); 834 return on_session_restored_callbacks()->Add(callback);
851 } 835 }
852 836
853 // static 837 // static
854 base::CallbackList<void(int)>* 838 base::CallbackList<void(int)>*
855 SessionRestore::on_session_restored_callbacks_ = nullptr; 839 SessionRestore::on_session_restored_callbacks_ = nullptr;
OLDNEW
« no previous file with comments | « chrome/browser/sessions/session_restore.h ('k') | chrome/browser/sessions/session_restore_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698