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

Side by Side Diff: components/metrics/chromeos/linearhistogram_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/linearhistogram_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 LinearHistogramSample::LinearHistogramSample(const std::string& histname,
19 int sample,
20 int max)
21 : MetricSample(MetricSample::LINEAR_HISTOGRAM, histname),
22 sample_(sample),
23 max_(max) {}
24
25 LinearHistogramSample::~LinearHistogramSample() {}
26
27 std::string LinearHistogramSample::ToString() const {
28 return base::StringPrintf(
29 "linearhistogram%c%s %d %d%c", '\0', name().c_str(), sample_, max_, '\0');
30 }
31
32 // static
33 scoped_ptr<LinearHistogramSample> LinearHistogramSample::ReadLinearHistogram(
34 const std::string& histogram_serialized) {
35 std::vector<std::string> parts;
36 int sample, max;
37 base::SplitString(histogram_serialized, ' ', &parts);
38 if (parts.size() != 3)
39 return scoped_ptr<LinearHistogramSample>();
40 if (parts[0].length() == 0 || !base::StringToInt(parts[1], &sample) ||
41 !base::StringToInt(parts[2], &max))
42 return scoped_ptr<LinearHistogramSample>();
43
44 return scoped_ptr<LinearHistogramSample>(
45 new LinearHistogramSample(parts[0], sample, max));
46 }
47
48 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698