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 <memory> |
| 6 |
| 7 #include "base/values.h" |
5 #include "components/ntp_snippets/pref_names.h" | 8 #include "components/ntp_snippets/pref_names.h" |
| 9 #include "components/prefs/pref_service.h" |
6 | 10 |
7 namespace ntp_snippets { | 11 namespace ntp_snippets { |
8 namespace prefs { | 12 namespace prefs { |
9 | 13 |
10 const char kEnableSnippets[] = "ntp_snippets.enable"; | 14 const char kEnableSnippets[] = "ntp_snippets.enable"; |
11 | 15 |
12 const char kSnippetHosts[] = "ntp_snippets.hosts"; | 16 const char kSnippetHosts[] = "ntp_snippets.hosts"; |
13 | 17 |
14 const char kSnippetFetcherRequestCount[] = | 18 const char kSnippetFetcherRequestCount[] = |
15 "ntp.request_throttler.suggestion_fetcher.count"; | 19 "ntp.request_throttler.suggestion_fetcher.count"; |
16 const char kSnippetFetcherInteractiveRequestCount[] = | 20 const char kSnippetFetcherInteractiveRequestCount[] = |
17 "ntp.request_throttler.suggestion_fetcher.interactive_count"; | 21 "ntp.request_throttler.suggestion_fetcher.interactive_count"; |
18 const char kSnippetFetcherRequestsDay[] = | 22 const char kSnippetFetcherRequestsDay[] = |
19 "ntp.request_throttler.suggestion_fetcher.day"; | 23 "ntp.request_throttler.suggestion_fetcher.day"; |
20 | 24 |
21 const char kSnippetThumbnailsRequestCount[] = | 25 const char kSnippetThumbnailsRequestCount[] = |
22 "ntp.request_throttler.suggestion_thumbnails.count"; | 26 "ntp.request_throttler.suggestion_thumbnails.count"; |
23 const char kSnippetThumbnailsInteractiveRequestCount[] = | 27 const char kSnippetThumbnailsInteractiveRequestCount[] = |
24 "ntp.request_throttler.suggestion_thumbnails.interactive_count"; | 28 "ntp.request_throttler.suggestion_thumbnails.interactive_count"; |
25 const char kSnippetThumbnailsRequestsDay[] = | 29 const char kSnippetThumbnailsRequestsDay[] = |
26 "ntp.request_throttler.suggestion_thumbnails.day"; | 30 "ntp.request_throttler.suggestion_thumbnails.day"; |
27 | 31 |
28 const char kDismissedRecentOfflineTabSuggestions[] = | 32 const char kDismissedRecentOfflineTabSuggestions[] = |
29 "ntp_suggestions.offline_pages.recent_tabs.dismissed_ids"; | 33 "ntp_suggestions.offline_pages.recent_tabs.dismissed_ids"; |
30 const char kDismissedDownloadSuggestions[] = | 34 const char kDismissedDownloadSuggestions[] = |
31 "ntp_suggestions.offline_pages.downloads.dismissed_ids"; | 35 "ntp_suggestions.offline_pages.downloads.dismissed_ids"; |
| 36 const char kDismissedForeignSessionsSuggestions[] = |
| 37 "ntp_suggestoin.foreign_sessions.dismissed_ids"; |
32 | 38 |
33 const char kBookmarksFirstM54Start[] = | 39 const char kBookmarksFirstM54Start[] = |
34 "ntp_suggestions.bookmarks.first_M54_start"; | 40 "ntp_suggestions.bookmarks.first_M54_start"; |
35 | 41 |
| 42 std::set<std::string> ReadDismissedIDsFromPrefs(const std::string& pref_name, |
| 43 PrefService* pref_service) { |
| 44 std::set<std::string> dismissed_ids; |
| 45 const base::ListValue* list = pref_service->GetList(pref_name); |
| 46 for (const std::unique_ptr<base::Value>& value : *list) { |
| 47 std::string dismissed_id; |
| 48 bool success = value->GetAsString(&dismissed_id); |
| 49 DCHECK(success) << "Failed to parse dismissed id from prefs param " |
| 50 << pref_name << " into string."; |
| 51 dismissed_ids.insert(dismissed_id); |
| 52 } |
| 53 return dismissed_ids; |
| 54 } |
| 55 |
| 56 void StoreDismissedIDsToPrefs(const std::string& pref_name, |
| 57 const std::set<std::string>& dismissed_ids, |
| 58 PrefService* pref_service) { |
| 59 base::ListValue list; |
| 60 for (const std::string& dismissed_id : dismissed_ids) { |
| 61 list.AppendString(dismissed_id); |
| 62 } |
| 63 pref_service->Set(pref_name, list); |
| 64 } |
| 65 |
36 } // namespace prefs | 66 } // namespace prefs |
37 } // namespace ntp_snippets | 67 } // namespace ntp_snippets |
OLD | NEW |