0

Use std::string_view in PrefFilter.

Bug: 349741884
Change-Id: I3d63e6649e767796d39855eb2d8af5e428a3e426
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5666576
Reviewed-by: Colin Blundell <blundell@chromium.org>
Commit-Queue: Jan Keitel <jkeitel@google.com>
Reviewed-by: Dominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1320950}
This commit is contained in:
Jan Keitel
2024-06-28 14:26:43 +00:00
committed by Chromium LUCI CQ
parent 667c35b8b5
commit ff51e2f893
6 changed files with 19 additions and 12 deletions

@ -74,7 +74,7 @@ class InterceptingPrefFilter : public PrefFilter {
// PrefFilter implementation:
void FilterOnLoad(PostFilterOnLoadCallback post_filter_on_load_callback,
base::Value::Dict pref_store_contents) override;
void FilterUpdate(const std::string& path) override {}
void FilterUpdate(std::string_view path) override {}
OnWriteCallbackPair FilterSerializeData(
base::Value::Dict& pref_store_contents) override {
return std::move(on_write_callback_pair_);

@ -5,7 +5,7 @@
#ifndef COMPONENTS_PREFS_PREF_FILTER_H_
#define COMPONENTS_PREFS_PREF_FILTER_H_
#include <string>
#include <string_view>
#include <utility>
#include "base/functional/callback_forward.h"
@ -27,7 +27,7 @@ class COMPONENTS_PREFS_EXPORT PrefFilter {
using PostFilterOnLoadCallback =
base::OnceCallback<void(base::Value::Dict prefs, bool schedule_write)>;
virtual ~PrefFilter() {}
virtual ~PrefFilter() = default;
// This method is given ownership of the |pref_store_contents| read from disk
// before the underlying PersistentPrefStore gets to use them. It must hand
@ -42,7 +42,7 @@ class COMPONENTS_PREFS_EXPORT PrefFilter {
// Receives notification when a pref store value is changed, before Observers
// are notified.
virtual void FilterUpdate(const std::string& path) = 0;
virtual void FilterUpdate(std::string_view path) = 0;
// Receives notification when the pref store is about to serialize data
// contained in |pref_store_contents| to a string. Modifications to

@ -16,7 +16,7 @@ namespace {
class TestInterceptablePrefFilter final : public InterceptablePrefFilter {
public:
void FilterUpdate(const std::string& path) override {}
void FilterUpdate(std::string_view path) override {}
OnWriteCallbackPair FilterSerializeData(
base::Value::Dict& pref_store_contents) override {

@ -173,7 +173,7 @@ void PrefHashFilter::Initialize(base::Value::Dict& pref_store_contents) {
// Marks |path| has having changed if it is part of |tracked_paths_|. A new hash
// will be stored for it the next time FilterSerializeData() is invoked.
void PrefHashFilter::FilterUpdate(const std::string& path) {
void PrefHashFilter::FilterUpdate(std::string_view path) {
auto it = tracked_paths_.find(path);
if (it != tracked_paths_.end())
changed_paths_.insert(std::make_pair(path, it->second.get()));

@ -7,10 +7,12 @@
#include <stddef.h>
#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string_view>
#include <unordered_map>
#include <vector>
@ -33,11 +35,9 @@ namespace base {
class Time;
} // namespace base
namespace prefs {
namespace mojom {
namespace prefs::mojom {
class TrackedPreferenceValidationDelegate;
}
}
namespace user_prefs {
class PrefRegistrySyncable;
@ -94,7 +94,7 @@ class PrefHashFilter final : public InterceptablePrefFilter {
void Initialize(base::Value::Dict& pref_store_contents);
// PrefFilter remaining implementation.
void FilterUpdate(const std::string& path) override;
void FilterUpdate(std::string_view path) override;
OnWriteCallbackPair FilterSerializeData(
base::Value::Dict& pref_store_contents) override;
@ -138,8 +138,14 @@ class PrefHashFilter final : public InterceptablePrefFilter {
// A map of paths to TrackedPreferences; this map owns this individual
// TrackedPreference objects.
struct StringViewHasher : public std::hash<std::string_view> {
using is_transparent = void;
};
using TrackedPreferencesMap =
std::unordered_map<std::string, std::unique_ptr<TrackedPreference>>;
std::unordered_map<std::string,
std::unique_ptr<TrackedPreference>,
StringViewHasher,
std::equal_to<>>;
// A map from changed paths to their corresponding TrackedPreferences (which
// aren't owned by this map).

@ -7,6 +7,7 @@
#include <memory>
#include <set>
#include <string>
#include <string_view>
#include <utility>
#include <vector>
@ -46,7 +47,7 @@ const char kPreviouslyProtectedPrefValue[] = "previously_protected_value";
class SimpleInterceptablePrefFilter final : public InterceptablePrefFilter {
public:
// PrefFilter remaining implementation.
void FilterUpdate(const std::string& path) override { ADD_FAILURE(); }
void FilterUpdate(std::string_view path) override { ADD_FAILURE(); }
OnWriteCallbackPair FilterSerializeData(
base::Value::Dict& pref_store_contents) override {
ADD_FAILURE();