Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: components/ntp_snippets/offline_pages/offline_page_suggestions_provider.h

Issue 2236303002: Make OfflinePage ContentSuggestions dismissable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVIDER_ H_ 5 #ifndef COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVIDER_ H_
6 #define COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVIDER_ H_ 6 #define COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVIDER_ H_
7 7
8 #include <set>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
12 #include "components/ntp_snippets/category.h" 13 #include "components/ntp_snippets/category.h"
13 #include "components/ntp_snippets/category_factory.h" 14 #include "components/ntp_snippets/category_factory.h"
14 #include "components/ntp_snippets/category_status.h" 15 #include "components/ntp_snippets/category_status.h"
15 #include "components/ntp_snippets/content_suggestion.h" 16 #include "components/ntp_snippets/content_suggestion.h"
16 #include "components/ntp_snippets/content_suggestions_provider.h" 17 #include "components/ntp_snippets/content_suggestions_provider.h"
17 #include "components/offline_pages/offline_page_model.h" 18 #include "components/offline_pages/offline_page_model.h"
18 #include "components/offline_pages/offline_page_types.h" 19 #include "components/offline_pages/offline_page_types.h"
19 20
21 class PrefRegistrySimple;
22 class PrefService;
23
20 namespace gfx { 24 namespace gfx {
21 class Image; 25 class Image;
22 } 26 }
23 27
24 namespace ntp_snippets { 28 namespace ntp_snippets {
25 29
26 // Provides content suggestions from the offline pages model. 30 // Provides content suggestions from the offline pages model.
27 // Currently, those are only the pages that the user last navigated to in an 31 // Currently, those are only the pages that the user last navigated to in an
28 // open tab and offlined bookmarks. 32 // open tab and offlined bookmarks.
29 class OfflinePageSuggestionsProvider 33 class OfflinePageSuggestionsProvider
30 : public ContentSuggestionsProvider, 34 : public ContentSuggestionsProvider,
31 public offline_pages::OfflinePageModel::Observer { 35 public offline_pages::OfflinePageModel::Observer {
32 public: 36 public:
33 OfflinePageSuggestionsProvider( 37 OfflinePageSuggestionsProvider(
34 ContentSuggestionsProvider::Observer* observer, 38 ContentSuggestionsProvider::Observer* observer,
35 CategoryFactory* category_factory, 39 CategoryFactory* category_factory,
36 offline_pages::OfflinePageModel* offline_page_model); 40 offline_pages::OfflinePageModel* offline_page_model,
41 PrefService* pref_service);
37 ~OfflinePageSuggestionsProvider() override; 42 ~OfflinePageSuggestionsProvider() override;
38 43
44 static void RegisterProfilePrefs(PrefRegistrySimple* registry);
45
39 private: 46 private:
40 // ContentSuggestionsProvider implementation. 47 // ContentSuggestionsProvider implementation.
41 std::vector<Category> GetProvidedCategories() override; 48 std::vector<Category> GetProvidedCategories() override;
42 CategoryStatus GetCategoryStatus(Category category) override; 49 CategoryStatus GetCategoryStatus(Category category) override;
43 CategoryInfo GetCategoryInfo(Category category) override; 50 CategoryInfo GetCategoryInfo(Category category) override;
44 void DismissSuggestion(const std::string& suggestion_id) override; 51 void DismissSuggestion(const std::string& suggestion_id) override;
45 void FetchSuggestionImage(const std::string& suggestion_id, 52 void FetchSuggestionImage(const std::string& suggestion_id,
46 const ImageFetchedCallback& callback) override; 53 const ImageFetchedCallback& callback) override;
47 void ClearCachedSuggestionsForDebugging(Category category) override; 54 void ClearCachedSuggestionsForDebugging(Category category) override;
48 std::vector<ContentSuggestion> GetDismissedSuggestionsForDebugging( 55 std::vector<ContentSuggestion> GetDismissedSuggestionsForDebugging(
49 Category category) override; 56 Category category) override;
50 void ClearDismissedSuggestionsForDebugging(Category category) override; 57 void ClearDismissedSuggestionsForDebugging(Category category) override;
51 58
52 // OfflinePageModel::Observer implementation. 59 // OfflinePageModel::Observer implementation.
53 void OfflinePageModelLoaded(offline_pages::OfflinePageModel* model) override; 60 void OfflinePageModelLoaded(offline_pages::OfflinePageModel* model) override;
54 void OfflinePageModelChanged(offline_pages::OfflinePageModel* model) override; 61 void OfflinePageModelChanged(offline_pages::OfflinePageModel* model) override;
55 void OfflinePageDeleted(int64_t offline_id, 62 void OfflinePageDeleted(int64_t offline_id,
56 const offline_pages::ClientId& client_id) override; 63 const offline_pages::ClientId& client_id) override;
57 64
58 // Queries the OfflinePageModel for offline pages. 65 // Queries the OfflinePageModel for offline pages.
59 void FetchOfflinePages(); 66 void FetchOfflinePages();
60 67
61 // Callback from the OfflinePageModel. 68 // Callback from the OfflinePageModel.
62 void OnOfflinePagesLoaded( 69 void OnOfflinePagesLoaded(
63 const offline_pages::MultipleOfflinePageItemResult& result); 70 const offline_pages::MultipleOfflinePageItemResult& result);
64 71
65 // Updates the |category_status_| and notifies the |observer_|, if necessary. 72 // Updates the |category_status_| and notifies the |observer_|, if necessary.
66 void NotifyStatusChanged(CategoryStatus new_status); 73 void NotifyStatusChanged(CategoryStatus new_status);
67 74
75 // Converts an OfflinePageItem to a ContentSuggestion.
76 ContentSuggestion ConvertOfflinePage(
77 const offline_pages::OfflinePageItem& offline_page) const;
78
79 // Reads |dismissed_ids_| from the prefs.
80 void ReadDismissedIDsFromPrefs();
81
82 // Writes |dismissed_ids_| to the prefs.
83 void StoreDismissedIDsToPrefs();
84
68 CategoryStatus category_status_; 85 CategoryStatus category_status_;
69 86
70 offline_pages::OfflinePageModel* offline_page_model_; 87 offline_pages::OfflinePageModel* offline_page_model_;
71 88
72 const Category provided_category_; 89 const Category provided_category_;
73 90
91 PrefService* pref_service_;
92
93 std::set<std::string> dismissed_ids_;
Marc Treib 2016/08/11 10:28:12 We could also get rid of this member, and just rea
Philipp Keck 2016/08/11 12:53:19 I don't know -- how slow are prefs? Since we're do
Marc Treib 2016/08/11 13:13:23 They're in memory at least, so it can't be too bad
Philipp Keck 2016/08/11 13:34:04 I tried it out and it doesn't make things easier.
Marc Treib 2016/08/11 13:41:56 For "remove all", there's a ClearPref method. But
94
74 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProvider); 95 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProvider);
75 }; 96 };
76 97
77 } // namespace ntp_snippets 98 } // namespace ntp_snippets
78 99
79 #endif // COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVID ER_H_ 100 #endif // COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVID ER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698