#include "services/preferences/tracked/tracked_preferences_migration.h"
#include <string>
#include <utility>
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
#include "base/values.h"
#include "components/prefs/pref_name_set.h"
#include "services/preferences/tracked/dictionary_hash_store_contents.h"
#include "services/preferences/tracked/hash_store_contents.h"
#include "services/preferences/tracked/interceptable_pref_filter.h"
#include "services/preferences/tracked/pref_hash_store.h"
#include "services/preferences/tracked/pref_hash_store_transaction.h"
namespace {
class TrackedPreferencesMigrator
: public base::RefCounted<TrackedPreferencesMigrator> { … };
void CleanupPrefStore(
const base::RepeatingCallback<void(const std::string& key)>& store_cleaner,
const PrefNameSet& keys_to_clean) { … }
void ScheduleSourcePrefStoreCleanup(
const base::RepeatingCallback<void(base::OnceClosure)>&
register_on_successful_destination_store_write_callback,
const base::RepeatingCallback<void(const std::string& key)>&
source_store_cleaner,
const PrefNameSet& keys_to_clean,
bool wait_for_commit_to_destination_store) { … }
void CleanupMigratedHashes(const PrefNameSet& migrated_pref_names,
PrefHashStore* origin_pref_hash_store,
base::Value::Dict& origin_pref_store) { … }
void MigratePrefsFromOldToNewStore(const PrefNameSet& pref_names,
base::Value::Dict& old_store,
base::Value::Dict& new_store,
PrefHashStore* new_hash_store,
bool* old_store_needs_cleanup,
bool* new_store_altered) { … }
TrackedPreferencesMigrator::TrackedPreferencesMigrator(
const PrefNameSet& unprotected_pref_names,
const PrefNameSet& protected_pref_names,
const base::RepeatingCallback<void(const std::string& key)>&
unprotected_store_cleaner,
const base::RepeatingCallback<void(const std::string& key)>&
protected_store_cleaner,
const base::RepeatingCallback<void(base::OnceClosure)>&
register_on_successful_unprotected_store_write_callback,
const base::RepeatingCallback<void(base::OnceClosure)>&
register_on_successful_protected_store_write_callback,
std::unique_ptr<PrefHashStore> unprotected_pref_hash_store,
std::unique_ptr<PrefHashStore> protected_pref_hash_store,
InterceptablePrefFilter* unprotected_pref_filter,
InterceptablePrefFilter* protected_pref_filter)
: … { … }
TrackedPreferencesMigrator::~TrackedPreferencesMigrator() { … }
void TrackedPreferencesMigrator::InterceptFilterOnLoad(
PrefFilterID id,
InterceptablePrefFilter::FinalizeFilterOnLoadCallback
finalize_filter_on_load,
base::Value::Dict prefs) { … }
void TrackedPreferencesMigrator::MigrateIfReady() { … }
}
void SetupTrackedPreferencesMigration(
const PrefNameSet& unprotected_pref_names,
const PrefNameSet& protected_pref_names,
const base::RepeatingCallback<void(const std::string& key)>&
unprotected_store_cleaner,
const base::RepeatingCallback<void(const std::string& key)>&
protected_store_cleaner,
const base::RepeatingCallback<void(base::OnceClosure)>&
register_on_successful_unprotected_store_write_callback,
const base::RepeatingCallback<void(base::OnceClosure)>&
register_on_successful_protected_store_write_callback,
std::unique_ptr<PrefHashStore> unprotected_pref_hash_store,
std::unique_ptr<PrefHashStore> protected_pref_hash_store,
InterceptablePrefFilter* unprotected_pref_filter,
InterceptablePrefFilter* protected_pref_filter) { … }