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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java

Issue 2522053002: WebView: don't allow processes to share data dir. (Closed)
Patch Set: 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 | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/AwSecondBrowserProcessTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
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 7eb2c2b5bcebbe70587b1bd0a36b1b4a9335a544..797f8437fa712cf50ed02b2a1343fe477c0e7ec7 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwBrowserProcess.java
@@ -12,6 +12,7 @@ import org.chromium.android_webview.policy.AwPolicyProvider;
import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
+import org.chromium.base.PackageUtils;
import org.chromium.base.PathUtils;
import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader;
@@ -74,14 +75,14 @@ public abstract class AwBrowserProcess {
* Note: it is up to the caller to ensure this is only called once.
*/
public static void start() {
- tryObtainingDataDirLockOrDie();
+ final Context appContext = ContextUtils.getApplicationContext();
+ tryObtainingDataDirLock(appContext);
// We must post to the UI thread to cover the case that the user
// has invoked Chromium startup by using the (thread-safe)
// CookieManager rather than creating a WebView.
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
- final Context appContext = ContextUtils.getApplicationContext();
boolean multiProcess = CommandLine.getInstance().hasSwitch(
AwSwitches.WEBVIEW_SANDBOXED_RENDERER);
if (multiProcess) {
@@ -109,9 +110,32 @@ public abstract class AwBrowserProcess {
});
}
- private static void tryObtainingDataDirLockOrDie() {
- StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
- StrictMode.allowThreadDiskWrites();
+ private static boolean checkMinAppVersion(Context context, String packageName, int minVersion) {
+ String appName = context.getPackageName();
+ if (packageName.equals(appName)) {
+ int versionCode = PackageUtils.getPackageVersion(context, packageName);
+ if (versionCode < minVersion) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static void tryObtainingDataDirLock(Context context) {
+ boolean dieOnFailure = true;
+ // Old versions of Facebook apps share the same data dir with multiple processes; current
+ // versions avoid this issue.
+ if (checkMinAppVersion(context, "com.facebook.katana", 34592776)
Torne 2016/11/22 19:41:15 Minimum versions here were provided by facebook.
sgurun-gerrit only 2016/11/22 21:42:07 is our plan to extend this list similarly if more
+ || checkMinAppVersion(context, "com.facebook.lite", 37569469)
+ || checkMinAppVersion(context, "com.instagram.android", 35440022)) {
+ dieOnFailure = false;
+ }
+ // GMS shares the same data dir with multiple processes in some cases; see b/26879632.
+ if ("com.google.android.gms".equals(context.getPackageName())) {
+ dieOnFailure = false;
+ }
+
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
try {
String dataPath = PathUtils.getDataDirectory();
File lockFile = new File(dataPath, EXCLUSIVE_LOCK_FILE);
@@ -125,8 +149,13 @@ public abstract class AwBrowserProcess {
Log.w(TAG, "Failed to create lock file " + lockFile, e);
}
if (!success) {
- Log.w(TAG, "The app may have another WebView opened in a separate process. "
- + "This is not recommended and may stop working in future versions.");
+ final String error = "Using WebView from more than one process at once in a single "
+ + "app is not supported. https://crbug.com/558377";
+ if (dieOnFailure) {
+ throw new RuntimeException(error);
+ } else {
+ Log.w(TAG, error);
+ }
}
} finally {
StrictMode.setThreadPolicy(oldPolicy);
« no previous file with comments | « no previous file | android_webview/javatests/src/org/chromium/android_webview/test/AwSecondBrowserProcessTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698