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

ash / system / privacy_hub / privacy_hub_metrics.cc [blame]

// Copyright 2022 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/system/privacy_hub/privacy_hub_metrics.h"

#include "ash/system/privacy_hub/privacy_hub_controller.h"

#include "base/metrics/histogram_functions.h"

namespace ash::privacy_hub_metrics {

void LogSensorEnabledFromNotification(Sensor sensor, bool enabled) {
  const char* histogram = nullptr;
  switch (sensor) {
    // Location needs to be handled separately as it has 3 states.
    case Sensor::kLocation: {
      histogram = kPrivacyHubGeolocationAccessLevelChangedFromNotification;

      // Only collect events that trigger system geolocation state changes. When
      // `enabled==false` it means the user just dismissed the notification, so
      // no change has happened.
      if (enabled) {
        const auto* controller = ash::GeolocationPrivacySwitchController::Get();
        CHECK(controller);
        base::UmaHistogramEnumeration(histogram, controller->AccessLevel());
      }
      return;
    }
    case Sensor::kCamera: {
      histogram = kPrivacyHubCameraEnabledFromNotificationHistogram;
      break;
    }
    case Sensor::kMicrophone: {
      histogram = kPrivacyHubMicrophoneEnabledFromNotificationHistogram;
      break;
    }
  }
  CHECK(histogram);
  base::UmaHistogramBoolean(histogram, enabled);
}

void LogPrivacyHubOpenedFromNotification() {
  base::UmaHistogramEnumeration(kPrivacyHubOpenedHistogram,
                                PrivacyHubNavigationOrigin::kNotification);
}

void LogPrivacyHubLearnMorePageOpened(PrivacyHubLearnMoreSensor sensor) {
  base::UmaHistogramEnumeration(kPrivacyHubLearnMorePageOpenedHistogram,
                                sensor);
}

}  // namespace ash::privacy_hub_metrics