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

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: rebase and fix findbugs warning 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 a0190f41f7137b9deb110cbb95d81fa366ea2421..725bef361304c2611074060745898a75627609b8 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
@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.ntp.cards;
+import android.util.Pair;
+
import org.chromium.base.Log;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
@@ -15,6 +17,7 @@
import org.chromium.chrome.browser.ntp.snippets.SnippetsConfig;
import org.chromium.chrome.browser.ntp.snippets.SuggestionsSource;
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge;
+import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter;
import java.util.LinkedHashMap;
import java.util.List;
@@ -24,8 +27,9 @@
* A node in the tree containing a list of all suggestions sections. It listens to changes in the
* suggestions source and updates the corresponding sections.
*/
-public class SectionList
- extends InnerNode implements SuggestionsSource.Observer, SuggestionsSection.Delegate {
+public class SectionList extends InnerNode implements SuggestionsSource.Observer,
+ SuggestionsSection.Delegate,
+ SuggestionsMetricsReporter.SuggestionRanker {
private static final String TAG = "Ntp";
/** Maps suggestion categories to sections, with stable iteration ordering. */
@@ -35,6 +39,7 @@
public SectionList(NewTabPageManager newTabPageManager, OfflinePageBridge offlinePageBridge) {
mNewTabPageManager = newTabPageManager;
+ mNewTabPageManager.getSuggestionsMetricsReporter().setRanker(this);
mNewTabPageManager.getSuggestionsSource().setObserver(this);
mOfflinePageBridge = offlinePageBridge;
resetSections(/* alwaysAllowEmptySections = */ false);
@@ -63,7 +68,8 @@ public void resetSections(boolean alwaysAllowEmptySections) {
resetSection(category, categoryStatus, alwaysAllowEmptySections);
}
- mNewTabPageManager.trackSnippetsPageImpression(categories, suggestionsPerCategory);
+ mNewTabPageManager.getSuggestionsMetricsReporter().onPageShown(
+ categories, suggestionsPerCategory);
}
/**
@@ -175,17 +181,6 @@ public void onFullRefreshRequired() {
private void setSuggestions(@CategoryInt int category, List<SnippetArticle> suggestions,
@CategoryStatusEnum int status) {
- // 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).addSuggestions(suggestions, status);
}
@@ -216,6 +211,29 @@ public void dismissSection(SuggestionsSection section) {
removeSection(section);
}
+ @Override
+ public Pair<Integer, Integer> getSuggestionRank(SnippetArticle suggestion) {
+ int globalRank = 0;
+ for (Map.Entry<Integer, SuggestionsSection> kvPair : mSections.entrySet()) {
+ if (kvPair.getKey() == suggestion.mCategory) {
+ int localRank = kvPair.getValue().getSuggestionRank(suggestion);
+ globalRank += localRank;
+
+ assert localRank != -1;
+ return new Pair<>(localRank, globalRank);
+ }
+ globalRank += kvPair.getValue().getSuggestionsCount();
+ }
+
+ throw new IndexOutOfBoundsException();
+ }
+
+ @Override
+ public int getActionItemRank(@CategoryInt int category) {
+ assert mSections.get(category).getActionItem().isVisible();
+ return mSections.get(category).getSuggestionsCount();
+ }
+
@VisibleForTesting
void removeSection(SuggestionsSection section) {
mSections.remove(section.getCategory());

Powered by Google App Engine
This is Rietveld 408576698