Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Fixes #3671 BrowserState-SessionStore sync #3669

Merged
merged 2 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Session implements ContentBlocking.Delegate, GeckoSession.Navigatio
private transient byte[] mPrivatePage;
private transient boolean mFirstContentfulPaint;
private transient long mKeepAlive;
private transient boolean mSessionRemoved;
private transient boolean mSessionAdded;

public interface BitmapChangedListener {
void onBitmapChanged(Session aSession, Bitmap aBitmap);
Expand Down Expand Up @@ -120,13 +120,15 @@ protected Session(Context aContext, GeckoRuntime aRuntime,
mRuntime = aRuntime;
initialize();
mState = createSession(aSettings);
mSessionAdded = true;
}

protected Session(Context aContext, GeckoRuntime aRuntime, @NonNull SessionState aRestoreState) {
mContext = aContext;
mRuntime = aRuntime;
initialize();
mState = aRestoreState;
mSessionAdded = false;
}

private void initialize() {
Expand Down Expand Up @@ -170,12 +172,10 @@ protected void shutdown() {
}
}

if (!mSessionRemoved) {
mSessionChangeListeners.forEach(listener -> {
listener.onSessionRemoved(mState.mId);
});
mSessionRemoved = true;
}
mSessionChangeListeners.forEach(listener -> {
listener.onSessionRemoved(mState.mId);
mSessionAdded = false;
});

mQueuedCalls.clear();
mNavigationListeners.clear();
Expand Down Expand Up @@ -458,7 +458,7 @@ private void loadDefaultPage() {
}
}

private void restore() {
private void restore(boolean addSession) {
SessionSettings settings = mState.mSettings;
if (settings == null) {
settings = new SessionSettings.Builder()
Expand All @@ -472,9 +472,9 @@ private void restore() {

// We call restore when a session is first activated and when it's recreated.
// We only need to notify of the session creation if it's not a recreation.
if (mSessionRemoved) {
if (addSession) {
mSessionChangeListeners.forEach(listener -> listener.onSessionAdded(this));
mSessionRemoved = false;
mSessionAdded = true;
}
keianhzo marked this conversation as resolved.
Show resolved Hide resolved

openSession();
Expand Down Expand Up @@ -541,7 +541,7 @@ void recreateSession() {

mState = mState.recreate();

restore();
restore(false);
keianhzo marked this conversation as resolved.
Show resolved Hide resolved

for (SessionChangeListener listener: mSessionChangeListeners) {
listener.onSessionStateChanged(this, true);
Expand Down Expand Up @@ -803,7 +803,8 @@ public void setActive(boolean aActive) {
mState.setActive(aActive);

} else if (aActive) {
restore();
restore(!mSessionAdded);

} else {
Log.e(LOGTAG, "ERROR: Setting null GeckoView to inactive!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.util.Pair;

Expand Down Expand Up @@ -149,6 +148,7 @@ public void onTrackingProtectionLevelUpdated(int level) {
if (BuildConfig.DEBUG) {
mStoreSubscription = ComponentsAdapter.get().getStore().observeManually(browserState -> {
Log.d(LOGTAG, "Session status BEGIN");
Log.d(LOGTAG, "BrowserStore: " + browserState.getTabs().size() + ", SessionStore: " + mSessions.size());
for (int i=0; i<browserState.getTabs().size(); i++) {
Log.d(LOGTAG, "BrowserStore Session: " + browserState.getTabs().get(i).getId());
}
Expand Down Expand Up @@ -188,8 +188,8 @@ public Session createSession(boolean openSession, boolean aPrivateMode) {
Session createSession(@NonNull SessionSettings aSettings, @Session.SessionOpenModeFlags int aOpenMode) {
Session session = new Session(mContext, mRuntime, aSettings);
session.addSessionChangeListener(this);
onSessionAdded(session);
if (aOpenMode == Session.SESSION_OPEN) {
onSessionAdded(session);
session.openSession();
session.setActive(true);
}
Expand Down