Bug 1888766 - Decouple the dismiss and profiler state update logics r=mleclair,android-reviewers,gl

Previously we had the `profilerViewModel.setProfilerState` call inside the
dismiss method. Because of this it was updating the profiler state prematurely
when user was pressing "upload profile" button and then returning home quickly.

After decoupling the dismiss and setProfilerState calls, now we only update the
profiler state once the profiler state changes, which makes sure that profiler
states in geckoview and ProfilerViewModel stay in sync.

Differential Revision: https://phabricator.services.mozilla.com/D206647
This commit is contained in:
Nazım Can Altınova 2024-04-16 22:48:46 +00:00
parent d0f70542e1
commit 644e75f157

View File

@ -56,9 +56,8 @@ class ProfilerStopDialogFragment : DialogFragment() {
}
}
override fun dismiss() {
private fun setProfilerState() {
profilerViewModel.setProfilerState(requireContext().components.core.engine.profiler!!.isProfilerActive())
super.dismiss()
}
@Composable
@ -111,7 +110,14 @@ class ProfilerStopDialogFragment : DialogFragment() {
) {
TextButton(
onClick = {
requireContext().components.core.engine.profiler?.stopProfiler({}, {})
requireContext().components.core.engine.profiler?.stopProfiler(
onSuccess = {
setProfilerState()
},
onError = {
setProfilerState()
},
)
dismiss()
},
) {
@ -162,6 +168,7 @@ class ProfilerStopDialogFragment : DialogFragment() {
resources.getString(message) + extra,
Toast.LENGTH_LONG,
).show()
setProfilerState()
dismiss()
}