| 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 CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ | 6 #define CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 const base::Callback<bool(const GURL& url)>& filter) override; | 68 const base::Callback<bool(const GURL& url)>& filter) override; |
| 69 void ClearCachedSuggestions(ntp_snippets::Category category) override; | 69 void ClearCachedSuggestions(ntp_snippets::Category category) override; |
| 70 void GetDismissedSuggestionsForDebugging( | 70 void GetDismissedSuggestionsForDebugging( |
| 71 ntp_snippets::Category category, | 71 ntp_snippets::Category category, |
| 72 const ntp_snippets::DismissedSuggestionsCallback& callback) override; | 72 const ntp_snippets::DismissedSuggestionsCallback& callback) override; |
| 73 void ClearDismissedSuggestionsForDebugging( | 73 void ClearDismissedSuggestionsForDebugging( |
| 74 ntp_snippets::Category category) override; | 74 ntp_snippets::Category category) override; |
| 75 | 75 |
| 76 static void RegisterProfilePrefs(PrefRegistrySimple* registry); | 76 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 77 | 77 |
| 78 static int GetMaxDismissedCountForTesting(); |
| 79 |
| 78 private: | 80 private: |
| 79 friend class DownloadSuggestionsProviderTest; | 81 friend class DownloadSuggestionsProviderTest; |
| 80 | 82 |
| 81 void GetPagesMatchingQueryCallbackForGetDismissedSuggestions( | 83 void GetPagesMatchingQueryCallbackForGetDismissedSuggestions( |
| 82 const ntp_snippets::DismissedSuggestionsCallback& callback, | 84 const ntp_snippets::DismissedSuggestionsCallback& callback, |
| 83 const std::vector<offline_pages::OfflinePageItem>& offline_pages) const; | 85 const std::vector<offline_pages::OfflinePageItem>& offline_pages) const; |
| 84 | 86 |
| 85 // OfflinePageModel::Observer implementation. | 87 // OfflinePageModel::Observer implementation. |
| 86 void OfflinePageModelLoaded(offline_pages::OfflinePageModel* model) override; | 88 void OfflinePageModelLoaded(offline_pages::OfflinePageModel* model) override; |
| 87 void OfflinePageAdded( | 89 void OfflinePageAdded( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 bool notify, | 166 bool notify, |
| 165 const std::vector<offline_pages::OfflinePageItem>& | 167 const std::vector<offline_pages::OfflinePageItem>& |
| 166 all_download_offline_pages); | 168 all_download_offline_pages); |
| 167 | 169 |
| 168 // Fires the |OnSuggestionInvalidated| event for the suggestion corresponding | 170 // Fires the |OnSuggestionInvalidated| event for the suggestion corresponding |
| 169 // to the given |id_within_category| and clears it from the dismissed IDs | 171 // to the given |id_within_category| and clears it from the dismissed IDs |
| 170 // list, if necessary. | 172 // list, if necessary. |
| 171 void InvalidateSuggestion(const std::string& id_within_category); | 173 void InvalidateSuggestion(const std::string& id_within_category); |
| 172 | 174 |
| 173 // Reads dismissed IDs related to asset downloads from prefs. | 175 // Reads dismissed IDs related to asset downloads from prefs. |
| 174 std::set<std::string> ReadAssetDismissedIDsFromPrefs() const; | 176 std::vector<std::string> ReadAssetDismissedIDsFromPrefs() const; |
| 175 | 177 |
| 176 // Writes |dismissed_ids| into prefs for asset downloads. | 178 // Writes |dismissed_ids| into prefs for asset downloads. |
| 177 void StoreAssetDismissedIDsToPrefs( | 179 void StoreAssetDismissedIDsToPrefs( |
| 178 const std::set<std::string>& dismissed_ids); | 180 const std::vector<std::string>& dismissed_ids); |
| 179 | 181 |
| 180 // Reads dismissed IDs related to offline page downloads from prefs. | 182 // Reads dismissed IDs related to offline page downloads from prefs. |
| 181 std::set<std::string> ReadOfflinePageDismissedIDsFromPrefs() const; | 183 std::set<std::string> ReadOfflinePageDismissedIDsFromPrefs() const; |
| 182 | 184 |
| 183 // Writes |dismissed_ids| into prefs for offline page downloads. | 185 // Writes |dismissed_ids| into prefs for offline page downloads. |
| 184 void StoreOfflinePageDismissedIDsToPrefs( | 186 void StoreOfflinePageDismissedIDsToPrefs( |
| 185 const std::set<std::string>& dismissed_ids); | 187 const std::set<std::string>& dismissed_ids); |
| 186 | 188 |
| 187 // Reads from prefs dismissed IDs related to either offline page or asset | 189 // Adds a suggestion ID to the dismissed list in prefs, if it is not there. |
| 188 // downloads (given by |for_offline_page_downloads|). | 190 // Works for both Offline Page and Asset downloads. |
| 189 std::set<std::string> ReadDismissedIDsFromPrefs( | 191 void AddToDismissedStorageIfNeeded( |
| 190 bool for_offline_page_downloads) const; | 192 const ntp_snippets::ContentSuggestion::ID& suggestion_id); |
| 191 | 193 |
| 192 // Writes |dismissed_ids| into prefs for either offline page or asset | 194 // Removes a suggestion ID from the dismissed list in prefs, if it is there. |
| 193 // downloads (given by |for_offline_page_downloads|). | 195 // Works for both Offline Page and Asset downloads. |
| 194 void StoreDismissedIDsToPrefs(bool for_offline_page_downloads, | 196 void RemoveFromDismissedStorageIfNeeded( |
| 195 const std::set<std::string>& dismissed_ids); | 197 const ntp_snippets::ContentSuggestion::ID& suggestion_id); |
| 196 | 198 |
| 197 void UnregisterDownloadItemObservers(); | 199 void UnregisterDownloadItemObservers(); |
| 198 | 200 |
| 199 ntp_snippets::CategoryStatus category_status_; | 201 ntp_snippets::CategoryStatus category_status_; |
| 200 const ntp_snippets::Category provided_category_; | 202 const ntp_snippets::Category provided_category_; |
| 201 offline_pages::OfflinePageModel* offline_page_model_; | 203 offline_pages::OfflinePageModel* offline_page_model_; |
| 202 content::DownloadManager* download_manager_; | 204 content::DownloadManager* download_manager_; |
| 203 | 205 |
| 204 PrefService* pref_service_; | 206 PrefService* pref_service_; |
| 205 | 207 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 219 // Whether the Download Manager UI is enabled, in which case the More button | 221 // Whether the Download Manager UI is enabled, in which case the More button |
| 220 // for the Downloads section can redirect there. | 222 // for the Downloads section can redirect there. |
| 221 const bool download_manager_ui_enabled_; | 223 const bool download_manager_ui_enabled_; |
| 222 | 224 |
| 223 base::WeakPtrFactory<DownloadSuggestionsProvider> weak_ptr_factory_; | 225 base::WeakPtrFactory<DownloadSuggestionsProvider> weak_ptr_factory_; |
| 224 | 226 |
| 225 DISALLOW_COPY_AND_ASSIGN(DownloadSuggestionsProvider); | 227 DISALLOW_COPY_AND_ASSIGN(DownloadSuggestionsProvider); |
| 226 }; | 228 }; |
| 227 | 229 |
| 228 #endif // CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ | 230 #endif // CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |