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
ash / webui / diagnostics_ui / diagnostics_metrics.cc [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/webui/diagnostics_ui/diagnostics_metrics.h"
#include "ash/constants/ash_features.h"
#include "chromeos/ash/components/feature_usage/feature_usage_metrics.h"
namespace ash {
namespace diagnostics {
namespace metrics {
namespace {
const char kDiagnosticsUmaFeatureName[] = "DiagnosticsUi";
}
DiagnosticsMetrics::DiagnosticsMetrics()
: feature_metrics_(kDiagnosticsUmaFeatureName, this),
successful_usage_started_(false) {}
bool DiagnosticsMetrics::IsEligible() const {
return true;
}
bool DiagnosticsMetrics::IsEnabled() const {
return true;
}
// Helper function for feature_usage::FeatureUsageMetrics RecordUsage.
void DiagnosticsMetrics::RecordUsage(bool success) {
feature_metrics_.RecordUsage(success);
// Start successful usage recording only when usage was successful and not
// currently recording a successful usage.
// See {@link feature_usage::FeatureUsageMetrics} for rationale behind
// starting and stopping usetime tracking.
if (success) {
DCHECK(!successful_usage_started_);
feature_metrics_.StartSuccessfulUsage();
successful_usage_started_ = true;
}
}
void DiagnosticsMetrics::StopSuccessfulUsage() {
// Exit early if usage was not started.
if (!successful_usage_started_) {
return;
}
feature_metrics_.StopSuccessfulUsage();
successful_usage_started_ = false;
}
// Test helpers to check state of `successful_usage_started`.
bool DiagnosticsMetrics::GetSuccessfulUsageStartedForTesting() {
return successful_usage_started_;
}
} // namespace metrics
} // namespace diagnostics
} // namespace ash