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 | #ifndef CROS_DISKS_METRICS_H_ |
| 6 | #define CROS_DISKS_METRICS_H_ |
| 7 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 8 | #include <string> |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 9 | #include <unordered_map> |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 10 | |
Ben Chan | 6d0b272 | 2011-11-18 08:24:14 -0800 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> |
| 13 | #include <metrics/metrics_library.h> |
| 14 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 15 | namespace cros_disks { |
| 16 | |
| 17 | // A class for collecting cros-disks related UMA metrics. |
| 18 | class Metrics { |
| 19 | public: |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 20 | Metrics() = default; |
Qijiang Fan | 6bc59e1 | 2020-11-11 02:51:06 +0900 | [diff] [blame] | 21 | Metrics(const Metrics&) = delete; |
| 22 | Metrics& operator=(const Metrics&) = delete; |
| 23 | |
Ben Chan | 5512355 | 2014-08-24 16:22:16 -0700 | [diff] [blame] | 24 | ~Metrics() = default; |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 25 | |
| 26 | // Records the type of archive that cros-disks is trying to mount. |
| 27 | void RecordArchiveType(const std::string& archive_type); |
| 28 | |
Ben Chan | 9ed09e3 | 2011-11-22 16:24:06 -0800 | [diff] [blame] | 29 | // Records the type of filesystem that cros-disks is trying to mount. |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 30 | void RecordFilesystemType(const std::string& filesystem_type); |
| 31 | |
| 32 | // Records the type of device media that cros-disks is trying to mount. |
| 33 | void RecordDeviceMediaType(DeviceMediaType device_media_type); |
| 34 | |
François Degros | aec21fb | 2020-03-06 15:23:43 +1100 | [diff] [blame] | 35 | // Records the error code returned by a FUSE mounter program. |
François Degros | 37f1948 | 2020-07-13 21:17:48 +1000 | [diff] [blame] | 36 | void RecordFuseMounterErrorCode(const std::string& mounter_name, |
François Degros | aec21fb | 2020-03-06 15:23:43 +1100 | [diff] [blame] | 37 | int error_code); |
| 38 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 39 | private: |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 40 | // Don't renumber these values. They are recorded in UMA metrics. |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 41 | enum ArchiveType { |
| 42 | kArchiveUnknown = 0, |
| 43 | kArchiveZip = 1, |
Ben Chan | d7ff95f | 2012-02-16 13:41:14 -0800 | [diff] [blame] | 44 | kArchiveRar = 2, |
| 45 | kArchiveTar = 3, |
| 46 | kArchiveTarBzip2 = 4, |
| 47 | kArchiveTarGzip = 5, |
| 48 | kArchiveMaxValue = 6, |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 51 | // Don't renumber these values. They are recorded in UMA metrics. |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 52 | enum FilesystemType { |
| 53 | kFilesystemUnknown = 0, |
| 54 | kFilesystemOther = 1, |
| 55 | kFilesystemVFAT = 2, |
| 56 | kFilesystemExFAT = 3, |
| 57 | kFilesystemNTFS = 4, |
| 58 | kFilesystemHFSPlus = 5, |
| 59 | kFilesystemExt2 = 6, |
| 60 | kFilesystemExt3 = 7, |
| 61 | kFilesystemExt4 = 8, |
| 62 | kFilesystemISO9660 = 9, |
| 63 | kFilesystemUDF = 10, |
| 64 | kFilesystemMaxValue = 11, |
| 65 | }; |
| 66 | |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 67 | // Returns the MetricsArchiveType enum value for the specified archive type |
| 68 | // string. |
| 69 | ArchiveType GetArchiveType(const std::string& archive_type) const; |
| 70 | |
| 71 | // Returns the MetricsFilesystemType enum value for the specified filesystem |
| 72 | // type string. |
| 73 | FilesystemType GetFilesystemType(const std::string& filesystem_type) const; |
| 74 | |
| 75 | MetricsLibrary metrics_library_; |
| 76 | |
| 77 | // Mapping from an archive type to its corresponding metric value. |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 78 | const std::unordered_map<std::string, ArchiveType> archive_type_map_{ |
| 79 | {"rar", kArchiveRar}, {"tar", kArchiveTar}, |
| 80 | {"tar.bz2", kArchiveTarBzip2}, {"tbz", kArchiveTarBzip2}, |
| 81 | {"tbz2", kArchiveTarBzip2}, {"tar.gz", kArchiveTarGzip}, |
| 82 | {"tgz", kArchiveTarGzip}, {"zip", kArchiveZip}}; |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 83 | |
| 84 | // Mapping from a filesystem type to its corresponding metric value. |
François Degros | 13d86e6 | 2020-07-12 13:09:13 +1000 | [diff] [blame] | 85 | const std::unordered_map<std::string, FilesystemType> filesystem_type_map_{ |
| 86 | {"", kFilesystemUnknown}, {"exfat", kFilesystemExFAT}, |
| 87 | {"ext2", kFilesystemExt2}, {"ext3", kFilesystemExt3}, |
| 88 | {"ext4", kFilesystemExt4}, {"hfsplus", kFilesystemHFSPlus}, |
| 89 | {"iso9660", kFilesystemISO9660}, {"ntfs", kFilesystemNTFS}, |
| 90 | {"udf", kFilesystemUDF}, {"vfat", kFilesystemVFAT}}; |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 91 | |
| 92 | FRIEND_TEST(MetricsTest, GetArchiveType); |
| 93 | FRIEND_TEST(MetricsTest, GetFilesystemType); |
Ben Chan | be2b4a7 | 2011-11-08 13:42:23 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | } // namespace cros_disks |
| 97 | |
| 98 | #endif // CROS_DISKS_METRICS_H_ |