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

Unified Diff: services/preferences/public/cpp/pref_store_client_mixin.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
Index: services/preferences/public/cpp/pref_store_client_mixin.cc
diff --git a/services/preferences/public/cpp/pref_store_client_mixin.cc b/services/preferences/public/cpp/pref_store_client_mixin.cc
index 0387883265f206a0a0e34b1c0f981b34f923f239..5d80040aef997115d2d3bde7985b9354d97a30a6 100644
--- a/services/preferences/public/cpp/pref_store_client_mixin.cc
+++ b/services/preferences/public/cpp/pref_store_client_mixin.cc
@@ -6,7 +6,9 @@
#include <utility>
+#include "base/strings/string_split.h"
#include "base/values.h"
+#include "services/preferences/public/cpp/lib/util.h"
#include "services/preferences/public/cpp/pref_store_client.h"
namespace prefs {
@@ -101,22 +103,39 @@ void PrefStoreClientMixin<BasePrefStore>::OnInitializationCompleted(
template <typename BasePrefStore>
void PrefStoreClientMixin<BasePrefStore>::OnPrefChanged(
const std::string& key,
- std::unique_ptr<base::Value> value) {
+ mojom::PrefUpdateValuePtr update_value) {
DCHECK(cached_prefs_);
bool changed = false;
- if (!value) { // Delete
- if (cached_prefs_->RemovePath(key, nullptr))
- changed = true;
- } else {
- const base::Value* prev;
- if (cached_prefs_->Get(key, &prev)) {
- if (!prev->Equals(value.get())) {
+ if (update_value->is_atomic_update()) {
+ auto& value = update_value->get_atomic_update();
+ if (!value) { // Delete
+ if (cached_prefs_->RemovePath(key, nullptr))
+ changed = true;
+ } else {
+ const base::Value* prev;
+ if (cached_prefs_->Get(key, &prev)) {
+ if (!prev->Equals(value.get())) {
+ cached_prefs_->Set(key, std::move(value));
+ changed = true;
+ }
+ } else {
cached_prefs_->Set(key, std::move(value));
changed = true;
}
- } else {
- cached_prefs_->Set(key, std::move(value));
+ }
+ } else if (update_value->is_split_updates()) {
+ auto& updates = update_value->get_split_updates();
+ if (!updates.empty())
changed = true;
+ for (auto& update : updates) {
+ if (update->path.empty())
+ continue;
+
+ std::vector<base::StringPiece> full_path = base::SplitStringPiece(
+ key, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ full_path.insert(full_path.end(), update->path.begin(),
+ update->path.end());
+ prefs::SetValue(cached_prefs_.get(), full_path, std::move(update->value));
}
}
if (changed && initialized_)
« no previous file with comments | « services/preferences/public/cpp/pref_store_client_mixin.h ('k') | services/preferences/public/cpp/pref_store_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698