Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: components/metrics/chromeos/sparsehistogram_sample.cc

Issue 227873002: Create a histogram serialization mechanism in components/metrics (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move files into chromeos. Fixed linting issues. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698