pwa_install_path_tracker.cc 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/webapps/browser/pwa_install_path_tracker.h"
  5. #include <string>
  6. #include "base/metrics/histogram_functions.h"
  7. #include "base/notreached.h"
  8. namespace webapps {
  9. namespace {
  10. void LogHistogram(PwaInstallPathTracker::InstallPathMetric metric) {
  11. base::UmaHistogramEnumeration("WebApk.Install.PathToInstall", metric);
  12. }
  13. } // anonymous namespace
  14. PwaInstallPathTracker::PwaInstallPathTracker() = default;
  15. PwaInstallPathTracker::~PwaInstallPathTracker() = default;
  16. void PwaInstallPathTracker::TrackInstallPath(
  17. bool bottom_sheet,
  18. WebappInstallSource install_source) {
  19. bottom_sheet_ = bottom_sheet;
  20. install_source_ = install_source;
  21. PwaInstallPathTracker::InstallPathMetric metric = GetInstallPathMetric();
  22. if (metric != InstallPathMetric::kUnknownMetric)
  23. LogHistogram(metric);
  24. }
  25. void PwaInstallPathTracker::TrackIphWasShown() {
  26. iph_was_shown_ = true;
  27. }
  28. PwaInstallPathTracker::InstallPathMetric
  29. PwaInstallPathTracker::GetInstallPathMetric() {
  30. if (bottom_sheet_) {
  31. switch (install_source_) {
  32. case WebappInstallSource::MENU_BROWSER_TAB:
  33. case WebappInstallSource::MENU_CUSTOM_TAB:
  34. return iph_was_shown_ ? InstallPathMetric::kAppMenuBottomSheetWithIph
  35. : InstallPathMetric::kAppMenuBottomSheet;
  36. case WebappInstallSource::API_BROWSER_TAB:
  37. case WebappInstallSource::API_CUSTOM_TAB:
  38. return iph_was_shown_
  39. ? InstallPathMetric::kApiInitiatedBottomSheetWithIph
  40. : InstallPathMetric::kApiInitiatedBottomSheet;
  41. case WebappInstallSource::AMBIENT_BADGE_BROWSER_TAB:
  42. case WebappInstallSource::AMBIENT_BADGE_CUSTOM_TAB:
  43. case WebappInstallSource::RICH_INSTALL_UI_WEBLAYER:
  44. return iph_was_shown_ ? InstallPathMetric::kAmbientBottomSheetWithIph
  45. : InstallPathMetric::kAmbientBottomSheet;
  46. default:
  47. NOTREACHED();
  48. break;
  49. }
  50. } else {
  51. switch (install_source_) {
  52. case WebappInstallSource::MENU_BROWSER_TAB:
  53. case WebappInstallSource::MENU_CUSTOM_TAB:
  54. return iph_was_shown_ ? InstallPathMetric::kAppMenuInstallWithIph
  55. : InstallPathMetric::kAppMenuInstall;
  56. case WebappInstallSource::API_BROWSER_TAB:
  57. case WebappInstallSource::API_CUSTOM_TAB:
  58. return iph_was_shown_ ? InstallPathMetric::kApiInitiatedInstallWithIph
  59. : InstallPathMetric::kApiInitiatedInstall;
  60. case WebappInstallSource::AMBIENT_BADGE_BROWSER_TAB:
  61. case WebappInstallSource::AMBIENT_BADGE_CUSTOM_TAB:
  62. case WebappInstallSource::RICH_INSTALL_UI_WEBLAYER:
  63. return iph_was_shown_ ? InstallPathMetric::kAmbientInfobarWithIph
  64. : InstallPathMetric::kAmbientInfobar;
  65. default:
  66. NOTREACHED();
  67. break;
  68. }
  69. }
  70. return InstallPathMetric::kUnknownMetric;
  71. }
  72. void PwaInstallPathTracker::Reset() {
  73. install_source_ = WebappInstallSource::COUNT;
  74. bottom_sheet_ = false;
  75. iph_was_shown_ = false;
  76. }
  77. } // namespace webapps