Chromium Code Reviews| 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 10 matching lines...) Expand all Loading... | |
| 21 #include "components/offline_pages/core/offline_page_model.h" | 21 #include "components/offline_pages/core/offline_page_model.h" |
| 22 #include "content/public/browser/download_manager.h" | 22 #include "content/public/browser/download_manager.h" |
| 23 | 23 |
| 24 class PrefRegistrySimple; | 24 class PrefRegistrySimple; |
| 25 class PrefService; | 25 class PrefService; |
| 26 | 26 |
| 27 namespace offline_pages { | 27 namespace offline_pages { |
| 28 struct OfflinePageItem; | 28 struct OfflinePageItem; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace base { | |
| 32 class Clock; | |
| 33 } | |
| 34 | |
| 31 // Provides download content suggestions from the offline pages model and the | 35 // Provides download content suggestions from the offline pages model and the |
| 32 // download manager (obtaining the data through DownloadManager and each | 36 // download manager (obtaining the data through DownloadManager and each |
| 33 // DownloadItem). Offline page related downloads are referred to as offline page | 37 // DownloadItem). Offline page related downloads are referred to as offline page |
| 34 // downloads, while the remaining downloads (e.g. images, music, books) are | 38 // downloads, while the remaining downloads (e.g. images, music, books) are |
| 35 // called asset downloads. In case either of the data sources is |nullptr|, it | 39 // called asset downloads. In case either of the data sources is |nullptr|, it |
| 36 // is ignored. | 40 // is ignored. |
| 37 class DownloadSuggestionsProvider | 41 class DownloadSuggestionsProvider |
| 38 : public ntp_snippets::ContentSuggestionsProvider, | 42 : public ntp_snippets::ContentSuggestionsProvider, |
| 39 public offline_pages::OfflinePageModel::Observer, | 43 public offline_pages::OfflinePageModel::Observer, |
| 40 public content::DownloadManager::Observer, | 44 public content::DownloadManager::Observer, |
| 41 public content::DownloadItem::Observer, | 45 public content::DownloadItem::Observer, |
| 42 public DownloadHistory::Observer { | 46 public DownloadHistory::Observer { |
| 43 public: | 47 public: |
| 44 DownloadSuggestionsProvider( | 48 DownloadSuggestionsProvider( |
| 45 ContentSuggestionsProvider::Observer* observer, | 49 ContentSuggestionsProvider::Observer* observer, |
| 46 offline_pages::OfflinePageModel* offline_page_model, | 50 offline_pages::OfflinePageModel* offline_page_model, |
| 47 content::DownloadManager* download_manager, | 51 content::DownloadManager* download_manager, |
| 48 DownloadHistory* download_history, | 52 DownloadHistory* download_history, |
| 49 PrefService* pref_service); | 53 PrefService* pref_service, |
| 54 std::unique_ptr<base::Clock> clock); | |
| 50 ~DownloadSuggestionsProvider() override; | 55 ~DownloadSuggestionsProvider() override; |
| 51 | 56 |
| 52 // ContentSuggestionsProvider implementation. | 57 // ContentSuggestionsProvider implementation. |
| 53 ntp_snippets::CategoryStatus GetCategoryStatus( | 58 ntp_snippets::CategoryStatus GetCategoryStatus( |
| 54 ntp_snippets::Category category) override; | 59 ntp_snippets::Category category) override; |
| 55 ntp_snippets::CategoryInfo GetCategoryInfo( | 60 ntp_snippets::CategoryInfo GetCategoryInfo( |
| 56 ntp_snippets::Category category) override; | 61 ntp_snippets::Category category) override; |
| 57 void DismissSuggestion( | 62 void DismissSuggestion( |
| 58 const ntp_snippets::ContentSuggestion::ID& suggestion_id) override; | 63 const ntp_snippets::ContentSuggestion::ID& suggestion_id) override; |
| 59 void FetchSuggestionImage( | 64 void FetchSuggestionImage( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 134 |
| 130 // Converts an OfflinePageItem to a ContentSuggestion for the | 135 // Converts an OfflinePageItem to a ContentSuggestion for the |
| 131 // |provided_category_|. | 136 // |provided_category_|. |
| 132 ntp_snippets::ContentSuggestion ConvertOfflinePage( | 137 ntp_snippets::ContentSuggestion ConvertOfflinePage( |
| 133 const offline_pages::OfflinePageItem& offline_page) const; | 138 const offline_pages::OfflinePageItem& offline_page) const; |
| 134 | 139 |
| 135 // Converts DownloadItem to a ContentSuggestion for the |provided_category_|. | 140 // Converts DownloadItem to a ContentSuggestion for the |provided_category_|. |
| 136 ntp_snippets::ContentSuggestion ConvertDownloadItem( | 141 ntp_snippets::ContentSuggestion ConvertDownloadItem( |
| 137 const content::DownloadItem& download_item) const; | 142 const content::DownloadItem& download_item) const; |
| 138 | 143 |
| 144 // Returns true if a download published time is too old to be shown. | |
| 145 bool IsDownloadOld(const base::Time& published_time); | |
|
tschumann
2017/02/02 14:30:34
'old' is a bit short on semantics.
Should we call
vitaliii
2017/02/07 10:26:05
Done. "Outdated"
| |
| 146 | |
| 139 // Adds |item| to the internal asset download cache if all of the following | 147 // Adds |item| to the internal asset download cache if all of the following |
| 140 // holds: | 148 // holds: |
| 141 // - the download is completed; | 149 // - the download is completed; |
| 142 // - its suggestion has not been dismissed; | 150 // - its suggestion has not been dismissed; |
| 143 // - there are less than |kMaxSuggestionsCount| items cached or the oldest | 151 // - there are less than |kMaxSuggestionsCount| items cached or the oldest |
| 144 // cached item is older than the current item (the oldest item is removed | 152 // cached item is older than the current item (the oldest item is removed |
| 145 // then); | 153 // then); |
| 146 // - the item is not present in the cache yet. | 154 // - the item is not present in the cache yet. |
| 147 // Returns |true| if the item has been added. | 155 // Returns |true| if the item has been added. |
| 148 bool CacheAssetDownloadIfNeeded(const content::DownloadItem* item); | 156 bool CacheAssetDownloadIfNeeded(const content::DownloadItem* item); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 void StoreDismissedIDsToPrefs(bool for_offline_page_downloads, | 206 void StoreDismissedIDsToPrefs(bool for_offline_page_downloads, |
| 199 const std::set<std::string>& dismissed_ids); | 207 const std::set<std::string>& dismissed_ids); |
| 200 | 208 |
| 201 void UnregisterDownloadItemObservers(); | 209 void UnregisterDownloadItemObservers(); |
| 202 | 210 |
| 203 ntp_snippets::CategoryStatus category_status_; | 211 ntp_snippets::CategoryStatus category_status_; |
| 204 const ntp_snippets::Category provided_category_; | 212 const ntp_snippets::Category provided_category_; |
| 205 offline_pages::OfflinePageModel* offline_page_model_; | 213 offline_pages::OfflinePageModel* offline_page_model_; |
| 206 content::DownloadManager* download_manager_; | 214 content::DownloadManager* download_manager_; |
| 207 DownloadHistory* download_history_; | 215 DownloadHistory* download_history_; |
| 208 | |
| 209 PrefService* pref_service_; | 216 PrefService* pref_service_; |
| 217 std::unique_ptr<base::Clock> clock_; | |
| 210 | 218 |
| 211 // Cached offline page downloads. If there are not enough asset downloads, all | 219 // Cached offline page downloads. If there are not enough asset downloads, all |
| 212 // of these could be shown (they are the most recently visited, not dismissed | 220 // of these could be shown (they are the most recently visited, not dismissed |
| 213 // and not invalidated). Order is undefined. If the model has less than | 221 // and not invalidated). Order is undefined. If the model has less than |
| 214 // |kMaxSuggestionsCount| offline pages, then all of them which satisfy the | 222 // |kMaxSuggestionsCount| offline pages, then all of them which satisfy the |
| 215 // criteria above are cached, otherwise only |kMaxSuggestionsCount|. | 223 // criteria above are cached, otherwise only |kMaxSuggestionsCount|. |
| 216 std::vector<offline_pages::OfflinePageItem> cached_offline_page_downloads_; | 224 std::vector<offline_pages::OfflinePageItem> cached_offline_page_downloads_; |
| 217 // Cached asset downloads. If there are not enough offline page downloads, all | 225 // Cached asset downloads. If there are not enough offline page downloads, all |
| 218 // of these could be shown (they are the most recently downloaded, not | 226 // of these could be shown (they are the most recently downloaded, not |
| 219 // dismissed and not invalidated). Order is undefined. If the model has less | 227 // dismissed and not invalidated). Order is undefined. If the model has less |
| 220 // than |kMaxSuggestionsCount| asset downloads, then all of them which satisfy | 228 // than |kMaxSuggestionsCount| asset downloads, then all of them which satisfy |
| 221 // the criteria above are cached, otherwise only |kMaxSuggestionsCount|. | 229 // the criteria above are cached, otherwise only |kMaxSuggestionsCount|. |
| 222 std::vector<const content::DownloadItem*> cached_asset_downloads_; | 230 std::vector<const content::DownloadItem*> cached_asset_downloads_; |
| 223 | 231 |
| 224 bool is_asset_downloads_initialization_complete_; | 232 bool is_asset_downloads_initialization_complete_; |
| 225 | 233 |
| 226 base::WeakPtrFactory<DownloadSuggestionsProvider> weak_ptr_factory_; | 234 base::WeakPtrFactory<DownloadSuggestionsProvider> weak_ptr_factory_; |
| 227 | 235 |
| 228 DISALLOW_COPY_AND_ASSIGN(DownloadSuggestionsProvider); | 236 DISALLOW_COPY_AND_ASSIGN(DownloadSuggestionsProvider); |
| 229 }; | 237 }; |
| 230 | 238 |
| 231 #endif // CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ | 239 #endif // CHROME_BROWSER_NTP_SNIPPETS_DOWNLOAD_SUGGESTIONS_PROVIDER_H_ |
| OLD | NEW |