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

Unified Diff: chrome/browser/ntp_snippets/download_suggestions_provider.cc

Issue 2555013003: [Offline Pages] Convert Download Suggestions Provider to using OfflinePageAdded (Closed)
Patch Set: rebase Created 4 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ntp_snippets/download_suggestions_provider.cc
diff --git a/chrome/browser/ntp_snippets/download_suggestions_provider.cc b/chrome/browser/ntp_snippets/download_suggestions_provider.cc
index 1189dd79942bbbc9192d5a45bfca4d5275f14de7..b29791506ea5587a8df16985b55739a458f8c180 100644
--- a/chrome/browser/ntp_snippets/download_suggestions_provider.cc
+++ b/chrome/browser/ntp_snippets/download_suggestions_provider.cc
@@ -48,6 +48,11 @@ const char kOfflinePageDownloadsPrefix = 'O';
const char* kMaxSuggestionsCountParamName = "downloads_max_count";
+bool CompareOfflinePagesForSorting(const OfflinePageItem& left,
vitaliii 2016/12/08 17:40:32 Could you have this consistent (naming, struct) wi
vitaliii 2016/12/08 18:17:20 Actually, I understood that then the struct is ugl
dewittj 2016/12/08 19:09:02 Done.
dewittj 2016/12/08 19:09:02 Done.
+ const OfflinePageItem& right) {
+ return left.creation_time > right.creation_time;
+}
+
int GetMaxSuggestionsCount() {
bool assets_enabled =
base::FeatureList::IsEnabled(features::kAssetDownloadSuggestionsFeature);
@@ -309,9 +314,24 @@ void DownloadSuggestionsProvider::OfflinePageModelLoaded(
void DownloadSuggestionsProvider::OfflinePageAdded(
vitaliii 2016/12/08 17:40:32 Do I understand right that OfflinePage can be eith
dewittj 2016/12/08 19:09:02 Currently pages can be accessed (and thus altered)
vitaliii 2016/12/09 10:02:37 Acknowledged.
offline_pages::OfflinePageModel* model,
const offline_pages::OfflinePageItem& added_page) {
- // TODO(dewittj, vitaliii): Don't refetch everything when this is called.
DCHECK_EQ(offline_page_model_, model);
- AsynchronouslyFetchOfflinePagesDownloads(/*notify=*/true);
+ if (!IsClientIdForOfflinePageDownload(model->GetPolicyController(),
+ added_page.client_id)) {
+ return;
+ }
+
+ cached_offline_page_downloads_.push_back(added_page);
vitaliii 2016/12/08 17:40:32 You also need to check that this offline page is n
vitaliii 2016/12/08 18:17:20 Ok, technically you do not need to check this unle
dewittj 2016/12/08 19:09:02 I didn't add that check because I assumed that new
dewittj 2016/12/08 19:09:02 Done.
+
+ if (static_cast<int>(cached_offline_page_downloads_.size()) >
+ GetMaxSuggestionsCount()) {
+ auto oldest_page_iterator = std::max_element(
+ cached_offline_page_downloads_.begin(),
+ cached_offline_page_downloads_.end(),
+ &CompareOfflinePagesForSorting);
+ cached_offline_page_downloads_.erase(oldest_page_iterator);
vitaliii 2016/12/08 17:40:32 Could you instead do (*oldest_page_iterator) = ad
dewittj 2016/12/08 19:09:02 Done.
+ }
+
+ SubmitContentSuggestions();
}
void DownloadSuggestionsProvider::OfflinePageDeleted(
@@ -658,7 +678,7 @@ void DownloadSuggestionsProvider::UpdateOfflinePagesCache(
std::nth_element(
items.begin(), items.begin() + max_suggestions_count, items.end(),
[](const OfflinePageItem* left, const OfflinePageItem* right) {
- return left->creation_time > right->creation_time;
+ return CompareOfflinePagesForSorting(*left, *right);
});
items.resize(max_suggestions_count);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698