| 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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 const base::android::JavaParamRef<jobject>& obj) { | 255 const base::android::JavaParamRef<jobject>& obj) { |
| 256 content_suggestions_service_->ReloadSuggestions(); | 256 content_suggestions_service_->ReloadSuggestions(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 void NTPSnippetsBridge::DismissSuggestion( | 259 void NTPSnippetsBridge::DismissSuggestion( |
| 260 JNIEnv* env, | 260 JNIEnv* env, |
| 261 const JavaParamRef<jobject>& obj, | 261 const JavaParamRef<jobject>& obj, |
| 262 const JavaParamRef<jstring>& jurl, | 262 const JavaParamRef<jstring>& jurl, |
| 263 jint global_position, | 263 jint global_position, |
| 264 jint j_category_id, | 264 jint j_category_id, |
| 265 jint category_position, | 265 jint position_in_category, |
| 266 const JavaParamRef<jstring>& id_within_category) { | 266 const JavaParamRef<jstring>& id_within_category) { |
| 267 Category category = Category::FromIDValue(j_category_id); | 267 Category category = Category::FromIDValue(j_category_id); |
| 268 | 268 |
| 269 content_suggestions_service_->DismissSuggestion(ContentSuggestion::ID( | 269 content_suggestions_service_->DismissSuggestion(ContentSuggestion::ID( |
| 270 category, ConvertJavaStringToUTF8(env, id_within_category))); | 270 category, ConvertJavaStringToUTF8(env, id_within_category))); |
| 271 | 271 |
| 272 history_service_->QueryURL( | 272 history_service_->QueryURL( |
| 273 GURL(ConvertJavaStringToUTF8(env, jurl)), /*want_visits=*/false, | 273 GURL(ConvertJavaStringToUTF8(env, jurl)), /*want_visits=*/false, |
| 274 base::Bind( | 274 base::Bind( |
| 275 [](int global_position, Category category, int category_position, | 275 [](int global_position, Category category, int position_in_category, |
| 276 bool success, const history::URLRow& row, | 276 bool success, const history::URLRow& row, |
| 277 const history::VisitVector& visit_vector) { | 277 const history::VisitVector& visit_vector) { |
| 278 bool visited = success && row.visit_count() != 0; | 278 bool visited = success && row.visit_count() != 0; |
| 279 ntp_snippets::metrics::OnSuggestionDismissed( | 279 ntp_snippets::metrics::OnSuggestionDismissed( |
| 280 global_position, category, category_position, visited); | 280 global_position, category, position_in_category, visited); |
| 281 }, | 281 }, |
| 282 global_position, category, category_position), | 282 global_position, category, position_in_category), |
| 283 &tracker_); | 283 &tracker_); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void NTPSnippetsBridge::DismissCategory(JNIEnv* env, | 286 void NTPSnippetsBridge::DismissCategory(JNIEnv* env, |
| 287 const JavaParamRef<jobject>& obj, | 287 const JavaParamRef<jobject>& obj, |
| 288 jint j_category_id) { | 288 jint j_category_id) { |
| 289 Category category = Category::FromIDValue(j_category_id); | 289 Category category = Category::FromIDValue(j_category_id); |
| 290 | 290 |
| 291 content_suggestions_service_->DismissCategory(category); | 291 content_suggestions_service_->DismissCategory(category); |
| 292 | 292 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 318 } | 318 } |
| 319 ntp_snippets::metrics::OnPageShown(suggestions_per_category); | 319 ntp_snippets::metrics::OnPageShown(suggestions_per_category); |
| 320 content_suggestions_service_->user_classifier()->OnEvent( | 320 content_suggestions_service_->user_classifier()->OnEvent( |
| 321 ntp_snippets::UserClassifier::Metric::NTP_OPENED); | 321 ntp_snippets::UserClassifier::Metric::NTP_OPENED); |
| 322 } | 322 } |
| 323 | 323 |
| 324 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, | 324 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, |
| 325 const JavaParamRef<jobject>& obj, | 325 const JavaParamRef<jobject>& obj, |
| 326 jint global_position, | 326 jint global_position, |
| 327 jint j_category_id, | 327 jint j_category_id, |
| 328 jint category_position, | 328 jint position_in_category, |
| 329 jlong publish_timestamp_ms, | 329 jlong publish_timestamp_ms, |
| 330 jfloat score) { | 330 jfloat score) { |
| 331 PrefService* pref_service = ProfileManager::GetLastUsedProfile()->GetPrefs(); | 331 PrefService* pref_service = ProfileManager::GetLastUsedProfile()->GetPrefs(); |
| 332 base::Time last_background_fetch_time = | 332 base::Time last_background_fetch_time = |
| 333 base::Time::FromInternalValue(pref_service->GetInt64( | 333 base::Time::FromInternalValue(pref_service->GetInt64( |
| 334 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); | 334 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); |
| 335 | 335 |
| 336 ntp_snippets::metrics::OnSuggestionShown( | 336 ntp_snippets::metrics::OnSuggestionShown( |
| 337 global_position, Category::FromIDValue(j_category_id), category_position, | 337 global_position, Category::FromIDValue(j_category_id), |
| 338 base::Time::FromJavaTime(publish_timestamp_ms), | 338 position_in_category, base::Time::FromJavaTime(publish_timestamp_ms), |
| 339 last_background_fetch_time, score); | 339 last_background_fetch_time, score); |
| 340 if (global_position == 0) { | 340 if (global_position == 0) { |
| 341 content_suggestions_service_->user_classifier()->OnEvent( | 341 content_suggestions_service_->user_classifier()->OnEvent( |
| 342 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); | 342 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); |
| 343 } | 343 } |
| 344 } | 344 } |
| 345 | 345 |
| 346 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, | 346 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, |
| 347 const JavaParamRef<jobject>& obj, | 347 const JavaParamRef<jobject>& obj, |
| 348 jint global_position, | 348 jint global_position, |
| 349 jint j_category_id, | 349 jint j_category_id, |
| 350 jint category_rank, | 350 jint category_rank, |
| 351 jint category_position, | 351 jint position_in_category, |
| 352 jlong publish_timestamp_ms, | 352 jlong publish_timestamp_ms, |
| 353 jfloat score, | 353 jfloat score, |
| 354 int windowOpenDisposition) { | 354 int windowOpenDisposition) { |
| 355 DCHECK_GT(category_rank, 0); | 355 DCHECK_GT(category_rank, 0); |
| 356 const Category category = Category::FromIDValue(j_category_id); |
| 356 ntp_snippets::metrics::OnSuggestionOpened( | 357 ntp_snippets::metrics::OnSuggestionOpened( |
| 357 global_position, Category::FromIDValue(j_category_id), category_position, | 358 global_position, category, category_rank, position_in_category, |
| 358 base::Time::FromJavaTime(publish_timestamp_ms), score, | 359 base::Time::FromJavaTime(publish_timestamp_ms), score, |
| 359 static_cast<WindowOpenDisposition>(windowOpenDisposition)); | 360 static_cast<WindowOpenDisposition>(windowOpenDisposition)); |
| 360 // TODO(vitaliii): Add ContentSuggestionsService::OnSuggestionOpened and | 361 // TODO(vitaliii): Add ContentSuggestionsService::OnSuggestionOpened and |
| 361 // notify the ranker and the classifier there instead. Do not expose both of | 362 // notify the ranker and the classifier there instead. Do not expose both of |
| 362 // them at all. See crbug.com/674080. | 363 // them at all. See crbug.com/674080. |
| 363 content_suggestions_service_->category_ranker()->OnSuggestionOpened( | 364 content_suggestions_service_->category_ranker()->OnSuggestionOpened(category); |
| 364 Category::FromIDValue(j_category_id)); | |
| 365 content_suggestions_service_->user_classifier()->OnEvent( | 365 content_suggestions_service_->user_classifier()->OnEvent( |
| 366 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED); | 366 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_USED); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, | 369 void NTPSnippetsBridge::OnSuggestionMenuOpened(JNIEnv* env, |
| 370 const JavaParamRef<jobject>& obj, | 370 const JavaParamRef<jobject>& obj, |
| 371 jint global_position, | 371 jint global_position, |
| 372 jint j_category_id, | 372 jint j_category_id, |
| 373 jint category_position, | 373 jint position_in_category, |
| 374 jlong publish_timestamp_ms, | 374 jlong publish_timestamp_ms, |
| 375 jfloat score) { | 375 jfloat score) { |
| 376 ntp_snippets::metrics::OnSuggestionMenuOpened( | 376 ntp_snippets::metrics::OnSuggestionMenuOpened( |
| 377 global_position, Category::FromIDValue(j_category_id), category_position, | 377 global_position, Category::FromIDValue(j_category_id), |
| 378 base::Time::FromJavaTime(publish_timestamp_ms), score); | 378 position_in_category, base::Time::FromJavaTime(publish_timestamp_ms), |
| 379 score); |
| 379 } | 380 } |
| 380 | 381 |
| 381 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, | 382 void NTPSnippetsBridge::OnMoreButtonShown(JNIEnv* env, |
| 382 const JavaParamRef<jobject>& obj, | 383 const JavaParamRef<jobject>& obj, |
| 383 jint j_category_id, | 384 jint j_category_id, |
| 384 jint position) { | 385 jint position) { |
| 385 ntp_snippets::metrics::OnMoreButtonShown(Category::FromIDValue(j_category_id), | 386 ntp_snippets::metrics::OnMoreButtonShown(Category::FromIDValue(j_category_id), |
| 386 position); | 387 position); |
| 387 } | 388 } |
| 388 | 389 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 JNIEnv* env = AttachCurrentThread(); | 486 JNIEnv* env = AttachCurrentThread(); |
| 486 Java_SnippetsBridge_onMoreSuggestions( | 487 Java_SnippetsBridge_onMoreSuggestions( |
| 487 env, bridge_, category.id(), | 488 env, bridge_, category.id(), |
| 488 ToJavaSuggestionList(env, category, suggestions)); | 489 ToJavaSuggestionList(env, category, suggestions)); |
| 489 } | 490 } |
| 490 | 491 |
| 491 // static | 492 // static |
| 492 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 493 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 493 return RegisterNativesImpl(env); | 494 return RegisterNativesImpl(env); |
| 494 } | 495 } |
| OLD | NEW |