rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 1 | // Copyright 2014 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 | |
mef | c2bd1aa | 2015-04-09 03:26:53 | [diff] [blame^] | 5 | #ifndef COMPONENTS_CRONET_HISTOGRAM_MANAGER_H_ |
| 6 | #define COMPONENTS_CRONET_HISTOGRAM_MANAGER_H_ |
rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "base/basictypes.h" |
| 12 | #include "base/lazy_instance.h" |
| 13 | #include "base/macros.h" |
| 14 | #include "base/memory/scoped_ptr.h" |
| 15 | #include "base/metrics/histogram_flattener.h" |
| 16 | #include "base/metrics/histogram_snapshot_manager.h" |
| 17 | #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" |
| 18 | |
mef | c2bd1aa | 2015-04-09 03:26:53 | [diff] [blame^] | 19 | namespace cronet { |
rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 20 | |
mef | c2bd1aa | 2015-04-09 03:26:53 | [diff] [blame^] | 21 | // A HistogramManager instance is created by the app. It is the central |
| 22 | // controller for the acquisition of log data, and recording deltas for |
| 23 | // transmission to an external server. |
rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 24 | class HistogramManager : public base::HistogramFlattener { |
| 25 | public: |
| 26 | HistogramManager(); |
dcheng | 6a89b90 | 2014-12-30 21:40:58 | [diff] [blame] | 27 | ~HistogramManager() override; |
rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 28 | |
| 29 | // Snapshot all histograms to record the delta into |uma_proto_| and then |
| 30 | // returns the serialized protobuf representation of the record in |data|. |
| 31 | // Returns true if it was successfully serialized. |
| 32 | bool GetDeltas(std::vector<uint8>* data); |
| 33 | |
| 34 | // TODO(mef): Hang Histogram Manager off java object instead of singleton. |
| 35 | static HistogramManager* GetInstance(); |
| 36 | |
| 37 | private: |
| 38 | friend struct base::DefaultLazyInstanceTraits<HistogramManager>; |
| 39 | |
| 40 | // base::HistogramFlattener: |
| 41 | void RecordDelta(const base::HistogramBase& histogram, |
| 42 | const base::HistogramSamples& snapshot) override; |
| 43 | void InconsistencyDetected( |
| 44 | base::HistogramBase::Inconsistency problem) override; |
| 45 | void UniqueInconsistencyDetected( |
| 46 | base::HistogramBase::Inconsistency problem) override; |
| 47 | void InconsistencyDetectedInLoggedCount(int amount) override; |
| 48 | |
| 49 | base::HistogramSnapshotManager histogram_snapshot_manager_; |
| 50 | |
| 51 | // Stores the protocol buffer representation for this log. |
| 52 | metrics::ChromeUserMetricsExtension uma_proto_; |
| 53 | |
| 54 | DISALLOW_COPY_AND_ASSIGN(HistogramManager); |
| 55 | }; |
| 56 | |
mef | c2bd1aa | 2015-04-09 03:26:53 | [diff] [blame^] | 57 | } // namespace cronet |
rtenneti | 7254696 | 2014-12-15 21:41:59 | [diff] [blame] | 58 | |
mef | c2bd1aa | 2015-04-09 03:26:53 | [diff] [blame^] | 59 | #endif // COMPONENTS_CRONET_HISTOGRAM_MANAGER_H_ |