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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.webapps;
6
7 import android.content.Context;
8 import android.content.SharedPreferences;
9
10 import org.chromium.base.ContextUtils;
11 import org.chromium.base.FileUtils;
12 import org.chromium.base.ThreadUtils;
13 import org.chromium.webapk.lib.client.DexOptimizer;
14
15 import java.io.File;
16
17 /**
18 * Updates installed WebAPKs after a Chrome update.
19 */
20 public class WebApkVersionManager {
21 /**
22 * Name of the shared preference to store whether an attempt to extract the WebAPK runtime
23 * library was made.
24 */
25 private static final String TRIED_EXTRACTING_DEX_PREF =
26 "org.chromium.chrome.browser.webapps.TRIED_EXTRACTING_DEX";
27
28 /**
29 * Tries to extract the WebAPK runtime dex from the Chrome APK if it has not tried already.
30 * Should not be called on UI thread.
31 */
32 public static void updateWebApksIfNeeded() {
33 assert !ThreadUtils.runningOnUiThread();
34
35 SharedPreferences preferences = ContextUtils.getAppSharedPreferences();
36 if (preferences.getBoolean(TRIED_EXTRACTING_DEX_PREF, false)) {
37 return;
38 }
39
40 SharedPreferences.Editor editor = preferences.edit();
Peter Wen 2016/05/26 15:19:39 It's often cleaner to do this in one line, but it'
41 editor.putBoolean(TRIED_EXTRACTING_DEX_PREF, true);
42 editor.apply();
43
44 Context context = ContextUtils.getApplicationContext();
45 File dexDir = context.getDir("dex", Context.MODE_PRIVATE);
46 File dexFile = new File(dexDir, "web_apk.dex");
47 if (!FileUtils.extractAsset(context, "web_apk.dex", dexFile)
48 || !DexOptimizer.optimize(dexFile)) {
49 return;
50 }
51
52 // Make dex file world-readable so that WebAPK can use it.
53 dexFile.setReadable(true, false);
54 }
55 }
OLDNEW
« 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