[Android TRM] Add TabResumptionModuleEnablement and tweak isEligible().
The decision logic for whether the Tab Resumption Module shows will be
further complicated by upcoming addition of Local Tab suggestions. This
CL refactors the TRM by extracting the current logic to a new class
TabResumptionModuleEnablement.
The decision logic has multiple layers:
1. Feature enablement: Overarching Chrome setting (e.g., chrome://flags,
policy). Magic Stack calls ModuleProviderBuilder.isEligible() to get
this and quickly decide whether the Builder should be instantiated.
2. Other user settings: Runtime-tweakable settings required by the
module. When Magic Stack calls ModuleProviderBuilder.build() these
get checked. In general, these can be used to decide whether to
instantiate suggestion Providers. Also, an already-shown TRM can
dynamically disappear on settings change. For TRM, these settings
are:
* Does the user allows the module to be shown?
* Is the user signed in?
* Is sync enabled?
3. Data availability: The TRM only shows if suggestions exist. For
Foreign Session suggestions, this is not known in build(), and thus
does not affect Magic Stack decisions and Provider instantiation.
However, for upcoming Local Tab suggestions, this can be determined
early on.
In TabResumptionModuleBuilder, previously isEligible() uses both (1) and
(2), and logs failure results there. This is semantically incorrect, so
this CL makes isEligible() to check (1) only (and log on failure), and
move the test for (2) to build() (and log on failure).
For the new class TabResumptionModuleEnablement (and inner classes),
static functions are used to wrap "atomic" conditions and to compose
these to clarify usage semantics. This also makes it easier to compute
@ModuleNotShownReason for logging.
Details:
* Remove TabResumptionModuleMetricsUtils.ModuleVisibility.
* It is replaced by @ModuleNotShownReason Integer, with null meaning
module should be shown.
* Add class TabResumptionModuleEnablement:
* Add inner class ForeignSession:
* Add isFeatureEnabled() for (1).
* Add isAllowedByConfig(), isSignedIn(), isSyncEnabled() for (2).
* Add shouldMakeProvider() as conjunction of (1) and all (2).
* Add isFeatureEnabled() for (1), replacing
TabResumptionModuleUtils.shouldShowTabResumptionModule()
* Add computeModuleNotShownReason() for logging, replacing
TabResumptionModuleUtils.computeModuleVisibility().
* TabResumptionModuleBuilder: Update usage.
Tests:
* Add TabResumptionModuleEnablementUnitTest(), taking 2 tests from
TabResumptionModuleUtilsUnitTest(). These tests now also check
@ModuleNotShownReason values (or null).
Bug: 332588018
Change-Id: Ibe8f3dacc9537f9c3610950c38e949334f9066a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5449681
Reviewed-by: Xi Han <hanxi@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1286720}
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all users to experience the web.
The project's web site is https://www.chromium.org.
To check out the source code locally, don't use git clone! Instead, follow the instructions on how to get the code.
Documentation in the source is rooted in docs/README.md.
Learn how to Get Around the Chromium Source Code Directory Structure.
For historical reasons, there are some small top level directories. Now the guidance is that new top level directories are for product (e.g. Chrome, Android WebView, Ash). Even if these products have multiple executables, the code should be in subdirectories of the product.
If you found a bug, please file it at https://crbug.com/new.