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 #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 <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 17 matching lines...) Expand all Loading... | |
28 namespace ntp_snippets { | 28 namespace ntp_snippets { |
29 | 29 |
30 // Provides content suggestions from the offline pages model. | 30 // Provides content suggestions from the offline pages model. |
31 // 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 |
32 // open tab and offlined bookmarks. | 32 // open tab and offlined bookmarks. |
33 class OfflinePageSuggestionsProvider | 33 class OfflinePageSuggestionsProvider |
34 : public ContentSuggestionsProvider, | 34 : public ContentSuggestionsProvider, |
35 public offline_pages::OfflinePageModel::Observer { | 35 public offline_pages::OfflinePageModel::Observer { |
36 public: | 36 public: |
37 OfflinePageSuggestionsProvider( | 37 OfflinePageSuggestionsProvider( |
38 bool recent_tabs_enabled, | |
39 bool downloads_enabled, | |
38 ContentSuggestionsProvider::Observer* observer, | 40 ContentSuggestionsProvider::Observer* observer, |
39 CategoryFactory* category_factory, | 41 CategoryFactory* category_factory, |
40 offline_pages::OfflinePageModel* offline_page_model, | 42 offline_pages::OfflinePageModel* offline_page_model, |
41 PrefService* pref_service); | 43 PrefService* pref_service); |
42 ~OfflinePageSuggestionsProvider() override; | 44 ~OfflinePageSuggestionsProvider() override; |
43 | 45 |
44 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 46 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
45 | 47 |
46 private: | 48 private: |
47 // ContentSuggestionsProvider implementation. | 49 // ContentSuggestionsProvider implementation. |
(...skipping 14 matching lines...) Expand all Loading... | |
62 void OfflinePageDeleted(int64_t offline_id, | 64 void OfflinePageDeleted(int64_t offline_id, |
63 const offline_pages::ClientId& client_id) override; | 65 const offline_pages::ClientId& client_id) override; |
64 | 66 |
65 // Queries the OfflinePageModel for offline pages. | 67 // Queries the OfflinePageModel for offline pages. |
66 void FetchOfflinePages(); | 68 void FetchOfflinePages(); |
67 | 69 |
68 // Callback from the OfflinePageModel. | 70 // Callback from the OfflinePageModel. |
69 void OnOfflinePagesLoaded( | 71 void OnOfflinePagesLoaded( |
70 const offline_pages::MultipleOfflinePageItemResult& result); | 72 const offline_pages::MultipleOfflinePageItemResult& result); |
71 | 73 |
72 // Updates the |category_status_| and notifies the |observer_|, if necessary. | 74 // Updates the |category_status_| of the |category| and notifies the |
73 void NotifyStatusChanged(CategoryStatus new_status); | 75 // |observer_|, if necessary. |
76 void NotifyStatusChanged(Category category, CategoryStatus new_status); | |
74 | 77 |
75 // Converts an OfflinePageItem to a ContentSuggestion. | 78 // Converts an OfflinePageItem to a ContentSuggestion for the |category|. |
76 ContentSuggestion ConvertOfflinePage( | 79 ContentSuggestion ConvertOfflinePage( |
80 Category category, | |
77 const offline_pages::OfflinePageItem& offline_page) const; | 81 const offline_pages::OfflinePageItem& offline_page) const; |
78 | 82 |
79 // Reads |dismissed_ids_| from the prefs. | 83 // Gets the |kMaxSuggestionsCount| most recently visited OfflinePageItems from |
80 void ReadDismissedIDsFromPrefs(); | 84 // the list, orders them by last visit date and converts them to |
85 // ContentSuggestions for the |category|. | |
86 std::vector<ContentSuggestion> GetMostRecentlyVisited( | |
87 Category category, | |
88 std::vector<const offline_pages::OfflinePageItem*>* offline_page_items) | |
89 const; | |
81 | 90 |
82 // Writes |dismissed_ids_| to the prefs. | 91 // Reads dismissed IDs from the pref with name |pref_name|. |
83 void StoreDismissedIDsToPrefs(); | 92 std::set<std::string> ReadDismissedIDsFromPrefs(const std::string& pref_name); |
Marc Treib
2016/08/12 09:21:14
const?
Philipp Keck
2016/08/12 09:56:40
Done.
| |
84 | 93 |
85 CategoryStatus category_status_; | 94 // Writes |dismissed_ids| to the pref with name |pref_name|. |
95 void StoreDismissedIDsToPrefs(const std::string& pref_name, | |
96 const std::set<std::string>& dismissed_ids); | |
97 | |
98 CategoryStatus recent_tabs_status_; | |
99 CategoryStatus downloads_status_; | |
86 | 100 |
87 offline_pages::OfflinePageModel* offline_page_model_; | 101 offline_pages::OfflinePageModel* offline_page_model_; |
88 | 102 |
89 const Category provided_category_; | 103 const Category recent_tabs_category_; |
104 const Category downloads_category_; | |
90 | 105 |
91 PrefService* pref_service_; | 106 PrefService* pref_service_; |
92 | 107 |
93 std::set<std::string> dismissed_ids_; | 108 std::set<std::string> dismissed_recent_tab_ids_; |
109 std::set<std::string> dismissed_download_ids_; | |
94 | 110 |
95 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProvider); | 111 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProvider); |
96 }; | 112 }; |
97 | 113 |
98 } // namespace ntp_snippets | 114 } // namespace ntp_snippets |
99 | 115 |
100 #endif // COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVID ER_H_ | 116 #endif // COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVID ER_H_ |
OLD | NEW |