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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsBridge.java

Issue 2618893003: 📰 Tweak the suggestion ranks for UMA to handle fetchMore (Closed)
Patch Set: rebase, address comments 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.ntp.snippets; 5 package org.chromium.chrome.browser.ntp.snippets;
6 6
7 import android.graphics.Bitmap; 7 import android.graphics.Bitmap;
8 8
9 import org.chromium.base.Callback; 9 import org.chromium.base.Callback;
10 import org.chromium.base.annotations.CalledByNative; 10 import org.chromium.base.annotations.CalledByNative;
11 import org.chromium.chrome.browser.ntp.NewTabPageUma;
12 import org.chromium.chrome.browser.ntp.cards.ActionItem;
11 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo; 13 import org.chromium.chrome.browser.ntp.cards.SuggestionsCategoryInfo;
12 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu m; 14 import org.chromium.chrome.browser.ntp.snippets.CategoryStatus.CategoryStatusEnu m;
13 import org.chromium.chrome.browser.profiles.Profile; 15 import org.chromium.chrome.browser.profiles.Profile;
16 import org.chromium.chrome.browser.suggestions.SuggestionsMetricsReporter;
17 import org.chromium.chrome.browser.suggestions.SuggestionsRanker;
14 18
15 import java.util.ArrayList; 19 import java.util.ArrayList;
16 import java.util.List; 20 import java.util.List;
17 21
18 /** 22 /**
19 * Provides access to the snippets to display on the NTP using the C++ ContentSu ggestionsService. 23 * Provides access to the snippets to display on the NTP using the C++ ContentSu ggestionsService.
20 */ 24 */
21 public class SnippetsBridge implements SuggestionsSource { 25 public class SnippetsBridge implements SuggestionsSource, SuggestionsMetricsRepo rter {
22 private static final String TAG = "SnippetsBridge"; 26 private static final String TAG = "SnippetsBridge";
23 27
24 private long mNativeSnippetsBridge; 28 private long mNativeSnippetsBridge;
25 private SuggestionsSource.Observer mObserver; 29 private SuggestionsSource.Observer mObserver;
30 private SuggestionsRanker mSuggestionsRanker;
26 31
27 public static boolean isCategoryStatusAvailable(@CategoryStatusEnum int stat us) { 32 public static boolean isCategoryStatusAvailable(@CategoryStatusEnum int stat us) {
28 // Note: This code is duplicated in content_suggestions_category_status. cc. 33 // Note: This code is duplicated in content_suggestions_category_status. cc.
29 return status == CategoryStatus.AVAILABLE_LOADING || status == CategoryS tatus.AVAILABLE; 34 return status == CategoryStatus.AVAILABLE_LOADING || status == CategoryS tatus.AVAILABLE;
30 } 35 }
31 36
32 /** Returns whether the category is considered "enabled", and can show conte nt suggestions. */ 37 /** Returns whether the category is considered "enabled", and can show conte nt suggestions. */
33 public static boolean isCategoryEnabled(@CategoryStatusEnum int status) { 38 public static boolean isCategoryEnabled(@CategoryStatusEnum int status) {
34 switch (status) { 39 switch (status) {
35 case CategoryStatus.INITIALIZING: 40 case CategoryStatus.INITIALIZING:
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 @Override 117 @Override
113 public void fetchSuggestionImage(SnippetArticle suggestion, Callback<Bitmap> callback) { 118 public void fetchSuggestionImage(SnippetArticle suggestion, Callback<Bitmap> callback) {
114 assert mNativeSnippetsBridge != 0; 119 assert mNativeSnippetsBridge != 0;
115 nativeFetchSuggestionImage(mNativeSnippetsBridge, suggestion.mCategory, 120 nativeFetchSuggestionImage(mNativeSnippetsBridge, suggestion.mCategory,
116 suggestion.mIdWithinCategory, callback); 121 suggestion.mIdWithinCategory, callback);
117 } 122 }
118 123
119 @Override 124 @Override
120 public void dismissSuggestion(SnippetArticle suggestion) { 125 public void dismissSuggestion(SnippetArticle suggestion) {
121 assert mNativeSnippetsBridge != 0; 126 assert mNativeSnippetsBridge != 0;
122 nativeDismissSuggestion(mNativeSnippetsBridge, suggestion.mUrl, suggesti on.mGlobalPosition, 127 nativeDismissSuggestion(mNativeSnippetsBridge, suggestion.mUrl, suggesti on.getGlobalRank(),
123 suggestion.mCategory, suggestion.mPosition, suggestion.mIdWithin Category); 128 suggestion.mCategory, suggestion.getPerSectionRank(), suggestion .mIdWithinCategory);
124 } 129 }
125 130
126 @Override 131 @Override
127 public void dismissCategory(@CategoryInt int category) { 132 public void dismissCategory(@CategoryInt int category) {
128 assert mNativeSnippetsBridge != 0; 133 assert mNativeSnippetsBridge != 0;
129 nativeDismissCategory(mNativeSnippetsBridge, category); 134 nativeDismissCategory(mNativeSnippetsBridge, category);
130 } 135 }
131 136
132 @Override 137 @Override
133 public void restoreDismissedCategories() { 138 public void restoreDismissedCategories() {
134 assert mNativeSnippetsBridge != 0; 139 assert mNativeSnippetsBridge != 0;
135 nativeRestoreDismissedCategories(mNativeSnippetsBridge); 140 nativeRestoreDismissedCategories(mNativeSnippetsBridge);
136 } 141 }
137 142
143 @Override
138 public void onPageShown(int[] categories, int[] suggestionsPerCategory) { 144 public void onPageShown(int[] categories, int[] suggestionsPerCategory) {
139 assert mNativeSnippetsBridge != 0; 145 assert mNativeSnippetsBridge != 0;
140 nativeOnPageShown(mNativeSnippetsBridge, categories, suggestionsPerCateg ory); 146 nativeOnPageShown(mNativeSnippetsBridge, categories, suggestionsPerCateg ory);
141 } 147 }
142 148
149 @Override
143 public void onSuggestionShown(SnippetArticle suggestion) { 150 public void onSuggestionShown(SnippetArticle suggestion) {
144 assert mNativeSnippetsBridge != 0; 151 assert mNativeSnippetsBridge != 0;
145 nativeOnSuggestionShown(mNativeSnippetsBridge, suggestion.mGlobalPositio n, 152 nativeOnSuggestionShown(mNativeSnippetsBridge, suggestion.getGlobalRank( ),
146 suggestion.mCategory, suggestion.mPosition, 153 suggestion.mCategory, suggestion.getPerSectionRank(),
147 suggestion.mPublishTimestampMilliseconds, suggestion.mScore); 154 suggestion.mPublishTimestampMilliseconds, suggestion.mScore);
148 } 155 }
149 156
150 public void onSuggestionOpened( 157 @Override
151 SnippetArticle suggestion, int categoryIndex, int windowOpenDisposit ion) { 158 public void onSuggestionOpened(SnippetArticle suggestion, int windowOpenDisp osition) {
152 assert mNativeSnippetsBridge != 0; 159 assert mNativeSnippetsBridge != 0;
153 nativeOnSuggestionOpened(mNativeSnippetsBridge, suggestion.mGlobalPositi on, 160 int categoryIndex = mSuggestionsRanker.getCategoryRank(suggestion.mCateg ory);
154 suggestion.mCategory, categoryIndex, suggestion.mPosition, 161 nativeOnSuggestionOpened(mNativeSnippetsBridge, suggestion.getGlobalRank (),
162 suggestion.mCategory, categoryIndex, suggestion.getPerSectionRan k(),
155 suggestion.mPublishTimestampMilliseconds, suggestion.mScore, win dowOpenDisposition); 163 suggestion.mPublishTimestampMilliseconds, suggestion.mScore, win dowOpenDisposition);
156 } 164 }
157 165
166 @Override
158 public void onSuggestionMenuOpened(SnippetArticle suggestion) { 167 public void onSuggestionMenuOpened(SnippetArticle suggestion) {
159 assert mNativeSnippetsBridge != 0; 168 assert mNativeSnippetsBridge != 0;
160 nativeOnSuggestionMenuOpened(mNativeSnippetsBridge, suggestion.mGlobalPo sition, 169 nativeOnSuggestionMenuOpened(mNativeSnippetsBridge, suggestion.getGlobal Rank(),
161 suggestion.mCategory, suggestion.mPosition, 170 suggestion.mCategory, suggestion.getPerSectionRank(),
162 suggestion.mPublishTimestampMilliseconds, suggestion.mScore); 171 suggestion.mPublishTimestampMilliseconds, suggestion.mScore);
163 } 172 }
164 173
165 public void onMoreButtonShown(int category, int position) { 174 @Override
175 public void onMoreButtonShown(ActionItem actionItem) {
166 assert mNativeSnippetsBridge != 0; 176 assert mNativeSnippetsBridge != 0;
167 nativeOnMoreButtonShown(mNativeSnippetsBridge, category, position); 177 nativeOnMoreButtonShown(
178 mNativeSnippetsBridge, actionItem.getCategory(), actionItem.getP erSectionRank());
168 } 179 }
169 180
170 public void onMoreButtonClicked(int category, int position) { 181 @Override
182 public void onMoreButtonClicked(ActionItem actionItem) {
171 assert mNativeSnippetsBridge != 0; 183 assert mNativeSnippetsBridge != 0;
172 nativeOnMoreButtonClicked(mNativeSnippetsBridge, category, position); 184 @CategoryInt
185 int category = actionItem.getCategory();
186 nativeOnMoreButtonClicked(mNativeSnippetsBridge, category, actionItem.ge tPerSectionRank());
187 switch (category) {
188 case KnownCategories.BOOKMARKS:
189 NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_BOOKMARKS _MANAGER);
190 break;
191 // MORE button in both categories leads to the recent tabs manager
192 case KnownCategories.FOREIGN_TABS:
193 case KnownCategories.RECENT_TABS:
194 NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_RECENT_TA BS_MANAGER);
195 break;
196 case KnownCategories.DOWNLOADS:
197 NewTabPageUma.recordAction(NewTabPageUma.ACTION_OPENED_DOWNLOADS _MANAGER);
198 break;
199 default:
200 // No action associated
201 break;
202 }
173 } 203 }
174 204
175 /** 205 /**
176 * Notifies the scheduler to adjust the plan due to a newly opened NTP. 206 * Notifies the scheduler to adjust the plan due to a newly opened NTP.
177 */ 207 */
178 public void onNtpInitialized() { 208 public void onNtpInitialized() {
179 assert mNativeSnippetsBridge != 0; 209 assert mNativeSnippetsBridge != 0;
180 nativeOnNTPInitialized(mNativeSnippetsBridge); 210 nativeOnNTPInitialized(mNativeSnippetsBridge);
181 } 211 }
182 212
183 public static void notifySchedulerAboutWarmResume() { 213 public static void notifySchedulerAboutWarmResume() {
184 SnippetsBridge snippetsBridge = new SnippetsBridge(Profile.getLastUsedPr ofile()); 214 SnippetsBridge snippetsBridge = new SnippetsBridge(Profile.getLastUsedPr ofile());
185 snippetsBridge.onActivityWarmResumed(); 215 snippetsBridge.onActivityWarmResumed();
186 } 216 }
187 217
188 public static void notifySchedulerAboutColdStart() { 218 public static void notifySchedulerAboutColdStart() {
189 SnippetsBridge snippetsBridge = new SnippetsBridge(Profile.getLastUsedPr ofile()); 219 SnippetsBridge snippetsBridge = new SnippetsBridge(Profile.getLastUsedPr ofile());
190 snippetsBridge.onColdStart(); 220 snippetsBridge.onColdStart();
191 } 221 }
192 222
193 public static void onSuggestionTargetVisited(int category, long visitTimeMs) { 223 public static void onSuggestionTargetVisited(int category, long visitTimeMs) {
194 nativeOnSuggestionTargetVisited(category, visitTimeMs); 224 nativeOnSuggestionTargetVisited(category, visitTimeMs);
195 } 225 }
196 226
197 /**
198 * Sets the recipient for the fetched snippets.
199 *
200 * An observer needs to be set before the native code attempts to transmit s nippets them to
201 * java. Upon registration, the observer will be notified of already fetched snippets.
202 *
203 * @param observer object to notify when snippets are received.
204 */
205 @Override 227 @Override
206 public void setObserver(SuggestionsSource.Observer observer) { 228 public void setObserver(Observer observer) {
207 assert observer != null; 229 assert observer != null;
208 mObserver = observer; 230 mObserver = observer;
209 } 231 }
210 232
211 @Override 233 @Override
234 public void setRanker(SuggestionsRanker suggestionsRanker) {
235 assert suggestionsRanker != null;
236 mSuggestionsRanker = suggestionsRanker;
237 }
238
239 @Override
212 public void fetchSuggestions(@CategoryInt int category, String[] displayedSu ggestionIds) { 240 public void fetchSuggestions(@CategoryInt int category, String[] displayedSu ggestionIds) {
213 nativeFetch(mNativeSnippetsBridge, category, displayedSuggestionIds); 241 nativeFetch(mNativeSnippetsBridge, category, displayedSuggestionIds);
214 } 242 }
215 243
216 private void onActivityWarmResumed() { 244 private void onActivityWarmResumed() {
217 assert mNativeSnippetsBridge != 0; 245 assert mNativeSnippetsBridge != 0;
218 nativeOnActivityWarmResumed(mNativeSnippetsBridge); 246 nativeOnActivityWarmResumed(mNativeSnippetsBridge);
219 } 247 }
220 248
221 private void onColdStart() { 249 private void onColdStart() {
222 assert mNativeSnippetsBridge != 0; 250 assert mNativeSnippetsBridge != 0;
223 nativeOnColdStart(mNativeSnippetsBridge); 251 nativeOnColdStart(mNativeSnippetsBridge);
224 } 252 }
225 253
226 @CalledByNative 254 @CalledByNative
227 private static List<SnippetArticle> createSuggestionList() { 255 private static List<SnippetArticle> createSuggestionList() {
228 return new ArrayList<>(); 256 return new ArrayList<>();
229 } 257 }
230 258
231 @CalledByNative 259 @CalledByNative
232 private static SnippetArticle addSuggestion(List<SnippetArticle> suggestions , int category, 260 private static SnippetArticle addSuggestion(List<SnippetArticle> suggestions , int category,
233 String id, String title, String publisher, String previewText, Strin g url, 261 String id, String title, String publisher, String previewText, Strin g url,
234 long timestamp, float score) { 262 long timestamp, float score) {
235 int position = suggestions.size(); 263 int position = suggestions.size();
236 suggestions.add(new SnippetArticle( 264 suggestions.add(new SnippetArticle(
237 category, id, title, publisher, previewText, url, timestamp, sco re, position)); 265 category, id, title, publisher, previewText, url, timestamp, sco re));
238 return suggestions.get(position); 266 return suggestions.get(position);
239 } 267 }
240 268
241 @CalledByNative 269 @CalledByNative
242 private static void setAssetDownloadDataForSuggestion( 270 private static void setAssetDownloadDataForSuggestion(
243 SnippetArticle suggestion, String filePath, String mimeType) { 271 SnippetArticle suggestion, String filePath, String mimeType) {
244 suggestion.setAssetDownloadData(filePath, mimeType); 272 suggestion.setAssetDownloadData(filePath, mimeType);
245 } 273 }
246 274
247 @CalledByNative 275 @CalledByNative
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 float score); 349 float score);
322 private native void nativeOnMoreButtonShown( 350 private native void nativeOnMoreButtonShown(
323 long nativeNTPSnippetsBridge, int category, int position); 351 long nativeNTPSnippetsBridge, int category, int position);
324 private native void nativeOnMoreButtonClicked( 352 private native void nativeOnMoreButtonClicked(
325 long nativeNTPSnippetsBridge, int category, int position); 353 long nativeNTPSnippetsBridge, int category, int position);
326 private native void nativeOnActivityWarmResumed(long nativeNTPSnippetsBridge ); 354 private native void nativeOnActivityWarmResumed(long nativeNTPSnippetsBridge );
327 private native void nativeOnColdStart(long nativeNTPSnippetsBridge); 355 private native void nativeOnColdStart(long nativeNTPSnippetsBridge);
328 private static native void nativeOnSuggestionTargetVisited(int category, lon g visitTimeMs); 356 private static native void nativeOnSuggestionTargetVisited(int category, lon g visitTimeMs);
329 private static native void nativeOnNTPInitialized(long nativeNTPSnippetsBrid ge); 357 private static native void nativeOnNTPInitialized(long nativeNTPSnippetsBrid ge);
330 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698