| 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 | 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 JavaIntArrayToIntVector(env, jsuggestions_per_category, | 237 JavaIntArrayToIntVector(env, jsuggestions_per_category, |
| 238 &suggestions_per_category_int); | 238 &suggestions_per_category_int); |
| 239 DCHECK_EQ(categories_int.size(), suggestions_per_category_int.size()); | 239 DCHECK_EQ(categories_int.size(), suggestions_per_category_int.size()); |
| 240 std::vector<std::pair<Category, int>> suggestions_per_category; | 240 std::vector<std::pair<Category, int>> suggestions_per_category; |
| 241 for (size_t i = 0; i < categories_int.size(); i++) { | 241 for (size_t i = 0; i < categories_int.size(); i++) { |
| 242 suggestions_per_category.push_back( | 242 suggestions_per_category.push_back( |
| 243 std::make_pair(CategoryFromIDValue(categories_int[i]), | 243 std::make_pair(CategoryFromIDValue(categories_int[i]), |
| 244 suggestions_per_category_int[i])); | 244 suggestions_per_category_int[i])); |
| 245 } | 245 } |
| 246 ntp_snippets::metrics::OnPageShown(suggestions_per_category); | 246 ntp_snippets::metrics::OnPageShown(suggestions_per_category); |
| 247 content_suggestions_service_->user_classifier()->OnNTPOpened(); |
| 247 } | 248 } |
| 248 | 249 |
| 249 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, | 250 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, |
| 250 const JavaParamRef<jobject>& obj, | 251 const JavaParamRef<jobject>& obj, |
| 251 jint global_position, | 252 jint global_position, |
| 252 jint category, | 253 jint category, |
| 253 jint category_position, | 254 jint category_position, |
| 254 jlong publish_timestamp_ms, | 255 jlong publish_timestamp_ms, |
| 255 jfloat score) { | 256 jfloat score) { |
| 256 ntp_snippets::metrics::OnSuggestionShown( | 257 ntp_snippets::metrics::OnSuggestionShown( |
| 257 global_position, CategoryFromIDValue(category), category_position, | 258 global_position, CategoryFromIDValue(category), category_position, |
| 258 TimeFromJavaTime(publish_timestamp_ms), score); | 259 TimeFromJavaTime(publish_timestamp_ms), score); |
| 260 if (global_position == 0) |
| 261 content_suggestions_service_->user_classifier()->OnSuggestionsShown(); |
| 259 } | 262 } |
| 260 | 263 |
| 261 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, | 264 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, |
| 262 const JavaParamRef<jobject>& obj, | 265 const JavaParamRef<jobject>& obj, |
| 263 jint global_position, | 266 jint global_position, |
| 264 jint category, | 267 jint category, |
| 265 jint category_position, | 268 jint category_position, |
| 266 jlong publish_timestamp_ms, | 269 jlong publish_timestamp_ms, |
| 267 jfloat score, | 270 jfloat score, |
| 268 int windowOpenDisposition) { | 271 int windowOpenDisposition) { |
| 269 ntp_snippets::metrics::OnSuggestionOpened( | 272 ntp_snippets::metrics::OnSuggestionOpened( |
| 270 global_position, CategoryFromIDValue(category), category_position, | 273 global_position, CategoryFromIDValue(category), category_position, |
| 271 TimeFromJavaTime(publish_timestamp_ms), score, | 274 TimeFromJavaTime(publish_timestamp_ms), score, |
| 272 static_cast<WindowOpenDisposition>(windowOpenDisposition)); | 275 static_cast<WindowOpenDisposition>(windowOpenDisposition)); |
| 276 content_suggestions_service_->user_classifier()->OnSuggestionsUsed(); |
| 273 } | 277 } |
| 274 | 278 |
| 275 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, | 279 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, |
| 276 const JavaParamRef<jobject>& obj, | 280 const JavaParamRef<jobject>& obj, |
| 277 jint global_position, | 281 jint global_position, |
| 278 jint category, | 282 jint category, |
| 279 jint category_position, | 283 jint category_position, |
| 280 jlong publish_timestamp_ms, | 284 jlong publish_timestamp_ms, |
| 281 jfloat score) { | 285 jfloat score) { |
| 282 ntp_snippets::metrics::OnSuggestionMenuOpened( | 286 ntp_snippets::metrics::OnSuggestionMenuOpened( |
| 283 global_position, CategoryFromIDValue(category), category_position, | 287 global_position, CategoryFromIDValue(category), category_position, |
| 284 TimeFromJavaTime(publish_timestamp_ms), score); | 288 TimeFromJavaTime(publish_timestamp_ms), score); |
| 285 } | 289 } |
| 286 | 290 |
| 287 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, | 291 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, |
| 288 const JavaParamRef<jobject>& obj, | 292 const JavaParamRef<jobject>& obj, |
| 289 jint category, | 293 jint category, |
| 290 jint position) { | 294 jint position) { |
| 291 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(category), | 295 ntp_snippets::metrics::OnMoreButtonShown(CategoryFromIDValue(category), |
| 292 position); | 296 position); |
| 293 } | 297 } |
| 294 | 298 |
| 295 void NTPSnippetsBridge::OnMoreButtonClicked(JNIEnv* env, | 299 void NTPSnippetsBridge::OnMoreButtonClicked(JNIEnv* env, |
| 296 const JavaParamRef<jobject>& obj, | 300 const JavaParamRef<jobject>& obj, |
| 297 jint category, | 301 jint category, |
| 298 jint position) { | 302 jint position) { |
| 299 ntp_snippets::metrics::OnMoreButtonClicked(CategoryFromIDValue(category), | 303 ntp_snippets::metrics::OnMoreButtonClicked(CategoryFromIDValue(category), |
| 300 position); | 304 position); |
| 305 content_suggestions_service_->user_classifier()->OnSuggestionsUsed(); |
| 301 } | 306 } |
| 302 | 307 |
| 303 NTPSnippetsBridge::~NTPSnippetsBridge() {} | 308 NTPSnippetsBridge::~NTPSnippetsBridge() {} |
| 304 | 309 |
| 305 void NTPSnippetsBridge::OnNewSuggestions(Category category) { | 310 void NTPSnippetsBridge::OnNewSuggestions(Category category) { |
| 306 if (observer_.is_null()) | 311 if (observer_.is_null()) |
| 307 return; | 312 return; |
| 308 | 313 |
| 309 JNIEnv* env = base::android::AttachCurrentThread(); | 314 JNIEnv* env = base::android::AttachCurrentThread(); |
| 310 Java_SnippetsBridge_onNewSuggestions(env, observer_, | 315 Java_SnippetsBridge_onNewSuggestions(env, observer_, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 } | 355 } |
| 351 | 356 |
| 352 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { | 357 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { |
| 353 return content_suggestions_service_->category_factory()->FromIDValue(id); | 358 return content_suggestions_service_->category_factory()->FromIDValue(id); |
| 354 } | 359 } |
| 355 | 360 |
| 356 // static | 361 // static |
| 357 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 362 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 358 return RegisterNativesImpl(env); | 363 return RegisterNativesImpl(env); |
| 359 } | 364 } |
| OLD | NEW |