summaryrefslogtreecommitdiff
path: root/chromium/components/prefs
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 17:21:03 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-01-23 16:25:15 +0000
commitc551f43206405019121bd2b2c93714319a0a3300 (patch)
tree1f48c30631c421fd4bbb3c36da20183c8a2ed7d7 /chromium/components/prefs
parent7961cea6d1041e3e454dae6a1da660b453efd238 (diff)
downloadqtwebengine-chromium-c551f43206405019121bd2b2c93714319a0a3300.tar.gz
BASELINE: Update Chromium to 79.0.3945.139
Change-Id: I336b7182fab9bca80b709682489c07db112eaca5 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/prefs')
-rw-r--r--chromium/components/prefs/json_pref_store.cc79
-rw-r--r--chromium/components/prefs/json_pref_store.h10
-rw-r--r--chromium/components/prefs/json_pref_store_unittest.cc34
-rw-r--r--chromium/components/prefs/mock_pref_change_callback.cc4
-rw-r--r--chromium/components/prefs/pref_change_registrar.cc10
-rw-r--r--chromium/components/prefs/pref_change_registrar.h4
-rw-r--r--chromium/components/prefs/pref_change_registrar_unittest.cc29
-rw-r--r--chromium/components/prefs/pref_filter.h8
-rw-r--r--chromium/components/prefs/pref_member.cc22
-rw-r--r--chromium/components/prefs/pref_member.h12
-rw-r--r--chromium/components/prefs/pref_member_unittest.cc4
-rw-r--r--chromium/components/prefs/pref_service.cc36
-rw-r--r--chromium/components/prefs/pref_service.h3
-rw-r--r--chromium/components/prefs/pref_service_unittest.cc2
-rw-r--r--chromium/components/prefs/pref_value_store.h2
-rw-r--r--chromium/components/prefs/pref_value_store_unittest.cc4
-rw-r--r--chromium/components/prefs/testing_pref_service.cc5
-rw-r--r--chromium/components/prefs/testing_pref_service.h13
18 files changed, 154 insertions, 127 deletions
diff --git a/chromium/components/prefs/json_pref_store.cc b/chromium/components/prefs/json_pref_store.cc
index 0dcdb176263..3b9553cd271 100644
--- a/chromium/components/prefs/json_pref_store.cc
+++ b/chromium/components/prefs/json_pref_store.cc
@@ -54,6 +54,13 @@ namespace {
// Some extensions we'll tack on to copies of the Preferences files.
const base::FilePath::CharType kBadExtension[] = FILE_PATH_LITERAL("bad");
+bool BackupPrefsFile(const base::FilePath& path) {
+ const base::FilePath bad = path.ReplaceExtension(kBadExtension);
+ const bool bad_existed = base::PathExists(bad);
+ base::Move(path, bad);
+ return bad_existed;
+}
+
PersistentPrefStore::PrefReadError HandleReadErrors(
const base::Value* value,
const base::FilePath& path,
@@ -78,13 +85,10 @@ PersistentPrefStore::PrefReadError HandleReadErrors(
// We keep the old file for possible support and debugging assistance
// as well as to detect if they're seeing these errors repeatedly.
// TODO(erikkay) Instead, use the last known good file.
- base::FilePath bad = path.ReplaceExtension(kBadExtension);
-
// If they've ever had a parse error before, put them in another bucket.
// 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::Move(path, bad);
+ const bool bad_existed = BackupPrefsFile(path);
return bad_existed ? PersistentPrefStore::PREF_READ_ERROR_JSON_REPEAT
: PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE;
}
@@ -269,8 +273,9 @@ void JsonPrefStore::ReadPrefsAsync(ReadErrorDelegate* 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_.get(), FROM_HERE,
+ base::BindOnce(&ReadPrefsFromDisk, path_),
+ base::BindOnce(&JsonPrefStore::OnFileRead, AsWeakPtr()));
}
void JsonPrefStore::CommitPendingWrite(
@@ -324,37 +329,37 @@ void JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback(
has_pending_write_reply_ = false;
if (!on_next_successful_write_reply_.is_null()) {
- base::Closure on_successful_write =
+ base::OnceClosure on_successful_write =
std::move(on_next_successful_write_reply_);
if (write_success) {
- on_successful_write.Run();
+ std::move(on_successful_write).Run();
} else {
- RegisterOnNextSuccessfulWriteReply(on_successful_write);
+ RegisterOnNextSuccessfulWriteReply(std::move(on_successful_write));
}
}
}
// static
void JsonPrefStore::PostWriteCallback(
- const base::Callback<void(bool success)>& on_next_write_callback,
- const base::Callback<void(bool success)>& on_next_write_reply,
+ base::OnceCallback<void(bool success)> on_next_write_callback,
+ base::OnceCallback<void(bool success)> on_next_write_reply,
scoped_refptr<base::SequencedTaskRunner> reply_task_runner,
bool write_success) {
if (!on_next_write_callback.is_null())
- on_next_write_callback.Run(write_success);
+ std::move(on_next_write_callback).Run(write_success);
// We can't run |on_next_write_reply| on the current thread. Bounce back to
// the |reply_task_runner| which is the correct sequenced thread.
reply_task_runner->PostTask(
- FROM_HERE, base::BindOnce(on_next_write_reply, write_success));
+ FROM_HERE, base::BindOnce(std::move(on_next_write_reply), write_success));
}
void JsonPrefStore::RegisterOnNextSuccessfulWriteReply(
- const base::Closure& on_next_successful_write_reply) {
+ base::OnceClosure on_next_successful_write_reply) {
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
@@ -362,11 +367,12 @@ void JsonPrefStore::RegisterOnNextSuccessfulWriteReply(
if (!has_pending_write_reply_) {
has_pending_write_reply_ = true;
writer_.RegisterOnNextWriteCallbacks(
- base::Closure(),
- base::Bind(
- &PostWriteCallback, base::Callback<void(bool success)>(),
- base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
- AsWeakPtr()),
+ base::OnceClosure(),
+ base::BindOnce(
+ &PostWriteCallback, base::OnceCallback<void(bool success)>(),
+ base::BindOnce(
+ &JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
+ AsWeakPtr()),
base::SequencedTaskRunnerHandle::Get()));
}
}
@@ -378,11 +384,12 @@ void JsonPrefStore::RegisterOnNextWriteSynchronousCallbacks(
has_pending_write_reply_ = true;
writer_.RegisterOnNextWriteCallbacks(
- callbacks.first,
- base::Bind(
- &PostWriteCallback, callbacks.second,
- base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
- AsWeakPtr()),
+ std::move(callbacks.first),
+ base::BindOnce(
+ &PostWriteCallback, std::move(callbacks.second),
+ base::BindOnce(
+ &JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
+ AsWeakPtr()),
base::SequencedTaskRunnerHandle::Get()));
}
@@ -439,11 +446,10 @@ void JsonPrefStore::OnFileRead(std::unique_ptr<ReadResult> read_result) {
if (pref_filter_) {
filtering_in_progress_ = true;
- const PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback(
- base::Bind(
- &JsonPrefStore::FinalizeFileRead, AsWeakPtr(),
- initialization_successful));
- pref_filter_->FilterOnLoad(post_filter_on_load_callback,
+ PrefFilter::PostFilterOnLoadCallback post_filter_on_load_callback(
+ base::BindOnce(&JsonPrefStore::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),
@@ -465,7 +471,7 @@ bool JsonPrefStore::SerializeData(std::string* output) {
OnWriteCallbackPair callbacks =
pref_filter_->FilterSerializeData(prefs_.get());
if (!callbacks.first.is_null() || !callbacks.second.is_null())
- RegisterOnNextWriteSynchronousCallbacks(callbacks);
+ RegisterOnNextWriteSynchronousCallbacks(std::move(callbacks));
}
JSONStringValueSerializer serializer(output);
@@ -473,8 +479,15 @@ bool JsonPrefStore::SerializeData(std::string* output) {
// 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_);
- DCHECK(success);
+ const bool success = serializer.Serialize(*prefs_);
+ if (!success) {
+ // Failed to serialize prefs file. Backup the existing prefs file and
+ // crash.
+ BackupPrefsFile(path_);
+ CHECK(false) << "Failed to serialize preferences : " << path_
+ << "\nBacked up under "
+ << path_.ReplaceExtension(kBadExtension);
+ }
return success;
}
diff --git a/chromium/components/prefs/json_pref_store.h b/chromium/components/prefs/json_pref_store.h
index 089ce0b6853..163df0f7899 100644
--- a/chromium/components/prefs/json_pref_store.h
+++ b/chromium/components/prefs/json_pref_store.h
@@ -48,7 +48,7 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
// A pair of callbacks to call before and after the preference file is written
// to disk.
using OnWriteCallbackPair =
- std::pair<base::Closure, base::Callback<void(bool success)>>;
+ std::pair<base::OnceClosure, base::OnceCallback<void(bool success)>>;
// |pref_filename| is the path to the file to read prefs from. It is incorrect
// to create multiple JsonPrefStore with the same |pref_filename|.
@@ -113,7 +113,7 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
// |on_next_successful_write_reply| will be called on the thread from which
// this method is called and does not need to be thread safe.
void RegisterOnNextSuccessfulWriteReply(
- const base::Closure& on_next_successful_write_reply);
+ base::OnceClosure on_next_successful_write_reply);
void ClearMutableValues() override;
@@ -134,8 +134,8 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
// |on_next_write_callback| on the current thread and posts
// |on_next_write_reply| on |reply_task_runner|.
static void PostWriteCallback(
- const base::Callback<void(bool success)>& on_next_write_callback,
- const base::Callback<void(bool success)>& on_next_write_reply,
+ base::OnceCallback<void(bool success)> on_next_write_callback,
+ base::OnceCallback<void(bool success)> on_next_write_reply,
scoped_refptr<base::SequencedTaskRunner> reply_task_runner,
bool write_success);
@@ -193,7 +193,7 @@ class COMPONENTS_PREFS_EXPORT JsonPrefStore
std::set<std::string> keys_need_empty_value_;
bool has_pending_write_reply_ = true;
- base::Closure on_next_successful_write_reply_;
+ base::OnceClosure on_next_successful_write_reply_;
SEQUENCE_CHECKER(sequence_checker_);
diff --git a/chromium/components/prefs/json_pref_store_unittest.cc b/chromium/components/prefs/json_pref_store_unittest.cc
index c747c368715..1395433b1af 100644
--- a/chromium/components/prefs/json_pref_store_unittest.cc
+++ b/chromium/components/prefs/json_pref_store_unittest.cc
@@ -68,12 +68,12 @@ class InterceptingPrefFilter : public PrefFilter {
// PrefFilter implementation:
void FilterOnLoad(
- const PostFilterOnLoadCallback& post_filter_on_load_callback,
+ PostFilterOnLoadCallback post_filter_on_load_callback,
std::unique_ptr<base::DictionaryValue> pref_store_contents) override;
void FilterUpdate(const std::string& path) override {}
OnWriteCallbackPair FilterSerializeData(
base::DictionaryValue* pref_store_contents) override {
- return on_write_callback_pair_;
+ return std::move(on_write_callback_pair_);
}
void OnStoreDeletionFromDisk() override {}
@@ -95,22 +95,22 @@ InterceptingPrefFilter::InterceptingPrefFilter() {}
InterceptingPrefFilter::InterceptingPrefFilter(
OnWriteCallbackPair callback_pair) {
- on_write_callback_pair_ = callback_pair;
+ on_write_callback_pair_ = std::move(callback_pair);
}
InterceptingPrefFilter::~InterceptingPrefFilter() {}
void InterceptingPrefFilter::FilterOnLoad(
- const PostFilterOnLoadCallback& post_filter_on_load_callback,
+ PostFilterOnLoadCallback post_filter_on_load_callback,
std::unique_ptr<base::DictionaryValue> pref_store_contents) {
- post_filter_on_load_callback_ = post_filter_on_load_callback;
+ post_filter_on_load_callback_ = std::move(post_filter_on_load_callback);
intercepted_prefs_ = std::move(pref_store_contents);
}
void InterceptingPrefFilter::ReleasePrefs() {
EXPECT_FALSE(post_filter_on_load_callback_.is_null());
- post_filter_on_load_callback_.Run(std::move(intercepted_prefs_), false);
- post_filter_on_load_callback_.Reset();
+ std::move(post_filter_on_load_callback_)
+ .Run(std::move(intercepted_prefs_), false);
}
class MockPrefStoreObserver : public PrefStore::Observer {
@@ -732,8 +732,8 @@ class SuccessfulWriteReplyObserver {
void SuccessfulWriteReplyObserver::ObserveNextWriteCallback(
JsonPrefStore* json_pref_store) {
json_pref_store->RegisterOnNextSuccessfulWriteReply(
- base::Bind(&SuccessfulWriteReplyObserver::OnSuccessfulWrite,
- base::Unretained(this)));
+ base::BindOnce(&SuccessfulWriteReplyObserver::OnSuccessfulWrite,
+ base::Unretained(this)));
}
enum WriteCallbackObservationState {
@@ -758,10 +758,10 @@ class WriteCallbacksObserver {
WriteCallbackObservationState GetAndResetPostWriteObservationState();
JsonPrefStore::OnWriteCallbackPair GetCallbackPair() {
- return std::make_pair(
- base::Bind(&WriteCallbacksObserver::OnPreWrite, base::Unretained(this)),
- base::Bind(&WriteCallbacksObserver::OnPostWrite,
- base::Unretained(this)));
+ return std::make_pair(base::BindOnce(&WriteCallbacksObserver::OnPreWrite,
+ base::Unretained(this)),
+ base::BindOnce(&WriteCallbacksObserver::OnPostWrite,
+ base::Unretained(this)));
}
void OnPreWrite() {
@@ -821,10 +821,10 @@ class JsonPrefStoreCallbackTest : public testing::Test {
void TriggerFakeWriteForCallback(JsonPrefStore* pref_store, bool success) {
JsonPrefStore::PostWriteCallback(
- base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
- pref_store->AsWeakPtr()),
- base::Bind(&WriteCallbacksObserver::OnPostWrite,
- base::Unretained(&write_callback_observer_)),
+ base::BindOnce(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback,
+ pref_store->AsWeakPtr()),
+ base::BindOnce(&WriteCallbacksObserver::OnPostWrite,
+ base::Unretained(&write_callback_observer_)),
base::SequencedTaskRunnerHandle::Get(), success);
}
diff --git a/chromium/components/prefs/mock_pref_change_callback.cc b/chromium/components/prefs/mock_pref_change_callback.cc
index 7ac2cd78451..28cd41d6561 100644
--- a/chromium/components/prefs/mock_pref_change_callback.cc
+++ b/chromium/components/prefs/mock_pref_change_callback.cc
@@ -13,8 +13,8 @@ MockPrefChangeCallback::MockPrefChangeCallback(PrefService* prefs)
MockPrefChangeCallback::~MockPrefChangeCallback() {}
PrefChangeRegistrar::NamedChangeCallback MockPrefChangeCallback::GetCallback() {
- return base::Bind(&MockPrefChangeCallback::OnPreferenceChanged,
- base::Unretained(this));
+ return base::BindRepeating(&MockPrefChangeCallback::OnPreferenceChanged,
+ base::Unretained(this));
}
void MockPrefChangeCallback::Expect(const std::string& pref_name,
diff --git a/chromium/components/prefs/pref_change_registrar.cc b/chromium/components/prefs/pref_change_registrar.cc
index da7de463621..0db9284998c 100644
--- a/chromium/components/prefs/pref_change_registrar.cc
+++ b/chromium/components/prefs/pref_change_registrar.cc
@@ -24,8 +24,9 @@ void PrefChangeRegistrar::Init(PrefService* service) {
}
void PrefChangeRegistrar::Add(const std::string& path,
- const base::Closure& obs) {
- Add(path, base::Bind(&PrefChangeRegistrar::InvokeUnnamedCallback, obs));
+ const base::RepeatingClosure& obs) {
+ Add(path,
+ base::BindRepeating(&PrefChangeRegistrar::InvokeUnnamedCallback, obs));
}
void PrefChangeRegistrar::Add(const std::string& path,
@@ -81,8 +82,9 @@ void PrefChangeRegistrar::OnPreferenceChanged(PrefService* service,
observers_[pref].Run(pref);
}
-void PrefChangeRegistrar::InvokeUnnamedCallback(const base::Closure& callback,
- const std::string& pref_name) {
+void PrefChangeRegistrar::InvokeUnnamedCallback(
+ const base::RepeatingClosure& callback,
+ const std::string& pref_name) {
callback.Run();
}
diff --git a/chromium/components/prefs/pref_change_registrar.h b/chromium/components/prefs/pref_change_registrar.h
index 8aba1b3dfee..86b47718c18 100644
--- a/chromium/components/prefs/pref_change_registrar.h
+++ b/chromium/components/prefs/pref_change_registrar.h
@@ -40,7 +40,7 @@ class COMPONENTS_PREFS_EXPORT PrefChangeRegistrar final : public PrefObserver {
// the preference that is changing as its parameter.
//
// Only one observer may be registered per path.
- void Add(const std::string& path, const base::Closure& obs);
+ void Add(const std::string& path, const base::RepeatingClosure& obs);
void Add(const std::string& path, const NamedChangeCallback& obs);
// Removes the pref observer registered for |path|.
@@ -67,7 +67,7 @@ class COMPONENTS_PREFS_EXPORT PrefChangeRegistrar final : public PrefObserver {
void OnPreferenceChanged(PrefService* service,
const std::string& pref_name) override;
- static void InvokeUnnamedCallback(const base::Closure& callback,
+ static void InvokeUnnamedCallback(const base::RepeatingClosure& callback,
const std::string& pref_name);
using ObserverMap = std::map<std::string, NamedChangeCallback>;
diff --git a/chromium/components/prefs/pref_change_registrar_unittest.cc b/chromium/components/prefs/pref_change_registrar_unittest.cc
index b02b13a5bbe..c41a62be4a3 100644
--- a/chromium/components/prefs/pref_change_registrar_unittest.cc
+++ b/chromium/components/prefs/pref_change_registrar_unittest.cc
@@ -34,6 +34,12 @@ class MockPrefService : public TestingPrefServiceSimple {
MOCK_METHOD2(RemovePrefObserver, void(const std::string&, PrefObserver*));
};
+// Due to overloads, base::DoNothing() cannot be passed directly to
+// PrefChangeRegistrar::Add() as it is convertible to all callbacks.
+base::RepeatingClosure DoNothingClosure() {
+ return base::DoNothing();
+}
+
} // namespace
class PrefChangeRegistrarTest : public testing::Test {
@@ -44,8 +50,6 @@ class PrefChangeRegistrarTest : public testing::Test {
protected:
void SetUp() override;
- base::Closure observer() const { return base::DoNothing(); }
-
MockPrefService* service() const { return service_.get(); }
private:
@@ -65,8 +69,8 @@ TEST_F(PrefChangeRegistrarTest, AddAndRemove) {
AddPrefObserver(Eq(std::string("test.pref.1")), &registrar));
EXPECT_CALL(*service(),
AddPrefObserver(Eq(std::string("test.pref.2")), &registrar));
- registrar.Add("test.pref.1", observer());
- registrar.Add("test.pref.2", observer());
+ registrar.Add("test.pref.1", DoNothingClosure());
+ registrar.Add("test.pref.2", DoNothingClosure());
EXPECT_FALSE(registrar.IsEmpty());
// Test removing.
@@ -91,7 +95,7 @@ TEST_F(PrefChangeRegistrarTest, AutoRemove) {
// Setup of auto-remove.
EXPECT_CALL(*service(),
AddPrefObserver(Eq(std::string("test.pref.1")), &registrar));
- registrar.Add("test.pref.1", observer());
+ registrar.Add("test.pref.1", DoNothingClosure());
Mock::VerifyAndClearExpectations(service());
EXPECT_FALSE(registrar.IsEmpty());
@@ -108,8 +112,8 @@ TEST_F(PrefChangeRegistrarTest, RemoveAll) {
AddPrefObserver(Eq(std::string("test.pref.1")), &registrar));
EXPECT_CALL(*service(),
AddPrefObserver(Eq(std::string("test.pref.2")), &registrar));
- registrar.Add("test.pref.1", observer());
- registrar.Add("test.pref.2", observer());
+ registrar.Add("test.pref.1", DoNothingClosure());
+ registrar.Add("test.pref.2", DoNothingClosure());
Mock::VerifyAndClearExpectations(service());
EXPECT_CALL(*service(),
@@ -136,10 +140,9 @@ class ObserveSetOfPreferencesTest : public testing::Test {
PrefChangeRegistrar* CreatePrefChangeRegistrar() {
PrefChangeRegistrar* pref_set = new PrefChangeRegistrar();
- base::Closure callback = base::DoNothing();
pref_set->Init(pref_service_.get());
- pref_set->Add(kHomePage, callback);
- pref_set->Add(kHomePageIsNewTabPage, callback);
+ pref_set->Add(kHomePage, DoNothingClosure());
+ pref_set->Add(kHomePageIsNewTabPage, DoNothingClosure());
return pref_set;
}
@@ -175,9 +178,9 @@ TEST_F(ObserveSetOfPreferencesTest, Observe) {
using testing::Mock;
PrefChangeRegistrar pref_set;
- PrefChangeRegistrar::NamedChangeCallback callback = base::Bind(
- &ObserveSetOfPreferencesTest::OnPreferenceChanged,
- base::Unretained(this));
+ PrefChangeRegistrar::NamedChangeCallback callback =
+ base::BindRepeating(&ObserveSetOfPreferencesTest::OnPreferenceChanged,
+ base::Unretained(this));
pref_set.Init(pref_service_.get());
pref_set.Add(kHomePage, callback);
pref_set.Add(kHomePageIsNewTabPage, callback);
diff --git a/chromium/components/prefs/pref_filter.h b/chromium/components/prefs/pref_filter.h
index 3d52136a731..33e61ccc534 100644
--- a/chromium/components/prefs/pref_filter.h
+++ b/chromium/components/prefs/pref_filter.h
@@ -22,15 +22,15 @@ class COMPONENTS_PREFS_EXPORT PrefFilter {
public:
// A pair of pre-write and post-write callbacks.
using OnWriteCallbackPair =
- std::pair<base::Closure, base::Callback<void(bool success)>>;
+ std::pair<base::OnceClosure, base::OnceCallback<void(bool success)>>;
// A callback to be invoked when |prefs| have been read (and possibly
// pre-modified) and are now ready to be handed back to this callback's
// 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(std::unique_ptr<base::DictionaryValue> prefs,
+ bool schedule_write)>;
virtual ~PrefFilter() {}
@@ -42,7 +42,7 @@ class COMPONENTS_PREFS_EXPORT PrefFilter {
// PersistentPrefStores should handle this to make the reads look synchronous
// to external users (see SegregatedPrefStore::ReadPrefs() for an example).
virtual void FilterOnLoad(
- const PostFilterOnLoadCallback& post_filter_on_load_callback,
+ PostFilterOnLoadCallback post_filter_on_load_callback,
std::unique_ptr<base::DictionaryValue> pref_store_contents) = 0;
// Receives notification when a pref store value is changed, before Observers
diff --git a/chromium/components/prefs/pref_member.cc b/chromium/components/prefs/pref_member.cc
index a8fa12c1b7f..4051e5cbb24 100644
--- a/chromium/components/prefs/pref_member.cc
+++ b/chromium/components/prefs/pref_member.cc
@@ -54,37 +54,37 @@ void PrefMemberBase::MoveToSequence(
VerifyValuePrefName();
// Load the value from preferences if it hasn't been loaded so far.
if (!internal())
- UpdateValueFromPref(base::Closure());
+ UpdateValueFromPref(base::OnceClosure());
internal()->MoveToSequence(std::move(task_runner));
}
void PrefMemberBase::OnPreferenceChanged(PrefService* service,
const std::string& pref_name) {
VerifyValuePrefName();
- UpdateValueFromPref((!setting_value_ && !observer_.is_null()) ?
- base::Bind(observer_, pref_name) : base::Closure());
+ UpdateValueFromPref((!setting_value_ && !observer_.is_null())
+ ? base::BindOnce(observer_, pref_name)
+ : base::OnceClosure());
}
-void PrefMemberBase::UpdateValueFromPref(const base::Closure& callback) const {
+void PrefMemberBase::UpdateValueFromPref(base::OnceClosure callback) const {
VerifyValuePrefName();
const PrefService::Preference* pref = prefs_->FindPreference(pref_name_);
DCHECK(pref);
if (!internal())
CreateInternal();
- internal()->UpdateValue(pref->GetValue()->DeepCopy(),
- pref->IsManaged(),
- pref->IsUserModifiable(),
- callback);
+ internal()->UpdateValue(pref->GetValue()->DeepCopy(), pref->IsManaged(),
+ pref->IsUserModifiable(), std::move(callback));
}
void PrefMemberBase::VerifyPref() const {
VerifyValuePrefName();
if (!internal())
- UpdateValueFromPref(base::Closure());
+ UpdateValueFromPref(base::OnceClosure());
}
-void PrefMemberBase::InvokeUnnamedCallback(const base::Closure& callback,
- const std::string& pref_name) {
+void PrefMemberBase::InvokeUnnamedCallback(
+ const base::RepeatingClosure& callback,
+ const std::string& pref_name) {
callback.Run();
}
diff --git a/chromium/components/prefs/pref_member.h b/chromium/components/prefs/pref_member.h
index f2166e64154..6f242739985 100644
--- a/chromium/components/prefs/pref_member.h
+++ b/chromium/components/prefs/pref_member.h
@@ -46,7 +46,7 @@ class COMPONENTS_PREFS_EXPORT PrefMemberBase : public PrefObserver {
public:
// Type of callback you can register if you need to know the name of
// the pref that is changing.
- typedef base::Callback<void(const std::string&)> NamedChangeCallback;
+ using NamedChangeCallback = base::RepeatingCallback<void(const std::string&)>;
PrefService* prefs() { return prefs_; }
const PrefService* prefs() const { return prefs_; }
@@ -123,7 +123,7 @@ class COMPONENTS_PREFS_EXPORT PrefMemberBase : public PrefObserver {
// This method is used to do the actual sync with the preference.
// Note: it is logically const, because it doesn't modify the state
// seen by the outside world. It is just doing a lazy load behind the scenes.
- void UpdateValueFromPref(const base::Closure& callback) const;
+ void UpdateValueFromPref(base::OnceClosure callback) const;
// Verifies the preference name, and lazily loads the preference value if
// it hasn't been loaded yet.
@@ -133,8 +133,8 @@ class COMPONENTS_PREFS_EXPORT PrefMemberBase : public PrefObserver {
virtual Internal* internal() const = 0;
- // Used to allow registering plain base::Closure callbacks.
- static void InvokeUnnamedCallback(const base::Closure& callback,
+ // Used to allow registering plain base::RepeatingClosure callbacks.
+ static void InvokeUnnamedCallback(const base::RepeatingClosure& callback,
const std::string& pref_name);
private:
@@ -173,10 +173,10 @@ class PrefMember : public subtle::PrefMemberBase {
}
void Init(const std::string& pref_name,
PrefService* prefs,
- const base::Closure& observer) {
+ const base::RepeatingClosure& observer) {
subtle::PrefMemberBase::Init(
pref_name, prefs,
- base::Bind(&PrefMemberBase::InvokeUnnamedCallback, observer));
+ base::BindRepeating(&PrefMemberBase::InvokeUnnamedCallback, observer));
}
void Init(const std::string& pref_name, PrefService* prefs) {
subtle::PrefMemberBase::Init(pref_name, prefs);
diff --git a/chromium/components/prefs/pref_member_unittest.cc b/chromium/components/prefs/pref_member_unittest.cc
index 126b18fc296..ed2b1a268ce 100644
--- a/chromium/components/prefs/pref_member_unittest.cc
+++ b/chromium/components/prefs/pref_member_unittest.cc
@@ -80,8 +80,8 @@ class PrefMemberTestClass {
explicit PrefMemberTestClass(PrefService* prefs)
: observe_cnt_(0), prefs_(prefs) {
str_.Init(kStringPref, prefs,
- base::Bind(&PrefMemberTestClass::OnPreferenceChanged,
- base::Unretained(this)));
+ base::BindRepeating(&PrefMemberTestClass::OnPreferenceChanged,
+ base::Unretained(this)));
}
void OnPreferenceChanged(const std::string& pref_name) {
diff --git a/chromium/components/prefs/pref_service.cc b/chromium/components/prefs/pref_service.cc
index f0796feafca..3c067f48bd2 100644
--- a/chromium/components/prefs/pref_service.cc
+++ b/chromium/components/prefs/pref_service.cc
@@ -465,34 +465,32 @@ void PrefService::RemovePrefObserverAllPrefs(PrefObserver* obs) {
}
void PrefService::Set(const std::string& path, const base::Value& value) {
- SetUserPrefValue(path, value.CreateDeepCopy());
+ SetUserPrefValue(path, 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::CreateFilePathValue(value));
}
void PrefService::SetInt64(const std::string& path, int64_t value) {
- SetUserPrefValue(path,
- base::Value::ToUniquePtrValue(util::Int64ToValue(value)));
+ SetUserPrefValue(path, util::Int64ToValue(value));
}
int64_t PrefService::GetInt64(const std::string& path) const {
@@ -503,8 +501,7 @@ int64_t PrefService::GetInt64(const std::string& path) const {
}
void PrefService::SetUint64(const std::string& path, uint64_t value) {
- SetUserPrefValue(path,
- std::make_unique<base::Value>(base::NumberToString(value)));
+ SetUserPrefValue(path, base::Value(base::NumberToString(value)));
}
uint64_t PrefService::GetUint64(const std::string& path) const {
@@ -523,8 +520,7 @@ uint64_t PrefService::GetUint64(const std::string& path) const {
}
void PrefService::SetTime(const std::string& path, base::Time value) {
- SetUserPrefValue(path,
- base::Value::ToUniquePtrValue(util::TimeToValue(value)));
+ SetUserPrefValue(path, util::TimeToValue(value));
}
base::Time PrefService::GetTime(const std::string& path) const {
@@ -535,8 +531,7 @@ base::Time PrefService::GetTime(const std::string& path) const {
}
void PrefService::SetTimeDelta(const std::string& path, base::TimeDelta value) {
- SetUserPrefValue(
- path, base::Value::ToUniquePtrValue(util::TimeDeltaToValue(value)));
+ SetUserPrefValue(path, util::TimeDeltaToValue(value));
}
base::TimeDelta PrefService::GetTimeDelta(const std::string& path) const {
@@ -604,7 +599,7 @@ void PrefService::ReportUserPrefChanged(
}
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);
@@ -612,14 +607,15 @@ void PrefService::SetUserPrefValue(const std::string& path,
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();
+ << pref->GetType() << " to value of type " << new_value.type();
return;
}
- user_pref_store_->SetValue(path, std::move(new_value), GetWriteFlags(pref));
+ user_pref_store_->SetValue(
+ path, base::Value::ToUniquePtrValue(std::move(new_value)),
+ GetWriteFlags(pref));
}
void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) {
diff --git a/chromium/components/prefs/pref_service.h b/chromium/components/prefs/pref_service.h
index 9580b48f192..b50a31cc0fd 100644
--- a/chromium/components/prefs/pref_service.h
+++ b/chromium/components/prefs/pref_service.h
@@ -428,8 +428,7 @@ class COMPONENTS_PREFS_EXPORT PrefService {
// 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);
+ void SetUserPrefValue(const std::string& path, 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/chromium/components/prefs/pref_service_unittest.cc b/chromium/components/prefs/pref_service_unittest.cc
index 3bdcf351fc4..4dc3d1154ed 100644
--- a/chromium/components/prefs/pref_service_unittest.cc
+++ b/chromium/components/prefs/pref_service_unittest.cc
@@ -399,7 +399,7 @@ TEST(PrefServiceTest, WriteablePrefStoreFlags) {
EXPECT_EQ(entry.write_flags, flag_checker->GetLastFlagsAndClear());
prefs->SetUserPrefValue(entry.pref_name,
- std::make_unique<base::DictionaryValue>());
+ base::Value(base::Value::Type::DICTIONARY));
EXPECT_TRUE(flag_checker->last_write_flags_set());
EXPECT_EQ(entry.write_flags, flag_checker->GetLastFlagsAndClear());
}
diff --git a/chromium/components/prefs/pref_value_store.h b/chromium/components/prefs/pref_value_store.h
index 70a92bc6c67..80ac8eb7eb4 100644
--- a/chromium/components/prefs/pref_value_store.h
+++ b/chromium/components/prefs/pref_value_store.h
@@ -33,7 +33,7 @@ class PrefStore;
// be called on the UI thread.
class COMPONENTS_PREFS_EXPORT PrefValueStore {
public:
- typedef base::Callback<void(const std::string&)> PrefChangedCallback;
+ using PrefChangedCallback = base::Callback<void(const std::string&)>;
// Delegate used to observe certain events in the |PrefValueStore|'s lifetime.
class Delegate {
diff --git a/chromium/components/prefs/pref_value_store_unittest.cc b/chromium/components/prefs/pref_value_store_unittest.cc
index bbbeed85a3f..146c623160c 100644
--- a/chromium/components/prefs/pref_value_store_unittest.cc
+++ b/chromium/components/prefs/pref_value_store_unittest.cc
@@ -122,8 +122,8 @@ class PrefValueStoreTest : public testing::Test {
&pref_notifier_));
pref_value_store_->set_callback(
- base::Bind(&MockPrefModelAssociator::ProcessPrefChange,
- base::Unretained(sync_associator_.get())));
+ base::BindRepeating(&MockPrefModelAssociator::ProcessPrefChange,
+ base::Unretained(sync_associator_.get())));
}
void CreateManagedPrefs() {
diff --git a/chromium/components/prefs/testing_pref_service.cc b/chromium/components/prefs/testing_pref_service.cc
index aa6582d018b..f6b170a7176 100644
--- a/chromium/components/prefs/testing_pref_service.cc
+++ b/chromium/components/prefs/testing_pref_service.cc
@@ -34,8 +34,9 @@ TestingPrefServiceBase<PrefService, PrefRegistry>::TestingPrefServiceBase(
pref_notifier),
user_prefs,
pref_registry,
- base::Bind(&TestingPrefServiceBase<PrefService,
- PrefRegistry>::HandleReadError),
+ base::BindRepeating(
+ &TestingPrefServiceBase<PrefService,
+ PrefRegistry>::HandleReadError),
false),
managed_prefs_(managed_prefs),
extension_prefs_(extension_prefs),
diff --git a/chromium/components/prefs/testing_pref_service.h b/chromium/components/prefs/testing_pref_service.h
index f10e0cb975b..badf4c1ed0c 100644
--- a/chromium/components/prefs/testing_pref_service.h
+++ b/chromium/components/prefs/testing_pref_service.h
@@ -64,6 +64,9 @@ class TestingPrefServiceBase : public SuperPrefService {
// Do-nothing implementation for TestingPrefService.
static void HandleReadError(PersistentPrefStore::PrefReadError error) {}
+ // Set initialization status of pref stores.
+ void SetInitializationCompleted();
+
protected:
TestingPrefServiceBase(TestingPrefStore* managed_prefs,
TestingPrefStore* extension_prefs,
@@ -230,4 +233,14 @@ void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
pref_store->RemoveValue(path, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
}
+template <class SuperPrefService, class ConstructionPrefRegistry>
+void TestingPrefServiceBase<SuperPrefService, ConstructionPrefRegistry>::
+ SetInitializationCompleted() {
+ managed_prefs_->SetInitializationCompleted();
+ extension_prefs_->SetInitializationCompleted();
+ recommended_prefs_->SetInitializationCompleted();
+ // |user_prefs_| is initialized in PrefService constructor so no need to
+ // set initialization status again.
+}
+
#endif // COMPONENTS_PREFS_TESTING_PREF_SERVICE_H_