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

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

Issue 2164033002: Refactoring startup logic for upcoming FRE changes (non-Win 10). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing getters to adders Created 4 years, 3 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 (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 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 5 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <memory> 11 #include <memory>
12 #include <vector> 12 #include <vector>
13 13
14 #include "apps/app_restore_service.h" 14 #include "apps/app_restore_service.h"
15 #include "apps/app_restore_service_factory.h" 15 #include "apps/app_restore_service_factory.h"
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/bind_helpers.h" 17 #include "base/bind_helpers.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/environment.h" 20 #include "base/environment.h"
21 #include "base/feature_list.h"
21 #include "base/lazy_instance.h" 22 #include "base/lazy_instance.h"
22 #include "base/metrics/histogram_macros.h" 23 #include "base/metrics/histogram_macros.h"
23 #include "base/metrics/statistics_recorder.h" 24 #include "base/metrics/statistics_recorder.h"
24 #include "base/strings/string_number_conversions.h" 25 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_split.h" 26 #include "base/strings/string_split.h"
26 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
27 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
28 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
29 #include "base/threading/thread_restrictions.h" 30 #include "base/threading/thread_restrictions.h"
30 #include "build/build_config.h" 31 #include "build/build_config.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #include "chrome/browser/ui/chrome_pages.h" 64 #include "chrome/browser/ui/chrome_pages.h"
64 #include "chrome/browser/ui/extensions/app_launch_params.h" 65 #include "chrome/browser/ui/extensions/app_launch_params.h"
65 #include "chrome/browser/ui/extensions/application_launch.h" 66 #include "chrome/browser/ui/extensions/application_launch.h"
66 #include "chrome/browser/ui/session_crashed_bubble.h" 67 #include "chrome/browser/ui/session_crashed_bubble.h"
67 #include "chrome/browser/ui/startup/bad_flags_prompt.h" 68 #include "chrome/browser/ui/startup/bad_flags_prompt.h"
68 #include "chrome/browser/ui/startup/default_browser_prompt.h" 69 #include "chrome/browser/ui/startup/default_browser_prompt.h"
69 #include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" 70 #include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h"
70 #include "chrome/browser/ui/startup/obsolete_system_infobar_delegate.h" 71 #include "chrome/browser/ui/startup/obsolete_system_infobar_delegate.h"
71 #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" 72 #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h"
72 #include "chrome/browser/ui/startup/startup_browser_creator.h" 73 #include "chrome/browser/ui/startup/startup_browser_creator.h"
74 #include "chrome/browser/ui/startup/startup_features.h"
73 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" 75 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
74 #include "chrome/browser/ui/tabs/tab_strip_model.h" 76 #include "chrome/browser/ui/tabs/tab_strip_model.h"
75 #include "chrome/common/chrome_constants.h" 77 #include "chrome/common/chrome_constants.h"
76 #include "chrome/common/chrome_paths.h" 78 #include "chrome/common/chrome_paths.h"
77 #include "chrome/common/chrome_result_codes.h" 79 #include "chrome/common/chrome_result_codes.h"
78 #include "chrome/common/chrome_switches.h" 80 #include "chrome/common/chrome_switches.h"
79 #include "chrome/common/extensions/extension_constants.h" 81 #include "chrome/common/extensions/extension_constants.h"
80 #include "chrome/common/extensions/extension_metrics.h" 82 #include "chrome/common/extensions/extension_metrics.h"
81 #include "chrome/common/pref_names.h" 83 #include "chrome/common/pref_names.h"
82 #include "chrome/common/url_constants.h" 84 #include "chrome/common/url_constants.h"
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 WebContents* app_tab = ::OpenAppShortcutWindow(profile, url); 496 WebContents* app_tab = ::OpenAppShortcutWindow(profile, url);
495 return (app_tab != NULL); 497 return (app_tab != NULL);
496 } 498 }
497 } 499 }
498 return false; 500 return false;
499 } 501 }
500 502
501 void StartupBrowserCreatorImpl::ProcessLaunchURLs( 503 void StartupBrowserCreatorImpl::ProcessLaunchURLs(
502 bool process_startup, 504 bool process_startup,
503 const std::vector<GURL>& urls_to_open) { 505 const std::vector<GURL>& urls_to_open) {
506 if (base::FeatureList::IsEnabled(features::kUseConsolidatedStartupFlow)) {
507 ProcessLaunchUrlsUsingConsolidatedFlow(process_startup, urls_to_open);
508 return;
509 }
510 // TODO(tmartino): Remainder of this function is deprecated. Remove when
511 // kUseConsolidatedStartupFlow is on by default.
512
504 // Don't open any browser windows if we're starting up in "background mode". 513 // Don't open any browser windows if we're starting up in "background mode".
505 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow)) 514 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow))
506 return; 515 return;
507 516
508 // Determine whether or not this launch must include the welcome page. 517 // Determine whether or not this launch must include the welcome page.
509 InitializeWelcomeRunType(urls_to_open); 518 InitializeWelcomeRunType(urls_to_open);
510 519
511 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor.
512 #if defined(OS_WIN)
513 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
514 // See if there are apps for this profile that should be launched on startup
515 // due to a switch from Metro mode.
516 app_metro_launch::HandleAppLaunchForMetroRestart(profile_);
517 }
518 #endif
519
520 if (process_startup && ProcessStartupURLs(urls_to_open)) { 520 if (process_startup && ProcessStartupURLs(urls_to_open)) {
521 // ProcessStartupURLs processed the urls, nothing else to do. 521 // ProcessStartupURLs processed the urls, nothing else to do.
522 return; 522 return;
523 } 523 }
524 524
525 chrome::startup::IsProcessStartup is_process_startup = process_startup ? 525 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
526 chrome::startup::IS_PROCESS_STARTUP : 526 chrome::startup::IS_PROCESS_STARTUP :
527 chrome::startup::IS_NOT_PROCESS_STARTUP; 527 chrome::startup::IS_NOT_PROCESS_STARTUP;
528 if (!process_startup) { 528 if (!process_startup) {
529 // Even if we're not starting a new process, this may conceptually be 529 // Even if we're not starting a new process, this may conceptually be
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 // Always open a list of urls in a window on the native desktop. 561 // Always open a list of urls in a window on the native desktop.
562 browser = chrome::FindTabbedBrowser(profile_, false); 562 browser = chrome::FindTabbedBrowser(profile_, false);
563 } 563 }
564 // This will launch a browser; prevent session restore. 564 // This will launch a browser; prevent session restore.
565 StartupBrowserCreator::in_synchronous_profile_launch_ = true; 565 StartupBrowserCreator::in_synchronous_profile_launch_ = true;
566 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls); 566 browser = OpenURLsInBrowser(browser, process_startup, adjusted_urls);
567 StartupBrowserCreator::in_synchronous_profile_launch_ = false; 567 StartupBrowserCreator::in_synchronous_profile_launch_ = false;
568 AddInfoBarsIfNecessary(browser, is_process_startup); 568 AddInfoBarsIfNecessary(browser, is_process_startup);
569 } 569 }
570 570
571 void StartupBrowserCreatorImpl::ProcessLaunchUrlsUsingConsolidatedFlow(
572 bool process_startup,
573 const std::vector<GURL>& cmd_line_urls) {
574 // Don't open any browser windows if starting up in "background mode".
575 if (process_startup && command_line_.HasSwitch(switches::kNoStartupWindow))
576 return;
577
578 // If command-line URLs were passed, they supercede all other policies and
579 // logic.
580 StartupTabs tabs;
581 if (!cmd_line_urls.empty()) {
582 UrlsToTabs(cmd_line_urls, &tabs);
583 } else {
584 std::unique_ptr<StartupTabProvider> provider(new StartupTabProviderImpl());
grt (UTC plus 2) 2016/09/12 07:28:46 regardless of whether you pass this instance to ca
585 bool is_incognito = IncognitoModePrefs::ShouldLaunchIncognito(
586 command_line_, profile_->GetPrefs());
587 bool is_crash = HasPendingUncleanExit(profile_);
588 tabs = DetermineStartupTabs(provider.get(), is_incognito, is_crash);
589 }
590
591 // TODO(tmartino): If this is not process startup, attempt to restore
592 // asynchronously and return here. This logic is self-contained in
593 // SessionService and therefore can't be combined with the other Browser
594 // creation logic.
595
596 // TODO(tmartino): Function which determines what behavior of session
597 // restore, if any, is necessary. Incorporates code from ProcessStartupUrls.
598
599 Browser* browser =
600 RestoreOrCreateBrowser(tabs
601 /* TODO(tmartino): Also pass behavior here */);
602
603 // Finally, add info bars.
604 AddInfoBarsIfNecessary(
605 browser, process_startup ? chrome::startup::IS_PROCESS_STARTUP
606 : chrome::startup::IS_NOT_PROCESS_STARTUP);
607 }
608
609 StartupTabs StartupBrowserCreatorImpl::DetermineStartupTabs(
610 const StartupTabProvider* provider,
611 bool is_incognito,
612 bool is_post_crash_launch) {
613 StartupTabs tabs;
614
615 // No policy- or profile-related content is shown in incognito mode.
616 // Similarly, when recovering from a crash, nothing should be opened
617 // automatically to prevent getting the user stuck in a crash loop.
618 if (!is_incognito && !is_post_crash_launch) {
grt (UTC plus 2) 2016/09/12 07:28:46 the body of this is so much easier to read than th
619 if (provider->AddDistributionFirstRunTabs(browser_creator_, &tabs)) {
620 // Master Preferences first run content overrides any other policy.
621 return tabs;
622 }
623
624 // Pinned tabs always appear as the leftmost tabs; insert at the beginning
625 // for consistency's sake.
626 provider->AddPinnedTabs(&tabs);
grt (UTC plus 2) 2016/09/12 07:28:46 how about adding a very brief comment for each of
627
628 provider->AddOnboardingTabs(&tabs);
629
630 provider->AddResetTriggerTabs(profile_, &tabs);
631
632 provider->AddPreferencesTabs(&tabs);
633 }
634
635 // Default to showing New Tab Page when nothing else is cued up.
636 if (tabs.empty())
637 tabs.push_back(StartupTab(GURL(chrome::kChromeUINewTabURL), 0));
grt (UTC plus 2) 2016/09/12 07:28:46 0 -> false
638
639 return tabs;
640 }
641
642 Browser* StartupBrowserCreatorImpl::RestoreOrCreateBrowser(StartupTabs tabs) {
grt (UTC plus 2) 2016/09/12 07:28:46 pass by constref
643 // TODO(tmartino): Based on passed behavior flag, possibly restore session
644 // instead of creating a new Browser.
645
646 return OpenTabsInBrowser(nullptr, true, tabs);
grt (UTC plus 2) 2016/09/12 07:28:46 why is |true| correct here rather than passing pro
647 }
648
571 bool StartupBrowserCreatorImpl::ProcessStartupURLs( 649 bool StartupBrowserCreatorImpl::ProcessStartupURLs(
572 const std::vector<GURL>& urls_to_open) { 650 const std::vector<GURL>& urls_to_open) {
573 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; 651 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs";
574 SessionStartupPref pref = 652 SessionStartupPref pref =
575 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); 653 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_);
576 if (pref.type == SessionStartupPref::LAST) 654 if (pref.type == SessionStartupPref::LAST)
577 VLOG(1) << "Pref: last"; 655 VLOG(1) << "Pref: last";
578 else if (pref.type == SessionStartupPref::URLS) 656 else if (pref.type == SessionStartupPref::URLS)
579 VLOG(1) << "Pref: urls"; 657 VLOG(1) << "Pref: urls";
580 else if (pref.type == SessionStartupPref::DEFAULT) 658 else if (pref.type == SessionStartupPref::DEFAULT)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 !HasPendingUncleanExit(profile_)) { 721 !HasPendingUncleanExit(profile_)) {
644 content::BrowserContext::GetDefaultStoragePartition(profile_)-> 722 content::BrowserContext::GetDefaultStoragePartition(profile_)->
645 GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); 723 GetDOMStorageContext()->StartScavengingUnusedSessionStorage();
646 } 724 }
647 725
648 return true; 726 return true;
649 } 727 }
650 728
651 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs( 729 Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs(
652 const std::vector<GURL>& urls_to_open) { 730 const std::vector<GURL>& urls_to_open) {
731 // TODO(tmartino): Deprecated, remove this once UseConsolidatedStartupFlow is
732 // enabled.
733
653 SessionStartupPref pref = 734 SessionStartupPref pref =
654 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); 735 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_);
655 StartupTabs tabs; 736 StartupTabs tabs;
656 // Pinned tabs should not be displayed when chrome is launched in incognito 737 // Pinned tabs should not be displayed when chrome is launched in incognito
657 // mode. Also, no pages should be opened automatically if the session 738 // mode. Also, no pages should be opened automatically if the session
658 // crashed. Otherwise it might trigger another crash, locking the user out of 739 // crashed. Otherwise it might trigger another crash, locking the user out of
659 // chrome. The crash infobar is shown in this case. 740 // chrome. The crash infobar is shown in this case.
660 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_, 741 if (!IncognitoModePrefs::ShouldLaunchIncognito(command_line_,
661 profile_->GetPrefs()) && 742 profile_->GetPrefs()) &&
662 !HasPendingUncleanExit(profile_)) { 743 !HasPendingUncleanExit(profile_)) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 browser_creator_->is_default_browser_dialog_suppressed())) { 903 browser_creator_->is_default_browser_dialog_suppressed())) {
823 chrome::ShowDefaultBrowserPrompt(profile_); 904 chrome::ShowDefaultBrowserPrompt(profile_);
824 } 905 }
825 } 906 }
826 #endif 907 #endif
827 } 908 }
828 } 909 }
829 910
830 void StartupBrowserCreatorImpl::AddStartupURLs( 911 void StartupBrowserCreatorImpl::AddStartupURLs(
831 std::vector<GURL>* startup_urls) const { 912 std::vector<GURL>* startup_urls) const {
832 // TODO(atwilson): Simplify the logic that decides which tabs to open on 913 // TODO(tmartino): Deprecated, remove this once UseConsolidatedStartupFlow is
833 // start-up and make it more consistent. http://crbug.com/248883 914 // enabled.
834 915
835 // If we have urls specified by the first run master preferences use them 916 // If we have urls specified by the first run master preferences use them
836 // and nothing else. 917 // and nothing else.
837 if (browser_creator_ && startup_urls->empty()) { 918 if (browser_creator_ && startup_urls->empty()) {
838 if (!browser_creator_->first_run_tabs_.empty()) { 919 if (!browser_creator_->first_run_tabs_.empty()) {
839 std::vector<GURL>::iterator it = 920 std::vector<GURL>::iterator it =
840 browser_creator_->first_run_tabs_.begin(); 921 browser_creator_->first_run_tabs_.begin();
841 while (it != browser_creator_->first_run_tabs_.end()) { 922 while (it != browser_creator_->first_run_tabs_.end()) {
842 // Replace magic names for the actual urls. 923 // Replace magic names for the actual urls.
843 if (it->host() == "new_tab_page") { 924 if (it->host() == "new_tab_page") {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) 970 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL))
890 startup_urls->at(0) = sync_promo_url; 971 startup_urls->at(0) = sync_promo_url;
891 else 972 else
892 startup_urls->insert(startup_urls->begin(), sync_promo_url); 973 startup_urls->insert(startup_urls->begin(), sync_promo_url);
893 } 974 }
894 } 975 }
895 } 976 }
896 977
897 void StartupBrowserCreatorImpl::AddSpecialURLs( 978 void StartupBrowserCreatorImpl::AddSpecialURLs(
898 std::vector<GURL>* url_list) const { 979 std::vector<GURL>* url_list) const {
980 // TODO(tmartino): Deprecated, remove this once UseConsolidatedStartupFlow is
981 // enabled.
982
899 // Optionally include the welcome page. 983 // Optionally include the welcome page.
900 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) 984 if (welcome_run_type_ == WelcomeRunType::FIRST_TAB)
901 url_list->insert(url_list->begin(), internals::GetWelcomePageURL()); 985 url_list->insert(url_list->begin(), internals::GetWelcomePageURL());
902 986
903 // If this Profile is marked for a reset prompt, ensure the reset 987 // If this Profile is marked for a reset prompt, ensure the reset
904 // settings dialog appears. 988 // settings dialog appears.
905 if (ProfileHasResetTrigger()) { 989 if (ProfileHasResetTrigger()) {
906 url_list->insert(url_list->begin(), 990 url_list->insert(url_list->begin(),
907 internals::GetTriggeredResetSettingsURL()); 991 internals::GetTriggeredResetSettingsURL());
908 } 992 }
909 } 993 }
910 994
911 // For first-run, the type will be FIRST_RUN_LAST for all systems except for 995 // For first-run, the type will be FIRST_RUN_LAST for all systems except for
912 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type 996 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type
913 // will be NONE for all systems except for Windows 10+, where it will be 997 // will be NONE for all systems except for Windows 10+, where it will be
914 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS 998 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS
915 // upgrade. 999 // upgrade.
1000
1001 // TODO(tmartino): Deprecated, remove this once UseConsolidatedStartupFlow is
1002 // enabled.
916 void StartupBrowserCreatorImpl::InitializeWelcomeRunType( 1003 void StartupBrowserCreatorImpl::InitializeWelcomeRunType(
917 const std::vector<GURL>& urls_to_open) { 1004 const std::vector<GURL>& urls_to_open) {
918 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE), 1005 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE),
919 static_cast<int>(welcome_run_type_)); 1006 static_cast<int>(welcome_run_type_));
920 #if defined(OS_WIN) 1007 #if defined(OS_WIN)
921 // Do not welcome if there are any URLs to open. 1008 // Do not welcome if there are any URLs to open.
922 if (!urls_to_open.empty()) 1009 if (!urls_to_open.empty())
923 return; 1010 return;
924 1011
925 base::win::OSInfo* const os_info = base::win::OSInfo::GetInstance(); 1012 base::win::OSInfo* const os_info = base::win::OSInfo::GetInstance();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 1067 }
981 1068
982 void StartupBrowserCreatorImpl::RecordRapporOnStartupURLs( 1069 void StartupBrowserCreatorImpl::RecordRapporOnStartupURLs(
983 const std::vector<GURL>& urls_to_open) { 1070 const std::vector<GURL>& urls_to_open) {
984 for (const GURL& url : urls_to_open) { 1071 for (const GURL& url : urls_to_open) {
985 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(), 1072 rappor::SampleDomainAndRegistryFromGURL(g_browser_process->rappor_service(),
986 "Startup.BrowserLaunchURL", url); 1073 "Startup.BrowserLaunchURL", url);
987 } 1074 }
988 } 1075 }
989 1076
1077 // TODO(tmartino): Deprecated, remove this once UseConsolidatedStartupFlow is
1078 // enabled.
990 bool StartupBrowserCreatorImpl::ProfileHasResetTrigger() const { 1079 bool StartupBrowserCreatorImpl::ProfileHasResetTrigger() const {
991 bool has_reset_trigger = false; 1080 bool has_reset_trigger = false;
992 #if defined(OS_WIN) 1081 #if defined(OS_WIN)
993 TriggeredProfileResetter* triggered_profile_resetter = 1082 TriggeredProfileResetter* triggered_profile_resetter =
994 TriggeredProfileResetterFactory::GetForBrowserContext(profile_); 1083 TriggeredProfileResetterFactory::GetForBrowserContext(profile_);
995 // TriggeredProfileResetter instance will be nullptr for incognito profiles. 1084 // TriggeredProfileResetter instance will be nullptr for incognito profiles.
996 if (triggered_profile_resetter) { 1085 if (triggered_profile_resetter) {
997 has_reset_trigger = triggered_profile_resetter->HasResetTrigger(); 1086 has_reset_trigger = triggered_profile_resetter->HasResetTrigger();
998 } 1087 }
999 #endif // defined(OS_WIN) 1088 #endif // defined(OS_WIN)
1000 return has_reset_trigger; 1089 return has_reset_trigger;
1001 } 1090 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698