Use std::string_view in PrefStore::Observer.
Bug: 349741884 Change-Id: Ifa66cb4a47c17864247eee8006fcaba33a7d90f8 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5666575 Reviewed-by: Dominic Battré <battre@chromium.org> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Auto-Submit: Jan Keitel <jkeitel@google.com> Commit-Queue: Sylvain Defresne <sdefresne@chromium.org> Cr-Commit-Position: refs/heads/main@{#1320933}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
49586524b8
commit
0523c5e385
chrome/browser/prefs
components
prefs
default_pref_store_unittest.ccjson_pref_store_unittest.ccoverlay_user_pref_store.ccpref_service.hpref_store.hpref_store_observer_mock.ccpref_store_observer_mock.hpref_value_store.ccpref_value_store.hpref_value_store_unittest.ccsegregated_pref_store.ccsegregated_pref_store.htesting_pref_store.ccwrap_with_prefix_pref_store.ccwrap_with_prefix_pref_store.hwrap_with_prefix_pref_store_unittest.cc
supervised_user
core
sync_preferences
ios/chrome/browser/net/model
third_party/libaddressinput/chromium
@ -24,8 +24,7 @@ class MockPrefStoreObserver : public PrefStore::Observer {
|
||||
}
|
||||
|
||||
// PrefStore::Observer implementation:
|
||||
void OnPrefValueChanged(const std::string& key) override;
|
||||
void OnInitializationCompleted(bool succeeded) override {}
|
||||
void OnPrefValueChanged(std::string_view key) override;
|
||||
|
||||
private:
|
||||
raw_ptr<DefaultPrefStore> pref_store_;
|
||||
@ -42,7 +41,7 @@ MockPrefStoreObserver::~MockPrefStoreObserver() {
|
||||
pref_store_->RemoveObserver(this);
|
||||
}
|
||||
|
||||
void MockPrefStoreObserver::OnPrefValueChanged(const std::string& key) {
|
||||
void MockPrefStoreObserver::OnPrefValueChanged(std::string_view key) {
|
||||
change_count_++;
|
||||
}
|
||||
|
||||
|
@ -118,13 +118,12 @@ void InterceptingPrefFilter::ReleasePrefs() {
|
||||
|
||||
class MockPrefStoreObserver : public PrefStore::Observer {
|
||||
public:
|
||||
MOCK_METHOD1(OnPrefValueChanged, void (const std::string&));
|
||||
MOCK_METHOD1(OnInitializationCompleted, void (bool));
|
||||
MOCK_METHOD(void, OnInitializationCompleted, (bool), (override));
|
||||
};
|
||||
|
||||
class MockReadErrorDelegate : public PersistentPrefStore::ReadErrorDelegate {
|
||||
public:
|
||||
MOCK_METHOD1(OnError, void(PersistentPrefStore::PrefReadError));
|
||||
MOCK_METHOD(void, OnError, (PersistentPrefStore::PrefReadError), (override));
|
||||
};
|
||||
|
||||
enum class CommitPendingWriteMode {
|
||||
|
@ -25,8 +25,10 @@ class OverlayUserPrefStore::ObserverAdapter : public PrefStore::Observer {
|
||||
: ephemeral_user_pref_store_(ephemeral), parent_(parent) {}
|
||||
|
||||
// Methods of PrefStore::Observer.
|
||||
void OnPrefValueChanged(const std::string& key) override {
|
||||
parent_->OnPrefValueChanged(ephemeral_user_pref_store_, key);
|
||||
void OnPrefValueChanged(std::string_view key) override {
|
||||
// TODO: crbug.com/349741884 - Pass `std::string_view` once the interface is
|
||||
// changed.
|
||||
parent_->OnPrefValueChanged(ephemeral_user_pref_store_, std::string(key));
|
||||
}
|
||||
void OnInitializationCompleted(bool succeeded) override {
|
||||
parent_->OnInitializationCompleted(ephemeral_user_pref_store_, succeeded);
|
||||
|
@ -492,7 +492,6 @@ class COMPONENTS_PREFS_EXPORT PrefService {
|
||||
explicit PersistentPrefStoreLoadingObserver(PrefService* pref_service_);
|
||||
|
||||
// PrefStore::Observer implementation
|
||||
void OnPrefValueChanged(const std::string& key) override {}
|
||||
void OnInitializationCompleted(bool succeeded) override;
|
||||
|
||||
private:
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define COMPONENTS_PREFS_PREF_STORE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/memory/ref_counted.h"
|
||||
@ -25,8 +24,8 @@ class COMPONENTS_PREFS_EXPORT PrefStore : public base::RefCounted<PrefStore> {
|
||||
// Observer interface for monitoring PrefStore.
|
||||
class COMPONENTS_PREFS_EXPORT Observer {
|
||||
public:
|
||||
// Called when the value for the given |key| in the store changes.
|
||||
virtual void OnPrefValueChanged(const std::string& key) {}
|
||||
// Called when the value for the given `key` in the store changes.
|
||||
virtual void OnPrefValueChanged(std::string_view key) {}
|
||||
// Notification about the PrefStore being fully initialized.
|
||||
virtual void OnInitializationCompleted(bool succeeded) {}
|
||||
|
||||
@ -47,9 +46,9 @@ class COMPONENTS_PREFS_EXPORT PrefStore : public base::RefCounted<PrefStore> {
|
||||
// Whether the store has completed all asynchronous initialization.
|
||||
virtual bool IsInitializationComplete() const;
|
||||
|
||||
// Get the value for a given preference |key| and stores it in |*result|.
|
||||
// |*result| is only modified if the return value is true and if |result|
|
||||
// is not NULL. Ownership of the |*result| value remains with the PrefStore.
|
||||
// Get the value for a given preference `key` and stores it in `*result`.
|
||||
// `*result` is only modified if the return value is true and if `result`
|
||||
// is not NULL. Ownership of the `*result` value remains with the PrefStore.
|
||||
virtual bool GetValue(std::string_view key,
|
||||
const base::Value** result) const = 0;
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "components/prefs/pref_store_observer_mock.h"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
PrefStoreObserverMock::PrefStoreObserverMock()
|
||||
@ -19,8 +21,8 @@ void PrefStoreObserverMock::VerifyAndResetChangedKey(
|
||||
changed_keys.clear();
|
||||
}
|
||||
|
||||
void PrefStoreObserverMock::OnPrefValueChanged(const std::string& key) {
|
||||
changed_keys.push_back(key);
|
||||
void PrefStoreObserverMock::OnPrefValueChanged(std::string_view key) {
|
||||
changed_keys.emplace_back(key);
|
||||
}
|
||||
|
||||
void PrefStoreObserverMock::OnInitializationCompleted(bool success) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#ifndef COMPONENTS_PREFS_PREF_STORE_OBSERVER_MOCK_H_
|
||||
#define COMPONENTS_PREFS_PREF_STORE_OBSERVER_MOCK_H_
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
@ -24,7 +24,7 @@ class PrefStoreObserverMock : public PrefStore::Observer {
|
||||
void VerifyAndResetChangedKey(const std::string& expected);
|
||||
|
||||
// PrefStore::Observer implementation
|
||||
void OnPrefValueChanged(const std::string& key) override;
|
||||
void OnPrefValueChanged(std::string_view key) override;
|
||||
void OnInitializationCompleted(bool success) override;
|
||||
|
||||
std::vector<std::string> changed_keys;
|
||||
|
@ -39,9 +39,10 @@ void PrefValueStore::PrefStoreKeeper::Initialize(
|
||||
pref_store_->AddObserver(this);
|
||||
}
|
||||
|
||||
void PrefValueStore::PrefStoreKeeper::OnPrefValueChanged(
|
||||
const std::string& key) {
|
||||
pref_value_store_->OnPrefValueChanged(type_, key);
|
||||
void PrefValueStore::PrefStoreKeeper::OnPrefValueChanged(std::string_view key) {
|
||||
// TODO: crbug.com/349741884 - Pass `std::string_view` once the interface is
|
||||
// changed.
|
||||
pref_value_store_->OnPrefValueChanged(type_, std::string(key));
|
||||
}
|
||||
|
||||
void PrefValueStore::PrefStoreKeeper::OnInitializationCompleted(
|
||||
|
@ -192,7 +192,7 @@ class COMPONENTS_PREFS_EXPORT PrefValueStore {
|
||||
|
||||
private:
|
||||
// PrefStore::Observer implementation.
|
||||
void OnPrefValueChanged(const std::string& key) override;
|
||||
void OnPrefValueChanged(std::string_view key) override;
|
||||
void OnInitializationCompleted(bool succeeded) override;
|
||||
|
||||
// PrefValueStore this keeper is part of.
|
||||
|
@ -23,8 +23,8 @@ namespace {
|
||||
// Allows to capture pref notifications through gmock.
|
||||
class MockPrefNotifier : public PrefNotifier {
|
||||
public:
|
||||
MOCK_METHOD1(OnPreferenceChanged, void(const std::string&));
|
||||
MOCK_METHOD1(OnInitializationCompleted, void(bool));
|
||||
MOCK_METHOD(void, OnPreferenceChanged, (const std::string&), (override));
|
||||
MOCK_METHOD(void, OnInitializationCompleted, (bool), (override));
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -23,7 +23,7 @@ SegregatedPrefStore::UnderlyingPrefStoreObserver::UnderlyingPrefStoreObserver(
|
||||
}
|
||||
|
||||
void SegregatedPrefStore::UnderlyingPrefStoreObserver::OnPrefValueChanged(
|
||||
const std::string& key) {
|
||||
std::string_view key) {
|
||||
// Notify Observers only after all underlying PrefStores of the outer
|
||||
// SegregatedPrefStore are initialized.
|
||||
if (!outer_->IsInitializationComplete())
|
||||
|
@ -100,7 +100,7 @@ class COMPONENTS_PREFS_EXPORT SegregatedPrefStore : public PersistentPrefStore {
|
||||
delete;
|
||||
|
||||
// PrefStore::Observer implementation
|
||||
void OnPrefValueChanged(const std::string& key) override;
|
||||
void OnPrefValueChanged(std::string_view key) override;
|
||||
void OnInitializationCompleted(bool succeeded) override;
|
||||
|
||||
bool initialization_succeeded() const { return initialization_succeeded_; }
|
||||
|
@ -51,7 +51,7 @@ class ChangedValueWaiter : public PrefStore::Observer {
|
||||
QuitRunLoopIfNewValueIsPresent();
|
||||
}
|
||||
|
||||
void OnPrefValueChanged(const std::string& key) override {
|
||||
void OnPrefValueChanged(std::string_view key) override {
|
||||
if (key == key_) {
|
||||
QuitRunLoopIfNewValueIsPresent();
|
||||
}
|
||||
|
@ -132,11 +132,11 @@ void WrapWithPrefixPrefStore::ReportValueChanged(const std::string& key,
|
||||
return target_pref_store_->ReportValueChanged(AddDottedPrefix(key), flags);
|
||||
}
|
||||
|
||||
void WrapWithPrefixPrefStore::OnPrefValueChanged(const std::string& key) {
|
||||
void WrapWithPrefixPrefStore::OnPrefValueChanged(std::string_view key) {
|
||||
if (!HasDottedPrefix(key)) {
|
||||
return;
|
||||
}
|
||||
std::string original_key(RemoveDottedPrefix(key));
|
||||
std::string_view original_key(RemoveDottedPrefix(key));
|
||||
for (PrefStore::Observer& observer : observers_) {
|
||||
observer.OnPrefValueChanged(original_key);
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ class COMPONENTS_PREFS_EXPORT WrapWithPrefixPrefStore
|
||||
bool HasReadErrorDelegate() const override;
|
||||
|
||||
// PrefStore::Observer implementation.
|
||||
void OnPrefValueChanged(const std::string& key) override;
|
||||
void OnPrefValueChanged(std::string_view key) override;
|
||||
void OnInitializationCompleted(bool succeeded) override;
|
||||
|
||||
protected:
|
||||
|
@ -58,7 +58,7 @@ class MockPrefStoreObserver : public PrefStore::Observer {
|
||||
public:
|
||||
~MockPrefStoreObserver() override = default;
|
||||
|
||||
MOCK_METHOD(void, OnPrefValueChanged, (const std::string& key), (override));
|
||||
MOCK_METHOD(void, OnPrefValueChanged, (std::string_view key), (override));
|
||||
MOCK_METHOD(void, OnInitializationCompleted, (bool succeeded), (override));
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user