blob: daea471a8ed10f0b50df4bf3d57a887527737fe6 [file] [log] [blame]
Ben Chanbe2b4a72011-11-08 13:42:23 -08001// 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 Chanbe2b4a72011-11-08 13:42:23 -08008#include <string>
François Degros13d86e62020-07-12 13:09:13 +10009#include <unordered_map>
Ben Chanbe2b4a72011-11-08 13:42:23 -080010
Ben Chan6d0b2722011-11-18 08:24:14 -080011#include <chromeos/dbus/service_constants.h>
Ben Chanbe2b4a72011-11-08 13:42:23 -080012#include <gtest/gtest_prod.h>
13#include <metrics/metrics_library.h>
14
Ben Chanbe2b4a72011-11-08 13:42:23 -080015namespace cros_disks {
16
17// A class for collecting cros-disks related UMA metrics.
18class Metrics {
19 public:
François Degros13d86e62020-07-12 13:09:13 +100020 Metrics() = default;
Qijiang Fan6bc59e12020-11-11 02:51:06 +090021 Metrics(const Metrics&) = delete;
22 Metrics& operator=(const Metrics&) = delete;
23
Ben Chan55123552014-08-24 16:22:16 -070024 ~Metrics() = default;
Ben Chanbe2b4a72011-11-08 13:42:23 -080025
26 // Records the type of archive that cros-disks is trying to mount.
27 void RecordArchiveType(const std::string& archive_type);
28
Ben Chan9ed09e32011-11-22 16:24:06 -080029 // Records the type of filesystem that cros-disks is trying to mount.
Ben Chanbe2b4a72011-11-08 13:42:23 -080030 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 Degrosaec21fb2020-03-06 15:23:43 +110035 // Records the error code returned by a FUSE mounter program.
François Degros37f19482020-07-13 21:17:48 +100036 void RecordFuseMounterErrorCode(const std::string& mounter_name,
François Degrosaec21fb2020-03-06 15:23:43 +110037 int error_code);
38
Ben Chanbe2b4a72011-11-08 13:42:23 -080039 private:
François Degros13d86e62020-07-12 13:09:13 +100040 // Don't renumber these values. They are recorded in UMA metrics.
Ben Chanbe2b4a72011-11-08 13:42:23 -080041 enum ArchiveType {
42 kArchiveUnknown = 0,
43 kArchiveZip = 1,
Ben Chand7ff95f2012-02-16 13:41:14 -080044 kArchiveRar = 2,
45 kArchiveTar = 3,
46 kArchiveTarBzip2 = 4,
47 kArchiveTarGzip = 5,
48 kArchiveMaxValue = 6,
Ben Chanbe2b4a72011-11-08 13:42:23 -080049 };
50
François Degros13d86e62020-07-12 13:09:13 +100051 // Don't renumber these values. They are recorded in UMA metrics.
Ben Chanbe2b4a72011-11-08 13:42:23 -080052 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 Chanbe2b4a72011-11-08 13:42:23 -080067 // 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 Degros13d86e62020-07-12 13:09:13 +100078 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 Chanbe2b4a72011-11-08 13:42:23 -080083
84 // Mapping from a filesystem type to its corresponding metric value.
François Degros13d86e62020-07-12 13:09:13 +100085 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 Chanbe2b4a72011-11-08 13:42:23 -080091
92 FRIEND_TEST(MetricsTest, GetArchiveType);
93 FRIEND_TEST(MetricsTest, GetFilesystemType);
Ben Chanbe2b4a72011-11-08 13:42:23 -080094};
95
96} // namespace cros_disks
97
98#endif // CROS_DISKS_METRICS_H_