Chromium Code Reviews| Index: chrome/browser/predictors/resource_prefetch_predictor_android.cc |
| diff --git a/chrome/browser/predictors/resource_prefetch_predictor_android.cc b/chrome/browser/predictors/resource_prefetch_predictor_android.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1dcf509b64d6b4ff71b318693957760f18a8a13d |
| --- /dev/null |
| +++ b/chrome/browser/predictors/resource_prefetch_predictor_android.cc |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/predictors/resource_prefetch_predictor_android.h" |
| + |
| +#include "base/android/jni_android.h" |
| +#include "base/android/jni_string.h" |
| +#include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| +#include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_android.h" |
| +#include "jni/ResourcePrefetchPredictor_jni.h" |
| + |
| +using base::android::JavaParamRef; |
| +using base::android::ScopedJavaLocalRef; |
| + |
| +namespace predictors { |
| + |
| +void ResourcePrefetchPredictorAndroid::StartPrefetching( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& jcaller, |
| + const JavaParamRef<jstring>& j_url) { |
| + ResourcePrefetchPredictor* predictor = |
| + ResourcePrefetchPredictorFactory::GetInstance()->GetForProfile(profile_); |
| + if (!predictor) |
| + return; |
| + GURL url = GURL(base::android::ConvertJavaStringToUTF16(env, j_url)); |
| + predictor->StartPrefetching(url); |
| +} |
| + |
| +void ResourcePrefetchPredictorAndroid::StopPrefetching( |
| + JNIEnv* env, |
| + const base::android::JavaParamRef<jobject>& jcaller, |
| + const JavaParamRef<jstring>& j_url) { |
| + ResourcePrefetchPredictor* predictor = |
| + ResourcePrefetchPredictorFactory::GetInstance()->GetForProfile(profile_); |
| + if (!predictor) |
| + return; |
| + GURL url = GURL(base::android::ConvertJavaStringToUTF16(env, j_url)); |
| + predictor->StopPrefetching(url); |
| +} |
| + |
| +// static |
| +jlong ResourcePrefetchPredictorAndroid::GetForProfile(JNIEnv* env, |
| + jclass clazz, |
| + jobject j_profile) { |
| + 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
|
| + ResourcePrefetchPredictorAndroid* predictor_android = |
| + new ResourcePrefetchPredictorAndroid(profile); |
| + return static_cast<jlong>(reinterpret_cast<intptr_t>(predictor_android)); |
| +} |
| + |
| +// static |
| +bool ResourcePrefetchPredictorAndroid::Register(JNIEnv* env) { |
| + return RegisterNativesImpl(env); |
| +} |
| + |
| +static jlong GetResourcePrefetchPredictorForProfile( |
| + JNIEnv* env, |
| + const JavaParamRef<jclass>& clazz, |
| + const JavaParamRef<jobject>& j_profile) { |
| + return ResourcePrefetchPredictorAndroid::GetForProfile(env, clazz.obj(), |
| + j_profile.obj()); |
| +} |
| + |
| +ResourcePrefetchPredictorAndroid::ResourcePrefetchPredictorAndroid( |
| + Profile* profile) |
| + : profile_(profile) {} |
| + |
| +} // namespace predictors |