Chromium Code Reviews| Index: components/metrics/metric_sample_chromeos.h |
| diff --git a/components/metrics/metric_sample_chromeos.h b/components/metrics/metric_sample_chromeos.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9c296677574acc988dbf2f7ea8a59c0c41bd8688 |
| --- /dev/null |
| +++ b/components/metrics/metric_sample_chromeos.h |
| @@ -0,0 +1,60 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef COMPONENTS_METRICS_METRIC_SAMPLE_CHROMEOS_H_ |
| +#define COMPONENTS_METRICS_METRIC_SAMPLE_CHROMEOS_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/base_export.h" |
| +#include "base/macros.h" |
| + |
| +namespace metrics { |
| + |
| +// Abstract class representing a metric sample (single measures). |
| +// This class and its subclasses are used by libmetrics (ChromeOS) to serialize |
| +// and deserialize measurements to send them to a metrics sending service. |
| +// It is meant to be a simple container with serialization functions. |
| +class BASE_EXPORT MetricSample { |
| + public: |
| + // Types of metric sample used. |
| + enum SampleType { |
| + CRASH, |
| + HISTOGRAM, |
| + LINEAR_HISTOGRAM, |
| + SPARSE_HISTOGRAM, |
| + USER_ACTION |
| + }; |
| + explicit MetricSample(SampleType type, const std::string& metric_name); |
|
Ben Chan
2014/04/18 20:27:08
explicit is not needed when there are two or more
|
| + virtual ~MetricSample(); |
| + |
| + // Returns true if the sample is valid (can be serialized without ambiguity). |
| + // |
| + // This function should be used to filter bad samples before serializing them |
| + // to disk. |
| + virtual bool IsValid() const; |
| + SampleType type() const { return type_; } |
| + std::string name() const { return name_; } |
|
Ben Chan
2014/04/18 20:27:08
why not "const std::string& name() const"
|
| + |
| + // Returns a serialized version of the sample. |
| + // |
| + // This function should be overriden by subclasses to define their own |
| + // serialization format. |
| + // The general serialized message is: |
| + // |sampletype|,\0,<sample type specific serialized data>,\0 |
| + // |
| + // The format is akward but it is implemented independently in both chrome os |
| + // and chrome. We will keep it for now. |
| + virtual std::string ToString() const; |
| + |
| + private: |
| + const SampleType type_; |
| + const std::string name_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MetricSample); |
| +}; |
| + |
| +} // namespace metrics |
| + |
| +#endif // COMPONENTS_METRICS_METRIC_SAMPLE_CHROMEOS_H_ |