1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/policy/skyvault/histogram_helper.h"
#include <string>
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "chrome/browser/ash/policy/skyvault/local_files_migration_constants.h"
#include "chrome/browser/ash/policy/skyvault/policy_utils.h"
namespace policy::local_user_files {
namespace {
constexpr char kSkyVaultUMAPrefix[] = "Enterprise.SkyVault.";
// Suffixes for upload flow histograms.
constexpr char kDeleteErrorSuffix[] = "DeleteError";
constexpr char kOneDriveSignInErrorSuffix[] = "SignInError";
// Suffixes for local storage histograms.
constexpr char kLocalStorageEnabledSuffix[] = "LocalStorage.Enabled";
constexpr char kLocalStorageMisconfiguredSuffix[] =
"LocalStorage.Misconfigured";
// Suffixes for migration flow histograms.
constexpr char kMigrationEnabledSuffix[] = "Enabled";
constexpr char kMigrationMisconfiguredSuffix[] = "Misconfigured";
constexpr char kMigrationResetSuffix[] = "Reset";
constexpr char kMigrationRetrySuffix[] = "Retry";
constexpr char kMigrationStoppedSuffix[] = "Stopped";
constexpr char kMigrationStateErrorContextSuffix[] = "StateErrorContext";
constexpr char kMigrationWrongStateSuffix[] = "WrongState";
constexpr char kMigrationFailedSuffix[] = "Failed";
constexpr char kMigrationSuccessDurationSuffix[] = "SuccessDuration";
constexpr char kMigrationFailureDurationSuffix[] = "FailureDuration";
constexpr char kMigrationWriteAccessErrorSuffix[] = "WriteAccessError";
constexpr char kMigrationUploadErrorSuffix[] = "UploadError";
constexpr char kMigrationWaitForConnectionSuffix[] = "WaitForConnection";
constexpr char kMigrationReconnectionDurationSuffix[] = "ReconnectionDuration";
constexpr char kMigrationCleanupErrorSuffix[] = "CleanupError";
constexpr char kMigrationDialogActionSuffix[] = "DialogAction";
constexpr char kMigrationDialogShownSuffix[] = "DialogShown";
constexpr char kScheduledTimeInPastInformUser[] =
"ScheduledTimeInPast.InformUser";
constexpr char kScheduledTimeInPastScheduleMigration[] =
"ScheduledTimeInPast.ScheduleMigration";
// Constants for cloud providers used in histogram names.
constexpr char kGoogleDriveProvider[] = "GoogleDrive";
constexpr char kOneDriveProvider[] = "OneDrive";
constexpr char kDelete[] = "Delete";
// Constants for upload triggers used in histogram names.
constexpr char kDownloadTrigger[] = "Download";
constexpr char kScreenCaptureTrigger[] = "ScreenCapture";
constexpr char kMigrationTrigger[] = "Migration";
// Min, max, and bucket count for migration duration histograms.
constexpr base::TimeDelta kMigrationDurationMin = base::Milliseconds(1);
constexpr base::TimeDelta kMigrationDurationMax = base::Hours(36);
// Number of buckets calculated to have a bucket size of 5 minutes:
// (kMax in h * 60 min/h) / 5 min/bucket = 36 * 60 / 5 = 432 buckets
constexpr int kMigrationDurationBuckets = 432;
// Min, max, and bucket count for reconnectivity waiting time histograms.
constexpr base::TimeDelta kReconnectionDurationMin = base::Milliseconds(1);
constexpr base::TimeDelta kReconnectionDurationMax = base::Hours(4);
// Number of buckets calculated to have a bucket size of 1 minute:
// (kMax in h * 60 min/h) / 1 min/bucket = 4 * 60 = 240 buckets
constexpr int kReconnectionDurationBuckets = 240;
// Converts `destination` to a string representation used to form a metric name.
std::string GetUMAMigrationDestination(MigrationDestination destination) {
switch (destination) {
case MigrationDestination::kNotSpecified:
NOTREACHED();
case MigrationDestination::kGoogleDrive:
return kGoogleDriveProvider;
case MigrationDestination::kOneDrive:
return kOneDriveProvider;
case MigrationDestination::kDelete:
return kDelete;
}
}
// Converts `trigger` to a string representation used to form a metric name.
std::string GetUMAAction(UploadTrigger trigger) {
std::string action;
switch (trigger) {
case UploadTrigger::kDownload:
return kDownloadTrigger;
case UploadTrigger::kScreenCapture:
return kScreenCaptureTrigger;
case UploadTrigger::kMigration:
return kMigrationTrigger;
}
}
std::string GetHistogramName(
const std::string& suffix,
std::optional<UploadTrigger> trigger = std::nullopt,
std::optional<MigrationDestination> destination = std::nullopt) {
std::vector<std::string> parts = {kSkyVaultUMAPrefix};
if (trigger.has_value()) {
parts.push_back(GetUMAAction(trigger.value()));
parts.push_back(".");
}
if (destination.has_value()) {
parts.push_back(GetUMAMigrationDestination(destination.value()));
parts.push_back(".");
}
parts.push_back(suffix);
return base::StrCat(parts);
}
} // namespace
void SkyVaultDeleteErrorHistogram(UploadTrigger trigger,
MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kDeleteErrorSuffix, trigger, destination), value);
}
void SkyVaultOneDriveSignInErrorHistogram(UploadTrigger trigger, bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kOneDriveSignInErrorSuffix, trigger,
MigrationDestination::kOneDrive),
value);
}
void SkyVaultLocalStorageEnabledHistogram(bool value) {
base::UmaHistogramBoolean(GetHistogramName(kLocalStorageEnabledSuffix),
value);
}
void SkyVaultLocalStorageMisconfiguredHistogram(bool value) {
base::UmaHistogramBoolean(GetHistogramName(kLocalStorageMisconfiguredSuffix),
value);
}
void SkyVaultMigrationEnabledHistogram(MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationEnabledSuffix, UploadTrigger::kMigration,
destination),
value);
}
void SkyVaultMigrationMisconfiguredHistogram(MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationMisconfiguredSuffix, UploadTrigger::kMigration,
destination),
value);
}
void SkyVaultMigrationResetHistogram(bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationResetSuffix, UploadTrigger::kMigration),
value);
}
void SkyVaultMigrationRetryHistogram(int count) {
base::UmaHistogramCustomCounts(
GetHistogramName(kMigrationRetrySuffix, UploadTrigger::kMigration), count,
1, kMaxRetryCount, kMaxRetryCount);
}
void SkyVaultDeletionRetryHistogram(int count) {
base::UmaHistogramCustomCounts(
GetHistogramName(kMigrationRetrySuffix, UploadTrigger::kMigration,
MigrationDestination::kDelete),
count, 1, kMaxRetryCount, kMaxRetryCount);
}
void SkyVaultMigrationStoppedHistogram(MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationStoppedSuffix, UploadTrigger::kMigration,
destination),
value);
}
void SkyVaultMigrationWrongStateHistogram(MigrationDestination destination,
StateErrorContext context,
State state) {
base::UmaHistogramEnumeration(
GetHistogramName(kMigrationStateErrorContextSuffix,
UploadTrigger::kMigration, destination),
context);
base::UmaHistogramEnumeration(
GetHistogramName(kMigrationWrongStateSuffix, UploadTrigger::kMigration,
destination),
state);
}
void SkyVaultDeletionDoneHistogram(bool success) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationFailedSuffix, UploadTrigger::kMigration,
MigrationDestination::kDelete),
!success);
}
void SkyVaultMigrationDoneHistograms(MigrationDestination destination,
bool success,
base::TimeDelta duration) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationFailedSuffix, UploadTrigger::kMigration,
destination),
!success);
const std::string suffix = success ? kMigrationSuccessDurationSuffix
: kMigrationFailureDurationSuffix;
base::UmaHistogramCustomTimes(
GetHistogramName(suffix, UploadTrigger::kMigration, destination),
duration, kMigrationDurationMin, kMigrationDurationMax,
kMigrationDurationBuckets);
}
void SkyVaultMigrationWriteAccessErrorHistogram(bool value) {
base::UmaHistogramBoolean(GetHistogramName(kMigrationWriteAccessErrorSuffix,
UploadTrigger::kMigration),
value);
}
void SkyVaultMigrationUploadErrorHistogram(MigrationDestination destination,
MigrationUploadError error) {
base::UmaHistogramEnumeration(
GetHistogramName(kMigrationUploadErrorSuffix, UploadTrigger::kMigration,
destination),
error);
}
void SkyVaultMigrationWaitForConnectionHistogram(
MigrationDestination destination,
bool waiting_for_connection) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationWaitForConnectionSuffix,
UploadTrigger::kMigration, destination),
waiting_for_connection);
}
void SkyVaultMigrationReconnectionDurationHistogram(
MigrationDestination destination,
base::TimeDelta duration) {
base::UmaHistogramCustomTimes(
GetHistogramName(kMigrationReconnectionDurationSuffix,
UploadTrigger::kMigration, destination),
duration, kReconnectionDurationMin, kReconnectionDurationMax,
kReconnectionDurationBuckets);
}
void SkyVaultMigrationCleanupErrorHistogram(MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationCleanupErrorSuffix, UploadTrigger::kMigration,
destination),
value);
}
void SkyVaultMigrationScheduledTimeInPastInformUser(
MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kScheduledTimeInPastInformUser,
UploadTrigger::kMigration, destination),
value);
}
void SkyVaultMigrationScheduledTimeInPastScheduleMigration(
MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kScheduledTimeInPastScheduleMigration,
UploadTrigger::kMigration, destination),
value);
}
void SkyVaultMigrationDialogActionHistogram(MigrationDestination destination,
DialogAction action) {
base::UmaHistogramEnumeration(
GetHistogramName(kMigrationDialogActionSuffix, UploadTrigger::kMigration,
destination),
action);
}
void SkyVaultMigrationDialogShownHistogram(MigrationDestination destination,
bool value) {
base::UmaHistogramBoolean(
GetHistogramName(kMigrationDialogShownSuffix, UploadTrigger::kMigration,
destination),
value);
}
} // namespace policy::local_user_files
|