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/offline_pages/offline_page_suggestions_provide r.h" | 5 #include "components/ntp_snippets/offline_pages/offline_page_suggestions_provide r.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | |
8 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/guid.h" | 11 #include "base/guid.h" |
11 #include "base/location.h" | 12 #include "base/location.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "components/ntp_snippets/pref_names.h" | 17 #include "components/ntp_snippets/pref_names.h" |
17 #include "components/offline_pages/client_namespace_constants.h" | 18 #include "components/offline_pages/client_namespace_constants.h" |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 if (category == recent_tabs_category_) | 355 if (category == recent_tabs_category_) |
355 return prefs::kDismissedRecentOfflineTabSuggestions; | 356 return prefs::kDismissedRecentOfflineTabSuggestions; |
356 if (category == downloads_category_) | 357 if (category == downloads_category_) |
357 return prefs::kDismissedDownloadSuggestions; | 358 return prefs::kDismissedDownloadSuggestions; |
358 NOTREACHED() << "Unknown category " << category.id(); | 359 NOTREACHED() << "Unknown category " << category.id(); |
359 return std::string(); | 360 return std::string(); |
360 } | 361 } |
361 | 362 |
362 std::set<std::string> OfflinePageSuggestionsProvider::ReadDismissedIDsFromPrefs( | 363 std::set<std::string> OfflinePageSuggestionsProvider::ReadDismissedIDsFromPrefs( |
363 Category category) const { | 364 Category category) const { |
364 std::set<std::string> dismissed_ids; | 365 return prefs::ReadDismissedIDsFromPrefs(GetDismissedPref(category), |
365 const base::ListValue* list = | 366 pref_service_); |
Marc Treib
2016/08/29 09:18:50
Hm, might as well get rid of the members now and j
skym
2016/09/15 23:18:17
I can do this if you still really want me to, and
| |
366 pref_service_->GetList(GetDismissedPref(category)); | |
367 for (const std::unique_ptr<base::Value>& value : *list) { | |
368 std::string dismissed_id; | |
369 bool success = value->GetAsString(&dismissed_id); | |
370 DCHECK(success) << "Failed to parse dismissed offline page ID from prefs"; | |
371 dismissed_ids.insert(dismissed_id); | |
372 } | |
373 return dismissed_ids; | |
374 } | 367 } |
375 | 368 |
376 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( | 369 void OfflinePageSuggestionsProvider::StoreDismissedIDsToPrefs( |
377 Category category, | 370 Category category, |
378 const std::set<std::string>& dismissed_ids) { | 371 const std::set<std::string>& dismissed_ids) { |
379 base::ListValue list; | 372 prefs::StoreDismissedIDsToPrefs(GetDismissedPref(category), dismissed_ids, |
380 for (const std::string& dismissed_id : dismissed_ids) | 373 pref_service_); |
381 list.AppendString(dismissed_id); | |
382 pref_service_->Set(GetDismissedPref(category), list); | |
383 } | 374 } |
384 | 375 |
385 } // namespace ntp_snippets | 376 } // namespace ntp_snippets |
OLD | NEW |