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/chromeos/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/chromeos/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 scoped_ptr<LinearHistogramSample> LinearHistogramSample::ReadLinearHistogram( |
| 34 const std::string& histogram_serialized) { |
| 35 std::vector<std::string> parts; |
| 36 int sample, max; |
| 37 base::SplitString(histogram_serialized, ' ', &parts); |
| 38 if (parts.size() != 3) |
| 39 return scoped_ptr<LinearHistogramSample>(); |
| 40 if (parts[0].length() == 0 || !base::StringToInt(parts[1], &sample) || |
| 41 !base::StringToInt(parts[2], &max)) |
| 42 return scoped_ptr<LinearHistogramSample>(); |
| 43 |
| 44 return scoped_ptr<LinearHistogramSample>( |
| 45 new LinearHistogramSample(parts[0], sample, max)); |
| 46 } |
| 47 |
| 48 } // namespace metrics |
OLD | NEW |