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

Side by Side Diff: components/metrics/export/histogram_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: Convert to use scoped_ptr. Remove using declarations. Fixed linting. 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/export/histogram_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/export/metric_sample.h"
15
16 namespace metrics {
17
18 HistogramSample::HistogramSample(const std::string& name,
19 int sample,
20 int min,
21 int max,
22 int nbucket)
23 : MetricSample(MetricSample::HISTOGRAM, name),
24 sample_(sample),
25 min_(min),
26 max_(max),
27 nbucket_(nbucket) {}
28
29 HistogramSample::~HistogramSample() {}
30
31 std::string HistogramSample::ToString() const {
32 return base::StringPrintf("histogram%c%s %d %d %d %d%c",
33 '\0',
34 name().c_str(),
35 sample_,
36 min_,
37 max_,
38 nbucket_,
39 '\0');
40 }
41
42 // static
43 // Read a histogram from a string listing |name|, |sample|, |min|, |max|,
44 // |nbucket| separated by a space.
45 scoped_ptr<HistogramSample> HistogramSample::ReadHistogram(
46 const std::string& histogram_serialized) {
47 std::vector<std::string> parts;
48 base::SplitString(histogram_serialized, ' ', &parts);
49 if (parts.size() != 5)
50 return scoped_ptr<HistogramSample>();
51 int sample, min, max, nbucket;
52 if (parts[0].length() == 0 || !base::StringToInt(parts[1], &sample) ||
53 !base::StringToInt(parts[2], &min) ||
54 !base::StringToInt(parts[3], &max) ||
55 !base::StringToInt(parts[4], &nbucket))
Alexei Svitkine (slow) 2014/05/01 15:57:09 Nit: {}
bsimonnet 2014/05/01 20:34:21 Done.
56 return scoped_ptr<HistogramSample>();
57
58 return scoped_ptr<HistogramSample>(
59 new HistogramSample(parts[0], sample, min, max, nbucket));
60 }
61
62 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698