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

Side by Side Diff: chrome/browser/first_run/first_run.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: Addressing rogerta feedback Created 4 years, 4 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/first_run/first_run.h" 5 #include "chrome/browser/first_run/first_run.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "build/build_config.h" 23 #include "build/build_config.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/chrome_notification_types.h" 25 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/extensions/extension_service.h" 26 #include "chrome/browser/extensions/extension_service.h"
27 #include "chrome/browser/extensions/updater/extension_updater.h" 27 #include "chrome/browser/extensions/updater/extension_updater.h"
28 #include "chrome/browser/first_run/first_run_features.h"
28 #include "chrome/browser/first_run/first_run_internal.h" 29 #include "chrome/browser/first_run/first_run_internal.h"
29 #include "chrome/browser/google/google_brand.h" 30 #include "chrome/browser/google/google_brand.h"
30 #include "chrome/browser/importer/external_process_importer_host.h" 31 #include "chrome/browser/importer/external_process_importer_host.h"
31 #include "chrome/browser/importer/importer_list.h" 32 #include "chrome/browser/importer/importer_list.h"
32 #include "chrome/browser/importer/importer_progress_observer.h" 33 #include "chrome/browser/importer/importer_progress_observer.h"
33 #include "chrome/browser/importer/importer_uma.h" 34 #include "chrome/browser/importer/importer_uma.h"
34 #include "chrome/browser/importer/profile_writer.h" 35 #include "chrome/browser/importer/profile_writer.h"
35 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 36 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
36 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/browser/profiles/profiles_state.h" 38 #include "chrome/browser/profiles/profiles_state.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #include "url/gurl.h" 76 #include "url/gurl.h"
76 77
77 namespace content { 78 namespace content {
78 class BrowserContext; 79 class BrowserContext;
79 } 80 }
80 81
81 using base::UserMetricsAction; 82 using base::UserMetricsAction;
82 83
83 namespace { 84 namespace {
84 85
86 // Constants: Magic words used by Master Prefs files to indicate that internal
87 // pages should appear on first run.
88 const char* kNewTabMagicWord = "new_tab_page";
grt (UTC plus 2) 2016/07/29 06:56:15 use "UrlHost" or something rather than "MagicWord"
grt (UTC plus 2) 2016/07/29 06:56:15 constexpr char kNewTabMagicWord[] = ...
grt (UTC plus 2) 2016/08/01 06:23:14 I find that "Keyword" is still vague. Neither the
tmartino 2016/08/02 23:46:50 Aha! In fact, I've been pointedly avoiding calling
grt (UTC plus 2) 2016/08/04 10:59:27 I see it from the other side: they are magic value
89 const char* kWelcomePageMagicWord = "welcome_page";
90
85 // A bitfield formed from values in AutoImportState to record the state of 91 // A bitfield formed from values in AutoImportState to record the state of
86 // AutoImport. This is used in testing to verify import startup actions that 92 // AutoImport. This is used in testing to verify import startup actions that
87 // occur before an observer can be registered in the test. 93 // occur before an observer can be registered in the test.
88 uint16_t g_auto_import_state = first_run::AUTO_IMPORT_NONE; 94 uint16_t g_auto_import_state = first_run::AUTO_IMPORT_NONE;
89 95
90 // Flags for functions of similar name. 96 // Flags for functions of similar name.
91 bool g_should_show_welcome_page = false; 97 bool g_should_show_welcome_page = false;
92 bool g_should_do_autofill_personal_data_manager_first_run = false; 98 bool g_should_do_autofill_personal_data_manager_first_run = false;
93 99
94 // This class acts as an observer for the ImporterProgressObserver::ImportEnded 100 // This class acts as an observer for the ImporterProgressObserver::ImportEnded
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 prefs::kDefaultBrowserSettingEnabled)) { 490 prefs::kDefaultBrowserSettingEnabled)) {
485 if (g_browser_process->local_state()->GetBoolean( 491 if (g_browser_process->local_state()->GetBoolean(
486 prefs::kDefaultBrowserSettingEnabled)) { 492 prefs::kDefaultBrowserSettingEnabled)) {
487 shell_integration::SetAsDefaultBrowser(); 493 shell_integration::SetAsDefaultBrowser();
488 } 494 }
489 } else if (make_chrome_default_for_user) { 495 } else if (make_chrome_default_for_user) {
490 shell_integration::SetAsDefaultBrowser(); 496 shell_integration::SetAsDefaultBrowser();
491 } 497 }
492 } 498 }
493 } 499 }
494
grt (UTC plus 2) 2016/07/29 06:56:15 nit: retain this blank line
495 } // namespace 500 } // namespace
496 501
497 namespace first_run { 502 namespace first_run {
498 namespace internal { 503 namespace internal {
499 504
500 FirstRunState g_first_run = FIRST_RUN_UNKNOWN; 505 FirstRunState g_first_run = FIRST_RUN_UNKNOWN;
501 506
502 void SetupMasterPrefsFromInstallPrefs( 507 void SetupMasterPrefsFromInstallPrefs(
503 const installer::MasterPreferences& install_prefs, 508 const installer::MasterPreferences& install_prefs,
504 MasterPrefs* out_prefs) { 509 MasterPrefs* out_prefs) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 base::CommandLine::ForCurrentProcess(); 645 base::CommandLine::ForCurrentProcess();
641 if (command_line->HasSwitch(switches::kForceFirstRun) || 646 if (command_line->HasSwitch(switches::kForceFirstRun) ||
642 (!command_line->HasSwitch(switches::kNoFirstRun) && 647 (!command_line->HasSwitch(switches::kNoFirstRun) &&
643 !internal::IsFirstRunSentinelPresent())) { 648 !internal::IsFirstRunSentinelPresent())) {
644 internal::g_first_run = internal::FIRST_RUN_TRUE; 649 internal::g_first_run = internal::FIRST_RUN_TRUE;
645 } 650 }
646 } 651 }
647 return internal::g_first_run == internal::FIRST_RUN_TRUE; 652 return internal::g_first_run == internal::FIRST_RUN_TRUE;
648 } 653 }
649 654
655 void SetFirstRunForTesting(bool is_first_run) {
656 internal::g_first_run =
657 is_first_run ? internal::FIRST_RUN_TRUE : internal::FIRST_RUN_FALSE;
658 }
659
650 #if defined(OS_MACOSX) 660 #if defined(OS_MACOSX)
651 bool IsFirstRunSuppressed(const base::CommandLine& command_line) { 661 bool IsFirstRunSuppressed(const base::CommandLine& command_line) {
652 return command_line.HasSwitch(switches::kNoFirstRun); 662 return command_line.HasSwitch(switches::kNoFirstRun);
653 } 663 }
654 #endif 664 #endif
655 665
656 bool IsMetricsReportingOptIn() { 666 bool IsMetricsReportingOptIn() {
657 #if defined(OS_CHROMEOS) 667 #if defined(OS_CHROMEOS)
658 return false; 668 return false;
659 #elif defined(OS_ANDROID) 669 #elif defined(OS_ANDROID)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 void SetShouldShowWelcomePage() { 717 void SetShouldShowWelcomePage() {
708 g_should_show_welcome_page = true; 718 g_should_show_welcome_page = true;
709 } 719 }
710 720
711 bool ShouldShowWelcomePage() { 721 bool ShouldShowWelcomePage() {
712 bool retval = g_should_show_welcome_page; 722 bool retval = g_should_show_welcome_page;
713 g_should_show_welcome_page = false; 723 g_should_show_welcome_page = false;
714 return retval; 724 return retval;
715 } 725 }
716 726
727 GURL GetWelcomePageURL() {
728 // TODO(tmartino): Once Consolidated FRE page is implemented, return that
729 // here when kUseConsolidatedFirstRun is true.
730 return GURL(l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL));
731 }
732
733 bool IsWin10() {
734 #if defined(OS_WIN)
735 return os_info->version() >= base::win::VERSION_WIN10;
grt (UTC plus 2) 2016/07/29 06:56:15 base::win::GetVersion() and #include "base/win/wi
736 #else
737 return false;
738 #endif
739 }
740
741 std::vector<GURL> GetOnboardingTabs() {
742 std::vector<GURL> tabs;
743 if (IsWin10()) {
744 // TODO(tmartino): Win 10 logic is more complex and will be added in its
745 // own change.
746 } else if (IsChromeFirstRun()) {
747 tabs.push_back(GetWelcomePageURL());
748 }
749 return tabs;
750 }
751
752 std::vector<GURL> ProcessMasterPrefsTabs(const std::vector<GURL>& tabs) {
753 std::vector<GURL> processed_tabs;
754 if (IsChromeFirstRun()) {
755 for (GURL tab : tabs) {
grt (UTC plus 2) 2016/07/29 06:56:15 const GURL& tab to avoid a copy here
756 if (tab.host() == kNewTabMagicWord) {
757 processed_tabs.push_back(GURL(chrome::kChromeUINewTabURL));
758 } else if (tab.host() == kWelcomePageMagicWord) {
759 processed_tabs.push_back(GetWelcomePageURL());
760 } else {
761 processed_tabs.push_back(tab);
762 }
763 }
764 }
765 return processed_tabs;
766 }
767
717 void SetShouldDoPersonalDataManagerFirstRun() { 768 void SetShouldDoPersonalDataManagerFirstRun() {
718 g_should_do_autofill_personal_data_manager_first_run = true; 769 g_should_do_autofill_personal_data_manager_first_run = true;
719 } 770 }
720 771
721 bool ShouldDoPersonalDataManagerFirstRun() { 772 bool ShouldDoPersonalDataManagerFirstRun() {
722 bool retval = g_should_do_autofill_personal_data_manager_first_run; 773 bool retval = g_should_do_autofill_personal_data_manager_first_run;
723 g_should_do_autofill_personal_data_manager_first_run = false; 774 g_should_do_autofill_personal_data_manager_first_run = false;
724 return retval; 775 return retval;
725 } 776 }
726 777
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 SetShouldDoPersonalDataManagerFirstRun(); 909 SetShouldDoPersonalDataManagerFirstRun();
859 910
860 internal::DoPostImportPlatformSpecificTasks(profile); 911 internal::DoPostImportPlatformSpecificTasks(profile);
861 } 912 }
862 913
863 uint16_t auto_import_state() { 914 uint16_t auto_import_state() {
864 return g_auto_import_state; 915 return g_auto_import_state;
865 } 916 }
866 917
867 } // namespace first_run 918 } // namespace first_run
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698