android-components / mozilla.components.browser.session / SessionManager

SessionManager

class SessionManager : Observable<Observer> (source)

This class provides access to a centralized registry of all active sessions.

Types

Name Summary
EngineSessionLinker class EngineSessionLinker
This class only exists for migrating from browser-session to browser-state. We need a way to dispatch the corresponding browser actions when an engine session is linked and unlinked.
Observer interface Observer
Interface to be implemented by classes that want to observe the session manager.
Snapshot data class Snapshot

Constructors

Name Summary
<init> SessionManager(engine: Engine, store: BrowserStore? = null, delegate: LegacySessionManager = LegacySessionManager(engine, EngineSessionLinker(store)))
This class provides access to a centralized registry of all active sessions.

Properties

Name Summary
all val all: List<Session>
Returns a list of all active sessions (including CustomTab sessions).
engine val engine: Engine
selectedSession val selectedSession: Session?
Gets the currently selected session if there is one.
selectedSessionOrThrow val selectedSessionOrThrow: Session
Gets the currently selected session or throws an IllegalStateException if no session is selected.
sessions val sessions: List<Session>
Returns a list of active sessions and filters out sessions used for CustomTabs.
size val size: Int
Returns the number of session including CustomTab sessions.

Functions

Name Summary
add fun add(session: Session, selected: Boolean = false, engineSession: EngineSession? = null, parent: Session? = null): Unit
Adds the provided session.fun add(sessions: List<Session>): Unit
Adds multiple sessions.
createSessionSnapshot fun createSessionSnapshot(session: Session): Item
Produces a Snapshot.Item of a single Session, suitable for restoring via SessionManager.restore.
createSnapshot fun createSnapshot(): Snapshot
Produces a snapshot of this manager’s state, suitable for restoring via SessionManager.restore. Only regular sessions are included in the snapshot. Private and Custom Tab sessions are omitted.
findSessionById fun findSessionById(id: String): Session?
Finds and returns the session with the given id. Returns null if no matching session could be found.
getEngineSession fun getEngineSession(session: Session = selectedSessionOrThrow): EngineSession?
Gets the linked engine session for the provided session (if it exists).
getOrCreateEngineSession fun getOrCreateEngineSession(session: Session = selectedSessionOrThrow): EngineSession
Gets the linked engine session for the provided session and creates it if needed.
onLowMemory fun onLowMemory(): Unit
Informs this SessionManager that the OS is in low memory condition so it can reduce its allocated objects.
remove fun remove(session: Session = selectedSessionOrThrow, selectParentIfExists: Boolean = false): Unit
Removes the provided session. If no session is provided then the selected session is removed.
removeAll fun removeAll(): Unit
Removes all sessions including CustomTab sessions.
removeSessions fun removeSessions(): Unit
Removes all sessions but CustomTab sessions.
restore fun restore(snapshot: Snapshot, updateSelection: Boolean = true): Unit
Restores sessions from the provided Snapshot.
select fun select(session: Session): Unit
Marks the given session as selected.

Companion Object Properties

Name Summary
NO_SELECTION const val NO_SELECTION: Int

Extension Functions

Name Summary
runWithSession fun SessionManager.runWithSession(sessionId: String?, block: SessionManager.(Session) -> Boolean): Boolean
Tries to find a session with the provided session ID and runs the block if found.
runWithSessionIdOrSelected fun SessionManager.runWithSessionIdOrSelected(sessionId: String?, block: SessionManager.(Session) -> Unit): Boolean
Tries to find a session with the provided session ID or uses the selected session and runs the block if found.