Chromium Code Reviews| Index: chrome/browser/android/webapk/webapk_installer.cc |
| diff --git a/chrome/browser/android/webapk/webapk_installer.cc b/chrome/browser/android/webapk/webapk_installer.cc |
| index 3e09705476b1da17ff780250ded602ab8e8ab6dd..d08f9e23b557c3d9a64c3bf55a1ecfab4a212f3d 100644 |
| --- a/chrome/browser/android/webapk/webapk_installer.cc |
| +++ b/chrome/browser/android/webapk/webapk_installer.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/android/webapk/webapk_installer.h" |
| +#include <stdlib.h> |
| + |
| #include "base/android/build_info.h" |
| #include "base/android/jni_android.h" |
| #include "base/android/jni_string.h" |
| @@ -18,11 +20,13 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/task_runner_util.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| +#include "chrome/browser/android/chrome_feature_list.h" |
| #include "chrome/browser/android/shortcut_helper.h" |
| #include "chrome/browser/android/webapk/webapk.pb.h" |
| #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/common/chrome_switches.h" |
| +#include "components/variations/variations_associated_data.h" |
| #include "components/version_info/version_info.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/common/manifest_util.h" |
| @@ -38,6 +42,9 @@ namespace { |
| const char kDefaultServerUrl[] = |
| "https://test-webapk.sandbox.googleapis.com/v1/webApks/?alt=proto&key=AIzaSyAoI6v-F31-3t9NunLYEiKcPIqgTJIUZBw"; |
| +// Flag of whether installing WebAPKs from Play Store is enabled. |
| +const char kPlayInstallWebApks[] = "play_install_webapks"; |
| + |
| // The MIME type of the POST data sent to the server. |
| const char kProtoMimeType[] = "application/x-protobuf"; |
| @@ -53,6 +60,13 @@ const int kWorldReadableFilePermission = base::FILE_PERMISSION_READ_BY_USER | |
| base::FILE_PERMISSION_READ_BY_GROUP | |
| base::FILE_PERMISSION_READ_BY_OTHERS; |
| +// Returns whether the |play_install_webapks| param of the currently active |
| +// field trials is true. |
| +bool IsPlayInstallWebApksEnabled() { |
| + return variations::GetVariationParamValueByFeature(chrome::android::kWebApks, |
| + kPlayInstallWebApks) == "true"; |
| +} |
| + |
| // Returns the WebAPK server URL based on the command line. |
| GURL GetServerUrl() { |
| base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| @@ -339,6 +353,16 @@ void WebApkInstaller::OnURLFetchComplete(const net::URLFetcher* source) { |
| OnFailure(); |
| return; |
| } |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + if (IsPlayInstallWebApksEnabled() && |
|
pkotwicz
2016/12/02 02:24:00
Is the IsPlayInstallWebApksEnabled() check necessa
Xi Han
2016/12/02 20:45:37
It isn't any more, removed.
|
| + Java_WebApkInstaller_hasWebApkInstallClientDelegate(env, java_ref_)) { |
| + InstallOrUpdateWebApkFromPlayStore(response->package_name(), |
|
pkotwicz
2016/12/02 02:24:00
Nit: InstallOrUpdateWebApkFromPlayStore() -> Insta
Xi Han
2016/12/02 20:45:37
Done.
|
| + std::atoi(response->version().c_str()), |
|
pkotwicz
2016/12/02 02:24:00
Nit: Use base::StringToInt()
Xi Han
2016/12/02 20:45:37
Done.
|
| + response->wam_token()); |
| + return; |
| + } |
| + |
| OnGotWebApkDownloadUrl(signed_download_url, response->package_name()); |
| } |
| @@ -410,6 +434,31 @@ void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto, |
| url_fetcher_->Start(); |
| } |
| +void WebApkInstaller::InstallOrUpdateWebApkFromPlayStore( |
| + const std::string& package_name, |
| + int version, |
| + const std::string& wam_token) { |
| + webapk_package_ = package_name; |
| + |
| + JNIEnv* env = base::android::AttachCurrentThread(); |
| + base::android::ScopedJavaLocalRef<jstring> java_webapk_package = |
| + base::android::ConvertUTF8ToJavaString(env, webapk_package_); |
| + base::android::ScopedJavaLocalRef<jstring> java_title = |
| + base::android::ConvertUTF16ToJavaString(env, shortcut_info_.user_title); |
| + base::android::ScopedJavaLocalRef<jstring> java_wam_token = |
| + base::android::ConvertUTF8ToJavaString(env, wam_token); |
| + |
| + if (task_type_ == WebApkInstaller::INSTALL) { |
| + Java_WebApkInstaller_installWebApkFromPlayStoreAsyncAndMonitorInstallation( |
| + env, java_ref_, java_webapk_package, version, java_title, |
| + java_wam_token); |
| + } else { |
| + Java_WebApkInstaller_updateAsyncFromPlayStore( |
| + env, java_ref_, java_webapk_package, version, java_title, |
| + java_wam_token); |
| + } |
| +} |
| + |
| void WebApkInstaller::OnGotWebApkDownloadUrl(const GURL& download_url, |
| const std::string& package_name) { |
| webapk_package_ = package_name; |