navigation_metrics.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2013 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/navigation_metrics/navigation_metrics.h"
  5. #include "base/i18n/rtl.h"
  6. #include "base/metrics/histogram_macros.h"
  7. #include "base/metrics/user_metrics.h"
  8. #include "components/dom_distiller/core/url_constants.h"
  9. #include "components/profile_metrics/browser_profile_type.h"
  10. #include "components/url_formatter/url_formatter.h"
  11. #include "url/gurl.h"
  12. namespace navigation_metrics {
  13. const char kMainFrameScheme[] = "Navigation.MainFrameScheme2";
  14. const char kMainFrameSchemeDifferentPage[] =
  15. "Navigation.MainFrameSchemeDifferentPage2";
  16. const char kMainFrameSchemeOTR[] = "Navigation.MainFrameSchemeOTR2";
  17. const char kMainFrameSchemeDifferentPageOTR[] =
  18. "Navigation.MainFrameSchemeDifferentPageOTR2";
  19. const char kMainFrameHasRTLDomain[] = "Navigation.MainFrameHasRTLDomain2";
  20. const char kMainFrameHasRTLDomainDifferentPage[] =
  21. "Navigation.MainFrameHasRTLDomainDifferentPage2";
  22. const char kMainFrameProfileType[] = "Navigation.MainFrameProfileType2";
  23. namespace {
  24. const char* const kSchemeNames[] = {
  25. "unknown",
  26. url::kHttpScheme,
  27. url::kHttpsScheme,
  28. url::kFileScheme,
  29. url::kFtpScheme,
  30. url::kDataScheme,
  31. url::kJavaScriptScheme,
  32. url::kAboutScheme,
  33. "chrome",
  34. url::kBlobScheme,
  35. url::kFileSystemScheme,
  36. "chrome-native",
  37. "chrome-search",
  38. dom_distiller::kDomDistillerScheme,
  39. "devtools",
  40. "chrome-extension",
  41. "view-source",
  42. "externalfile",
  43. };
  44. static_assert(std::size(kSchemeNames) == static_cast<int>(Scheme::COUNT),
  45. "kSchemeNames should have Scheme::COUNT elements");
  46. } // namespace
  47. Scheme GetScheme(const GURL& url) {
  48. for (int i = static_cast<int>(Scheme::HTTP);
  49. i < static_cast<int>(Scheme::COUNT); ++i) {
  50. if (url.SchemeIs(kSchemeNames[i]))
  51. return static_cast<Scheme>(i);
  52. }
  53. return Scheme::UNKNOWN;
  54. }
  55. void RecordPrimaryMainFrameNavigation(
  56. const GURL& url,
  57. bool is_same_document,
  58. bool is_off_the_record,
  59. profile_metrics::BrowserProfileType profile_type) {
  60. Scheme scheme = GetScheme(url);
  61. UMA_HISTOGRAM_ENUMERATION(kMainFrameScheme, scheme, Scheme::COUNT);
  62. if (!is_same_document) {
  63. UMA_HISTOGRAM_ENUMERATION("Navigation.MainFrameSchemeDifferentPage2",
  64. scheme, Scheme::COUNT);
  65. UMA_HISTOGRAM_BOOLEAN("Navigation.MainFrameHasRTLDomainDifferentPage2",
  66. base::i18n::StringContainsStrongRTLChars(
  67. url_formatter::IDNToUnicode(url.host())));
  68. }
  69. UMA_HISTOGRAM_BOOLEAN("Navigation.MainFrameHasRTLDomain2",
  70. base::i18n::StringContainsStrongRTLChars(
  71. url_formatter::IDNToUnicode(url.host())));
  72. if (is_off_the_record) {
  73. UMA_HISTOGRAM_ENUMERATION("Navigation.MainFrameSchemeOTR2", scheme,
  74. Scheme::COUNT);
  75. if (!is_same_document) {
  76. UMA_HISTOGRAM_ENUMERATION("Navigation.MainFrameSchemeDifferentPageOTR2",
  77. scheme, Scheme::COUNT);
  78. }
  79. }
  80. UMA_HISTOGRAM_ENUMERATION("Navigation.MainFrameProfileType2", profile_type);
  81. }
  82. void RecordOmniboxURLNavigation(const GURL& url) {
  83. UMA_HISTOGRAM_ENUMERATION("Omnibox.URLNavigationScheme", GetScheme(url),
  84. Scheme::COUNT);
  85. }
  86. } // namespace navigation_metrics