From 87af7314d4319a0ccaaf466a25e3fe4f416cc953 Mon Sep 17 00:00:00 2001 From: Kristian Monsen Date: Fri, 9 Sep 2011 02:12:51 +0100 Subject: [PATCH] Cleanup for bug 5278763 Variable is not needed, and removing unneeded check Also throwing an exception if sContext gets set to null. Change-Id: Ic61ba4c88a162eb730e166f0e9f477e809b51f42 --- core/java/android/webkit/CookieSyncManager.java | 4 ++++ core/java/android/webkit/JniUtil.java | 16 +++++++--------- core/java/android/webkit/WebView.java | 4 ++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/core/java/android/webkit/CookieSyncManager.java b/core/java/android/webkit/CookieSyncManager.java index 313f7558bfe7c..a6998006e895a 100644 --- a/core/java/android/webkit/CookieSyncManager.java +++ b/core/java/android/webkit/CookieSyncManager.java @@ -88,6 +88,10 @@ public final class CookieSyncManager extends WebSyncManager { */ public static synchronized CookieSyncManager createInstance( Context context) { + if (context == null) { + throw new IllegalArgumentException("Invalid context argument"); + } + JniUtil.setContext(context); Context appContext = context.getApplicationContext(); if (sRef == null) { diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java index ef1641de73aa5..7759ff37053ed 100644 --- a/core/java/android/webkit/JniUtil.java +++ b/core/java/android/webkit/JniUtil.java @@ -39,25 +39,21 @@ class JniUtil { private static Boolean sUseChromiumHttpStack; private static Context sContext; - private static boolean initialized = false; - private static void checkInitialized() { - if (!initialized) { + if (sContext == null) { throw new IllegalStateException("Call CookieSyncManager::createInstance() or create a webview before using this class"); } } protected static synchronized void setContext(Context context) { - if (initialized) + if (sContext != null) { return; + } sContext = context.getApplicationContext(); - initialized = true; } protected static synchronized Context getContext() { - if (!initialized) - return null; return sContext; } @@ -68,8 +64,9 @@ class JniUtil { private static synchronized String getDatabaseDirectory() { checkInitialized(); - if (sDatabaseDirectory == null) + if (sDatabaseDirectory == null) { sDatabaseDirectory = sContext.getDatabasePath("dummy").getParent(); + } return sDatabaseDirectory; } @@ -81,8 +78,9 @@ class JniUtil { private static synchronized String getCacheDirectory() { checkInitialized(); - if (sCacheDirectory == null) + if (sCacheDirectory == null) { sCacheDirectory = sContext.getCacheDir().getAbsolutePath(); + } return sCacheDirectory; } diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 47abbc2e6d2d5..ca5d9506498a7 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -1050,6 +1050,10 @@ public class WebView extends AbsoluteLayout super(context, attrs, defStyle); checkThread(); + if (context == null) { + throw new IllegalArgumentException("Invalid context argument"); + } + // Used by the chrome stack to find application paths JniUtil.setContext(context);