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

Side by Side Diff: chrome/browser/first_run/first_run.cc

Issue 2714853002: Remove kDistroDict from Preferences. (Closed)
Patch Set: kRlzPingDelay -> kRlzPingDelaySeconds Created 3 years, 9 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
« no previous file with comments | « chrome/browser/first_run/first_run.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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 29 matching lines...) Expand all
47 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 48 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
48 #include "chrome/common/chrome_constants.h" 49 #include "chrome/common/chrome_constants.h"
49 #include "chrome/common/chrome_paths.h" 50 #include "chrome/common/chrome_paths.h"
50 #include "chrome/common/chrome_switches.h" 51 #include "chrome/common/chrome_switches.h"
51 #include "chrome/common/pref_names.h" 52 #include "chrome/common/pref_names.h"
52 #include "chrome/common/url_constants.h" 53 #include "chrome/common/url_constants.h"
53 #include "chrome/grit/locale_settings.h" 54 #include "chrome/grit/locale_settings.h"
54 #include "chrome/installer/util/master_preferences.h" 55 #include "chrome/installer/util/master_preferences.h"
55 #include "chrome/installer/util/master_preferences_constants.h" 56 #include "chrome/installer/util/master_preferences_constants.h"
56 #include "chrome/installer/util/util_constants.h" 57 #include "chrome/installer/util/util_constants.h"
57 #include "components/pref_registry/pref_registry_syncable.h"
58 #include "components/prefs/pref_service.h" 58 #include "components/prefs/pref_service.h"
59 #include "components/search_engines/template_url_service.h" 59 #include "components/search_engines/template_url_service.h"
60 #include "components/signin/core/browser/signin_manager.h" 60 #include "components/signin/core/browser/signin_manager.h"
61 #include "components/signin/core/browser/signin_tracker.h" 61 #include "components/signin/core/browser/signin_tracker.h"
62 #include "content/public/browser/navigation_entry.h" 62 #include "content/public/browser/navigation_entry.h"
63 #include "content/public/browser/notification_observer.h" 63 #include "content/public/browser/notification_observer.h"
64 #include "content/public/browser/notification_registrar.h" 64 #include "content/public/browser/notification_registrar.h"
65 #include "content/public/browser/notification_service.h" 65 #include "content/public/browser/notification_service.h"
66 #include "content/public/browser/notification_types.h" 66 #include "content/public/browser/notification_types.h"
67 #include "content/public/browser/user_metrics.h" 67 #include "content/public/browser/user_metrics.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 440 }
441 441
442 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing 442 static base::LazyInstance<base::FilePath> master_prefs_path_for_testing
443 = LAZY_INSTANCE_INITIALIZER; 443 = LAZY_INSTANCE_INITIALIZER;
444 444
445 // Loads master preferences from the master preference file into the installer 445 // Loads master preferences from the master preference file into the installer
446 // master preferences. Returns the pointer to installer::MasterPreferences 446 // master preferences. Returns the pointer to installer::MasterPreferences
447 // object if successful; otherwise, returns NULL. 447 // object if successful; otherwise, returns NULL.
448 installer::MasterPreferences* LoadMasterPrefs() { 448 installer::MasterPreferences* LoadMasterPrefs() {
449 base::FilePath master_prefs_path; 449 base::FilePath master_prefs_path;
450 if (!master_prefs_path_for_testing.Get().empty()) 450 if (!master_prefs_path_for_testing.Get().empty()) {
451 master_prefs_path = master_prefs_path_for_testing.Get(); 451 master_prefs_path = master_prefs_path_for_testing.Get();
452 else 452 } else {
453 master_prefs_path = base::FilePath(first_run::internal::MasterPrefsPath()); 453 master_prefs_path = base::FilePath(first_run::internal::MasterPrefsPath());
454 }
454 if (master_prefs_path.empty()) 455 if (master_prefs_path.empty())
455 return NULL; 456 return NULL;
456 installer::MasterPreferences* install_prefs = 457 installer::MasterPreferences* install_prefs =
457 new installer::MasterPreferences(master_prefs_path); 458 new installer::MasterPreferences(master_prefs_path);
458 if (!install_prefs->read_from_file()) { 459 if (!install_prefs->read_from_file()) {
459 delete install_prefs; 460 delete install_prefs;
460 return NULL; 461 return NULL;
461 } 462 }
462 463
463 return install_prefs; 464 return install_prefs;
(...skipping 23 matching lines...) Expand all
487 488
488 namespace first_run { 489 namespace first_run {
489 namespace internal { 490 namespace internal {
490 491
491 void SetupMasterPrefsFromInstallPrefs( 492 void SetupMasterPrefsFromInstallPrefs(
492 const installer::MasterPreferences& install_prefs, 493 const installer::MasterPreferences& install_prefs,
493 MasterPrefs* out_prefs) { 494 MasterPrefs* out_prefs) {
494 ConvertStringVectorToGURLVector( 495 ConvertStringVectorToGURLVector(
495 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs); 496 install_prefs.GetFirstRunTabs(), &out_prefs->new_tabs);
496 497
497 install_prefs.GetInt(installer::master_preferences::kDistroPingDelay,
498 &out_prefs->ping_delay);
499
500 bool value = false; 498 bool value = false;
501 if (install_prefs.GetBool( 499 if (install_prefs.GetBool(
502 installer::master_preferences::kDistroImportSearchPref, &value)) { 500 installer::master_preferences::kDistroImportSearchPref, &value)) {
503 if (value) { 501 if (value) {
504 out_prefs->do_import_items |= importer::SEARCH_ENGINES; 502 out_prefs->do_import_items |= importer::SEARCH_ENGINES;
505 } else { 503 } else {
506 out_prefs->dont_import_items |= importer::SEARCH_ENGINES; 504 out_prefs->dont_import_items |= importer::SEARCH_ENGINES;
507 } 505 }
508 } 506 }
509 507
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 bool force_first_run, 610 bool force_first_run,
613 bool no_first_run) { 611 bool no_first_run) {
614 return (force_first_run || (!has_sentinel && !no_first_run)) 612 return (force_first_run || (!has_sentinel && !no_first_run))
615 ? FIRST_RUN_TRUE 613 ? FIRST_RUN_TRUE
616 : FIRST_RUN_FALSE; 614 : FIRST_RUN_FALSE;
617 } 615 }
618 616
619 } // namespace internal 617 } // namespace internal
620 618
621 MasterPrefs::MasterPrefs() 619 MasterPrefs::MasterPrefs()
622 : ping_delay(0), 620 : homepage_defined(false),
623 homepage_defined(false),
624 do_import_items(0), 621 do_import_items(0),
625 dont_import_items(0), 622 dont_import_items(0),
626 make_chrome_default_for_user(false), 623 make_chrome_default_for_user(false),
627 suppress_first_run_default_browser_prompt(false), 624 suppress_first_run_default_browser_prompt(false),
628 welcome_page_on_os_upgrade_enabled(true) { 625 welcome_page_on_os_upgrade_enabled(true) {}
629 }
630 626
631 MasterPrefs::~MasterPrefs() {} 627 MasterPrefs::~MasterPrefs() {}
632 628
633 bool IsChromeFirstRun() { 629 bool IsChromeFirstRun() {
634 if (g_first_run == internal::FIRST_RUN_UNKNOWN) { 630 if (g_first_run == internal::FIRST_RUN_UNKNOWN) {
635 const base::CommandLine* command_line = 631 const base::CommandLine* command_line =
636 base::CommandLine::ForCurrentProcess(); 632 base::CommandLine::ForCurrentProcess();
637 g_first_run = internal::DetermineFirstRunState( 633 g_first_run = internal::DetermineFirstRunState(
638 internal::IsFirstRunSentinelPresent(), 634 internal::IsFirstRunSentinelPresent(),
639 command_line->HasSwitch(switches::kForceFirstRun), 635 command_line->HasSwitch(switches::kForceFirstRun),
(...skipping 13 matching lines...) Expand all
653 // However, user will have chance to modify metrics reporting state during 649 // However, user will have chance to modify metrics reporting state during
654 // first run. 650 // first run.
655 return false; 651 return false;
656 } 652 }
657 653
658 void CreateSentinelIfNeeded() { 654 void CreateSentinelIfNeeded() {
659 if (IsChromeFirstRun()) 655 if (IsChromeFirstRun())
660 internal::CreateSentinel(); 656 internal::CreateSentinel();
661 } 657 }
662 658
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) {
670 registry->RegisterIntegerPref(GetPingDelayPrefName().c_str(), 0);
671 }
672
673 bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) { 659 bool SetShowFirstRunBubblePref(FirstRunBubbleOptions show_bubble_option) {
674 PrefService* local_state = g_browser_process->local_state(); 660 PrefService* local_state = g_browser_process->local_state();
675 if (!local_state) 661 if (!local_state)
676 return false; 662 return false;
677 if (local_state->GetInteger( 663 if (local_state->GetInteger(
678 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) { 664 prefs::kShowFirstRunBubbleOption) != FIRST_RUN_BUBBLE_SUPPRESS) {
679 // Set the new state as long as the bubble wasn't explicitly suppressed 665 // Set the new state as long as the bubble wasn't explicitly suppressed
680 // already. 666 // already.
681 local_state->SetInteger(prefs::kShowFirstRunBubbleOption, 667 local_state->SetInteger(prefs::kShowFirstRunBubbleOption,
682 show_bubble_option); 668 show_bubble_option);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 721 }
736 722
737 ProcessMasterPreferencesResult ProcessMasterPreferences( 723 ProcessMasterPreferencesResult ProcessMasterPreferences(
738 const base::FilePath& user_data_dir, 724 const base::FilePath& user_data_dir,
739 MasterPrefs* out_prefs) { 725 MasterPrefs* out_prefs) {
740 DCHECK(!user_data_dir.empty()); 726 DCHECK(!user_data_dir.empty());
741 727
742 std::unique_ptr<installer::MasterPreferences> install_prefs( 728 std::unique_ptr<installer::MasterPreferences> install_prefs(
743 LoadMasterPrefs()); 729 LoadMasterPrefs());
744 730
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()) { 731 if (install_prefs.get()) {
749 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get())) 732 if (!internal::ShowPostInstallEULAIfNeeded(install_prefs.get()))
750 return EULA_EXIT_NOW; 733 return EULA_EXIT_NOW;
751 734
735 std::unique_ptr<base::DictionaryValue> master_dictionary =
736 install_prefs->master_dictionary().CreateDeepCopy();
737 // The distribution dictionary (and any prefs below it) are never registered
738 // for use in Chrome's PrefService. Strip them from the master dictionary
739 // before mapping it to prefs.
740 master_dictionary->RemoveWithoutPathExpansion(
741 installer::master_preferences::kDistroDict, nullptr);
742
752 if (!chrome_prefs::InitializePrefsFromMasterPrefs( 743 if (!chrome_prefs::InitializePrefsFromMasterPrefs(
753 profiles::GetDefaultProfileDir(user_data_dir), 744 profiles::GetDefaultProfileDir(user_data_dir),
754 install_prefs->master_dictionary())) { 745 std::move(master_dictionary))) {
755 DLOG(ERROR) << "Failed to initialize from master_preferences."; 746 DLOG(ERROR) << "Failed to initialize from master_preferences.";
756 } 747 }
757 748
758 DoDelayedInstallExtensionsIfNeeded(install_prefs.get()); 749 DoDelayedInstallExtensionsIfNeeded(install_prefs.get());
759 750
760 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs); 751 internal::SetupMasterPrefsFromInstallPrefs(*install_prefs, out_prefs);
761 } 752 }
762 753
763 return FIRST_RUN_PROCEED; 754 return FIRST_RUN_PROCEED;
764 } 755 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 SetShouldDoPersonalDataManagerFirstRun(); 850 SetShouldDoPersonalDataManagerFirstRun();
860 851
861 internal::DoPostImportPlatformSpecificTasks(profile); 852 internal::DoPostImportPlatformSpecificTasks(profile);
862 } 853 }
863 854
864 uint16_t auto_import_state() { 855 uint16_t auto_import_state() {
865 return g_auto_import_state; 856 return g_auto_import_state;
866 } 857 }
867 858
868 } // namespace first_run 859 } // namespace first_run
OLDNEW
« no previous file with comments | « chrome/browser/first_run/first_run.h ('k') | chrome/browser/prefs/browser_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698