From d1c68aa675d8d5586e2cda7df1ad56d5e4129e59 Mon Sep 17 00:00:00 2001 From: boliu Date: Fri, 25 Mar 2016 16:38:57 -0700 Subject: aw: Remove WindowAndroid caching Caching sCachedWindowAndroid is incorrect since it is possible for the one Application context to be wrapped differently. There is no point in caching ActivityWindowAndroid either due to the way ResourcesContextWrapperFactory works. So remove caching altogether and always create a new WindowAndroid instance. BUG=597526 Review URL: https://codereview.chromium.org/1831373003 Cr-Commit-Position: refs/heads/master@{#383408} --- .../org/chromium/android_webview/AwContents.java | 26 +++++----------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 046ccfc..1332679 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -82,7 +82,6 @@ import java.net.URL; import java.util.HashMap; import java.util.Locale; import java.util.Map; -import java.util.WeakHashMap; import java.util.concurrent.Callable; /** @@ -921,31 +920,16 @@ public class AwContents implements SmartClipProvider, return mWindowAndroid; } } - private static WindowAndroidWrapper sCachedWindowAndroid; - private static WeakHashMap sActivityContextWindowMap; - // getWindowAndroid is only called on UI thread, so there are no threading issues with lazy - // initialization. - @SuppressFBWarnings("LI_LAZY_INIT_STATIC") - private static WindowAndroidWrapper getWindowAndroid(Context context) { + private static WindowAndroidWrapper createWindowAndroid(Context context) { // TODO(boliu): WebView does not currently initialize ApplicationStatus, crbug.com/470582. boolean contextWrapsActivity = activityFromContext(context) != null; if (!contextWrapsActivity) { - if (sCachedWindowAndroid == null) { - sCachedWindowAndroid = new WindowAndroidWrapper(new WindowAndroid(context)); - } - return sCachedWindowAndroid; + return new WindowAndroidWrapper(new WindowAndroid(context)); } - if (sActivityContextWindowMap == null) sActivityContextWindowMap = new WeakHashMap<>(); - WindowAndroidWrapper activityWindowAndroid = sActivityContextWindowMap.get(context); - if (activityWindowAndroid == null) { - final boolean listenToActivityState = false; - activityWindowAndroid = new WindowAndroidWrapper( - new ActivityWindowAndroid(context, listenToActivityState)); - sActivityContextWindowMap.put(context, activityWindowAndroid); - } - return activityWindowAndroid; + final boolean listenToActivityState = false; + return new WindowAndroidWrapper(new ActivityWindowAndroid(context, listenToActivityState)); } @VisibleForTesting @@ -979,7 +963,7 @@ public class AwContents implements SmartClipProvider, WebContents webContents = nativeGetWebContents(mNativeAwContents); - mWindowAndroid = getWindowAndroid(mContext); + mWindowAndroid = createWindowAndroid(mContext); mContentViewCore = createAndInitializeContentViewCore(mContainerView, mContext, mInternalAccessAdapter, webContents, new AwGestureStateListener(), mContentViewClient, mZoomControls, mWindowAndroid.getWindowAndroid()); -- cgit v1.1