| Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
|
| index 4525f1f16c2e94dfe3fea99fd0b3a160d8efecb0..9a182e02528be4ca81d5ba668398d365450c9a9f 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java
|
| @@ -5,12 +5,15 @@
|
| package org.chromium.chrome.browser.ntp.snippets;
|
|
|
| import android.graphics.Bitmap;
|
| +import android.util.Pair;
|
|
|
| import org.chromium.base.Callback;
|
| import org.chromium.base.annotations.CalledByNative;
|
| +import org.chromium.chrome.browser.ntp.NewTabPageUma;
|
| import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo;
|
| import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnum;
|
| import org.chromium.chrome.browser.profiles.Profile;
|
| +import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter;
|
|
|
| import java.util.ArrayList;
|
| import java.util.List;
|
| @@ -18,11 +21,12 @@
|
| /**
|
| * Provides access to the snippets to display on the NTP using the C++ ContentSuggestionsService.
|
| */
|
| -public class SnippetsBridge implements SuggestionsSource {
|
| +public class SnippetsBridge implements SuggestionsSource, SuggestionsMetricsReporter {
|
| private static final String TAG = "SnippetsBridge";
|
|
|
| private long mNativeSnippetsBridge;
|
| private SuggestionsSource.Observer mObserver;
|
| + private SuggestionRanker mRanker;
|
|
|
| public static boolean isCategoryStatusAvailable(@CategoryStatusEnum int status) {
|
| // Note: This code is duplicated in content_suggestions_category_status.cc.
|
| @@ -119,8 +123,9 @@ public void fetchSuggestionImage(SnippetArticle suggestion, Callback<Bitmap> cal
|
| @Override
|
| public void dismissSuggestion(SnippetArticle suggestion) {
|
| assert mNativeSnippetsBridge != 0;
|
| - nativeDismissSuggestion(mNativeSnippetsBridge, suggestion.mUrl, suggestion.mGlobalPosition,
|
| - suggestion.mCategory, suggestion.mPosition, suggestion.mIdWithinCategory);
|
| + Pair<Integer, Integer> suggestionRank = mRanker.getSuggestionRank(suggestion);
|
| + nativeDismissSuggestion(mNativeSnippetsBridge, suggestion.mUrl, suggestionRank.second,
|
| + suggestion.mCategory, suggestionRank.first, suggestion.mIdWithinCategory);
|
| }
|
|
|
| @Override
|
| @@ -135,40 +140,66 @@ public void restoreDismissedCategories() {
|
| nativeRestoreDismissedCategories(mNativeSnippetsBridge);
|
| }
|
|
|
| + @Override
|
| public void onPageShown(int[] categories, int[] suggestionsPerCategory) {
|
| assert mNativeSnippetsBridge != 0;
|
| nativeOnPageShown(mNativeSnippetsBridge, categories, suggestionsPerCategory);
|
| }
|
|
|
| + @Override
|
| public void onSuggestionShown(SnippetArticle suggestion) {
|
| assert mNativeSnippetsBridge != 0;
|
| - nativeOnSuggestionShown(mNativeSnippetsBridge, suggestion.mGlobalPosition,
|
| - suggestion.mCategory, suggestion.mPosition,
|
| - suggestion.mPublishTimestampMilliseconds, suggestion.mScore);
|
| + Pair<Integer, Integer> suggestionRank = mRanker.getSuggestionRank(suggestion);
|
| + nativeOnSuggestionShown(mNativeSnippetsBridge, suggestionRank.second, suggestion.mCategory,
|
| + suggestionRank.first, suggestion.mPublishTimestampMilliseconds, suggestion.mScore);
|
| }
|
|
|
| + @Override
|
| public void onSuggestionOpened(SnippetArticle suggestion, int windowOpenDisposition) {
|
| assert mNativeSnippetsBridge != 0;
|
| - nativeOnSuggestionOpened(mNativeSnippetsBridge, suggestion.mGlobalPosition,
|
| - suggestion.mCategory, suggestion.mPosition,
|
| - suggestion.mPublishTimestampMilliseconds, suggestion.mScore, windowOpenDisposition);
|
| + Pair<Integer, Integer> suggestionRank = mRanker.getSuggestionRank(suggestion);
|
| + nativeOnSuggestionOpened(mNativeSnippetsBridge, suggestionRank.second, suggestion.mCategory,
|
| + suggestionRank.first, suggestion.mPublishTimestampMilliseconds, suggestion.mScore,
|
| + windowOpenDisposition);
|
| }
|
|
|
| + @Override
|
| public void onSuggestionMenuOpened(SnippetArticle suggestion) {
|
| assert mNativeSnippetsBridge != 0;
|
| - nativeOnSuggestionMenuOpened(mNativeSnippetsBridge, suggestion.mGlobalPosition,
|
| - suggestion.mCategory, suggestion.mPosition,
|
| + Pair<Integer, Integer> suggestionRank = mRanker.getSuggestionRank(suggestion);
|
| + nativeOnSuggestionMenuOpened(mNativeSnippetsBridge, suggestionRank.second,
|
| + suggestion.mCategory, suggestionRank.first,
|
| suggestion.mPublishTimestampMilliseconds, suggestion.mScore);
|
| }
|
|
|
| - public void onMoreButtonShown(int category, int position) {
|
| + @Override
|
| + public void onMoreButtonShown(@CategoryInt int category) {
|
| assert mNativeSnippetsBridge != 0;
|
| - nativeOnMoreButtonShown(mNativeSnippetsBridge, category, position);
|
| + nativeOnMoreButtonShown(
|
| + mNativeSnippetsBridge, category, mRanker.getActionItemRank(category));
|
| }
|
|
|
| - public void onMoreButtonClicked(int category, int position) {
|
| + @Override
|
| + public void onMoreButtonClicked(int category) {
|
| assert mNativeSnippetsBridge != 0;
|
| - nativeOnMoreButtonClicked(mNativeSnippetsBridge, category, position);
|
| + nativeOnMoreButtonClicked(
|
| + mNativeSnippetsBridge, category, mRanker.getActionItemRank(category));
|
| + switch (category) {
|
| + case KnownCategories.BOOKMARKS:
|
| + NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARKS_MANAGER);
|
| + break;
|
| + // MORE button in both categories leads to the recent tabs manager
|
| + case KnownCategories.FOREIGN_TABS:
|
| + case KnownCategories.RECENT_TABS:
|
| + NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_RECENT_TABS_MANAGER);
|
| + break;
|
| + case KnownCategories.DOWNLOADS:
|
| + NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_DOWNLOADS_MANAGER);
|
| + break;
|
| + default:
|
| + // No action associated
|
| + break;
|
| + }
|
| }
|
|
|
| /**
|
| @@ -193,21 +224,19 @@ public static void onSuggestionTargetVisited(int category, long visitTimeMs) {
|
| nativeOnSuggestionTargetVisited(category, visitTimeMs);
|
| }
|
|
|
| - /**
|
| - * Sets the recipient for the fetched snippets.
|
| - *
|
| - * An observer needs to be set before the native code attempts to transmit snippets them to
|
| - * java. Upon registration, the observer will be notified of already fetched snippets.
|
| - *
|
| - * @param observer object to notify when snippets are received.
|
| - */
|
| @Override
|
| - public void setObserver(SuggestionsSource.Observer observer) {
|
| + public void setObserver(Observer observer) {
|
| assert observer != null;
|
| mObserver = observer;
|
| }
|
|
|
| @Override
|
| + public void setRanker(SuggestionRanker suggestionRanker) {
|
| + assert suggestionRanker != null;
|
| + mRanker = suggestionRanker;
|
| + }
|
| +
|
| + @Override
|
| public void fetchSuggestions(@CategoryInt int category, String[] displayedSuggestionIds) {
|
| nativeFetch(mNativeSnippetsBridge, category, displayedSuggestionIds);
|
| }
|
| @@ -233,7 +262,7 @@ private static SnippetArticle addSuggestion(List<SnippetArticle> suggestions, in
|
| long timestamp, float score) {
|
| int position = suggestions.size();
|
| suggestions.add(new SnippetArticle(
|
| - category, id, title, publisher, previewText, url, timestamp, score, position));
|
| + category, id, title, publisher, previewText, url, timestamp, score));
|
| return suggestions.get(position);
|
| }
|
|
|
|
|