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, |
| 40 bool download_manager_ui_enabled, |
38 ContentSuggestionsProvider::Observer* observer, | 41 ContentSuggestionsProvider::Observer* observer, |
39 CategoryFactory* category_factory, | 42 CategoryFactory* category_factory, |
40 offline_pages::OfflinePageModel* offline_page_model, | 43 offline_pages::OfflinePageModel* offline_page_model, |
41 PrefService* pref_service); | 44 PrefService* pref_service); |
42 ~OfflinePageSuggestionsProvider() override; | 45 ~OfflinePageSuggestionsProvider() override; |
43 | 46 |
44 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 47 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
45 | 48 |
46 private: | 49 private: |
47 // ContentSuggestionsProvider implementation. | 50 // ContentSuggestionsProvider implementation. |
(...skipping 14 matching lines...) Expand all Loading... |
62 void OfflinePageDeleted(int64_t offline_id, | 65 void OfflinePageDeleted(int64_t offline_id, |
63 const offline_pages::ClientId& client_id) override; | 66 const offline_pages::ClientId& client_id) override; |
64 | 67 |
65 // Queries the OfflinePageModel for offline pages. | 68 // Queries the OfflinePageModel for offline pages. |
66 void FetchOfflinePages(); | 69 void FetchOfflinePages(); |
67 | 70 |
68 // Callback from the OfflinePageModel. | 71 // Callback from the OfflinePageModel. |
69 void OnOfflinePagesLoaded( | 72 void OnOfflinePagesLoaded( |
70 const offline_pages::MultipleOfflinePageItemResult& result); | 73 const offline_pages::MultipleOfflinePageItemResult& result); |
71 | 74 |
72 // Updates the |category_status_| and notifies the |observer_|, if necessary. | 75 // Updates the |category_status_| of the |category| and notifies the |
73 void NotifyStatusChanged(CategoryStatus new_status); | 76 // |observer_|, if necessary. |
| 77 void NotifyStatusChanged(Category category, CategoryStatus new_status); |
74 | 78 |
75 // Converts an OfflinePageItem to a ContentSuggestion. | 79 // Converts an OfflinePageItem to a ContentSuggestion for the |category|. |
76 ContentSuggestion ConvertOfflinePage( | 80 ContentSuggestion ConvertOfflinePage( |
| 81 Category category, |
77 const offline_pages::OfflinePageItem& offline_page) const; | 82 const offline_pages::OfflinePageItem& offline_page) const; |
78 | 83 |
79 // Reads |dismissed_ids_| from the prefs. | 84 // Gets the |kMaxSuggestionsCount| most recently visited OfflinePageItems from |
80 void ReadDismissedIDsFromPrefs(); | 85 // the list, orders them by last visit date and converts them to |
| 86 // ContentSuggestions for the |category|. |
| 87 std::vector<ContentSuggestion> GetMostRecentlyVisited( |
| 88 Category category, |
| 89 std::vector<const offline_pages::OfflinePageItem*> offline_page_items) |
| 90 const; |
81 | 91 |
82 // Writes |dismissed_ids_| to the prefs. | 92 // Reads dismissed IDs from the pref with name |pref_name|. |
83 void StoreDismissedIDsToPrefs(); | 93 std::set<std::string> ReadDismissedIDsFromPrefs( |
| 94 const std::string& pref_name) const; |
84 | 95 |
85 CategoryStatus category_status_; | 96 // Writes |dismissed_ids| to the pref with name |pref_name|. |
| 97 void StoreDismissedIDsToPrefs(const std::string& pref_name, |
| 98 const std::set<std::string>& dismissed_ids); |
| 99 |
| 100 CategoryStatus recent_tabs_status_; |
| 101 CategoryStatus downloads_status_; |
86 | 102 |
87 offline_pages::OfflinePageModel* offline_page_model_; | 103 offline_pages::OfflinePageModel* offline_page_model_; |
88 | 104 |
89 const Category provided_category_; | 105 const Category recent_tabs_category_; |
| 106 const Category downloads_category_; |
90 | 107 |
91 PrefService* pref_service_; | 108 PrefService* pref_service_; |
92 | 109 |
93 std::set<std::string> dismissed_ids_; | 110 std::set<std::string> dismissed_recent_tab_ids_; |
| 111 std::set<std::string> dismissed_download_ids_; |
| 112 |
| 113 // Whether the Download Manager UI is enabled, in which case the More button |
| 114 // for the Downloads section can redirect there. |
| 115 const bool download_manager_ui_enabled_; |
94 | 116 |
95 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProvider); | 117 DISALLOW_COPY_AND_ASSIGN(OfflinePageSuggestionsProvider); |
96 }; | 118 }; |
97 | 119 |
98 } // namespace ntp_snippets | 120 } // namespace ntp_snippets |
99 | 121 |
100 #endif // COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVID
ER_H_ | 122 #endif // COMPONENTS_NTP_SNIPPETS_OFFLINE_PAGES_OFFLINE_PAGE_SUGGESTIONS_PROVID
ER_H_ |
OLD | NEW |