[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}
7 files changed
tree: bffc3b06f8dfb6681d9b114b04ced6c9697e5fc7
  1. android_webview/
  2. apps/
  3. ash/
  4. base/
  5. build/
  6. build_overrides/
  7. buildtools/
  8. cc/
  9. chrome/
  10. chromecast/
  11. chromeos/
  12. codelabs/
  13. components/
  14. content/
  15. courgette/
  16. crypto/
  17. dbus/
  18. device/
  19. docs/
  20. extensions/
  21. fuchsia_web/
  22. gin/
  23. google_apis/
  24. google_update/
  25. gpu/
  26. headless/
  27. infra/
  28. ios/
  29. ipc/
  30. media/
  31. mojo/
  32. native_client_sdk/
  33. net/
  34. pdf/
  35. ppapi/
  36. printing/
  37. remoting/
  38. rlz/
  39. sandbox/
  40. services/
  41. skia/
  42. sql/
  43. storage/
  44. styleguide/
  45. testing/
  46. third_party/
  47. tools/
  48. ui/
  49. url/
  50. webkit/
  51. .clang-format
  52. .clang-tidy
  53. .clangd
  54. .eslintrc.js
  55. .git-blame-ignore-revs
  56. .gitallowed
  57. .gitattributes
  58. .gitignore
  59. .gitmodules
  60. .gn
  61. .mailmap
  62. .rustfmt.toml
  63. .vpython3
  64. .yapfignore
  65. ATL_OWNERS
  66. AUTHORS
  67. BUILD.gn
  68. CODE_OF_CONDUCT.md
  69. codereview.settings
  70. CPPLINT.cfg
  71. DEPS
  72. DIR_METADATA
  73. LICENSE
  74. LICENSE.chromium_os
  75. OWNERS
  76. PRESUBMIT.py
  77. PRESUBMIT_test.py
  78. PRESUBMIT_test_mocks.py
  79. README.md
  80. WATCHLISTS
README.md

Logo Chromium

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.