| 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" | |
| 26 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" | 25 #include "components/ntp_snippets/remote/remote_suggestions_provider.h" |
| 27 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" | 26 #include "components/ntp_snippets/remote/remote_suggestions_scheduler.h" |
| 28 #include "components/prefs/pref_service.h" | |
| 29 #include "jni/SnippetsBridge_jni.h" | 27 #include "jni/SnippetsBridge_jni.h" |
| 30 #include "ui/base/window_open_disposition.h" | 28 #include "ui/base/window_open_disposition.h" |
| 31 #include "ui/gfx/android/java_bitmap.h" | 29 #include "ui/gfx/android/java_bitmap.h" |
| 32 #include "ui/gfx/image/image.h" | 30 #include "ui/gfx/image/image.h" |
| 33 | 31 |
| 34 using base::android::AttachCurrentThread; | 32 using base::android::AttachCurrentThread; |
| 35 using base::android::ConvertJavaStringToUTF8; | 33 using base::android::ConvertJavaStringToUTF8; |
| 36 using base::android::ConvertUTF8ToJavaString; | 34 using base::android::ConvertUTF8ToJavaString; |
| 37 using base::android::ConvertUTF16ToJavaString; | 35 using base::android::ConvertUTF16ToJavaString; |
| 38 using base::android::JavaIntArrayToIntVector; | 36 using base::android::JavaIntArrayToIntVector; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 58 Java_SnippetsBridge_createSuggestionList(env); | 56 Java_SnippetsBridge_createSuggestionList(env); |
| 59 for (const ContentSuggestion& suggestion : suggestions) { | 57 for (const ContentSuggestion& suggestion : suggestions) { |
| 60 ScopedJavaLocalRef<jobject> java_suggestion = | 58 ScopedJavaLocalRef<jobject> java_suggestion = |
| 61 Java_SnippetsBridge_addSuggestion( | 59 Java_SnippetsBridge_addSuggestion( |
| 62 env, result, category.id(), | 60 env, result, category.id(), |
| 63 ConvertUTF8ToJavaString(env, suggestion.id().id_within_category()), | 61 ConvertUTF8ToJavaString(env, suggestion.id().id_within_category()), |
| 64 ConvertUTF16ToJavaString(env, suggestion.title()), | 62 ConvertUTF16ToJavaString(env, suggestion.title()), |
| 65 ConvertUTF16ToJavaString(env, suggestion.publisher_name()), | 63 ConvertUTF16ToJavaString(env, suggestion.publisher_name()), |
| 66 ConvertUTF16ToJavaString(env, suggestion.snippet_text()), | 64 ConvertUTF16ToJavaString(env, suggestion.snippet_text()), |
| 67 ConvertUTF8ToJavaString(env, suggestion.url().spec()), | 65 ConvertUTF8ToJavaString(env, suggestion.url().spec()), |
| 68 suggestion.publish_date().ToJavaTime(), suggestion.score()); | 66 suggestion.publish_date().ToJavaTime(), suggestion.score(), |
| 67 suggestion.fetch_date().ToJavaTime()); |
| 69 if (suggestion.id().category().IsKnownCategory( | 68 if (suggestion.id().category().IsKnownCategory( |
| 70 KnownCategories::DOWNLOADS) && | 69 KnownCategories::DOWNLOADS) && |
| 71 suggestion.download_suggestion_extra() != nullptr) { | 70 suggestion.download_suggestion_extra() != nullptr) { |
| 72 if (suggestion.download_suggestion_extra()->is_download_asset) { | 71 if (suggestion.download_suggestion_extra()->is_download_asset) { |
| 73 Java_SnippetsBridge_setAssetDownloadDataForSuggestion( | 72 Java_SnippetsBridge_setAssetDownloadDataForSuggestion( |
| 74 env, java_suggestion, | 73 env, java_suggestion, |
| 75 ConvertUTF8ToJavaString(env, suggestion.download_suggestion_extra() | 74 ConvertUTF8ToJavaString(env, suggestion.download_suggestion_extra() |
| 76 ->target_file_path.value()), | 75 ->target_file_path.value()), |
| 77 ConvertUTF8ToJavaString( | 76 ConvertUTF8ToJavaString( |
| 78 env, suggestion.download_suggestion_extra()->mime_type)); | 77 env, suggestion.download_suggestion_extra()->mime_type)); |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 content_suggestions_service_->user_classifier()->OnEvent( | 317 content_suggestions_service_->user_classifier()->OnEvent( |
| 319 ntp_snippets::UserClassifier::Metric::NTP_OPENED); | 318 ntp_snippets::UserClassifier::Metric::NTP_OPENED); |
| 320 } | 319 } |
| 321 | 320 |
| 322 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, | 321 void NTPSnippetsBridge::OnSuggestionShown(JNIEnv* env, |
| 323 const JavaParamRef<jobject>& obj, | 322 const JavaParamRef<jobject>& obj, |
| 324 jint global_position, | 323 jint global_position, |
| 325 jint j_category_id, | 324 jint j_category_id, |
| 326 jint position_in_category, | 325 jint position_in_category, |
| 327 jlong publish_timestamp_ms, | 326 jlong publish_timestamp_ms, |
| 328 jfloat score) { | 327 jfloat score, |
| 329 PrefService* pref_service = ProfileManager::GetLastUsedProfile()->GetPrefs(); | 328 jlong fetch_timestamp_ms) { |
| 330 base::Time last_background_fetch_time = | |
| 331 base::Time::FromInternalValue(pref_service->GetInt64( | |
| 332 ntp_snippets::prefs::kLastSuccessfulBackgroundFetchTime)); | |
| 333 | |
| 334 ntp_snippets::metrics::OnSuggestionShown( | 329 ntp_snippets::metrics::OnSuggestionShown( |
| 335 global_position, Category::FromIDValue(j_category_id), | 330 global_position, Category::FromIDValue(j_category_id), |
| 336 position_in_category, base::Time::FromJavaTime(publish_timestamp_ms), | 331 position_in_category, base::Time::FromJavaTime(publish_timestamp_ms), |
| 337 last_background_fetch_time, score); | 332 score, base::Time::FromJavaTime(fetch_timestamp_ms)); |
| 338 if (global_position == 0) { | 333 if (global_position == 0) { |
| 339 content_suggestions_service_->user_classifier()->OnEvent( | 334 content_suggestions_service_->user_classifier()->OnEvent( |
| 340 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); | 335 ntp_snippets::UserClassifier::Metric::SUGGESTIONS_SHOWN); |
| 341 } | 336 } |
| 342 } | 337 } |
| 343 | 338 |
| 344 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, | 339 void NTPSnippetsBridge::OnSuggestionOpened(JNIEnv* env, |
| 345 const JavaParamRef<jobject>& obj, | 340 const JavaParamRef<jobject>& obj, |
| 346 jint global_position, | 341 jint global_position, |
| 347 jint j_category_id, | 342 jint j_category_id, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 JNIEnv* env = AttachCurrentThread(); | 478 JNIEnv* env = AttachCurrentThread(); |
| 484 Java_SnippetsBridge_onMoreSuggestions( | 479 Java_SnippetsBridge_onMoreSuggestions( |
| 485 env, bridge_, category.id(), | 480 env, bridge_, category.id(), |
| 486 ToJavaSuggestionList(env, category, suggestions)); | 481 ToJavaSuggestionList(env, category, suggestions)); |
| 487 } | 482 } |
| 488 | 483 |
| 489 // static | 484 // static |
| 490 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 485 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 491 return RegisterNativesImpl(env); | 486 return RegisterNativesImpl(env); |
| 492 } | 487 } |
| OLD | NEW |