OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/metrics/sparse_histogram.h" | 5 #include "base/metrics/sparse_histogram.h" |
6 | 6 |
7 #include "base/metrics/sample_map.h" | 7 #include "base/metrics/sample_map.h" |
8 #include "base/metrics/statistics_recorder.h" | 8 #include "base/metrics/statistics_recorder.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 | 11 |
12 using std::map; | 12 using std::map; |
13 using std::string; | 13 using std::string; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 typedef HistogramBase::Count Count; | 17 typedef HistogramBase::Count Count; |
18 typedef HistogramBase::Sample Sample; | 18 typedef HistogramBase::Sample Sample; |
19 | 19 |
20 // static | 20 // static |
21 HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) { | 21 HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) { |
22 // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder. | 22 HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); |
23 HistogramBase* histogram = new SparseHistogram(name); | 23 |
24 histogram->SetFlags(flags); | 24 if (!histogram) { |
| 25 // To avoid racy destruction at shutdown, the following will be leaked. |
| 26 HistogramBase* tentative_histogram = new SparseHistogram(name); |
| 27 tentative_histogram->SetFlags(flags); |
| 28 histogram = |
| 29 StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
| 30 } |
| 31 DCHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType()); |
25 return histogram; | 32 return histogram; |
26 } | 33 } |
27 | 34 |
28 SparseHistogram::~SparseHistogram() {} | 35 SparseHistogram::~SparseHistogram() {} |
29 | 36 |
30 HistogramType SparseHistogram::GetHistogramType() const { | 37 HistogramType SparseHistogram::GetHistogramType() const { |
31 return SPARSE_HISTOGRAM; | 38 return SPARSE_HISTOGRAM; |
32 } | 39 } |
33 | 40 |
34 bool SparseHistogram::HasConstructionArguments(Sample minimum, | 41 bool SparseHistogram::HasConstructionArguments(Sample minimum, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 void SparseHistogram::GetParameters(DictionaryValue* params) const { | 100 void SparseHistogram::GetParameters(DictionaryValue* params) const { |
94 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) | 101 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) |
95 } | 102 } |
96 | 103 |
97 void SparseHistogram::GetCountAndBucketData(Count* count, | 104 void SparseHistogram::GetCountAndBucketData(Count* count, |
98 ListValue* buckets) const { | 105 ListValue* buckets) const { |
99 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) | 106 // TODO(kaiwang): Implement. (See HistogramBase::WriteJSON.) |
100 } | 107 } |
101 | 108 |
102 } // namespace base | 109 } // namespace base |
OLD | NEW |