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

Unified Diff: services/preferences/public/cpp/lib/util.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/lib/util.cc
diff --git a/services/preferences/public/cpp/lib/util.cc b/services/preferences/public/cpp/lib/util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..dcd9f32bfc40b7922b33c22df211acba389efd9a
--- /dev/null
+++ b/services/preferences/public/cpp/lib/util.cc
@@ -0,0 +1,34 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/preferences/public/cpp/lib/util.h"
+
+#include <utility>
+
+#include "base/memory/ptr_util.h"
+#include "base/values.h"
+
+namespace prefs {
+
+void SetValue(base::DictionaryValue* dictionary_value,
+ const std::vector<base::StringPiece>& path_components,
+ std::unique_ptr<base::Value> value) {
+ for (size_t i = 0; i < path_components.size() - 1; ++i) {
+ if (!dictionary_value->GetDictionaryWithoutPathExpansion(
+ path_components[i], &dictionary_value)) {
+ auto new_dict_value_owner = base::MakeUnique<base::DictionaryValue>();
+ auto* new_dict_value = new_dict_value_owner.get();
+ dictionary_value->SetWithoutPathExpansion(
+ path_components[i], std::move(new_dict_value_owner));
+ dictionary_value = new_dict_value;
+ }
+ }
+ const auto& key = path_components.back();
+ if (value)
+ dictionary_value->SetWithoutPathExpansion(key, std::move(value));
+ else
+ dictionary_value->RemoveWithoutPathExpansion(key, nullptr);
+}
+
+} // namespace prefs
« no previous file with comments | « services/preferences/public/cpp/lib/util.h ('k') | services/preferences/public/cpp/persistent_pref_store_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698