| 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 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 static void OnSuggestionTargetVisited(JNIEnv* env, | 151 static void OnSuggestionTargetVisited(JNIEnv* env, |
| 152 const JavaParamRef<jclass>& caller, | 152 const JavaParamRef<jclass>& caller, |
| 153 jint j_category_id, | 153 jint j_category_id, |
| 154 jlong visit_time_ms) { | 154 jlong visit_time_ms) { |
| 155 ntp_snippets::metrics::OnSuggestionTargetVisited( | 155 ntp_snippets::metrics::OnSuggestionTargetVisited( |
| 156 Category::FromIDValue(j_category_id), | 156 Category::FromIDValue(j_category_id), |
| 157 base::TimeDelta::FromMilliseconds(visit_time_ms)); | 157 base::TimeDelta::FromMilliseconds(visit_time_ms)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 static void SetRemoteSuggestionsServiceEnabled( | 160 static void SetRemoteSuggestionsEnabled(JNIEnv* env, |
| 161 JNIEnv* env, | 161 const JavaParamRef<jclass>& caller, |
| 162 const JavaParamRef<jclass>& caller, | 162 jboolean enabled) { |
| 163 jboolean enabled) { | |
| 164 ntp_snippets::ContentSuggestionsService* content_suggestions_service = | 163 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 165 ContentSuggestionsServiceFactory::GetForProfile( | 164 ContentSuggestionsServiceFactory::GetForProfile( |
| 166 ProfileManager::GetLastUsedProfile()); | 165 ProfileManager::GetLastUsedProfile()); |
| 167 if (!content_suggestions_service) | 166 if (!content_suggestions_service) |
| 168 return; | 167 return; |
| 169 | 168 |
| 170 content_suggestions_service->SetRemoteSuggestionsServiceEnabled(enabled); | 169 content_suggestions_service->SetRemoteSuggestionsEnabled(enabled); |
| 171 } | 170 } |
| 172 | 171 |
| 173 static jboolean IsRemoteSuggestionsServiceEnabled( | 172 static jboolean AreRemoteSuggestionsEnabled( |
| 174 JNIEnv* env, | 173 JNIEnv* env, |
| 175 const JavaParamRef<jclass>& caller) { | 174 const JavaParamRef<jclass>& caller) { |
| 176 ntp_snippets::ContentSuggestionsService* content_suggestions_service = | 175 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 177 ContentSuggestionsServiceFactory::GetForProfile( | 176 ContentSuggestionsServiceFactory::GetForProfile( |
| 178 ProfileManager::GetLastUsedProfile()); | 177 ProfileManager::GetLastUsedProfile()); |
| 179 if (!content_suggestions_service) | 178 if (!content_suggestions_service) |
| 180 return false; | 179 return false; |
| 181 | 180 |
| 182 return content_suggestions_service->IsRemoteSuggestionsServiceEnabled(); | 181 return content_suggestions_service->AreRemoteSuggestionsEnabled(); |
| 183 } | 182 } |
| 184 | 183 |
| 185 // Returns true if the remote service is managed by an adminstrator's policy. | 184 // Returns true if the remote provider is managed by an adminstrator's policy. |
| 186 static jboolean IsRemoteSuggestionsServiceManaged( | 185 static jboolean AreRemoteSuggestionsManaged( |
| 187 JNIEnv* env, | 186 JNIEnv* env, |
| 188 const JavaParamRef<jclass>& caller) { | 187 const JavaParamRef<jclass>& caller) { |
| 189 ntp_snippets::ContentSuggestionsService* content_suggestions_service = | 188 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 190 ContentSuggestionsServiceFactory::GetForProfile( | 189 ContentSuggestionsServiceFactory::GetForProfile( |
| 191 ProfileManager::GetLastUsedProfile()); | 190 ProfileManager::GetLastUsedProfile()); |
| 192 if (!content_suggestions_service) | 191 if (!content_suggestions_service) |
| 193 return false; | 192 return false; |
| 194 | 193 |
| 195 return content_suggestions_service->IsRemoteSuggestionsServiceManaged(); | 194 return content_suggestions_service->AreRemoteSuggestionsManaged(); |
| 196 } | 195 } |
| 197 | 196 |
| 198 // Returns true if the remote service is managed by a supervisor | 197 // Returns true if the remote provider is managed by a supervisor |
| 199 static jboolean IsRemoteSuggestionsServiceManagedByCustodian( | 198 static jboolean AreRemoteSuggestionsManagedByCustodian( |
| 200 JNIEnv* env, | 199 JNIEnv* env, |
| 201 const JavaParamRef<jclass>& caller) { | 200 const JavaParamRef<jclass>& caller) { |
| 202 ntp_snippets::ContentSuggestionsService* content_suggestions_service = | 201 ntp_snippets::ContentSuggestionsService* content_suggestions_service = |
| 203 ContentSuggestionsServiceFactory::GetForProfile( | 202 ContentSuggestionsServiceFactory::GetForProfile( |
| 204 ProfileManager::GetLastUsedProfile()); | 203 ProfileManager::GetLastUsedProfile()); |
| 205 if (!content_suggestions_service) | 204 if (!content_suggestions_service) |
| 206 return false; | 205 return false; |
| 207 | 206 |
| 208 return content_suggestions_service | 207 return content_suggestions_service->AreRemoteSuggestionsManagedByCustodian(); |
| 209 ->IsRemoteSuggestionsServiceManagedByCustodian(); | |
| 210 } | 208 } |
| 211 | 209 |
| 212 static void SetContentSuggestionsNotificationsEnabled( | 210 static void SetContentSuggestionsNotificationsEnabled( |
| 213 JNIEnv* env, | 211 JNIEnv* env, |
| 214 const JavaParamRef<jclass>& caller, | 212 const JavaParamRef<jclass>& caller, |
| 215 jboolean enabled) { | 213 jboolean enabled) { |
| 216 ContentSuggestionsNotifierService* notifier_service = | 214 ContentSuggestionsNotifierService* notifier_service = |
| 217 ContentSuggestionsNotifierServiceFactory::GetForProfile( | 215 ContentSuggestionsNotifierServiceFactory::GetForProfile( |
| 218 ProfileManager::GetLastUsedProfile()); | 216 ProfileManager::GetLastUsedProfile()); |
| 219 if (!notifier_service) | 217 if (!notifier_service) |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 JNIEnv* env = AttachCurrentThread(); | 571 JNIEnv* env = AttachCurrentThread(); |
| 574 Java_SnippetsBridge_onMoreSuggestions( | 572 Java_SnippetsBridge_onMoreSuggestions( |
| 575 env, bridge_, category.id(), | 573 env, bridge_, category.id(), |
| 576 ToJavaSuggestionList(env, category, suggestions)); | 574 ToJavaSuggestionList(env, category, suggestions)); |
| 577 } | 575 } |
| 578 | 576 |
| 579 // static | 577 // static |
| 580 bool NTPSnippetsBridge::Register(JNIEnv* env) { | 578 bool NTPSnippetsBridge::Register(JNIEnv* env) { |
| 581 return RegisterNativesImpl(env); | 579 return RegisterNativesImpl(env); |
| 582 } | 580 } |
| OLD | NEW |