OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_COMMON_METRICS_HISTOGRAM_SENDER_H_ | |
6 #define CHROME_COMMON_METRICS_HISTOGRAM_SENDER_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <string> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/metrics/histogram.h" | |
15 | |
16 // HistogramSender handles the logistics of gathering up available histograms | |
17 // for transmission (such as from renderer to browser, or from browser to UMA | |
18 // upload). It has several pure virtual functions that are replaced in | |
19 // derived classes to allow the exact lower level transmission mechanism, | |
20 // or error report mechanism, to be replaced. Since histograms can sit in | |
21 // memory for an extended period of time, and are vulnerable to memory | |
22 // corruption, this class also validates as much rendundancy as it can before | |
23 // calling for the marginal change (a.k.a., delta) in a histogram to be sent | |
24 // onward. | |
25 class HistogramSender { | |
26 protected: | |
27 HistogramSender(); | |
28 virtual ~HistogramSender(); | |
29 | |
30 // Snapshot all histograms, and transmit the delta. | |
31 // The arguments allow a derived class to select only a subset for | |
32 // transmission, or to set a flag in each transmitted histogram. | |
33 void TransmitAllHistograms(base::Histogram::Flags flags_to_set, | |
34 bool send_only_uma); | |
35 | |
36 // Send the histograms onward, as defined in a derived class. | |
37 // This is only called with a delta, listing samples that have not previously | |
38 // been transmitted. | |
39 virtual void TransmitHistogramDelta( | |
40 const base::Histogram& histogram, | |
41 const base::Histogram::SampleSet& snapshot) = 0; | |
42 | |
43 // Record various errors found during attempts to send histograms. | |
44 virtual void InconsistencyDetected(int problem) = 0; | |
45 virtual void UniqueInconsistencyDetected(int problem) = 0; | |
46 virtual void SnapshotProblemResolved(int amount) = 0; | |
47 | |
48 private: | |
49 // Maintain a map of histogram names to the sample stats we've sent. | |
50 typedef std::map<std::string, base::Histogram::SampleSet> LoggedSampleMap; | |
51 // List of histograms names, and their encontered corruptions. | |
52 typedef std::map<std::string, int> ProblemMap; | |
53 | |
54 // Snapshot this histogram, and transmit the delta. | |
55 void TransmitHistogram(const base::Histogram& histogram); | |
56 | |
57 // For histograms, record what we've already transmitted (as a sample for each | |
58 // histogram) so that we can send only the delta with the next log. | |
59 LoggedSampleMap logged_samples_; | |
60 | |
61 // List of histograms found corrupt to be corrupt, and their problems. | |
62 scoped_ptr<ProblemMap> inconsistencies_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(HistogramSender); | |
65 }; | |
66 | |
67 #endif // CHROME_COMMON_METRICS_HISTOGRAM_SENDER_H_ | |
OLD | NEW |