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

Side by Side Diff: services/preferences/public/cpp/lib/util.cc

Issue 2812863002: Pref service: Add a ScopedDictionaryPrefUpdate to track value changes. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "services/preferences/public/cpp/lib/util.h"
6
7 #include <utility>
8
9 #include "base/memory/ptr_util.h"
10 #include "base/values.h"
11
12 namespace prefs {
13
14 void SetValue(base::DictionaryValue* dictionary_value,
15 const std::vector<base::StringPiece>& path_components,
16 std::unique_ptr<base::Value> value) {
17 for (size_t i = 0; i < path_components.size() - 1; ++i) {
18 if (!dictionary_value->GetDictionaryWithoutPathExpansion(
19 path_components[i], &dictionary_value)) {
20 auto new_dict_value_owner = base::MakeUnique<base::DictionaryValue>();
21 auto* new_dict_value = new_dict_value_owner.get();
22 dictionary_value->SetWithoutPathExpansion(
23 path_components[i], std::move(new_dict_value_owner));
24 dictionary_value = new_dict_value;
25 }
26 }
27 const auto& key = path_components.back();
28 if (value)
29 dictionary_value->SetWithoutPathExpansion(key, std::move(value));
30 else
31 dictionary_value->RemoveWithoutPathExpansion(key, nullptr);
32 }
33
34 } // namespace prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698