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