Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 "base/metrics/sparsehistogram_sample_chromeos.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/metrics/metric_sample_chromeos.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/strings/string_split.h" | |
| 12 #include "base/strings/stringprintf.h" | |
| 13 | |
| 14 using std::string; | |
| 15 using std::vector; | |
| 16 | |
| 17 namespace base { | |
| 18 | |
| 19 SparseHistogramSample::SparseHistogramSample(const std::string& histogram_name, | |
| 20 int sample) | |
| 21 : MetricSample(MetricSample::SPARSE_HISTOGRAM, histogram_name), | |
| 22 sample_(sample) {} | |
| 23 | |
| 24 int SparseHistogramSample::sample() const { return sample_; } | |
| 25 | |
| 26 SparseHistogramSample* SparseHistogramSample::ReadSparseHistogram( | |
| 27 const std::string& histogram_serialized) { | |
| 28 vector<string> parts; | |
| 29 SplitString(histogram_serialized, ' ', &parts); | |
| 30 if (parts.size() != 2) { | |
|
Alexei Svitkine (slow)
2014/04/17 16:33:21
Nit: No need for {}'s for single-line bodies. Plea
| |
| 31 return NULL; | |
| 32 } | |
| 33 int sample; | |
| 34 if (!StringToInt(parts[1], &sample)) { | |
| 35 return NULL; | |
| 36 } | |
| 37 return new SparseHistogramSample(parts[0], sample); | |
| 38 } | |
| 39 | |
| 40 SparseHistogramSample::~SparseHistogramSample() {} | |
| 41 | |
| 42 string SparseHistogramSample::ToString() const { | |
| 43 return StringPrintf( | |
| 44 "sparsehistogram%c%s %d%c", '\0', name_.c_str(), sample_, '\0'); | |
| 45 } | |
| 46 } // namespace base | |
| OLD | NEW |