OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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/metrics/export/linearhistogram_sample.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/strings/string_number_conversions.h" | |
12 #include "base/strings/string_split.h" | |
13 #include "base/strings/stringprintf.h" | |
14 #include "components/metrics/export/metric_sample.h" | |
15 | |
16 namespace metrics { | |
17 | |
18 LinearHistogramSample::LinearHistogramSample(const std::string& histname, | |
19 int sample, | |
20 int max) | |
21 : MetricSample(MetricSample::LINEAR_HISTOGRAM, histname), | |
22 sample_(sample), | |
23 max_(max) {} | |
24 | |
25 LinearHistogramSample::~LinearHistogramSample() {} | |
26 | |
27 std::string LinearHistogramSample::ToString() const { | |
28 return base::StringPrintf( | |
29 "linearhistogram%c%s %d %d%c", '\0', name().c_str(), sample_, max_, '\0'); | |
30 } | |
31 | |
32 // static | |
33 // Read a linear histogram from a string listing |name|, |sample|, |max| | |
34 // separated by space. | |
Alexei Svitkine (slow)
2014/05/01 15:57:09
Nit: This comment should only say: // static
The
bsimonnet
2014/05/01 20:34:21
Done.
| |
35 scoped_ptr<LinearHistogramSample> LinearHistogramSample::ReadLinearHistogram( | |
36 const std::string& histogram_serialized) { | |
37 std::vector<std::string> parts; | |
38 int sample, max; | |
39 base::SplitString(histogram_serialized, ' ', &parts); | |
40 if (parts.size() != 3) | |
41 return scoped_ptr<LinearHistogramSample>(); | |
42 if (parts[0].length() == 0 || !base::StringToInt(parts[1], &sample) || | |
43 !base::StringToInt(parts[2], &max)) | |
44 return scoped_ptr<LinearHistogramSample>(); | |
45 | |
46 return scoped_ptr<LinearHistogramSample>( | |
47 new LinearHistogramSample(parts[0], sample, max)); | |
48 } | |
49 | |
50 } // namespace metrics | |
OLD | NEW |