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

Side by Side Diff: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java

Issue 1888773004: 🙅 Bind a WebAPK to its "host" browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add template apk Created 4 years, 8 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 package org.chromium.base.library_loader; 5 package org.chromium.base.library_loader;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.SharedPreferences;
10 import android.content.pm.ApplicationInfo; 9 import android.content.pm.ApplicationInfo;
11 import android.content.pm.PackageInfo; 10 import android.content.pm.PackageInfo;
12 import android.content.pm.PackageManager.NameNotFoundException;
13 import android.os.AsyncTask; 11 import android.os.AsyncTask;
14 import android.os.Build; 12 import android.os.Build;
15 import android.os.SystemClock; 13 import android.os.SystemClock;
16 14
17 import org.chromium.base.CommandLine; 15 import org.chromium.base.CommandLine;
18 import org.chromium.base.Log; 16 import org.chromium.base.Log;
19 import org.chromium.base.PackageUtils; 17 import org.chromium.base.PackageUtils;
20 import org.chromium.base.TraceEvent; 18 import org.chromium.base.TraceEvent;
21 import org.chromium.base.annotations.CalledByNative; 19 import org.chromium.base.annotations.CalledByNative;
22 import org.chromium.base.annotations.JNINamespace; 20 import org.chromium.base.annotations.JNINamespace;
23 import org.chromium.base.metrics.RecordHistogram; 21 import org.chromium.base.metrics.RecordHistogram;
24 import org.chromium.minting.lib.common.WebAPKConstants; 22 import org.chromium.minting.lib.common.WebAPKUtils;
25 23
26 import java.util.concurrent.atomic.AtomicBoolean; 24 import java.util.concurrent.atomic.AtomicBoolean;
27 25
28 import javax.annotation.Nullable; 26 import javax.annotation.Nullable;
29 27
30 /** 28 /**
31 * This class provides functionality to load and register the native libraries. 29 * This class provides functionality to load and register the native libraries.
32 * Callers are allowed to separate loading the libraries from initializing them. 30 * Callers are allowed to separate loading the libraries from initializing them.
33 * This may be an advantage for Android Webview, where the libraries can be load ed 31 * This may be an advantage for Android Webview, where the libraries can be load ed
34 * by the zygote process, but then needs per process initialization after the 32 * by the zygote process, but then needs per process initialization after the
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // in the final .apk don't need to be explicitly loaded. 263 // in the final .apk don't need to be explicitly loaded.
266 if (linker.isChromiumLinkerLibrary(library)) { 264 if (linker.isChromiumLinkerLibrary(library)) {
267 if (DEBUG) Log.i(TAG, "ignoring self-linker load"); 265 if (DEBUG) Log.i(TAG, "ignoring self-linker load");
268 continue; 266 continue;
269 } 267 }
270 268
271 // Determine where the library should be loaded from. 269 // Determine where the library should be loaded from.
272 String zipFilePath = null; 270 String zipFilePath = null;
273 String libFilePath = System.mapLibraryName(library); 271 String libFilePath = System.mapLibraryName(library);
274 if (Linker.isInZipFile()) { 272 if (Linker.isInZipFile()) {
275 SharedPreferences prefs = context.getSharedPreferenc es( 273 Context contextForApk = (mLibraryProcessType == Libr aryProcessType.PROCESS_WEBAPK_CHILD)
276 WebAPKConstants.MINT_PREFS, Context.MODE_PRI VATE); 274 ? WebAPKUtils.getHostBrowserContext(context) : context;
277 String packageString = prefs.getString(
278 WebAPKConstants.HOST_PACKAGE_PREF,
279 WebAPKConstants.DEFAULT_HOST_PACKAGE_NAME);
280 Context remoteContext = context;
281 if (mLibraryProcessType == LibraryProcessType.PROCES S_WEBAPK_CHILD) {
282 try {
283 // Construct the context of the WebAPK host, which has native
284 // libraries that the WebAPK.
285 Log.w(TAG, "package name from context: %s",
286 context.getPackageName());
287 remoteContext =
288 context.getApplicationContext().crea tePackageContext(
289 packageString,
290 Context.CONTEXT_IGNORE_SECUR ITY
291 | Context.CONTEXT_INCLUDE_CO DE);
292 } catch (NameNotFoundException e) {
293 e.printStackTrace();
294 }
295 }
296 // Load directly from the APK. 275 // Load directly from the APK.
297 zipFilePath = getLibraryApkPath(remoteContext); 276 zipFilePath = getLibraryApkPath(contextForApk);
298 Log.i(TAG, "Loading " + library + " from within " + zipFilePath); 277 Log.i(TAG, "Loading " + library + " from within " + zipFilePath);
299 } else { 278 } else {
300 // The library is in its own file. 279 // The library is in its own file.
301 Log.i(TAG, "Loading " + library); 280 Log.i(TAG, "Loading " + library);
302 } 281 }
303 282
304 // Load the library using this Linker. May throw Unsatis fiedLinkError. 283 // Load the library using this Linker. May throw Unsatis fiedLinkError.
305 loadLibrary(linker, zipFilePath, libFilePath); 284 loadLibrary(linker, zipFilePath, libFilePath);
306 } 285 }
307 286
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 493
515 // Finds the ranges corresponding to the native library pages, forks a new 494 // Finds the ranges corresponding to the native library pages, forks a new
516 // process to prefetch these pages and waits for it. The new process then 495 // process to prefetch these pages and waits for it. The new process then
517 // terminates. This is blocking. 496 // terminates. This is blocking.
518 private static native boolean nativeForkAndPrefetchNativeLibrary(); 497 private static native boolean nativeForkAndPrefetchNativeLibrary();
519 498
520 // Returns the percentage of the native library code page that are currently reseident in 499 // Returns the percentage of the native library code page that are currently reseident in
521 // memory. 500 // memory.
522 private static native int nativePercentageOfResidentNativeLibraryCode(); 501 private static native int nativePercentageOfResidentNativeLibraryCode();
523 } 502 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698