| Index: chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| diff --git a/chrome/browser/android/ntp/ntp_snippets_bridge.cc b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| index 1674d00ad9ba3b2e66c6bf13b4463ead1ec16829..4aecf3461c883c49150311e09cef4a24be9c97c0 100644
|
| --- a/chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| +++ b/chrome/browser/android/ntp/ntp_snippets_bridge.cc
|
| @@ -94,7 +94,7 @@ ScopedJavaLocalRef<jobject> ToJavaSuggestionList(
|
| return result;
|
| }
|
|
|
| -ntp_snippets::RemoteSuggestionsProvider* GetRemoteSuggestionsProvider() {
|
| +ntp_snippets::PersistentScheduler::Listener* GetPersistentSchedulerListener() {
|
| ntp_snippets::ContentSuggestionsService* content_suggestions_service =
|
| ContentSuggestionsServiceFactory::GetForProfile(
|
| ProfileManager::GetLastUsedProfile());
|
| @@ -102,7 +102,7 @@ ntp_snippets::RemoteSuggestionsProvider* GetRemoteSuggestionsProvider() {
|
| if (!content_suggestions_service) {
|
| return nullptr;
|
| }
|
| - return content_suggestions_service->ntp_snippets_service();
|
| + return content_suggestions_service->persistent_scheduler_listener();
|
| }
|
|
|
| } // namespace
|
| @@ -114,57 +114,35 @@ static jlong Init(JNIEnv* env,
|
| return reinterpret_cast<intptr_t>(snippets_bridge);
|
| }
|
|
|
| -static void FetchRemoteSuggestions(JNIEnv* env,
|
| - const JavaParamRef<jclass>& caller) {
|
| - ntp_snippets::RemoteSuggestionsProvider* remote_suggestions_provider =
|
| - GetRemoteSuggestionsProvider();
|
| - // Can be null if the feature has been disabled but the scheduler has not been
|
| - // unregistered yet. The next start should unregister it.
|
| - if (!remote_suggestions_provider) {
|
| - return;
|
| - }
|
| - remote_suggestions_provider->FetchSnippetsForAllCategories();
|
| -}
|
| -
|
| -static void FetchRemoteSuggestionsInTheBackground(
|
| +// Initiates a background fetch for remote suggestions.
|
| +static void PersistentSchedulerListenerOnFetchDue(
|
| JNIEnv* env,
|
| const JavaParamRef<jclass>& caller) {
|
| - ntp_snippets::RemoteSuggestionsProvider* remote_suggestions_provider =
|
| - GetRemoteSuggestionsProvider();
|
| + ntp_snippets::PersistentScheduler::Listener* listener =
|
| + GetPersistentSchedulerListener();
|
| // Can be null if the feature has been disabled but the scheduler has not been
|
| // unregistered yet. The next start should unregister it.
|
| - if (!remote_suggestions_provider) {
|
| + if (!listener) {
|
| return;
|
| }
|
| - remote_suggestions_provider->FetchSnippetsInTheBackground();
|
| +
|
| + listener->OnFetchDue();
|
| }
|
|
|
| // Reschedules the fetching of snippets. If tasks are already scheduled, they
|
| // will be rescheduled anyway, so all running intervals will be reset.
|
| -static void RescheduleFetching(JNIEnv* env,
|
| - const JavaParamRef<jclass>& caller) {
|
| - Profile* profile = ProfileManager::GetLastUsedProfile();
|
| - // Temporary check while investigating crbug.com/647920.
|
| - CHECK(profile);
|
| -
|
| - ntp_snippets::ContentSuggestionsService* content_suggestions_service =
|
| - ContentSuggestionsServiceFactory::GetForProfile(profile);
|
| -
|
| - // Can maybe be null in some cases? (Incognito profile?) crbug.com/647920
|
| - if (!content_suggestions_service) {
|
| - return;
|
| - }
|
| -
|
| - ntp_snippets::RemoteSuggestionsProvider* service =
|
| - content_suggestions_service->ntp_snippets_service();
|
| -
|
| +static void PersistentSchedulerListenerRescheduleFetching(
|
| + JNIEnv* env,
|
| + const JavaParamRef<jclass>& caller) {
|
| + ntp_snippets::PersistentScheduler::Listener* listener =
|
| + GetPersistentSchedulerListener();
|
| // Can be null if the feature has been disabled but the scheduler has not been
|
| // unregistered yet. The next start should unregister it.
|
| - if (!service) {
|
| + if (!listener) {
|
| return;
|
| }
|
|
|
| - service->RescheduleFetching(/*force=*/true);
|
| + listener->RescheduleFetching();
|
| }
|
|
|
| static void OnSuggestionTargetVisited(JNIEnv* env,
|
| @@ -278,6 +256,12 @@ void NTPSnippetsBridge::Fetch(
|
| weak_ptr_factory_.GetWeakPtr(), category));
|
| }
|
|
|
| +void NTPSnippetsBridge::ReloadSuggestions(
|
| + JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& obj) {
|
| + content_suggestions_service_->ReloadSuggestions();
|
| +}
|
| +
|
| void NTPSnippetsBridge::DismissSuggestion(
|
| JNIEnv* env,
|
| const JavaParamRef<jobject>& obj,
|
|
|