1
0
Fork 0
fenix/app/src/main/java/org/mozilla/fenix/perf/StartupTimeline.kt

48 lines
1.9 KiB
Kotlin

/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 org.mozilla.fenix.perf
import androidx.annotation.UiThread
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.home.sessioncontrol.viewholders.topsites.TopSiteItemViewHolder
import org.mozilla.fenix.perf.StartupTimelineStateMachine.StartupActivity
import org.mozilla.fenix.perf.StartupTimelineStateMachine.StartupDestination
import org.mozilla.fenix.perf.StartupTimelineStateMachine.StartupState
/**
* A collection of functionality to instrument, measure, and understand startup performance. The
* responsibilities of this class are to update the internal [StartupState] based on the methods
* called and to delegate calls to its dependencies, which handle other functionality related to
* understanding startup.
*
* This class, and its dependencies, may need to be modified for any changes in startup.
*
* This class is not thread safe and should only be called from the main thread.
*/
@UiThread
object StartupTimeline {
private var state: StartupState = StartupState.Cold(StartupDestination.UNKNOWN)
private val reportFullyDrawn = StartupReportFullyDrawn()
fun onActivityCreateEndIntentReceiver() {
advanceState(StartupActivity.INTENT_RECEIVER)
}
fun onActivityCreateEndHome(activity: HomeActivity) {
advanceState(StartupActivity.HOME)
reportFullyDrawn.onActivityCreateEndHome(state, activity)
}
fun onTopSitesItemBound(holder: TopSiteItemViewHolder) {
// no advanceState associated with this method.
reportFullyDrawn.onTopSitesItemBound(state, holder)
}
private fun advanceState(startingActivity: StartupActivity) {
state = StartupTimelineStateMachine.getNextState(state, startingActivity)
}
}