OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/ntp_snippets/pref_util.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/values.h" |
| 10 #include "components/prefs/pref_service.h" |
| 11 |
| 12 namespace ntp_snippets { |
| 13 namespace prefs { |
| 14 |
| 15 std::set<std::string> ReadDismissedIDsFromPrefs(const PrefService& pref_service, |
| 16 const std::string& pref_name) { |
| 17 std::set<std::string> dismissed_ids; |
| 18 const base::ListValue* list = pref_service.GetList(pref_name); |
| 19 for (const std::unique_ptr<base::Value>& value : *list) { |
| 20 std::string dismissed_id; |
| 21 bool success = value->GetAsString(&dismissed_id); |
| 22 DCHECK(success) << "Failed to parse dismissed id from prefs param " |
| 23 << pref_name << " into string."; |
| 24 dismissed_ids.insert(dismissed_id); |
| 25 } |
| 26 return dismissed_ids; |
| 27 } |
| 28 |
| 29 void StoreDismissedIDsToPrefs(PrefService* pref_service, |
| 30 const std::string& pref_name, |
| 31 const std::set<std::string>& dismissed_ids) { |
| 32 base::ListValue list; |
| 33 for (const std::string& dismissed_id : dismissed_ids) { |
| 34 list.AppendString(dismissed_id); |
| 35 } |
| 36 pref_service->Set(pref_name, list); |
| 37 } |
| 38 |
| 39 } // namespace prefs |
| 40 } // namespace ntp_snippets |
OLD | NEW |