Use std::string_view in PrefRegistry.
Bug: 349741884 Change-Id: I495cc538641abe57a93b586d467d9d0049c23b67 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5678719 Reviewed-by: Dominic Battré <battre@chromium.org> Commit-Queue: Dominic Battré <battre@chromium.org> Auto-Submit: Jan Keitel <jkeitel@google.com> Cr-Commit-Position: refs/heads/main@{#1326193}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
cb6e41f4b4
commit
b0955c2061
@ -4,7 +4,6 @@
|
||||
|
||||
#include "components/prefs/default_pref_store.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
||||
@ -41,8 +40,7 @@ void DefaultPrefStore::SetDefaultValue(std::string_view key, Value value) {
|
||||
prefs_.SetValue(key, std::move(value));
|
||||
}
|
||||
|
||||
void DefaultPrefStore::ReplaceDefaultValue(const std::string& key,
|
||||
Value value) {
|
||||
void DefaultPrefStore::ReplaceDefaultValue(std::string_view key, Value value) {
|
||||
DCHECK(GetValue(key, nullptr));
|
||||
bool notify = prefs_.SetValue(key, std::move(value));
|
||||
if (notify) {
|
||||
|
@ -6,7 +6,6 @@
|
||||
#define COMPONENTS_PREFS_DEFAULT_PREF_STORE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include "base/observer_list.h"
|
||||
@ -39,7 +38,7 @@ class COMPONENTS_PREFS_EXPORT DefaultPrefStore : public PrefStore {
|
||||
|
||||
// Replaces the the value for `key` with a new value. Should only be called
|
||||
// if a value has already been set; otherwise call SetDefaultValue().
|
||||
void ReplaceDefaultValue(const std::string& key, base::Value value);
|
||||
void ReplaceDefaultValue(std::string_view key, base::Value value);
|
||||
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
|
@ -21,8 +21,7 @@ PrefRegistry::PrefRegistry()
|
||||
PrefRegistry::~PrefRegistry() {
|
||||
}
|
||||
|
||||
uint32_t PrefRegistry::GetRegistrationFlags(
|
||||
const std::string& pref_name) const {
|
||||
uint32_t PrefRegistry::GetRegistrationFlags(std::string_view pref_name) const {
|
||||
const auto& it = registration_flags_.find(pref_name);
|
||||
return it != registration_flags_.end() ? it->second : NO_REGISTRATION_FLAGS;
|
||||
}
|
||||
@ -39,7 +38,7 @@ PrefRegistry::const_iterator PrefRegistry::end() const {
|
||||
return defaults_->end();
|
||||
}
|
||||
|
||||
void PrefRegistry::SetDefaultPrefValue(const std::string& pref_name,
|
||||
void PrefRegistry::SetDefaultPrefValue(std::string_view pref_name,
|
||||
base::Value value) {
|
||||
const base::Value* current_value = nullptr;
|
||||
DCHECK(defaults_->GetValue(pref_name, ¤t_value))
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "base/memory/ref_counted.h"
|
||||
#include "components/prefs/pref_value_map.h"
|
||||
#include "components/prefs/prefs_export.h"
|
||||
#include "components/prefs/transparent_unordered_string_map.h"
|
||||
|
||||
namespace base {
|
||||
class Value;
|
||||
@ -52,8 +53,8 @@ class COMPONENTS_PREFS_EXPORT PrefRegistry
|
||||
// Registering a pref as public allows other services to access it.
|
||||
static constexpr PrefRegistrationFlags PUBLIC = 1 << 9;
|
||||
|
||||
typedef PrefValueMap::const_iterator const_iterator;
|
||||
typedef std::unordered_map<std::string, uint32_t> PrefRegistrationFlagsMap;
|
||||
using const_iterator = PrefValueMap::const_iterator;
|
||||
using PrefRegistrationFlagsMap = TransparentUnorderedStringMap<uint32_t>;
|
||||
|
||||
PrefRegistry();
|
||||
|
||||
@ -62,7 +63,7 @@ class COMPONENTS_PREFS_EXPORT PrefRegistry
|
||||
|
||||
// Retrieve the set of registration flags for the given preference. The return
|
||||
// value is a bitmask of PrefRegistrationFlags.
|
||||
uint32_t GetRegistrationFlags(const std::string& pref_name) const;
|
||||
uint32_t GetRegistrationFlags(std::string_view pref_name) const;
|
||||
|
||||
// Gets the registered defaults.
|
||||
scoped_refptr<PrefStore> defaults();
|
||||
@ -74,7 +75,7 @@ class COMPONENTS_PREFS_EXPORT PrefRegistry
|
||||
// Changes the default value for a preference.
|
||||
//
|
||||
// `pref_name` must be a previously registered preference.
|
||||
void SetDefaultPrefValue(const std::string& pref_name, base::Value value);
|
||||
void SetDefaultPrefValue(std::string_view pref_name, base::Value value);
|
||||
|
||||
protected:
|
||||
friend class base::RefCounted<PrefRegistry>;
|
||||
|
@ -383,14 +383,14 @@ const base::Value* PrefService::GetUserPrefValue(std::string_view path) const {
|
||||
return value;
|
||||
}
|
||||
|
||||
void PrefService::SetDefaultPrefValue(const std::string& path,
|
||||
void PrefService::SetDefaultPrefValue(std::string_view path,
|
||||
base::Value value) {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
pref_registry_->SetDefaultPrefValue(path, std::move(value));
|
||||
}
|
||||
|
||||
const base::Value* PrefService::GetDefaultPrefValue(
|
||||
const std::string& path) const {
|
||||
std::string_view path) const {
|
||||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
|
||||
// Lookup the preference in the default store.
|
||||
const base::Value* value = nullptr;
|
||||
|
@ -325,12 +325,12 @@ class COMPONENTS_PREFS_EXPORT PrefService {
|
||||
//
|
||||
// Will cause a pref change notification to be fired if this causes
|
||||
// the effective value to change.
|
||||
void SetDefaultPrefValue(const std::string& path, base::Value value);
|
||||
void SetDefaultPrefValue(std::string_view path, base::Value value);
|
||||
|
||||
// Returns the default value of the given preference. |path| must point to a
|
||||
// registered preference. In that case, will never return nullptr, so callers
|
||||
// do not need to check this.
|
||||
const base::Value* GetDefaultPrefValue(const std::string& path) const;
|
||||
const base::Value* GetDefaultPrefValue(std::string_view path) const;
|
||||
|
||||
// Returns true if a value has been set for the specified path.
|
||||
// NOTE: this is NOT the same as FindPreference. In particular
|
||||
|
Reference in New Issue
Block a user