Index: components/ntp_snippets/pref_names.cc |
diff --git a/components/ntp_snippets/pref_names.cc b/components/ntp_snippets/pref_names.cc |
index 4221d60082acf7625a499fb94496a95ee74be955..890f1e59f7e6cb5bfa8fb1f059e2bda59bfa44b9 100644 |
--- a/components/ntp_snippets/pref_names.cc |
+++ b/components/ntp_snippets/pref_names.cc |
@@ -2,7 +2,11 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <memory> |
+ |
+#include "base/values.h" |
#include "components/ntp_snippets/pref_names.h" |
+#include "components/prefs/pref_service.h" |
namespace ntp_snippets { |
namespace prefs { |
@@ -29,9 +33,35 @@ const char kDismissedRecentOfflineTabSuggestions[] = |
"ntp_suggestions.offline_pages.recent_tabs.dismissed_ids"; |
const char kDismissedDownloadSuggestions[] = |
"ntp_suggestions.offline_pages.downloads.dismissed_ids"; |
+const char kDismissedForeignSessionsSuggestions[] = |
+ "ntp_suggestoin.foreign_sessions.dismissed_ids"; |
const char kBookmarksFirstM54Start[] = |
"ntp_suggestions.bookmarks.first_M54_start"; |
+std::set<std::string> ReadDismissedIDsFromPrefs(const std::string& pref_name, |
+ PrefService* pref_service) { |
+ std::set<std::string> dismissed_ids; |
+ const base::ListValue* list = pref_service->GetList(pref_name); |
+ for (const std::unique_ptr<base::Value>& value : *list) { |
+ std::string dismissed_id; |
+ bool success = value->GetAsString(&dismissed_id); |
+ DCHECK(success) << "Failed to parse dismissed id from prefs param " |
+ << pref_name << " into string."; |
+ dismissed_ids.insert(dismissed_id); |
+ } |
+ return dismissed_ids; |
+} |
+ |
+void StoreDismissedIDsToPrefs(const std::string& pref_name, |
+ const std::set<std::string>& dismissed_ids, |
+ PrefService* pref_service) { |
+ base::ListValue list; |
+ for (const std::string& dismissed_id : dismissed_ids) { |
+ list.AppendString(dismissed_id); |
+ } |
+ pref_service->Set(pref_name, list); |
+} |
+ |
} // namespace prefs |
} // namespace ntp_snippets |