Skip to content

Commit

Permalink
Complete migration from browser-session to browser-state.
Browse files Browse the repository at this point in the history
* Issue mozilla-mobile#10197: Move EngineObserver and EngineMiddleware to browser-state and refactor SessionManager dependency away.
* Issue mozilla-mobile#3532: Migrate TabsUseCases to use BrowserStore exclusively.
* Issue mozilla-mobile#10209: Migrate SessionUseCases to use BrowserStore exclusively.
* Issue mozilla-mobile#3532, mozilla-mobile#10209: Migrate components to use new UseCase APIs.
* Issue mozilla-mobile#10209: Migrate UndoMiddleware to use BrowserStore.
* Issue mozilla-mobile#3532: Migrate CustomTabsUseCases to use BrowserStore.
* Issue mozilla-mobile#10211: Migrate sample-browser to not depend on browser-session.
* Issue mozilla-mobile#10209: Remove browser-session dependency.
* Issue mozilla-mobile#3532: feature-tabs: Remove browser-session dependency.
* Issue mozilla-mobile#10209: Fix UndoMiddlewareTest
* Issue mozilla-mobile#10209: Refactor SessionUseCasesTest to not use SessionManager.
* Issue mozilla-mobile#10209: Fix SessionFeatureTest.
* Refactor support-migration tests to not use SessionManager.
* Fix tests in feature-contextmenu.
* Refactor feature-recentlyclosed tests to not use SessionManager
* Refactor browser-session-storage tests to not use SessionManager
* Refactor feature-intent tests to not use SessionManager
* Refactor feature-tabs tests to not use SessionManager pt. 1
* Refactor feature-customtabs tests to not depend on browser-session.
* Make sure initial load url flags are correct
* Refactor feature-tabs tests to not use SessionManager pt. 2
  • Loading branch information
pocmo committed May 7, 2021
1 parent 9de5d1b commit 20616f4
Show file tree
Hide file tree
Showing 59 changed files with 1,686 additions and 1,901 deletions.
2 changes: 0 additions & 2 deletions components/browser/session-storage/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ dependencies {

testImplementation project(':support-test')
testImplementation project(':support-test-libstate')
testImplementation project(':browser-session')
testImplementation project(':feature-tabs')
testImplementation Dependencies.androidx_test_core
testImplementation Dependencies.androidx_test_junit
Expand All @@ -58,7 +57,6 @@ dependencies {

androidTestImplementation project(':browser-engine-gecko')
androidTestImplementation project(':support-android-test')
androidTestImplementation project(':browser-session')
androidTestImplementation project(':feature-tabs')
androidTestImplementation Dependencies.androidx_test_core
androidTestImplementation Dependencies.androidx_test_runner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.engine.EngineMiddleware
import mozilla.components.browser.state.engine.EngineMiddleware
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.Engine
Expand Down Expand Up @@ -45,9 +43,8 @@ class FullRestoreTest {
// Set up
// -------------------------------------------------------------------------------------

val (sessionManager, store) = createSessionManagerAndStore(engine)

val tabsUseCases = TabsUseCases(store, sessionManager)
val store = createStore(engine)
val tabsUseCases = TabsUseCases(store)

// -------------------------------------------------------------------------------------
// Add a tab
Expand All @@ -74,8 +71,8 @@ class FullRestoreTest {

val storage = SessionStorage(context, engine)

val (newSessionManager, newStore) = createSessionManagerAndStore(engine)
val newUseCases = TabsUseCases(newStore, newSessionManager)
val newStore = createStore(engine)
val newUseCases = TabsUseCases(newStore)

assertNull(newStore.state.selectedTab)

Expand All @@ -94,28 +91,15 @@ class FullRestoreTest {
}
}

private fun createSessionManagerAndStore(
private fun createStore(
engine: Engine
): Pair<SessionManager, BrowserStore> {
): BrowserStore {
return runBlocking(Dispatchers.Main) {
val lookup = SessionManagerLookup()

val store = BrowserStore(middleware = EngineMiddleware.create(engine, lookup::lookup))

val sessionManager = SessionManager(engine, store)
lookup.sessionManager = sessionManager

Pair(sessionManager, store)
BrowserStore(middleware = EngineMiddleware.create(engine))
}
}
}

private class SessionManagerLookup {
var sessionManager: SessionManager? = null

fun lookup(tabId: String): Session? = sessionManager!!.findSessionById(tabId)
}

private fun waitFor(timeoutMs: Long = 10000, cadence: Long = 100, predicate: () -> Boolean) {
val start = SystemClock.elapsedRealtime()

Expand Down
1 change: 1 addition & 0 deletions components/browser/state/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dependencies {
testImplementation Dependencies.testing_junit
testImplementation Dependencies.testing_mockito
testImplementation Dependencies.testing_robolectric
testImplementation Dependencies.testing_coroutines
}

apply from: '../../../publish.gradle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package mozilla.components.browser.session.engine
package mozilla.components.browser.state.engine

import androidx.annotation.MainThread
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.engine.middleware.CrashMiddleware
import mozilla.components.browser.session.engine.middleware.CreateEngineSessionMiddleware
import mozilla.components.browser.session.engine.middleware.EngineDelegateMiddleware
import mozilla.components.browser.session.engine.middleware.LinkingMiddleware
import mozilla.components.browser.session.engine.middleware.SuspendMiddleware
import mozilla.components.browser.session.engine.middleware.TabsRemovedMiddleware
import mozilla.components.browser.session.engine.middleware.TrimMemoryMiddleware
import mozilla.components.browser.session.engine.middleware.WebExtensionMiddleware
import mozilla.components.browser.state.engine.middleware.CrashMiddleware
import mozilla.components.browser.state.engine.middleware.CreateEngineSessionMiddleware
import mozilla.components.browser.state.engine.middleware.EngineDelegateMiddleware
import mozilla.components.browser.state.engine.middleware.LinkingMiddleware
import mozilla.components.browser.state.engine.middleware.SuspendMiddleware
import mozilla.components.browser.state.engine.middleware.TabsRemovedMiddleware
import mozilla.components.browser.state.engine.middleware.TrimMemoryMiddleware
import mozilla.components.browser.state.engine.middleware.WebExtensionMiddleware
import mozilla.components.browser.state.action.BrowserAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.selector.findTabOrCustomTab
Expand All @@ -38,21 +37,18 @@ object EngineMiddleware {
*/
fun create(
engine: Engine,
sessionLookup: (String) -> Session?,
scope: CoroutineScope = MainScope()
): List<Middleware<BrowserState, BrowserAction>> {
return listOf(
EngineDelegateMiddleware(
engine,
sessionLookup,
scope
),
CreateEngineSessionMiddleware(
engine,
sessionLookup,
scope
),
LinkingMiddleware(scope, sessionLookup),
LinkingMiddleware(scope),
TabsRemovedMiddleware(scope),
SuspendMiddleware(scope),
WebExtensionMiddleware(),
Expand All @@ -67,7 +63,6 @@ object EngineMiddleware {
internal fun getOrCreateEngineSession(
engine: Engine,
logger: Logger,
sessionLookup: (String) -> Session?,
store: Store<BrowserState, BrowserAction>,
tabId: String
): EngineSession? {
Expand All @@ -87,23 +82,16 @@ internal fun getOrCreateEngineSession(
return it
}

return createEngineSession(engine, logger, sessionLookup, store, tab)
return createEngineSession(engine, logger, store, tab)
}

@MainThread
private fun createEngineSession(
engine: Engine,
logger: Logger,
sessionLookup: (String) -> Session?,
store: Store<BrowserState, BrowserAction>,
tab: SessionState
): EngineSession? {
val session = sessionLookup(tab.id)
if (session == null) {
logger.error("Requested creation of EngineSession without matching Session (${tab.id})")
return null
}

): EngineSession {
val engineSession = engine.createSession(tab.content.private, tab.contextId)
logger.debug("Created engine session for tab ${tab.id}")

Expand Down
Loading

0 comments on commit 20616f4

Please sign in to comment.