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

Side by Side Diff: components/ntp_snippets/pref_util.cc

Issue 2823073003: Make Use of Value::GetList API
Patch Set: Further Usages 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ntp_snippets/pref_util.h" 5 #include "components/ntp_snippets/pref_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "components/prefs/pref_service.h" 10 #include "components/prefs/pref_service.h"
11 11
12 namespace ntp_snippets { 12 namespace ntp_snippets {
13 namespace prefs { 13 namespace prefs {
14 14
15 std::set<std::string> ReadDismissedIDsFromPrefs(const PrefService& pref_service, 15 std::set<std::string> ReadDismissedIDsFromPrefs(const PrefService& pref_service,
16 const std::string& pref_name) { 16 const std::string& pref_name) {
17 std::set<std::string> dismissed_ids; 17 std::set<std::string> dismissed_ids;
18 const base::ListValue* list = pref_service.GetList(pref_name); 18 const base::Value* list = pref_service.GetList(pref_name);
19 for (const base::Value& value : *list) { 19 for (const base::Value& value : list->GetList()) {
20 std::string dismissed_id; 20 std::string dismissed_id;
21 bool success = value.GetAsString(&dismissed_id); 21 bool success = value.GetAsString(&dismissed_id);
22 DCHECK(success) << "Failed to parse dismissed id from prefs param " 22 DCHECK(success) << "Failed to parse dismissed id from prefs param "
23 << pref_name << " into string."; 23 << pref_name << " into string.";
24 dismissed_ids.insert(dismissed_id); 24 dismissed_ids.insert(dismissed_id);
25 } 25 }
26 return dismissed_ids; 26 return dismissed_ids;
27 } 27 }
28 28
29 void StoreDismissedIDsToPrefs(PrefService* pref_service, 29 void StoreDismissedIDsToPrefs(PrefService* pref_service,
30 const std::string& pref_name, 30 const std::string& pref_name,
31 const std::set<std::string>& dismissed_ids) { 31 const std::set<std::string>& dismissed_ids) {
32 base::ListValue list; 32 base::Value list(base::Value::Type::LIST);
33 for (const std::string& dismissed_id : dismissed_ids) { 33 for (const std::string& dismissed_id : dismissed_ids) {
34 list.AppendString(dismissed_id); 34 list.GetList().emplace_back(dismissed_id);
35 } 35 }
36 pref_service->Set(pref_name, list); 36 pref_service->Set(pref_name, list);
37 } 37 }
38 38
39 } // namespace prefs 39 } // namespace prefs
40 } // namespace ntp_snippets 40 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/protocol_handlers_handler.cc ('k') | components/sync/driver/about_sync_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698