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

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

Issue 1226643002: Welcome page changes for Windows 10 and over. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplified recording of welcome run complete Created 5 years, 5 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 <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "apps/app_restore_service.h" 10 #include "apps/app_restore_service.h"
11 #include "apps/app_restore_service_factory.h" 11 #include "apps/app_restore_service_factory.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/environment.h" 16 #include "base/environment.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/metrics/statistics_recorder.h" 20 #include "base/metrics/statistics_recorder.h"
21 #include "base/prefs/pref_service.h" 21 #include "base/prefs/pref_service.h"
22 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
23 #include "base/strings/string_split.h" 23 #include "base/strings/string_split.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/thread_restrictions.h" 27 #include "base/threading/thread_restrictions.h"
27 #include "chrome/browser/apps/install_chrome_app.h" 28 #include "chrome/browser/apps/install_chrome_app.h"
28 #include "chrome/browser/auto_launch_trial.h" 29 #include "chrome/browser/auto_launch_trial.h"
29 #include "chrome/browser/browser_process.h" 30 #include "chrome/browser/browser_process.h"
30 #include "chrome/browser/chrome_notification_types.h" 31 #include "chrome/browser/chrome_notification_types.h"
31 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" 32 #include "chrome/browser/custom_handlers/protocol_handler_registry.h"
32 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" 33 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
33 #include "chrome/browser/defaults.h" 34 #include "chrome/browser/defaults.h"
34 #include "chrome/browser/extensions/extension_creator.h" 35 #include "chrome/browser/extensions/extension_creator.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 #include "chrome/browser/ui/startup/startup_browser_creator.h" 70 #include "chrome/browser/ui/startup/startup_browser_creator.h"
70 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" 71 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
71 #include "chrome/browser/ui/tabs/tab_strip_model.h" 72 #include "chrome/browser/ui/tabs/tab_strip_model.h"
72 #include "chrome/common/chrome_constants.h" 73 #include "chrome/common/chrome_constants.h"
73 #include "chrome/common/chrome_paths.h" 74 #include "chrome/common/chrome_paths.h"
74 #include "chrome/common/chrome_result_codes.h" 75 #include "chrome/common/chrome_result_codes.h"
75 #include "chrome/common/chrome_switches.h" 76 #include "chrome/common/chrome_switches.h"
76 #include "chrome/common/chrome_version_info.h" 77 #include "chrome/common/chrome_version_info.h"
77 #include "chrome/common/extensions/extension_constants.h" 78 #include "chrome/common/extensions/extension_constants.h"
78 #include "chrome/common/extensions/extension_metrics.h" 79 #include "chrome/common/extensions/extension_metrics.h"
80 #include "chrome/common/pref_names.h"
79 #include "chrome/common/url_constants.h" 81 #include "chrome/common/url_constants.h"
80 #include "chrome/grit/locale_settings.h" 82 #include "chrome/grit/locale_settings.h"
81 #include "chrome/installer/util/browser_distribution.h" 83 #include "chrome/installer/util/browser_distribution.h"
82 #include "components/google/core/browser/google_util.h" 84 #include "components/google/core/browser/google_util.h"
83 #include "content/public/browser/child_process_security_policy.h" 85 #include "content/public/browser/child_process_security_policy.h"
84 #include "content/public/browser/dom_storage_context.h" 86 #include "content/public/browser/dom_storage_context.h"
85 #include "content/public/browser/notification_observer.h" 87 #include "content/public/browser/notification_observer.h"
86 #include "content/public/browser/notification_registrar.h" 88 #include "content/public/browser/notification_registrar.h"
87 #include "content/public/browser/storage_partition.h" 89 #include "content/public/browser/storage_partition.h"
88 #include "content/public/browser/web_contents.h" 90 #include "content/public/browser/web_contents.h"
89 #include "extensions/browser/extension_prefs.h" 91 #include "extensions/browser/extension_prefs.h"
90 #include "extensions/browser/extension_registry.h" 92 #include "extensions/browser/extension_registry.h"
91 #include "extensions/common/constants.h" 93 #include "extensions/common/constants.h"
92 #include "extensions/common/extension.h" 94 #include "extensions/common/extension.h"
93 #include "extensions/common/extension_set.h" 95 #include "extensions/common/extension_set.h"
96 #include "net/base/network_change_notifier.h"
94 #include "ui/base/l10n/l10n_util.h" 97 #include "ui/base/l10n/l10n_util.h"
95 98
96 #if defined(OS_MACOSX) 99 #if defined(OS_MACOSX)
97 #include "base/mac/mac_util.h" 100 #include "base/mac/mac_util.h"
98 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" 101 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h"
99 #endif 102 #endif
100 103
101 #if defined(OS_WIN) 104 #if defined(OS_WIN)
102 #include "base/win/windows_version.h" 105 #include "base/win/windows_version.h"
103 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" 106 #include "chrome/browser/apps/app_launch_for_metro_restart_win.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } // namespace internals 293 } // namespace internals
291 294
292 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( 295 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
293 const base::FilePath& cur_dir, 296 const base::FilePath& cur_dir,
294 const base::CommandLine& command_line, 297 const base::CommandLine& command_line,
295 chrome::startup::IsFirstRun is_first_run) 298 chrome::startup::IsFirstRun is_first_run)
296 : cur_dir_(cur_dir), 299 : cur_dir_(cur_dir),
297 command_line_(command_line), 300 command_line_(command_line),
298 profile_(NULL), 301 profile_(NULL),
299 browser_creator_(NULL), 302 browser_creator_(NULL),
300 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { 303 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN),
304 welcome_run_type_(WelcomeRunType::NONE) {
301 } 305 }
302 306
303 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl( 307 StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
304 const base::FilePath& cur_dir, 308 const base::FilePath& cur_dir,
305 const base::CommandLine& command_line, 309 const base::CommandLine& command_line,
306 StartupBrowserCreator* browser_creator, 310 StartupBrowserCreator* browser_creator,
307 chrome::startup::IsFirstRun is_first_run) 311 chrome::startup::IsFirstRun is_first_run)
308 : cur_dir_(cur_dir), 312 : cur_dir_(cur_dir),
309 command_line_(command_line), 313 command_line_(command_line),
310 profile_(NULL), 314 profile_(NULL),
311 browser_creator_(browser_creator), 315 browser_creator_(browser_creator),
312 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) { 316 is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN),
317 welcome_run_type_(WelcomeRunType::NONE) {
313 } 318 }
314 319
315 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() { 320 StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() {
316 } 321 }
317 322
318 bool StartupBrowserCreatorImpl::Launch(Profile* profile, 323 bool StartupBrowserCreatorImpl::Launch(Profile* profile,
319 const std::vector<GURL>& urls_to_open, 324 const std::vector<GURL>& urls_to_open,
320 bool process_startup, 325 bool process_startup,
321 chrome::HostDesktopType desktop_type) { 326 chrome::HostDesktopType desktop_type) {
322 DCHECK(profile); 327 DCHECK(profile);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 chrome::HostDesktopType desktop_type) { 533 chrome::HostDesktopType desktop_type) {
529 // If we're starting up in "background mode" (no open browser window) then 534 // If we're starting up in "background mode" (no open browser window) then
530 // don't open any browser windows, unless kAutoLaunchAtStartup is also 535 // don't open any browser windows, unless kAutoLaunchAtStartup is also
531 // specified. 536 // specified.
532 if (process_startup && 537 if (process_startup &&
533 command_line_.HasSwitch(switches::kNoStartupWindow) && 538 command_line_.HasSwitch(switches::kNoStartupWindow) &&
534 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) { 539 !command_line_.HasSwitch(switches::kAutoLaunchAtStartup)) {
535 return; 540 return;
536 } 541 }
537 542
543 // Determine whether or not this launch must include the welcome page.
544 InitializeWelcomeRunType(urls_to_open);
545
538 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor. 546 // TODO(tapted): Move this to startup_browser_creator_win.cc after refactor.
539 #if defined(OS_WIN) 547 #if defined(OS_WIN)
540 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { 548 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
541 // See if there are apps for this profile that should be launched on startup 549 // See if there are apps for this profile that should be launched on startup
542 // due to a switch from Metro mode. 550 // due to a switch from Metro mode.
543 app_metro_launch::HandleAppLaunchForMetroRestart(profile_); 551 app_metro_launch::HandleAppLaunchForMetroRestart(profile_);
544 } 552 }
545 #endif 553 #endif
546 554
547 if (process_startup && ProcessStartupURLs(urls_to_open, desktop_type)) { 555 if (process_startup && ProcessStartupURLs(urls_to_open, desktop_type)) {
548 // ProcessStartupURLs processed the urls, nothing else to do. 556 // ProcessStartupURLs processed the urls, nothing else to do.
549 return; 557 return;
550 } 558 }
551 559
552 chrome::startup::IsProcessStartup is_process_startup = process_startup ? 560 chrome::startup::IsProcessStartup is_process_startup = process_startup ?
553 chrome::startup::IS_PROCESS_STARTUP : 561 chrome::startup::IS_PROCESS_STARTUP :
554 chrome::startup::IS_NOT_PROCESS_STARTUP; 562 chrome::startup::IS_NOT_PROCESS_STARTUP;
555 if (!process_startup) { 563 if (!process_startup) {
556 // Even if we're not starting a new process, this may conceptually be 564 // Even if we're not starting a new process, this may conceptually be
557 // "startup" for the user and so should be handled in a similar way. Eg., 565 // "startup" for the user and so should be handled in a similar way. Eg.,
558 // Chrome may have been running in the background due to an app with a 566 // Chrome may have been running in the background due to an app with a
559 // background page being installed, or running with only an app window 567 // background page being installed, or running with only an app window
560 // displayed. 568 // displayed.
561 SessionService* service = 569 SessionService* service =
562 SessionServiceFactory::GetForProfileForSessionRestore(profile_); 570 SessionServiceFactory::GetForProfileForSessionRestore(profile_);
563 if (service && service->ShouldNewWindowStartSession()) { 571 if (service && service->ShouldNewWindowStartSession()) {
564 // Restore the last session if any. 572 // Restore the last session if any, optionally including the welcome page
565 if (!HasPendingUncleanExit(profile_) && 573 // if desired.
566 service->RestoreIfNecessary(urls_to_open)) { 574 if (!HasPendingUncleanExit(profile_)) {
567 return; 575 std::vector<GURL> adjusted_urls(urls_to_open);
576 if (welcome_run_type_ != WelcomeRunType::NONE) {
577 adjusted_urls.insert(adjusted_urls.begin(),
msw 2015/07/10 22:07:32 Could this be inserting the page at the front for
grt (UTC plus 2) 2015/07/11 12:16:08 This change started with a simple helper like that
578 internals::GetWelcomePageURL());
579 }
580 if (service->RestoreIfNecessary(adjusted_urls))
581 return;
568 } 582 }
583
569 // Open user-specified URLs like pinned tabs and startup tabs. 584 // Open user-specified URLs like pinned tabs and startup tabs.
570 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); 585 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type);
571 if (browser) { 586 if (browser) {
572 AddInfoBarsIfNecessary(browser, is_process_startup); 587 AddInfoBarsIfNecessary(browser, is_process_startup);
573 return; 588 return;
574 } 589 }
575 } 590 }
576 } 591 }
577 592
578 // Session startup didn't occur, open the urls. 593 // Session startup didn't occur, open the urls.
579 Browser* browser = NULL; 594 Browser* browser = NULL;
580 std::vector<GURL> adjust_urls = urls_to_open; 595 std::vector<GURL> adjusted_urls = urls_to_open;
581 if (adjust_urls.empty()) { 596 if (adjusted_urls.empty()) {
582 AddStartupURLs(&adjust_urls); 597 AddStartupURLs(&adjusted_urls);
583 } else if (!command_line_.HasSwitch(switches::kOpenInNewWindow)) { 598 } else if (!command_line_.HasSwitch(switches::kOpenInNewWindow)) {
584 // Always open a list of urls in a window on the native desktop. 599 // Always open a list of urls in a window on the native desktop.
585 browser = chrome::FindTabbedBrowser(profile_, false, 600 browser = chrome::FindTabbedBrowser(profile_, false,
586 chrome::HOST_DESKTOP_TYPE_NATIVE); 601 chrome::HOST_DESKTOP_TYPE_NATIVE);
587 } 602 }
588 // This will launch a browser; prevent session restore. 603 // This will launch a browser; prevent session restore.
589 StartupBrowserCreator::in_synchronous_profile_launch_ = true; 604 StartupBrowserCreator::in_synchronous_profile_launch_ = true;
590 browser = OpenURLsInBrowser(browser, process_startup, adjust_urls, 605 browser =
591 desktop_type); 606 OpenURLsInBrowser(browser, process_startup, adjusted_urls, desktop_type);
592 StartupBrowserCreator::in_synchronous_profile_launch_ = false; 607 StartupBrowserCreator::in_synchronous_profile_launch_ = false;
593 AddInfoBarsIfNecessary(browser, is_process_startup); 608 AddInfoBarsIfNecessary(browser, is_process_startup);
594 } 609 }
595 610
596 bool StartupBrowserCreatorImpl::ProcessStartupURLs( 611 bool StartupBrowserCreatorImpl::ProcessStartupURLs(
597 const std::vector<GURL>& urls_to_open, 612 const std::vector<GURL>& urls_to_open,
598 chrome::HostDesktopType desktop_type) { 613 chrome::HostDesktopType desktop_type) {
599 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs"; 614 VLOG(1) << "StartupBrowserCreatorImpl::ProcessStartupURLs";
600 SessionStartupPref pref = 615 SessionStartupPref pref =
601 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_); 616 StartupBrowserCreator::GetSessionStartupPref(command_line_, profile_);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 #if defined(OS_MACOSX) 650 #if defined(OS_MACOSX)
636 // On Mac, when restoring a session with no windows, suppress the creation 651 // On Mac, when restoring a session with no windows, suppress the creation
637 // of a new window in the case where the system is launching Chrome via a 652 // of a new window in the case where the system is launching Chrome via a
638 // login item or Lion's resume feature. 653 // login item or Lion's resume feature.
639 if (base::mac::WasLaunchedAsLoginOrResumeItem()) { 654 if (base::mac::WasLaunchedAsLoginOrResumeItem()) {
640 restore_behavior = restore_behavior & 655 restore_behavior = restore_behavior &
641 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER; 656 ~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER;
642 } 657 }
643 #endif 658 #endif
644 659
660 // Optionally include the welcome page.
661 std::vector<GURL> adjusted_urls(urls_to_open);
662 if (welcome_run_type_ != WelcomeRunType::NONE) {
663 adjusted_urls.insert(adjusted_urls.begin(),
msw 2015/07/10 22:07:32 Why is this always inserting first, why doesn't th
grt (UTC plus 2) 2015/07/11 12:16:08 This is handling session restore rather than first
664 internals::GetWelcomePageURL());
665 }
666
645 // The startup code only executes for browsers launched in desktop mode. 667 // The startup code only executes for browsers launched in desktop mode.
646 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here. 668 // i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here.
647 Browser* browser = SessionRestore::RestoreSession( 669 Browser* browser = SessionRestore::RestoreSession(
648 profile_, NULL, desktop_type, restore_behavior, 670 profile_, NULL, desktop_type, restore_behavior, adjusted_urls);
649 urls_to_open);
650 671
651 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); 672 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
652 return true; 673 return true;
653 } 674 }
654 675
655 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type); 676 Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type);
656 if (!browser) 677 if (!browser)
657 return false; 678 return false;
658 679
659 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP); 680 AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 // If urls were specified on the command line, use them. 713 // If urls were specified on the command line, use them.
693 UrlsToTabs(urls_to_open, &tabs); 714 UrlsToTabs(urls_to_open, &tabs);
694 } else if (pref.type == SessionStartupPref::DEFAULT || 715 } else if (pref.type == SessionStartupPref::DEFAULT ||
695 (is_first_run_ && 716 (is_first_run_ &&
696 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) { 717 browser_creator_ && !browser_creator_->first_run_tabs_.empty())) {
697 std::vector<GURL> urls; 718 std::vector<GURL> urls;
698 AddStartupURLs(&urls); 719 AddStartupURLs(&urls);
699 UrlsToTabs(urls, &tabs); 720 UrlsToTabs(urls, &tabs);
700 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() && 721 } else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() &&
701 !HasPendingUncleanExit(profile_)) { 722 !HasPendingUncleanExit(profile_)) {
723 // Optionally include the welcome page first.
724 if (welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST)
msw 2015/07/10 22:07:32 Ditto: Why doesn't this need to handle FIRST_RUN_*
grt (UTC plus 2) 2015/07/11 12:16:08 Because this isn't a first-run codepath.
725 UrlsToTabs(std::vector<GURL>(1, internals::GetWelcomePageURL()), &tabs);
702 // Only use the set of urls specified in preferences if nothing was 726 // Only use the set of urls specified in preferences if nothing was
703 // specified on the command line. Filter out any urls that are to be 727 // specified on the command line. Filter out any urls that are to be
704 // restored by virtue of having been previously pinned. 728 // restored by virtue of having been previously pinned.
705 AddUniqueURLs(pref.urls, &tabs); 729 AddUniqueURLs(pref.urls, &tabs);
706 } else if (pref.type == SessionStartupPref::HOMEPAGE) { 730 } else if (pref.type == SessionStartupPref::HOMEPAGE) {
707 // If 'homepage' selected, either by the user or by a policy, we should 731 // If 'homepage' selected, either by the user or by a policy, we should
708 // have migrated them to another value. 732 // have migrated them to another value.
709 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE"; 733 NOTREACHED() << "SessionStartupPref has deprecated type HOMEPAGE";
710 } 734 }
711 735
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 startup_urls->push_back(internals::GetWelcomePageURL()); 897 startup_urls->push_back(internals::GetWelcomePageURL());
874 } else { 898 } else {
875 startup_urls->push_back(*it); 899 startup_urls->push_back(*it);
876 } 900 }
877 ++it; 901 ++it;
878 } 902 }
879 browser_creator_->first_run_tabs_.clear(); 903 browser_creator_->first_run_tabs_.clear();
880 } 904 }
881 } 905 }
882 906
883 // Otherwise open at least the new tab page (and the welcome page, if this 907 // Otherwise open at least the new tab page (and optionally the welcome page
884 // is the first time the browser is being started), or the set of URLs 908 // at the front or back as indicated by welcome_run_type_), or the set of URLs
885 // specified on the command line. 909 // specified on the command line.
886 if (startup_urls->empty()) { 910 if (startup_urls->empty()) {
911 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_FIRST ||
912 welcome_run_type_ == WelcomeRunType::ANY_RUN_FIRST) {
913 startup_urls->push_back(internals::GetWelcomePageURL());
914 }
887 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL)); 915 startup_urls->push_back(GURL(chrome::kChromeUINewTabURL));
888 if (first_run::ShouldShowWelcomePage()) 916 if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_LAST)
889 startup_urls->push_back(internals::GetWelcomePageURL()); 917 startup_urls->push_back(internals::GetWelcomePageURL());
890 } 918 }
891 919
892 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) { 920 if (signin::ShouldShowPromoAtStartup(profile_, is_first_run_)) {
893 signin::DidShowPromoAtStartup(profile_); 921 signin::DidShowPromoAtStartup(profile_);
894 922
895 const GURL sync_promo_url = signin::GetPromoURL( 923 const GURL sync_promo_url = signin::GetPromoURL(
896 signin_metrics::SOURCE_START_PAGE, false); 924 signin_metrics::SOURCE_START_PAGE, false);
897 925
898 // No need to add if the sync promo is already in the startup list. 926 // No need to add if the sync promo is already in the startup list.
(...skipping 11 matching lines...) Expand all
910 // behavior is desired because completing or skipping the sync promo 938 // behavior is desired because completing or skipping the sync promo
911 // causes a redirect to the NTP. 939 // causes a redirect to the NTP.
912 if (!startup_urls->empty() && 940 if (!startup_urls->empty() &&
913 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL)) 941 startup_urls->at(0) == GURL(chrome::kChromeUINewTabURL))
914 startup_urls->at(0) = sync_promo_url; 942 startup_urls->at(0) = sync_promo_url;
915 else 943 else
916 startup_urls->insert(startup_urls->begin(), sync_promo_url); 944 startup_urls->insert(startup_urls->begin(), sync_promo_url);
917 } 945 }
918 } 946 }
919 } 947 }
948
949 // For first-run, the type will be FIRST_RUN_LAST for all systems except for
950 // Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type
951 // will be NONE for all systems except for Windows 10+, where it will be
952 // ANY_RUN_FIRST if this is the first somewhat normal launch since an OS
953 // upgrade.
954 void StartupBrowserCreatorImpl::InitializeWelcomeRunType(
955 const std::vector<GURL>& urls_to_open) {
956 DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE),
957 static_cast<int>(welcome_run_type_));
958 #if defined(OS_WIN)
959 // Do not welcome if there are any URLs to open.
960 if (!urls_to_open.empty())
961 return;
962
963 base::win::OSInfo* const os_info = base::win::OSInfo::GetInstance();
964 const base::win::OSInfo::VersionNumber v(os_info->version_number());
965 const std::string this_version(base::StringPrintf("%d.%d", v.major, v.minor));
966 PrefService* const local_state = g_browser_process->local_state();
967
968 // Always welcome on first run.
969 if (first_run::ShouldShowWelcomePage()) {
970 // First tab for Win10+, last tab otherwise.
971 welcome_run_type_ = os_info->version() >= base::win::VERSION_WIN10
972 ? WelcomeRunType::FIRST_RUN_FIRST
msw 2015/07/10 22:07:32 It would be better to reduce the enum to NONE/FIRS
grt (UTC plus 2) 2015/07/11 12:16:08 I'll take a stab at it in the next patch set to se
grt (UTC plus 2) 2015/07/13 15:10:07 It turned out to be quite simple. PTAL.
973 : WelcomeRunType::FIRST_RUN_LAST;
msw 2015/07/10 22:07:32 I don't think you ever addressed my question: Bett
grt (UTC plus 2) 2015/07/11 12:16:08 Because this is what the product deciders have dec
msw 2015/07/13 19:16:05 Then let's double check with the deciders [sic]. W
974 } else {
975 // Otherwise, do not welcome pre-Win10.
976 if (base::win::GetVersion() < base::win::VERSION_WIN10)
977 return;
978
979 // Do not welcome if launching into incognito.
980 if (IncognitoModePrefs::ShouldLaunchIncognito(command_line_,
981 profile_->GetPrefs())) {
982 return;
983 }
984
985 // Do not welcome if there is no local state (tests).
986 if (!local_state)
987 return;
988
989 // Do not welcome if disabled by policy or master_preferences.
990 if (!local_state->GetBoolean(prefs::kWelcomePageOnOSUpgradeEnabled))
991 return;
992
993 // Do not welcome if already shown for this OS version.
994 if (local_state->GetString(prefs::kLastWelcomedOSVersion) == this_version)
995 return;
996
997 // Do not welcome if offline.
998 if (net::NetworkChangeNotifier::IsOffline())
999 return;
1000
1001 // Do not welcome if Chrome was the default browser at startup.
1002 if (g_browser_process->CachedDefaultWebClientState() ==
1003 ShellIntegration::IS_DEFAULT) {
1004 return;
1005 }
1006
1007 // Show the welcome page in the first tab.
1008 welcome_run_type_ = WelcomeRunType::ANY_RUN_FIRST;
1009 }
1010
1011 // Remember that the welcome page was shown for this OS version.
1012 local_state->SetString(prefs::kLastWelcomedOSVersion, this_version);
msw 2015/07/10 22:07:32 By inlining RecordWelcomeRunComplete here, that pr
grt (UTC plus 2) 2015/07/11 12:16:08 A potentially stale value is only alive for the li
msw 2015/07/13 19:16:05 I think it's okay as-is, but I don't feel too stro
1013 #else // OS_WIN
1014 // Show the welcome page as the last tab only on first-run.
1015 if (first_run::ShouldShowWelcomePage())
1016 welcome_run_type_ = WelcomeRunType::FIRST_RUN_LAST;
1017 #endif // !OS_WIN
1018 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698