Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9340)

Unified Diff: components/policy/core/common/policy_load_status.cc

Issue 2860973002: Allow PolicyLoadStatusSample to override reporting method (Closed)
Patch Set: Change lambda bind to a more classical bind. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/policy/core/common/policy_load_status.cc
diff --git a/components/policy/core/common/policy_load_status.cc b/components/policy/core/common/policy_load_status.cc
index 71c5059a7fd338f7897d0a4bf318e10b2337903a..22870beaa545feadcaaa2df65e71ff693ab61954 100644
--- a/components/policy/core/common/policy_load_status.cc
+++ b/components/policy/core/common/policy_load_status.cc
@@ -4,6 +4,7 @@
#include "components/policy/core/common/policy_load_status.h"
+#include "base/bind.h"
#include "base/metrics/histogram.h"
#include "base/strings/stringprintf.h"
#include "components/policy/core/common/policy_types.h"
@@ -14,20 +15,31 @@ namespace {
const char kHistogramName[] = "Enterprise.PolicyLoadStatus";
+void ReportPolicyLoadStatus(base::HistogramBase* histogram,
+ PolicyLoadStatus status) {
+ histogram->Add(status);
+}
+
} // namespace
-PolicyLoadStatusSample::PolicyLoadStatusSample()
- : histogram_(base::LinearHistogram::FactoryGet(
- kHistogramName, 1, POLICY_LOAD_STATUS_SIZE,
- POLICY_LOAD_STATUS_SIZE + 1,
- base::Histogram::kUmaTargetedHistogramFlag)) {
+PolicyLoadStatusSample::PolicyLoadStatusSample(
+ const ReportCallback& report_callback)
+ : report_callback_(report_callback) {
+ // Report to a base::LinearHistogram by default.
+ if (report_callback_.is_null()) {
+ base::HistogramBase* histogram(base::LinearHistogram::FactoryGet(
+ kHistogramName, 1, POLICY_LOAD_STATUS_SIZE, POLICY_LOAD_STATUS_SIZE + 1,
+ base::Histogram::kUmaTargetedHistogramFlag));
+ report_callback_ = base::Bind(&ReportPolicyLoadStatus, histogram);
+ }
+
Add(POLICY_LOAD_STATUS_STARTED);
}
PolicyLoadStatusSample::~PolicyLoadStatusSample() {
for (int i = 0; i < POLICY_LOAD_STATUS_SIZE; ++i) {
if (status_bits_[i])
- histogram_->Add(i);
+ report_callback_.Run(static_cast<PolicyLoadStatus>(i));
}
}

Powered by Google App Engine
This is Rietveld 408576698