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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkVersionManager.java

Issue 2011613003: Upstream: Extract "WebAPK service" implementation from Chrome APK (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months 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
Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkVersionManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkVersionManager.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkVersionManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..e6f84a8f6e734a61b457328151d1558f8c5f5780
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebApkVersionManager.java
@@ -0,0 +1,53 @@
+// 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.
+
+package org.chromium.chrome.browser.webapps;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+import org.chromium.base.ContextUtils;
+import org.chromium.base.FileUtils;
+import org.chromium.base.ThreadUtils;
+import org.chromium.webapk.lib.client.DexOptimizer;
+
+import java.io.File;
+
+/**
+ * Updates installed WebAPKs after a Chrome update.
+ */
+public class WebApkVersionManager {
+ /**
+ * Name of the shared preference to store whether an attempt to extract the WebAPK runtime
+ * library was made.
+ */
+ private static final String TRIED_EXTRACTING_DEX_PREF =
+ "org.chromium.chrome.browser.webapps.TRIED_EXTRACTING_DEX";
+
+ /**
+ * Tries to extract the WebAPK runtime dex from the Chrome APK if it has not tried already.
+ * Should not be called on UI thread.
+ */
+ public static void updateWebApksIfNeeded() {
+ assert !ThreadUtils.runningOnUiThread();
+
+ SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
+ if (preferences.getBoolean(TRIED_EXTRACTING_DEX_PREF, false)) {
+ return;
+ }
+
+ preferences.edit().putBoolean(TRIED_EXTRACTING_DEX_PREF, true).apply();
+
+ Context context = ContextUtils.getApplicationContext();
+ File dexDir = context.getDir("dex", Context.MODE_PRIVATE);
+ File dexFile = new File(dexDir, "web_apk.dex");
+ if (!FileUtils.extractAsset(context, "web_apk.dex", dexFile)
+ || !DexOptimizer.optimize(dexFile)) {
+ return;
+ }
+
+ // Make dex file world-readable so that WebAPK can use it.
+ dexFile.setReadable(true, false);
+ }
+}
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/DeferredStartupHandler.java ('k') | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698