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/sparsehistogram_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::SplitString; |
| 15 using base::StringPrintf; |
| 16 using base::StringToInt; |
| 17 using std::string; |
| 18 using std::vector; |
| 19 |
| 20 namespace metrics { |
| 21 |
| 22 SparseHistogramSample::SparseHistogramSample(const std::string& histogram_name, |
| 23 int sample) |
| 24 : MetricSample(MetricSample::SPARSE_HISTOGRAM, histogram_name), |
| 25 sample_(sample) {} |
| 26 |
| 27 SparseHistogramSample::~SparseHistogramSample() {} |
| 28 |
| 29 string SparseHistogramSample::ToString() const { |
| 30 return StringPrintf( |
| 31 "sparsehistogram%c%s %d%c", '\0', name().c_str(), sample_, '\0'); |
| 32 } |
| 33 |
| 34 // static |
| 35 SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram( |
| 36 const std::string& histogram_serialized) { |
| 37 vector<string> parts; |
| 38 SplitString(histogram_serialized, ' ', &parts); |
| 39 if (parts.size() != 2) return NULL; |
| 40 int sample; |
| 41 if (!StringToInt(parts[1], &sample)) return NULL; |
| 42 |
| 43 return new SparseHistogramSample(parts[0], sample); |
| 44 } |
| 45 |
| 46 } // namespace metrics |
OLD | NEW |