chromium/chrome/browser/prefs/chrome_pref_service_factory.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "chrome/browser/prefs/chrome_pref_service_factory.h"

#include <stddef.h>

#include <string>
#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
#include "base/path_service.h"
#include "base/strings/stringprintf.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/enterprise/signin/enterprise_signin_prefs.h"
#include "chrome/browser/policy/chrome_browser_policy_connector.h"
#include "chrome/browser/prefs/chrome_command_line_pref_store.h"
#include "chrome/browser/prefs/chrome_pref_model_associator_client.h"
#include "chrome/browser/prefs/profile_pref_store_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/glue/sync_start_util.h"
#include "chrome/browser/sync/prefs/chrome_syncable_prefs_database.h"
#include "chrome/browser/ui/profiles/profile_error_dialog.h"
#include "chrome/common/buildflags.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h"
#include "components/component_updater/pref_names.h"
#include "components/policy/core/browser/configuration_policy_pref_store.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/default_pref_store.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/prefs/pref_notifier_impl.h"
#include "components/prefs/pref_registry.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/pref_store.h"
#include "components/prefs/pref_value_store.h"
#include "components/prefs/wrap_with_prefix_pref_store.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/search_engines/default_search_manager.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/signin/public/base/signin_pref_names.h"
#include "components/supervised_user/core/browser/supervised_user_pref_store.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/features.h"
#include "components/sync/base/pref_names.h"
#include "components/sync_preferences/pref_model_associator.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "components/sync_preferences/pref_service_syncable_factory.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/buildflags/buildflags.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "rlz/buildflags/buildflags.h"
#include "services/preferences/public/cpp/tracked/configuration.h"
#include "services/preferences/public/cpp/tracked/pref_names.h"
#include "sql/error_delegate_util.h"
#include "ui/base/resource/resource_bundle.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "base/files/file_util.h"
#endif

#if BUILDFLAG(ENABLE_EXTENSIONS)
#include "extensions/browser/pref_names.h"
#endif

#if BUILDFLAG(IS_WIN)
#include "base/enterprise_util.h"
#if BUILDFLAG(ENABLE_RLZ)
#include "rlz/lib/machine_id.h"  // nogncheck crbug.com/1125897
#endif  // BUILDFLAG(ENABLE_RLZ)
#endif  // BUILDFLAG(IS_WIN)

BrowserContext;
BrowserThread;

EnforcementLevel;
PrefTrackingStrategy;
ValueType;

namespace {

#if BUILDFLAG(IS_WIN)
// Whether we are in testing mode; can be enabled via
// DisableDomainCheckForTesting(). Forces startup checks to ignore the presence
// of a domain when determining the active SettingsEnforcement group.
bool g_disable_domain_check_for_testing = false;
#endif  // BUILDFLAG(IS_WIN)

// These preferences must be kept in sync with the TrackedPreference enum in
// tools/metrics/histograms/metadata/settings/enums.xml. To add a new
// preference, append it to the array and add a corresponding value to the
// histogram enum. Each tracked preference must be given a unique reporting ID.
// See CleanupDeprecatedTrackedPreferences() in pref_hash_filter.cc to remove a
// deprecated tracked preference.
const prefs::TrackedPreferenceMetadata kTrackedPrefs[] =;

// One more than the last tracked preferences ID above.
const size_t kTrackedPrefsReportingIDsCount =;

// Each group enforces a superset of the protection provided by the previous
// one.
enum SettingsEnforcementGroup {};

SettingsEnforcementGroup GetSettingsEnforcementGroup() {}

// Returns the effective preference tracking configuration.
std::vector<prefs::mojom::TrackedPreferenceMetadataPtr>
GetTrackingConfiguration() {}

std::unique_ptr<ProfilePrefStoreManager> CreateProfilePrefStoreManager(
    const base::FilePath& profile_path) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
// The initial implementation of the standalone browser store
// saved the preferences associated with a user under /home/chronos, which made
// the prefs available for all users which subsequently log in on the device.
// Currently the preferences are stored under the user profile directory. This
// method cleans up the standalone browser preferences file under /home/chronos.
// Note that the standalone browser preferences can't be migrated from the
// /home/chronos directory to the profile directory because it's not possible to
// know which profile has configured the settings. Once the user signs into the
// user session and starts the Lacros browser, the standalone browser settings
// will be restored in Ash and saved to the correct location.
// TODO(b/304685319): Remove this cleanup method.
void CleanupObsoleteStandaloneBrowserPrefsFile() {
  base::FilePath user_data_dir;
  CHECK(base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));

  base::FilePath obsolete_standalone_browser_file = user_data_dir.Append(
      FILE_PATH_LITERAL("standalone_browser_preferences.json"));

  if (!base::PathExists(obsolete_standalone_browser_file)) {
    return;
  }

  LOG(WARNING) << "Removing obsolete " << obsolete_standalone_browser_file
               << " file: "
               << base::DeleteFile(obsolete_standalone_browser_file);
}
#endif

void PrepareFactory(
    sync_preferences::PrefServiceSyncableFactory* factory,
    const base::FilePath& pref_filename,
    policy::PolicyService* policy_service,
    supervised_user::SupervisedUserSettingsService* supervised_user_settings,
    scoped_refptr<PersistentPrefStore> user_pref_store,
    scoped_refptr<PrefStore> extension_prefs,
    scoped_refptr<PersistentPrefStore> standalone_browser_prefs,
    bool async,
    policy::BrowserPolicyConnector* policy_connector) {}

class ResetOnLoadObserverImpl : public prefs::mojom::ResetOnLoadObserver {};

}  // namespace

namespace chrome_prefs {

const char kAccountPreferencesPrefix[] =;

std::unique_ptr<PrefService> CreateLocalState(
    const base::FilePath& pref_filename,
    scoped_refptr<PersistentPrefStore> pref_store,
    policy::PolicyService* policy_service,
    scoped_refptr<PrefRegistry> pref_registry,
    policy::BrowserPolicyConnector* policy_connector) {}

std::unique_ptr<sync_preferences::PrefServiceSyncable> CreateProfilePrefs(
    const base::FilePath& profile_path,
    mojo::PendingRemote<prefs::mojom::TrackedPreferenceValidationDelegate>
        validation_delegate,
    policy::PolicyService* policy_service,
    supervised_user::SupervisedUserSettingsService* supervised_user_settings,
    scoped_refptr<PrefStore> extension_prefs,
    scoped_refptr<user_prefs::PrefRegistrySyncable> pref_registry,
    policy::BrowserPolicyConnector* connector,
    bool async,
    scoped_refptr<base::SequencedTaskRunner> io_task_runner) {}

void DisableDomainCheckForTesting() {}

bool InitializePrefsFromMasterPrefs(const base::FilePath& profile_path,
                                    base::Value::Dict master_prefs) {}

base::Time GetResetTime(Profile* profile) {}

void ClearResetTime(Profile* profile) {}

void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {}

void HandlePersistentPrefStoreReadError(
    const base::FilePath& pref_filename,
    PersistentPrefStore::PrefReadError error) {}

}  // namespace chrome_prefs