summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfeng@chromium.org <feng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 14:42:19 +0000
committerfeng@chromium.org <feng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-03 14:42:19 +0000
commiteb4319e9a9d5088660f465b652c54b187bf951c8 (patch)
tree8f07237ace42653e54b1cc2d1e67b7bcd5751ed9
parent9e49614d56fe1369ecaec4f802e3001f6a6b0638 (diff)
downloadchromium_src-eb4319e9a9d5088660f465b652c54b187bf951c8.zip
chromium_src-eb4319e9a9d5088660f465b652c54b187bf951c8.tar.gz
chromium_src-eb4319e9a9d5088660f465b652c54b187bf951c8.tar.bz2
[Android] Fix a few issues related to old lib deletion.
Discovered following issues: 1. after each native library load, the code starts a thread to delete old libs; 2. render process also tries to delete old libs; 3. Context.getDir(...) creates the directory if not existing, so existence test is always successful, and assertion may fail; The CL fixes these issues. LibraryLoader.ensureInitialized and LibraryLoader.loadNow have a second boolean parameter, inBrowserProcess, used by caller to indicate whether the code should try to delete old libs. BUG=357655 Review URL: https://codereview.chromium.org/217283005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261382 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java2
-rw-r--r--base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java58
-rw-r--r--base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java28
-rw-r--r--content/public/android/java/src/org/chromium/content/app/ChildProcessService.java2
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java2
-rw-r--r--content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java2
-rw-r--r--content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java2
-rw-r--r--content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java2
-rw-r--r--content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestActivity.java2
-rw-r--r--content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java2
-rw-r--r--mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java2
11 files changed, 63 insertions, 41 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
index 589ca62..b3aa4f8 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
@@ -33,7 +33,7 @@ public abstract class AwBrowserProcess {
public static void loadLibrary() {
PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX);
try {
- LibraryLoader.loadNow(null);
+ LibraryLoader.loadNow();
initTraceEvent();
} catch (ProcessInitException e) {
throw new RuntimeException("Cannot load WebView", e);
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
index c3b3b35f..4b922d5 100644
--- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
+++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java
@@ -47,14 +47,20 @@ public class LibraryLoader {
// The flag is used to report UMA stats later.
private static boolean sNativeLibraryHackWasUsed = false;
+ // TODO(fqian): Remove this method once downstream CL is
+ // committed.
+ public static void ensureInitialized(Context context) throws ProcessInitException {
+ ensureInitialized(context, true);
+ }
/**
- * TODO: http://crbug.com/354655
- * remove this method once WebViewChromiumFactoryProvider.java
- * changes the call to ensureInitialized(null).
+ * The same as ensureInitialized(null, false), should only be called
+ * by non-browser processes.
+ *
+ * @throws ProcessInitException
*/
public static void ensureInitialized() throws ProcessInitException {
- ensureInitialized(null);
+ ensureInitialized(null, false);
}
/**
@@ -70,14 +76,19 @@ public class LibraryLoader {
* will extract the native libraries from APK. This is a hack used to
* work around some Sony devices with the following platform bug:
* http://b/13216167.
+ *
+ * @param shouldDeleteOldWorkaroundLibraries The flag tells whether the method
+ * should delete the old workaround libraries or not.
*/
- public static void ensureInitialized(Context context) throws ProcessInitException {
+ public static void ensureInitialized(
+ Context context, boolean shouldDeleteOldWorkaroundLibraries)
+ throws ProcessInitException {
synchronized (sLock) {
if (sInitialized) {
// Already initialized, nothing to do.
return;
}
- loadAlreadyLocked(context);
+ loadAlreadyLocked(context, shouldDeleteOldWorkaroundLibraries);
initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull());
}
}
@@ -92,17 +103,32 @@ public class LibraryLoader {
}
/**
+ * The same as loadNow(null, false), should only be called by
+ * non-browser process.
+ *
+ * @throws ProcessInitException
+ */
+ public static void loadNow() throws ProcessInitException {
+ loadNow(null, false);
+ }
+
+ /**
* Loads the library and blocks until the load completes. The caller is responsible
* for subsequently calling ensureInitialized().
* May be called on any thread, but should only be called once. Note the thread
* this is called on will be the thread that runs the native code's static initializers.
* See the comment in doInBackground() for more considerations on this.
*
+ * @param context The context the code is running, or null if it doesn't have one.
+ * @param shouldDeleteOldWorkaroundLibraries The flag tells whether the method
+ * should delete the old workaround libraries or not.
+ *
* @throws ProcessInitException if the native library failed to load.
*/
- public static void loadNow(Context context) throws ProcessInitException {
+ public static void loadNow(Context context, boolean shouldDeleteOldWorkaroundLibraries)
+ throws ProcessInitException {
synchronized (sLock) {
- loadAlreadyLocked(context);
+ loadAlreadyLocked(context, shouldDeleteOldWorkaroundLibraries);
}
}
@@ -120,7 +146,9 @@ public class LibraryLoader {
}
// Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code
- private static void loadAlreadyLocked(Context context) throws ProcessInitException {
+ private static void loadAlreadyLocked(
+ Context context, boolean shouldDeleteOldWorkaroundLibraries)
+ throws ProcessInitException {
try {
if (!sLoaded) {
assert !sInitialized;
@@ -137,10 +165,6 @@ public class LibraryLoader {
} else {
try {
System.loadLibrary(library);
- if (context != null) {
- LibraryLoaderHelper.deleteWorkaroundLibrariesAsynchronously(
- context);
- }
} catch (UnsatisfiedLinkError e) {
if (context != null
&& LibraryLoaderHelper.tryLoadLibraryUsingWorkaround(context,
@@ -153,6 +177,14 @@ public class LibraryLoader {
}
}
if (useChromiumLinker) Linker.finishLibraryLoad();
+
+ if (context != null
+ && shouldDeleteOldWorkaroundLibraries
+ && !sNativeLibraryHackWasUsed) {
+ LibraryLoaderHelper.deleteWorkaroundLibrariesAsynchronously(
+ context);
+ }
+
long stopTime = SystemClock.uptimeMillis();
Log.i(TAG, String.format("Time to load native libraries: %d ms (timestamps %d-%d)",
stopTime - startTime,
diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java
index 7eeb2c8..0751beb 100644
--- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java
+++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoaderHelper.java
@@ -133,10 +133,7 @@ public class LibraryLoaderHelper {
sLibrariesWereUnpacked = true;
File libDir = getWorkaroundLibDir(context);
- if (libDir.exists()) {
- assert libDir.isDirectory();
- deleteDirectorySync(libDir);
- }
+ deleteDirectorySync(libDir);
try {
ApplicationInfo appInfo = context.getApplicationInfo();
@@ -210,19 +207,14 @@ public class LibraryLoaderHelper {
*
* @param context
*/
- static void deleteWorkaroundLibrariesAsynchronously(Context context) {
+ static void deleteWorkaroundLibrariesAsynchronously(final Context context) {
// Child process should not reach here.
- final File libDir = getWorkaroundLibDir(context);
- if (libDir.exists()) {
- assert libDir.isDirectory();
- // Async deletion
- new Thread() {
- @Override
- public void run() {
- deleteDirectorySync(libDir);
- }
- }.start();
- }
+ new Thread() {
+ @Override
+ public void run() {
+ deleteWorkaroundLibrariesSynchronously(context);
+ }
+ }.start();
}
/**
@@ -232,9 +224,7 @@ public class LibraryLoaderHelper {
*/
public static void deleteWorkaroundLibrariesSynchronously(Context context) {
File libDir = getWorkaroundLibDir(context);
- if (libDir.exists()) {
- deleteDirectorySync(libDir);
- }
+ deleteDirectorySync(libDir);
}
private static void deleteDirectorySync(File dir) {
diff --git a/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java b/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java
index ed694b7..2e028c46 100644
--- a/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java
+++ b/content/public/android/java/src/org/chromium/content/app/ChildProcessService.java
@@ -141,7 +141,7 @@ public class ChildProcessService extends Service {
}
}
try {
- LibraryLoader.loadNow(getApplicationContext());
+ LibraryLoader.loadNow(getApplicationContext(), false);
} catch (ProcessInitException e) {
Log.e(TAG, "Failed to load native library, exiting child process", e);
System.exit(-1);
diff --git a/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java b/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java
index 4bc70d3..4b4420a 100644
--- a/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java
+++ b/content/public/android/java/src/org/chromium/content/browser/BrowserStartupController.java
@@ -271,7 +271,7 @@ public class BrowserStartupController {
// Normally Main.java will have already loaded the library asynchronously, we only need
// to load it here if we arrived via another flow, e.g. bookmark access & sync setup.
- LibraryLoader.ensureInitialized(mContext);
+ LibraryLoader.ensureInitialized(mContext, true);
// TODO(yfriedman): Remove dependency on a command line flag for this.
DeviceUtils.addDeviceSpecificUserAgentSwitch(mContext);
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java
index 3bb1ee4..a0a3d4e 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentCommandLineTest.java
@@ -47,7 +47,7 @@ public class ContentCommandLineTest extends InstrumentationTestCase {
public void run() {
ContentShellApplication.initializeApplicationParameters();
try {
- LibraryLoader.ensureInitialized(null);
+ LibraryLoader.ensureInitialized();
} catch (ProcessInitException e) {
throw new Error(e);
}
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java
index 5ff9949..66c17e0f 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ImportantFileWriterAndroidTest.java
@@ -34,7 +34,7 @@ public class ImportantFileWriterAndroidTest extends InstrumentationTestCase {
public void run() {
ContentShellApplication.initializeApplicationParameters();
try {
- LibraryLoader.ensureInitialized(null);
+ LibraryLoader.ensureInitialized();
} catch (ProcessInitException e) {
throw new Error(e);
}
diff --git a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java
index 987a6d2..f00dfd1 100644
--- a/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java
+++ b/content/shell/android/browsertests_apk/src/org/chromium/content_browsertests_apk/ContentBrowserTestsActivity.java
@@ -34,7 +34,7 @@ public class ContentBrowserTestsActivity extends Activity {
super.onCreate(savedInstanceState);
try {
- LibraryLoader.ensureInitialized(null);
+ LibraryLoader.ensureInitialized();
} catch (ProcessInitException e) {
Log.i(TAG, "Cannot load content_browsertests:" + e);
System.exit(-1);
diff --git a/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestActivity.java b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestActivity.java
index 91dc5f3..b3bca6b 100644
--- a/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestActivity.java
+++ b/content/shell/android/linker_test_apk/src/org/chromium/chromium_linker_test_apk/ChromiumLinkerTestActivity.java
@@ -85,7 +85,7 @@ public class ChromiumLinkerTestActivity extends Activity {
// Load the library in the browser process, this will also run the test
// runner in this process.
try {
- LibraryLoader.ensureInitialized(null);
+ LibraryLoader.ensureInitialized();
} catch (ProcessInitException e) {
Log.i(TAG, "Cannot load chromium_linker_test:" + e);
}
diff --git a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java
index a8424d7..be8ceaf 100644
--- a/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java
+++ b/content/shell/android/shell_apk/src/org/chromium/content_shell_apk/ContentShellActivity.java
@@ -56,7 +56,7 @@ public class ContentShellActivity extends Activity {
DeviceUtils.addDeviceSpecificUserAgentSwitch(this);
try {
- LibraryLoader.ensureInitialized(null);
+ LibraryLoader.ensureInitialized();
} catch (ProcessInitException e) {
Log.e(TAG, "ContentView initialization failed.", e);
// Since the library failed to initialize nothing in the application
diff --git a/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java b/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java
index c697f5e..15a5861 100644
--- a/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java
+++ b/mojo/shell/android/apk/src/org/chromium/mojo_shell_apk/MojoShellActivity.java
@@ -26,7 +26,7 @@ public class MojoShellActivity extends Activity {
super.onCreate(savedInstanceState);
try {
- LibraryLoader.ensureInitialized(null);
+ LibraryLoader.ensureInitialized();
} catch (ProcessInitException e) {
Log.e(TAG, "libmojo_shell initialization failed.", e);
finish();