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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/policy/core/common/policy_load_status.h" 5 #include "components/policy/core/common/policy_load_status.h"
6 6
7 #include "base/bind.h"
7 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
8 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
9 #include "components/policy/core/common/policy_types.h" 10 #include "components/policy/core/common/policy_types.h"
10 11
11 namespace policy { 12 namespace policy {
12 13
13 namespace { 14 namespace {
14 15
15 const char kHistogramName[] = "Enterprise.PolicyLoadStatus"; 16 const char kHistogramName[] = "Enterprise.PolicyLoadStatus";
16 17
18 void ReportPolicyLoadStatus(base::HistogramBase* histogram,
19 PolicyLoadStatus status) {
20 histogram->Add(status);
21 }
22
17 } // namespace 23 } // namespace
18 24
19 PolicyLoadStatusSample::PolicyLoadStatusSample() 25 PolicyLoadStatusSample::PolicyLoadStatusSample(
20 : histogram_(base::LinearHistogram::FactoryGet( 26 const ReportCallback& report_callback)
21 kHistogramName, 1, POLICY_LOAD_STATUS_SIZE, 27 : report_callback_(report_callback) {
22 POLICY_LOAD_STATUS_SIZE + 1, 28 // Report to a base::LinearHistogram by default.
23 base::Histogram::kUmaTargetedHistogramFlag)) { 29 if (report_callback_.is_null()) {
30 base::HistogramBase* histogram(base::LinearHistogram::FactoryGet(
31 kHistogramName, 1, POLICY_LOAD_STATUS_SIZE, POLICY_LOAD_STATUS_SIZE + 1,
32 base::Histogram::kUmaTargetedHistogramFlag));
33 report_callback_ = base::Bind(&ReportPolicyLoadStatus, histogram);
34 }
35
24 Add(POLICY_LOAD_STATUS_STARTED); 36 Add(POLICY_LOAD_STATUS_STARTED);
25 } 37 }
26 38
27 PolicyLoadStatusSample::~PolicyLoadStatusSample() { 39 PolicyLoadStatusSample::~PolicyLoadStatusSample() {
28 for (int i = 0; i < POLICY_LOAD_STATUS_SIZE; ++i) { 40 for (int i = 0; i < POLICY_LOAD_STATUS_SIZE; ++i) {
29 if (status_bits_[i]) 41 if (status_bits_[i])
30 histogram_->Add(i); 42 report_callback_.Run(static_cast<PolicyLoadStatus>(i));
31 } 43 }
32 } 44 }
33 45
34 void PolicyLoadStatusSample::Add(PolicyLoadStatus status) { 46 void PolicyLoadStatusSample::Add(PolicyLoadStatus status) {
35 status_bits_[status] = true; 47 status_bits_[status] = true;
36 } 48 }
37 49
38 } // namespace policy 50 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698