Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/predictors/resource_prefetch_predictor_android.h" | |
| 6 | |
| 7 #include "base/android/jni_android.h" | |
| 8 #include "base/android/jni_string.h" | |
| 9 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | |
| 10 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/profiles/profile_android.h" | |
| 13 #include "jni/ResourcePrefetchPredictor_jni.h" | |
| 14 | |
| 15 using base::android::JavaParamRef; | |
| 16 using base::android::ScopedJavaLocalRef; | |
| 17 | |
| 18 namespace predictors { | |
| 19 | |
| 20 void ResourcePrefetchPredictorAndroid::StartPrefetching( | |
| 21 JNIEnv* env, | |
| 22 const base::android::JavaParamRef<jobject>& jcaller, | |
| 23 const JavaParamRef<jstring>& j_url) { | |
| 24 ResourcePrefetchPredictor* predictor = | |
| 25 ResourcePrefetchPredictorFactory::GetInstance()->GetForProfile(profile_); | |
| 26 if (!predictor) | |
| 27 return; | |
| 28 GURL url = GURL(base::android::ConvertJavaStringToUTF16(env, j_url)); | |
| 29 predictor->StartPrefetching(url); | |
| 30 } | |
| 31 | |
| 32 void ResourcePrefetchPredictorAndroid::StopPrefetching( | |
| 33 JNIEnv* env, | |
| 34 const base::android::JavaParamRef<jobject>& jcaller, | |
| 35 const JavaParamRef<jstring>& j_url) { | |
| 36 ResourcePrefetchPredictor* predictor = | |
| 37 ResourcePrefetchPredictorFactory::GetInstance()->GetForProfile(profile_); | |
| 38 if (!predictor) | |
| 39 return; | |
| 40 GURL url = GURL(base::android::ConvertJavaStringToUTF16(env, j_url)); | |
| 41 predictor->StopPrefetching(url); | |
| 42 } | |
| 43 | |
| 44 // static | |
| 45 jlong ResourcePrefetchPredictorAndroid::GetForProfile(JNIEnv* env, | |
| 46 jclass clazz, | |
| 47 jobject j_profile) { | |
| 48 Profile* profile = ProfileAndroid::FromProfileAndroid(j_profile); | |
|
gone
2016/09/28 18:18:15
FromProfileAndroid can return null.
Benoit L
2016/10/03 09:42:05
The resulting profile is used to call ResourcePref
gone
2016/10/03 21:30:32
If that and the ResourcePretchPredictorAndroid tha
| |
| 49 ResourcePrefetchPredictorAndroid* predictor_android = | |
| 50 new ResourcePrefetchPredictorAndroid(profile); | |
| 51 return static_cast<jlong>(reinterpret_cast<intptr_t>(predictor_android)); | |
| 52 } | |
| 53 | |
| 54 // static | |
| 55 bool ResourcePrefetchPredictorAndroid::Register(JNIEnv* env) { | |
| 56 return RegisterNativesImpl(env); | |
| 57 } | |
| 58 | |
| 59 static jlong GetResourcePrefetchPredictorForProfile( | |
| 60 JNIEnv* env, | |
| 61 const JavaParamRef<jclass>& clazz, | |
| 62 const JavaParamRef<jobject>& j_profile) { | |
| 63 return ResourcePrefetchPredictorAndroid::GetForProfile(env, clazz.obj(), | |
| 64 j_profile.obj()); | |
| 65 } | |
| 66 | |
| 67 ResourcePrefetchPredictorAndroid::ResourcePrefetchPredictorAndroid( | |
| 68 Profile* profile) | |
| 69 : profile_(profile) {} | |
| 70 | |
| 71 } // namespace predictors | |
| OLD | NEW |