OLD | NEW |
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 29 matching lines...) Expand all Loading... |
67 #include "content/public/browser/notification_service.h" | 68 #include "content/public/browser/notification_service.h" |
68 #include "content/public/browser/notification_types.h" | 69 #include "content/public/browser/notification_types.h" |
69 #include "content/public/browser/user_metrics.h" | 70 #include "content/public/browser/user_metrics.h" |
70 #include "content/public/browser/web_contents.h" | 71 #include "content/public/browser/web_contents.h" |
71 #include "extensions/browser/extension_system.h" | 72 #include "extensions/browser/extension_system.h" |
72 #include "extensions/common/one_shot_event.h" | 73 #include "extensions/common/one_shot_event.h" |
73 #include "google_apis/gaia/gaia_auth_util.h" | 74 #include "google_apis/gaia/gaia_auth_util.h" |
74 #include "ui/base/l10n/l10n_util.h" | 75 #include "ui/base/l10n/l10n_util.h" |
75 #include "url/gurl.h" | 76 #include "url/gurl.h" |
76 | 77 |
| 78 #if defined(OS_WIN) |
| 79 #include "base/win/windows_version.h" |
| 80 #endif |
| 81 |
77 namespace content { | 82 namespace content { |
78 class BrowserContext; | 83 class BrowserContext; |
79 } | 84 } |
80 | 85 |
81 using base::UserMetricsAction; | 86 using base::UserMetricsAction; |
82 | 87 |
83 namespace { | 88 namespace { |
84 | 89 |
| 90 // Constants: Magic words used by Master Prefs files to indicate that internal |
| 91 // pages should appear on first run. |
| 92 constexpr char kNewTabKeyword[] = "new_tab_page"; |
| 93 constexpr char kWelcomePageKeyword[] = "welcome_page"; |
| 94 |
85 // A bitfield formed from values in AutoImportState to record the state of | 95 // 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 | 96 // AutoImport. This is used in testing to verify import startup actions that |
87 // occur before an observer can be registered in the test. | 97 // occur before an observer can be registered in the test. |
88 uint16_t g_auto_import_state = first_run::AUTO_IMPORT_NONE; | 98 uint16_t g_auto_import_state = first_run::AUTO_IMPORT_NONE; |
89 | 99 |
90 // Flags for functions of similar name. | 100 // Flags for functions of similar name. |
91 bool g_should_show_welcome_page = false; | 101 bool g_should_show_welcome_page = false; |
92 bool g_should_do_autofill_personal_data_manager_first_run = false; | 102 bool g_should_do_autofill_personal_data_manager_first_run = false; |
93 | 103 |
94 // This class acts as an observer for the ImporterProgressObserver::ImportEnded | 104 // This class acts as an observer for the ImporterProgressObserver::ImportEnded |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 if (g_browser_process->local_state()->GetBoolean( | 495 if (g_browser_process->local_state()->GetBoolean( |
486 prefs::kDefaultBrowserSettingEnabled)) { | 496 prefs::kDefaultBrowserSettingEnabled)) { |
487 shell_integration::SetAsDefaultBrowser(); | 497 shell_integration::SetAsDefaultBrowser(); |
488 } | 498 } |
489 } else if (make_chrome_default_for_user) { | 499 } else if (make_chrome_default_for_user) { |
490 shell_integration::SetAsDefaultBrowser(); | 500 shell_integration::SetAsDefaultBrowser(); |
491 } | 501 } |
492 } | 502 } |
493 } | 503 } |
494 | 504 |
| 505 // Returns true iff the current OS is Windows and the version is >= 10. |
| 506 bool IsWin10() { |
| 507 #if defined(OS_WIN) |
| 508 return base::win::GetVersion() >= base::win::VERSION_WIN10; |
| 509 #else |
| 510 return false; |
| 511 #endif |
| 512 } |
| 513 |
495 } // namespace | 514 } // namespace |
496 | 515 |
497 namespace first_run { | 516 namespace first_run { |
498 namespace internal { | 517 namespace internal { |
499 | 518 |
500 FirstRunState g_first_run = FIRST_RUN_UNKNOWN; | 519 FirstRunState g_first_run = FIRST_RUN_UNKNOWN; |
501 | 520 |
502 void SetupMasterPrefsFromInstallPrefs( | 521 void SetupMasterPrefsFromInstallPrefs( |
503 const installer::MasterPreferences& install_prefs, | 522 const installer::MasterPreferences& install_prefs, |
504 MasterPrefs* out_prefs) { | 523 MasterPrefs* out_prefs) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 base::CommandLine::ForCurrentProcess(); | 659 base::CommandLine::ForCurrentProcess(); |
641 if (command_line->HasSwitch(switches::kForceFirstRun) || | 660 if (command_line->HasSwitch(switches::kForceFirstRun) || |
642 (!command_line->HasSwitch(switches::kNoFirstRun) && | 661 (!command_line->HasSwitch(switches::kNoFirstRun) && |
643 !internal::IsFirstRunSentinelPresent())) { | 662 !internal::IsFirstRunSentinelPresent())) { |
644 internal::g_first_run = internal::FIRST_RUN_TRUE; | 663 internal::g_first_run = internal::FIRST_RUN_TRUE; |
645 } | 664 } |
646 } | 665 } |
647 return internal::g_first_run == internal::FIRST_RUN_TRUE; | 666 return internal::g_first_run == internal::FIRST_RUN_TRUE; |
648 } | 667 } |
649 | 668 |
| 669 void SetFirstRunForTesting(bool is_first_run) { |
| 670 internal::g_first_run = |
| 671 is_first_run ? internal::FIRST_RUN_TRUE : internal::FIRST_RUN_FALSE; |
| 672 } |
| 673 |
650 #if defined(OS_MACOSX) | 674 #if defined(OS_MACOSX) |
651 bool IsFirstRunSuppressed(const base::CommandLine& command_line) { | 675 bool IsFirstRunSuppressed(const base::CommandLine& command_line) { |
652 return command_line.HasSwitch(switches::kNoFirstRun); | 676 return command_line.HasSwitch(switches::kNoFirstRun); |
653 } | 677 } |
654 #endif | 678 #endif |
655 | 679 |
656 bool IsMetricsReportingOptIn() { | 680 bool IsMetricsReportingOptIn() { |
657 #if defined(OS_CHROMEOS) | 681 #if defined(OS_CHROMEOS) |
658 return false; | 682 return false; |
659 #elif defined(OS_ANDROID) | 683 #elif defined(OS_ANDROID) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 void SetShouldShowWelcomePage() { | 731 void SetShouldShowWelcomePage() { |
708 g_should_show_welcome_page = true; | 732 g_should_show_welcome_page = true; |
709 } | 733 } |
710 | 734 |
711 bool ShouldShowWelcomePage() { | 735 bool ShouldShowWelcomePage() { |
712 bool retval = g_should_show_welcome_page; | 736 bool retval = g_should_show_welcome_page; |
713 g_should_show_welcome_page = false; | 737 g_should_show_welcome_page = false; |
714 return retval; | 738 return retval; |
715 } | 739 } |
716 | 740 |
| 741 GURL GetWelcomePageURL() { |
| 742 // TODO(tmartino): Once Consolidated FRE page is implemented, return that |
| 743 // here when kUseConsolidatedFirstRun is true. |
| 744 return GURL(l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL)); |
| 745 } |
| 746 |
| 747 std::vector<GURL> GetOnboardingTabs() { |
| 748 std::vector<GURL> tabs; |
| 749 if (IsWin10()) { |
| 750 // TODO(tmartino): Win 10 logic is more complex and will be added in its |
| 751 // own change. |
| 752 } else if (IsChromeFirstRun()) { |
| 753 tabs.push_back(GetWelcomePageURL()); |
| 754 } |
| 755 return tabs; |
| 756 } |
| 757 |
| 758 std::vector<GURL> ProcessMasterPrefsTabs(const std::vector<GURL>& tabs) { |
| 759 std::vector<GURL> processed_tabs; |
| 760 if (IsChromeFirstRun()) { |
| 761 for (const GURL& tab : tabs) { |
| 762 if (tab.host() == kNewTabKeyword) { |
| 763 processed_tabs.push_back(GURL(chrome::kChromeUINewTabURL)); |
| 764 } else if (tab.host() == kWelcomePageKeyword) { |
| 765 processed_tabs.push_back(GetWelcomePageURL()); |
| 766 } else { |
| 767 processed_tabs.push_back(tab); |
| 768 } |
| 769 } |
| 770 } |
| 771 return processed_tabs; |
| 772 } |
| 773 |
717 void SetShouldDoPersonalDataManagerFirstRun() { | 774 void SetShouldDoPersonalDataManagerFirstRun() { |
718 g_should_do_autofill_personal_data_manager_first_run = true; | 775 g_should_do_autofill_personal_data_manager_first_run = true; |
719 } | 776 } |
720 | 777 |
721 bool ShouldDoPersonalDataManagerFirstRun() { | 778 bool ShouldDoPersonalDataManagerFirstRun() { |
722 bool retval = g_should_do_autofill_personal_data_manager_first_run; | 779 bool retval = g_should_do_autofill_personal_data_manager_first_run; |
723 g_should_do_autofill_personal_data_manager_first_run = false; | 780 g_should_do_autofill_personal_data_manager_first_run = false; |
724 return retval; | 781 return retval; |
725 } | 782 } |
726 | 783 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 SetShouldDoPersonalDataManagerFirstRun(); | 915 SetShouldDoPersonalDataManagerFirstRun(); |
859 | 916 |
860 internal::DoPostImportPlatformSpecificTasks(profile); | 917 internal::DoPostImportPlatformSpecificTasks(profile); |
861 } | 918 } |
862 | 919 |
863 uint16_t auto_import_state() { | 920 uint16_t auto_import_state() { |
864 return g_auto_import_state; | 921 return g_auto_import_state; |
865 } | 922 } |
866 | 923 |
867 } // namespace first_run | 924 } // namespace first_run |
OLD | NEW |