OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/histogram_delta_serialization.h" | 5 #include "base/metrics/histogram_delta_serialization.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/metrics/histogram_base.h" | 8 #include "base/metrics/histogram_base.h" |
9 #include "base/metrics/histogram_snapshot_manager.h" | 9 #include "base/metrics/histogram_snapshot_manager.h" |
| 10 #include "base/numerics/safe_conversions.h" |
10 #include "base/pickle.h" | 11 #include "base/pickle.h" |
11 #include "base/safe_numerics.h" | |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // Create or find existing histogram and add the samples from pickle. | 18 // Create or find existing histogram and add the samples from pickle. |
19 // Silently returns when seeing any data problem in the pickle. | 19 // Silently returns when seeing any data problem in the pickle. |
20 void DeserializeHistogramAndAddSamples(PickleIterator* iter) { | 20 void DeserializeHistogramAndAddSamples(PickleIterator* iter) { |
21 HistogramBase* histogram = DeserializeHistogramInfo(iter); | 21 HistogramBase* histogram = DeserializeHistogramInfo(iter); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 histogram_snapshot_manager_.PrepareDeltas( | 68 histogram_snapshot_manager_.PrepareDeltas( |
69 Histogram::kIPCSerializationSourceFlag, false); | 69 Histogram::kIPCSerializationSourceFlag, false); |
70 serialized_deltas_ = NULL; | 70 serialized_deltas_ = NULL; |
71 } | 71 } |
72 | 72 |
73 // static | 73 // static |
74 void HistogramDeltaSerialization::DeserializeAndAddSamples( | 74 void HistogramDeltaSerialization::DeserializeAndAddSamples( |
75 const std::vector<std::string>& serialized_deltas) { | 75 const std::vector<std::string>& serialized_deltas) { |
76 for (std::vector<std::string>::const_iterator it = serialized_deltas.begin(); | 76 for (std::vector<std::string>::const_iterator it = serialized_deltas.begin(); |
77 it != serialized_deltas.end(); ++it) { | 77 it != serialized_deltas.end(); ++it) { |
78 Pickle pickle(it->data(), checked_numeric_cast<int>(it->size())); | 78 Pickle pickle(it->data(), checked_cast<int>(it->size())); |
79 PickleIterator iter(pickle); | 79 PickleIterator iter(pickle); |
80 DeserializeHistogramAndAddSamples(&iter); | 80 DeserializeHistogramAndAddSamples(&iter); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void HistogramDeltaSerialization::RecordDelta( | 84 void HistogramDeltaSerialization::RecordDelta( |
85 const HistogramBase& histogram, | 85 const HistogramBase& histogram, |
86 const HistogramSamples& snapshot) { | 86 const HistogramSamples& snapshot) { |
87 DCHECK_NE(0, snapshot.TotalCount()); | 87 DCHECK_NE(0, snapshot.TotalCount()); |
88 | 88 |
(...skipping 13 matching lines...) Expand all Loading... |
102 HistogramBase::Inconsistency problem) { | 102 HistogramBase::Inconsistency problem) { |
103 inconsistencies_unique_histogram_->Add(problem); | 103 inconsistencies_unique_histogram_->Add(problem); |
104 } | 104 } |
105 | 105 |
106 void HistogramDeltaSerialization::InconsistencyDetectedInLoggedCount( | 106 void HistogramDeltaSerialization::InconsistencyDetectedInLoggedCount( |
107 int amount) { | 107 int amount) { |
108 inconsistent_snapshot_histogram_->Add(std::abs(amount)); | 108 inconsistent_snapshot_histogram_->Add(std::abs(amount)); |
109 } | 109 } |
110 | 110 |
111 } // namespace base | 111 } // namespace base |
OLD | NEW |