xref: /aosp_15_r20/external/libchrome/components/policy/core/common/policy_load_status.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1 // Copyright (c) 2013 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 
5 #include "components/policy/core/common/policy_load_status.h"
6 
7 #include "base/bind.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/stringprintf.h"
10 #include "components/policy/core/common/policy_types.h"
11 
12 namespace policy {
13 
14 namespace {
15 
16 const char kHistogramName[] = "Enterprise.PolicyLoadStatus";
17 
18 }  // namespace
19 
PolicyLoadStatusSampler()20 PolicyLoadStatusSampler::PolicyLoadStatusSampler() {
21   Add(POLICY_LOAD_STATUS_STARTED);
22 }
23 
~PolicyLoadStatusSampler()24 PolicyLoadStatusSampler::~PolicyLoadStatusSampler() {}
25 
Add(PolicyLoadStatus status)26 void PolicyLoadStatusSampler::Add(PolicyLoadStatus status) {
27   status_bits_[status] = true;
28 }
29 
PolicyLoadStatusUmaReporter()30 PolicyLoadStatusUmaReporter::PolicyLoadStatusUmaReporter() {}
31 
~PolicyLoadStatusUmaReporter()32 PolicyLoadStatusUmaReporter::~PolicyLoadStatusUmaReporter() {
33   base::HistogramBase* histogram(base::LinearHistogram::FactoryGet(
34       kHistogramName, 1, POLICY_LOAD_STATUS_SIZE, POLICY_LOAD_STATUS_SIZE + 1,
35       base::Histogram::kUmaTargetedHistogramFlag));
36 
37   for (int i = 0; i < POLICY_LOAD_STATUS_SIZE; ++i) {
38     if (GetStatusSet()[i])
39       histogram->Add(i);
40   }
41 }
42 
43 }  // namespace policy
44