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 <memory> | |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 #include "content/public/browser/navigation_entry.h" | 63 #include "content/public/browser/navigation_entry.h" |
| 63 #include "content/public/browser/notification_observer.h" | 64 #include "content/public/browser/notification_observer.h" |
| 64 #include "content/public/browser/notification_registrar.h" | 65 #include "content/public/browser/notification_registrar.h" |
| 65 #include "content/public/browser/notification_service.h" | 66 #include "content/public/browser/notification_service.h" |
| 66 #include "content/public/browser/notification_types.h" | 67 #include "content/public/browser/notification_types.h" |
| 67 #include "content/public/browser/user_metrics.h" | 68 #include "content/public/browser/user_metrics.h" |
| 68 #include "content/public/browser/web_contents.h" | 69 #include "content/public/browser/web_contents.h" |
| 69 #include "extensions/browser/extension_system.h" | 70 #include "extensions/browser/extension_system.h" |
| 70 #include "extensions/common/one_shot_event.h" | 71 #include "extensions/common/one_shot_event.h" |
| 71 #include "google_apis/gaia/gaia_auth_util.h" | 72 #include "google_apis/gaia/gaia_auth_util.h" |
| 73 #include "rlz/features/features.h" | |
| 72 #include "ui/base/l10n/l10n_util.h" | 74 #include "ui/base/l10n/l10n_util.h" |
| 73 #include "url/gurl.h" | 75 #include "url/gurl.h" |
| 74 | 76 |
| 75 namespace content { | 77 namespace content { |
| 76 class BrowserContext; | 78 class BrowserContext; |
| 77 } | 79 } |
| 78 | 80 |
| 79 using base::UserMetricsAction; | 81 using base::UserMetricsAction; |
| 80 | 82 |
| 81 namespace { | 83 namespace { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 = LAZY_INSTANCE_INITIALIZER; | 445 = LAZY_INSTANCE_INITIALIZER; |
| 444 | 446 |
| 445 // Loads master preferences from the master preference file into the installer | 447 // Loads master preferences from the master preference file into the installer |
| 446 // master preferences. Returns the pointer to installer::MasterPreferences | 448 // master preferences. Returns the pointer to installer::MasterPreferences |
| 447 // object if successful; otherwise, returns NULL. | 449 // object if successful; otherwise, returns NULL. |
| 448 installer::MasterPreferences* LoadMasterPrefs() { | 450 installer::MasterPreferences* LoadMasterPrefs() { |
| 449 base::FilePath master_prefs_path; | 451 base::FilePath master_prefs_path; |
| 450 if (!master_prefs_path_for_testing.Get().empty()) | 452 if (!master_prefs_path_for_testing.Get().empty()) |
| 451 master_prefs_path = master_prefs_path_for_testing.Get(); | 453 master_prefs_path = master_prefs_path_for_testing.Get(); |
| 452 else | 454 else |
| 453 master_prefs_path = base::FilePath(first_run::internal::MasterPrefsPath()); | 455 master_prefs_path = base::FilePath(first_run::internal::MasterPrefsPath()); |
|
Roger Tawa OOO till Jul 10th
2017/02/24 16:02:17
nit: should have curly braces in on this if/else
gab
2017/02/28 19:54:45
Done.
| |
| 454 if (master_prefs_path.empty()) | 456 if (master_prefs_path.empty()) |
| 455 return NULL; | 457 return NULL; |
| 456 installer::MasterPreferences* install_prefs = | 458 installer::MasterPreferences* install_prefs = |
| 457 new installer::MasterPreferences(master_prefs_path); | 459 new installer::MasterPreferences(master_prefs_path); |
| 458 if (!install_prefs->read_from_file()) { | 460 if (!install_prefs->read_from_file()) { |
| 459 delete install_prefs; | 461 delete install_prefs; |
| 460 return NULL; | 462 return NULL; |
| 461 } | 463 } |
| 462 | 464 |
| 463 return install_prefs; | 465 return install_prefs; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 487 | 489 |
| 488 namespace first_run { | 490 namespace first_run { |
| 489 namespace internal { | 491 namespace internal { |
| 490 | 492 |
| 491 void SetupMasterPrefsFromInstallPrefs( | 493 void SetupMasterPrefsFromInstallPrefs( |
| 492 const installer::MasterPreferences& install_prefs, | 494 const installer::MasterPreferences& install_prefs, |
| 493 MasterPrefs* out_prefs) { | 495 MasterPrefs* out_prefs) { |
| 494 ConvertStringVectorToGURLVector( | 496 ConvertStringVectorToGURLVector( |
| 495 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs); | 497 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs); |
| 496 | 498 |
| 497 install_prefs.GetInt(installer::master_preferences::kDistroPingDelay, | |
| 498 &out_prefs->ping_delay); | |
| 499 | |
| 500 bool value = false; | 499 bool value = false; |
| 501 if (install_prefs.GetBool( | 500 if (install_prefs.GetBool( |
| 502 installer::master_preferences::kDistroImportSearchPref, &value)) { | 501 installer::master_preferences::kDistroImportSearchPref, &value)) { |
| 503 if (value) { | 502 if (value) { |
| 504 out_prefs->do_import_items |= importer::SEARCH_ENGINES; | 503 out_prefs->do_import_items |= importer::SEARCH_ENGINES; |
| 505 } else { | 504 } else { |
| 506 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; | 505 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; |
| 507 } | 506 } |
| 508 } | 507 } |
| 509 | 508 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 612 bool force_first_run, | 611 bool force_first_run, |
| 613 bool no_first_run) { | 612 bool no_first_run) { |
| 614 return (force_first_run || (!has_sentinel && !no_first_run)) | 613 return (force_first_run || (!has_sentinel && !no_first_run)) |
| 615 ? FIRST_RUN_TRUE | 614 ? FIRST_RUN_TRUE |
| 616 : FIRST_RUN_FALSE; | 615 : FIRST_RUN_FALSE; |
| 617 } | 616 } |
| 618 | 617 |
| 619 } // namespace internal | 618 } // namespace internal |
| 620 | 619 |
| 621 MasterPrefs::MasterPrefs() | 620 MasterPrefs::MasterPrefs() |
| 622 : ping_delay(0), | 621 : homepage_defined(false), |
| 623 homepage_defined(false), | |
| 624 do_import_items(0), | 622 do_import_items(0), |
| 625 dont_import_items(0), | 623 dont_import_items(0), |
| 626 make_chrome_default_for_user(false), | 624 make_chrome_default_for_user(false), |
| 627 suppress_first_run_default_browser_prompt(false), | 625 suppress_first_run_default_browser_prompt(false), |
| 628 welcome_page_on_os_upgrade_enabled(true) { | 626 welcome_page_on_os_upgrade_enabled(true) {} |
| 629 } | |
| 630 | 627 |
| 631 MasterPrefs::~MasterPrefs() {} | 628 MasterPrefs::~MasterPrefs() {} |
| 632 | 629 |
| 633 bool IsChromeFirstRun() { | 630 bool IsChromeFirstRun() { |
| 634 if (g_first_run == internal::FIRST_RUN_UNKNOWN) { | 631 if (g_first_run == internal::FIRST_RUN_UNKNOWN) { |
| 635 const base::CommandLine* command_line = | 632 const base::CommandLine* command_line = |
| 636 base::CommandLine::ForCurrentProcess(); | 633 base::CommandLine::ForCurrentProcess(); |
| 637 g_first_run = internal::DetermineFirstRunState( | 634 g_first_run = internal::DetermineFirstRunState( |
| 638 internal::IsFirstRunSentinelPresent(), | 635 internal::IsFirstRunSentinelPresent(), |
| 639 command_line->HasSwitch(switches::kForceFirstRun), | 636 command_line->HasSwitch(switches::kForceFirstRun), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 653 // However, user will have chance to modify metrics reporting state during | 650 // However, user will have chance to modify metrics reporting state during |
| 654 // first run. | 651 // first run. |
| 655 return false; | 652 return false; |
| 656 } | 653 } |
| 657 | 654 |
| 658 void CreateSentinelIfNeeded() { | 655 void CreateSentinelIfNeeded() { |
| 659 if (IsChromeFirstRun()) | 656 if (IsChromeFirstRun()) |
| 660 internal::CreateSentinel(); | 657 internal::CreateSentinel(); |
| 661 } | 658 } |
| 662 | 659 |
| 663 std::string GetPingDelayPrefName() { | |
| 664 return base::StringPrintf("%s.%s", | |
| 665 installer::master_preferences::kDistroDict, | |
| 666 installer::master_preferences::kDistroPingDelay); | |
| 667 } | |
| 668 | |
| 669 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 660 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 670 registry->RegisterIntegerPref(GetPingDelayPrefName().c_str(), 0); | 661 #if BUILDFLAG(ENABLE_RLZ) |
| 662 registry->RegisterIntegerPref(prefs::kRlzPingDelay, 90); | |
|
grt (UTC plus 2)
2017/02/24 07:42:20
this doesn't feel like the right place. rlz isn't
grt (UTC plus 2)
2017/02/24 07:42:20
while 90 has been the default, should it really be
Roger Tawa OOO till Jul 10th
2017/02/24 16:02:17
See my other comment. I believe this is a bug tha
Roger Tawa OOO till Jul 10th
2017/02/24 16:02:17
Could be moved to c/b/rlz/chrome_rlz_tracker_deleg
gab
2017/02/28 19:54:45
Done.
gab
2017/02/28 19:54:45
I think it's intentionally tied to the default pro
| |
| 663 #endif | |
| 671 } | 664 } |
| 672 | 665 |
| 673 bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) { | 666 bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) { |
| 674 PrefService* local_state = g_browser_process->local_state(); | 667 PrefService* local_state = g_browser_process->local_state(); |
| 675 if (!local_state) | 668 if (!local_state) |
| 676 return false; | 669 return false; |
| 677 if (local_state->GetInteger( | 670 if (local_state->GetInteger( |
| 678 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) { | 671 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) { |
| 679 // Set the new state as long as the bubble wasn't explicitly suppressed | 672 // Set the new state as long as the bubble wasn't explicitly suppressed |
| 680 // already. | 673 // already. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 735 } | 728 } |
| 736 | 729 |
| 737 ProcessMasterPreferencesResult ProcessMasterPreferences( | 730 ProcessMasterPreferencesResult ProcessMasterPreferences( |
| 738 const base::FilePath& user_data_dir, | 731 const base::FilePath& user_data_dir, |
| 739 MasterPrefs* out_prefs) { | 732 MasterPrefs* out_prefs) { |
| 740 DCHECK(!user_data_dir.empty()); | 733 DCHECK(!user_data_dir.empty()); |
| 741 | 734 |
| 742 std::unique_ptr<installer::MasterPreferences> install_prefs( | 735 std::unique_ptr<installer::MasterPreferences> install_prefs( |
| 743 LoadMasterPrefs()); | 736 LoadMasterPrefs()); |
| 744 | 737 |
| 745 // Default value in case master preferences is missing or corrupt, or | |
| 746 // ping_delay is missing. | |
| 747 out_prefs->ping_delay = 90; | |
| 748 if (install_prefs.get()) { | 738 if (install_prefs.get()) { |
| 749 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) | 739 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) |
| 750 return EULA_EXIT_NOW; | 740 return EULA_EXIT_NOW; |
| 751 | 741 |
| 742 std::unique_ptr<base::DictionaryValue> master_dictionary = | |
| 743 install_prefs->master_dictionary().CreateDeepCopy(); | |
| 744 // The distribution dictionary (and any prefs below it) are never registered | |
| 745 // for use in Chrome's PrefService. Strip them from the master dictionary | |
| 746 // before mapping it to prefs. | |
| 747 master_dictionary->RemoveWithoutPathExpansion( | |
| 748 installer::master_preferences::kDistroDict, nullptr); | |
| 749 | |
| 752 if (!chrome_prefs::InitializePrefsFromMasterPrefs( | 750 if (!chrome_prefs::InitializePrefsFromMasterPrefs( |
| 753 profiles::GetDefaultProfileDir(user_data_dir), | 751 profiles::GetDefaultProfileDir(user_data_dir), |
| 754 install_prefs->master_dictionary())) { | 752 std::move(master_dictionary))) { |
| 755 DLOG(ERROR) << "Failed to initialize from master_preferences."; | 753 DLOG(ERROR) << "Failed to initialize from master_preferences."; |
| 756 } | 754 } |
| 757 | 755 |
| 758 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); | 756 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); |
| 759 | 757 |
| 760 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); | 758 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); |
| 761 } | 759 } |
| 762 | 760 |
| 763 return FIRST_RUN_PROCEED; | 761 return FIRST_RUN_PROCEED; |
| 764 } | 762 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 859 SetShouldDoPersonalDataManagerFirstRun(); | 857 SetShouldDoPersonalDataManagerFirstRun(); |
| 860 | 858 |
| 861 internal::DoPostImportPlatformSpecificTasks(profile); | 859 internal::DoPostImportPlatformSpecificTasks(profile); |
| 862 } | 860 } |
| 863 | 861 |
| 864 uint16_t auto_import_state() { | 862 uint16_t auto_import_state() { |
| 865 return g_auto_import_state; | 863 return g_auto_import_state; |
| 866 } | 864 } |
| 867 | 865 |
| 868 } // namespace first_run | 866 } // namespace first_run |
| OLD | NEW |