| OLD | NEW |
| 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 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 using base::android::ScopedJavaLocalRef; | 39 using base::android::ScopedJavaLocalRef; |
| 40 using base::android::ToJavaIntArray; | 40 using base::android::ToJavaIntArray; |
| 41 using ntp_snippets::Category; | 41 using ntp_snippets::Category; |
| 42 using ntp_snippets::CategoryInfo; | 42 using ntp_snippets::CategoryInfo; |
| 43 using ntp_snippets::CategoryStatus; | 43 using ntp_snippets::CategoryStatus; |
| 44 using ntp_snippets::KnownCategories; | 44 using ntp_snippets::KnownCategories; |
| 45 using ntp_snippets::ContentSuggestion; | 45 using ntp_snippets::ContentSuggestion; |
| 46 | 46 |
| 47 namespace { | 47 namespace { |
| 48 | 48 |
| 49 // TODO(treib): Move this into the Time class itself. | |
| 50 base::Time TimeFromJavaTime(jlong timestamp_ms) { | |
| 51 return base::Time::UnixEpoch() + | |
| 52 base::TimeDelta::FromMilliseconds(timestamp_ms); | |
| 53 } | |
| 54 | |
| 55 // Converts a vector of ContentSuggestions to its Java equivalent. | 49 // Converts a vector of ContentSuggestions to its Java equivalent. |
| 56 ScopedJavaLocalRef<jobject> ToJavaSuggestionList( | 50 ScopedJavaLocalRef<jobject> ToJavaSuggestionList( |
| 57 JNIEnv* env, | 51 JNIEnv* env, |
| 58 const Category& category, | 52 const Category& category, |
| 59 const std::vector<ContentSuggestion>& suggestions) { | 53 const std::vector<ContentSuggestion>& suggestions) { |
| 60 ScopedJavaLocalRef<jobject> result = | 54 ScopedJavaLocalRef<jobject> result = |
| 61 Java_SnippetsBridge_createSuggestionList(env); | 55 Java_SnippetsBridge_createSuggestionList(env); |
| 62 for (const ContentSuggestion& suggestion : suggestions) { | 56 for (const ContentSuggestion& suggestion : suggestions) { |
| 63 ScopedJavaLocalRef<jobject> java_suggestion = | 57 ScopedJavaLocalRef<jobject> java_suggestion = |
| 64 Java_SnippetsBridge_addSuggestion( | 58 Java_SnippetsBridge_addSuggestion( |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 | 345 |
| 352 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, | 346 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, |
| 353 const JavaParamRef<jobject>& obj, | 347 const JavaParamRef<jobject>& obj, |
| 354 jint global_position, | 348 jint global_position, |
| 355 jint j_category_id, | 349 jint j_category_id, |
| 356 jint category_position, | 350 jint category_position, |
| 357 jlong publish_timestamp_ms, | 351 jlong publish_timestamp_ms, |
| 358 jfloat score) { | 352 jfloat score) { |
| 359 ntp_snippets::metrics::OnSuggestionShown( | 353 ntp_snippets::metrics::OnSuggestionShown( |
| 360 global_position, CategoryFromIDValue(j_category_id), category_position, | 354 global_position, CategoryFromIDValue(j_category_id), category_position, |
| 361 TimeFromJavaTime(publish_timestamp_ms), score); | 355 base::Time::FromJavaTime(publish_timestamp_ms), score); |
| 362 if (global_position == 0) { | 356 if (global_position == 0) { |
| 363 content_suggestions_service_->user_classifier()->OnEvent( | 357 content_suggestions_service_->user_classifier()->OnEvent( |
| 364 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); | 358 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); |
| 365 } | 359 } |
| 366 } | 360 } |
| 367 | 361 |
| 368 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, | 362 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, |
| 369 const JavaParamRef<jobject>& obj, | 363 const JavaParamRef<jobject>& obj, |
| 370 jint global_position, | 364 jint global_position, |
| 371 jint j_category_id, | 365 jint j_category_id, |
| 372 jint category_position, | 366 jint category_position, |
| 373 jlong publish_timestamp_ms, | 367 jlong publish_timestamp_ms, |
| 374 jfloat score, | 368 jfloat score, |
| 375 int windowOpenDisposition) { | 369 int windowOpenDisposition) { |
| 376 ntp_snippets::metrics::OnSuggestionOpened( | 370 ntp_snippets::metrics::OnSuggestionOpened( |
| 377 global_position, CategoryFromIDValue(j_category_id), category_position, | 371 global_position, CategoryFromIDValue(j_category_id), category_position, |
| 378 TimeFromJavaTime(publish_timestamp_ms), score, | 372 base::Time::FromJavaTime(publish_timestamp_ms), score, |
| 379 static_cast<WindowOpenDisposition>(windowOpenDisposition)); | 373 static_cast<WindowOpenDisposition>(windowOpenDisposition)); |
| 380 content_suggestions_service_->user_classifier()->OnEvent( | 374 content_suggestions_service_->user_classifier()->OnEvent( |
| 381 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED); | 375 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED); |
| 382 } | 376 } |
| 383 | 377 |
| 384 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, | 378 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, |
| 385 const JavaParamRef<jobject>& obj, | 379 const JavaParamRef<jobject>& obj, |
| 386 jint global_position, | 380 jint global_position, |
| 387 jint j_category_id, | 381 jint j_category_id, |
| 388 jint category_position, | 382 jint category_position, |
| 389 jlong publish_timestamp_ms, | 383 jlong publish_timestamp_ms, |
| 390 jfloat score) { | 384 jfloat score) { |
| 391 ntp_snippets::metrics::OnSuggestionMenuOpened( | 385 ntp_snippets::metrics::OnSuggestionMenuOpened( |
| 392 global_position, CategoryFromIDValue(j_category_id), category_position, | 386 global_position, CategoryFromIDValue(j_category_id), category_position, |
| 393 TimeFromJavaTime(publish_timestamp_ms), score); | 387 base::Time::FromJavaTime(publish_timestamp_ms), score); |
| 394 } | 388 } |
| 395 | 389 |
| 396 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, | 390 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, |
| 397 const JavaParamRef<jobject>& obj, | 391 const JavaParamRef<jobject>& obj, |
| 398 jint j_category_id, | 392 jint j_category_id, |
| 399 jint position) { | 393 jint position) { |
| 400 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(j_category_id), | 394 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(j_category_id), |
| 401 position); | 395 position); |
| 402 } | 396 } |
| 403 | 397 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 } | 476 } |
| 483 | 477 |
| 484 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { | 478 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { |
| 485 return content_suggestions_service_->category_factory()->FromIDValue(id); | 479 return content_suggestions_service_->category_factory()->FromIDValue(id); |
| 486 } | 480 } |
| 487 | 481 |
| 488 // static | 482 // static |
| 489 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 483 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 490 return RegisterNativesImpl(env); | 484 return RegisterNativesImpl(env); |
| 491 } | 485 } |
| OLD | NEW |