0

Use std::string_view in WritablePrefStore.

Bug: 349741884
Change-Id: I3b202188de492556d87c9f86b446874ac721951c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5667357
Commit-Queue: Jan Keitel <jkeitel@google.com>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Reviewed-by: Dominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1320952}
This commit is contained in:
Jan Keitel
2024-06-28 14:30:53 +00:00
committed by Chromium LUCI CQ
parent c92ab8c815
commit 331cd16999
19 changed files with 138 additions and 150 deletions

@@ -25,7 +25,7 @@ base::Value::Dict InMemoryPrefStore::GetValues() const {
return prefs_.AsDict(); return prefs_.AsDict();
} }
bool InMemoryPrefStore::GetMutableValue(const std::string& key, bool InMemoryPrefStore::GetMutableValue(std::string_view key,
base::Value** value) { base::Value** value) {
return prefs_.GetValue(key, value); return prefs_.GetValue(key, value);
} }
@@ -46,26 +46,25 @@ bool InMemoryPrefStore::IsInitializationComplete() const {
return true; return true;
} }
void InMemoryPrefStore::SetValue(const std::string& key, void InMemoryPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
if (prefs_.SetValue(key, std::move(value))) if (prefs_.SetValue(key, std::move(value)))
ReportValueChanged(key, flags); ReportValueChanged(key, flags);
} }
void InMemoryPrefStore::SetValueSilently(const std::string& key, void InMemoryPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
prefs_.SetValue(key, std::move(value)); prefs_.SetValue(key, std::move(value));
} }
void InMemoryPrefStore::RemoveValue(const std::string& key, uint32_t flags) { void InMemoryPrefStore::RemoveValue(std::string_view key, uint32_t flags) {
if (prefs_.RemoveValue(key)) if (prefs_.RemoveValue(key))
ReportValueChanged(key, flags); ReportValueChanged(key, flags);
} }
void InMemoryPrefStore::RemoveValuesByPrefixSilently( void InMemoryPrefStore::RemoveValuesByPrefixSilently(std::string_view prefix) {
const std::string& prefix) {
prefs_.ClearWithPrefix(prefix); prefs_.ClearWithPrefix(prefix);
} }
@@ -85,7 +84,7 @@ void InMemoryPrefStore::ReadPrefsAsync(ReadErrorDelegate* error_delegate) {
delete error_delegate; delete error_delegate;
} }
void InMemoryPrefStore::ReportValueChanged(const std::string& key, void InMemoryPrefStore::ReportValueChanged(std::string_view key,
uint32_t flags) { uint32_t flags) {
for (Observer& observer : observers_) for (Observer& observer : observers_)
observer.OnPrefValueChanged(key); observer.OnPrefValueChanged(key);

@@ -7,7 +7,6 @@
#include <stdint.h> #include <stdint.h>
#include <string>
#include <string_view> #include <string_view>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
@@ -37,15 +36,15 @@ class COMPONENTS_PREFS_EXPORT InMemoryPrefStore : public PersistentPrefStore {
bool IsInitializationComplete() const override; bool IsInitializationComplete() const override;
// PersistentPrefStore implementation. // PersistentPrefStore implementation.
bool GetMutableValue(const std::string& key, base::Value** result) override; bool GetMutableValue(std::string_view key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
bool ReadOnly() const override; bool ReadOnly() const override;
PrefReadError GetReadError() const override; PrefReadError GetReadError() const override;
PersistentPrefStore::PrefReadError ReadPrefs() override; PersistentPrefStore::PrefReadError ReadPrefs() override;
@@ -53,7 +52,7 @@ class COMPONENTS_PREFS_EXPORT InMemoryPrefStore : public PersistentPrefStore {
void SchedulePendingLossyWrites() override {} void SchedulePendingLossyWrites() override {}
void OnStoreDeletionFromDisk() override {} void OnStoreDeletionFromDisk() override {}
bool IsInMemoryPrefStore() const override; bool IsInMemoryPrefStore() const override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
bool HasReadErrorDelegate() const override; bool HasReadErrorDelegate() const override;
protected: protected:

@@ -57,7 +57,7 @@ namespace {
const base::FilePath::CharType kBadExtension[] = FILE_PATH_LITERAL("bad"); const base::FilePath::CharType kBadExtension[] = FILE_PATH_LITERAL("bad");
// Report a key that triggers a write into the Preferences files. // Report a key that triggers a write into the Preferences files.
void ReportKeyChangedToUMA(const std::string& key) { void ReportKeyChangedToUMA(std::string_view key) {
// Truncate the sign bit. Even if the type is unsigned, UMA displays 32-bit // Truncate the sign bit. Even if the type is unsigned, UMA displays 32-bit
// negative numbers. // negative numbers.
const uint32_t hash = base::PersistentHash(key) & 0x7FFFFFFF; const uint32_t hash = base::PersistentHash(key) & 0x7FFFFFFF;
@@ -212,7 +212,7 @@ bool JsonPrefStore::IsInitializationComplete() const {
return initialized_; return initialized_;
} }
bool JsonPrefStore::GetMutableValue(const std::string& key, bool JsonPrefStore::GetMutableValue(std::string_view key,
base::Value** result) { base::Value** result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -225,7 +225,7 @@ bool JsonPrefStore::GetMutableValue(const std::string& key,
return true; return true;
} }
void JsonPrefStore::SetValue(const std::string& key, void JsonPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -238,7 +238,7 @@ void JsonPrefStore::SetValue(const std::string& key,
} }
} }
void JsonPrefStore::SetValueSilently(const std::string& key, void JsonPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -251,7 +251,7 @@ void JsonPrefStore::SetValueSilently(const std::string& key,
} }
} }
void JsonPrefStore::RemoveValue(const std::string& key, uint32_t flags) { void JsonPrefStore::RemoveValue(std::string_view key, uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (prefs_.RemoveByDottedPath(key)) { if (prefs_.RemoveByDottedPath(key)) {
@@ -259,15 +259,14 @@ void JsonPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
} }
} }
void JsonPrefStore::RemoveValueSilently(const std::string& key, void JsonPrefStore::RemoveValueSilently(std::string_view key, uint32_t flags) {
uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
prefs_.RemoveByDottedPath(key); prefs_.RemoveByDottedPath(key);
ScheduleWrite(flags); ScheduleWrite(flags);
} }
void JsonPrefStore::RemoveValuesByPrefixSilently(const std::string& prefix) { void JsonPrefStore::RemoveValuesByPrefixSilently(std::string_view prefix) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
RemoveValueSilently(prefix, /*flags*/ 0); RemoveValueSilently(prefix, /*flags*/ 0);
} }
@@ -338,7 +337,7 @@ void JsonPrefStore::SchedulePendingLossyWrites() {
writer_.ScheduleWrite(this); writer_.ScheduleWrite(this);
} }
void JsonPrefStore::ReportValueChanged(const std::string& key, uint32_t flags) { void JsonPrefStore::ReportValueChanged(std::string_view key, uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (pref_filter_) if (pref_filter_)

@@ -10,7 +10,6 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <set> #include <set>
#include <string>
#include <string_view> #include <string_view>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
@@ -85,14 +84,14 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore final
bool IsInitializationComplete() const override; bool IsInitializationComplete() const override;
// PersistentPrefStore overrides: // PersistentPrefStore overrides:
bool GetMutableValue(const std::string& key, base::Value** result) override; bool GetMutableValue(std::string_view key, base::Value** result) override;
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
bool ReadOnly() const override; bool ReadOnly() const override;
PrefReadError GetReadError() const override; PrefReadError GetReadError() const override;
bool HasReadErrorDelegate() const override; bool HasReadErrorDelegate() const override;
@@ -106,15 +105,15 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore final
base::OnceClosure synchronous_done_callback = base::OnceClosure synchronous_done_callback =
base::OnceClosure()) override; base::OnceClosure()) override;
void SchedulePendingLossyWrites() override; void SchedulePendingLossyWrites() override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
// Just like RemoveValue(), but doesn't notify observers. Used when doing some // Just like RemoveValue(), but doesn't notify observers. Used when doing some
// cleanup that shouldn't otherwise alert observers. // cleanup that shouldn't otherwise alert observers.
void RemoveValueSilently(const std::string& key, uint32_t flags); void RemoveValueSilently(std::string_view key, uint32_t flags);
// Just like RemoveValue(), but removes all the prefs that start with // Just like RemoveValue(), but removes all the prefs that start with
// |prefix|. Used for pref-initialization cleanup. // |prefix|. Used for pref-initialization cleanup.
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
// Registers |on_next_successful_write_reply| to be called once, on the next // Registers |on_next_successful_write_reply| to be called once, on the next
// successful write event of |writer_|. // successful write event of |writer_|.

@@ -108,7 +108,7 @@ base::Value::Dict OverlayUserPrefStore::GetValues() const {
return values; return values;
} }
bool OverlayUserPrefStore::GetMutableValue(const std::string& key, bool OverlayUserPrefStore::GetMutableValue(std::string_view key,
base::Value** result) { base::Value** result) {
if (ShallBeStoredInPersistent(key)) if (ShallBeStoredInPersistent(key))
return persistent_user_pref_store_->GetMutableValue(key, result); return persistent_user_pref_store_->GetMutableValue(key, result);
@@ -128,7 +128,7 @@ bool OverlayUserPrefStore::GetMutableValue(const std::string& key,
return true; return true;
} }
void OverlayUserPrefStore::SetValue(const std::string& key, void OverlayUserPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
if (ShallBeStoredInPersistent(key)) { if (ShallBeStoredInPersistent(key)) {
@@ -142,7 +142,7 @@ void OverlayUserPrefStore::SetValue(const std::string& key,
ephemeral_user_pref_store_->SetValue(key, std::move(value), flags); ephemeral_user_pref_store_->SetValue(key, std::move(value), flags);
} }
void OverlayUserPrefStore::SetValueSilently(const std::string& key, void OverlayUserPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
if (ShallBeStoredInPersistent(key)) { if (ShallBeStoredInPersistent(key)) {
@@ -153,7 +153,7 @@ void OverlayUserPrefStore::SetValueSilently(const std::string& key,
ephemeral_user_pref_store_->SetValueSilently(key, std::move(value), flags); ephemeral_user_pref_store_->SetValueSilently(key, std::move(value), flags);
} }
void OverlayUserPrefStore::RemoveValue(const std::string& key, uint32_t flags) { void OverlayUserPrefStore::RemoveValue(std::string_view key, uint32_t flags) {
if (ShallBeStoredInPersistent(key)) { if (ShallBeStoredInPersistent(key)) {
persistent_user_pref_store_->RemoveValue(key, flags); persistent_user_pref_store_->RemoveValue(key, flags);
return; return;
@@ -163,7 +163,7 @@ void OverlayUserPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
} }
void OverlayUserPrefStore::RemoveValuesByPrefixSilently( void OverlayUserPrefStore::RemoveValuesByPrefixSilently(
const std::string& prefix) { std::string_view prefix) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
@@ -200,7 +200,7 @@ void OverlayUserPrefStore::SchedulePendingLossyWrites() {
persistent_user_pref_store_->SchedulePendingLossyWrites(); persistent_user_pref_store_->SchedulePendingLossyWrites();
} }
void OverlayUserPrefStore::ReportValueChanged(const std::string& key, void OverlayUserPrefStore::ReportValueChanged(std::string_view key,
uint32_t flags) { uint32_t flags) {
for (PrefStore::Observer& observer : observers_) for (PrefStore::Observer& observer : observers_)
observer.OnPrefValueChanged(key); observer.OnPrefValueChanged(key);

@@ -50,15 +50,15 @@ class COMPONENTS_PREFS_EXPORT OverlayUserPrefStore
base::Value::Dict GetValues() const override; base::Value::Dict GetValues() const override;
// Methods of PersistentPrefStore. // Methods of PersistentPrefStore.
bool GetMutableValue(const std::string& key, base::Value** result) override; bool GetMutableValue(std::string_view key, base::Value** result) override;
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
bool ReadOnly() const override; bool ReadOnly() const override;
PrefReadError GetReadError() const override; PrefReadError GetReadError() const override;
PrefReadError ReadPrefs() override; PrefReadError ReadPrefs() override;
@@ -66,7 +66,7 @@ class COMPONENTS_PREFS_EXPORT OverlayUserPrefStore
void CommitPendingWrite(base::OnceClosure reply_callback, void CommitPendingWrite(base::OnceClosure reply_callback,
base::OnceClosure synchronous_done_callback) override; base::OnceClosure synchronous_done_callback) override;
void SchedulePendingLossyWrites() override; void SchedulePendingLossyWrites() override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
// Registers preferences that should be stored in the persistent preferences // Registers preferences that should be stored in the persistent preferences
// (|persistent_user_pref_store_|). // (|persistent_user_pref_store_|).

@@ -316,25 +316,25 @@ TEST(PrefServiceTest, SetTimeDeltaValue_ZeroTimeDelta) {
// values to it. // values to it.
class WriteFlagChecker : public TestingPrefStore { class WriteFlagChecker : public TestingPrefStore {
public: public:
WriteFlagChecker() {} WriteFlagChecker() = default;
void ReportValueChanged(const std::string& key, uint32_t flags) override { void ReportValueChanged(std::string_view key, uint32_t flags) override {
SetLastWriteFlags(flags); SetLastWriteFlags(flags);
} }
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override { uint32_t flags) override {
SetLastWriteFlags(flags); SetLastWriteFlags(flags);
} }
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override { uint32_t flags) override {
SetLastWriteFlags(flags); SetLastWriteFlags(flags);
} }
void RemoveValue(const std::string& key, uint32_t flags) override { void RemoveValue(std::string_view key, uint32_t flags) override {
SetLastWriteFlags(flags); SetLastWriteFlags(flags);
} }

@@ -4,7 +4,6 @@
#include "components/prefs/segregated_pref_store.h" #include "components/prefs/segregated_pref_store.h"
#include <string>
#include <string_view> #include <string_view>
#include <utility> #include <utility>
@@ -107,35 +106,35 @@ base::Value::Dict SegregatedPrefStore::GetValues() const {
return values; return values;
} }
void SegregatedPrefStore::SetValue(const std::string& key, void SegregatedPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
StoreForKey(key)->SetValue(key, std::move(value), flags); StoreForKey(key)->SetValue(key, std::move(value), flags);
} }
void SegregatedPrefStore::RemoveValue(const std::string& key, uint32_t flags) { void SegregatedPrefStore::RemoveValue(std::string_view key, uint32_t flags) {
StoreForKey(key)->RemoveValue(key, flags); StoreForKey(key)->RemoveValue(key, flags);
} }
void SegregatedPrefStore::RemoveValuesByPrefixSilently( void SegregatedPrefStore::RemoveValuesByPrefixSilently(
const std::string& prefix) { std::string_view prefix) {
// Since we can't guarantee to have all the prefs in one the pref stores, we // Since we can't guarantee to have all the prefs in one the pref stores, we
// have to push the removal command down to both of them. // have to push the removal command down to both of them.
default_pref_store_->RemoveValuesByPrefixSilently(prefix); default_pref_store_->RemoveValuesByPrefixSilently(prefix);
selected_pref_store_->RemoveValuesByPrefixSilently(prefix); selected_pref_store_->RemoveValuesByPrefixSilently(prefix);
} }
bool SegregatedPrefStore::GetMutableValue(const std::string& key, bool SegregatedPrefStore::GetMutableValue(std::string_view key,
base::Value** result) { base::Value** result) {
return StoreForKey(key)->GetMutableValue(key, result); return StoreForKey(key)->GetMutableValue(key, result);
} }
void SegregatedPrefStore::ReportValueChanged(const std::string& key, void SegregatedPrefStore::ReportValueChanged(std::string_view key,
uint32_t flags) { uint32_t flags) {
StoreForKey(key)->ReportValueChanged(key, flags); StoreForKey(key)->ReportValueChanged(key, flags);
} }
void SegregatedPrefStore::SetValueSilently(const std::string& key, void SegregatedPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
StoreForKey(key)->SetValueSilently(key, std::move(value), flags); StoreForKey(key)->SetValueSilently(key, std::move(value), flags);

@@ -10,7 +10,6 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <set> #include <set>
#include <string>
#include <string_view> #include <string_view>
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
@@ -60,16 +59,16 @@ class COMPONENTS_PREFS_EXPORT SegregatedPrefStore : public PersistentPrefStore {
base::Value::Dict GetValues() const override; base::Value::Dict GetValues() const override;
// WriteablePrefStore implementation // WriteablePrefStore implementation
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
// PersistentPrefStore implementation // PersistentPrefStore implementation
bool GetMutableValue(const std::string& key, base::Value** result) override; bool GetMutableValue(std::string_view key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
bool ReadOnly() const override; bool ReadOnly() const override;

@@ -83,7 +83,7 @@ base::Value::Dict TestingPrefStore::GetValues() const {
return prefs_.AsDict(); return prefs_.AsDict();
} }
bool TestingPrefStore::GetMutableValue(const std::string& key, bool TestingPrefStore::GetMutableValue(std::string_view key,
base::Value** value) { base::Value** value) {
return prefs_.GetValue(key, value); return prefs_.GetValue(key, value);
} }
@@ -104,7 +104,7 @@ bool TestingPrefStore::IsInitializationComplete() const {
return init_complete_; return init_complete_;
} }
void TestingPrefStore::SetValue(const std::string& key, void TestingPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
if (prefs_.SetValue(key, std::move(value))) { if (prefs_.SetValue(key, std::move(value))) {
@@ -113,7 +113,7 @@ void TestingPrefStore::SetValue(const std::string& key,
} }
} }
void TestingPrefStore::SetValueSilently(const std::string& key, void TestingPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
CheckPrefIsSerializable(key, value); CheckPrefIsSerializable(key, value);
@@ -121,14 +121,14 @@ void TestingPrefStore::SetValueSilently(const std::string& key,
committed_ = false; committed_ = false;
} }
void TestingPrefStore::RemoveValue(const std::string& key, uint32_t flags) { void TestingPrefStore::RemoveValue(std::string_view key, uint32_t flags) {
if (prefs_.RemoveValue(key)) { if (prefs_.RemoveValue(key)) {
committed_ = false; committed_ = false;
NotifyPrefValueChanged(key); NotifyPrefValueChanged(key);
} }
} }
void TestingPrefStore::RemoveValuesByPrefixSilently(const std::string& prefix) { void TestingPrefStore::RemoveValuesByPrefixSilently(std::string_view prefix) {
prefs_.ClearWithPrefix(prefix); prefs_.ClearWithPrefix(prefix);
} }
@@ -168,7 +168,7 @@ void TestingPrefStore::SetInitializationCompleted() {
NotifyInitializationCompleted(); NotifyInitializationCompleted();
} }
void TestingPrefStore::NotifyPrefValueChanged(const std::string& key) { void TestingPrefStore::NotifyPrefValueChanged(std::string_view key) {
for (Observer& observer : observers_) for (Observer& observer : observers_)
observer.OnPrefValueChanged(key); observer.OnPrefValueChanged(key);
} }
@@ -184,7 +184,7 @@ void TestingPrefStore::NotifyInitializationCompleted() {
observer.OnInitializationCompleted(read_success_); observer.OnInitializationCompleted(read_success_);
} }
void TestingPrefStore::ReportValueChanged(const std::string& key, void TestingPrefStore::ReportValueChanged(std::string_view key,
uint32_t flags) { uint32_t flags) {
const base::Value* value = nullptr; const base::Value* value = nullptr;
if (prefs_.GetValue(key, &value)) if (prefs_.GetValue(key, &value))
@@ -290,7 +290,7 @@ TestingPrefStore::~TestingPrefStore() {
CheckPrefIsSerializable(pref.first, pref.second); CheckPrefIsSerializable(pref.first, pref.second);
} }
void TestingPrefStore::CheckPrefIsSerializable(const std::string& key, void TestingPrefStore::CheckPrefIsSerializable(std::string_view key,
const base::Value& value) { const base::Value& value) {
std::string json; std::string json;
EXPECT_TRUE(base::JSONWriter::Write(value, &json)) EXPECT_TRUE(base::JSONWriter::Write(value, &json))

@@ -37,16 +37,16 @@ class TestingPrefStore : public PersistentPrefStore {
bool IsInitializationComplete() const override; bool IsInitializationComplete() const override;
// PersistentPrefStore overrides: // PersistentPrefStore overrides:
bool GetMutableValue(const std::string& key, base::Value** result) override; bool GetMutableValue(std::string_view key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
bool ReadOnly() const override; bool ReadOnly() const override;
PrefReadError GetReadError() const override; PrefReadError GetReadError() const override;
PersistentPrefStore::PrefReadError ReadPrefs() override; PersistentPrefStore::PrefReadError ReadPrefs() override;
@@ -60,7 +60,7 @@ class TestingPrefStore : public PersistentPrefStore {
void SetInitializationCompleted(); void SetInitializationCompleted();
// Used for tests to trigger notifications explicitly. // Used for tests to trigger notifications explicitly.
void NotifyPrefValueChanged(const std::string& key); void NotifyPrefValueChanged(std::string_view key);
void NotifyInitializationCompleted(); void NotifyInitializationCompleted();
// Some convenience getters/setters. // Some convenience getters/setters.
@@ -101,8 +101,7 @@ class TestingPrefStore : public PersistentPrefStore {
~TestingPrefStore() override; ~TestingPrefStore() override;
private: private:
void CheckPrefIsSerializable(const std::string& key, void CheckPrefIsSerializable(std::string_view key, const base::Value& value);
const base::Value& value);
// Stores the preference values. // Stores the preference values.
PrefValueMap prefs_; PrefValueMap prefs_;

@@ -4,15 +4,13 @@
#include "components/prefs/value_map_pref_store.h" #include "components/prefs/value_map_pref_store.h"
#include <algorithm>
#include <string>
#include <string_view> #include <string_view>
#include <utility> #include <utility>
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/values.h" #include "base/values.h"
ValueMapPrefStore::ValueMapPrefStore() {} ValueMapPrefStore::ValueMapPrefStore() = default;
bool ValueMapPrefStore::GetValue(std::string_view key, bool ValueMapPrefStore::GetValue(std::string_view key,
const base::Value** value) const { const base::Value** value) const {
@@ -35,7 +33,7 @@ bool ValueMapPrefStore::HasObservers() const {
return !observers_.empty(); return !observers_.empty();
} }
void ValueMapPrefStore::SetValue(const std::string& key, void ValueMapPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
if (prefs_.SetValue(key, std::move(value))) { if (prefs_.SetValue(key, std::move(value))) {
@@ -44,25 +42,25 @@ void ValueMapPrefStore::SetValue(const std::string& key,
} }
} }
void ValueMapPrefStore::RemoveValue(const std::string& key, uint32_t flags) { void ValueMapPrefStore::RemoveValue(std::string_view key, uint32_t flags) {
if (prefs_.RemoveValue(key)) { if (prefs_.RemoveValue(key)) {
for (Observer& observer : observers_) for (Observer& observer : observers_)
observer.OnPrefValueChanged(key); observer.OnPrefValueChanged(key);
} }
} }
bool ValueMapPrefStore::GetMutableValue(const std::string& key, bool ValueMapPrefStore::GetMutableValue(std::string_view key,
base::Value** value) { base::Value** value) {
return prefs_.GetValue(key, value); return prefs_.GetValue(key, value);
} }
void ValueMapPrefStore::ReportValueChanged(const std::string& key, void ValueMapPrefStore::ReportValueChanged(std::string_view key,
uint32_t flags) { uint32_t flags) {
for (Observer& observer : observers_) for (Observer& observer : observers_)
observer.OnPrefValueChanged(key); observer.OnPrefValueChanged(key);
} }
void ValueMapPrefStore::SetValueSilently(const std::string& key, void ValueMapPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
prefs_.SetValue(key, std::move(value)); prefs_.SetValue(key, std::move(value));
@@ -75,7 +73,6 @@ void ValueMapPrefStore::NotifyInitializationCompleted() {
observer.OnInitializationCompleted(true); observer.OnInitializationCompleted(true);
} }
void ValueMapPrefStore::RemoveValuesByPrefixSilently( void ValueMapPrefStore::RemoveValuesByPrefixSilently(std::string_view prefix) {
const std::string& prefix) {
prefs_.ClearWithPrefix(prefix); prefs_.ClearWithPrefix(prefix);
} }

@@ -8,7 +8,6 @@
#include <stdint.h> #include <stdint.h>
#include <map> #include <map>
#include <string>
#include <string_view> #include <string_view>
#include "base/observer_list.h" #include "base/observer_list.h"
@@ -34,16 +33,16 @@ class COMPONENTS_PREFS_EXPORT ValueMapPrefStore : public WriteablePrefStore {
bool HasObservers() const override; bool HasObservers() const override;
// WriteablePrefStore overrides: // WriteablePrefStore overrides:
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
bool GetMutableValue(const std::string& key, base::Value** value) override; bool GetMutableValue(std::string_view key, base::Value** value) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
protected: protected:
~ValueMapPrefStore() override; ~ValueMapPrefStore() override;

@@ -37,7 +37,7 @@ base::Value::Dict WrapWithPrefixPrefStore::GetValues() const {
return {}; return {};
} }
bool WrapWithPrefixPrefStore::GetMutableValue(const std::string& key, bool WrapWithPrefixPrefStore::GetMutableValue(std::string_view key,
base::Value** value) { base::Value** value) {
return target_pref_store_->GetMutableValue(AddDottedPrefix(key), value); return target_pref_store_->GetMutableValue(AddDottedPrefix(key), value);
} }
@@ -58,26 +58,26 @@ bool WrapWithPrefixPrefStore::IsInitializationComplete() const {
return target_pref_store_->IsInitializationComplete(); return target_pref_store_->IsInitializationComplete();
} }
void WrapWithPrefixPrefStore::SetValue(const std::string& key, void WrapWithPrefixPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
target_pref_store_->SetValue(AddDottedPrefix(key), std::move(value), flags); target_pref_store_->SetValue(AddDottedPrefix(key), std::move(value), flags);
} }
void WrapWithPrefixPrefStore::SetValueSilently(const std::string& key, void WrapWithPrefixPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
target_pref_store_->SetValueSilently(AddDottedPrefix(key), std::move(value), target_pref_store_->SetValueSilently(AddDottedPrefix(key), std::move(value),
flags); flags);
} }
void WrapWithPrefixPrefStore::RemoveValue(const std::string& key, void WrapWithPrefixPrefStore::RemoveValue(std::string_view key,
uint32_t flags) { uint32_t flags) {
target_pref_store_->RemoveValue(AddDottedPrefix(key), flags); target_pref_store_->RemoveValue(AddDottedPrefix(key), flags);
} }
void WrapWithPrefixPrefStore::RemoveValuesByPrefixSilently( void WrapWithPrefixPrefStore::RemoveValuesByPrefixSilently(
const std::string& prefix) { std::string_view prefix) {
target_pref_store_->RemoveValuesByPrefixSilently(AddDottedPrefix(prefix)); target_pref_store_->RemoveValuesByPrefixSilently(AddDottedPrefix(prefix));
} }
@@ -127,7 +127,7 @@ void WrapWithPrefixPrefStore::OnStoreDeletionFromDisk() {
// independently notified of this. // independently notified of this.
} }
void WrapWithPrefixPrefStore::ReportValueChanged(const std::string& key, void WrapWithPrefixPrefStore::ReportValueChanged(std::string_view key,
uint32_t flags) { uint32_t flags) {
return target_pref_store_->ReportValueChanged(AddDottedPrefix(key), flags); return target_pref_store_->ReportValueChanged(AddDottedPrefix(key), flags);
} }

@@ -53,22 +53,22 @@ class COMPONENTS_PREFS_EXPORT WrapWithPrefixPrefStore
bool IsInitializationComplete() const override; bool IsInitializationComplete() const override;
// PersistentPrefStore implementation. // PersistentPrefStore implementation.
bool GetMutableValue(const std::string& key, base::Value** result) override; bool GetMutableValue(std::string_view key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
bool ReadOnly() const override; bool ReadOnly() const override;
PrefReadError GetReadError() const override; PrefReadError GetReadError() const override;
PersistentPrefStore::PrefReadError ReadPrefs() override; PersistentPrefStore::PrefReadError ReadPrefs() override;
void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override; void ReadPrefsAsync(ReadErrorDelegate* error_delegate) override;
void SchedulePendingLossyWrites() override; void SchedulePendingLossyWrites() override;
void OnStoreDeletionFromDisk() override; void OnStoreDeletionFromDisk() override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
bool HasReadErrorDelegate() const override; bool HasReadErrorDelegate() const override;
// PrefStore::Observer implementation. // PrefStore::Observer implementation.

@@ -5,7 +5,7 @@
#include "components/prefs/writeable_pref_store.h" #include "components/prefs/writeable_pref_store.h"
void WriteablePrefStore::ReportSubValuesChanged( void WriteablePrefStore::ReportSubValuesChanged(
const std::string& key, std::string_view key,
std::set<std::vector<std::string>> path_components, std::set<std::vector<std::string>> path_components,
uint32_t flags) { uint32_t flags) {
// Default implementation. Subclasses may use |path_components| to improve // Default implementation. Subclasses may use |path_components| to improve

@@ -10,6 +10,7 @@
#include <memory> #include <memory>
#include <set> #include <set>
#include <string> #include <string>
#include <string_view>
#include <vector> #include <vector>
#include "components/prefs/pref_store.h" #include "components/prefs/pref_store.h"
@@ -32,59 +33,58 @@ class COMPONENTS_PREFS_EXPORT WriteablePrefStore : public PrefStore {
LOSSY_PREF_WRITE_FLAG = 1 << 1 LOSSY_PREF_WRITE_FLAG = 1 << 1
}; };
WriteablePrefStore() {} WriteablePrefStore() = default;
WriteablePrefStore(const WriteablePrefStore&) = delete; WriteablePrefStore(const WriteablePrefStore&) = delete;
WriteablePrefStore& operator=(const WriteablePrefStore&) = delete; WriteablePrefStore& operator=(const WriteablePrefStore&) = delete;
// Sets a |value| for |key| in the store. |flags| is a bitmask of // Sets a `value` for `key` in the store. `flags` is a bitmask of
// PrefWriteFlags. // PrefWriteFlags.
virtual void SetValue(const std::string& key, virtual void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) = 0; uint32_t flags) = 0;
// Removes the value for |key|. |flags| is a bitmask of // Removes the value for `key`. `flags` is a bitmask of
// PrefWriteFlags. // PrefWriteFlags.
virtual void RemoveValue(const std::string& key, uint32_t flags) = 0; virtual void RemoveValue(std::string_view key, uint32_t flags) = 0;
// Equivalent to PrefStore::GetValue but returns a mutable value. // Equivalent to PrefStore::GetValue but returns a mutable value.
virtual bool GetMutableValue(const std::string& key, virtual bool GetMutableValue(std::string_view key, base::Value** result) = 0;
base::Value** result) = 0;
// Triggers a value changed notification. This function or // Triggers a value changed notification. This function or
// ReportSubValuesChanged needs to be called if one retrieves a list or // ReportSubValuesChanged needs to be called if one retrieves a list or
// dictionary with GetMutableValue and change its value. SetValue takes care // dictionary with GetMutableValue and change its value. SetValue takes care
// of notifications itself. Note that ReportValueChanged will trigger // of notifications itself. Note that ReportValueChanged will trigger
// notifications even if nothing has changed. |flags| is a bitmask of // notifications even if nothing has changed. `flags` is a bitmask of
// PrefWriteFlags. // PrefWriteFlags.
virtual void ReportValueChanged(const std::string& key, uint32_t flags) = 0; virtual void ReportValueChanged(std::string_view key, uint32_t flags) = 0;
// Triggers a value changed notification for |path_components| in the |key| // Triggers a value changed notification for `path_components` in the `key`
// pref. This function or ReportValueChanged needs to be called if one // pref. This function or ReportValueChanged needs to be called if one
// retrieves a list or dictionary with GetMutableValue and change its value. // retrieves a list or dictionary with GetMutableValue and change its value.
// SetValue takes care of notifications itself. Note that // SetValue takes care of notifications itself. Note that
// ReportSubValuesChanged will trigger notifications even if nothing has // ReportSubValuesChanged will trigger notifications even if nothing has
// changed. |flags| is a bitmask of PrefWriteFlags. // changed. `flags` is a bitmask of PrefWriteFlags.
virtual void ReportSubValuesChanged( virtual void ReportSubValuesChanged(
const std::string& key, std::string_view key,
std::set<std::vector<std::string>> path_components, std::set<std::vector<std::string>> path_components,
uint32_t flags); uint32_t flags);
// Same as SetValue, but doesn't generate notifications. This is used by // Same as SetValue, but doesn't generate notifications. This is used by
// PrefService::GetMutableUserPref() in order to put empty entries // PrefService::GetMutableUserPref() in order to put empty entries
// into the user pref store. Using SetValue is not an option since existing // into the user pref store. Using SetValue is not an option since existing
// tests rely on the number of notifications generated. |flags| is a bitmask // tests rely on the number of notifications generated. `flags` is a bitmask
// of PrefWriteFlags. // of PrefWriteFlags.
virtual void SetValueSilently(const std::string& key, virtual void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) = 0; uint32_t flags) = 0;
// Clears all the preferences which names start with |prefix| and doesn't // Clears all the preferences which names start with `prefix` and doesn't
// generate update notifications. // generate update notifications.
virtual void RemoveValuesByPrefixSilently(const std::string& prefix) = 0; virtual void RemoveValuesByPrefixSilently(std::string_view prefix) = 0;
protected: protected:
~WriteablePrefStore() override {} ~WriteablePrefStore() override = default;
}; };
#endif // COMPONENTS_PREFS_WRITEABLE_PREF_STORE_H_ #endif // COMPONENTS_PREFS_WRITEABLE_PREF_STORE_H_

@@ -180,7 +180,7 @@ base::Value::Dict DualLayerUserPrefStore::GetValues() const {
return values; return values;
} }
void DualLayerUserPrefStore::SetValue(const std::string& key, void DualLayerUserPrefStore::SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
const base::Value* initial_value = nullptr; const base::Value* initial_value = nullptr;
@@ -213,8 +213,7 @@ void DualLayerUserPrefStore::SetValue(const std::string& key,
} }
} }
void DualLayerUserPrefStore::RemoveValue(const std::string& key, void DualLayerUserPrefStore::RemoveValue(std::string_view key, uint32_t flags) {
uint32_t flags) {
// Only proceed if the pref exists. // Only proceed if the pref exists.
if (!GetValue(key, nullptr)) { if (!GetValue(key, nullptr)) {
return; return;
@@ -236,7 +235,7 @@ void DualLayerUserPrefStore::RemoveValue(const std::string& key,
} }
} }
bool DualLayerUserPrefStore::GetMutableValue(const std::string& key, bool DualLayerUserPrefStore::GetMutableValue(std::string_view key,
base::Value** result) { base::Value** result) {
if (!ShouldGetValueFromAccountStore(key)) { if (!ShouldGetValueFromAccountStore(key)) {
return local_pref_store_->GetMutableValue(key, result); return local_pref_store_->GetMutableValue(key, result);
@@ -270,7 +269,7 @@ bool DualLayerUserPrefStore::GetMutableValue(const std::string& key,
return true; return true;
} }
void DualLayerUserPrefStore::ReportValueChanged(const std::string& key, void DualLayerUserPrefStore::ReportValueChanged(std::string_view key,
uint32_t flags) { uint32_t flags) {
{ {
base::AutoReset<bool> setting_prefs(&is_setting_prefs_, true); base::AutoReset<bool> setting_prefs(&is_setting_prefs_, true);
@@ -306,7 +305,7 @@ void DualLayerUserPrefStore::ReportValueChanged(const std::string& key,
} }
} }
void DualLayerUserPrefStore::SetValueSilently(const std::string& key, void DualLayerUserPrefStore::SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) { uint32_t flags) {
if (ShouldSetValueInAccountStore(key)) { if (ShouldSetValueInAccountStore(key)) {
@@ -327,7 +326,7 @@ void DualLayerUserPrefStore::SetValueSilently(const std::string& key,
} }
void DualLayerUserPrefStore::RemoveValuesByPrefixSilently( void DualLayerUserPrefStore::RemoveValuesByPrefixSilently(
const std::string& prefix) { std::string_view prefix) {
local_pref_store_->RemoveValuesByPrefixSilently(prefix); local_pref_store_->RemoveValuesByPrefixSilently(prefix);
// RemoveValuesByPrefixSilently() is not used for the account store since it // RemoveValuesByPrefixSilently() is not used for the account store since it
@@ -421,7 +420,7 @@ void DualLayerUserPrefStore::OnStoreDeletionFromDisk() {
} }
bool DualLayerUserPrefStore::ShouldSetValueInAccountStore( bool DualLayerUserPrefStore::ShouldSetValueInAccountStore(
const std::string& key) const { std::string_view key) const {
// A preference `key` is added to account store only if it is syncable, the // A preference `key` is added to account store only if it is syncable, the
// corresponding pref type is active, and falls under the current user // corresponding pref type is active, and falls under the current user
// consent, i.e. "privacy-sensitive" prefs require history opt-in. // consent, i.e. "privacy-sensitive" prefs require history opt-in.
@@ -433,7 +432,7 @@ bool DualLayerUserPrefStore::ShouldSetValueInAccountStore(
auto metadata = pref_model_associator_client_->GetSyncablePrefsDatabase() auto metadata = pref_model_associator_client_->GetSyncablePrefsDatabase()
.GetSyncablePrefMetadata(key); .GetSyncablePrefMetadata(key);
// Checks if the pref type is active. // Checks if the pref type is active.
if (!active_types_.count(metadata->model_type()) && if (!active_types_.contains(metadata->model_type()) &&
// Checks if the pref already exists in the account store. // Checks if the pref already exists in the account store.
// This is to handle cases where a pref might pre-exist before sync is // This is to handle cases where a pref might pre-exist before sync is
// initialized and the type is marked as active. // initialized and the type is marked as active.
@@ -444,7 +443,7 @@ bool DualLayerUserPrefStore::ShouldSetValueInAccountStore(
} }
bool DualLayerUserPrefStore::ShouldGetValueFromAccountStore( bool DualLayerUserPrefStore::ShouldGetValueFromAccountStore(
const std::string& key) const { std::string_view key) const {
// A preference `key` is queried from account store only if it is syncable and // A preference `key` is queried from account store only if it is syncable and
// falls under the current user consent, i.e. "privacy-sensitive" prefs // falls under the current user consent, i.e. "privacy-sensitive" prefs
// require history opt-in. // require history opt-in.
@@ -561,7 +560,7 @@ bool DualLayerUserPrefStore::IsPrefKeyMergeable(std::string_view key) const {
} }
const base::Value* DualLayerUserPrefStore::MaybeMerge( const base::Value* DualLayerUserPrefStore::MaybeMerge(
const std::string& pref_name, std::string_view pref_name,
const base::Value& local_value, const base::Value& local_value,
const base::Value& account_value) const { const base::Value& account_value) const {
// Return the account value if `pref_name` is not mergeable. // Return the account value if `pref_name` is not mergeable.
@@ -596,7 +595,7 @@ const base::Value* DualLayerUserPrefStore::MaybeMerge(
return merged_pref; return merged_pref;
} }
base::Value* DualLayerUserPrefStore::MaybeMerge(const std::string& pref_name, base::Value* DualLayerUserPrefStore::MaybeMerge(std::string_view pref_name,
base::Value& local_value, base::Value& local_value,
base::Value& account_value) { base::Value& account_value) {
// Doing const_cast should be safe as ultimately the value being pointed to is // Doing const_cast should be safe as ultimately the value being pointed to is
@@ -606,7 +605,7 @@ base::Value* DualLayerUserPrefStore::MaybeMerge(const std::string& pref_name,
} }
std::pair<base::Value, base::Value> DualLayerUserPrefStore::UnmergeValue( std::pair<base::Value, base::Value> DualLayerUserPrefStore::UnmergeValue(
const std::string& pref_name, std::string_view pref_name,
base::Value value, base::Value value,
uint32_t flags) const { uint32_t flags) const {
CHECK(ShouldSetValueInAccountStore(pref_name)); CHECK(ShouldSetValueInAccountStore(pref_name));

@@ -83,16 +83,16 @@ class DualLayerUserPrefStore : public PersistentPrefStore,
base::Value::Dict GetValues() const override; base::Value::Dict GetValues() const override;
// WriteablePrefStore implementation. // WriteablePrefStore implementation.
void SetValue(const std::string& key, void SetValue(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override; void RemoveValue(std::string_view key, uint32_t flags) override;
bool GetMutableValue(const std::string& key, base::Value** result) override; bool GetMutableValue(std::string_view key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override; void ReportValueChanged(std::string_view key, uint32_t flags) override;
void SetValueSilently(const std::string& key, void SetValueSilently(std::string_view key,
base::Value value, base::Value value,
uint32_t flags) override; uint32_t flags) override;
void RemoveValuesByPrefixSilently(const std::string& prefix) override; void RemoveValuesByPrefixSilently(std::string_view prefix) override;
// PersistentPrefStore implementation. // PersistentPrefStore implementation.
bool ReadOnly() const override; bool ReadOnly() const override;
@@ -151,11 +151,11 @@ class DualLayerUserPrefStore : public PersistentPrefStore,
// Returns whether the pref with the given `key` should be inserted into the // Returns whether the pref with the given `key` should be inserted into the
// account pref store. Note that the account store keeps in sync with the // account pref store. Note that the account store keeps in sync with the
// account. // account.
bool ShouldSetValueInAccountStore(const std::string& key) const; bool ShouldSetValueInAccountStore(std::string_view key) const;
// Returns whether the pref with the given `key` should be queried from the // Returns whether the pref with the given `key` should be queried from the
// account pref store. Note that the account store keeps in sync with the // account pref store. Note that the account store keeps in sync with the
// account. // account.
bool ShouldGetValueFromAccountStore(const std::string& key) const; bool ShouldGetValueFromAccountStore(std::string_view key) const;
// Returns whether the pref with the given `key` is mergeable. // Returns whether the pref with the given `key` is mergeable.
bool IsPrefKeyMergeable(std::string_view key) const; bool IsPrefKeyMergeable(std::string_view key) const;
@@ -164,16 +164,16 @@ class DualLayerUserPrefStore : public PersistentPrefStore,
// `pref_name` is a mergeable pref, a new merged pref is returned, which is // `pref_name` is a mergeable pref, a new merged pref is returned, which is
// owned by `merged_prefs_`. Else, it returns a pointer to the account value, // owned by `merged_prefs_`. Else, it returns a pointer to the account value,
// given that in this case the account value overrides the local value. // given that in this case the account value overrides the local value.
const base::Value* MaybeMerge(const std::string& pref_name, const base::Value* MaybeMerge(std::string_view pref_name,
const base::Value& local_value, const base::Value& local_value,
const base::Value& account_value) const; const base::Value& account_value) const;
base::Value* MaybeMerge(const std::string& pref_name, base::Value* MaybeMerge(std::string_view pref_name,
base::Value& local_value, base::Value& local_value,
base::Value& account_value); base::Value& account_value);
// Unmerges `value` and returns the new local value and the account value (in // Unmerges `value` and returns the new local value and the account value (in
// that order). // that order).
std::pair<base::Value, base::Value> UnmergeValue(const std::string& pref_name, std::pair<base::Value, base::Value> UnmergeValue(std::string_view pref_name,
base::Value value, base::Value value,
uint32_t flags) const; uint32_t flags) const;