Import cobalt 25.master.0.1034729
diff --git a/components/prefs/BUILD.gn b/components/prefs/BUILD.gn
index d625cc5..ee349a0 100644
--- a/components/prefs/BUILD.gn
+++ b/components/prefs/BUILD.gn
@@ -56,10 +56,7 @@
configs += [ ":prefs_config" ]
- deps = [
- "//base",
- "//base/util/values:values_util",
- ]
+ deps = [ "//base" ]
}
source_set("test_support") {
diff --git a/components/prefs/METADATA b/components/prefs/METADATA
index d7757ae..48c0ec2 100644
--- a/components/prefs/METADATA
+++ b/components/prefs/METADATA
@@ -1,3 +1,5 @@
+name: "chrome_prefs"
+
third_party {
identifier {
type: "ChromiumVersion"
diff --git a/components/prefs/command_line_pref_store.cc b/components/prefs/command_line_pref_store.cc
index 79fc10c..bd3e1f1 100644
--- a/components/prefs/command_line_pref_store.cc
+++ b/components/prefs/command_line_pref_store.cc
@@ -7,6 +7,7 @@
#include <memory>
#include <string>
+#include "base/logging.h"
#include "base/files/file_path.h"
#include "base/strings/string_number_conversions.h"
@@ -22,7 +23,7 @@
for (size_t i = 0; i < size; ++i) {
if (command_line_->HasSwitch(string_switch[i].switch_name)) {
SetValue(string_switch[i].preference_path,
- std::make_unique<base::Value>(command_line_->GetSwitchValueASCII(
+ base::Value(command_line_->GetSwitchValueASCII(
string_switch[i].switch_name)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
@@ -35,7 +36,7 @@
for (size_t i = 0; i < size; ++i) {
if (command_line_->HasSwitch(path_switch[i].switch_name)) {
SetValue(path_switch[i].preference_path,
- std::make_unique<base::Value>(
+ base::Value(
command_line_->GetSwitchValuePath(path_switch[i].switch_name)
.value()),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
@@ -58,7 +59,7 @@
continue;
}
SetValue(integer_switch[i].preference_path,
- std::make_unique<base::Value>(int_value),
+ base::Value(int_value),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
@@ -70,7 +71,7 @@
for (size_t i = 0; i < size; ++i) {
if (command_line_->HasSwitch(boolean_switch_map[i].switch_name)) {
SetValue(boolean_switch_map[i].preference_path,
- std::make_unique<base::Value>(boolean_switch_map[i].set_value),
+ base::Value(boolean_switch_map[i].set_value),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
}
diff --git a/components/prefs/default_pref_store.cc b/components/prefs/default_pref_store.cc
index d8d13ec..92cfc3a 100644
--- a/components/prefs/default_pref_store.cc
+++ b/components/prefs/default_pref_store.cc
@@ -17,8 +17,8 @@
return prefs_.GetValue(key, result);
}
-std::unique_ptr<base::DictionaryValue> DefaultPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict DefaultPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
void DefaultPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -30,7 +30,7 @@
}
bool DefaultPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
void DefaultPrefStore::SetDefaultValue(const std::string& key, Value value) {
diff --git a/components/prefs/default_pref_store.h b/components/prefs/default_pref_store.h
index 17ba3ec..37db218 100644
--- a/components/prefs/default_pref_store.h
+++ b/components/prefs/default_pref_store.h
@@ -25,7 +25,7 @@
// PrefStore implementation:
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
diff --git a/components/prefs/in_memory_pref_store.cc b/components/prefs/in_memory_pref_store.cc
index 20d1eea..1aebddf 100644
--- a/components/prefs/in_memory_pref_store.cc
+++ b/components/prefs/in_memory_pref_store.cc
@@ -18,8 +18,8 @@
return prefs_.GetValue(key, value);
}
-std::unique_ptr<base::DictionaryValue> InMemoryPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict InMemoryPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
bool InMemoryPrefStore::GetMutableValue(const std::string& key,
@@ -36,7 +36,7 @@
}
bool InMemoryPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool InMemoryPrefStore::IsInitializationComplete() const {
@@ -44,18 +44,18 @@
}
void InMemoryPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value))))
+ DCHECK(!value.is_none());
+ if (prefs_.SetValue(key, std::move(value)))
ReportValueChanged(key, flags);
}
void InMemoryPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
- uint32_t flags) {
- DCHECK(value);
- prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)));
+ base::Value value,
+ uint32_t flags) {
+ DCHECK(!value.is_none());
+ prefs_.SetValue(key, std::move(value));
}
void InMemoryPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
diff --git a/components/prefs/in_memory_pref_store.h b/components/prefs/in_memory_pref_store.h
index c623adb..7e20c01 100644
--- a/components/prefs/in_memory_pref_store.h
+++ b/components/prefs/in_memory_pref_store.h
@@ -26,7 +26,7 @@
// PrefStore implementation.
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -36,10 +36,10 @@
bool GetMutableValue(const std::string& key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
diff --git a/components/prefs/json_pref_store.cc b/components/prefs/json_pref_store.cc
index 9fb45fa..ce678ba 100644
--- a/components/prefs/json_pref_store.cc
+++ b/components/prefs/json_pref_store.cc
@@ -9,6 +9,7 @@
#include <algorithm>
#include <utility>
+#include "base/logging.h"
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
@@ -19,11 +20,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#include "base/task_runner_util.h"
-#include "base/threading/sequenced_task_runner_handle.h"
#include "base/time/default_clock.h"
#include "base/values.h"
#include "components/prefs/pref_filter.h"
@@ -84,8 +83,7 @@
// TODO(erikkay) if we keep this error checking for very long, we may
// want to differentiate between recent and long ago errors.
bool bad_existed = base::PathExists(bad);
- base::CopyFile(path, bad);
- base::DeleteFile(path, false);
+ base::Move(path, bad);
return bad_existed ? PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT
: PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE;
}
@@ -139,7 +137,6 @@
scoped_refptr<base::SequencedTaskRunner> file_task_runner)
: path_(pref_filename),
file_task_runner_(std::move(file_task_runner)),
- prefs_(new base::DictionaryValue()),
read_only_(false),
writer_(pref_filename, file_task_runner_),
pref_filter_(std::move(pref_filter)),
@@ -155,8 +152,12 @@
const base::Value** result) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::Value* tmp = nullptr;
- if (!prefs_->Get(key, &tmp))
+#if defined(STARBOARD)
+ const base::Value* tmp = prefs_.Find(key);
+#else
+ const base::Value* tmp = prefs_.FindByDottedPath(key);
+#endif
+ if (!tmp)
return false;
if (result)
@@ -164,8 +165,8 @@
return true;
}
-std::unique_ptr<base::DictionaryValue> JsonPrefStore::GetValues() const {
- return prefs_->CreateDeepCopy();
+base::Value::Dict JsonPrefStore::GetValues() const {
+ return prefs_.Clone();
}
void JsonPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -183,7 +184,7 @@
bool JsonPrefStore::HasObservers() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool JsonPrefStore::IsInitializationComplete() const {
@@ -196,42 +197,54 @@
base::Value** result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- return prefs_->Get(key, result);
+#if defined(STARBOARD)
+ base::Value* tmp = prefs_.Find(key);
+#else
+ base::Value* tmp = prefs_.FindByDottedPath(key);
+#endif
+ if (!tmp)
+ return false;
+
+ if (result)
+ *result = tmp;
+ return true;
}
void JsonPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(value);
- base::Value* old_value = nullptr;
- prefs_->Get(key, &old_value);
- if (!old_value || !value->Equals(old_value)) {
#if defined(STARBOARD)
- // Value::DictionaryValue::Set creates a nested dictionary treating a URL
- // key as a path, SetKey avoids this.
- prefs_->SetKey(key, base::Value::FromUniquePtrValue(std::move(value)));
+ base::Value* old_value = prefs_.Find(key);
#else
- prefs_->Set(key, std::move(value));
+ base::Value* old_value = prefs_.FindByDottedPath(key);
+#endif
+ if (!old_value || value != *old_value) {
+#if defined(STARBOARD)
+ prefs_.Set(key, std::move(value));
+#else
+ prefs_.SetByDottedPath(key, std::move(value));
#endif
ReportValueChanged(key, flags);
}
}
void JsonPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- DCHECK(value);
- base::Value* old_value = nullptr;
- prefs_->Get(key, &old_value);
- if (!old_value || !value->Equals(old_value)) {
#if defined(STARBOARD)
- prefs_->SetKey(key, base::Value::FromUniquePtrValue(std::move(value)));
+ base::Value* old_value = prefs_.Find(key);
#else
- prefs_->Set(key, std::move(value));
+ base::Value* old_value = prefs_.FindByDottedPath(key);
+#endif
+ if (!old_value || value != *old_value) {
+#if defined(STARBOARD)
+ prefs_.Set(key, std::move(value));
+#else
+ prefs_.SetByDottedPath(key, std::move(value));
#endif
ScheduleWrite(flags);
}
@@ -240,7 +253,11 @@
void JsonPrefStore::RemoveValue(const std::string& key, uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- if (prefs_->RemovePath({key})) {
+#if defined(STARBOARD)
+ if (prefs_.Remove(key)) {
+#else
+ if (prefs_.RemoveByDottedPath(key)) {
+#endif
ReportValueChanged(key, flags);
}
}
@@ -249,7 +266,11 @@
uint32_t flags) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- prefs_->RemovePath({key});
+#if defined(STARBOARD)
+ prefs_.Remove(key);
+#else
+ prefs_.RemoveByDottedPath(key);
+#endif
ScheduleWrite(flags);
}
@@ -280,9 +301,9 @@
error_delegate_.reset(error_delegate);
// Weakly binds the read task so that it doesn't kick in during shutdown.
- base::PostTaskAndReplyWithResult(
- file_task_runner_.get(), FROM_HERE, base::Bind(&ReadPrefsFromDisk, path_),
- base::Bind(&JsonPrefStore::OnFileRead, AsWeakPtr()));
+ file_task_runner_->PostTaskAndReplyWithResult(
+ FROM_HERE, base::BindOnce(&ReadPrefsFromDisk, path_),
+ base::BindOnce(&JsonPrefStore::OnFileRead, AsWeakPtr()));
}
void JsonPrefStore::CommitPendingWrite(
@@ -330,6 +351,16 @@
ScheduleWrite(flags);
}
+void JsonPrefStore::PerformPreserializationTasks() {
+ DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
+ pending_lossy_write_ = false;
+ if (pref_filter_) {
+ OnWriteCallbackPair callbacks = pref_filter_->FilterSerializeData(prefs_);
+ if (!callbacks.first.is_null() || !callbacks.second.is_null())
+ RegisterOnNextWriteSynchronousCallbacks(std::move(callbacks));
+ }
+}
+
void JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback(
bool write_success) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -366,7 +397,7 @@
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(on_next_successful_write_reply_.is_null());
- on_next_successful_write_reply_ = on_next_successful_write_reply;
+ on_next_successful_write_reply_ = std::move(on_next_successful_write_reply);
// If there are pending callbacks, avoid erasing them; the reply will be used
// as we set |on_next_successful_write_reply_|. Otherwise, setup a reply with
@@ -374,12 +405,13 @@
if (!has_pending_write_reply_) {
has_pending_write_reply_ = true;
writer_.RegisterOnNextWriteCallbacks(
- base::Closure(),
+ base::OnceClosure(),
base::Bind(
&PostWriteCallback, base::Callback<void(bool success)>(),
- base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
- AsWeakPtr()),
- base::SequencedTaskRunnerHandle::Get()));
+ base::Bind(
+ &JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
+ AsWeakPtr()),
+ base::SequencedTaskRunner::GetCurrentDefault()));
}
}
@@ -390,12 +422,13 @@
has_pending_write_reply_ = true;
writer_.RegisterOnNextWriteCallbacks(
- callbacks.first,
+ std::move(callbacks.first),
base::Bind(
- &PostWriteCallback, callbacks.second,
- base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
- AsWeakPtr()),
- base::SequencedTaskRunnerHandle::Get()));
+ &PostWriteCallback, std::move(callbacks.second),
+ base::Bind(
+ &JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
+ AsWeakPtr()),
+ base::SequencedTaskRunner::GetCurrentDefault()));
}
void JsonPrefStore::ClearMutableValues() {
@@ -412,8 +445,7 @@
DCHECK(read_result);
- std::unique_ptr<base::DictionaryValue> unfiltered_prefs(
- new base::DictionaryValue);
+ base::Value::Dict unfiltered_prefs;
read_error_ = read_result->error;
@@ -430,8 +462,8 @@
break;
case PREF_READ_ERROR_NONE:
DCHECK(read_result->value);
- unfiltered_prefs.reset(
- static_cast<base::DictionaryValue*>(read_result->value.release()));
+ DCHECK(read_result->value->is_dict());
+ unfiltered_prefs = std::move(*read_result->value).TakeDict();
break;
case PREF_READ_ERROR_NO_FILE:
// If the file just doesn't exist, maybe this is first run. In any case
@@ -468,31 +500,32 @@
CommitPendingWrite();
}
-bool JsonPrefStore::SerializeData(std::string* output) {
+absl::optional<std::string> JsonPrefStore::SerializeData() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
pending_lossy_write_ = false;
if (pref_filter_) {
OnWriteCallbackPair callbacks =
- pref_filter_->FilterSerializeData(prefs_.get());
+ pref_filter_->FilterSerializeData(prefs_);
if (!callbacks.first.is_null() || !callbacks.second.is_null())
RegisterOnNextWriteSynchronousCallbacks(callbacks);
}
- JSONStringValueSerializer serializer(output);
+ std::string output;
+ JSONStringValueSerializer serializer(&output);
// Not pretty-printing prefs shrinks pref file size by ~30%. To obtain
// readable prefs for debugging purposes, you can dump your prefs into any
// command-line or online JSON pretty printing tool.
serializer.set_pretty_print(false);
- bool success = serializer.Serialize(*prefs_);
+ bool success = serializer.Serialize(prefs_);
DCHECK(success);
- return success;
+ return output;
}
void JsonPrefStore::FinalizeFileRead(
bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
diff --git a/components/prefs/json_pref_store.h b/components/prefs/json_pref_store.h
index e29e3b5..566eefd 100644
--- a/components/prefs/json_pref_store.h
+++ b/components/prefs/json_pref_store.h
@@ -11,7 +11,7 @@
#include <set>
#include <string>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/files/important_file_writer.h"
@@ -20,7 +20,8 @@
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
-#include "base/task/post_task.h"
+#include "base/task/thread_pool.h"
+#include "base/values.h"
#include "components/prefs/persistent_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/prefs/prefs_export.h"
@@ -67,14 +68,14 @@
JsonPrefStore(const base::FilePath& pref_filename,
std::unique_ptr<PrefFilter> pref_filter = nullptr,
scoped_refptr<base::SequencedTaskRunner> file_task_runner =
- base::CreateSequencedTaskRunnerWithTraits(
+ base::ThreadPool::CreateSequencedTaskRunner(
{base::MayBlock(), base::TaskPriority::USER_VISIBLE,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN}));
// PrefStore overrides:
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -83,10 +84,10 @@
// PersistentPrefStore overrides:
bool GetMutableValue(const std::string& key, base::Value** result) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
@@ -125,6 +126,10 @@
~JsonPrefStore() override;
+ // Perform pre-serialization bookkeeping common to either serialization flow
+ // (main thread or background thread).
+ void PerformPreserializationTasks();
+
// If |write_success| is true, runs |on_next_successful_write_|.
// Otherwise, re-registers |on_next_successful_write_|.
void RunOrScheduleNextSuccessfulWriteCallback(bool write_success);
@@ -152,7 +157,7 @@
void OnFileRead(std::unique_ptr<ReadResult> read_result);
// ImportantFileWriter::DataSerializer overrides:
- bool SerializeData(std::string* output) override;
+ absl::optional<std::string> SerializeData() override;
// This method is called after the JSON file has been read and the result has
// potentially been intercepted and modified by |pref_filter_|.
@@ -162,7 +167,7 @@
// (typically because the |pref_filter_| has already altered the |prefs|) --
// this will be ignored if this store is read-only.
void FinalizeFileRead(bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write);
// Schedule a write with the file writer as long as |flags| doesn't contain
@@ -172,7 +177,7 @@
const base::FilePath path_;
const scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
- std::unique_ptr<base::DictionaryValue> prefs_;
+ base::Value::Dict prefs_;
bool read_only_;
diff --git a/components/prefs/json_pref_store_unittest.cc b/components/prefs/json_pref_store_unittest.cc
index de878aa..f2da53b 100644
--- a/components/prefs/json_pref_store_unittest.cc
+++ b/components/prefs/json_pref_store_unittest.cc
@@ -72,7 +72,7 @@
std::unique_ptr<base::DictionaryValue> pref_store_contents) override;
void FilterUpdate(const std::string& path) override {}
OnWriteCallbackPair FilterSerializeData(
- base::DictionaryValue* pref_store_contents) override {
+ base::Value::Dict& pref_store_contents) override {
return on_write_callback_pair_;
}
void OnStoreDeletionFromDisk() override {}
diff --git a/components/prefs/json_read_only_pref_store.cc b/components/prefs/json_read_only_pref_store.cc
index 9c50844..5a960ba 100644
--- a/components/prefs/json_read_only_pref_store.cc
+++ b/components/prefs/json_read_only_pref_store.cc
@@ -11,16 +11,15 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/logging.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
-#include "base/task_runner_util.h"
-#include "base/threading/sequenced_task_runner_handle.h"
#include "base/values.h"
#include "components/prefs/pref_filter.h"
@@ -78,8 +77,7 @@
// TODO(erikkay) if we keep this error checking for very long, we may
// want to differentiate between recent and long ago errors.
bool bad_existed = base::PathExists(bad);
- base::CopyFile(path, bad);
- base::DeleteFile(path, false);
+ base::Move(path, bad);
return bad_existed ? PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT
: PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE;
}
@@ -133,7 +131,6 @@
scoped_refptr<base::SequencedTaskRunner> file_task_runner)
: path_(pref_filename),
file_task_runner_(std::move(file_task_runner)),
- prefs_(new base::DictionaryValue()),
pref_filter_(std::move(pref_filter)),
initialized_(false),
filtering_in_progress_(false),
@@ -145,8 +142,8 @@
const base::Value** result) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::Value* tmp = nullptr;
- if (!prefs_->Get(key, &tmp))
+ const base::Value* tmp = prefs_.FindByDottedPath(key);
+ if (!tmp)
return false;
if (result)
@@ -154,9 +151,9 @@
return true;
}
-std::unique_ptr<base::DictionaryValue> JsonReadOnlyPrefStore::GetValues()
+base::Value::Dict JsonReadOnlyPrefStore::GetValues()
const {
- return prefs_->CreateDeepCopy();
+ return prefs_.Clone();
}
void JsonReadOnlyPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -173,8 +170,7 @@
bool JsonReadOnlyPrefStore::HasObservers() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
-
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool JsonReadOnlyPrefStore::IsInitializationComplete() const {
@@ -187,17 +183,23 @@
base::Value** result) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- return prefs_->Get(key, result);
+ base::Value* tmp = prefs_.FindByDottedPath(key);
+ if (!tmp)
+ return false;
+
+ if (result)
+ *result = tmp;
+ return true;
}
void JsonReadOnlyPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
NOTIMPLEMENTED();
}
void JsonReadOnlyPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
NOTIMPLEMENTED();
}
@@ -232,9 +234,9 @@
error_delegate_.reset(error_delegate);
// Weakly binds the read task so that it doesn't kick in during shutdown.
- base::PostTaskAndReplyWithResult(
- file_task_runner_.get(), FROM_HERE, base::Bind(&ReadPrefsFromDisk, path_),
- base::Bind(&JsonReadOnlyPrefStore::OnFileRead, AsWeakPtr()));
+ file_task_runner_->PostTaskAndReplyWithResult(
+ FROM_HERE, base::BindOnce(&ReadPrefsFromDisk, path_),
+ base::BindOnce(&JsonReadOnlyPrefStore::OnFileRead, AsWeakPtr()));
}
void JsonReadOnlyPrefStore::CommitPendingWrite(
@@ -267,8 +269,7 @@
DCHECK(read_result);
- std::unique_ptr<base::DictionaryValue> unfiltered_prefs(
- new base::DictionaryValue);
+ base::Value::Dict unfiltered_prefs;
read_error_ = read_result->error;
@@ -284,8 +285,8 @@
break;
case PREF_READ_ERROR_NONE:
DCHECK(read_result->value);
- unfiltered_prefs.reset(
- static_cast<base::DictionaryValue*>(read_result->value.release()));
+ DCHECK(read_result->value->is_dict());
+ unfiltered_prefs = std::move(*read_result->value).TakeDict();
break;
case PREF_READ_ERROR_NO_FILE:
@@ -306,10 +307,10 @@
if (pref_filter_) {
filtering_in_progress_ = true;
- const PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback(
- base::Bind(&JsonReadOnlyPrefStore::FinalizeFileRead, AsWeakPtr(),
- initialization_successful));
- pref_filter_->FilterOnLoad(post_filter_on_load_callback,
+ PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback(
+ base::BindOnce(&JsonReadOnlyPrefStore::FinalizeFileRead, AsWeakPtr(),
+ initialization_successful));
+ pref_filter_->FilterOnLoad(std::move(post_filter_on_load_callback),
std::move(unfiltered_prefs));
} else {
FinalizeFileRead(initialization_successful, std::move(unfiltered_prefs),
@@ -319,7 +320,7 @@
void JsonReadOnlyPrefStore::FinalizeFileRead(
bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
diff --git a/components/prefs/json_read_only_pref_store.h b/components/prefs/json_read_only_pref_store.h
index 4577c01..a2c2190 100644
--- a/components/prefs/json_read_only_pref_store.h
+++ b/components/prefs/json_read_only_pref_store.h
@@ -11,14 +11,15 @@
#include <set>
#include <string>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/sequence_checker.h"
-#include "base/task/post_task.h"
+#include "base/task/thread_pool.h"
+#include "base/values.h"
#include "components/prefs/persistent_pref_store.h"
#include "components/prefs/pref_filter.h"
#include "components/prefs/prefs_export.h"
@@ -45,14 +46,14 @@
const base::FilePath& pref_filename,
std::unique_ptr<PrefFilter> pref_filter = nullptr,
scoped_refptr<base::SequencedTaskRunner> file_task_runner =
- base::CreateSequencedTaskRunnerWithTraits(
- {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
- base::TaskShutdownBehavior::BLOCK_SHUTDOWN}));
+ base::ThreadPool::CreateSequencedTaskRunner(
+ {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
+ base::TaskShutdownBehavior::BLOCK_SHUTDOWN}));
// PrefStore overrides:
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -61,10 +62,10 @@
// PersistentPrefStore overrides:
bool GetMutableValue(const std::string& key, base::Value** result) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
@@ -104,13 +105,13 @@
// (typically because the |pref_filter_| has already altered the |prefs|) --
// this will be ignored if this store is read-only.
void FinalizeFileRead(bool initialization_successful,
- std::unique_ptr<base::DictionaryValue> prefs,
+ base::Value::Dict prefs,
bool schedule_write);
const base::FilePath path_;
const scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
- std::unique_ptr<base::DictionaryValue> prefs_;
+ base::Value::Dict prefs_;
std::unique_ptr<PrefFilter> pref_filter_;
base::ObserverList<PrefStore::Observer, true>::Unchecked observers_;
diff --git a/components/prefs/mock_pref_change_callback.h b/components/prefs/mock_pref_change_callback.h
index 9c0aeec..1581237 100644
--- a/components/prefs/mock_pref_change_callback.h
+++ b/components/prefs/mock_pref_change_callback.h
@@ -28,7 +28,7 @@
return value == NULL;
if (!value)
return actual_value == NULL;
- return value->Equals(actual_value);
+ return value == actual_value;
}
// A mock for testing preference notifications and easy setup of expectations.
diff --git a/components/prefs/overlay_user_pref_store.cc b/components/prefs/overlay_user_pref_store.cc
index 0baa6c4..ec6c048 100644
--- a/components/prefs/overlay_user_pref_store.cc
+++ b/components/prefs/overlay_user_pref_store.cc
@@ -63,7 +63,7 @@
}
bool OverlayUserPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool OverlayUserPrefStore::IsInitializationComplete() const {
@@ -83,7 +83,7 @@
return persistent_user_pref_store_->GetValue(key, result);
}
-std::unique_ptr<base::DictionaryValue> OverlayUserPrefStore::GetValues() const {
+base::Value::Dict OverlayUserPrefStore::GetValues() const {
auto values = ephemeral_user_pref_store_->GetValues();
auto persistent_values = persistent_user_pref_store_->GetValues();
@@ -92,10 +92,9 @@
// overwritten by the content of |persistent_user_pref_store_| (the persistent
// store).
for (const auto& key : persistent_names_set_) {
- std::unique_ptr<base::Value> out_value;
- persistent_values->Remove(key, &out_value);
+ absl::optional<base::Value> out_value = persistent_values.Extract(key);
if (out_value) {
- values->Set(key, std::move(out_value));
+ values.Set(key, std::move(*out_value));
}
}
return values;
@@ -116,14 +115,14 @@
return false;
ephemeral_user_pref_store_->SetValue(
- key, persistent_value->CreateDeepCopy(),
+ key, persistent_value->Clone(),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
ephemeral_user_pref_store_->GetMutableValue(key, result);
return true;
}
void OverlayUserPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
if (ShallBeStoredInPersistent(key)) {
persistent_user_pref_store_->SetValue(key, std::move(value), flags);
@@ -138,7 +137,7 @@
}
void OverlayUserPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
if (ShallBeStoredInPersistent(key)) {
persistent_user_pref_store_->SetValueSilently(key, std::move(value), flags);
diff --git a/components/prefs/overlay_user_pref_store.h b/components/prefs/overlay_user_pref_store.h
index 9b7c95a..35eb9c5 100644
--- a/components/prefs/overlay_user_pref_store.h
+++ b/components/prefs/overlay_user_pref_store.h
@@ -42,15 +42,15 @@
bool IsInitializationComplete() const override;
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
// Methods of PersistentPrefStore.
bool GetMutableValue(const std::string& key, base::Value** result) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
diff --git a/components/prefs/persistent_pref_store.cc b/components/prefs/persistent_pref_store.cc
index 9086c1e..656f9ef 100644
--- a/components/prefs/persistent_pref_store.cc
+++ b/components/prefs/persistent_pref_store.cc
@@ -6,7 +6,7 @@
#include <utility>
-#include "base/threading/sequenced_task_runner_handle.h"
+#include "base/task/sequenced_task_runner.h"
void PersistentPrefStore::CommitPendingWrite(
base::OnceClosure reply_callback,
@@ -21,7 +21,7 @@
std::move(synchronous_done_callback).Run();
if (reply_callback) {
- base::SequencedTaskRunnerHandle::Get()->PostTask(FROM_HERE,
+ base::SequencedTaskRunner::GetCurrentDefault()->PostTask(FROM_HERE,
std::move(reply_callback));
}
}
diff --git a/components/prefs/pref_filter.h b/components/prefs/pref_filter.h
index 3d52136..8e7384b 100644
--- a/components/prefs/pref_filter.h
+++ b/components/prefs/pref_filter.h
@@ -9,13 +9,10 @@
#include <string>
#include <utility>
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
+#include "base/values.h"
#include "components/prefs/prefs_export.h"
-namespace base {
-class DictionaryValue;
-} // namespace base
-
// Filters preferences as they are loaded from disk or updated at runtime.
// Currently supported only by JsonPrefStore.
class COMPONENTS_PREFS_EXPORT PrefFilter {
@@ -29,8 +26,7 @@
// builder. |schedule_write| indicates whether a write should be immediately
// scheduled (typically because the |prefs| were pre-modified).
using PostFilterOnLoadCallback =
- base::Callback<void(std::unique_ptr<base::DictionaryValue> prefs,
- bool schedule_write)>;
+ base::OnceCallback<void(base::Value::Dict prefs, bool schedule_write)>;
virtual ~PrefFilter() {}
@@ -43,7 +39,7 @@
// to external users (see SegregatedPrefStore::ReadPrefs() for an example).
virtual void FilterOnLoad(
const PostFilterOnLoadCallback& post_filter_on_load_callback,
- std::unique_ptr<base::DictionaryValue> pref_store_contents) = 0;
+ base::Value::Dict pref_store_contents) = 0;
// Receives notification when a pref store value is changed, before Observers
// are notified.
@@ -57,7 +53,7 @@
// invoked synchronously after the next write (from the I/O TaskRunner so they
// must not be bound to thread-unsafe member state).
virtual OnWriteCallbackPair FilterSerializeData(
- base::DictionaryValue* pref_store_contents) = 0;
+ base::Value::Dict& pref_store_contents) = 0;
// Cleans preference data that may have been saved outside of the store.
virtual void OnStoreDeletionFromDisk() = 0;
diff --git a/components/prefs/pref_member.cc b/components/prefs/pref_member.cc
index a8fa12c..08bb7bf 100644
--- a/components/prefs/pref_member.cc
+++ b/components/prefs/pref_member.cc
@@ -6,11 +6,10 @@
#include <utility>
+#include "base/json/values_util.h"
#include "base/callback.h"
-#include "base/callback_helpers.h"
+#include "base/functional/callback_helpers.h"
#include "base/location.h"
-#include "base/threading/sequenced_task_runner_handle.h"
-#include "base/value_conversions.h"
#include "components/prefs/pref_service.h"
using base::SequencedTaskRunner;
@@ -71,10 +70,9 @@
DCHECK(pref);
if (!internal())
CreateInternal();
- internal()->UpdateValue(pref->GetValue()->DeepCopy(),
- pref->IsManaged(),
- pref->IsUserModifiable(),
- callback);
+ internal()->UpdateValue(
+ base::Value::ToUniquePtrValue(pref->GetValue()->Clone()).release(),
+ pref->IsManaged(), pref->IsUserModifiable(), callback);
}
void PrefMemberBase::VerifyPref() const {
@@ -89,7 +87,7 @@
}
PrefMemberBase::Internal::Internal()
- : owning_task_runner_(base::SequencedTaskRunnerHandle::Get()),
+ : owning_task_runner_(base::SequencedTaskRunner::GetCurrentDefault()),
is_managed_(false),
is_user_modifiable_(false) {}
PrefMemberBase::Internal::~Internal() { }
@@ -129,15 +127,15 @@
std::vector<std::string>* string_vector) {
if (!value.is_list())
return false;
- const base::ListValue* list = static_cast<const base::ListValue*>(&value);
+ const base::Value::List* list = value.GetIfList();
std::vector<std::string> local_vector;
for (auto it = list->begin(); it != list->end(); ++it) {
- std::string string_value;
- if (!it->GetAsString(&string_value))
+ const std::string* string_value = it->GetIfString();
+ if (string_value == nullptr) {
return false;
-
- local_vector.push_back(string_value);
+ }
+ local_vector.push_back(*string_value);
}
string_vector->swap(local_vector);
@@ -154,7 +152,10 @@
template <>
bool PrefMember<bool>::Internal::UpdateValueInternal(
const base::Value& value) const {
- return value.GetAsBoolean(&value_);
+ absl::optional<bool> temp = value.GetIfBool();
+ if (value.is_bool())
+ value_ = value.GetBool();
+ return value.is_bool();;
}
template <>
@@ -165,7 +166,10 @@
template <>
bool PrefMember<int>::Internal::UpdateValueInternal(
const base::Value& value) const {
- return value.GetAsInteger(&value_);
+ absl::optional<int> temp = value.GetIfInt();
+ if (value.is_int())
+ value_ = value.GetInt();
+ return value.is_int();
}
template <>
@@ -174,9 +178,11 @@
}
template <>
-bool PrefMember<double>::Internal::UpdateValueInternal(const base::Value& value)
- const {
- return value.GetAsDouble(&value_);
+bool PrefMember<double>::Internal::UpdateValueInternal(
+ const base::Value& value) const {
+ if (value.is_double() || value.is_int())
+ value_ = value.GetDouble();
+ return value.is_double() || value.is_int();
}
template <>
@@ -186,9 +192,10 @@
template <>
bool PrefMember<std::string>::Internal::UpdateValueInternal(
- const base::Value& value)
- const {
- return value.GetAsString(&value_);
+ const base::Value& value) const {
+ if (value.is_string())
+ value_ = value.GetString();
+ return value.is_string();
}
template <>
@@ -198,17 +205,22 @@
template <>
bool PrefMember<base::FilePath>::Internal::UpdateValueInternal(
- const base::Value& value)
- const {
- return base::GetValueAsFilePath(value, &value_);
+ const base::Value& value) const {
+ absl::optional<base::FilePath> path = base::ValueToFilePath(value);
+ if (!path)
+ return false;
+ value_ = *path;
+ return true;
}
template <>
void PrefMember<std::vector<std::string> >::UpdatePref(
const std::vector<std::string>& value) {
- base::ListValue list_value;
- list_value.AppendStrings(value);
- prefs()->Set(pref_name(), list_value);
+ base::Value::List list_value;
+ for (const std::string& val : value)
+ list_value.Append(val);
+
+ prefs()->SetList(pref_name(), std::move(list_value));
}
template <>
diff --git a/components/prefs/pref_member.h b/components/prefs/pref_member.h
index f2166e6..4d9dc97 100644
--- a/components/prefs/pref_member.h
+++ b/components/prefs/pref_member.h
@@ -28,12 +28,13 @@
#include <vector>
#include "base/bind.h"
-#include "base/callback_forward.h"
+#include "base/functional/callback_forward.h"
#include "base/files/file_path.h"
+#include "base/callback.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "base/values.h"
#include "components/prefs/pref_observer.h"
#include "components/prefs/prefs_export.h"
diff --git a/components/prefs/pref_registry_simple.cc b/components/prefs/pref_registry_simple.cc
index bab05dd..f4bbc47 100644
--- a/components/prefs/pref_registry_simple.cc
+++ b/components/prefs/pref_registry_simple.cc
@@ -57,7 +57,7 @@
void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
uint32_t flags) {
- RegisterPreference(path, base::Value(base::Value::Type::DICTIONARY), flags);
+ RegisterPreference(path, base::Value(base::Value::Type::DICT), flags);
}
void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
diff --git a/components/prefs/pref_service.cc b/components/prefs/pref_service.cc
index f9a5088..9f0da31 100644
--- a/components/prefs/pref_service.cc
+++ b/components/prefs/pref_service.cc
@@ -8,6 +8,7 @@
#include <map>
#include <utility>
+#include "base/optional.h"
#include "base/bind.h"
#include "base/debug/alias.h"
#include "base/debug/dump_without_crashing.h"
@@ -16,13 +17,12 @@
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
-#include "base/single_thread_task_runner.h"
+#include "base/task/single_thread_task_runner.h"
#include "base/stl_util.h"
+#include "base/json/values_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h"
-#include "base/util/values/values_util.h"
-#include "base/value_conversions.h"
#include "build/build_config.h"
#include "components/prefs/default_pref_store.h"
#include "components/prefs/pref_notifier_impl.h"
@@ -69,16 +69,17 @@
if (!pref_store)
return;
auto values = pref_store->GetValues();
- for (const auto& item : values->DictItems()) {
+ for (base::Value::Dict::iterator it = values.begin(); it != values.end();
+ ++it) {
// If the key already presents, skip it as a store with higher precedence
// already sets the entry.
- if (pref_changed_map->find(item.first) != pref_changed_map->end())
+ if (pref_changed_map->find(it->first) != pref_changed_map->end())
continue;
const PrefService::Preference* pref =
- pref_service->FindPreference(item.first);
+ pref_service->FindPreference(it->first);
if (!pref)
continue;
- pref_changed_map->emplace(item.first, *(pref->GetValue()) != item.second);
+ pref_changed_map->emplace(it->first, *(pref->GetValue()) != it->second);
}
}
@@ -164,9 +165,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsBoolean(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetBool();
}
int PrefService::GetInteger(const std::string& path) const {
@@ -177,9 +176,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsInteger(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetInt();
}
double PrefService::GetDouble(const std::string& path) const {
@@ -190,9 +187,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsDouble(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetDouble();
}
std::string PrefService::GetString(const std::string& path) const {
@@ -203,9 +198,7 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return result;
- bool rv = value->GetAsString(&result);
- DCHECK(rv);
- return result;
+ return (*value).GetString();
}
base::FilePath PrefService::GetFilePath(const std::string& path) const {
@@ -216,9 +209,9 @@
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return base::FilePath(result);
- bool rv = base::GetValueAsFilePath(*value, &result);
+ absl::optional<base::FilePath> rv = base::ValueToFilePath(value);
DCHECK(rv);
- return result;
+ return *rv;
}
bool PrefService::HasPrefPath(const std::string& path) const {
@@ -234,18 +227,18 @@
callback.Run(it.first, *GetPreferenceValue(it.first));
}
-std::unique_ptr<base::DictionaryValue> PrefService::GetPreferenceValues(
+base::Value::Dict PrefService::GetPreferenceValues(
IncludeDefaults include_defaults) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- std::unique_ptr<base::DictionaryValue> out(new base::DictionaryValue);
+ base::Value::Dict out;
for (const auto& it : *pref_registry_) {
if (include_defaults == INCLUDE_DEFAULTS) {
- out->Set(it.first, GetPreferenceValue(it.first)->CreateDeepCopy());
+ out.Set(it.first, GetPreferenceValue(it.first)->Clone());
} else {
const Preference* pref = FindPreference(it.first);
if (pref->IsDefaultValue())
continue;
- out->Set(it.first, pref->GetValue()->CreateDeepCopy());
+ out.Set(it.first, pref->GetValue()->Clone());
}
}
return out;
@@ -320,18 +313,18 @@
return value;
}
-const base::DictionaryValue* PrefService::GetDictionary(
+const base::Value::Dict* PrefService::GetDictionary(
const std::string& path) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const base::Value* value = GetPreferenceValueChecked(path);
if (!value)
return nullptr;
- if (value->type() != base::Value::Type::DICTIONARY) {
+ if (value->type() != base::Value::Type::DICT) {
NOTREACHED();
return nullptr;
}
- return static_cast<const base::DictionaryValue*>(value);
+ return value->GetIfDict();
}
const base::Value* PrefService::GetUserPrefValue(
@@ -374,7 +367,7 @@
return value;
}
-const base::ListValue* PrefService::GetList(const std::string& path) const {
+const base::Value::List* PrefService::GetList(const std::string& path) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const base::Value* value = GetPreferenceValueChecked(path);
@@ -384,7 +377,7 @@
NOTREACHED();
return nullptr;
}
- return static_cast<const base::ListValue*>(value);
+ return value->GetIfList();
}
void PrefService::AddPrefObserver(const std::string& path, PrefObserver* obs) {
@@ -471,46 +464,52 @@
}
void PrefService::Set(const std::string& path, const base::Value& value) {
- SetUserPrefValue(path, value.CreateDeepCopy());
+ SetUserPrefValue(path, value.Clone());
+}
+
+void PrefService::SetList(const std::string& path, const base::Value::List& value) {
+ SetUserPrefValue(path, base::Value(value.Clone()));
+}
+
+void PrefService::SetDict(const std::string& path, const base::Value::Dict& value) {
+ SetUserPrefValue(path, base::Value(value.Clone()));
}
void PrefService::SetBoolean(const std::string& path, bool value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetInteger(const std::string& path, int value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetDouble(const std::string& path, double value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetString(const std::string& path, const std::string& value) {
- SetUserPrefValue(path, std::make_unique<base::Value>(value));
+ SetUserPrefValue(path, base::Value(value));
}
void PrefService::SetFilePath(const std::string& path,
const base::FilePath& value) {
- SetUserPrefValue(
- path, base::Value::ToUniquePtrValue(base::CreateFilePathValue(value)));
+ SetUserPrefValue(path, base::FilePathToValue(value));
}
void PrefService::SetInt64(const std::string& path, int64_t value) {
- SetUserPrefValue(path,
- base::Value::ToUniquePtrValue(util::Int64ToValue(value)));
+ SetUserPrefValue(path, base::Int64ToValue(value));
}
int64_t PrefService::GetInt64(const std::string& path) const {
const base::Value* value = GetPreferenceValueChecked(path);
- base::Optional<int64_t> integer = util::ValueToInt64(value);
+ absl::optional<int64_t> integer = base::ValueToInt64(value);
DCHECK(integer);
return integer.value_or(0);
}
void PrefService::SetUint64(const std::string& path, uint64_t value) {
SetUserPrefValue(path,
- std::make_unique<base::Value>(base::NumberToString(value)));
+ base::Value(base::NumberToString(value)));
}
uint64_t PrefService::GetUint64(const std::string& path) const {
@@ -520,8 +519,8 @@
if (!value)
return 0;
std::string result("0");
- bool rv = value->GetAsString(&result);
- DCHECK(rv);
+ if (!(*value).is_string())
+ return 0;
uint64_t val;
base::StringToUint64(result, &val);
@@ -530,31 +529,31 @@
void PrefService::SetTime(const std::string& path, base::Time value) {
SetUserPrefValue(path,
- base::Value::ToUniquePtrValue(util::TimeToValue(value)));
+ base::Value(base::TimeToValue(value)));
}
base::Time PrefService::GetTime(const std::string& path) const {
const base::Value* value = GetPreferenceValueChecked(path);
- base::Optional<base::Time> time = util::ValueToTime(value);
+ absl::optional<base::Time> time = base::ValueToTime(value);
DCHECK(time);
return time.value_or(base::Time());
}
void PrefService::SetTimeDelta(const std::string& path, base::TimeDelta value) {
SetUserPrefValue(
- path, base::Value::ToUniquePtrValue(util::TimeDeltaToValue(value)));
+ path, base::Value(base::TimeDeltaToValue(value)));
}
base::TimeDelta PrefService::GetTimeDelta(const std::string& path) const {
const base::Value* value = GetPreferenceValueChecked(path);
- base::Optional<base::TimeDelta> time_delta = util::ValueToTimeDelta(value);
+ absl::optional<base::TimeDelta> time_delta = base::ValueToTimeDelta(value);
DCHECK(time_delta);
return time_delta.value_or(base::TimeDelta());
}
base::Value* PrefService::GetMutableUserPref(const std::string& path,
base::Value::Type type) {
- CHECK(type == base::Value::Type::DICTIONARY ||
+ CHECK(type == base::Value::Type::DICT ||
type == base::Value::Type::LIST);
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
@@ -590,7 +589,7 @@
DEBUG_ALIAS_FOR_CSTR(path_copy, path.c_str(), 1024);
base::debug::DumpWithoutCrashing();
}
- user_pref_store_->SetValueSilently(path, default_value->CreateDeepCopy(),
+ user_pref_store_->SetValueSilently(path, default_value->Clone(),
GetWriteFlags(pref));
user_pref_store_->GetMutableValue(path, &value);
return value;
@@ -610,7 +609,7 @@
}
void PrefService::SetUserPrefValue(const std::string& path,
- std::unique_ptr<base::Value> new_value) {
+ base::Value new_value) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
const Preference* pref = FindPreference(path);
@@ -618,10 +617,10 @@
NOTREACHED() << "Trying to write an unregistered pref: " << path;
return;
}
- if (pref->GetType() != new_value->type()) {
+ if (pref->GetType() != new_value.type()) {
NOTREACHED() << "Trying to set pref " << path << " of type "
<< pref->GetType() << " to value of type "
- << new_value->type();
+ << new_value.type();
return;
}
diff --git a/components/prefs/pref_service.h b/components/prefs/pref_service.h
index 9580b48..7019c7e 100644
--- a/components/prefs/pref_service.h
+++ b/components/prefs/pref_service.h
@@ -222,8 +222,8 @@
// Note that |path| must point to a registered preference. In that case, these
// functions will never return NULL.
const base::Value* Get(const std::string& path) const;
- const base::DictionaryValue* GetDictionary(const std::string& path) const;
- const base::ListValue* GetList(const std::string& path) const;
+ const base::Value::Dict* GetDictionary(const std::string& path) const;
+ const base::Value::List* GetList(const std::string& path) const;
// Removes a user pref and restores the pref to its default value.
void ClearPref(const std::string& path);
@@ -234,6 +234,8 @@
// Set(), but to modify the value of a dictionary or list use either
// ListPrefUpdate or DictionaryPrefUpdate from scoped_user_pref_update.h.
void Set(const std::string& path, const base::Value& value);
+ void SetList(const std::string& path, const base::Value::List& value);
+ void SetDict(const std::string& path, const base::Value::Dict& value);
void SetBoolean(const std::string& path, bool value);
void SetInteger(const std::string& path, int value);
void SetDouble(const std::string& path, double value);
@@ -295,7 +297,7 @@
// If INCLUDE_DEFAULTS is requested, preferences set to their default values
// will be included. Otherwise, these will be omitted from the returned
// dictionary.
- std::unique_ptr<base::DictionaryValue> GetPreferenceValues(
+ base::Value::Dict GetPreferenceValues(
IncludeDefaults include_defaults) const;
bool ReadOnly() const;
@@ -429,7 +431,7 @@
// Sets the value for this pref path in the user pref store and informs the
// PrefNotifier of the change.
void SetUserPrefValue(const std::string& path,
- std::unique_ptr<base::Value> new_value);
+ base::Value new_value);
// Load preferences from storage, attempting to diagnose and handle errors.
// This should only be called from the constructor.
diff --git a/components/prefs/pref_service_factory.cc b/components/prefs/pref_service_factory.cc
index cc8e52d..f1c5436 100644
--- a/components/prefs/pref_service_factory.cc
+++ b/components/prefs/pref_service_factory.cc
@@ -8,7 +8,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "base/sequenced_task_runner.h"
+#include "base/task/sequenced_task_runner.h"
#include "components/prefs/default_pref_store.h"
#include "components/prefs/json_pref_store.h"
#include "components/prefs/pref_filter.h"
diff --git a/components/prefs/pref_store.h b/components/prefs/pref_store.h
index 5f5f092..e7e07fb 100644
--- a/components/prefs/pref_store.h
+++ b/components/prefs/pref_store.h
@@ -10,12 +10,9 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
+#include "base/values.h"
#include "components/prefs/prefs_export.h"
-namespace base {
-class DictionaryValue;
-class Value;
-}
// This is an abstract interface for reading and writing from/to a persistent
// preference store, used by PrefService. An implementation using a JSON file
@@ -55,7 +52,7 @@
const base::Value** result) const = 0;
// Get all the values. Never returns a null pointer.
- virtual std::unique_ptr<base::DictionaryValue> GetValues() const = 0;
+ virtual base::Value::Dict GetValues() const = 0;
protected:
friend class base::RefCounted<PrefStore>;
diff --git a/components/prefs/pref_value_map.cc b/components/prefs/pref_value_map.cc
index b932eef..eb13555 100644
--- a/components/prefs/pref_value_map.cc
+++ b/components/prefs/pref_value_map.cc
@@ -82,7 +82,11 @@
bool PrefValueMap::GetBoolean(const std::string& key,
bool* value) const {
const base::Value* stored_value = nullptr;
- return GetValue(key, &stored_value) && stored_value->GetAsBoolean(value);
+ if (GetValue(key, &stored_value) && stored_value->is_bool()) {
+ *value = stored_value->GetBool();
+ return true;
+ }
+ return false;
}
void PrefValueMap::SetBoolean(const std::string& key, bool value) {
@@ -92,7 +96,11 @@
bool PrefValueMap::GetString(const std::string& key,
std::string* value) const {
const base::Value* stored_value = nullptr;
- return GetValue(key, &stored_value) && stored_value->GetAsString(value);
+ if (GetValue(key, &stored_value) && stored_value->is_string()) {
+ *value = stored_value->GetString();
+ return true;
+ }
+ return false;
}
void PrefValueMap::SetString(const std::string& key,
@@ -102,7 +110,11 @@
bool PrefValueMap::GetInteger(const std::string& key, int* value) const {
const base::Value* stored_value = nullptr;
- return GetValue(key, &stored_value) && stored_value->GetAsInteger(value);
+ if (GetValue(key, &stored_value) && stored_value->is_int()) {
+ *value = stored_value->GetInt();
+ return true;
+ }
+ return false;
}
void PrefValueMap::SetInteger(const std::string& key, const int value) {
@@ -132,7 +144,7 @@
while (this_pref != this_prefs.end() && other_pref != other_prefs.end()) {
const int diff = this_pref->first.compare(other_pref->first);
if (diff == 0) {
- if (!this_pref->second->Equals(other_pref->second))
+ if (*this_pref->second != *other_pref->second)
differing_keys->push_back(this_pref->first);
++this_pref;
++other_pref;
@@ -152,10 +164,10 @@
differing_keys->push_back(other_pref->first);
}
-std::unique_ptr<base::DictionaryValue> PrefValueMap::AsDictionaryValue() const {
- auto dictionary = std::make_unique<base::DictionaryValue>();
+base::Value::Dict PrefValueMap::AsDict() const {
+ base::Value::Dict dictionary;
for (const auto& value : prefs_)
- dictionary->Set(value.first, value.second.CreateDeepCopy());
+ dictionary.SetByDottedPath(value.first, value.second.Clone());
return dictionary;
}
diff --git a/components/prefs/pref_value_map.h b/components/prefs/pref_value_map.h
index 6a9b4b6..92f9386 100644
--- a/components/prefs/pref_value_map.h
+++ b/components/prefs/pref_value_map.h
@@ -11,13 +11,9 @@
#include <vector>
#include "base/macros.h"
+#include "base/values.h"
#include "components/prefs/prefs_export.h"
-namespace base {
-class DictionaryValue;
-class Value;
-}
-
// A generic string to value map used by the PrefStore implementations.
class COMPONENTS_PREFS_EXPORT PrefValueMap {
public:
@@ -83,8 +79,8 @@
void GetDifferingKeys(const PrefValueMap* other,
std::vector<std::string>* differing_keys) const;
- // Copies the map into a dictionary value.
- std::unique_ptr<base::DictionaryValue> AsDictionaryValue() const;
+ // Copies the map into a Value::Dict.
+ base::Value::Dict AsDict() const;
private:
Map prefs_;
diff --git a/components/prefs/scoped_user_pref_update.cc b/components/prefs/scoped_user_pref_update.cc
index 27d56af..3e36c63 100644
--- a/components/prefs/scoped_user_pref_update.cc
+++ b/components/prefs/scoped_user_pref_update.cc
@@ -42,3 +42,11 @@
}
} // namespace subtle
+
+base::Value::Dict& ScopedDictPrefUpdate::Get() {
+ return GetValueOfType(base::Value::Type::DICT)->GetDict();
+}
+
+base::Value::List& ScopedListPrefUpdate::Get() {
+ return GetValueOfType(base::Value::Type::LIST)->GetList();
+}
diff --git a/components/prefs/scoped_user_pref_update.h b/components/prefs/scoped_user_pref_update.h
index 7de6bfb..8c283f4 100644
--- a/components/prefs/scoped_user_pref_update.h
+++ b/components/prefs/scoped_user_pref_update.h
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -10,7 +10,7 @@
#include <string>
-#include "base/macros.h"
+#include "base/memory/raw_ptr.h"
#include "base/sequence_checker.h"
#include "base/values.h"
#include "components/prefs/pref_service.h"
@@ -18,11 +18,6 @@
class PrefService;
-namespace base {
-class DictionaryValue;
-class ListValue;
-}
-
namespace subtle {
// Base class for ScopedUserPrefUpdateTemplate that contains the parts
@@ -32,6 +27,10 @@
// and getting access to PrefService::GetMutableUserPref and
// PrefService::ReportUserPrefChanged.
class COMPONENTS_PREFS_EXPORT ScopedUserPrefUpdateBase {
+ public:
+ ScopedUserPrefUpdateBase(const ScopedUserPrefUpdateBase&) = delete;
+ ScopedUserPrefUpdateBase& operator=(const ScopedUserPrefUpdateBase&) = delete;
+
protected:
ScopedUserPrefUpdateBase(PrefService* service, const std::string& path);
@@ -47,64 +46,85 @@
void Notify();
// Weak pointer.
- PrefService* service_;
+ raw_ptr<PrefService> service_;
// Path of the preference being updated.
std::string path_;
// Cache of value from user pref store (set between Get() and Notify() calls).
- base::Value* value_;
+ raw_ptr<base::Value> value_;
SEQUENCE_CHECKER(sequence_checker_);
-
- DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdateBase);
};
} // namespace subtle
-// Class to support modifications to DictionaryValues and ListValues while
-// guaranteeing that PrefObservers are notified of changed values.
+// Class to support modifications to base::Value::Dicts while guaranteeing
+// that PrefObservers are notified of changed values.
//
// This class may only be used on the UI thread as it requires access to the
// PrefService.
-template <typename T, base::Value::Type type_enum_value>
-class ScopedUserPrefUpdate : public subtle::ScopedUserPrefUpdateBase {
+class COMPONENTS_PREFS_EXPORT ScopedDictPrefUpdate
+ : public subtle::ScopedUserPrefUpdateBase {
public:
- ScopedUserPrefUpdate(PrefService* service, const std::string& path)
+ // The underlying dictionary must not be removed from `service` during
+ // the lifetime of the created ScopedDictPrefUpdate.
+ ScopedDictPrefUpdate(PrefService* service, const std::string& path)
: ScopedUserPrefUpdateBase(service, path) {}
- // Triggers an update notification if Get() was called.
- virtual ~ScopedUserPrefUpdate() {}
+ ScopedDictPrefUpdate(const ScopedDictPrefUpdate&) = delete;
+ ScopedDictPrefUpdate& operator=(const ScopedDictPrefUpdate&) = delete;
- // Returns a mutable |T| instance that
+ // Triggers an update notification if Get() was called.
+ virtual ~ScopedDictPrefUpdate() = default;
+
+ // Returns a mutable `base::Value::Dict` instance that
// - is already in the user pref store, or
// - is (silently) created and written to the user pref store if none existed
// before.
//
- // Calling Get() implies that an update notification is necessary at
- // destruction time.
+ // Calling Get() will result in an update notification automatically
+ // being triggered at destruction time.
//
// The ownership of the return value remains with the user pref store.
- // Virtual so it can be overriden in subclasses that transform the value
- // before returning it (for example to return a subelement of a dictionary).
- virtual T* Get() {
- return static_cast<T*>(GetValueOfType(type_enum_value));
- }
+ base::Value::Dict& Get();
- T& operator*() {
- return *Get();
- }
+ base::Value::Dict& operator*() { return Get(); }
- T* operator->() {
- return Get();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ScopedUserPrefUpdate);
+ base::Value::Dict* operator->() { return &Get(); }
};
-typedef ScopedUserPrefUpdate<base::DictionaryValue,
- base::Value::Type::DICTIONARY>
- DictionaryPrefUpdate;
-typedef ScopedUserPrefUpdate<base::ListValue, base::Value::Type::LIST>
- ListPrefUpdate;
+// Class to support modifications to base::Value::Lists while guaranteeing
+// that PrefObservers are notified of changed values.
+//
+// This class may only be used on the UI thread as it requires access to the
+// PrefService.
+class COMPONENTS_PREFS_EXPORT ScopedListPrefUpdate
+ : public subtle::ScopedUserPrefUpdateBase {
+ public:
+ // The underlying list must not be removed from `service` during
+ // the lifetime of the created ScopedListPrefUpdate.
+ ScopedListPrefUpdate(PrefService* service, const std::string& path)
+ : ScopedUserPrefUpdateBase(service, path) {}
+
+ ScopedListPrefUpdate(const ScopedListPrefUpdate&) = delete;
+ ScopedListPrefUpdate& operator=(const ScopedListPrefUpdate&) = delete;
+
+ // Triggers an update notification if Get() was called.
+ virtual ~ScopedListPrefUpdate() = default;
+
+ // Returns a mutable `base::Value::List` instance that
+ // - is already in the user pref store, or
+ // - is (silently) created and written to the user pref store if none existed
+ // before.
+ //
+ // Calling Get() will result in an update notification automatically
+ // being triggered at destruction time.
+ //
+ // The ownership of the return value remains with the user pref store.
+ base::Value::List& Get();
+
+ base::Value::List& operator*() { return Get(); }
+
+ base::Value::List* operator->() { return &Get(); }
+};
#endif // COMPONENTS_PREFS_SCOPED_USER_PREF_UPDATE_H_
diff --git a/components/prefs/testing_pref_service.h b/components/prefs/testing_pref_service.h
index f10e0cb..f0b05fa 100644
--- a/components/prefs/testing_pref_service.h
+++ b/components/prefs/testing_pref_service.h
@@ -220,7 +220,7 @@
SetPref(TestingPrefStore* pref_store,
const std::string& path,
std::unique_ptr<base::Value> value) {
- pref_store->SetValue(path, std::move(value),
+ pref_store->SetValue(path, base::Value(std::move(*value)),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
diff --git a/components/prefs/testing_pref_store.cc b/components/prefs/testing_pref_store.cc
index 4380407..a5da9b7 100644
--- a/components/prefs/testing_pref_store.cc
+++ b/components/prefs/testing_pref_store.cc
@@ -8,7 +8,6 @@
#include <utility>
#include "base/json/json_writer.h"
-#include "base/threading/sequenced_task_runner_handle.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -26,8 +25,8 @@
return prefs_.GetValue(key, value);
}
-std::unique_ptr<base::DictionaryValue> TestingPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict TestingPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
bool TestingPrefStore::GetMutableValue(const std::string& key,
@@ -44,7 +43,7 @@
}
bool TestingPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
bool TestingPrefStore::IsInitializationComplete() const {
@@ -52,21 +51,19 @@
}
void TestingPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)))) {
+ if (prefs_.SetValue(key, base::Value(std::move(value)))) {
committed_ = false;
NotifyPrefValueChanged(key);
}
}
void TestingPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- CheckPrefIsSerializable(key, *value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value))))
+ CheckPrefIsSerializable(key, value);
+ if (prefs_.SetValue(key, base::Value(std::move(value))))
committed_ = false;
}
@@ -139,15 +136,15 @@
void TestingPrefStore::SetString(const std::string& key,
const std::string& value) {
- SetValue(key, std::make_unique<base::Value>(value), DEFAULT_PREF_WRITE_FLAGS);
+ SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
void TestingPrefStore::SetInteger(const std::string& key, int value) {
- SetValue(key, std::make_unique<base::Value>(value), DEFAULT_PREF_WRITE_FLAGS);
+ SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
void TestingPrefStore::SetBoolean(const std::string& key, bool value) {
- SetValue(key, std::make_unique<base::Value>(value), DEFAULT_PREF_WRITE_FLAGS);
+ SetValue(key, base::Value(value), DEFAULT_PREF_WRITE_FLAGS);
}
bool TestingPrefStore::GetString(const std::string& key,
@@ -156,7 +153,11 @@
if (!prefs_.GetValue(key, &stored_value) || !stored_value)
return false;
- return stored_value->GetAsString(value);
+ if (value && stored_value->is_string()) {
+ *value = stored_value->GetString();
+ return true;
+ }
+ return stored_value->is_string();
}
bool TestingPrefStore::GetInteger(const std::string& key, int* value) const {
@@ -164,7 +165,11 @@
if (!prefs_.GetValue(key, &stored_value) || !stored_value)
return false;
- return stored_value->GetAsInteger(value);
+ if (value && stored_value->is_int()) {
+ *value = stored_value->GetInt();
+ return true;
+ }
+ return stored_value->is_int();
}
bool TestingPrefStore::GetBoolean(const std::string& key, bool* value) const {
@@ -172,7 +177,11 @@
if (!prefs_.GetValue(key, &stored_value) || !stored_value)
return false;
- return stored_value->GetAsBoolean(value);
+ if (value && stored_value->is_bool()) {
+ *value = stored_value->GetBool();
+ return true;
+ }
+ return stored_value->is_bool();
}
void TestingPrefStore::SetBlockAsyncRead(bool block_async_read) {
diff --git a/components/prefs/testing_pref_store.h b/components/prefs/testing_pref_store.h
index 499b094..233294b 100644
--- a/components/prefs/testing_pref_store.h
+++ b/components/prefs/testing_pref_store.h
@@ -25,7 +25,7 @@
// Overriden from PrefStore.
bool GetValue(const std::string& key,
const base::Value** result) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
@@ -35,10 +35,10 @@
bool GetMutableValue(const std::string& key, base::Value** result) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override;
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool ReadOnly() const override;
diff --git a/components/prefs/value_map_pref_store.cc b/components/prefs/value_map_pref_store.cc
index 79c2017..7305a28 100644
--- a/components/prefs/value_map_pref_store.cc
+++ b/components/prefs/value_map_pref_store.cc
@@ -17,8 +17,8 @@
return prefs_.GetValue(key, value);
}
-std::unique_ptr<base::DictionaryValue> ValueMapPrefStore::GetValues() const {
- return prefs_.AsDictionaryValue();
+base::Value::Dict ValueMapPrefStore::GetValues() const {
+ return prefs_.AsDict();
}
void ValueMapPrefStore::AddObserver(PrefStore::Observer* observer) {
@@ -30,14 +30,13 @@
}
bool ValueMapPrefStore::HasObservers() const {
- return observers_.might_have_observers();
+ return !observers_.empty();
}
void ValueMapPrefStore::SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- if (prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)))) {
+ if (prefs_.SetValue(key, std::move(value))) {
for (Observer& observer : observers_)
observer.OnPrefValueChanged(key);
}
@@ -62,10 +61,9 @@
}
void ValueMapPrefStore::SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) {
- DCHECK(value);
- prefs_.SetValue(key, base::Value::FromUniquePtrValue(std::move(value)));
+ prefs_.SetValue(key, std::move(value));
}
ValueMapPrefStore::~ValueMapPrefStore() {}
diff --git a/components/prefs/value_map_pref_store.h b/components/prefs/value_map_pref_store.h
index f0de0cd..7fff0f8 100644
--- a/components/prefs/value_map_pref_store.h
+++ b/components/prefs/value_map_pref_store.h
@@ -25,20 +25,20 @@
// PrefStore overrides:
bool GetValue(const std::string& key,
const base::Value** value) const override;
- std::unique_ptr<base::DictionaryValue> GetValues() const override;
+ base::Value::Dict GetValues() const override;
void AddObserver(PrefStore::Observer* observer) override;
void RemoveObserver(PrefStore::Observer* observer) override;
bool HasObservers() const override;
// WriteablePrefStore overrides:
void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
void RemoveValue(const std::string& key, uint32_t flags) override;
bool GetMutableValue(const std::string& key, base::Value** value) override;
void ReportValueChanged(const std::string& key, uint32_t flags) override;
void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) override;
protected:
diff --git a/components/prefs/writeable_pref_store.h b/components/prefs/writeable_pref_store.h
index 9a69c7c..9d5d281 100644
--- a/components/prefs/writeable_pref_store.h
+++ b/components/prefs/writeable_pref_store.h
@@ -38,7 +38,7 @@
// Sets a |value| for |key| in the store. |value| must be non-NULL. |flags| is
// a bitmask of PrefWriteFlags.
virtual void SetValue(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) = 0;
// Removes the value for |key|.
@@ -73,7 +73,7 @@
// tests rely on the number of notifications generated. |flags| is a bitmask
// of PrefWriteFlags.
virtual void SetValueSilently(const std::string& key,
- std::unique_ptr<base::Value> value,
+ base::Value value,
uint32_t flags) = 0;
protected: