| OLD | NEW |
| 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::ListValue* list = pref_service.GetList(pref_name); |
| 19 for (const std::unique_ptr<base::Value>& value : *list) { | 19 for (const base::Value& value : *list) { |
| 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::ListValue 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.AppendString(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 |
| OLD | NEW |