| 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 |
| 11 #include "base/android/callback_android.h" | 11 #include "base/android/callback_android.h" |
| 12 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 13 #include "base/android/jni_array.h" | 13 #include "base/android/jni_array.h" |
| 14 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
| 18 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" | 18 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/profiles/profile_android.h" | 20 #include "chrome/browser/profiles/profile_android.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "components/history/core/browser/history_service.h" | 22 #include "components/history/core/browser/history_service.h" |
| 23 #include "components/ntp_snippets/content_suggestion.h" | 23 #include "components/ntp_snippets/content_suggestion.h" |
| 24 #include "components/ntp_snippets/content_suggestions_metrics.h" | 24 #include "components/ntp_snippets/content_suggestions_metrics.h" |
| 25 #include "components/ntp_snippets/pref_names.h" |
| 25 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" | 26 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
| 27 #include "components/prefs/pref_service.h" |
| 26 #include "jni/SnippetsBridge_jni.h" | 28 #include "jni/SnippetsBridge_jni.h" |
| 27 #include "ui/base/window_open_disposition.h" | 29 #include "ui/base/window_open_disposition.h" |
| 28 #include "ui/gfx/android/java_bitmap.h" | 30 #include "ui/gfx/android/java_bitmap.h" |
| 29 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
| 30 | 32 |
| 31 using base::android::AttachCurrentThread; | 33 using base::android::AttachCurrentThread; |
| 32 using base::android::ConvertJavaStringToUTF8; | 34 using base::android::ConvertJavaStringToUTF8; |
| 33 using base::android::ConvertUTF8ToJavaString; | 35 using base::android::ConvertUTF8ToJavaString; |
| 34 using base::android::ConvertUTF16ToJavaString; | 36 using base::android::ConvertUTF16ToJavaString; |
| 35 using base::android::JavaIntArrayToIntVector; | 37 using base::android::JavaIntArrayToIntVector; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 ntp_snippets::UserClassifier::Metric::NTP_OPENED); | 345 ntp_snippets::UserClassifier::Metric::NTP_OPENED); |
| 344 } | 346 } |
| 345 | 347 |
| 346 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, | 348 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, |
| 347 const JavaParamRef<jobject>& obj, | 349 const JavaParamRef<jobject>& obj, |
| 348 jint global_position, | 350 jint global_position, |
| 349 jint j_category_id, | 351 jint j_category_id, |
| 350 jint category_position, | 352 jint category_position, |
| 351 jlong publish_timestamp_ms, | 353 jlong publish_timestamp_ms, |
| 352 jfloat score) { | 354 jfloat score) { |
| 355 PrefService* pref_service = ProfileManager::GetLastUsedProfile()->GetPrefs(); |
| 356 base::Time last_background_fetch_time = |
| 357 base::Time::FromInternalValue(pref_service->GetInt64( |
| 358 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); |
| 359 |
| 353 ntp_snippets::metrics::OnSuggestionShown( | 360 ntp_snippets::metrics::OnSuggestionShown( |
| 354 global_position, CategoryFromIDValue(j_category_id), category_position, | 361 global_position, CategoryFromIDValue(j_category_id), category_position, |
| 355 base::Time::FromJavaTime(publish_timestamp_ms), score); | 362 base::Time::FromJavaTime(publish_timestamp_ms), |
| 363 last_background_fetch_time, score); |
| 356 if (global_position == 0) { | 364 if (global_position == 0) { |
| 357 content_suggestions_service_->user_classifier()->OnEvent( | 365 content_suggestions_service_->user_classifier()->OnEvent( |
| 358 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); | 366 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); |
| 359 } | 367 } |
| 360 } | 368 } |
| 361 | 369 |
| 362 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, | 370 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, |
| 363 const JavaParamRef<jobject>& obj, | 371 const JavaParamRef<jobject>& obj, |
| 364 jint global_position, | 372 jint global_position, |
| 365 jint j_category_id, | 373 jint j_category_id, |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 } | 484 } |
| 477 | 485 |
| 478 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { | 486 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { |
| 479 return content_suggestions_service_->category_factory()->FromIDValue(id); | 487 return content_suggestions_service_->category_factory()->FromIDValue(id); |
| 480 } | 488 } |
| 481 | 489 |
| 482 // static | 490 // static |
| 483 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 491 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 484 return RegisterNativesImpl(env); | 492 return RegisterNativesImpl(env); |
| 485 } | 493 } |
| OLD | NEW |