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

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

Issue 2346263002: Extending the UserClassifier to actually support classification. (Closed)
Patch Set: Bernhard's comments 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
« no previous file with comments | « no previous file | chrome/browser/resources/snippets_internals.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
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);
288 }
286 } 289 }
287 290
288 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, 291 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env,
289 const JavaParamRef<jobject>& obj, 292 const JavaParamRef<jobject>& obj,
290 jint global_position, 293 jint global_position,
291 jint category, 294 jint category,
292 jint category_position, 295 jint category_position,
293 jlong publish_timestamp_ms, 296 jlong publish_timestamp_ms,
294 jfloat score, 297 jfloat score,
295 int windowOpenDisposition) { 298 int windowOpenDisposition) {
296 ntp_snippets::metrics::OnSuggestionOpened( 299 ntp_snippets::metrics::OnSuggestionOpened(
297 global_position, CategoryFromIDValue(category), category_position, 300 global_position, CategoryFromIDValue(category), category_position,
298 TimeFromJavaTime(publish_timestamp_ms), score, 301 TimeFromJavaTime(publish_timestamp_ms), score,
299 static_cast<WindowOpenDisposition>(windowOpenDisposition)); 302 static_cast<WindowOpenDisposition>(windowOpenDisposition));
300 content_suggestions_service_->user_classifier()->OnSuggestionsUsed(); 303 content_suggestions_service_->user_classifier()->OnEvent(
304 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED);
301 } 305 }
302 306
303 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, 307 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env,
304 const JavaParamRef<jobject>& obj, 308 const JavaParamRef<jobject>& obj,
305 jint global_position, 309 jint global_position,
306 jint category, 310 jint category,
307 jint category_position, 311 jint category_position,
308 jlong publish_timestamp_ms, 312 jlong publish_timestamp_ms,
309 jfloat score) { 313 jfloat score) {
310 ntp_snippets::metrics::OnSuggestionMenuOpened( 314 ntp_snippets::metrics::OnSuggestionMenuOpened(
311 global_position, CategoryFromIDValue(category), category_position, 315 global_position, CategoryFromIDValue(category), category_position,
312 TimeFromJavaTime(publish_timestamp_ms), score); 316 TimeFromJavaTime(publish_timestamp_ms), score);
313 } 317 }
314 318
315 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, 319 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env,
316 const JavaParamRef<jobject>& obj, 320 const JavaParamRef<jobject>& obj,
317 jint category, 321 jint category,
318 jint position) { 322 jint position) {
319 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(category), 323 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(category),
320 position); 324 position);
321 } 325 }
322 326
323 void NTPSnippetsBridge::OnMoreButtonClicked(JNIEnv* env, 327 void NTPSnippetsBridge::OnMoreButtonClicked(JNIEnv* env,
324 const JavaParamRef<jobject>& obj, 328 const JavaParamRef<jobject>& obj,
325 jint category, 329 jint category,
326 jint position) { 330 jint position) {
327 ntp_snippets::metrics::OnMoreButtonClicked(CategoryFromIDValue(category), 331 ntp_snippets::metrics::OnMoreButtonClicked(CategoryFromIDValue(category),
328 position); 332 position);
329 content_suggestions_service_->user_classifier()->OnSuggestionsUsed(); 333 content_suggestions_service_->user_classifier()->OnEvent(
334 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED);
330 } 335 }
331 336
332 NTPSnippetsBridge::~NTPSnippetsBridge() {} 337 NTPSnippetsBridge::~NTPSnippetsBridge() {}
333 338
334 void NTPSnippetsBridge::OnNewSuggestions(Category category) { 339 void NTPSnippetsBridge::OnNewSuggestions(Category category) {
335 if (observer_.is_null()) 340 if (observer_.is_null())
336 return; 341 return;
337 342
338 JNIEnv* env = base::android::AttachCurrentThread(); 343 JNIEnv* env = base::android::AttachCurrentThread();
339 Java_SnippetsBridge_onNewSuggestions(env, observer_, 344 Java_SnippetsBridge_onNewSuggestions(env, observer_,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 383 }
379 384
380 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { 385 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) {
381 return content_suggestions_service_->category_factory()->FromIDValue(id); 386 return content_suggestions_service_->category_factory()->FromIDValue(id);
382 } 387 }
383 388
384 // static 389 // static
385 bool NTPSnippetsBridge::Register(JNIEnv* env) { 390 bool NTPSnippetsBridge::Register(JNIEnv* env) {
386 return RegisterNativesImpl(env); 391 return RegisterNativesImpl(env);
387 } 392 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/snippets_internals.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698