blob: 3da9fd5dc5ef99ffc4c4b5118b36ea71299bae04 [file] [log] [blame]
[email protected]0c38b262013-08-23 23:34:241// 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
5#include "chrome/browser/diagnostics/diagnostics_metrics.h"
6
7#include <string>
8
asvitkineaa060312016-09-01 22:44:139#include "base/metrics/histogram_macros.h"
Avi Drissmand251e912018-12-26 15:46:3710#include "base/stl_util.h"
[email protected]0c38b262013-08-23 23:34:2411#include "chrome/browser/diagnostics/diagnostics_test.h"
12
13namespace diagnostics {
14
15namespace {
16
17// A struct to hold information about the tests.
18struct TestNameInfo {
19 // Should only contain characters [A-Za-z0-9] (no spaces).
20 const char* name;
21
22 // A non-localized description only meant for developer consumption.
23 const char* description;
24};
25
26// This structure MUST have DIAGNOSTICS_TEST_COUNT entries in it: one for each
27// value of DiagnosticsTestId. Note that the values in the "name" fields are
28// used for UMA metrics names (with "Diagnostics.Test." or
29// "Diagnostics.Recovery." prepended), so do not change them without
30// understanding the consequences.
31const TestNameInfo kTestNameInfo[] = {
32 {"ConflictingDlls", "Conflicting modules"},
33 {"DiskSpace", "Available disk space"},
34 {"InstallType", "Install type"},
35 {"JSONBookmarks", "Bookmark file"},
36 {"JSONLocalState", "Local state integrity"},
37 {"JSONPreferences", "User preferences integrity"},
38 {"OperatingSystem", "Operating system supported version"},
39 {"PathDictionaries", "App dictionaries directory path"},
40 {"PathLocalState", "Local state path"},
41 {"PathResources", "Resources path"},
42 {"PathUserData", "User data path"},
43 {"Version", "Chrome version test"},
44 {"SQLiteIntegrityAppCache", "Application cache database"},
[email protected]28a7e952014-07-02 12:41:2645 {"SQLiteIntegrityArchivedHistory", "Archived history database (obsolete)"},
[email protected]0c38b262013-08-23 23:34:2446 {"SQLiteIntegrityCookie", "Cookie database"},
47 {"SQLiteIntegrityDatabaseTracker", "Database tracker database"},
48 {"SQLiteIntegrityHistory", "History database"},
49 {"SQLiteIntegrityNSSCert", "NSS certificate database"},
50 {"SQLiteIntegrityNSSKey", "NSS Key database"},
shessd31f1802016-06-05 20:11:5651 {"SQLiteIntegrityThumbnails", "Thumbnails database (obsolete)"},
[email protected]0c38b262013-08-23 23:34:2452 {"SQLiteIntegrityWebData", "Web Data database"},
shessd31f1802016-06-05 20:11:5653 {"SQLiteIntegrityFavicons", "Favicons database"},
54 {"SQLiteIntegrityTopSites", "Top Sites database"},
[email protected]0c38b262013-08-23 23:34:2455 // Add new entries in the same order as DiagnosticsTestId.
56};
57
Avi Drissmand251e912018-12-26 15:46:3758static_assert(base::size(kTestNameInfo) == DIAGNOSTICS_TEST_ID_COUNT,
mostynb3a46e0bf2014-12-23 09:02:4359 "diagnostics test info mismatch");
[email protected]0c38b262013-08-23 23:34:2460
61const TestNameInfo* FindTestInfo(DiagnosticsTestId id) {
62 DCHECK(id < DIAGNOSTICS_TEST_ID_COUNT);
63 return &kTestNameInfo[id];
64}
65
66} // namespace
67
68std::string GetTestName(DiagnosticsTestId id) {
69 return std::string(FindTestInfo(id)->name);
70}
71
72std::string GetTestDescription(DiagnosticsTestId id) {
73 return std::string(FindTestInfo(id)->description);
74}
75
76#define TEST_CASE(name, id) \
77 case id: \
78 UMA_HISTOGRAM_ENUMERATION(name, result, RESULT_COUNT); \
79 break
80
81// These must each have their own complete case so that the UMA macros create
82// a unique static pointer block for each individual metric. This is done as a
83// macro to prevent errors where the ID is added to one function below, but not
84// the other, because they must match.
85#define TEST_CASES(name) \
86 TEST_CASE(name, DIAGNOSTICS_CONFLICTING_DLLS_TEST); \
87 TEST_CASE(name, DIAGNOSTICS_DISK_SPACE_TEST); \
88 TEST_CASE(name, DIAGNOSTICS_INSTALL_TYPE_TEST); \
89 TEST_CASE(name, DIAGNOSTICS_JSON_BOOKMARKS_TEST); \
90 TEST_CASE(name, DIAGNOSTICS_JSON_LOCAL_STATE_TEST); \
91 TEST_CASE(name, DIAGNOSTICS_JSON_PREFERENCES_TEST); \
92 TEST_CASE(name, DIAGNOSTICS_OPERATING_SYSTEM_TEST); \
93 TEST_CASE(name, DIAGNOSTICS_PATH_DICTIONARIES_TEST); \
94 TEST_CASE(name, DIAGNOSTICS_PATH_LOCAL_STATE_TEST); \
95 TEST_CASE(name, DIAGNOSTICS_PATH_RESOURCES_TEST); \
96 TEST_CASE(name, DIAGNOSTICS_PATH_USER_DATA_TEST); \
97 TEST_CASE(name, DIAGNOSTICS_VERSION_TEST); \
98 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_APP_CACHE_TEST); \
[email protected]28a7e952014-07-02 12:41:2699 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_ARCHIVED_HISTORY_TEST_OBSOLETE);\
[email protected]0c38b262013-08-23 23:34:24100 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_COOKIE_TEST); \
101 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_DATABASE_TRACKER_TEST); \
102 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_HISTORY_TEST); \
103 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_NSS_CERT_TEST); \
104 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_NSS_KEY_TEST); \
shessd31f1802016-06-05 20:11:56105 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_THUMBNAILS_TEST_OBSOLETE);\
106 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_WEB_DATA_TEST); \
107 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_FAVICONS_TEST); \
108 TEST_CASE(name, DIAGNOSTICS_SQLITE_INTEGRITY_TOPSITES_TEST);
[email protected]0c38b262013-08-23 23:34:24109
110void RecordUMARecoveryResult(DiagnosticsTestId id, RunResultMetrics result) {
111 const std::string name("Diagnostics.Recovery." +
112 GetTestName(static_cast<DiagnosticsTestId>(id)));
113 switch (id) {
114 TEST_CASES(name); // See above
115 default:
116 NOTREACHED() << "Unhandled UMA Metric type" << id;
117 }
118}
119
120void RecordUMATestResult(DiagnosticsTestId id, RunResultMetrics result) {
121 const std::string name("Diagnostics.Test." +
122 GetTestName(static_cast<DiagnosticsTestId>(id)));
123 switch (id) {
124 TEST_CASES(name); // See above
125 default:
126 NOTREACHED() << "Unhandled UMA Metric type" << id;
127 }
128}
129#undef TEST_CASE
130#undef TEST_CASES
131
132} // namespace diagnostics