network_utils.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2022 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 "ash/system/network/network_utils.h"
  5. #include "base/metrics/histogram_functions.h"
  6. #include "base/strings/strcat.h"
  7. namespace ash {
  8. namespace {
  9. std::string GetNetworkTypeName(
  10. chromeos::network_config::mojom::NetworkType network_type) {
  11. switch (network_type) {
  12. case chromeos::network_config::mojom::NetworkType::kCellular:
  13. [[fallthrough]];
  14. case chromeos::network_config::mojom::NetworkType::kTether:
  15. [[fallthrough]];
  16. case chromeos::network_config::mojom::NetworkType::kMobile:
  17. return "Mobile";
  18. case chromeos::network_config::mojom::NetworkType::kWiFi:
  19. return "WiFi";
  20. default:
  21. // A network type of other is unexpected, and no success
  22. // metric for it exists.
  23. NOTREACHED();
  24. return "";
  25. }
  26. }
  27. } // namespace
  28. void RecordNetworkRowClickedAction(NetworkRowClickedAction action) {
  29. base::UmaHistogramEnumeration("ChromeOS.SystemTray.Network.RowClickedAction",
  30. action);
  31. }
  32. void RecordDetailedViewSection(DetailedViewSection section) {
  33. base::UmaHistogramEnumeration("ChromeOS.SystemTray.Network.SectionShown",
  34. section);
  35. }
  36. void RecordNetworkTypeToggled(
  37. chromeos::network_config::mojom::NetworkType network_type,
  38. bool new_state) {
  39. const std::string network_name = GetNetworkTypeName(network_type);
  40. DCHECK(!network_name.empty());
  41. base::UmaHistogramBoolean(
  42. base::StrCat({"ChromeOS.SystemTray.Network.", network_name, ".Toggled"}),
  43. new_state);
  44. }
  45. } // namespace ash