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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java

Issue 2618893003: 📰 Tweak the suggestion ranks for UMA to handle fetchMore (Closed)
Patch Set: Fix action item reported position Created 3 years, 11 months 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
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
index c4ecfd880faeb8c229a9edc9d5489d7c293eb21d..bc2c4b0e4685f59dc7a0e97a182bafbee7255ca3 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/SectionList.java
@@ -32,8 +32,10 @@
private final Map<Integer, SuggestionsSection> mSections = new LinkedHashMap<>();
private final NewTabPageManager mNewTabPageManager;
private final OfflinePageBridge mOfflinePageBridge;
+ private final SuggestionRanker mSuggestionRanker;
public SectionList(NewTabPageManager newTabPageManager, OfflinePageBridge offlinePageBridge) {
+ mSuggestionRanker = new SuggestionRanker();
mNewTabPageManager = newTabPageManager;
mNewTabPageManager.getSuggestionsSource().setObserver(this);
mOfflinePageBridge = offlinePageBridge;
@@ -63,7 +65,8 @@ public void resetSections(boolean alwaysAllowEmptySections) {
resetSection(category, categoryStatus, alwaysAllowEmptySections);
}
- mNewTabPageManager.trackSnippetsPageImpression(categories, suggestionsPerCategory);
+ mNewTabPageManager.getSuggestionsMetricsReporter().onPageShown(
+ categories, suggestionsPerCategory);
}
/**
@@ -92,8 +95,10 @@ private int resetSection(@CategoryInt int category, @CategoryStatusEnum int cate
// Create the section if needed.
if (section == null) {
- section = new SuggestionsSection(this, mNewTabPageManager, mOfflinePageBridge, info);
+ section = new SuggestionsSection(
+ this, mNewTabPageManager, mSuggestionRanker, mOfflinePageBridge, info);
mSections.put(category, section);
+ mSuggestionRanker.registerCategory(category);
addChild(section);
}
@@ -183,17 +188,6 @@ public void onFullRefreshRequired() {
*/
private void setSuggestions(@CategoryInt int category, List<SnippetArticle> suggestions,
@CategoryStatusEnum int status, boolean replaceExisting) {
- // Count the number of suggestions before this category.
- int globalPositionOffset = 0;
- for (Map.Entry<Integer, SuggestionsSection> entry : mSections.entrySet()) {
- if (entry.getKey() == category) break;
- globalPositionOffset += entry.getValue().getSuggestionsCount();
- }
- // Assign global indices to the new suggestions.
- for (SnippetArticle suggestion : suggestions) {
- suggestion.mGlobalPosition = globalPositionOffset + suggestion.mPosition;
- }
-
mSections.get(category).setSuggestions(suggestions, status, replaceExisting);
}
@@ -254,4 +248,41 @@ public boolean isEmpty() {
SuggestionsSection getSectionForTesting(@CategoryInt int categoryId) {
return mSections.get(categoryId);
}
+
+ /**
+ * Attributes ranks to suggestions and related elements.
+ *
+ * Ranks here are 0-based scores attributed based on the position or loading order of the
+ * elements. See implementation for more details.
+ */
+ public static class SuggestionRanker {
Bernhard Bauer 2017/01/17 17:42:31 Can we move this to a separate class? There isn't
dgn 2017/01/17 18:46:24 Done.
+ private final Map<Integer, Integer> mSuggestionsAddedPerSection = new LinkedHashMap<>();
+ private int mTotalAddedSuggestions;
+
+ /**
+ * Attributes a per section rank to the provided action item.
+ * @see ActionItem#getPerSectionRank()
+ */
+ public void rankItem(ActionItem actionItem, SuggestionsSection section) {
Bernhard Bauer 2017/01/17 17:42:31 Can we rename these methods to rankActionItem() an
dgn 2017/01/17 18:46:24 Done.
+ if (actionItem.getPerSectionRank() != -1) return; // Item was already ranked.
+ actionItem.setRank(section.getSuggestionsCount());
+ }
+
+ /**
+ * Attributes global and per section rank to the provided suggestion.
+ * @see SnippetArticle#getPerSectionRank()
+ * @see SnippetArticle#getGlobalRank()
+ */
+ public void rankItem(SnippetArticle suggestion) {
+ int globalRank = mTotalAddedSuggestions++;
+ int perSectionRank = mSuggestionsAddedPerSection.get(suggestion.mCategory);
+ mSuggestionsAddedPerSection.put(suggestion.mCategory, perSectionRank + 1);
+
+ suggestion.setRank(perSectionRank, globalRank);
+ }
+
+ public void registerCategory(@CategoryInt int category) {
+ mSuggestionsAddedPerSection.put(category, 0);
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698