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/linearhistogram_sample_chromeos.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/strings/string_number_conversions.h" | |
10 #include "base/strings/string_split.h" | |
11 #include "base/strings/stringprintf.h" | |
12 #include "components/metrics/metric_sample_chromeos.h" | |
13 | |
14 using base::StringPrintf; | |
15 using base::StringToInt; | |
16 using base::SplitString; | |
17 using std::string; | |
18 using std::vector; | |
19 | |
20 namespace metrics { | |
21 | |
22 LinearHistogramSample::LinearHistogramSample(const std::string& histname, | |
23 int sample, | |
24 int max) | |
25 : MetricSample(MetricSample::LINEAR_HISTOGRAM, histname), | |
26 sample_(sample), | |
27 max_(max) {} | |
28 | |
29 LinearHistogramSample::~LinearHistogramSample() {} | |
30 | |
31 string LinearHistogramSample::ToString() const { | |
32 return StringPrintf( | |
33 "linearhistogram%c%s %d %d%c", '\0', name().c_str(), sample_, max_, '\0'); | |
34 } | |
35 | |
36 // static | |
37 LinearHistogramSample* LinearHistogramSample::ReadLinearHistogram( | |
38 const std::string& histogram_serialized) { | |
39 vector<string> parts; | |
40 int sample, max; | |
41 SplitString(histogram_serialized, ' ', &parts); | |
42 if (parts.size() != 3) return NULL; | |
43 if (!StringToInt(parts[1], &sample) || !StringToInt(parts[2], &max)) | |
44 return NULL; | |
45 | |
46 return new LinearHistogramSample(parts[0], sample, max); | |
Ben Chan
2014/04/18 20:27:08
see previous comments on commenting serialized for
| |
47 } | |
48 | |
49 } // namespace metrics | |
OLD | NEW |