| 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/webapk/chrome_webapk_host.h" | 5 #include "chrome/browser/android/webapk/chrome_webapk_host.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/bind.h" |
| 7 #include "chrome/browser/android/chrome_feature_list.h" | 9 #include "chrome/browser/android/chrome_feature_list.h" |
| 10 #include "chrome/browser/android/webapk/webapk_install_service.h" |
| 8 #include "components/variations/variations_associated_data.h" | 11 #include "components/variations/variations_associated_data.h" |
| 9 #include "jni/ChromeWebApkHost_jni.h" | 12 #include "jni/ChromeWebApkHost_jni.h" |
| 10 | 13 |
| 11 namespace { | 14 namespace { |
| 12 | 15 |
| 13 // Variations flag to enable installing WebAPKs using Google Play. | 16 // Variations flag to enable installing WebAPKs using Google Play. |
| 14 const char* kPlayInstall = "play_install"; | 17 const char* kPlayInstall = "play_install"; |
| 15 | 18 |
| 19 bool IsGooglePlayInstallAllowed() { |
| 20 return variations::GetVariationParamValueByFeature( |
| 21 chrome::android::kImprovedA2HS, kPlayInstall) == "true"; |
| 22 } |
| 23 |
| 16 } // anonymous namespace | 24 } // anonymous namespace |
| 17 | 25 |
| 18 // static | 26 // static |
| 19 bool ChromeWebApkHost::Register(JNIEnv* env) { | 27 bool ChromeWebApkHost::Register(JNIEnv* env) { |
| 20 return RegisterNativesImpl(env); | 28 return RegisterNativesImpl(env); |
| 21 } | 29 } |
| 22 | 30 |
| 23 // static | 31 // static |
| 24 bool ChromeWebApkHost::AreWebApkEnabled() { | 32 bool ChromeWebApkHost::AreWebApkEnabled() { |
| 25 JNIEnv* env = base::android::AttachCurrentThread(); | 33 JNIEnv* env = base::android::AttachCurrentThread(); |
| 26 return Java_ChromeWebApkHost_areWebApkEnabled(env); | 34 return Java_ChromeWebApkHost_areWebApkEnabled(env); |
| 27 } | 35 } |
| 28 | 36 |
| 29 // static | 37 // static |
| 30 jboolean CanUseGooglePlayToInstallWebApk( | 38 jboolean CanUseGooglePlayToInstallWebApk( |
| 31 JNIEnv* env, | 39 JNIEnv* env, |
| 32 const base::android::JavaParamRef<jclass>& clazz) { | 40 const base::android::JavaParamRef<jclass>& clazz) { |
| 33 return variations::GetVariationParamValueByFeature( | 41 return IsGooglePlayInstallAllowed(); |
| 34 chrome::android::kImprovedA2HS, kPlayInstall) == "true"; | |
| 35 } | 42 } |
| 43 |
| 44 // static |
| 45 bool ChromeWebApkHost::CanUseGooglePlayToInstallWebApk() { |
| 46 return IsGooglePlayInstallAllowed(); |
| 47 } |
| 48 |
| 49 ChromeWebApkHost::ChromeWebApkHost() { |
| 50 CreateJavaRef(); |
| 51 } |
| 52 |
| 53 void ChromeWebApkHost::CanUseGooglePlayInstallApi( |
| 54 const CanUseGooglePlayInstallApiCallback& callback) { |
| 55 callback_ = callback; |
| 56 Java_ChromeWebApkHost_canUseGooglePlayInstallApi( |
| 57 base::android::AttachCurrentThread(), java_ref_); |
| 58 } |
| 59 |
| 60 void ChromeWebApkHost::OnCanUseGooglePlayInstallApi( |
| 61 JNIEnv* env, |
| 62 const base::android::JavaParamRef<jobject>& obj, |
| 63 jboolean is_available) { |
| 64 callback_.Run(is_available); |
| 65 delete this; |
| 66 } |
| 67 |
| 68 void ChromeWebApkHost::CreateJavaRef() { |
| 69 JNIEnv* env = base::android::AttachCurrentThread(); |
| 70 java_ref_.Reset(Java_ChromeWebApkHost_create( |
| 71 env, reinterpret_cast<intptr_t>(this))); |
| 72 } |
| 73 |
| 74 ChromeWebApkHost::~ChromeWebApkHost() { |
| 75 JNIEnv* env = base::android::AttachCurrentThread(); |
| 76 Java_ChromeWebApkHost_destroy(env, java_ref_); |
| 77 java_ref_.Reset(); |
| 78 } |
| OLD | NEW |