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

Side by Side Diff: chrome/browser/android/ntp/ntp_snippets_bridge.cc

Issue 2346263002: Extending the UserClassifier to actually support classification. (Closed)
Patch Set: Comments of Tim and Marc Created 4 years, 3 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 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h" 5 #include "chrome/browser/android/ntp/ntp_snippets_bridge.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 8
9 #include "base/android/callback_android.h" 9 #include "base/android/callback_android.h"
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 JavaIntArrayToIntVector(env, jsuggestions_per_category, 261 JavaIntArrayToIntVector(env, jsuggestions_per_category,
262 &suggestions_per_category_int); 262 &suggestions_per_category_int);
263 DCHECK_EQ(categories_int.size(), suggestions_per_category_int.size()); 263 DCHECK_EQ(categories_int.size(), suggestions_per_category_int.size());
264 std::vector<std::pair<Category, int>> suggestions_per_category; 264 std::vector<std::pair<Category, int>> suggestions_per_category;
265 for (size_t i = 0; i < categories_int.size(); i++) { 265 for (size_t i = 0; i < categories_int.size(); i++) {
266 suggestions_per_category.push_back( 266 suggestions_per_category.push_back(
267 std::make_pair(CategoryFromIDValue(categories_int[i]), 267 std::make_pair(CategoryFromIDValue(categories_int[i]),
268 suggestions_per_category_int[i])); 268 suggestions_per_category_int[i]));
269 } 269 }
270 ntp_snippets::metrics::OnPageShown(suggestions_per_category); 270 ntp_snippets::metrics::OnPageShown(suggestions_per_category);
271 content_suggestions_service_->user_classifier()->OnNTPOpened(); 271 content_suggestions_service_->user_classifier()->OnEvent(
272 ntp_snippets::UserClassifier::Metric::NTP_OPENED);
Marc Treib 2016/09/20 13:26:52 misaligned
272 } 273 }
273 274
274 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, 275 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env,
275 const JavaParamRef<jobject>& obj, 276 const JavaParamRef<jobject>& obj,
276 jint global_position, 277 jint global_position,
277 jint category, 278 jint category,
278 jint category_position, 279 jint category_position,
279 jlong publish_timestamp_ms, 280 jlong publish_timestamp_ms,
280 jfloat score) { 281 jfloat score) {
281 ntp_snippets::metrics::OnSuggestionShown( 282 ntp_snippets::metrics::OnSuggestionShown(
282 global_position, CategoryFromIDValue(category), category_position, 283 global_position, CategoryFromIDValue(category), category_position,
283 TimeFromJavaTime(publish_timestamp_ms), score); 284 TimeFromJavaTime(publish_timestamp_ms), score);
284 if (global_position == 0) 285 if (global_position == 0)
285 content_suggestions_service_->user_classifier()->OnSuggestionsShown(); 286 content_suggestions_service_->user_classifier()->OnEvent(
287 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN);
286 } 288 }
287 289
288 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, 290 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env,
289 const JavaParamRef<jobject>& obj, 291 const JavaParamRef<jobject>& obj,
290 jint global_position, 292 jint global_position,
291 jint category, 293 jint category,
292 jint category_position, 294 jint category_position,
293 jlong publish_timestamp_ms, 295 jlong publish_timestamp_ms,
294 jfloat score, 296 jfloat score,
295 int windowOpenDisposition) { 297 int windowOpenDisposition) {
296 ntp_snippets::metrics::OnSuggestionOpened( 298 ntp_snippets::metrics::OnSuggestionOpened(
297 global_position, CategoryFromIDValue(category), category_position, 299 global_position, CategoryFromIDValue(category), category_position,
298 TimeFromJavaTime(publish_timestamp_ms), score, 300 TimeFromJavaTime(publish_timestamp_ms), score,
299 static_cast<WindowOpenDisposition>(windowOpenDisposition)); 301 static_cast<WindowOpenDisposition>(windowOpenDisposition));
300 content_suggestions_service_->user_classifier()->OnSuggestionsUsed(); 302 content_suggestions_service_->user_classifier()->OnEvent(
303 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED);
301 } 304 }
302 305
303 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, 306 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env,
304 const JavaParamRef<jobject>& obj, 307 const JavaParamRef<jobject>& obj,
305 jint global_position, 308 jint global_position,
306 jint category, 309 jint category,
307 jint category_position, 310 jint category_position,
308 jlong publish_timestamp_ms, 311 jlong publish_timestamp_ms,
309 jfloat score) { 312 jfloat score) {
310 ntp_snippets::metrics::OnSuggestionMenuOpened( 313 ntp_snippets::metrics::OnSuggestionMenuOpened(
311 global_position, CategoryFromIDValue(category), category_position, 314 global_position, CategoryFromIDValue(category), category_position,
312 TimeFromJavaTime(publish_timestamp_ms), score); 315 TimeFromJavaTime(publish_timestamp_ms), score);
313 } 316 }
314 317
315 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, 318 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env,
316 const JavaParamRef<jobject>& obj, 319 const JavaParamRef<jobject>& obj,
317 jint category, 320 jint category,
318 jint position) { 321 jint position) {
319 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(category), 322 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(category),
320 position); 323 position);
321 } 324 }
322 325
323 void NTPSnippetsBridge::OnMoreButtonClicked(JNIEnv* env, 326 void NTPSnippetsBridge::OnMoreButtonClicked(JNIEnv* env,
324 const JavaParamRef<jobject>& obj, 327 const JavaParamRef<jobject>& obj,
325 jint category, 328 jint category,
326 jint position) { 329 jint position) {
327 ntp_snippets::metrics::OnMoreButtonClicked(CategoryFromIDValue(category), 330 ntp_snippets::metrics::OnMoreButtonClicked(CategoryFromIDValue(category),
328 position); 331 position);
329 content_suggestions_service_->user_classifier()->OnSuggestionsUsed(); 332 content_suggestions_service_->user_classifier()->OnEvent(
333 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED);
330 } 334 }
331 335
332 NTPSnippetsBridge::~NTPSnippetsBridge() {} 336 NTPSnippetsBridge::~NTPSnippetsBridge() {}
333 337
334 void NTPSnippetsBridge::OnNewSuggestions(Category category) { 338 void NTPSnippetsBridge::OnNewSuggestions(Category category) {
335 if (observer_.is_null()) 339 if (observer_.is_null())
336 return; 340 return;
337 341
338 JNIEnv* env = base::android::AttachCurrentThread(); 342 JNIEnv* env = base::android::AttachCurrentThread();
339 Java_SnippetsBridge_onNewSuggestions(env, observer_, 343 Java_SnippetsBridge_onNewSuggestions(env, observer_,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 382 }
379 383
380 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { 384 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) {
381 return content_suggestions_service_->category_factory()->FromIDValue(id); 385 return content_suggestions_service_->category_factory()->FromIDValue(id);
382 } 386 }
383 387
384 // static 388 // static
385 bool NTPSnippetsBridge::Register(JNIEnv* env) { 389 bool NTPSnippetsBridge::Register(JNIEnv* env) {
386 return RegisterNativesImpl(env); 390 return RegisterNativesImpl(env);
387 } 391 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698