Chromium Code Reviews| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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"; | |
| 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 Loading... | |
| 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 | |
| 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 Loading... | |
| 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 if (is_first_run) { | |
| 657 internal::g_first_run = internal::FIRST_RUN_TRUE; | |
| 658 } else { | |
| 659 internal::g_first_run = internal::FIRST_RUN_FALSE; | |
| 660 } | |
| 661 } | |
|
Roger Tawa OOO till Jul 10th
2016/07/26 15:00:26
Nit:
internal::g_first_run =
is_first_run
tmartino
2016/07/27 18:40:43
Done.
| |
| 662 | |
| 650 #if defined(OS_MACOSX) | 663 #if defined(OS_MACOSX) |
| 651 bool IsFirstRunSuppressed(const base::CommandLine& command_line) { | 664 bool IsFirstRunSuppressed(const base::CommandLine& command_line) { |
| 652 return command_line.HasSwitch(switches::kNoFirstRun); | 665 return command_line.HasSwitch(switches::kNoFirstRun); |
| 653 } | 666 } |
| 654 #endif | 667 #endif |
| 655 | 668 |
| 656 bool IsMetricsReportingOptIn() { | 669 bool IsMetricsReportingOptIn() { |
| 657 #if defined(OS_CHROMEOS) | 670 #if defined(OS_CHROMEOS) |
| 658 return false; | 671 return false; |
| 659 #elif defined(OS_ANDROID) | 672 #elif defined(OS_ANDROID) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 void SetShouldShowWelcomePage() { | 720 void SetShouldShowWelcomePage() { |
| 708 g_should_show_welcome_page = true; | 721 g_should_show_welcome_page = true; |
| 709 } | 722 } |
| 710 | 723 |
| 711 bool ShouldShowWelcomePage() { | 724 bool ShouldShowWelcomePage() { |
| 712 bool retval = g_should_show_welcome_page; | 725 bool retval = g_should_show_welcome_page; |
| 713 g_should_show_welcome_page = false; | 726 g_should_show_welcome_page = false; |
| 714 return retval; | 727 return retval; |
| 715 } | 728 } |
| 716 | 729 |
| 730 GURL GetWelcomePageURL() { | |
| 731 if (base::FeatureList::IsEnabled(features::kUseNewFirstRun)) { | |
| 732 return GURL("http://www.startribune.com"); | |
| 733 } else { | |
| 734 return GURL(l10n_util::GetStringUTF8(IDS_WELCOME_PAGE_URL)); | |
| 735 } | |
| 736 } | |
| 737 | |
| 738 bool IsWin10() { | |
| 739 #if defined(OS_WIN) | |
| 740 return os_info->version() >= base::win::VERSION_WIN10; | |
| 741 #else | |
| 742 return false; | |
| 743 #endif | |
| 744 } | |
| 745 | |
| 746 std::vector<GURL> GetOnboardingTabs() { | |
| 747 std::vector<GURL> tabs; | |
| 748 if (IsWin10()) { | |
| 749 // TODO(tmartino): Win 10 logic is more complex and will be added in its | |
| 750 // own change. | |
| 751 NOTREACHED(); | |
| 752 } else if (IsChromeFirstRun()) { | |
| 753 tabs.push_back(GetWelcomePageURL()); | |
| 754 } | |
| 755 return tabs; | |
| 756 } | |
|
Roger Tawa OOO till Jul 10th
2016/07/26 15:00:26
Might be better to move some parts of GetOnboardin
tmartino
2016/07/27 18:40:43
Hmm. I've thought about this a bit and the best wa
| |
| 757 | |
| 758 std::vector<GURL> ProcessMasterPrefsTabs(const std::vector<GURL>& tabs) { | |
| 759 std::vector<GURL> processed_tabs; | |
| 760 if (IsChromeFirstRun()) { | |
| 761 for (GURL tab : tabs) { | |
| 762 if (tab.host() == kNewTabMagicWord) { | |
| 763 processed_tabs.push_back(GURL(chrome::kChromeUINewTabURL)); | |
| 764 } else if (tab.host() == kWelcomePageMagicWord) { | |
| 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 |