1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_SYNC_PREFERENCES_PREFERENCES_MERGE_HELPER_H_
#define COMPONENTS_SYNC_PREFERENCES_PREFERENCES_MERGE_HELPER_H_
#include <string_view>
#include <utility>
#include "base/values.h"
namespace sync_preferences {
class PrefModelAssociatorClient;
namespace helper {
// Merges `local_value` and `server_value` list values.
// All entries of `server_value` come first and then of `local_value`. Any
// repeating value in `local_value` is excluded in the result.
base::Value::List MergeListValues(const base::Value::List& local_value,
const base::Value::List& server_value);
// Merges `local_value` and `server_value` dict values.
// Entry from `server_value` wins in case of conflict.
base::Value::Dict MergeDictionaryValues(const base::Value::Dict& local_value,
const base::Value::Dict& server_value);
// Merges the `local_value` into the supplied `server_value` and returns
// the result. If there is a conflict, the server value takes precedence. Note
// that only certain preferences will actually be merged, all others will
// return a copy of the server value.
// Note: `client` can NULL in some tests, in which case `server_value` is
// returned.
base::Value MergePreference(const PrefModelAssociatorClient* client,
std::string_view pref_name,
const base::Value& local_value,
const base::Value& server_value);
// This separates individual dictionary pref updates between the account store
// and the local store, from the updated merged value `new_value`. Returns a
// pair with the first item being the updated local value, followed by the
// updated account value.
std::pair<base::Value::Dict, base::Value::Dict> UnmergeDictionaryValues(
base::Value::Dict new_value,
const base::Value::Dict& original_local_value,
const base::Value::Dict& original_account_value);
} // namespace helper
} // namespace sync_preferences
#endif // COMPONENTS_SYNC_PREFERENCES_PREFERENCES_MERGE_HELPER_H_
|