| 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/predictors/resource_prefetch_predictor_android.h" | 5 #include "chrome/browser/predictors/resource_prefetch_predictor_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 9 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 10 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 10 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 const JavaParamRef<jobject>& j_profile) { | 22 const JavaParamRef<jobject>& j_profile) { |
| 23 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | 23 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); |
| 24 if (!profile) | 24 if (!profile) |
| 25 return nullptr; | 25 return nullptr; |
| 26 return ResourcePrefetchPredictorFactory::GetInstance()->GetForProfile( | 26 return ResourcePrefetchPredictorFactory::GetInstance()->GetForProfile( |
| 27 profile); | 27 profile); |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 static jboolean StartInitialization(JNIEnv* env, |
| 33 const JavaParamRef<jclass>& clazz, |
| 34 const JavaParamRef<jobject>& j_profile) { |
| 35 auto predictor = ResourcePrefetchPredictorFromProfileAndroid(j_profile); |
| 36 if (!predictor) |
| 37 return false; |
| 38 predictor->StartInitialization(); |
| 39 return true; |
| 40 } |
| 41 |
| 32 static jboolean StartPrefetching(JNIEnv* env, | 42 static jboolean StartPrefetching(JNIEnv* env, |
| 33 const JavaParamRef<jclass>& clazz, | 43 const JavaParamRef<jclass>& clazz, |
| 34 const JavaParamRef<jobject>& j_profile, | 44 const JavaParamRef<jobject>& j_profile, |
| 35 const JavaParamRef<jstring>& j_url) { | 45 const JavaParamRef<jstring>& j_url) { |
| 36 auto predictor = ResourcePrefetchPredictorFromProfileAndroid(j_profile); | 46 auto predictor = ResourcePrefetchPredictorFromProfileAndroid(j_profile); |
| 37 if (!predictor) | 47 if (!predictor) |
| 38 return false; | 48 return false; |
| 39 GURL url = GURL(base::android::ConvertJavaStringToUTF16(env, j_url)); | 49 GURL url = GURL(base::android::ConvertJavaStringToUTF16(env, j_url)); |
| 40 predictor->StartPrefetching(url); | 50 predictor->StartPrefetching(url); |
| 41 | 51 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 53 predictor->StopPrefetching(url); | 63 predictor->StopPrefetching(url); |
| 54 | 64 |
| 55 return true; | 65 return true; |
| 56 } | 66 } |
| 57 | 67 |
| 58 bool RegisterResourcePrefetchPredictor(JNIEnv* env) { | 68 bool RegisterResourcePrefetchPredictor(JNIEnv* env) { |
| 59 return RegisterNativesImpl(env); | 69 return RegisterNativesImpl(env); |
| 60 } | 70 } |
| 61 | 71 |
| 62 } // namespace predictors | 72 } // namespace predictors |
| OLD | NEW |