1 // Copyright 2020 The Chromium Authors 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 COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_ 7 #include "components/prefs/persistent_pref_store.h" 8 9 namespace metrics::structured { 10 11 // Possible internal errors of the structured metrics system. These are events 12 // we expect to never see, so only the absolute counts should be looked at, the 13 // bucket proportion doesn't make sense. These values are persisted to logs. 14 // Entries should not be renumbered and numeric values should never be reused. 15 enum class StructuredMetricsError { 16 kMissingKey = 0, 17 kWrongKeyLength = 1, 18 kMissingLastRotation = 2, 19 kMissingRotationPeriod = 3, 20 kFailedUintConversion = 4, 21 kKeyReadError = 5, 22 kKeyParseError = 6, 23 kKeyWriteError = 7, 24 kKeySerializationError = 8, 25 kEventReadError = 9, 26 kEventParseError = 10, 27 kEventWriteError = 11, 28 kEventSerializationError = 12, 29 kUninitializedClient = 13, 30 kInvalidEventParsed = 14, 31 kMaxValue = kInvalidEventParsed, 32 }; 33 34 // Whether a single event was recorded correctly, or otherwise what error state 35 // occurred. These values are persisted to logs. Entries should not be 36 // renumbered and numeric values should never be reused. 37 enum class EventRecordingState { 38 kRecorded = 0, 39 kProviderUninitialized = 1, 40 kRecordingDisabled = 2, 41 kProviderMissing = 3, 42 kProjectDisallowed = 4, 43 kMaxValue = kProjectDisallowed, 44 }; 45 46 // Describes the action taken by KeyData::ValidateAndGetKey on a particular user 47 // event key. A key can either be valid with no action taken, missing and so 48 // created, or out of its rotation period and so re-created. These values are 49 // persisted to logs. Entries should not be renumbered and numeric values should 50 // never be reused. 51 enum class KeyValidationState { 52 kValid = 0, 53 kCreated = 1, 54 kRotated = 2, 55 kMaxValue = kRotated, 56 }; 57 58 void LogInternalError(StructuredMetricsError error); 59 60 void LogEventRecordingState(EventRecordingState state); 61 62 void LogKeyValidation(KeyValidationState state); 63 64 // Log how many structured metrics events were contained in a call to 65 // ProvideCurrentSessionData. 66 void LogNumEventsInUpload(int num_events); 67 68 // Logs that an event was recorded using the mojo API. 69 void LogIsEventRecordedUsingMojo(bool used_mojo_api); 70 71 // Logs the number of events that were recorded before device and user 72 // cryptographic keys have been loaded to hash events. These events will be kept 73 // in memory. 74 void LogNumEventsRecordedBeforeInit(int num_events); 75 76 // Logs the number of files processed per external metrics scan. 77 void LogNumFilesPerExternalMetricsScan(int num_files); 78 79 // Logs the file size of an event. 80 void LogEventFileSizeKB(int64_t file_size_kb); 81 82 // Logs the serialized size of an event when it is recorded in bytes. 83 void LogEventSerializedSizeBytes(int64_t event_size_bytes); 84 85 // Logs the StructuredMetrics uploaded size to UMA in bytes. 86 void LogUploadSizeBytes(int64_t upload_size_bytes); 87 88 // Logs the number of external metrics were scanned for an upload. 89 void LogExternalMetricsScanInUpload(int num_scans); 90 91 } // namespace metrics::structured 92 93 #endif // COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_ 94