Index: base/metrics/histogram.cc |
diff --git a/base/metrics/histogram.cc b/base/metrics/histogram.cc |
index fbe66d05d29fd3c2896f8499dd1dc07d9793d095..52dc8ef656d8a372d53803171fd779a52a5ece33 100644 |
--- a/base/metrics/histogram.cc |
+++ b/base/metrics/histogram.cc |
@@ -76,6 +76,23 @@ bool ValidateRangeChecksum(const HistogramBase& histogram, |
return casted_histogram.bucket_ranges()->checksum() == range_checksum; |
} |
+// DummyHistogram is an object that overrides Histogram's Add* functions |
+// to provide no functionality. This can be returned in the case of mismatched |
+// construction arguments to any of the other Histograms' FactoryGet calls. |
+class DummyHistogram : public Histogram { |
+ public: |
+ virtual void Add(Sample value) OVERRIDE {} |
+ virtual void AddSamples(const HistogramSamples& samples) OVERRIDE {} |
+ virtual bool AddSamplesFromPickle(PickleIterator* iter) OVERRIDE { |
+ return false; |
+ } |
+ |
+ DummyHistogram() : Histogram("Dummy", 0, 1, NULL) {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(DummyHistogram); |
+}; |
+ |
} // namespace |
typedef HistogramBase::Count Count; |
@@ -110,7 +127,16 @@ HistogramBase* Histogram::FactoryGet(const string& name, |
} |
DCHECK_EQ(HISTOGRAM, histogram->GetHistogramType()); |
- CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); |
+ if (!histogram->HasConstructionArguments(minimum, maximum, bucket_count)) { |
jar (doing other things)
2014/01/23 02:16:18
This is a sad thing... as it means we can't catch
|
+ // The construction arguments do not match the existing histogram. This can |
+ // come about if an extension updates in the middle of a chrome run and has |
+ // changed one of them. We return a dummy object here instead of crashing |
+ // so poor use of extension/Pepper APIs do not cause crashes in Chrome. |
+ DLOG(ERROR) << "Histogram " << name << " has bad construction arguments"; |
+ DummyHistogram* tentative_histogram = new DummyHistogram; |
+ histogram = |
+ StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
+ } |
return histogram; |
} |
@@ -567,7 +593,16 @@ HistogramBase* LinearHistogram::FactoryGetWithRangeDescription( |
} |
DCHECK_EQ(LINEAR_HISTOGRAM, histogram->GetHistogramType()); |
- CHECK(histogram->HasConstructionArguments(minimum, maximum, bucket_count)); |
jar (doing other things)
2014/01/23 02:16:18
Same issue... I really wish we could preserve this
Alexei Svitkine (slow)
2014/01/23 15:28:22
Personally, I think this is a reasonable place to
elijahtaylor1
2014/01/24 01:27:26
I've implemented this suggestion to see how ugly i
|
+ if (!histogram->HasConstructionArguments(minimum, maximum, bucket_count)) { |
+ // The construction arguments do not match the existing histogram. This can |
+ // come about if an extension updates in the middle of a chrome run and has |
+ // changed one of them. We return a dummy object here instead of crashing |
+ // so poor use of extension/Pepper APIs do not cause crashes in Chrome. |
+ DLOG(ERROR) << "Histogram " << name << " has bad construction arguments"; |
+ DummyHistogram* tentative_histogram = new DummyHistogram; |
+ histogram = |
+ StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
+ } |
return histogram; |
} |