Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3598)

Unified Diff: chrome/browser/android/webapk/webapk_installer.cc

Issue 2515293004: Chrome talks to Play to install WebAPKs. (Closed)
Patch Set: Rebase. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c771a039110668c5e5a65507d300a198cdfcab41 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() &&
+ Java_WebApkInstaller_hasWebApkInstallClientDelegate(env, java_ref_)) {
+ InstallWebApkFromPlayStore(response->package_name(),
+ std::atoi(response->version().c_str()),
+ response->wam_token());
+ return;
+ }
+
OnGotWebApkDownloadUrl(signed_download_url, response->package_name());
}
@@ -410,6 +434,24 @@ void WebApkInstaller::SendRequest(std::unique_ptr<webapk::WebApk> request_proto,
url_fetcher_->Start();
}
+void WebApkInstaller::InstallWebApkFromPlayStore(
pkotwicz 2016/12/01 04:18:04 We should probably rename this method to InstallOr
Xi Han 2016/12/01 22:22:28 Good catch! The update part is added.
+ 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);
+
+ Java_WebApkInstaller_installWebApkFromPlayStoreAsyncAndMonitorInstallation(
+ 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;
« no previous file with comments | « chrome/browser/android/webapk/webapk_installer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698