Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS 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 | |
| 5 | #include "cros-disks/metrics.h" |
| 6 | |
| 7 | #include <base/logging.h> |
| 8 | |
Anand K Mistry | 40cff45 | 2019-07-30 10:24:48 +1000 | [diff] [blame^] | 9 | namespace cros_disks { |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 10 | namespace { |
| 11 | |
| 12 | const char kArchiveTypeMetricName[] = "CrosDisks.ArchiveType"; |
| 13 | const char kDeviceMediaTypeMetricName[] = "CrosDisks.DeviceMediaType"; |
| 14 | const char kFilesystemTypeMetricName[] = "CrosDisks.FilesystemType"; |
| 15 | |
| 16 | } // namespace |
| 17 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 18 | Metrics::Metrics() { |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 19 | InitializeArchiveTypeMap(); |
| 20 | InitializeFilesystemTypeMap(); |
| 21 | } |
| 22 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 23 | void Metrics::InitializeArchiveTypeMap() { |
| 24 | archive_type_map_["zip"] = kArchiveZip; |
Ben Chan | 68e325a | 2012-02-14 22:35:15 -0800 | [diff] [blame] | 25 | archive_type_map_["tar"] = kArchiveTar; |
| 26 | archive_type_map_["tar.bz2"] = kArchiveTarBzip2; |
| 27 | archive_type_map_["tbz"] = kArchiveTarBzip2; |
| 28 | archive_type_map_["tbz2"] = kArchiveTarBzip2; |
| 29 | archive_type_map_["tar.gz"] = kArchiveTarGzip; |
| 30 | archive_type_map_["tgz"] = kArchiveTarGzip; |
Ben Chan | d7ff95f | 2012-02-16 13:41:14 -0800 | [diff] [blame] | 31 | archive_type_map_["rar"] = kArchiveRar; |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | void Metrics::InitializeFilesystemTypeMap() { |
| 35 | filesystem_type_map_["vfat"] = kFilesystemVFAT; |
| 36 | filesystem_type_map_["exfat"] = kFilesystemExFAT; |
| 37 | filesystem_type_map_["ntfs"] = kFilesystemNTFS; |
| 38 | filesystem_type_map_["hfsplus"] = kFilesystemHFSPlus; |
| 39 | filesystem_type_map_["ext2"] = kFilesystemExt2; |
| 40 | filesystem_type_map_["ext3"] = kFilesystemExt3; |
| 41 | filesystem_type_map_["ext4"] = kFilesystemExt4; |
| 42 | filesystem_type_map_["iso9660"] = kFilesystemISO9660; |
| 43 | filesystem_type_map_["udf"] = kFilesystemUDF; |
| 44 | filesystem_type_map_[""] = kFilesystemUnknown; |
| 45 | } |
| 46 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 47 | Metrics::ArchiveType Metrics::GetArchiveType( |
| 48 | const std::string& archive_type) const { |
| 49 | std::map<std::string, ArchiveType>::const_iterator map_iter = |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 50 | archive_type_map_.find(archive_type); |
| 51 | if (map_iter != archive_type_map_.end()) |
| 52 | return map_iter->second; |
| 53 | return kArchiveUnknown; |
| 54 | } |
| 55 | |
| 56 | Metrics::FilesystemType Metrics::GetFilesystemType( |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 57 | const std::string& filesystem_type) const { |
| 58 | std::map<std::string, FilesystemType>::const_iterator map_iter = |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 59 | filesystem_type_map_.find(filesystem_type); |
| 60 | if (map_iter != filesystem_type_map_.end()) |
| 61 | return map_iter->second; |
| 62 | return kFilesystemOther; |
| 63 | } |
| 64 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 65 | void Metrics::RecordArchiveType(const std::string& archive_type) { |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 66 | if (!metrics_library_.SendEnumToUMA(kArchiveTypeMetricName, |
| 67 | GetArchiveType(archive_type), |
| 68 | kArchiveMaxValue)) |
| 69 | LOG(WARNING) << "Failed to send archive type sample to UMA"; |
| 70 | } |
| 71 | |
Ben Chan | 213c6d9 | 2019-04-10 16:21:52 -0700 | [diff] [blame] | 72 | void Metrics::RecordFilesystemType(const std::string& filesystem_type) { |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 73 | if (!metrics_library_.SendEnumToUMA(kFilesystemTypeMetricName, |
| 74 | GetFilesystemType(filesystem_type), |
| 75 | kFilesystemMaxValue)) |
| 76 | LOG(WARNING) << "Failed to send filesystem type sample to UMA"; |
| 77 | } |
| 78 | |
| 79 | void Metrics::RecordDeviceMediaType(DeviceMediaType device_media_type) { |
| 80 | if (!metrics_library_.SendEnumToUMA(kDeviceMediaTypeMetricName, |
| 81 | device_media_type, |
Ben Chan | 6d0b272 | 2011-11-18 08:24:14 -0800 | [diff] [blame] | 82 | DEVICE_MEDIA_NUM_VALUES)) |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 83 | LOG(WARNING) << "Failed to send device media type sample to UMA"; |
| 84 | } |
| 85 | |
| 86 | } // namespace cros_disks |