diagnostics_metrics.cc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2021 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. #include "ash/webui/diagnostics_ui/diagnostics_metrics.h"
  5. #include "ash/constants/ash_features.h"
  6. #include "chromeos/ash/components/feature_usage/feature_usage_metrics.h"
  7. namespace ash {
  8. namespace diagnostics {
  9. namespace metrics {
  10. namespace {
  11. const char kDiagnosticsUmaFeatureName[] = "DiagnosticsUi";
  12. }
  13. DiagnosticsMetrics::DiagnosticsMetrics()
  14. : feature_metrics_(kDiagnosticsUmaFeatureName, this),
  15. successful_usage_started_(false) {}
  16. bool DiagnosticsMetrics::IsEligible() const {
  17. return true;
  18. }
  19. bool DiagnosticsMetrics::IsEnabled() const {
  20. return true;
  21. }
  22. // Helper function for feature_usage::FeatureUsageMetrics RecordUsage.
  23. void DiagnosticsMetrics::RecordUsage(bool success) {
  24. feature_metrics_.RecordUsage(success);
  25. // Start successful usage recording only when usage was successful and not
  26. // currently recording a successful usage.
  27. // See {@link feature_usage::FeatureUsageMetrics} for rationale behind
  28. // starting and stopping usetime tracking.
  29. if (success) {
  30. DCHECK(!successful_usage_started_);
  31. feature_metrics_.StartSuccessfulUsage();
  32. successful_usage_started_ = true;
  33. }
  34. }
  35. void DiagnosticsMetrics::StopSuccessfulUsage() {
  36. // Exit early if usage was not started.
  37. if (!successful_usage_started_) {
  38. return;
  39. }
  40. feature_metrics_.StopSuccessfulUsage();
  41. successful_usage_started_ = false;
  42. }
  43. // Test helpers to check state of `successful_usage_started`.
  44. bool DiagnosticsMetrics::GetSuccessfulUsageStartedForTesting() {
  45. return successful_usage_started_;
  46. }
  47. } // namespace metrics
  48. } // namespace diagnostics
  49. } // namespace ash