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..b48d784648f6f95188f89ec03254ee42a3f43bc5 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 |
@@ -8,9 +8,12 @@ |
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.ActionItem; |
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,7 +21,7 @@ |
/** |
* 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; |
@@ -119,8 +122,8 @@ 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); |
+ nativeDismissSuggestion(mNativeSnippetsBridge, suggestion.mUrl, suggestion.getGlobalRank(), |
+ suggestion.mCategory, suggestion.getPerSectionRank(), suggestion.mIdWithinCategory); |
} |
@Override |
@@ -135,40 +138,65 @@ 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, |
+ nativeOnSuggestionShown(mNativeSnippetsBridge, suggestion.getGlobalRank(), |
+ suggestion.mCategory, suggestion.getPerSectionRank(), |
suggestion.mPublishTimestampMilliseconds, suggestion.mScore); |
} |
+ @Override |
public void onSuggestionOpened(SnippetArticle suggestion, int windowOpenDisposition) { |
assert mNativeSnippetsBridge != 0; |
- nativeOnSuggestionOpened(mNativeSnippetsBridge, suggestion.mGlobalPosition, |
- suggestion.mCategory, suggestion.mPosition, |
+ nativeOnSuggestionOpened(mNativeSnippetsBridge, suggestion.getGlobalRank(), |
+ suggestion.mCategory, suggestion.getPerSectionRank(), |
suggestion.mPublishTimestampMilliseconds, suggestion.mScore, windowOpenDisposition); |
} |
+ @Override |
public void onSuggestionMenuOpened(SnippetArticle suggestion) { |
assert mNativeSnippetsBridge != 0; |
- nativeOnSuggestionMenuOpened(mNativeSnippetsBridge, suggestion.mGlobalPosition, |
- suggestion.mCategory, suggestion.mPosition, |
+ nativeOnSuggestionMenuOpened(mNativeSnippetsBridge, suggestion.getGlobalRank(), |
+ suggestion.mCategory, suggestion.getPerSectionRank(), |
suggestion.mPublishTimestampMilliseconds, suggestion.mScore); |
} |
- public void onMoreButtonShown(int category, int position) { |
+ @Override |
+ public void onMoreButtonShown(ActionItem actionItem) { |
assert mNativeSnippetsBridge != 0; |
- nativeOnMoreButtonShown(mNativeSnippetsBridge, category, position); |
+ nativeOnMoreButtonShown( |
+ mNativeSnippetsBridge, actionItem.getCategory(), actionItem.getPerSectionRank()); |
} |
- public void onMoreButtonClicked(int category, int position) { |
+ @Override |
+ public void onMoreButtonClicked(ActionItem actionItem) { |
assert mNativeSnippetsBridge != 0; |
- nativeOnMoreButtonClicked(mNativeSnippetsBridge, category, position); |
+ @CategoryInt |
+ int category = actionItem.getCategory(); |
+ nativeOnMoreButtonClicked(mNativeSnippetsBridge, category, actionItem.getPerSectionRank()); |
+ 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,16 +221,8 @@ 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; |
} |
@@ -233,7 +253,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); |
} |