From dbb511491b6901a6175ebd87cc19051c21e5a2a9 Mon Sep 17 00:00:00 2001 From: Imanol Fernandez Date: Mon, 2 Dec 2019 12:12:45 +0100 Subject: [PATCH] Use CopyOnWriteArrayList for all Session event listeners --- .../vrbrowser/browser/engine/Session.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java index ddd50f426..ac7f8c2c3 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/browser/engine/Session.java @@ -42,13 +42,12 @@ import org.mozilla.vrbrowser.telemetry.TelemetryWrapper; import org.mozilla.vrbrowser.utils.BitmapCache; import org.mozilla.vrbrowser.utils.InternalPages; -import org.mozilla.vrbrowser.utils.StringUtils; import org.mozilla.vrbrowser.utils.SystemUtils; import java.net.URI; import java.net.URISyntaxException; -import java.util.LinkedList; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -66,17 +65,17 @@ public class Session implements ContentBlocking.Delegate, GeckoSession.Navigatio private static UserAgentOverride sUserAgentOverride; private static final long KEEP_ALIVE_DURATION_MS = 1000; // 1 second. - private transient LinkedList mNavigationListeners; - private transient LinkedList mProgressListeners; - private transient LinkedList mContentListeners; - private transient LinkedList mSessionChangeListeners; - private transient LinkedList mTextInputListeners; - private transient LinkedList mVideoAvailabilityListeners; - private transient LinkedList mBitmapChangedListeners; - private transient LinkedList mSelectionActionListeners; + private transient CopyOnWriteArrayList mNavigationListeners; + private transient CopyOnWriteArrayList mProgressListeners; + private transient CopyOnWriteArrayList mContentListeners; + private transient CopyOnWriteArrayList mSessionChangeListeners; + private transient CopyOnWriteArrayList mTextInputListeners; + private transient CopyOnWriteArrayList mVideoAvailabilityListeners; + private transient CopyOnWriteArrayList mBitmapChangedListeners; + private transient CopyOnWriteArrayList mSelectionActionListeners; private SessionState mState; - private LinkedList mQueuedCalls = new LinkedList<>(); + private CopyOnWriteArrayList mQueuedCalls = new CopyOnWriteArrayList<>(); private transient GeckoSession.PermissionDelegate mPermissionDelegate; private transient GeckoSession.PromptDelegate mPromptDelegate; private transient GeckoSession.HistoryDelegate mHistoryDelegate; @@ -113,14 +112,14 @@ protected Session(Context aContext, GeckoRuntime aRuntime, @NonNull SessionState } private void initialize() { - mNavigationListeners = new LinkedList<>(); - mProgressListeners = new LinkedList<>(); - mContentListeners = new LinkedList<>(); - mSessionChangeListeners = new LinkedList<>(); - mTextInputListeners = new LinkedList<>(); - mVideoAvailabilityListeners = new LinkedList<>(); - mSelectionActionListeners = new LinkedList<>(); - mBitmapChangedListeners = new LinkedList<>(); + mNavigationListeners = new CopyOnWriteArrayList<>(); + mProgressListeners = new CopyOnWriteArrayList<>(); + mContentListeners = new CopyOnWriteArrayList<>(); + mSessionChangeListeners = new CopyOnWriteArrayList<>(); + mTextInputListeners = new CopyOnWriteArrayList<>(); + mVideoAvailabilityListeners = new CopyOnWriteArrayList<>(); + mSelectionActionListeners = new CopyOnWriteArrayList<>(); + mBitmapChangedListeners = new CopyOnWriteArrayList<>(); if (mPrefs != null) { mPrefs.registerOnSharedPreferenceChangeListener(this); @@ -956,7 +955,7 @@ public GeckoResult onNewSession(@NonNull GeckoSession aSession, @N Session session = SessionStore.get().createSession(mState.mSettings, SESSION_DO_NOT_OPEN); session.mState.mParentId = mState.mId; session.mKeepAlive = mKeepAlive; - for (SessionChangeListener listener: new LinkedList<>(mSessionChangeListeners)) { + for (SessionChangeListener listener: mSessionChangeListeners) { listener.onStackSession(session); } mSessionChangeListeners.add(session);