0

Perform minor cleanup in PrefService.

Eliminate an unnecessary copy and make it explicit that a raw_ptr is
always non-null by using a raw_ref.

Bug: n/a
Change-Id: I39191ec7647a52fb84875c83649fe8b9f6ff68bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5658253
Reviewed-by: Dominic Battré <battre@chromium.org>
Commit-Queue: Dominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1319918}
This commit is contained in:
Jan Keitel
2024-06-26 18:41:25 +00:00
committed by Chromium LUCI CQ
parent 1ed9c8decf
commit 0d3ea0a54a
2 changed files with 5 additions and 3 deletions

@ -10,6 +10,7 @@
#include <string_view>
#include <utility>
#include "base/check_deref.h"
#include "base/check_op.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
@ -615,7 +616,7 @@ PrefService::Preference::Preference(const PrefService* service,
// Cache the registration flags at creation time to avoid multiple map
// lookups later.
registration_flags_(service->pref_registry_->GetRegistrationFlags(name_)),
pref_service_(service) {}
pref_service_(CHECK_DEREF(service)) {}
const base::Value* PrefService::Preference::GetValue() const {
return pref_service_->GetPreferenceValue(name_);

@ -23,6 +23,7 @@
#include "base/compiler_specific.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/memory/ref_counted.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
@ -109,7 +110,7 @@ class COMPONENTS_PREFS_EXPORT PrefService {
// Returns the name of the Preference (i.e., the key, e.g.,
// browser.window_placement).
std::string name() const { return name_; }
const std::string& name() const { return name_; }
// Returns the registered type of the preference.
base::Value::Type GetType() const { return type_; }
@ -196,7 +197,7 @@ class COMPONENTS_PREFS_EXPORT PrefService {
const uint32_t registration_flags_;
// Reference to the PrefService in which this pref was created.
const raw_ptr<const PrefService> pref_service_;
const raw_ref<const PrefService> pref_service_;
};
// You may wish to use PrefServiceFactory or one of its subclasses