| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 const JavaParamRef<jobject>& obj, | 64 const JavaParamRef<jobject>& obj, |
| 65 const JavaParamRef<jobject>& j_profile) { | 65 const JavaParamRef<jobject>& j_profile) { |
| 66 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); | 66 NTPSnippetsBridge* snippets_bridge = new NTPSnippetsBridge(env, j_profile); |
| 67 return reinterpret_cast<intptr_t>(snippets_bridge); | 67 return reinterpret_cast<intptr_t>(snippets_bridge); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static void FetchSnippets(JNIEnv* env, | 70 static void FetchSnippets(JNIEnv* env, |
| 71 const JavaParamRef<jclass>& caller, | 71 const JavaParamRef<jclass>& caller, |
| 72 jboolean j_force_request) { | 72 jboolean j_force_request) { |
| 73 Profile* profile = ProfileManager::GetLastUsedProfile(); | 73 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 74 // Temporary check while investigating crbug.com/647920. |
| 75 CHECK(profile); |
| 76 |
| 77 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 78 ContentSuggestionsServiceFactory::GetForProfile(profile); |
| 79 |
| 80 // Can maybe be null in some cases? (Incognito profile?) crbug.com/647920 |
| 81 if (!content_suggestions_service) |
| 82 return; |
| 83 |
| 74 ntp_snippets::NTPSnippetsService* service = | 84 ntp_snippets::NTPSnippetsService* service = |
| 75 ContentSuggestionsServiceFactory::GetForProfile(profile) | 85 content_suggestions_service->ntp_snippets_service(); |
| 76 ->ntp_snippets_service(); | |
| 77 | 86 |
| 78 // 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 |
| 79 // unregistered yet. The next start should unregister it. | 88 // unregistered yet. The next start should unregister it. |
| 80 if (!service) | 89 if (!service) |
| 81 return; | 90 return; |
| 82 | 91 |
| 83 service->FetchSnippets(j_force_request); | 92 service->FetchSnippets(j_force_request); |
| 84 } | 93 } |
| 85 | 94 |
| 86 // Reschedules the fetching of snippets. Used to support different fetching | 95 // Reschedules the fetching of snippets. Used to support different fetching |
| 87 // intervals for different times of day. | 96 // intervals for different times of day. |
| 88 static void RescheduleFetching(JNIEnv* env, | 97 static void RescheduleFetching(JNIEnv* env, |
| 89 const JavaParamRef<jclass>& caller) { | 98 const JavaParamRef<jclass>& caller) { |
| 90 Profile* profile = ProfileManager::GetLastUsedProfile(); | 99 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 100 // Temporary check while investigating crbug.com/647920. |
| 101 CHECK(profile); |
| 102 |
| 103 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 104 ContentSuggestionsServiceFactory::GetForProfile(profile); |
| 105 |
| 106 // Can maybe be null in some cases? (Incognito profile?) crbug.com/647920 |
| 107 if (!content_suggestions_service) |
| 108 return; |
| 109 |
| 91 ntp_snippets::NTPSnippetsService* service = | 110 ntp_snippets::NTPSnippetsService* service = |
| 92 ContentSuggestionsServiceFactory::GetForProfile(profile) | 111 content_suggestions_service->ntp_snippets_service(); |
| 93 ->ntp_snippets_service(); | |
| 94 | 112 |
| 95 // 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 |
| 96 // unregistered yet. The next start should unregister it. | 114 // unregistered yet. The next start should unregister it. |
| 97 if (!service) | 115 if (!service) |
| 98 return; | 116 return; |
| 99 | 117 |
| 100 service->RescheduleFetching(); | 118 service->RescheduleFetching(); |
| 101 } | 119 } |
| 102 | 120 |
| 103 static void OnSuggestionTargetVisited(JNIEnv* env, | 121 static void OnSuggestionTargetVisited(JNIEnv* env, |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } | 378 } |
| 361 | 379 |
| 362 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { | 380 Category NTPSnippetsBridge::CategoryFromIDValue(jint id) { |
| 363 return content_suggestions_service_->category_factory()->FromIDValue(id); | 381 return content_suggestions_service_->category_factory()->FromIDValue(id); |
| 364 } | 382 } |
| 365 | 383 |
| 366 // static | 384 // static |
| 367 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 385 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 368 return RegisterNativesImpl(env); | 386 return RegisterNativesImpl(env); |
| 369 } | 387 } |
| OLD | NEW |