chromium/services/preferences/tracked/tracked_preferences_migration.cc

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

#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> {};

// Invokes |store_cleaner| for every |keys_to_clean|.
void CleanupPrefStore(
    const base::RepeatingCallback<void(const std::string& key)>& store_cleaner,
    const PrefNameSet& keys_to_clean) {}

// If |wait_for_commit_to_destination_store|: schedules (via
// |register_on_successful_destination_store_write_callback|) a cleanup of the
// |keys_to_clean| from the source pref store (through |source_store_cleaner|)
// once the destination pref store they were migrated to was successfully
// written to disk. Otherwise, executes the cleanup right away.
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) {}

// Removes hashes for |migrated_pref_names| from |origin_pref_store| using
// the configuration/implementation in |origin_pref_hash_store|.
void CleanupMigratedHashes(const PrefNameSet& migrated_pref_names,
                           PrefHashStore* origin_pref_hash_store,
                           base::Value::Dict& origin_pref_store) {}

// Copies the value of each pref in |pref_names| which is set in |old_store|,
// but not in |new_store| into |new_store|. Sets |old_store_needs_cleanup| to
// true if any old duplicates remain in |old_store| and sets |new_store_altered|
// to true if any value was copied to |new_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() {}

}  // namespace

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) {}