Support using UMA_HISTOGRAM_CUSTOM_ENUMERATION from the renderer.
BUG=103633
TEST=trybots & manually checking that chrome://histograms/Aspect now shows the two custom enum histograms from r108951, with correctly specific buckets.
Review URL: http://codereview.chromium.org/8506038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109823 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc
index 7077b09..a44a2eb88 100644
--- a/base/metrics/histogram.cc
+++ b/base/metrics/histogram.cc
@@ -239,13 +239,16 @@
pickle.WriteInt(histogram.flags());
snapshot.Serialize(&pickle);
+
+ histogram.SerializeRanges(&pickle);
+
return std::string(static_cast<const char*>(pickle.data()), pickle.size());
}
// static
bool Histogram::DeserializeHistogramInfo(const std::string& histogram_info) {
if (histogram_info.empty()) {
- return false;
+ return false;
}
Pickle pickle(histogram_info.data(),
@@ -271,6 +274,7 @@
DLOG(ERROR) << "Pickle error decoding Histogram: " << histogram_name;
return false;
}
+
DCHECK(pickle_flags & kIPCSerializationSourceFlag);
// Since these fields may have come from an untrusted renderer, do additional
// checks above and beyond those in Histogram::Initialize()
@@ -294,6 +298,14 @@
histogram_name, declared_min, declared_max, bucket_count, flags);
} else if (histogram_type == BOOLEAN_HISTOGRAM) {
render_histogram = BooleanHistogram::FactoryGet(histogram_name, flags);
+ } else if (histogram_type == CUSTOM_HISTOGRAM) {
+ std::vector<Histogram::Sample> sample_ranges(bucket_count);
+ if (!CustomHistogram::DeserializeRanges(&iter, pickle, &sample_ranges)) {
+ DLOG(ERROR) << "Pickle error decoding ranges: " << histogram_name;
+ return false;
+ }
+ render_histogram =
+ CustomHistogram::FactoryGet(histogram_name, sample_ranges, flags);
} else {
DLOG(ERROR) << "Error Deserializing Histogram Unknown histogram_type: "
<< histogram_type;
@@ -440,6 +452,10 @@
DCHECK(ValidateBucketRanges());
}
+bool Histogram::SerializeRanges(Pickle* pickle) const {
+ return true;
+}
+
// Calculate what range of values are held in each bucket.
// We have to be careful that we don't pick a ratio between starting points in
// consecutive buckets that is sooo small, that the integer bounds are the same
@@ -981,6 +997,24 @@
DCHECK_EQ(custom_ranges[0], 0);
}
+bool CustomHistogram::SerializeRanges(Pickle* pickle) const {
+ for (size_t i = 0; i < cached_ranges()->size(); ++i) {
+ if (!pickle->WriteInt(cached_ranges()->ranges(i)))
+ return false;
+ }
+ return true;
+}
+
+// static
+bool CustomHistogram::DeserializeRanges(
+ void** iter, const Pickle& pickle, std::vector<Histogram::Sample>* ranges) {
+ for (size_t i = 0; i < ranges->size(); ++i) {
+ if (!pickle.ReadInt(iter, &(*ranges)[i]))
+ return false;
+ }
+ return true;
+}
+
void CustomHistogram::InitializedCustomBucketRange(
const std::vector<Sample>& custom_ranges) {
DCHECK_GT(custom_ranges.size(), 1u);