| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 content_suggestions_service->ntp_snippets_service(); | 85 content_suggestions_service->ntp_snippets_service(); |
| 86 | 86 |
| 87 // Can be null if the feature has been disabled but the scheduler has not been | 87 // Can be null if the feature has been disabled but the scheduler has not been |
| 88 // unregistered yet. The next start should unregister it. | 88 // unregistered yet. The next start should unregister it. |
| 89 if (!service) | 89 if (!service) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 service->FetchSnippets(j_force_request); | 92 service->FetchSnippets(j_force_request); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Reschedules the fetching of snippets. | 95 // Reschedules the fetching of snippets. If tasks are already scheduled, they |
| 96 // will be rescheduled anyway, so all running intervals will be reset. |
| 96 static void RescheduleFetching(JNIEnv* env, | 97 static void RescheduleFetching(JNIEnv* env, |
| 97 const JavaParamRef<jclass>& caller) { | 98 const JavaParamRef<jclass>& caller) { |
| 98 Profile* profile = ProfileManager::GetLastUsedProfile(); | 99 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 99 // Temporary check while investigating crbug.com/647920. | 100 // Temporary check while investigating crbug.com/647920. |
| 100 CHECK(profile); | 101 CHECK(profile); |
| 101 | 102 |
| 102 ntp_snippets::ContentSuggestionsService* content_suggestions_service = | 103 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 103 ContentSuggestionsServiceFactory::GetForProfile(profile); | 104 ContentSuggestionsServiceFactory::GetForProfile(profile); |
| 104 | 105 |
| 105 // Can maybe be null in some cases? (Incognito profile?) crbug.com/647920 | 106 // Can maybe be null in some cases? (Incognito profile?) crbug.com/647920 |
| 106 if (!content_suggestions_service) | 107 if (!content_suggestions_service) |
| 107 return; | 108 return; |
| 108 | 109 |
| 109 ntp_snippets::NTPSnippetsService* service = | 110 ntp_snippets::NTPSnippetsService* service = |
| 110 content_suggestions_service->ntp_snippets_service(); | 111 content_suggestions_service->ntp_snippets_service(); |
| 111 | 112 |
| 112 // Can be null if the feature has been disabled but the scheduler has not been | 113 // Can be null if the feature has been disabled but the scheduler has not been |
| 113 // unregistered yet. The next start should unregister it. | 114 // unregistered yet. The next start should unregister it. |
| 114 if (!service) | 115 if (!service) |
| 115 return; | 116 return; |
| 116 | 117 |
| 117 service->RescheduleFetching(); | 118 service->RescheduleFetching(/*force=*/true); |
| 118 } | 119 } |
| 119 | 120 |
| 120 static void OnSuggestionTargetVisited(JNIEnv* env, | 121 static void OnSuggestionTargetVisited(JNIEnv* env, |
| 121 const JavaParamRef<jclass>& caller, | 122 const JavaParamRef<jclass>& caller, |
| 122 jint category, | 123 jint category, |
| 123 jlong visit_time_ms) { | 124 jlong visit_time_ms) { |
| 124 Profile* profile = ProfileManager::GetLastUsedProfile(); | 125 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 125 ntp_snippets::ContentSuggestionsService* content_suggestions_service = | 126 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 126 ContentSuggestionsServiceFactory::GetForProfile(profile); | 127 ContentSuggestionsServiceFactory::GetForProfile(profile); |
| 127 ntp_snippets::metrics::OnSuggestionTargetVisited( | 128 ntp_snippets::metrics::OnSuggestionTargetVisited( |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 383 } |
| 383 | 384 |
| 384 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { | 385 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { |
| 385 return content_suggestions_service_->category_factory()->FromIDValue(id); | 386 return content_suggestions_service_->category_factory()->FromIDValue(id); |
| 386 } | 387 } |
| 387 | 388 |
| 388 // static | 389 // static |
| 389 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 390 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 390 return RegisterNativesImpl(env); | 391 return RegisterNativesImpl(env); |
| 391 } | 392 } |
| OLD | NEW |