Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Unified Diff: services/preferences/persistent_pref_store_impl.cc

Issue 2812863002: Pref service: Add a ScopedDictionaryPrefUpdate to track value changes. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/preferences/BUILD.gn ('k') | services/preferences/pref_service_factory_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/preferences/persistent_pref_store_impl.cc
diff --git a/services/preferences/persistent_pref_store_impl.cc b/services/preferences/persistent_pref_store_impl.cc
index 95930387654f5c875d845330787287e8bbb2b662..ed0d1c824df963dfc70b274eb89b4487901775ac 100644
--- a/services/preferences/persistent_pref_store_impl.cc
+++ b/services/preferences/persistent_pref_store_impl.cc
@@ -11,7 +11,9 @@
#include "base/stl_util.h"
#include "base/values.h"
#include "components/prefs/persistent_pref_store.h"
+#include "mojo/common/values_struct_traits.h"
#include "mojo/public/cpp/bindings/binding.h"
+#include "services/preferences/public/cpp/lib/util.h"
namespace prefs {
@@ -41,9 +43,7 @@ class PersistentPrefStoreImpl::Connection : public mojom::PersistentPrefStore {
std::vector<mojom::PrefUpdatePtr> filtered_updates;
for (const auto& update : updates) {
if (base::ContainsKey(observed_keys_, update->key)) {
- filtered_updates.push_back(mojom::PrefUpdate::New(
- update->key,
- update->value ? update->value->CreateDeepCopy() : nullptr, 0));
+ filtered_updates.push_back(update->Clone());
}
}
if (!filtered_updates.empty())
@@ -133,11 +133,39 @@ void PersistentPrefStoreImpl::SetValues(
entry.first->OnPrefValuesChanged(updates);
for (auto& update : updates) {
- if (update->value) {
- backing_pref_store_->SetValue(update->key, std::move(update->value),
+ if (update->value->is_atomic_update()) {
+ auto& value = update->value->get_atomic_update();
+ if (value) {
+ backing_pref_store_->SetValue(update->key, value->CreateDeepCopy(),
+ update->flags);
+ } else {
+ backing_pref_store_->RemoveValue(update->key, update->flags);
+ }
+ continue;
+ }
+
+ DCHECK(update->value->is_split_updates());
+ base::Value* mutable_value = nullptr;
+ base::DictionaryValue* dictionary_value = nullptr;
+ std::unique_ptr<base::DictionaryValue> pending_dictionary;
+ if (!backing_pref_store_->GetMutableValue(update->key, &mutable_value) ||
+ !mutable_value->GetAsDictionary(&dictionary_value)) {
+ pending_dictionary = base::MakeUnique<base::DictionaryValue>();
+ dictionary_value = pending_dictionary.get();
+ }
+ for (auto& split_update : update->value->get_split_updates()) {
+ if (split_update->path.empty())
+ continue;
+
+ SetValue(dictionary_value,
+ {split_update->path.begin(), split_update->path.end()},
+ std::move(split_update->value));
+ }
+ if (pending_dictionary) {
+ backing_pref_store_->SetValue(update->key, std::move(pending_dictionary),
update->flags);
} else {
- backing_pref_store_->RemoveValue(update->key, update->flags);
+ backing_pref_store_->ReportValueChanged(update->key, update->flags);
}
}
}
« no previous file with comments | « services/preferences/BUILD.gn ('k') | services/preferences/pref_service_factory_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698